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