1 /* $NetBSD: clnp.h,v 1.26 2008/08/06 15:01:23 plunky Exp $ */
4 * Copyright (c) 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)clnp.h 8.2 (Berkeley) 4/16/94
34 /***********************************************************
35 Copyright IBM Corporation 1987
39 Permission to use, copy, modify, and distribute this software and its
40 documentation for any purpose and without fee is hereby granted,
41 provided that the above copyright notice appear in all copies and that
42 both that copyright notice and this permission notice appear in
43 supporting documentation, and that the name of IBM not be
44 used in advertising or publicity pertaining to distribution of the
45 software without specific, written prior permission.
47 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
48 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
49 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
50 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
51 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
52 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 ******************************************************************/
57 #ifndef _NETISO_CLNP_H_
58 #define _NETISO_CLNP_H_
60 #include <net/route.h>
63 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
66 /* should be config option but cpp breaks with too many #defines */
70 * Return true if the mbuf is a cluster mbuf
72 #define IS_CLUSTER(m) ((m)->m_flags & M_EXT)
75 * Move the halfword into the two characters
77 #define HTOC(msb, lsb, hword)\
78 (msb) = (u_char)((hword) >> 8);\
79 (lsb) = (u_char)((hword) & 0xff)
81 * Move the two charcters into the halfword
83 #define CTOH(msb, lsb, hword)\
84 (hword) = ((msb) << 8) | (lsb)
87 * Return true if the checksum has been set - ie. the checksum is
90 #define CKSUM_REQUIRED(clnp)\
91 (((clnp)->cnf_cksum_msb != 0) || ((clnp)->cnf_cksum_lsb != 0))
94 * Fixed part of clnp header
97 u_char cnf_proto_id
; /* network layer protocol identifier */
98 u_char cnf_hdr_len
; /* length indicator (octets) */
99 u_char cnf_vers
; /* version/protocol identifier
101 u_char cnf_ttl
;/* lifetime (500 milliseconds) */
102 u_char cnf_type
; /* type code */
103 /* Includes err_ok, more_segs, and seg_ok */
104 u_char cnf_seglen_msb
; /* pdu segment length (octets) high
106 u_char cnf_seglen_lsb
; /* pdu segment length (octets) low
108 u_char cnf_cksum_msb
; /* checksum high byte */
109 u_char cnf_cksum_lsb
; /* checksum low byte */
111 #define CNF_TYPE 0x1f
112 #define CNF_ERR_OK 0x20
113 #define CNF_MORE_SEGS 0x40
114 #define CNF_SEG_OK 0x80
116 #define CLNP_CKSUM_OFF 0x07 /* offset of checksum */
118 #define clnl_fixed clnp_fixed
121 * Segmentation part of clnp header
123 struct clnp_segment
{
124 u_short cng_id
; /* data unit identifier */
125 u_short cng_off
;/* segment offset */
126 u_short cng_tot_len
; /* total length */
130 * Clnp fragment reassembly structures:
132 * All packets undergoing reassembly are linked together in
133 * clnp_fragl structures. Each clnp_fragl structure contains a
134 * pointer to the original clnp packet header, as well as a
135 * list of packet fragments. Each packet fragment
136 * is headed by a clnp_frag structure. This structure contains the
137 * offset of the first and last byte of the fragment, as well as
138 * a pointer to the data (an mbuf chain) of the fragment.
143 * The clnp_frag structure is stored in an mbuf immedately
144 * preceding the fragment data. Since there are words in
145 * this struct, it must be word aligned.
148 * All the fragment code assumes that the entire clnp header is
149 * contained in the first mbuf.
152 u_int cfr_first
; /* offset of first byte of this frag */
153 u_int cfr_last
; /* offset of last byte of this frag */
154 u_int cfr_bytes
; /* bytes to shave to get to data */
155 struct mbuf
*cfr_data
; /* ptr to data for this frag */
156 struct clnp_frag
*cfr_next
; /* next fragment in list */
160 struct iso_addr cfl_src
;/* source of the pkt */
161 struct iso_addr cfl_dst
;/* destination of the pkt */
162 u_short cfl_id
; /* id of the pkt */
163 u_char cfl_ttl
;/* current ttl of pkt */
164 u_short cfl_last
; /* offset of last byte of packet */
165 struct mbuf
*cfl_orighdr
; /* ptr to original header */
166 struct clnp_frag
*cfl_frags
; /* linked list of fragments for pkt */
167 struct clnp_fragl
*cfl_next
; /* next pkt being reassembled */
171 * The following structure is used to index into an options section
172 * of a clnp datagram. These values can be used without worry that
173 * offset or length fields are invalid or too big, etc. That is,
174 * the consistancy of the options will be guaranteed before this
175 * structure is filled in. Any pointer (field ending in p) is
176 * actually the offset from the beginning of the mbuf the option
177 * is contained in. A value of NULL for any pointer
178 * means that the option is not present. The length any option
179 * does not include the option code or option length fields.
182 u_short cni_securep
; /* ptr to start of security option */
183 char cni_secure_len
; /* length of entire security option */
185 u_short cni_srcrt_s
; /* offset of start of src rt option */
186 u_short cni_srcrt_len
; /* length of entire src rt option */
188 u_short cni_recrtp
; /* ptr to beginning of recrt option */
189 char cni_recrt_len
; /* length of entire recrt option */
191 char cni_priorp
; /* ptr to priority option */
193 u_short cni_qos_formatp
; /* ptr to format of qos
195 char cni_qos_len
; /* length of entire qos option */
197 u_char cni_er_reason
; /* reason from ER pdu option */
201 u_short cni_esct
; /* value from ISH ESCT option */
203 u_short cni_netmaskp
; /* ptr to beginning of netmask option */
204 char cni_netmask_len
; /* length of entire netmask
207 u_short cni_snpamaskp
; /* ptr to start of snpamask option */
208 char cni_snpamask_len
; /* length of entire snpamask
213 #define ER_INVALREAS 0xff /* code for invalid ER pdu discard reason */
215 /* given an mbuf and addr of option, return offset from data of mbuf */
216 #define CLNP_OPTTOOFF(m, opt) ((u_short) (opt - mtod(m, char *)))
218 /* given an mbuf and offset of option, return address of option */
219 #define CLNP_OFFTOOPT(m, off) ((char *) (mtod(m, char *) + off))
221 /* return true iff src route is valid */
222 #define CLNPSRCRT_VALID(oidx) ((oidx) && (oidx->cni_srcrt_s))
224 /* return the offset field of the src rt */
225 #define CLNPSRCRT_OFF(oidx, options)\
226 (*((u_char *)(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s) + 1)))
228 /* return the type field of the src rt */
229 #define CLNPSRCRT_TYPE(oidx, options)\
230 ((u_char)(*(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s))))
232 /* return the length of the current address */
233 #define CLNPSRCRT_CLEN(oidx, options)\
234 ((u_char)(*(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s) + CLNPSRCRT_OFF(oidx, options) - 1)))
236 /* return the address of the current address */
237 #define CLNPSRCRT_CADDR(oidx, options)\
238 ((void *)(CLNP_OFFTOOPT(options, oidx->cni_srcrt_s) + CLNPSRCRT_OFF(oidx, options)))
241 * return true if the src route has run out of routes this is true if the
242 * offset of next route is greater than the end of the rt
244 #define CLNPSRCRT_TERM(oidx, options)\
245 (CLNPSRCRT_OFF(oidx, options) > oidx->cni_srcrt_len)
248 * Options a user can set/get
250 #define CLNPOPT_FLAGS 0x01 /* flags: seg permitted, no er xmit, etc */
251 #define CLNPOPT_OPTS 0x02 /* datagram options */
254 * Values for particular datagram options
256 #define CLNPOVAL_PAD 0xcc /* padding */
257 #define CLNPOVAL_SECURE 0xc5 /* security */
258 #define CLNPOVAL_SRCRT 0xc8 /* source routing */
259 #define CLNPOVAL_RECRT 0xcb /* record route */
260 #define CLNPOVAL_QOS 0xc3 /* quality of service */
261 #define CLNPOVAL_PRIOR 0xcd /* priority */
262 #define CLNPOVAL_ERREAS 0xc1 /* ER PDU ONLY: reason for discard */
264 #define CLNPOVAL_SRCSPEC 0x40 /* source address specific */
265 #define CLNPOVAL_DSTSPEC 0x80 /* destination address specific */
266 #define CLNPOVAL_GLOBAL 0xc0 /* globally unique */
268 /* Globally Unique QOS */
269 #define CLNPOVAL_SEQUENCING 0x10 /* sequencing preferred */
270 #define CLNPOVAL_CONGESTED 0x08 /* congestion experienced */
271 #define CLNPOVAL_LOWDELAY 0x04 /* low transit delay */
273 #define CLNPOVAL_PARTRT 0x00 /* partial source routing */
274 #define CLNPOVAL_COMPRT 0x01 /* complete source routing */
277 * Clnp flags used in a control block flags field.
278 * NOTE: these must be out of the range of bits defined in ../net/raw_cb.h
280 #define CLNP_NO_SEG 0x010 /* segmentation not permitted */
281 #define CLNP_NO_ER 0x020 /* do not generate ERs */
282 #define CLNP_SEND_RAW 0x080 /* send pkt as RAW DT not TP DT */
283 #define CLNP_NO_CKSUM 0x100 /* don't use clnp checksum */
284 #define CLNP_ECHO 0x200 /* send echo request */
285 #define CLNP_NOCACHE 0x400 /* don't store cache information */
286 #define CLNP_ECHOR 0x800 /* send echo reply */
288 /* valid clnp flags */
289 #define CLNP_VFLAGS \
290 (CLNP_SEND_RAW|CLNP_NO_SEG|CLNP_NO_ER|CLNP_NO_CKSUM|\
291 CLNP_ECHO|CLNP_NOCACHE|CLNP_ECHOR)
294 * Constants used by clnp
296 #define CLNP_HDR_MIN (sizeof (struct clnp_fixed))
297 #define CLNP_HDR_MAX (254)
298 #define CLNP_TTL_UNITS 2 /* 500 milliseconds */
299 #define CLNP_TTL 15*CLNP_TTL_UNITS /* time to live (seconds) */
300 #define ISO8473_V1 0x01
304 * In order to test raw clnp and tp/clnp simultaneously, a third type of
305 * packet has been defined: CLNP_RAW. This is done so that the input
306 * routine can switch to the correct input routine (rclnp_input or
307 * tpclnp_input) based on the type field. If clnp had a higher level
308 * protocol field, this would not be necessary.
310 #define CLNP_DT 0x1C /* normal data */
311 #define CLNP_ER 0x01 /* error report */
312 #define CLNP_RAW 0x1D /* debug only */
313 #define CLNP_EC 0x1E /* echo packet */
314 #define CLNP_ECR 0x1F /* echo reply */
319 #define GEN_NOREAS 0x00 /* reason not specified */
320 #define GEN_PROTOERR 0x01 /* protocol procedure error */
321 #define GEN_BADCSUM 0x02 /* incorrect checksum */
322 #define GEN_CONGEST 0x03 /* pdu discarded due to congestion */
323 #define GEN_HDRSYNTAX 0x04 /* header syntax error */
324 #define GEN_SEGNEEDED 0x05 /* need segmentation but not allowed */
325 #define GEN_INCOMPLETE 0x06 /* incomplete pdu received */
326 #define GEN_DUPOPT 0x07 /* duplicate option */
329 #define ADDR_DESTUNREACH 0x80 /* destination address unreachable */
330 #define ADDR_DESTUNKNOWN 0x81 /* destination address unknown */
333 #define SRCRT_UNSPECERR 0x90 /* unspecified src rt error */
334 #define SRCRT_SYNTAX 0x91 /* syntax error in src rt field */
335 #define SRCRT_UNKNOWNADDR 0x92 /* unknown addr in src rt field */
336 #define SRCRT_BADPATH 0x93 /* path not acceptable */
339 #define TTL_EXPTRANSIT 0xa0 /* lifetime expired during transit */
340 #define TTL_EXPREASS 0xa1 /* lifetime expired during reassembly */
343 #define DISC_UNSUPPOPT 0xb0 /* unsupported option not specified? */
344 #define DISC_UNSUPPVERS 0xb1 /* unsupported protocol version */
345 #define DISC_UNSUPPSECURE 0xb2 /* unsupported security option */
346 #define DISC_UNSUPPSRCRT 0xb3 /* unsupported src rt option */
347 #define DISC_UNSUPPRECRT 0xb4 /* unsupported rec rt option */
350 #define REASS_INTERFERE 0xc0 /* reassembly interference */
351 #define CLNP_ERRORS 22
355 u_char clnp_er_codes
[CLNP_ERRORS
] = {
356 GEN_NOREAS
, GEN_PROTOERR
, GEN_BADCSUM
, GEN_CONGEST
,
357 GEN_HDRSYNTAX
, GEN_SEGNEEDED
, GEN_INCOMPLETE
, GEN_DUPOPT
,
358 ADDR_DESTUNREACH
, ADDR_DESTUNKNOWN
,
359 SRCRT_UNSPECERR
, SRCRT_SYNTAX
, SRCRT_UNKNOWNADDR
, SRCRT_BADPATH
,
360 TTL_EXPTRANSIT
, TTL_EXPREASS
,
361 DISC_UNSUPPOPT
, DISC_UNSUPPVERS
, DISC_UNSUPPSECURE
,
362 DISC_UNSUPPSRCRT
, DISC_UNSUPPRECRT
, REASS_INTERFERE
368 #define TR_DUPEND 0x01 /* duplicate end of fragment */
369 #define TR_DUPPKT 0x02 /* duplicate entire packet */
370 #define TR_DROPPKT 0x04 /* drop packet on output */
371 #define TR_TRIM 0x08 /* trim bytes from packet */
372 #define TR_CHANGE 0x10 /* change bytes in packet */
373 #define TR_MTU 0x20 /* delta to change device mtu */
374 #define TR_CHUCK 0x40 /* drop packet in rclnp_input */
375 #define TR_BLAST 0x80 /* force rclnp_output to blast many
377 #define TR_RAWLOOP 0x100 /* make if_loop call clnpintr
380 int tr_ops
; /* operations to perform */
381 float tr_dup_size
; /* % to duplicate */
382 float tr_dup_freq
; /* frequency to duplicate packets */
383 float tr_drop_freq
; /* frequence to drop packets */
384 int tr_mtu_adj
; /* delta to adjust if mtu */
385 int tr_blast_cnt
; /* # of pkts to blast out */
388 #define SN_OUTPUT(clcp, m)\
389 troll_output(clcp->clc_ifp, m, clcp->clc_firsthop, clcp->clc_rt)
391 #define SN_MTU(ifp, rt) (((rt && rt->rt_rmx.rmx_mtu) ?\
392 rt->rt_rmx.rmx_mtu : clnp_badmtu(ifp, rt, __LINE__, __FILE__))\
393 - trollctl.tr_mtu_adj)
396 extern float troll_random
;
401 #define SN_OUTPUT(clcp, m)\
402 (*clcp->clc_ifp->if_output)(clcp->clc_ifp, m, clcp->clc_firsthop, \
405 #define SN_MTU(ifp, rt) (((rt && rt->rt_rmx.rmx_mtu) ?\
406 rt->rt_rmx.rmx_mtu : clnp_badmtu(ifp, rt, __LINE__, __FILE__)))
411 * Macro to remove an address from a clnp header
413 #define CLNP_EXTRACT_ADDR(isoa, hoff, hend)\
415 isoa.isoa_len = (u_char)*hoff;\
416 if ((((++hoff) + isoa.isoa_len) > hend) ||\
417 (isoa.isoa_len > 20) || (isoa.isoa_len == 0)) {\
420 (void)memcpy(isoa.isoa_genaddr, hoff, \
422 hoff += isoa.isoa_len;\
427 * Macro to insert an address into a clnp header
429 #define CLNP_INSERT_ADDR(hoff, isoa)\
430 *hoff++ = (isoa).isoa_len;\
431 (void) memcpy( hoff, (void *)((isoa).isoa_genaddr), (isoa).isoa_len);\
432 hoff += (isoa).isoa_len;
435 * Clnp hdr cache. Whenever a clnp packet is sent, a copy of the
436 * header is made and kept in this cache. In addition to a copy of
437 * the cached clnp hdr, the cache contains
438 * information necessary to determine whether the new packet
439 * to send requires a new header to be built.
442 /* these fields are used to check the validity of the cache */
443 struct iso_addr clc_dst
;/* destination of packet */
444 struct mbuf
*clc_options
; /* ptr to options mbuf */
445 int clc_flags
; /* flags passed to clnp_output */
447 /* these fields are state that clnp_output requires to finish the pkt */
448 int clc_segoff
; /* offset of seg part of header */
449 struct rtentry
*clc_rt
; /* ptr to rtentry (points into the route
451 const struct sockaddr
*clc_firsthop
; /* first hop of packet */
452 struct ifnet
*clc_ifp
;/* ptr to interface structure */
454 *clc_ifa
;/* ptr to interface address */
455 struct mbuf
*clc_hdr
;/* cached pkt hdr (finally)! */
472 char *clnp_hexp (const char *, int, char *);
473 char *clnp_iso_addrp(const struct iso_addr
*);
474 char *clnp_saddr_isop(const struct sockaddr_iso
*);
477 void clnp_er_input (struct mbuf
*, struct iso_addr
*, u_int
);
478 void clnp_discard (struct mbuf
*, u_int
);
479 void clnp_emit_er (struct mbuf
*, u_int
);
480 int clnp_er_index (u_int
);
482 int clnp_fragment (struct ifnet
*, struct mbuf
*, const struct sockaddr
*,
483 int, int, int, struct rtentry
*);
484 struct mbuf
*clnp_reass (struct mbuf
*, struct iso_addr
*,
485 struct iso_addr
*, struct clnp_segment
*);
486 int clnp_newpkt (struct mbuf
*, struct iso_addr
*, struct iso_addr
*,
487 struct clnp_segment
*);
488 void clnp_insert_frag (struct clnp_fragl
*, struct mbuf
*,
489 struct clnp_segment
*);
490 struct mbuf
*clnp_comp_pdu (struct clnp_fragl
*);
492 float troll_random (void);
493 int troll_output (struct ifnet
*, struct mbuf
*, struct sockaddr
*,
498 void clnp_init (void);
499 void clnlintr (void);
500 void clnp_input (struct mbuf
*, ...);
503 void clnp_update_srcrt (struct mbuf
*, struct clnp_optidx
*);
504 void clnp_dooptions (struct mbuf
*, struct clnp_optidx
*, struct ifnet
*,
506 int clnp_set_opts (struct mbuf
**, struct mbuf
**);
507 int clnp_opt_sanity (struct mbuf
*, void *, int, struct clnp_optidx
*);
510 int clnp_output (struct mbuf
*, ...);
511 void clnp_ctloutput (void);
514 void rclnp_input (struct mbuf
*, ...);
515 int rclnp_output (struct mbuf
*, ...);
516 int rclnp_ctloutput (int, struct socket
*, struct sockopt
*);
517 int clnp_usrreq (struct socket
*, int, struct mbuf
*, struct mbuf
*,
518 struct mbuf
*, struct lwp
*);
521 struct mbuf
*clnp_data_ck (struct mbuf
*, int);
522 void *clnp_extract_addr (void *, int, struct iso_addr
*,
524 int clnp_ours (struct iso_addr
*);
525 void clnp_forward (struct mbuf
*, int, struct iso_addr
*,
526 struct clnp_optidx
*, int, struct snpa_hdr
*);
527 void *clnp_insert_addr (void *, struct iso_addr
*, struct iso_addr
*);
528 int clnp_route (struct iso_addr
*, struct route
*, int,
529 const struct sockaddr
**, struct iso_ifaddr
**);
530 int clnp_srcroute (struct mbuf
*, struct clnp_optidx
*, struct route
*,
531 const struct sockaddr
**, struct iso_ifaddr
**,
533 int clnp_echoreply (struct mbuf
*, int, struct sockaddr_iso
*,
534 struct sockaddr_iso
*, struct clnp_optidx
*);
535 int clnp_badmtu (struct ifnet
*, struct rtentry
*, int, const char *);
536 void clnp_ypocb (void *, void *, u_int
);
539 struct clnp_fragl
*clnp_freefrags (struct clnp_fragl
*);
540 void clnp_slowtimo (void);
541 void clnp_drain (void);
544 struct troll trollctl
;
549 #endif /* !_NETISO_CLNP_H_ */