00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef _IP_H_
00034 #define _IP_H_
00035
00036 #ifdef WORDS_BIGENDIAN
00037 # ifndef NTOHL
00038 # define NTOHL(d)
00039 # endif
00040 # ifndef NTOHS
00041 # define NTOHS(d)
00042 # endif
00043 # ifndef HTONL
00044 # define HTONL(d)
00045 # endif
00046 # ifndef HTONS
00047 # define HTONS(d)
00048 # endif
00049 #else
00050 # ifndef NTOHL
00051 # define NTOHL(d) ((d) = ntohl((d)))
00052 # endif
00053 # ifndef NTOHS
00054 # define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
00055 # endif
00056 # ifndef HTONL
00057 # define HTONL(d) ((d) = htonl((d)))
00058 # endif
00059 # ifndef HTONS
00060 # define HTONS(d) ((d) = htons((u_int16_t)(d)))
00061 # endif
00062 #endif
00063
00064 typedef u_int32_t n_long;
00065
00066
00067
00068
00069
00070 #define IPVERSION 4
00071
00072
00073
00074
00075 struct ip {
00076 #ifdef WORDS_BIGENDIAN
00077 u_int ip_v:4,
00078 ip_hl:4;
00079 #else
00080 u_int ip_hl:4,
00081 ip_v:4;
00082 #endif
00083 u_int8_t ip_tos;
00084 u_int16_t ip_len;
00085 u_int16_t ip_id;
00086 u_int16_t ip_off;
00087 #define IP_DF 0x4000
00088 #define IP_MF 0x2000
00089 #define IP_OFFMASK 0x1fff
00090 u_int8_t ip_ttl;
00091 u_int8_t ip_p;
00092 u_int16_t ip_sum;
00093 struct in_addr ip_src,ip_dst;
00094 };
00095
00096 #define IP_MAXPACKET 65535
00097
00098
00099
00100
00101 #define IPTOS_LOWDELAY 0x10
00102 #define IPTOS_THROUGHPUT 0x08
00103 #define IPTOS_RELIABILITY 0x04
00104
00105
00106
00107
00108 #define IPOPT_COPIED(o) ((o)&0x80)
00109 #define IPOPT_CLASS(o) ((o)&0x60)
00110 #define IPOPT_NUMBER(o) ((o)&0x1f)
00111
00112 #define IPOPT_CONTROL 0x00
00113 #define IPOPT_RESERVED1 0x20
00114 #define IPOPT_DEBMEAS 0x40
00115 #define IPOPT_RESERVED2 0x60
00116
00117 #define IPOPT_EOL 0
00118 #define IPOPT_NOP 1
00119
00120 #define IPOPT_RR 7
00121 #define IPOPT_TS 68
00122 #define IPOPT_SECURITY 130
00123 #define IPOPT_LSRR 131
00124 #define IPOPT_SATID 136
00125 #define IPOPT_SSRR 137
00126
00127
00128
00129
00130 #define IPOPT_OPTVAL 0
00131 #define IPOPT_OLEN 1
00132 #define IPOPT_OFFSET 2
00133 #define IPOPT_MINOFF 4
00134
00135
00136
00137
00138 struct ip_timestamp {
00139 u_int8_t ipt_code;
00140 u_int8_t ipt_len;
00141 u_int8_t ipt_ptr;
00142 #ifdef WORDS_BIGENDIAN
00143 u_int ipt_oflw:4,
00144 ipt_flg:4;
00145 #else
00146 u_int ipt_flg:4,
00147 ipt_oflw:4;
00148 #endif
00149 union ipt_timestamp {
00150 n_long ipt_time[1];
00151 struct ipt_ta {
00152 struct in_addr ipt_addr;
00153 n_long ipt_time;
00154 } ipt_ta[1];
00155 } ipt_timestamp;
00156 };
00157
00158
00159 #define IPOPT_TS_TSONLY 0
00160 #define IPOPT_TS_TSANDADDR 1
00161 #define IPOPT_TS_PRESPEC 3
00162
00163
00164 #define IPOPT_SECUR_UNCLASS 0x0000
00165 #define IPOPT_SECUR_CONFID 0xf135
00166 #define IPOPT_SECUR_EFTO 0x789a
00167 #define IPOPT_SECUR_MMMM 0xbc4d
00168 #define IPOPT_SECUR_RESTR 0xaf13
00169 #define IPOPT_SECUR_SECRET 0xd788
00170 #define IPOPT_SECUR_TOPSECRET 0x6bc5
00171
00172
00173
00174
00175 #define MAXTTL 255
00176 #define IPDEFTTL 64
00177 #define IPFRAGTTL 60
00178 #define IPTTLDEC 1
00179
00180 #define IP_MSS 576
00181
00182 #if SIZEOF_CHAR_P == 4
00183 struct mbuf_ptr {
00184 struct mbuf *mptr;
00185 uint32_t dummy;
00186 };
00187 #else
00188 struct mbuf_ptr {
00189 struct mbuf *mptr;
00190 };
00191 #endif
00192 struct qlink {
00193 void *next, *prev;
00194 };
00195
00196
00197
00198
00199 struct ipovly {
00200 struct mbuf_ptr ih_mbuf;
00201 u_int8_t ih_x1;
00202 u_int8_t ih_pr;
00203 u_int16_t ih_len;
00204 struct in_addr ih_src;
00205 struct in_addr ih_dst;
00206 } __attribute__((packed));
00207
00208
00209
00210
00211
00212
00213
00214
00215 struct ipq {
00216 struct qlink frag_link;
00217 struct qlink ip_link;
00218 u_int8_t ipq_ttl;
00219 u_int8_t ipq_p;
00220 u_int16_t ipq_id;
00221 struct in_addr ipq_src,ipq_dst;
00222 };
00223
00224
00225
00226
00227
00228
00229 struct ipasfrag {
00230 struct qlink ipf_link;
00231 struct ip ipf_ip;
00232 };
00233
00234 #define ipf_off ipf_ip.ip_off
00235 #define ipf_tos ipf_ip.ip_tos
00236 #define ipf_len ipf_ip.ip_len
00237 #define ipf_next ipf_link.next
00238 #define ipf_prev ipf_link.prev
00239
00240
00241
00242
00243
00244
00245
00246 #define MAX_IPOPTLEN 40
00247
00248 struct ipoption {
00249 struct in_addr ipopt_dst;
00250 int8_t ipopt_list[MAX_IPOPTLEN];
00251 };
00252
00253 #ifdef LOG_ENABLED
00254
00255
00256
00257
00258
00259 struct ipstat {
00260 u_long ips_total;
00261 u_long ips_badsum;
00262 u_long ips_tooshort;
00263 u_long ips_toosmall;
00264 u_long ips_badhlen;
00265 u_long ips_badlen;
00266 u_long ips_fragments;
00267 u_long ips_fragdropped;
00268 u_long ips_fragtimeout;
00269 u_long ips_forward;
00270 u_long ips_cantforward;
00271 u_long ips_redirectsent;
00272 u_long ips_noproto;
00273 u_long ips_delivered;
00274 u_long ips_localout;
00275 u_long ips_odropped;
00276 u_long ips_reassembled;
00277 u_long ips_fragmented;
00278 u_long ips_ofragments;
00279 u_long ips_cantfrag;
00280 u_long ips_badoptions;
00281 u_long ips_noroute;
00282 u_long ips_badvers;
00283 u_long ips_rawout;
00284 u_long ips_unaligned;
00285 };
00286
00287 extern struct ipstat ipstat;
00288 #endif
00289
00290 extern struct ipq ipq;
00291 extern u_int16_t ip_id;
00292
00293 #endif