1 1.2 christos /* $NetBSD: ip.h,v 1.2 2018/04/07 22:37:30 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* NetBSD: ip.h,v 1.9 1995/05/15 01:22:44 cgd Exp */ 4 1.1 christos 5 1.1 christos /* 6 1.1 christos * Copyright (c) 1982, 1986, 1993 7 1.1 christos * The Regents of the University of California. All rights reserved. 8 1.1 christos * 9 1.1 christos * Redistribution and use in source and binary forms, with or without 10 1.1 christos * modification, are permitted provided that the following conditions 11 1.1 christos * are met: 12 1.1 christos * 1. Redistributions of source code must retain the above copyright 13 1.1 christos * notice, this list of conditions and the following disclaimer. 14 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 christos * notice, this list of conditions and the following disclaimer in the 16 1.1 christos * documentation and/or other materials provided with the distribution. 17 1.1 christos * 3. Neither the name of the University nor the names of its contributors 18 1.1 christos * may be used to endorse or promote products derived from this software 19 1.1 christos * without specific prior written permission. 20 1.1 christos * 21 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 1.1 christos * SUCH DAMAGE. 32 1.1 christos * 33 1.1 christos * @(#)ip.h 8.1 (Berkeley) 6/10/93 34 1.1 christos */ 35 1.1 christos 36 1.1 christos /* 37 1.1 christos * Definitions for internet protocol version 4. 38 1.1 christos * Per RFC 791, September 1981. 39 1.1 christos */ 40 1.1 christos #define IPVERSION 4 41 1.1 christos 42 1.1 christos /* 43 1.1 christos * Structure of an internet header, naked of options. 44 1.1 christos * 45 1.1 christos * We declare ip_len and ip_off to be short, rather than u_short 46 1.1 christos * pragmatically since otherwise unsigned comparisons can result 47 1.1 christos * against negative integers quite easily, and fail in subtle ways. 48 1.1 christos */ 49 1.1 christos struct ip { 50 1.1 christos u_int8_t ip_fvhl; /* header length, version */ 51 1.1 christos u_int8_t ip_tos; /* type of service */ 52 1.1 christos int16_t ip_len; /* total length */ 53 1.1 christos u_int16_t ip_id; /* identification */ 54 1.1 christos int16_t ip_off; /* fragment offset field */ 55 1.1 christos #define IP_DF 0x4000 /* dont fragment flag */ 56 1.1 christos #define IP_MF 0x2000 /* more fragments flag */ 57 1.1 christos #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 58 1.1 christos u_int8_t ip_ttl; /* time to live */ 59 1.1 christos u_int8_t ip_p; /* protocol */ 60 1.1 christos u_int16_t ip_sum; /* checksum */ 61 1.1 christos struct in_addr ip_src, ip_dst; /* source and dest address */ 62 1.1 christos }; 63 1.1 christos 64 1.1 christos #define IP_V(iph) ((iph)->ip_fvhl >> 4) 65 1.1 christos #define IP_HL(iph) (((iph)->ip_fvhl & 0x0F) << 2) 66 1.1 christos #define IP_V_SET(iph,x) ((iph)->ip_fvhl = ((iph)->ip_fvhl & 0x0F) | ((x) << 4)) 67 1.1 christos #define IP_HL_SET(iph,x) ((iph)->ip_fvhl = \ 68 1.1 christos ((iph)->ip_fvhl & 0xF0) | (((x) >> 2) & 0x0F)) 69 1.1 christos 70 1.1 christos #define IP_MAXPACKET 65535 /* maximum packet size */ 71 1.1 christos 72 1.1 christos /* 73 1.1 christos * Definitions for IP type of service (ip_tos) 74 1.1 christos */ 75 1.1 christos #define IPTOS_LOWDELAY 0x10 76 1.1 christos #define IPTOS_THROUGHPUT 0x08 77 1.1 christos #define IPTOS_RELIABILITY 0x04 78 1.1 christos /* IPTOS_LOWCOST 0x02 XXX */ 79 1.1 christos 80 1.1 christos /* 81 1.1 christos * Definitions for IP precedence (also in ip_tos) (hopefully unused) 82 1.1 christos */ 83 1.1 christos #define IPTOS_PREC_NETCONTROL 0xe0 84 1.1 christos #define IPTOS_PREC_INTERNETCONTROL 0xc0 85 1.1 christos #define IPTOS_PREC_CRITIC_ECP 0xa0 86 1.1 christos #define IPTOS_PREC_FLASHOVERRIDE 0x80 87 1.1 christos #define IPTOS_PREC_FLASH 0x60 88 1.1 christos #define IPTOS_PREC_IMMEDIATE 0x40 89 1.1 christos #define IPTOS_PREC_PRIORITY 0x20 90 1.1 christos #define IPTOS_PREC_ROUTINE 0x00 91 1.1 christos 92 1.1 christos /* 93 1.1 christos * Definitions for options. 94 1.1 christos */ 95 1.1 christos #define IPOPT_COPIED(o) ((o)&0x80) 96 1.1 christos #define IPOPT_CLASS(o) ((o)&0x60) 97 1.1 christos #define IPOPT_NUMBER(o) ((o)&0x1f) 98 1.1 christos 99 1.1 christos #define IPOPT_CONTROL 0x00 100 1.1 christos #define IPOPT_RESERVED1 0x20 101 1.1 christos #define IPOPT_DEBMEAS 0x40 102 1.1 christos #define IPOPT_RESERVED2 0x60 103 1.1 christos 104 1.1 christos #define IPOPT_EOL 0 /* end of option list */ 105 1.1 christos #define IPOPT_NOP 1 /* no operation */ 106 1.1 christos 107 1.1 christos #define IPOPT_RR 7 /* record packet route */ 108 1.1 christos #define IPOPT_TS 68 /* timestamp */ 109 1.1 christos #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ 110 1.1 christos #define IPOPT_LSRR 131 /* loose source route */ 111 1.1 christos #define IPOPT_SATID 136 /* satnet id */ 112 1.1 christos #define IPOPT_SSRR 137 /* strict source route */ 113 1.1 christos 114 1.1 christos /* 115 1.1 christos * Offsets to fields in options other than EOL and NOP. 116 1.1 christos */ 117 1.1 christos #define IPOPT_OPTVAL 0 /* option ID */ 118 1.1 christos #define IPOPT_OLEN 1 /* option length */ 119 1.1 christos #define IPOPT_OFFSET 2 /* offset within option */ 120 1.1 christos #define IPOPT_MINOFF 4 /* min value of above */ 121 1.1 christos 122 1.1 christos /* 123 1.1 christos * Time stamp option structure. 124 1.1 christos */ 125 1.1 christos struct ip_timestamp { 126 1.1 christos u_int8_t ipt_code; /* IPOPT_TS */ 127 1.1 christos u_int8_t ipt_len; /* size of structure (variable) */ 128 1.1 christos u_int8_t ipt_ptr; /* index of current entry */ 129 1.1 christos u_int8_t ipt_flg_oflw; /* flags, see below, overflow counter */ 130 1.1 christos union ipt_timestamp { 131 1.1 christos u_int32_t ipt_time[1]; 132 1.1 christos struct ipt_ta { 133 1.1 christos struct in_addr ipt_addr; 134 1.1 christos u_int32_t ipt_time; 135 1.1 christos } ipt_ta[1]; 136 1.1 christos } ipt_timestamp; 137 1.1 christos }; 138 1.1 christos 139 1.1 christos /* flag bits for ipt_flg */ 140 1.1 christos #define IPOPT_TS_TSONLY 0 /* timestamps only */ 141 1.1 christos #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ 142 1.1 christos #define IPOPT_TS_PRESPEC 3 /* specified modules only */ 143 1.1 christos 144 1.1 christos /* bits for security (not byte swapped) */ 145 1.1 christos #define IPOPT_SECUR_UNCLASS 0x0000 146 1.1 christos #define IPOPT_SECUR_CONFID 0xf135 147 1.1 christos #define IPOPT_SECUR_EFTO 0x789a 148 1.1 christos #define IPOPT_SECUR_MMMM 0xbc4d 149 1.1 christos #define IPOPT_SECUR_RESTR 0xaf13 150 1.1 christos #define IPOPT_SECUR_SECRET 0xd788 151 1.1 christos #define IPOPT_SECUR_TOPSECRET 0x6bc5 152 1.1 christos 153 1.1 christos /* 154 1.1 christos * Internet implementation parameters. 155 1.1 christos */ 156 1.1 christos #define MAXTTL 255 /* maximum time to live (seconds) */ 157 1.1 christos #define IPDEFTTL 64 /* default ttl, from RFC 1340 */ 158 1.1 christos #define IPFRAGTTL 60 /* time to live for frags, slowhz */ 159 1.1 christos #define IPTTLDEC 1 /* subtracted when forwarding */ 160 1.1 christos 161 1.1 christos #define IP_MSS 576 /* default maximum segment size */ 162