]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Definitions for the 'struct sk_buff' memory handlers. | |
3 | * | |
4 | * Authors: | |
5 | * Alan Cox, <[email protected]> | |
6 | * Florian La Roche, <[email protected]> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License | |
10 | * as published by the Free Software Foundation; either version | |
11 | * 2 of the License, or (at your option) any later version. | |
12 | */ | |
13 | ||
14 | #ifndef _LINUX_SKBUFF_H | |
15 | #define _LINUX_SKBUFF_H | |
16 | ||
1da177e4 LT |
17 | #include <linux/kernel.h> |
18 | #include <linux/compiler.h> | |
19 | #include <linux/time.h> | |
20 | #include <linux/cache.h> | |
21 | ||
22 | #include <asm/atomic.h> | |
23 | #include <asm/types.h> | |
24 | #include <linux/spinlock.h> | |
1da177e4 | 25 | #include <linux/net.h> |
3fc7e8a6 | 26 | #include <linux/textsearch.h> |
1da177e4 | 27 | #include <net/checksum.h> |
a80958f4 | 28 | #include <linux/rcupdate.h> |
97fc2f08 | 29 | #include <linux/dmaengine.h> |
1da177e4 LT |
30 | |
31 | #define HAVE_ALLOC_SKB /* For the drivers to know */ | |
32 | #define HAVE_ALIGNABLE_SKB /* Ditto 8) */ | |
1da177e4 LT |
33 | |
34 | #define CHECKSUM_NONE 0 | |
84fa7933 | 35 | #define CHECKSUM_PARTIAL 1 |
1da177e4 | 36 | #define CHECKSUM_UNNECESSARY 2 |
84fa7933 | 37 | #define CHECKSUM_COMPLETE 3 |
1da177e4 LT |
38 | |
39 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ | |
40 | ~(SMP_CACHE_BYTES - 1)) | |
41 | #define SKB_MAX_ORDER(X, ORDER) (((PAGE_SIZE << (ORDER)) - (X) - \ | |
42 | sizeof(struct skb_shared_info)) & \ | |
43 | ~(SMP_CACHE_BYTES - 1)) | |
44 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) | |
45 | #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) | |
46 | ||
47 | /* A. Checksumming of received packets by device. | |
48 | * | |
49 | * NONE: device failed to checksum this packet. | |
50 | * skb->csum is undefined. | |
51 | * | |
52 | * UNNECESSARY: device parsed packet and wouldbe verified checksum. | |
53 | * skb->csum is undefined. | |
54 | * It is bad option, but, unfortunately, many of vendors do this. | |
55 | * Apparently with secret goal to sell you new device, when you | |
56 | * will add new protocol to your host. F.e. IPv6. 8) | |
57 | * | |
84fa7933 | 58 | * COMPLETE: the most generic way. Device supplied checksum of _all_ |
1da177e4 LT |
59 | * the packet as seen by netif_rx in skb->csum. |
60 | * NOTE: Even if device supports only some protocols, but | |
84fa7933 | 61 | * is able to produce some skb->csum, it MUST use COMPLETE, |
1da177e4 LT |
62 | * not UNNECESSARY. |
63 | * | |
64 | * B. Checksumming on output. | |
65 | * | |
66 | * NONE: skb is checksummed by protocol or csum is not required. | |
67 | * | |
84fa7933 | 68 | * PARTIAL: device is required to csum packet as seen by hard_start_xmit |
1da177e4 LT |
69 | * from skb->h.raw to the end and to record the checksum |
70 | * at skb->h.raw+skb->csum. | |
71 | * | |
72 | * Device must show its capabilities in dev->features, set | |
73 | * at device setup time. | |
74 | * NETIF_F_HW_CSUM - it is clever device, it is able to checksum | |
75 | * everything. | |
76 | * NETIF_F_NO_CSUM - loopback or reliable single hop media. | |
77 | * NETIF_F_IP_CSUM - device is dumb. It is able to csum only | |
78 | * TCP/UDP over IPv4. Sigh. Vendors like this | |
79 | * way by an unknown reason. Though, see comment above | |
80 | * about CHECKSUM_UNNECESSARY. 8) | |
81 | * | |
82 | * Any questions? No questions, good. --ANK | |
83 | */ | |
84 | ||
1da177e4 LT |
85 | struct net_device; |
86 | ||
87 | #ifdef CONFIG_NETFILTER | |
88 | struct nf_conntrack { | |
89 | atomic_t use; | |
90 | void (*destroy)(struct nf_conntrack *); | |
91 | }; | |
92 | ||
93 | #ifdef CONFIG_BRIDGE_NETFILTER | |
94 | struct nf_bridge_info { | |
95 | atomic_t use; | |
96 | struct net_device *physindev; | |
97 | struct net_device *physoutdev; | |
98 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) | |
99 | struct net_device *netoutdev; | |
100 | #endif | |
101 | unsigned int mask; | |
102 | unsigned long data[32 / sizeof(unsigned long)]; | |
103 | }; | |
104 | #endif | |
105 | ||
106 | #endif | |
107 | ||
108 | struct sk_buff_head { | |
109 | /* These two members must be first. */ | |
110 | struct sk_buff *next; | |
111 | struct sk_buff *prev; | |
112 | ||
113 | __u32 qlen; | |
114 | spinlock_t lock; | |
115 | }; | |
116 | ||
117 | struct sk_buff; | |
118 | ||
119 | /* To allow 64K frame to be packed as single skb without frag_list */ | |
120 | #define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2) | |
121 | ||
122 | typedef struct skb_frag_struct skb_frag_t; | |
123 | ||
124 | struct skb_frag_struct { | |
125 | struct page *page; | |
126 | __u16 page_offset; | |
127 | __u16 size; | |
128 | }; | |
129 | ||
130 | /* This data is invariant across clones and lives at | |
131 | * the end of the header data, ie. at skb->end. | |
132 | */ | |
133 | struct skb_shared_info { | |
134 | atomic_t dataref; | |
4947d3ef | 135 | unsigned short nr_frags; |
7967168c HX |
136 | unsigned short gso_size; |
137 | /* Warning: this field is not always filled in (UFO)! */ | |
138 | unsigned short gso_segs; | |
139 | unsigned short gso_type; | |
ae08e1f0 | 140 | __be32 ip6_frag_id; |
1da177e4 LT |
141 | struct sk_buff *frag_list; |
142 | skb_frag_t frags[MAX_SKB_FRAGS]; | |
143 | }; | |
144 | ||
145 | /* We divide dataref into two halves. The higher 16 bits hold references | |
146 | * to the payload part of skb->data. The lower 16 bits hold references to | |
147 | * the entire skb->data. It is up to the users of the skb to agree on | |
148 | * where the payload starts. | |
149 | * | |
150 | * All users must obey the rule that the skb->data reference count must be | |
151 | * greater than or equal to the payload reference count. | |
152 | * | |
153 | * Holding a reference to the payload part means that the user does not | |
154 | * care about modifications to the header part of skb->data. | |
155 | */ | |
156 | #define SKB_DATAREF_SHIFT 16 | |
157 | #define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1) | |
158 | ||
a61bbcf2 PM |
159 | struct skb_timeval { |
160 | u32 off_sec; | |
161 | u32 off_usec; | |
162 | }; | |
163 | ||
d179cd12 DM |
164 | |
165 | enum { | |
166 | SKB_FCLONE_UNAVAILABLE, | |
167 | SKB_FCLONE_ORIG, | |
168 | SKB_FCLONE_CLONE, | |
169 | }; | |
170 | ||
7967168c HX |
171 | enum { |
172 | SKB_GSO_TCPV4 = 1 << 0, | |
f83ef8c0 | 173 | SKB_GSO_UDP = 1 << 1, |
576a30eb HX |
174 | |
175 | /* This indicates the skb is from an untrusted source. */ | |
176 | SKB_GSO_DODGY = 1 << 2, | |
b0da8537 MC |
177 | |
178 | /* This indicates the tcp segment has CWR set. */ | |
f83ef8c0 HX |
179 | SKB_GSO_TCP_ECN = 1 << 3, |
180 | ||
181 | SKB_GSO_TCPV6 = 1 << 4, | |
7967168c HX |
182 | }; |
183 | ||
1da177e4 LT |
184 | /** |
185 | * struct sk_buff - socket buffer | |
186 | * @next: Next buffer in list | |
187 | * @prev: Previous buffer in list | |
1da177e4 | 188 | * @sk: Socket we are owned by |
325ed823 | 189 | * @tstamp: Time we arrived |
1da177e4 LT |
190 | * @dev: Device we arrived on/are leaving by |
191 | * @input_dev: Device we arrived on | |
1da177e4 LT |
192 | * @h: Transport layer header |
193 | * @nh: Network layer header | |
194 | * @mac: Link layer header | |
67be2dd1 MW |
195 | * @dst: destination entry |
196 | * @sp: the security path, used for xfrm | |
1da177e4 LT |
197 | * @cb: Control buffer. Free for use by every layer. Put private vars here |
198 | * @len: Length of actual data | |
199 | * @data_len: Data length | |
200 | * @mac_len: Length of link layer header | |
201 | * @csum: Checksum | |
67be2dd1 | 202 | * @local_df: allow local fragmentation |
1da177e4 LT |
203 | * @cloned: Head may be cloned (check refcnt to be sure) |
204 | * @nohdr: Payload reference only, must not modify header | |
205 | * @pkt_type: Packet class | |
c83c2486 | 206 | * @fclone: skbuff clone status |
1da177e4 LT |
207 | * @ip_summed: Driver fed us an IP checksum |
208 | * @priority: Packet queueing priority | |
209 | * @users: User count - see {datagram,tcp}.c | |
210 | * @protocol: Packet protocol from driver | |
1da177e4 LT |
211 | * @truesize: Buffer size |
212 | * @head: Head of buffer | |
213 | * @data: Data head pointer | |
214 | * @tail: Tail pointer | |
215 | * @end: End pointer | |
216 | * @destructor: Destruct function | |
82e91ffe | 217 | * @mark: Generic packet mark |
1da177e4 | 218 | * @nfct: Associated connection, if any |
c83c2486 | 219 | * @ipvs_property: skbuff is owned by ipvs |
1da177e4 | 220 | * @nfctinfo: Relationship of this skb to the connection |
461ddf3b | 221 | * @nfct_reasm: netfilter conntrack re-assembly pointer |
1da177e4 | 222 | * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c |
1da177e4 LT |
223 | * @tc_index: Traffic control index |
224 | * @tc_verd: traffic control verdict | |
f4b8ea78 RD |
225 | * @dma_cookie: a cookie to one of several possible DMA operations |
226 | * done by skb DMA functions | |
984bc16c | 227 | * @secmark: security marking |
1da177e4 LT |
228 | */ |
229 | ||
230 | struct sk_buff { | |
231 | /* These two members must be first. */ | |
232 | struct sk_buff *next; | |
233 | struct sk_buff *prev; | |
234 | ||
1da177e4 | 235 | struct sock *sk; |
a61bbcf2 | 236 | struct skb_timeval tstamp; |
1da177e4 LT |
237 | struct net_device *dev; |
238 | struct net_device *input_dev; | |
1da177e4 LT |
239 | |
240 | union { | |
241 | struct tcphdr *th; | |
242 | struct udphdr *uh; | |
243 | struct icmphdr *icmph; | |
244 | struct igmphdr *igmph; | |
245 | struct iphdr *ipiph; | |
246 | struct ipv6hdr *ipv6h; | |
247 | unsigned char *raw; | |
248 | } h; | |
249 | ||
250 | union { | |
251 | struct iphdr *iph; | |
252 | struct ipv6hdr *ipv6h; | |
253 | struct arphdr *arph; | |
254 | unsigned char *raw; | |
255 | } nh; | |
256 | ||
257 | union { | |
258 | unsigned char *raw; | |
259 | } mac; | |
260 | ||
261 | struct dst_entry *dst; | |
262 | struct sec_path *sp; | |
263 | ||
264 | /* | |
265 | * This is the control buffer. It is free to use for every | |
266 | * layer. Please put your private variables there. If you | |
267 | * want to keep them across layers you have to do a skb_clone() | |
268 | * first. This is owned by whoever has the skb queued ATM. | |
269 | */ | |
3e3850e9 | 270 | char cb[48]; |
1da177e4 LT |
271 | |
272 | unsigned int len, | |
273 | data_len, | |
1f61ab5c | 274 | mac_len; |
ff1dcadb AV |
275 | union { |
276 | __wsum csum; | |
277 | __u32 csum_offset; | |
278 | }; | |
1da177e4 | 279 | __u32 priority; |
1cbb3380 TG |
280 | __u8 local_df:1, |
281 | cloned:1, | |
282 | ip_summed:2, | |
6869c4d8 HW |
283 | nohdr:1, |
284 | nfctinfo:3; | |
d179cd12 | 285 | __u8 pkt_type:3, |
b84f4cc9 PM |
286 | fclone:2, |
287 | ipvs_property:1; | |
a0d3bea3 | 288 | __be16 protocol; |
1da177e4 LT |
289 | |
290 | void (*destructor)(struct sk_buff *skb); | |
291 | #ifdef CONFIG_NETFILTER | |
1da177e4 | 292 | struct nf_conntrack *nfct; |
9fb9cbb1 YK |
293 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
294 | struct sk_buff *nfct_reasm; | |
295 | #endif | |
1da177e4 LT |
296 | #ifdef CONFIG_BRIDGE_NETFILTER |
297 | struct nf_bridge_info *nf_bridge; | |
298 | #endif | |
299 | #endif /* CONFIG_NETFILTER */ | |
1da177e4 | 300 | #ifdef CONFIG_NET_SCHED |
b6b99eb5 | 301 | __u16 tc_index; /* traffic control index */ |
1da177e4 | 302 | #ifdef CONFIG_NET_CLS_ACT |
b6b99eb5 | 303 | __u16 tc_verd; /* traffic control verdict */ |
1da177e4 | 304 | #endif |
1da177e4 | 305 | #endif |
97fc2f08 CL |
306 | #ifdef CONFIG_NET_DMA |
307 | dma_cookie_t dma_cookie; | |
308 | #endif | |
984bc16c JM |
309 | #ifdef CONFIG_NETWORK_SECMARK |
310 | __u32 secmark; | |
311 | #endif | |
1da177e4 | 312 | |
82e91ffe | 313 | __u32 mark; |
1da177e4 LT |
314 | |
315 | /* These elements must be at the end, see alloc_skb() for details. */ | |
316 | unsigned int truesize; | |
317 | atomic_t users; | |
318 | unsigned char *head, | |
319 | *data, | |
320 | *tail, | |
321 | *end; | |
322 | }; | |
323 | ||
324 | #ifdef __KERNEL__ | |
325 | /* | |
326 | * Handling routines are only of interest to the kernel | |
327 | */ | |
328 | #include <linux/slab.h> | |
329 | ||
330 | #include <asm/system.h> | |
331 | ||