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