]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Definitions for the 'struct sk_buff' memory handlers. | |
3 | * | |
4 | * Authors: | |
5 | * Alan Cox, <gw4pts@gw4pts.ampr.org> | |
6 | * Florian La Roche, <rzsfl@rz.uni-sb.de> | |
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 | 34 | |
60476372 | 35 | /* Don't change this without changing skb_csum_unnecessary! */ |
1da177e4 | 36 | #define CHECKSUM_NONE 0 |
60476372 HX |
37 | #define CHECKSUM_UNNECESSARY 1 |
38 | #define CHECKSUM_COMPLETE 2 | |
39 | #define CHECKSUM_PARTIAL 3 | |
1da177e4 LT |
40 | |
41 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ | |
42 | ~(SMP_CACHE_BYTES - 1)) | |
fc910a27 DM |
43 | #define SKB_WITH_OVERHEAD(X) \ |
44 | (((X) - sizeof(struct skb_shared_info)) & \ | |
45 | ~(SMP_CACHE_BYTES - 1)) | |
46 | #define SKB_MAX_ORDER(X, ORDER) \ | |
47 | SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) | |
1da177e4 LT |
48 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) |
49 | #define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2)) | |
50 | ||
51 | /* A. Checksumming of received packets by device. | |
52 | * | |
53 | * NONE: device failed to checksum this packet. | |
54 | * skb->csum is undefined. | |
55 | * | |
56 | * UNNECESSARY: device parsed packet and wouldbe verified checksum. | |
57 | * skb->csum is undefined. | |
58 | * It is bad option, but, unfortunately, many of vendors do this. | |
59 | * Apparently with secret goal to sell you new device, when you | |
60 | * will add new protocol to your host. F.e. IPv6. 8) | |
61 | * | |
84fa7933 | 62 | * COMPLETE: the most generic way. Device supplied checksum of _all_ |
1da177e4 LT |
63 | * the packet as seen by netif_rx in skb->csum. |
64 | * NOTE: Even if device supports only some protocols, but | |
84fa7933 | 65 | * is able to produce some skb->csum, it MUST use COMPLETE, |
1da177e4 LT |
66 | * not UNNECESSARY. |
67 | * | |
68 | * B. Checksumming on output. | |
69 | * | |
70 | * NONE: skb is checksummed by protocol or csum is not required. | |
71 | * | |
84fa7933 | 72 | * PARTIAL: device is required to csum packet as seen by hard_start_xmit |
b0e380b1 ACM |
73 | * from skb->transport_header to the end and to record the checksum |
74 | * at skb->transport_header + skb->csum. | |
1da177e4 LT |
75 | * |
76 | * Device must show its capabilities in dev->features, set | |
77 | * at device setup time. | |
78 | * NETIF_F_HW_CSUM - it is clever device, it is able to checksum | |
79 | * everything. | |
80 | * NETIF_F_NO_CSUM - loopback or reliable single hop media. | |
81 | * NETIF_F_IP_CSUM - device is dumb. It is able to csum only | |
82 | * TCP/UDP over IPv4. Sigh. Vendors like this | |
83 | * way by an unknown reason. Though, see comment above | |
84 | * about CHECKSUM_UNNECESSARY. 8) | |
85 | * | |
86 | * Any questions? No questions, good. --ANK | |
87 | */ | |
88 | ||
1da177e4 | 89 | struct net_device; |
716ea3a7 | 90 | struct scatterlist; |
1da177e4 | 91 | |
5f79e0f9 | 92 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
1da177e4 LT |
93 | struct nf_conntrack { |
94 | atomic_t use; | |
1da177e4 | 95 | }; |
5f79e0f9 | 96 | #endif |
1da177e4 LT |
97 | |
98 | #ifdef CONFIG_BRIDGE_NETFILTER | |
99 | struct nf_bridge_info { | |
100 | atomic_t use; | |
101 | struct net_device *physindev; | |
102 | struct net_device *physoutdev; | |
103 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) | |
104 | struct net_device *netoutdev; | |
105 | #endif | |
106 | unsigned int mask; | |
107 | unsigned long data[32 / sizeof(unsigned long)]; | |
108 | }; | |
109 | #endif | |
110 | ||
1da177e4 LT |
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 | |
334a8132 PM |
150 | * the entire skb->data. A clone of a headerless skb holds the length of |
151 | * the header in skb->hdr_len. | |
1da177e4 LT |
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 | ||
2e07fa9c ACM |
182 | #if BITS_PER_LONG > 32 |
183 | #define NET_SKBUFF_DATA_USES_OFFSET 1 | |
184 | #endif | |
185 | ||
186 | #ifdef NET_SKBUFF_DATA_USES_OFFSET | |
187 | typedef unsigned int sk_buff_data_t; | |
188 | #else | |
189 | typedef unsigned char *sk_buff_data_t; | |
190 | #endif | |
191 | ||
1da177e4 LT |
192 | /** |
193 | * struct sk_buff - socket buffer | |
194 | * @next: Next buffer in list | |
195 | * @prev: Previous buffer in list | |
1da177e4 | 196 | * @sk: Socket we are owned by |
325ed823 | 197 | * @tstamp: Time we arrived |
1da177e4 | 198 | * @dev: Device we arrived on/are leaving by |
be52178b | 199 | * @transport_header: Transport layer header |
b0e380b1 ACM |
200 | * @network_header: Network layer header |
201 | * @mac_header: Link layer header | |
67be2dd1 MW |
202 | * @dst: destination entry |
203 | * @sp: the security path, used for xfrm | |
1da177e4 LT |
204 | * @cb: Control buffer. Free for use by every layer. Put private vars here |
205 | * @len: Length of actual data | |
206 | * @data_len: Data length | |
207 | * @mac_len: Length of link layer header | |
334a8132 | 208 | * @hdr_len: writable header length of cloned skb |
663ead3b HX |
209 | * @csum: Checksum (must include start/offset pair) |
210 | * @csum_start: Offset from skb->head where checksumming should start | |
211 | * @csum_offset: Offset from csum_start where checksum should be stored | |
67be2dd1 | 212 | * @local_df: allow local fragmentation |
1da177e4 LT |
213 | * @cloned: Head may be cloned (check refcnt to be sure) |
214 | * @nohdr: Payload reference only, must not modify header | |
215 | * @pkt_type: Packet class | |
c83c2486 | 216 | * @fclone: skbuff clone status |
1da177e4 LT |
217 | * @ip_summed: Driver fed us an IP checksum |
218 | * @priority: Packet queueing priority | |
219 | * @users: User count - see {datagram,tcp}.c | |
220 | * @protocol: Packet protocol from driver | |
1da177e4 LT |
221 | * @truesize: Buffer size |
222 | * @head: Head of buffer | |
223 | * @data: Data head pointer | |
224 | * @tail: Tail pointer | |
225 | * @end: End pointer | |
226 | * @destructor: Destruct function | |
82e91ffe | 227 | * @mark: Generic packet mark |
1da177e4 | 228 | * @nfct: Associated connection, if any |
c83c2486 | 229 | * @ipvs_property: skbuff is owned by ipvs |
ba9dda3a | 230 | * @nf_trace: netfilter packet trace flag |
1da177e4 | 231 | * @nfctinfo: Relationship of this skb to the connection |
461ddf3b | 232 | * @nfct_reasm: netfilter conntrack re-assembly pointer |
1da177e4 | 233 | * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c |
f25f4e44 PWJ |
234 | * @iif: ifindex of device we arrived on |
235 | * @queue_mapping: Queue mapping for multiqueue devices | |
1da177e4 LT |
236 | * @tc_index: Traffic control index |
237 | * @tc_verd: traffic control verdict | |
f4b8ea78 RD |
238 | * @dma_cookie: a cookie to one of several possible DMA operations |
239 | * done by skb DMA functions | |
984bc16c | 240 | * @secmark: security marking |
1da177e4 LT |
241 | */ |
242 | ||
243 | struct sk_buff { | |
244 | /* These two members must be first. */ | |
245 | struct sk_buff *next; | |
246 | struct sk_buff *prev; | |
247 | ||
1da177e4 | 248 | struct sock *sk; |
b7aa0bf7 | 249 | ktime_t tstamp; |
1da177e4 | 250 | struct net_device *dev; |
1da177e4 | 251 | |
1da177e4 LT |
252 | struct dst_entry *dst; |
253 | struct sec_path *sp; | |
254 | ||
255 | /* | |
256 | * This is the control buffer. It is free to use for every | |
257 | * layer. Please put your private variables there. If you | |
258 | * want to keep them across layers you have to do a skb_clone() | |
259 | * first. This is owned by whoever has the skb queued ATM. | |
260 | */ | |
3e3850e9 | 261 | char cb[48]; |
1da177e4 LT |
262 | |
263 | unsigned int len, | |
334a8132 PM |
264 | data_len; |
265 | __u16 mac_len, | |
266 | hdr_len; | |
ff1dcadb AV |
267 | union { |
268 | __wsum csum; | |
663ead3b HX |
269 | struct { |
270 | __u16 csum_start; | |
271 | __u16 csum_offset; | |
272 | }; | |
ff1dcadb | 273 | }; |
1da177e4 | 274 | __u32 priority; |
1cbb3380 TG |
275 | __u8 local_df:1, |
276 | cloned:1, | |
277 | ip_summed:2, | |
6869c4d8 HW |
278 | nohdr:1, |
279 | nfctinfo:3; | |
d179cd12 | 280 | __u8 pkt_type:3, |
b84f4cc9 | 281 | fclone:2, |
ba9dda3a JK |
282 | ipvs_property:1, |
283 | nf_trace:1; | |
a0d3bea3 | 284 | __be16 protocol; |
1da177e4 LT |
285 | |
286 | void (*destructor)(struct sk_buff *skb); | |
9fb9cbb1 | 287 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
5f79e0f9 | 288 | struct nf_conntrack *nfct; |
9fb9cbb1 YK |
289 | struct sk_buff *nfct_reasm; |
290 | #endif | |
1da177e4 LT |
291 | #ifdef CONFIG_BRIDGE_NETFILTER |
292 | struct nf_bridge_info *nf_bridge; | |
293 | #endif | |
f25f4e44 PWJ |
294 | |
295 | int iif; | |
296 | __u16 queue_mapping; | |
297 | ||
1da177e4 | 298 | #ifdef CONFIG_NET_SCHED |
b6b99eb5 | 299 | __u16 tc_index; /* traffic control index */ |
1da177e4 | 300 | #ifdef CONFIG_NET_CLS_ACT |
b6b99eb5 | 301 | __u16 tc_verd; /* traffic control verdict */ |
1da177e4 | 302 | #endif |
1da177e4 | 303 | #endif |
f25f4e44 PWJ |
304 | /* 2 byte hole */ |
305 | ||
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 | 314 | |
27a884dc ACM |
315 | sk_buff_data_t transport_header; |
316 | sk_buff_data_t network_header; | |
317 | sk_buff_data_t mac_header; | |
1da177e4 | 318 | /* These elements must be at the end, see alloc_skb() for details. */ |
27a884dc | 319 | sk_buff_data_t tail; |
4305b541 | 320 | sk_buff_data_t end; |
1da177e4 | 321 | unsigned char *head, |
4305b541 | 322 | *data; |
27a884dc ACM |
323 | unsigned int truesize; |
324 | atomic_t users; | |
1da177e4 LT |
325 | }; |
326 | ||
327 | #ifdef __KERNEL__ | |
328 | /* | |
329 | * Handling routines are only of interest to the kernel | |
330 | */ | |
331 | #include <linux/slab.h> | |
332 | ||
333 | #include <asm/system.h> | |
334 | ||