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