]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/skbuff.h
kmemcheck: introduce bitfield API
[net-next-2.6.git] / include / linux / skbuff.h
CommitLineData
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 31
60476372 32/* Don't change this without changing skb_csum_unnecessary! */
1da177e4 33#define CHECKSUM_NONE 0
60476372
HX
34#define CHECKSUM_UNNECESSARY 1
35#define CHECKSUM_COMPLETE 2
36#define CHECKSUM_PARTIAL 3
1da177e4
LT
37
38#define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \
39 ~(SMP_CACHE_BYTES - 1))
fc910a27 40#define SKB_WITH_OVERHEAD(X) \
deea84b0 41 ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
fc910a27
DM
42#define SKB_MAX_ORDER(X, ORDER) \
43 SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
1da177e4
LT
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 *
c6c6e3e0
HX
64 * PARTIAL: identical to the case for output below. This may occur
65 * on a packet received directly from another Linux OS, e.g.,
66 * a virtualised Linux kernel on the same host. The packet can
67 * be treated in the same way as UNNECESSARY except that on
68 * output (i.e., forwarding) the checksum must be filled in
69 * by the OS or the hardware.
70 *
1da177e4
LT
71 * B. Checksumming on output.
72 *
73 * NONE: skb is checksummed by protocol or csum is not required.
74 *
84fa7933 75 * PARTIAL: device is required to csum packet as seen by hard_start_xmit
c6c6e3e0
HX
76 * from skb->csum_start to the end and to record the checksum
77 * at skb->csum_start + skb->csum_offset.
1da177e4
LT
78 *
79 * Device must show its capabilities in dev->features, set
80 * at device setup time.
81 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
82 * everything.
83 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
84 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
85 * TCP/UDP over IPv4. Sigh. Vendors like this
86 * way by an unknown reason. Though, see comment above
87 * about CHECKSUM_UNNECESSARY. 8)
c6c6e3e0 88 * NETIF_F_IPV6_CSUM about as dumb as the last one but does IPv6 instead.
1da177e4
LT
89 *
90 * Any questions? No questions, good. --ANK
91 */
92
1da177e4 93struct net_device;
716ea3a7 94struct scatterlist;
9c55e01c 95struct pipe_inode_info;
1da177e4 96
5f79e0f9 97#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1da177e4
LT
98struct nf_conntrack {
99 atomic_t use;
1da177e4 100};
5f79e0f9 101#endif
1da177e4
LT
102
103#ifdef CONFIG_BRIDGE_NETFILTER
104struct nf_bridge_info {
105 atomic_t use;
106 struct net_device *physindev;
107 struct net_device *physoutdev;
1da177e4
LT
108 unsigned int mask;
109 unsigned long data[32 / sizeof(unsigned long)];
110};
111#endif
112
1da177e4
LT
113struct sk_buff_head {
114 /* These two members must be first. */
115 struct sk_buff *next;
116 struct sk_buff *prev;
117
118 __u32 qlen;
119 spinlock_t lock;
120};
121
122struct sk_buff;
123
124/* To allow 64K frame to be packed as single skb without frag_list */
125#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
126
127typedef struct skb_frag_struct skb_frag_t;
128
129struct skb_frag_struct {
130 struct page *page;
a309bb07
DM
131 __u32 page_offset;
132 __u32 size;
1da177e4
LT
133};
134
ac45f602
PO
135#define HAVE_HW_TIME_STAMP
136
137/**
d3a21be8 138 * struct skb_shared_hwtstamps - hardware time stamps
ac45f602
PO
139 * @hwtstamp: hardware time stamp transformed into duration
140 * since arbitrary point in time
141 * @syststamp: hwtstamp transformed to system time base
142 *
143 * Software time stamps generated by ktime_get_real() are stored in
144 * skb->tstamp. The relation between the different kinds of time
145 * stamps is as follows:
146 *
147 * syststamp and tstamp can be compared against each other in
148 * arbitrary combinations. The accuracy of a
149 * syststamp/tstamp/"syststamp from other device" comparison is
150 * limited by the accuracy of the transformation into system time
151 * base. This depends on the device driver and its underlying
152 * hardware.
153 *
154 * hwtstamps can only be compared against other hwtstamps from
155 * the same device.
156 *
157 * This structure is attached to packets as part of the
158 * &skb_shared_info. Use skb_hwtstamps() to get a pointer.
159 */
160struct skb_shared_hwtstamps {
161 ktime_t hwtstamp;
162 ktime_t syststamp;
163};
164
165/**
d3a21be8 166 * struct skb_shared_tx - instructions for time stamping of outgoing packets
ac45f602
PO
167 * @hardware: generate hardware time stamp
168 * @software: generate software time stamp
169 * @in_progress: device driver is going to provide
170 * hardware time stamp
4b21cd4e 171 * @flags: all shared_tx flags
ac45f602
PO
172 *
173 * These flags are attached to packets as part of the
174 * &skb_shared_info. Use skb_tx() to get a pointer.
175 */
176union skb_shared_tx {
177 struct {
178 __u8 hardware:1,
179 software:1,
180 in_progress:1;
181 };
182 __u8 flags;
183};
184
1da177e4
LT
185/* This data is invariant across clones and lives at
186 * the end of the header data, ie. at skb->end.
187 */
188struct skb_shared_info {
189 atomic_t dataref;
4947d3ef 190 unsigned short nr_frags;
7967168c
HX
191 unsigned short gso_size;
192 /* Warning: this field is not always filled in (UFO)! */
193 unsigned short gso_segs;
194 unsigned short gso_type;
ae08e1f0 195 __be32 ip6_frag_id;
ac45f602 196 union skb_shared_tx tx_flags;
271bff7a
DM
197#ifdef CONFIG_HAS_DMA
198 unsigned int num_dma_maps;
199#endif
1da177e4 200 struct sk_buff *frag_list;
ac45f602 201 struct skb_shared_hwtstamps hwtstamps;
1da177e4 202 skb_frag_t frags[MAX_SKB_FRAGS];
271bff7a
DM
203#ifdef CONFIG_HAS_DMA
204 dma_addr_t dma_maps[MAX_SKB_FRAGS + 1];
205#endif
1da177e4
LT
206};
207
208/* We divide dataref into two halves. The higher 16 bits hold references
209 * to the payload part of skb->data. The lower 16 bits hold references to
334a8132
PM
210 * the entire skb->data. A clone of a headerless skb holds the length of
211 * the header in skb->hdr_len.
1da177e4
LT
212 *
213 * All users must obey the rule that the skb->data reference count must be
214 * greater than or equal to the payload reference count.
215 *
216 * Holding a reference to the payload part means that the user does not
217 * care about modifications to the header part of skb->data.
218 */
219#define SKB_DATAREF_SHIFT 16
220#define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
221
d179cd12
DM
222
223enum {
224 SKB_FCLONE_UNAVAILABLE,
225 SKB_FCLONE_ORIG,
226 SKB_FCLONE_CLONE,
227};
228
7967168c
HX
229enum {
230 SKB_GSO_TCPV4 = 1 << 0,
f83ef8c0 231 SKB_GSO_UDP = 1 << 1,
576a30eb
HX
232
233 /* This indicates the skb is from an untrusted source. */
234 SKB_GSO_DODGY = 1 << 2,
b0da8537
MC
235
236 /* This indicates the tcp segment has CWR set. */
f83ef8c0
HX
237 SKB_GSO_TCP_ECN = 1 << 3,
238
239 SKB_GSO_TCPV6 = 1 << 4,
01d5b2fc
CL
240
241 SKB_GSO_FCOE = 1 << 5,
7967168c
HX
242};
243
2e07fa9c
ACM
244#if BITS_PER_LONG > 32
245#define NET_SKBUFF_DATA_USES_OFFSET 1
246#endif
247
248#ifdef NET_SKBUFF_DATA_USES_OFFSET
249typedef unsigned int sk_buff_data_t;
250#else
251typedef unsigned char *sk_buff_data_t;
252#endif
253
1da177e4
LT
254/**
255 * struct sk_buff - socket buffer
256 * @next: Next buffer in list
257 * @prev: Previous buffer in list
1da177e4 258 * @sk: Socket we are owned by
325ed823 259 * @tstamp: Time we arrived
1da177e4 260 * @dev: Device we arrived on/are leaving by
be52178b 261 * @transport_header: Transport layer header
b0e380b1
ACM
262 * @network_header: Network layer header
263 * @mac_header: Link layer header
67be2dd1
MW
264 * @dst: destination entry
265 * @sp: the security path, used for xfrm
1da177e4
LT
266 * @cb: Control buffer. Free for use by every layer. Put private vars here
267 * @len: Length of actual data
268 * @data_len: Data length
269 * @mac_len: Length of link layer header
334a8132 270 * @hdr_len: writable header length of cloned skb
663ead3b
HX
271 * @csum: Checksum (must include start/offset pair)
272 * @csum_start: Offset from skb->head where checksumming should start
273 * @csum_offset: Offset from csum_start where checksum should be stored
67be2dd1 274 * @local_df: allow local fragmentation
1da177e4
LT
275 * @cloned: Head may be cloned (check refcnt to be sure)
276 * @nohdr: Payload reference only, must not modify header
277 * @pkt_type: Packet class
c83c2486 278 * @fclone: skbuff clone status
1da177e4
LT
279 * @ip_summed: Driver fed us an IP checksum
280 * @priority: Packet queueing priority
281 * @users: User count - see {datagram,tcp}.c
282 * @protocol: Packet protocol from driver
1da177e4
LT
283 * @truesize: Buffer size
284 * @head: Head of buffer
285 * @data: Data head pointer
286 * @tail: Tail pointer
287 * @end: End pointer
288 * @destructor: Destruct function
82e91ffe 289 * @mark: Generic packet mark
1da177e4 290 * @nfct: Associated connection, if any
c83c2486 291 * @ipvs_property: skbuff is owned by ipvs
31729363
RD
292 * @peeked: this packet has been seen already, so stats have been
293 * done for it, don't do them again
ba9dda3a 294 * @nf_trace: netfilter packet trace flag
1da177e4 295 * @nfctinfo: Relationship of this skb to the connection
461ddf3b 296 * @nfct_reasm: netfilter conntrack re-assembly pointer
1da177e4 297 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
f25f4e44
PWJ
298 * @iif: ifindex of device we arrived on
299 * @queue_mapping: Queue mapping for multiqueue devices
1da177e4
LT
300 * @tc_index: Traffic control index
301 * @tc_verd: traffic control verdict
553a5672 302 * @ndisc_nodetype: router type (from link layer)
4a7b61d2 303 * @do_not_encrypt: set to prevent encryption of this frame
8b30b1fe
S
304 * @requeue: set to indicate that the wireless core should attempt
305 * a software retry on this frame if we failed to
306 * receive an ACK for it
f4b8ea78
RD
307 * @dma_cookie: a cookie to one of several possible DMA operations
308 * done by skb DMA functions
984bc16c 309 * @secmark: security marking
6aa895b0 310 * @vlan_tci: vlan tag control information
1da177e4
LT
311 */
312
313struct sk_buff {
314 /* These two members must be first. */
315 struct sk_buff *next;
316 struct sk_buff *prev;
317
1da177e4 318 struct sock *sk;
b7aa0bf7 319 ktime_t tstamp;
1da177e4 320 struct net_device *dev;
1da177e4 321
ee6b9673
ED
322 union {
323 struct dst_entry *dst;
324 struct rtable *rtable;
325 };
def8b4fa 326#ifdef CONFIG_XFRM
1da177e4 327 struct sec_path *sp;
def8b4fa 328#endif
1da177e4
LT
329 /*
330 * This is the control buffer. It is free to use for every
331 * layer. Please put your private variables there. If you
332 * want to keep them across layers you have to do a skb_clone()
333 * first. This is owned by whoever has the skb queued ATM.
334 */
3e3850e9 335 char cb[48];
1da177e4
LT
336
337 unsigned int len,
334a8132
PM
338 data_len;
339 __u16 mac_len,
340 hdr_len;
ff1dcadb
AV
341 union {
342 __wsum csum;
663ead3b
HX
343 struct {
344 __u16 csum_start;
345 __u16 csum_offset;
346 };
ff1dcadb 347 };
1da177e4 348 __u32 priority;
1cbb3380
TG
349 __u8 local_df:1,
350 cloned:1,
351 ip_summed:2,
6869c4d8
HW
352 nohdr:1,
353 nfctinfo:3;
d179cd12 354 __u8 pkt_type:3,
b84f4cc9 355 fclone:2,
ba9dda3a 356 ipvs_property:1,
a59322be 357 peeked:1,
ba9dda3a 358 nf_trace:1;
a0d3bea3 359 __be16 protocol;
1da177e4
LT
360
361 void (*destructor)(struct sk_buff *skb);
9fb9cbb1 362#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
5f79e0f9 363 struct nf_conntrack *nfct;
9fb9cbb1
YK
364 struct sk_buff *nfct_reasm;
365#endif
1da177e4
LT
366#ifdef CONFIG_BRIDGE_NETFILTER
367 struct nf_bridge_info *nf_bridge;
368#endif
f25f4e44
PWJ
369
370 int iif;
371 __u16 queue_mapping;
1da177e4 372#ifdef CONFIG_NET_SCHED
b6b99eb5 373 __u16 tc_index; /* traffic control index */
1da177e4 374#ifdef CONFIG_NET_CLS_ACT
b6b99eb5 375 __u16 tc_verd; /* traffic control verdict */
1da177e4 376#endif
1da177e4 377#endif
de357cc0 378#ifdef CONFIG_IPV6_NDISC_NODETYPE
fadf6bf0 379 __u8 ndisc_nodetype:2;
de357cc0 380#endif
d0f09804
JB
381#if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE)
382 __u8 do_not_encrypt:1;
8b30b1fe 383 __u8 requeue:1;
d0f09804
JB
384#endif
385 /* 0/13/14 bit hole */
f25f4e44 386
97fc2f08
CL
387#ifdef CONFIG_NET_DMA
388 dma_cookie_t dma_cookie;
389#endif
984bc16c
JM
390#ifdef CONFIG_NETWORK_SECMARK
391 __u32 secmark;
392#endif
1da177e4 393
82e91ffe 394 __u32 mark;
1da177e4 395
6aa895b0
PM
396 __u16 vlan_tci;
397
27a884dc
ACM
398 sk_buff_data_t transport_header;
399 sk_buff_data_t network_header;
400 sk_buff_data_t mac_header;
1da177e4 401 /* These elements must be at the end, see alloc_skb() for details. */
27a884dc 402 sk_buff_data_t tail;
4305b541 403 sk_buff_data_t end;
1da177e4 404 unsigned char *head,
4305b541 405 *data;
27a884dc
ACM
406 unsigned int truesize;
407 atomic_t users;
1da177e4
LT
408};
409
410#ifdef __KERNEL__
411/*
412 * Handling routines are only of interest to the kernel
413 */
414#include <linux/slab.h>
415
416#include <asm/system.h>
417
a40c24a1
DM
418#ifdef CONFIG_HAS_DMA
419#include <linux/dma-mapping.h>
420extern int skb_dma_map(struct device *dev, struct sk_buff *skb,
421 enum dma_data_direction dir);
422extern void skb_dma_unmap(struct device *dev, struct sk_buff *skb,
423 enum dma_data_direction dir);
424#endif
425