1685295f4SBill Fenner /* 2685295f4SBill Fenner * Copyright (c) 1982, 1986, 1993 3685295f4SBill Fenner * The Regents of the University of California. All rights reserved. 4685295f4SBill Fenner * 5685295f4SBill Fenner * Redistribution and use in source and binary forms, with or without 6685295f4SBill Fenner * modification, are permitted provided that the following conditions 7685295f4SBill Fenner * are met: 8685295f4SBill Fenner * 1. Redistributions of source code must retain the above copyright 9685295f4SBill Fenner * notice, this list of conditions and the following disclaimer. 10685295f4SBill Fenner * 2. Redistributions in binary form must reproduce the above copyright 11685295f4SBill Fenner * notice, this list of conditions and the following disclaimer in the 12685295f4SBill Fenner * documentation and/or other materials provided with the distribution. 13685295f4SBill Fenner * 3. All advertising materials mentioning features or use of this software 14685295f4SBill Fenner * must display the following acknowledgement: 15685295f4SBill Fenner * This product includes software developed by the University of 16685295f4SBill Fenner * California, Berkeley and its contributors. 17685295f4SBill Fenner * 4. Neither the name of the University nor the names of its contributors 18685295f4SBill Fenner * may be used to endorse or promote products derived from this software 19685295f4SBill Fenner * without specific prior written permission. 20685295f4SBill Fenner * 21685295f4SBill Fenner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22685295f4SBill Fenner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23685295f4SBill Fenner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24685295f4SBill Fenner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25685295f4SBill Fenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26685295f4SBill Fenner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27685295f4SBill Fenner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28685295f4SBill Fenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29685295f4SBill Fenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30685295f4SBill Fenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31685295f4SBill Fenner * SUCH DAMAGE. 32685295f4SBill Fenner * 33685295f4SBill Fenner * @(#)ip.h 8.2 (Berkeley) 6/1/94 34685295f4SBill Fenner */ 35685295f4SBill Fenner 363340d773SGleb Smirnoff #ifndef netdissect_ip_h 373340d773SGleb Smirnoff #define netdissect_ip_h 388bdc5a62SPatrick Kelsey 39685295f4SBill Fenner /* 40685295f4SBill Fenner * Definitions for internet protocol version 4. 41685295f4SBill Fenner * Per RFC 791, September 1981. 42685295f4SBill Fenner */ 43685295f4SBill Fenner #define IPVERSION 4 44685295f4SBill Fenner 45685295f4SBill Fenner /* 46685295f4SBill Fenner * Structure of an internet header, naked of options. 47685295f4SBill Fenner * 48685295f4SBill Fenner * We declare ip_len and ip_off to be short, rather than u_short 49685295f4SBill Fenner * pragmatically since otherwise unsigned comparisons can result 50685295f4SBill Fenner * against negative integers quite easily, and fail in subtle ways. 51685295f4SBill Fenner */ 52685295f4SBill Fenner struct ip { 533340d773SGleb Smirnoff nd_uint8_t ip_vhl; /* header length, version */ 54*ee67461eSJoseph Mingrone #define IP_V(ip) ((GET_U_1((ip)->ip_vhl) & 0xf0) >> 4) 55*ee67461eSJoseph Mingrone #define IP_HL(ip) (GET_U_1((ip)->ip_vhl) & 0x0f) 563340d773SGleb Smirnoff nd_uint8_t ip_tos; /* type of service */ 573340d773SGleb Smirnoff nd_uint16_t ip_len; /* total length */ 583340d773SGleb Smirnoff nd_uint16_t ip_id; /* identification */ 593340d773SGleb Smirnoff nd_uint16_t ip_off; /* fragment offset field */ 60*ee67461eSJoseph Mingrone #define IP_DF 0x4000 /* don't fragment flag */ 61685295f4SBill Fenner #define IP_MF 0x2000 /* more fragments flag */ 62685295f4SBill Fenner #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 633340d773SGleb Smirnoff nd_uint8_t ip_ttl; /* time to live */ 643340d773SGleb Smirnoff nd_uint8_t ip_p; /* protocol */ 653340d773SGleb Smirnoff nd_uint16_t ip_sum; /* checksum */ 663340d773SGleb Smirnoff nd_ipv4 ip_src,ip_dst; /* source and dest address */ 673340d773SGleb Smirnoff }; 68685295f4SBill Fenner 69685295f4SBill Fenner #define IP_MAXPACKET 65535 /* maximum packet size */ 70685295f4SBill Fenner 71685295f4SBill Fenner /* 72685295f4SBill Fenner * Definitions for IP type of service (ip_tos) 73685295f4SBill Fenner */ 74685295f4SBill Fenner #define IPTOS_LOWDELAY 0x10 75685295f4SBill Fenner #define IPTOS_THROUGHPUT 0x08 76685295f4SBill Fenner #define IPTOS_RELIABILITY 0x04 77685295f4SBill Fenner 78685295f4SBill Fenner /* 79685295f4SBill Fenner * Definitions for IP precedence (also in ip_tos) (hopefully unused) 80685295f4SBill Fenner */ 81685295f4SBill Fenner #define IPTOS_PREC_NETCONTROL 0xe0 82685295f4SBill Fenner #define IPTOS_PREC_INTERNETCONTROL 0xc0 83685295f4SBill Fenner #define IPTOS_PREC_CRITIC_ECP 0xa0 84685295f4SBill Fenner #define IPTOS_PREC_FLASHOVERRIDE 0x80 85685295f4SBill Fenner #define IPTOS_PREC_FLASH 0x60 86685295f4SBill Fenner #define IPTOS_PREC_IMMEDIATE 0x40 87685295f4SBill Fenner #define IPTOS_PREC_PRIORITY 0x20 88685295f4SBill Fenner #define IPTOS_PREC_ROUTINE 0x00 89685295f4SBill Fenner 90685295f4SBill Fenner /* 91685295f4SBill Fenner * Definitions for options. 92685295f4SBill Fenner */ 93685295f4SBill Fenner #define IPOPT_COPIED(o) ((o)&0x80) 94685295f4SBill Fenner #define IPOPT_CLASS(o) ((o)&0x60) 95685295f4SBill Fenner #define IPOPT_NUMBER(o) ((o)&0x1f) 96685295f4SBill Fenner 97685295f4SBill Fenner #define IPOPT_CONTROL 0x00 98685295f4SBill Fenner #define IPOPT_RESERVED1 0x20 99685295f4SBill Fenner #define IPOPT_DEBMEAS 0x40 100685295f4SBill Fenner #define IPOPT_RESERVED2 0x60 101685295f4SBill Fenner 102685295f4SBill Fenner #define IPOPT_EOL 0 /* end of option list */ 103685295f4SBill Fenner #define IPOPT_NOP 1 /* no operation */ 104685295f4SBill Fenner 105685295f4SBill Fenner #define IPOPT_RR 7 /* record packet route */ 106685295f4SBill Fenner #define IPOPT_TS 68 /* timestamp */ 107b5bfcb5dSMax Laier #define IPOPT_RFC1393 82 /* traceroute RFC 1393 */ 108685295f4SBill Fenner #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ 109685295f4SBill Fenner #define IPOPT_LSRR 131 /* loose source route */ 110685295f4SBill Fenner #define IPOPT_SSRR 137 /* strict source route */ 1111de50e9fSSam Leffler #define IPOPT_RA 148 /* router-alert, rfc2113 */ 112685295f4SBill Fenner 113685295f4SBill Fenner /* 114685295f4SBill Fenner * Offsets to fields in options other than EOL and NOP. 115685295f4SBill Fenner */ 116685295f4SBill Fenner #define IPOPT_OPTVAL 0 /* option ID */ 117685295f4SBill Fenner #define IPOPT_OLEN 1 /* option length */ 118685295f4SBill Fenner #define IPOPT_OFFSET 2 /* offset within option */ 119685295f4SBill Fenner #define IPOPT_MINOFF 4 /* min value of above */ 120685295f4SBill Fenner 121685295f4SBill Fenner /* 122685295f4SBill Fenner * Time stamp option structure. 123685295f4SBill Fenner */ 124685295f4SBill Fenner struct ip_timestamp { 1253340d773SGleb Smirnoff nd_uint8_t ipt_code; /* IPOPT_TS */ 1263340d773SGleb Smirnoff nd_uint8_t ipt_len; /* size of structure (variable) */ 1273340d773SGleb Smirnoff nd_uint8_t ipt_ptr; /* index of current entry */ 1283340d773SGleb Smirnoff nd_uint8_t ipt_oflwflg; /* flags, overflow counter */ 129685295f4SBill Fenner #define IPTS_OFLW(ip) (((ipt)->ipt_oflwflg & 0xf0) >> 4) 130685295f4SBill Fenner #define IPTS_FLG(ip) ((ipt)->ipt_oflwflg & 0x0f) 131685295f4SBill Fenner union ipt_timestamp { 1323340d773SGleb Smirnoff nd_uint32_t ipt_time[1]; 133685295f4SBill Fenner struct ipt_ta { 1343340d773SGleb Smirnoff nd_ipv4 ipt_addr; 1353340d773SGleb Smirnoff nd_uint32_t ipt_time; 136685295f4SBill Fenner } ipt_ta[1]; 137685295f4SBill Fenner } ipt_timestamp; 1383340d773SGleb Smirnoff }; 139685295f4SBill Fenner 140685295f4SBill Fenner /* flag bits for ipt_flg */ 141685295f4SBill Fenner #define IPOPT_TS_TSONLY 0 /* timestamps only */ 142685295f4SBill Fenner #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ 143685295f4SBill Fenner #define IPOPT_TS_PRESPEC 3 /* specified modules only */ 144685295f4SBill Fenner 145685295f4SBill Fenner /* bits for security (not byte swapped) */ 146685295f4SBill Fenner #define IPOPT_SECUR_UNCLASS 0x0000 147685295f4SBill Fenner #define IPOPT_SECUR_CONFID 0xf135 148685295f4SBill Fenner #define IPOPT_SECUR_EFTO 0x789a 149685295f4SBill Fenner #define IPOPT_SECUR_MMMM 0xbc4d 150685295f4SBill Fenner #define IPOPT_SECUR_RESTR 0xaf13 151685295f4SBill Fenner #define IPOPT_SECUR_SECRET 0xd788 152685295f4SBill Fenner #define IPOPT_SECUR_TOPSECRET 0x6bc5 153685295f4SBill Fenner 154685295f4SBill Fenner /* 155685295f4SBill Fenner * Internet implementation parameters. 156685295f4SBill Fenner */ 157685295f4SBill Fenner #define MAXTTL 255 /* maximum time to live (seconds) */ 158685295f4SBill Fenner #define IPDEFTTL 64 /* default ttl, from RFC 1340 */ 159685295f4SBill Fenner #define IPFRAGTTL 60 /* time to live for frags, slowhz */ 160685295f4SBill Fenner #define IPTTLDEC 1 /* subtracted when forwarding */ 161685295f4SBill Fenner 162685295f4SBill Fenner #define IP_MSS 576 /* default maximum segment size */ 1633340d773SGleb Smirnoff #endif /* netdissect_ip_h */ 164