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