]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/skbuff.h
drivers/net/sunvnet.c: Use pr_<level> and netdev_<level>
[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 17#include <linux/kernel.h>
fe55f6d5 18#include <linux/kmemcheck.h>
1da177e4
LT
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>
1da177e4 26#include <linux/net.h>
3fc7e8a6 27#include <linux/textsearch.h>
1da177e4 28#include <net/checksum.h>
a80958f4 29#include <linux/rcupdate.h>
97fc2f08 30#include <linux/dmaengine.h>
b7aa0bf7 31#include <linux/hrtimer.h>
1da177e4 32
60476372 33/* Don't change this without changing skb_csum_unnecessary! */
1da177e4 34#define CHECKSUM_NONE 0
60476372
HX
35#define CHECKSUM_UNNECESSARY 1
36#define CHECKSUM_COMPLETE 2
37#define CHECKSUM_PARTIAL 3
1da177e4
LT
38
39#define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \
40 ~(SMP_CACHE_BYTES - 1))
fc910a27 41#define SKB_WITH_OVERHEAD(X) \
deea84b0 42 ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
fc910a27
DM
43#define SKB_MAX_ORDER(X, ORDER) \
44 SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X))
1da177e4
LT
45#define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0))
46#define SKB_MAX_ALLOC (SKB_MAX_ORDER(0, 2))
47
48/* A. Checksumming of received packets by device.
49 *
50 * NONE: device failed to checksum this packet.
51 * skb->csum is undefined.
52 *
53 * UNNECESSARY: device parsed packet and wouldbe verified checksum.
54 * skb->csum is undefined.
55 * It is bad option, but, unfortunately, many of vendors do this.
56 * Apparently with secret goal to sell you new device, when you
57 * will add new protocol to your host. F.e. IPv6. 8)
58 *
84fa7933 59 * COMPLETE: the most generic way. Device supplied checksum of _all_
1da177e4
LT
60 * the packet as seen by netif_rx in skb->csum.
61 * NOTE: Even if device supports only some protocols, but
84fa7933 62 * is able to produce some skb->csum, it MUST use COMPLETE,
1da177e4
LT
63 * not UNNECESSARY.
64 *
c6c6e3e0
HX
65 * PARTIAL: identical to the case for output below. This may occur
66 * on a packet received directly from another Linux OS, e.g.,
67 * a virtualised Linux kernel on the same host. The packet can
68 * be treated in the same way as UNNECESSARY except that on
69 * output (i.e., forwarding) the checksum must be filled in
70 * by the OS or the hardware.
71 *
1da177e4
LT
72 * B. Checksumming on output.
73 *
74 * NONE: skb is checksummed by protocol or csum is not required.
75 *
84fa7933 76 * PARTIAL: device is required to csum packet as seen by hard_start_xmit
c6c6e3e0
HX
77 * from skb->csum_start to the end and to record the checksum
78 * at skb->csum_start + skb->csum_offset.
1da177e4
LT
79 *
80 * Device must show its capabilities in dev->features, set
81 * at device setup time.
82 * NETIF_F_HW_CSUM - it is clever device, it is able to checksum
83 * everything.
84 * NETIF_F_NO_CSUM - loopback or reliable single hop media.
85 * NETIF_F_IP_CSUM - device is dumb. It is able to csum only
86 * TCP/UDP over IPv4. Sigh. Vendors like this
87 * way by an unknown reason. Though, see comment above
88 * about CHECKSUM_UNNECESSARY. 8)
c6c6e3e0 89 * NETIF_F_IPV6_CSUM about as dumb as the last one but does IPv6 instead.
1da177e4
LT
90 *
91 * Any questions? No questions, good. --ANK
92 */
93
1da177e4 94struct net_device;
716ea3a7 95struct scatterlist;
9c55e01c 96struct pipe_inode_info;
1da177e4 97
5f79e0f9 98#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1da177e4
LT
99struct nf_conntrack {
100 atomic_t use;
1da177e4 101};
5f79e0f9 102#endif
1da177e4
LT
103
104#ifdef CONFIG_BRIDGE_NETFILTER
105struct nf_bridge_info {
106 atomic_t use;
107 struct net_device *physindev;
108 struct net_device *physoutdev;
1da177e4
LT
109 unsigned int mask;
110 unsigned long data[32 / sizeof(unsigned long)];
111};
112#endif
113
1da177e4
LT
114struct sk_buff_head {
115 /* These two members must be first. */
116 struct sk_buff *next;
117 struct sk_buff *prev;
118
119 __u32 qlen;
120 spinlock_t lock;
121};
122
123struct sk_buff;
124
125/* To allow 64K frame to be packed as single skb without frag_list */
126#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 2)
127
128typedef struct skb_frag_struct skb_frag_t;
129
130struct skb_frag_struct {
131 struct page *page;
a309bb07
DM
132 __u32 page_offset;
133 __u32 size;
1da177e4
LT
134};
135
ac45f602
PO
136#define HAVE_HW_TIME_STAMP
137
138/**
d3a21be8 139 * struct skb_shared_hwtstamps - hardware time stamps
ac45f602
PO
140 * @hwtstamp: hardware time stamp transformed into duration
141 * since arbitrary point in time
142 * @syststamp: hwtstamp transformed to system time base
143 *
144 * Software time stamps generated by ktime_get_real() are stored in
145 * skb->tstamp. The relation between the different kinds of time
146 * stamps is as follows:
147 *
148 * syststamp and tstamp can be compared against each other in
149 * arbitrary combinations. The accuracy of a
150 * syststamp/tstamp/"syststamp from other device" comparison is
151 * limited by the accuracy of the transformation into system time
152 * base. This depends on the device driver and its underlying
153 * hardware.
154 *
155 * hwtstamps can only be compared against other hwtstamps from
156 * the same device.
157 *
158 * This structure is attached to packets as part of the
159 * &skb_shared_info. Use skb_hwtstamps() to get a pointer.
160 */
161struct skb_shared_hwtstamps {
162 ktime_t hwtstamp;
163 ktime_t syststamp;
164};
165
166/**
d3a21be8 167 * struct skb_shared_tx - instructions for time stamping of outgoing packets
ac45f602
PO
168 * @hardware: generate hardware time stamp
169 * @software: generate software time stamp
170 * @in_progress: device driver is going to provide
171 * hardware time stamp
cff0d6e6 172 * @prevent_sk_orphan: make sk reference available on driver level
4b21cd4e 173 * @flags: all shared_tx flags
ac45f602
PO
174 *
175 * These flags are attached to packets as part of the
176 * &skb_shared_info. Use skb_tx() to get a pointer.
177 */
178union skb_shared_tx {
179 struct {
180 __u8 hardware:1,
181 software:1,
cff0d6e6
OH
182 in_progress:1,
183 prevent_sk_orphan:1;
ac45f602
PO
184 };
185 __u8 flags;
186};
187
1da177e4
LT
188/* This data is invariant across clones and lives at
189 * the end of the header data, ie. at skb->end.
190 */
191struct skb_shared_info {
4947d3ef 192 unsigned short nr_frags;
7967168c
HX
193 unsigned short gso_size;
194 /* Warning: this field is not always filled in (UFO)! */
195 unsigned short gso_segs;
196 unsigned short gso_type;
ae08e1f0 197 __be32 ip6_frag_id;
ac45f602 198 union skb_shared_tx tx_flags;
1da177e4 199 struct sk_buff *frag_list;
ac45f602 200 struct skb_shared_hwtstamps hwtstamps;
ec7d2f2c
ED
201
202 /*
203 * Warning : all fields before dataref are cleared in __alloc_skb()
204 */
205 atomic_t dataref;
206
69e3c75f
JB
207 /* Intermediate layers must ensure that destructor_arg
208 * remains valid until skb destructor */
209 void * destructor_arg;
fed66381
ED
210 /* must be last field, see pskb_expand_head() */
211 skb_frag_t frags[MAX_SKB_FRAGS];
1da177e4
LT
212};
213
214/* We divide dataref into two halves. The higher 16 bits hold references
215 * to the payload part of skb->data. The lower 16 bits hold references to
334a8132
PM
216 * the entire skb->data. A clone of a headerless skb holds the length of
217 * the header in skb->hdr_len.
1da177e4
LT
218 *
219 * All users must obey the rule that the skb->data reference count must be
220 * greater than or equal to the payload reference count.
221 *
222 * Holding a reference to the payload part means that the user does not
223 * care about modifications to the header part of skb->data.
224 */
225#define SKB_DATAREF_SHIFT 16
226#define SKB_DATAREF_MASK ((1 << SKB_DATAREF_SHIFT) - 1)
227
d179cd12
DM
228
229enum {
230 SKB_FCLONE_UNAVAILABLE,
231 SKB_FCLONE_ORIG,
232 SKB_FCLONE_CLONE,
233};
234
7967168c
HX
235enum {
236 SKB_GSO_TCPV4 = 1 << 0,
f83ef8c0 237 SKB_GSO_UDP = 1 << 1,
576a30eb
HX
238
239 /* This indicates the skb is from an untrusted source. */
240 SKB_GSO_DODGY = 1 << 2,
b0da8537
MC
241
242 /* This indicates the tcp segment has CWR set. */
f83ef8c0
HX
243 SKB_GSO_TCP_ECN = 1 << 3,
244
245 SKB_GSO_TCPV6 = 1 << 4,
01d5b2fc
CL
246
247 SKB_GSO_FCOE = 1 << 5,
7967168c
HX
248};
249
2e07fa9c
ACM
250#if BITS_PER_LONG > 32
251#define NET_SKBUFF_DATA_USES_OFFSET 1
252#endif
253
254#ifdef NET_SKBUFF_DATA_USES_OFFSET
255typedef unsigned int sk_buff_data_t;
256#else
257typedef unsigned char *sk_buff_data_t;
258#endif
259
1da177e4
LT
260/**
261 * struct sk_buff - socket buffer
262 * @next: Next buffer in list
263 * @prev: Previous buffer in list
1da177e4 264 * @sk: Socket we are owned by
325ed823 265 * @tstamp: Time we arrived
1da177e4 266 * @dev: Device we arrived on/are leaving by
be52178b 267 * @transport_header: Transport layer header
b0e380b1
ACM
268 * @network_header: Network layer header
269 * @mac_header: Link layer header
7fee226a 270 * @_skb_refdst: destination entry (with norefcount bit)
67be2dd1 271 * @sp: the security path, used for xfrm
1da177e4
LT
272 * @cb: Control buffer. Free for use by every layer. Put private vars here
273 * @len: Length of actual data
274 * @data_len: Data length
275 * @mac_len: Length of link layer header
334a8132 276 * @hdr_len: writable header length of cloned skb
663ead3b
HX
277 * @csum: Checksum (must include start/offset pair)
278 * @csum_start: Offset from skb->head where checksumming should start
279 * @csum_offset: Offset from csum_start where checksum should be stored
67be2dd1 280 * @local_df: allow local fragmentation
1da177e4
LT
281 * @cloned: Head may be cloned (check refcnt to be sure)
282 * @nohdr: Payload reference only, must not modify header
283 * @pkt_type: Packet class
c83c2486 284 * @fclone: skbuff clone status
1da177e4
LT
285 * @ip_summed: Driver fed us an IP checksum
286 * @priority: Packet queueing priority
287 * @users: User count - see {datagram,tcp}.c
288 * @protocol: Packet protocol from driver
1da177e4
LT
289 * @truesize: Buffer size
290 * @head: Head of buffer
291 * @data: Data head pointer
292 * @tail: Tail pointer
293 * @end: End pointer
294 * @destructor: Destruct function
82e91ffe 295 * @mark: Generic packet mark
1da177e4 296 * @nfct: Associated connection, if any
c83c2486 297 * @ipvs_property: skbuff is owned by ipvs
31729363
RD
298 * @peeked: this packet has been seen already, so stats have been
299 * done for it, don't do them again
ba9dda3a 300 * @nf_trace: netfilter packet trace flag
1da177e4 301 * @nfctinfo: Relationship of this skb to the connection
461ddf3b 302 * @nfct_reasm: netfilter conntrack re-assembly pointer
1da177e4 303 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
8964be4a 304 * @skb_iif: ifindex of device we arrived on
0a9627f2 305 * @rxhash: the packet hash computed on receive
f25f4e44 306 * @queue_mapping: Queue mapping for multiqueue devices
1da177e4
LT
307 * @tc_index: Traffic control index
308 * @tc_verd: traffic control verdict
553a5672 309 * @ndisc_nodetype: router type (from link layer)
f4b8ea78
RD
310 * @dma_cookie: a cookie to one of several possible DMA operations
311 * done by skb DMA functions
984bc16c 312 * @secmark: security marking
6aa895b0 313 * @vlan_tci: vlan tag control information
1da177e4
LT
314 */
315
316struct sk_buff {
317 /* These two members must be first. */
318 struct sk_buff *next;
319 struct sk_buff *prev;
320
b7aa0bf7 321 ktime_t tstamp;
da3f5cf1
FF
322
323 struct sock *sk;
1da177e4 324 struct net_device *dev;
1da177e4 325
1da177e4
LT
326 /*
327 * This is the control buffer. It is free to use for every
328 * layer. Please put your private variables there. If you
329 * want to keep them across layers you have to do a skb_clone()
330 * first. This is owned by whoever has the skb queued ATM.
331 */
da3f5cf1 332 char cb[48] __aligned(8);
1da177e4 333
7fee226a 334 unsigned long _skb_refdst;
da3f5cf1
FF
335#ifdef CONFIG_XFRM
336 struct sec_path *sp;
337#endif
1da177e4 338 unsigned int len,
334a8132
PM
339 data_len;
340 __u16 mac_len,
341 hdr_len;
ff1dcadb
AV
342 union {
343 __wsum csum;
663ead3b
HX
344 struct {
345 __u16 csum_start;
346 __u16 csum_offset;
347 };
ff1dcadb 348 };
1da177e4 349 __u32 priority;
fe55f6d5 350 kmemcheck_bitfield_begin(flags1);
1cbb3380
TG
351 __u8 local_df:1,
352 cloned:1,
353 ip_summed:2,
6869c4d8
HW
354 nohdr:1,
355 nfctinfo:3;
d179cd12 356 __u8 pkt_type:3,
b84f4cc9 357 fclone:2,
ba9dda3a 358 ipvs_property:1,
a59322be 359 peeked:1,
ba9dda3a 360 nf_trace:1;
fe55f6d5 361 kmemcheck_bitfield_end(flags1);
4ab408de 362 __be16 protocol;
1da177e4
LT
363
364 void (*destructor)(struct sk_buff *skb);
9fb9cbb1 365#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
5f79e0f9 366 struct nf_conntrack *nfct;
9fb9cbb1
YK
367 struct sk_buff *nfct_reasm;
368#endif
1da177e4
LT
369#ifdef CONFIG_BRIDGE_NETFILTER
370 struct nf_bridge_info *nf_bridge;
371#endif
f25f4e44 372
8964be4a 373 int skb_iif;
1da177e4 374#ifdef CONFIG_NET_SCHED
b6b99eb5 375 __u16 tc_index; /* traffic control index */
1da177e4 376#ifdef CONFIG_NET_CLS_ACT
b6b99eb5 377 __u16 tc_verd; /* traffic control verdict */
1da177e4 378#endif
1da177e4 379#endif
fe55f6d5 380
0a9627f2
TH
381 __u32 rxhash;
382
fe55f6d5 383 kmemcheck_bitfield_begin(flags2);
14d18a81 384 __u16 queue_mapping:16;
de357cc0 385#ifdef CONFIG_IPV6_NDISC_NODETYPE
597a264b
JF
386 __u8 ndisc_nodetype:2,
387 deliver_no_wcard:1;
388#else
389 __u8 deliver_no_wcard:1;
d0f09804 390#endif
fe55f6d5
VN
391 kmemcheck_bitfield_end(flags2);
392
72bce627 393 /* 0/14 bit hole */
f25f4e44 394
97fc2f08
CL
395#ifdef CONFIG_NET_DMA
396 dma_cookie_t dma_cookie;
397#endif
984bc16c
JM
398#ifdef CONFIG_NETWORK_SECMARK
399 __u32 secmark;
400#endif
3b885787
NH
401 union {
402 __u32 mark;
403 __u32 dropcount;
404 };
1da177e4 405
6aa895b0
PM
406 __u16 vlan_tci;
407
27a884dc
ACM
408 sk_buff_data_t transport_header;
409 sk_buff_data_t network_header;
410 sk_buff_data_t mac_header;
1da177e4 411 /* These elements must be at the end, see alloc_skb() for details. */
27a884dc 412 sk_buff_data_t tail;
4305b541 413 sk_buff_data_t end;
1da177e4 414 unsigned char *head,
4305b541 415 *data;
27a884dc
ACM
416 unsigned int truesize;
417 atomic_t users;
1da177e4
LT
418};
419
420#ifdef __KERNEL__
421/*
422 * Handling routines are only of interest to the kernel
423 */
424#include <linux/slab.h>
425
426#include <asm/system.h>
427
7fee226a
ED
428/*
429 * skb might have a dst pointer attached, refcounted or not.
430 * _skb_refdst low order bit is set if refcount was _not_ taken
431 */
432#define SKB_DST_NOREF 1UL
433#define SKB_DST_PTRMASK ~(SKB_DST_NOREF)
434
435/**
436 * skb_dst - returns skb dst_entry
437 * @skb: buffer
438 *
439 * Returns skb dst_entry, regardless of reference taken or not.
440 */
adf30907
ED
441static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
442{
7fee226a
ED
443 /* If refdst was not refcounted, check we still are in a
444 * rcu_read_lock section
445 */
446 WARN_ON((skb->_skb_refdst & SKB_DST_NOREF) &&
447 !rcu_read_lock_held() &&
448 !rcu_read_lock_bh_held());
449 return (struct dst_entry *)(skb->_skb_refdst & SKB_DST_PTRMASK);
adf30907
ED
450}
451
7fee226a
ED
452/**
453 * skb_dst_set - sets skb dst
454 * @skb: buffer
455 * @dst: dst entry
456 *
457 * Sets skb dst, assuming a reference was taken on dst and should
458 * be released by skb_dst_drop()
459 */
adf30907
ED
460static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
461{
7fee226a
ED
462 skb->_skb_refdst = (unsigned long)dst;
463}
464
465/**
466 * skb_dst_set_noref - sets skb dst, without a reference
467 * @skb: buffer
468 * @dst: dst entry
469 *
470 * Sets skb dst, assuming a reference was not taken on dst
471 * skb_dst_drop() should not dst_release() this dst
472 */
473static inline void skb_dst_set_noref(struct sk_buff *skb, struct dst_entry *dst)
474{
475 WARN_ON(!rcu_read_lock_held() && !rcu_read_lock_bh_held());
476 skb->_skb_refdst = (unsigned long)dst | SKB_DST_NOREF;
477}
478
479/**
480 * skb_dst_is_noref - Test if skb dst isnt refcounted
481 * @skb: buffer
482 */
483static inline bool skb_dst_is_noref(const struct sk_buff *skb)
484{
485 return (skb->_skb_refdst & SKB_DST_NOREF) && skb_dst(skb);
adf30907
ED
486}
487
511c3f92
ED
488static inline struct rtable *skb_rtable(const struct sk_buff *skb)
489{
adf30907 490 return (struct rtable *)skb_dst(skb);
511c3f92
ED
491}
492