xref: /csrg-svn/sys/netiso/clnp.h (revision 37469)
1 /***********************************************************
2 		Copyright IBM Corporation 1987
3 
4                       All Rights Reserved
5 
6 Permission to use, copy, modify, and distribute this software and its
7 documentation for any purpose and without fee is hereby granted,
8 provided that the above copyright notice appear in all copies and that
9 both that copyright notice and this permission notice appear in
10 supporting documentation, and that the name of IBM not be
11 used in advertising or publicity pertaining to distribution of the
12 software without specific, written prior permission.
13 
14 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
15 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
16 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
17 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
19 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
20 SOFTWARE.
21 
22 ******************************************************************/
23 
24 /*
25  * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
26  */
27 /* $Header: /var/src/sys/netiso/RCS/clnp.h,v 5.1 89/02/09 16:17:22 hagens Exp $ */
28 /* $Source: /var/src/sys/netiso/RCS/clnp.h,v $ */
29 /*	@(#)clnp.h	7.4 (Berkeley) 04/22/89 */
30 
31 #ifndef BYTE_ORDER
32 /*
33  * Definitions for byte order,
34  * according to byte significance from low address to high.
35  */
36 #define	LITTLE_ENDIAN	1234	/* least-significant byte first (vax) */
37 #define	BIG_ENDIAN	4321	/* most-significant byte first (IBM, net) */
38 #define	PDP_ENDIAN	3412	/* LSB first in word, MSW first in long (pdp) */
39 
40 #ifdef vax
41 #define	BYTE_ORDER	LITTLE_ENDIAN
42 #else
43 #define	BYTE_ORDER	BIG_ENDIAN	/* mc68000, tahoe, most others */
44 #endif
45 #endif BYTE_ORDER
46 
47 /* should be config option but cpp breaks with too many #defines */
48 #define	DECBIT
49 
50 /*
51  *	Return true if the mbuf is a cluster mbuf
52  */
53 #define	IS_CLUSTER(m)	((m)->m_flags & M_EXT)
54 
55 /*
56  *	Move the halfword into the two characters
57  */
58 #define	HTOC(msb, lsb, hword)\
59 	(msb) = (u_char)((hword) >> 8);\
60 	(lsb) = (u_char)((hword) & 0xff)
61 /*
62  *	Move the two charcters into the halfword
63  */
64 #define	CTOH(msb, lsb, hword)\
65 	(hword) = ((msb) << 8) | (lsb)
66 
67 /*
68  *	Return true if the checksum has been set - ie. the checksum is
69  *	not zero
70  */
71 #define	CKSUM_REQUIRED(clnp)\
72 	(((clnp)->cnf_cksum_msb != 0) || ((clnp)->cnf_cksum_lsb != 0))
73 
74 /*
75  *	Fixed part of clnp header
76  */
77 struct clnp_fixed {
78 	u_char	cnf_proto_id;		/* network layer protocol identifier */
79 	u_char	cnf_hdr_len;		/* length indicator (octets) */
80 	u_char	cnf_vers;			/* version/protocol identifier extension */
81 	u_char	cnf_ttl;			/* lifetime (500 milliseconds) */
82 	u_char	cnf_type;			/* type code */
83 								/* Includes err_ok, more_segs, and seg_ok */
84 	u_char	cnf_seglen_msb;		/* pdu segment length (octets) high byte */
85 	u_char	cnf_seglen_lsb;		/* pdu segment length (octets) low byte */
86 	u_char	cnf_cksum_msb;		/* checksum high byte */
87 	u_char	cnf_cksum_lsb;		/* checksum low byte */
88 };
89 #define CNF_TYPE	0x1f
90 #define CNF_ERR_OK	0x20
91 #define CNF_MORE_SEGS	0x40
92 #define CNF_SEG_OK	0x80
93 
94 #define CLNP_CKSUM_OFF	0x07	/* offset of checksum */
95 
96 #define	clnl_fixed	clnp_fixed
97 
98 /*
99  *	Segmentation part of clnp header
100  */
101 struct clnp_segment {
102 	u_short	cng_id;				/* data unit identifier */
103 	u_short	cng_off;			/* segment offset */
104 	u_short	cng_tot_len;		/* total length */
105 };
106 
107 /*
108  *	Clnp fragment reassembly structures:
109  *
110  *	All packets undergoing reassembly are linked together in
111  *	clnp_fragl structures. Each clnp_fragl structure contains a
112  *	pointer to the original clnp packet header, as well as a
113  *	list of packet fragments. Each packet fragment
114  *	is headed by a clnp_frag structure. This structure contains the
115  *	offset of the first and last byte of the fragment, as well as
116  *	a pointer to the data (an mbuf chain) of the fragment.
117  */
118 
119 /*
120  *	NOTE:
121  *		The clnp_frag structure is stored in an mbuf immedately preceeding
122  *	the fragment data. Since there are words in this struct,
123  *	it must be word aligned.
124  *
125  *	NOTE:
126  *		All the fragment code assumes that the entire clnp header is
127  *	contained in the first mbuf.
128  */
129 struct clnp_frag {
130 	u_int				cfr_first;		/* offset of first byte of this frag */
131 	u_int				cfr_last;		/* offset of last byte of this frag */
132 	u_int				cfr_bytes;		/* bytes to shave to get to data */
133 	struct mbuf			*cfr_data;		/* ptr to data for this frag */
134 	struct clnp_frag	*cfr_next;		/* next fragment in list */
135 };
136 
137 struct clnp_fragl {
138 	struct iso_addr		cfl_src;		/* source of the pkt */
139 	struct iso_addr		cfl_dst;		/* destination of the pkt */
140 	u_short				cfl_id;			/* id of the pkt */
141 	u_char				cfl_ttl;		/* current ttl of pkt */
142 	u_short				cfl_last;		/* offset of last byte of packet */
143 	struct mbuf 		*cfl_orighdr;	/* ptr to original header */
144 	struct clnp_frag	*cfl_frags;		/* linked list of fragments for pkt */
145 	struct clnp_fragl	*cfl_next;		/* next pkt being reassembled */
146 };
147 
148 /*
149  *	The following structure is used to index into an options section
150  *	of a clnp datagram. These values can be used without worry that
151  *	offset or length fields are invalid or too big, etc. That is,
152  *	the consistancy of the options will be guaranteed before this
153  *	structure is filled in. Any pointer (field ending in p) is
154  *	actually the offset from the beginning of the mbuf the option
155  *	is contained in.  A value of NULL for any pointer
156  *	means that the option is not present. The length any option
157  *	does not include the option code or option length fields.
158  */
159 struct clnp_optidx {
160 	u_short	cni_securep;		/* ptr to beginning of security option */
161 	char	cni_secure_len;		/* length of entire security option */
162 
163 	u_short	cni_srcrt_s;		/* offset of start of src rt option */
164 	u_short	cni_srcrt_len;		/* length of entire src rt option */
165 
166 	u_short	cni_recrtp;			/* ptr to beginning of recrt option */
167 	char	cni_recrt_len;		/* length of entire recrt option */
168 
169 	char	cni_priorp;			/* ptr to priority option */
170 
171 	u_short	cni_qos_formatp;	/* ptr to format of qos option */
172 	char	cni_qos_len;		/* length of entire qos option */
173 
174 	u_char	cni_er_reason;		/* reason from ER pdu option */
175 
176 								/* ESIS options */
177 
178 	u_short	cni_esct;			/* value from ISH ESCT option */
179 
180 	u_short	cni_netmaskp;		/* ptr to beginning of netmask option */
181 	char	cni_netmask_len;		/* length of entire netmask option */
182 
183 	u_short	cni_snpamaskp;		/* ptr to beginning of snpamask option */
184 	char	cni_snpamask_len;		/* length of entire snpamask option */
185 
186 };
187 
188 #define	ER_INVALREAS	0xff	/* code for invalid ER pdu discard reason */
189 
190 /* given an mbuf and addr of option, return offset from data of mbuf */
191 #define CLNP_OPTTOOFF(m, opt)\
192 	((u_short) (opt - mtod(m, caddr_t)))
193 
194 /* given an mbuf and offset of option, return address of option */
195 #define CLNP_OFFTOOPT(m, off)\
196 	((caddr_t) (mtod(m, caddr_t) + off))
197 
198 /*	return true iff src route is valid */
199 #define	CLNPSRCRT_VALID(oidx)\
200 	((oidx) && (oidx->cni_srcrt_s))
201 
202 /*	return the offset field of the src rt */
203 #define CLNPSRCRT_OFF(oidx, options)\
204 	(*((u_char *)(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s) + 1)))
205 
206 /*	return the type field of the src rt */
207 #define CLNPSRCRT_TYPE(oidx, options)\
208 	((u_char)(*(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s))))
209 
210 /* return the length of the current address */
211 #define CLNPSRCRT_CLEN(oidx, options)\
212 	((u_char)(*(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s) + CLNPSRCRT_OFF(oidx, options) - 1)))
213 
214 /* return the address of the current address */
215 #define CLNPSRCRT_CADDR(oidx, options)\
216 	((caddr_t)(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s) + CLNPSRCRT_OFF(oidx, options)))
217 
218 /*
219  *	return true if the src route has run out of routes
220  *	this is true if the offset of next route is greater than the end of the rt
221  */
222 #define	CLNPSRCRT_TERM(oidx, options)\
223 	(CLNPSRCRT_OFF(oidx, options) > oidx->cni_srcrt_len)
224 
225 /*
226  *	Options a user can set/get
227  */
228 #define	CLNPOPT_FLAGS	0x01	/* flags: seg permitted, no er xmit, etc  */
229 #define	CLNPOPT_OPTS	0x02	/* datagram options */
230 
231 /*
232  *	Values for particular datagram options
233  */
234 #define	CLNPOVAL_PAD		0xcc	/* padding */
235 #define	CLNPOVAL_SECURE		0xc5	/* security */
236 #define	CLNPOVAL_SRCRT		0xc8	/* source routing */
237 #define	CLNPOVAL_RECRT		0xcb	/* record route */
238 #define	CLNPOVAL_QOS		0xc3	/* quality of service */
239 #define	CLNPOVAL_PRIOR		0xcd	/* priority */
240 #define CLNPOVAL_ERREAS		0xc1	/* ER PDU ONLY: reason for discard */
241 
242 #define	CLNPOVAL_SRCSPEC	0x40	/* source address specific */
243 #define	CLNPOVAL_DSTSPEC	0x80	/* destination address specific */
244 #define	CLNPOVAL_GLOBAL		0xc0	/* globally unique */
245 
246 /* Globally Unique QOS */
247 #define	CLNPOVAL_SEQUENCING	0x10	/* sequencing preferred */
248 #define CLNPOVAL_CONGESTED	0x08	/* congestion experienced */
249 #define CLNPOVAL_LOWDELAY	0x04	/* low transit delay */
250 
251 #define	CLNPOVAL_PARTRT		0x00	/* partial source routing */
252 #define CLNPOVAL_COMPRT		0x01	/* complete source routing */
253 
254 /*
255  *	Clnp flags used in a control block flags field.
256  *	NOTE: these must be out of the range of bits defined in ../net/raw_cb.h
257  */
258 #define	CLNP_NO_SEG		0x010	/* segmentation not permitted */
259 #define	CLNP_NO_ER		0x020	/* do not generate ERs */
260 #define CLNP_SEND_RAW	0x080	/* send pkt as RAW DT rather than TP DT */
261 #define	CLNP_NO_CKSUM	0x100	/* don't use clnp checksum */
262 #define CLNP_ECHO		0x200	/* fake echo function */
263 #define	CLNP_NOCACHE	0x400	/* don't store cache information */
264 
265 /* valid clnp flags */
266 #define CLNP_VFLAGS		(CLNP_SEND_RAW|CLNP_NO_SEG|CLNP_NO_ER|CLNP_NO_CKSUM\
267 	|CLNP_ECHO|CLNP_NOCACHE)
268 
269 /*
270  *	Constants used by clnp
271  */
272 #define	CLNP_HDR_MIN	(sizeof (struct clnp_fixed))
273 #define	CLNP_HDR_MAX	(254)
274 #define	CLNP_TTL_UNITS	2					/* 500 milliseconds */
275 #define CLNP_TTL		15*CLNP_TTL_UNITS	/* time to live (seconds) */
276 #define	ISO8473_V1		0x01
277 
278 /*
279  *	Clnp packet types
280  *	In order to test raw clnp and tp/clnp simultaneously, a third type of
281  *	packet has been defined: CLNP_RAW. This is done so that the input
282  *	routine can switch to the correct input routine (rclnp_input or
283  *	tpclnp_input) based on the type field. If clnp had a higher level protocol
284  *	field, this would not be necessary.
285  */
286 #define	CLNP_DT			0x1C	/* normal data */
287 #define	CLNP_ER			0x01	/* error report */
288 #define	CLNP_RAW		0x1D	/* debug only */
289 #define CLNP_EC			0x1E	/* echo packet */
290 #define CLNP_ECR		0x1F	/* echo reply */
291 
292 /*
293  *	ER pdu error codes
294  */
295 #define GEN_NOREAS			0x00	/* reason not specified */
296 #define GEN_PROTOERR		0x01	/* protocol procedure error */
297 #define GEN_BADCSUM			0x02	/* incorrect checksum */
298 #define GEN_CONGEST			0x03	/* pdu discarded due to congestion */
299 #define GEN_HDRSYNTAX		0x04	/* header syntax error */
300 #define GEN_SEGNEEDED		0x05	/* segmentation needed, but not permitted */
301 #define GEN_INCOMPLETE		0x06	/* incomplete pdu received */
302 #define GEN_DUPOPT			0x07	/* duplicate option */
303 
304 /* address errors */
305 #define ADDR_DESTUNREACH	0x80	/* destination address unreachable */
306 #define ADDR_DESTUNKNOWN	0x81	/* destination address unknown */
307 
308 /* source routing */
309 #define SRCRT_UNSPECERR		0x90	/* unspecified src rt error */
310 #define SRCRT_SYNTAX		0x91	/* syntax error in src rt field */
311 #define SRCRT_UNKNOWNADDR	0x92	/* unknown addr in src rt field */
312 #define SRCRT_BADPATH		0x93	/* path not acceptable */
313 
314 /* lifetime */
315 #define TTL_EXPTRANSIT		0xa0	/* lifetime expired during transit */
316 #define TTL_EXPREASS		0xa1	/* lifetime expired during reassembly */
317 
318 /* pdu discarded */
319 #define DISC_UNSUPPOPT		0xb0	/* unsupported option not specified? */
320 #define DISC_UNSUPPVERS		0xb1	/* unsupported protocol version */
321 #define DISC_UNSUPPSECURE	0xb2	/* unsupported security option */
322 #define DISC_UNSUPPSRCRT	0xb3	/* unsupported src rt option */
323 #define DISC_UNSUPPRECRT	0xb4	/* unsupported rec rt option */
324 
325 /* reassembly */
326 #define REASS_INTERFERE		0xc0	/* reassembly interference */
327 
328 #ifdef	TROLL
329 
330 #define	TR_DUPEND		0x01	/* duplicate end of fragment */
331 #define TR_DUPPKT		0x02	/* duplicate entire packet */
332 #define	TR_DROPPKT		0x04	/* drop packet on output */
333 #define TR_TRIM			0x08	/* trim bytes from packet */
334 #define TR_CHANGE		0x10	/* change bytes in packet */
335 #define TR_MTU			0x20	/* delta to change device mtu */
336 #define	TR_CHUCK		0x40	/* drop packet in rclnp_input */
337 #define	TR_BLAST		0x80	/* force rclnp_output to blast many packet */
338 #define	TR_RAWLOOP		0x100	/* make if_loop call clnpintr directly */
339 struct troll {
340 	int		tr_ops;				/* operations to perform */
341 	float	tr_dup_size;		/* % to duplicate */
342 	float	tr_dup_freq;		/* frequency to duplicate packets */
343 	float	tr_drop_freq;		/* frequence to drop packets */
344 	int		tr_mtu_adj;			/* delta to adjust if mtu */
345 	int		tr_blast_cnt;		/* # of pkts to blast out */
346 };
347 
348 #define	SN_OUTPUT(clcp, m)\
349 	troll_output(clcp->clc_ifa->ia_ifp, m, clcp->clc_firsthop)
350 
351 #define	SN_MTU(ifp)\
352 	(ifp->if_mtu - trollctl.tr_mtu_adj)
353 
354 #ifdef KERNEL
355 extern float troll_random;
356 #endif
357 
358 #else	/* NO TROLL */
359 
360 #define	SN_OUTPUT(clcp, m)\
361 	(*clcp->clc_ifa->ia_ifp->if_output)(clcp->clc_ifa->ia_ifp, m, clcp->clc_firsthop)
362 
363 #define	SN_MTU(ifp)\
364 	(ifp->if_mtu)
365 
366 #endif	TROLL
367 
368 /*
369  *	Macro to remove an address from a clnp header
370  */
371 #define CLNP_EXTRACT_ADDR(isoa, hoff, hend)\
372 	{\
373 		isoa.isoa_len = (u_char)*hoff;\
374 		if ((((++hoff) + isoa.isoa_len) > hend) ||\
375 			(isoa.isoa_len > 20) || (isoa.isoa_len == 0)) {\
376 			hoff = (caddr_t)0;\
377 		} else {\
378 			(void) bcopy(hoff, (caddr_t)isoa.isoa_genaddr, isoa.isoa_len);\
379 			hoff += isoa.isoa_len;\
380 		}\
381 	}
382 
383 /*
384  *	Macro to insert an address into a clnp header
385  */
386 #define CLNP_INSERT_ADDR(hoff, isoa)\
387 	*hoff++ = (isoa).isoa_len;\
388 	(void) bcopy((caddr_t)((isoa).isoa_genaddr), hoff, (isoa).isoa_len);\
389 	hoff += (isoa).isoa_len;
390 
391 /*
392  *	Clnp hdr cache.	Whenever a clnp packet is sent, a copy of the
393  *	header is made and kept in this cache. In addition to a copy of
394  *	the cached clnp hdr, the cache contains
395  *	information necessary to determine whether the new packet
396  *	to send requires a new header to be built.
397  */
398 struct clnp_cache {
399 	/* these fields are used to check the validity of the cache */
400 	struct iso_addr		clc_dst;		/* destination of packet */
401 	struct mbuf 		*clc_options;	/* ptr to options mbuf */
402 	int					clc_flags;		/* flags passed to clnp_output */
403 
404 	/* these fields are state that clnp_output requires to finish the pkt */
405 	int					clc_segoff;		/* offset of seg part of header */
406 	struct sockaddr		*clc_firsthop;	/* first hop of packet (points into
407 											the route structure) */
408 	struct iso_ifaddr	*clc_ifa;		/* ptr to interface (points into
409 											the route structure) */
410 	struct mbuf 		*clc_hdr;		/* cached pkt hdr (finally)! */
411 };
412 
413 #ifndef	satosiso
414 #define	satosiso(sa)\
415 	((struct sockaddr_iso *)(sa))
416 #endif
417 
418 #ifdef	KERNEL
419 caddr_t			clnp_insert_addr();
420 struct iso_addr	*clnp_srcaddr();
421 struct mbuf		*clnp_reass();
422 #ifdef	TROLL
423 struct troll	trollctl;
424 #endif	TROLL
425 #endif	KERNEL
426