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