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