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