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