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