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