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