]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * INET An implementation of the TCP/IP protocol suite for the LINUX | |
3 | * operating system. INET is implemented using the BSD Socket | |
4 | * interface as the means of communication with the user level. | |
5 | * | |
6 | * Definitions for the IP protocol. | |
7 | * | |
8 | * Version: @(#)ip.h 1.0.2 04/28/93 | |
9 | * | |
10 | * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU General Public License | |
14 | * as published by the Free Software Foundation; either version | |
15 | * 2 of the License, or (at your option) any later version. | |
16 | */ | |
17 | #ifndef _LINUX_IP_H | |
18 | #define _LINUX_IP_H | |
19 | #include <asm/byteorder.h> | |
20 | ||
21 | #define IPTOS_TOS_MASK 0x1E | |
22 | #define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK) | |
23 | #define IPTOS_LOWDELAY 0x10 | |
24 | #define IPTOS_THROUGHPUT 0x08 | |
25 | #define IPTOS_RELIABILITY 0x04 | |
26 | #define IPTOS_MINCOST 0x02 | |
27 | ||
28 | #define IPTOS_PREC_MASK 0xE0 | |
29 | #define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK) | |
30 | #define IPTOS_PREC_NETCONTROL 0xe0 | |
31 | #define IPTOS_PREC_INTERNETCONTROL 0xc0 | |
32 | #define IPTOS_PREC_CRITIC_ECP 0xa0 | |
33 | #define IPTOS_PREC_FLASHOVERRIDE 0x80 | |
34 | #define IPTOS_PREC_FLASH 0x60 | |
35 | #define IPTOS_PREC_IMMEDIATE 0x40 | |
36 | #define IPTOS_PREC_PRIORITY 0x20 | |
37 | #define IPTOS_PREC_ROUTINE 0x00 | |
38 | ||
39 | ||
40 | /* IP options */ | |
41 | #define IPOPT_COPY 0x80 | |
42 | #define IPOPT_CLASS_MASK 0x60 | |
43 | #define IPOPT_NUMBER_MASK 0x1f | |
44 | ||
45 | #define IPOPT_COPIED(o) ((o)&IPOPT_COPY) | |
46 | #define IPOPT_CLASS(o) ((o)&IPOPT_CLASS_MASK) | |
47 | #define IPOPT_NUMBER(o) ((o)&IPOPT_NUMBER_MASK) | |
48 | ||
49 | #define IPOPT_CONTROL 0x00 | |
50 | #define IPOPT_RESERVED1 0x20 | |
51 | #define IPOPT_MEASUREMENT 0x40 | |
52 | #define IPOPT_RESERVED2 0x60 | |
53 | ||
54 | #define IPOPT_END (0 |IPOPT_CONTROL) | |
55 | #define IPOPT_NOOP (1 |IPOPT_CONTROL) | |
56 | #define IPOPT_SEC (2 |IPOPT_CONTROL|IPOPT_COPY) | |
57 | #define IPOPT_LSRR (3 |IPOPT_CONTROL|IPOPT_COPY) | |
58 | #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT) | |
59 | #define IPOPT_RR (7 |IPOPT_CONTROL) | |
60 | #define IPOPT_SID (8 |IPOPT_CONTROL|IPOPT_COPY) | |
61 | #define IPOPT_SSRR (9 |IPOPT_CONTROL|IPOPT_COPY) | |
62 | #define IPOPT_RA (20|IPOPT_CONTROL|IPOPT_COPY) | |
63 | ||
64 | #define IPVERSION 4 | |
65 | #define MAXTTL 255 | |
66 | #define IPDEFTTL 64 | |
67 | ||
68 | #define IPOPT_OPTVAL 0 | |
69 | #define IPOPT_OLEN 1 | |
70 | #define IPOPT_OFFSET 2 | |
71 | #define IPOPT_MINOFF 4 | |
72 | #define MAX_IPOPTLEN 40 | |
73 | #define IPOPT_NOP IPOPT_NOOP | |
74 | #define IPOPT_EOL IPOPT_END | |
75 | #define IPOPT_TS IPOPT_TIMESTAMP | |
76 | ||
77 | #define IPOPT_TS_TSONLY 0 /* timestamps only */ | |
78 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ | |
79 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ | |
80 | ||
81 | #ifdef __KERNEL__ | |
82 | #include <linux/config.h> | |
83 | #include <linux/types.h> | |
2e6599cb | 84 | #include <net/request_sock.h> |
1da177e4 LT |
85 | #include <net/sock.h> |
86 | #include <linux/igmp.h> | |
87 | #include <net/flow.h> | |
88 | ||
89 | struct ip_options { | |
90 | __u32 faddr; /* Saved first hop address */ | |
91 | unsigned char optlen; | |
92 | unsigned char srr; | |
93 | unsigned char rr; | |
94 | unsigned char ts; | |
95 | unsigned char is_setbyuser:1, /* Set by setsockopt? */ | |
96 | is_data:1, /* Options in __data, rather than skb */ | |
97 | is_strictroute:1, /* Strict source route */ | |
98 | srr_is_hit:1, /* Packet destination addr was our one */ | |
99 | is_changed:1, /* IP checksum more not valid */ | |
100 | rr_needaddr:1, /* Need to record addr of outgoing dev */ | |
101 | ts_needtime:1, /* Need to record timestamp */ | |
102 | ts_needaddr:1; /* Need to record addr of outgoing dev */ | |
103 | unsigned char router_alert; | |
104 | unsigned char __pad1; | |
105 | unsigned char __pad2; | |
106 | unsigned char __data[0]; | |
107 | }; | |
108 | ||
109 | #define optlength(opt) (sizeof(struct ip_options) + opt->optlen) | |
110 | ||
2e6599cb | 111 | struct inet_request_sock { |
60236fdd | 112 | struct request_sock req; |
ca304b61 ACM |
113 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
114 | u16 inet6_rsk_offset; | |
115 | /* 2 bytes hole, try to pack */ | |
116 | #endif | |
2e6599cb ACM |
117 | u32 loc_addr; |
118 | u32 rmt_addr; | |
119 | u16 rmt_port; | |
120 | u16 snd_wscale : 4, | |
121 | rcv_wscale : 4, | |
122 | tstamp_ok : 1, | |
123 | sack_ok : 1, | |
124 | wscale_ok : 1, | |
125 | ecn_ok : 1, | |
126 | acked : 1; | |
127 | struct ip_options *opt; | |
128 | }; | |
129 | ||
60236fdd | 130 | static inline struct inet_request_sock *inet_rsk(const struct request_sock *sk) |
2e6599cb ACM |
131 | { |
132 | return (struct inet_request_sock *)sk; | |
133 | } | |
134 | ||
1da177e4 LT |
135 | struct ipv6_pinfo; |
136 | ||
137 | struct inet_sock { | |
138 | /* sk and pinet6 has to be the first two members of inet_sock */ | |
139 | struct sock sk; | |
140 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | |
141 | struct ipv6_pinfo *pinet6; | |
142 | #endif | |
143 | /* Socket demultiplex comparisons on incoming packets. */ | |
144 | __u32 daddr; /* Foreign IPv4 addr */ | |
145 | __u32 rcv_saddr; /* Bound local IPv4 addr */ | |
146 | __u16 dport; /* Destination port */ | |
147 | __u16 num; /* Local port */ | |
148 | __u32 saddr; /* Sending source */ | |
149 | __s16 uc_ttl; /* Unicast TTL */ | |
150 | __u16 cmsg_flags; | |
151 | struct ip_options *opt; | |
152 | __u16 sport; /* Source port */ | |
153 | __u16 id; /* ID counter for DF pkts */ | |
154 | __u8 tos; /* TOS */ | |
155 | __u8 mc_ttl; /* Multicasting TTL */ | |
156 | __u8 pmtudisc; | |
157 | unsigned recverr : 1, | |
d83d8461 | 158 | is_icsk : 1, /* inet_connection_sock? */ |
1da177e4 LT |
159 | freebind : 1, |
160 | hdrincl : 1, | |
161 | mc_loop : 1; | |
162 | int mc_index; /* Multicast device index */ | |
163 | __u32 mc_addr; | |
164 | struct ip_mc_socklist *mc_list; /* Group array */ | |
165 | /* | |
166 | * Following members are used to retain the infomation to build | |
167 | * an ip header on each ip fragmentation while the socket is corked. | |
168 | */ | |
169 | struct { | |
170 | unsigned int flags; | |
171 | unsigned int fragsize; | |
172 | struct ip_options *opt; | |
173 | struct rtable *rt; | |
174 | int length; /* Total length of all frames */ | |
175 | u32 addr; | |
176 | struct flowi fl; | |
177 | } cork; | |
178 | }; | |
179 | ||
180 | #define IPCORK_OPT 1 /* ip-options has been held in ipcork.opt */ | |
181 | #define IPCORK_ALLFRAG 2 /* always fragment (for ipv6 for now) */ | |
182 | ||
183 | static inline struct inet_sock *inet_sk(const struct sock *sk) | |
184 | { | |
185 | return (struct inet_sock *)sk; | |
186 | } | |
187 | ||
188 | static inline void __inet_sk_copy_descendant(struct sock *sk_to, | |
189 | const struct sock *sk_from, | |
190 | const int ancestor_size) | |
191 | { | |
192 | memcpy(inet_sk(sk_to) + 1, inet_sk(sk_from) + 1, | |
193 | sk_from->sk_prot->obj_size - ancestor_size); | |
194 | } | |
195 | #if !(defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)) | |
196 | static inline void inet_sk_copy_descendant(struct sock *sk_to, | |
197 | const struct sock *sk_from) | |
198 | { | |
199 | __inet_sk_copy_descendant(sk_to, sk_from, sizeof(struct inet_sock)); | |
200 | } | |
201 | #endif | |
202 | #endif | |
203 | ||
32519f11 ACM |
204 | extern int inet_sk_rebuild_header(struct sock *sk); |
205 | ||
1da177e4 LT |
206 | struct iphdr { |
207 | #if defined(__LITTLE_ENDIAN_BITFIELD) | |
208 | __u8 ihl:4, | |
209 | version:4; | |
210 | #elif defined (__BIG_ENDIAN_BITFIELD) | |
211 | __u8 version:4, | |
212 | ihl:4; | |
213 | #else | |
214 | #error "Please fix <asm/byteorder.h>" | |
215 | #endif | |
216 | __u8 tos; | |
217 | __u16 tot_len; | |
218 | __u16 id; | |
219 | __u16 frag_off; | |
220 | __u8 ttl; | |
221 | __u8 protocol; | |
222 | __u16 check; | |
223 | __u32 saddr; | |
224 | __u32 daddr; | |
225 | /*The options start here. */ | |
226 | }; | |
227 | ||
228 | struct ip_auth_hdr { | |
229 | __u8 nexthdr; | |
230 | __u8 hdrlen; /* This one is measured in 32 bit units! */ | |
231 | __u16 reserved; | |
232 | __u32 spi; | |
233 | __u32 seq_no; /* Sequence number */ | |
234 | __u8 auth_data[0]; /* Variable len but >=4. Mind the 64 bit alignment! */ | |
235 | }; | |
236 | ||
237 | struct ip_esp_hdr { | |
238 | __u32 spi; | |
239 | __u32 seq_no; /* Sequence number */ | |
240 | __u8 enc_data[0]; /* Variable len but >=8. Mind the 64 bit alignment! */ | |
241 | }; | |
242 | ||
243 | struct ip_comp_hdr { | |
244 | __u8 nexthdr; | |
245 | __u8 flags; | |
246 | __u16 cpi; | |
247 | }; | |
248 | ||
249 | #endif /* _LINUX_IP_H */ |