aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/skbuff.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/skbuff.h')
-rw-r--r--include/linux/skbuff.h182
1 files changed, 152 insertions, 30 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index ae836fded530..77eb60d2b496 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -169,6 +169,7 @@ struct skb_shared_hwtstamps {
169 * @software: generate software time stamp 169 * @software: generate software time stamp
170 * @in_progress: device driver is going to provide 170 * @in_progress: device driver is going to provide
171 * hardware time stamp 171 * hardware time stamp
172 * @prevent_sk_orphan: make sk reference available on driver level
172 * @flags: all shared_tx flags 173 * @flags: all shared_tx flags
173 * 174 *
174 * These flags are attached to packets as part of the 175 * These flags are attached to packets as part of the
@@ -178,7 +179,8 @@ union skb_shared_tx {
178 struct { 179 struct {
179 __u8 hardware:1, 180 __u8 hardware:1,
180 software:1, 181 software:1,
181 in_progress:1; 182 in_progress:1,
183 prevent_sk_orphan:1;
182 }; 184 };
183 __u8 flags; 185 __u8 flags;
184}; 186};
@@ -187,12 +189,8 @@ union skb_shared_tx {
187 * the end of the header data, ie. at skb->end. 189 * the end of the header data, ie. at skb->end.
188 */ 190 */
189struct skb_shared_info { 191struct skb_shared_info {
190 atomic_t dataref;
191 unsigned short nr_frags; 192 unsigned short nr_frags;
192 unsigned short gso_size; 193 unsigned short gso_size;
193#ifdef CONFIG_HAS_DMA
194 dma_addr_t dma_head;
195#endif
196 /* Warning: this field is not always filled in (UFO)! */ 194 /* Warning: this field is not always filled in (UFO)! */
197 unsigned short gso_segs; 195 unsigned short gso_segs;
198 unsigned short gso_type; 196 unsigned short gso_type;
@@ -200,13 +198,17 @@ struct skb_shared_info {
200 union skb_shared_tx tx_flags; 198 union skb_shared_tx tx_flags;
201 struct sk_buff *frag_list; 199 struct sk_buff *frag_list;
202 struct skb_shared_hwtstamps hwtstamps; 200 struct skb_shared_hwtstamps hwtstamps;
203 skb_frag_t frags[MAX_SKB_FRAGS]; 201
204#ifdef CONFIG_HAS_DMA 202 /*
205 dma_addr_t dma_maps[MAX_SKB_FRAGS]; 203 * Warning : all fields before dataref are cleared in __alloc_skb()
206#endif 204 */
205 atomic_t dataref;
206
207 /* Intermediate layers must ensure that destructor_arg 207 /* Intermediate layers must ensure that destructor_arg
208 * remains valid until skb destructor */ 208 * remains valid until skb destructor */
209 void * destructor_arg; 209 void * destructor_arg;
210 /* must be last field, see pskb_expand_head() */
211 skb_frag_t frags[MAX_SKB_FRAGS];
210}; 212};
211 213
212/* We divide dataref into two halves. The higher 16 bits hold references 214/* We divide dataref into two halves. The higher 16 bits hold references
@@ -265,7 +267,7 @@ typedef unsigned char *sk_buff_data_t;
265 * @transport_header: Transport layer header 267 * @transport_header: Transport layer header
266 * @network_header: Network layer header 268 * @network_header: Network layer header
267 * @mac_header: Link layer header 269 * @mac_header: Link layer header
268 * @_skb_dst: destination entry 270 * @_skb_refdst: destination entry (with norefcount bit)
269 * @sp: the security path, used for xfrm 271 * @sp: the security path, used for xfrm
270 * @cb: Control buffer. Free for use by every layer. Put private vars here 272 * @cb: Control buffer. Free for use by every layer. Put private vars here
271 * @len: Length of actual data 273 * @len: Length of actual data
@@ -300,6 +302,7 @@ typedef unsigned char *sk_buff_data_t;
300 * @nfct_reasm: netfilter conntrack re-assembly pointer 302 * @nfct_reasm: netfilter conntrack re-assembly pointer
301 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c 303 * @nf_bridge: Saved data about a bridged frame - see br_netfilter.c
302 * @skb_iif: ifindex of device we arrived on 304 * @skb_iif: ifindex of device we arrived on
305 * @rxhash: the packet hash computed on receive
303 * @queue_mapping: Queue mapping for multiqueue devices 306 * @queue_mapping: Queue mapping for multiqueue devices
304 * @tc_index: Traffic control index 307 * @tc_index: Traffic control index
305 * @tc_verd: traffic control verdict 308 * @tc_verd: traffic control verdict
@@ -315,22 +318,23 @@ struct sk_buff {
315 struct sk_buff *next; 318 struct sk_buff *next;
316 struct sk_buff *prev; 319 struct sk_buff *prev;
317 320
318 struct sock *sk;
319 ktime_t tstamp; 321 ktime_t tstamp;
322
323 struct sock *sk;
320 struct net_device *dev; 324 struct net_device *dev;
321 325
322 unsigned long _skb_dst;
323#ifdef CONFIG_XFRM
324 struct sec_path *sp;
325#endif
326 /* 326 /*
327 * This is the control buffer. It is free to use for every 327 * This is the control buffer. It is free to use for every
328 * layer. Please put your private variables there. If you 328 * layer. Please put your private variables there. If you
329 * want to keep them across layers you have to do a skb_clone() 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. 330 * first. This is owned by whoever has the skb queued ATM.
331 */ 331 */
332 char cb[48]; 332 char cb[48] __aligned(8);
333 333
334 unsigned long _skb_refdst;
335#ifdef CONFIG_XFRM
336 struct sec_path *sp;
337#endif
334 unsigned int len, 338 unsigned int len,
335 data_len; 339 data_len;
336 __u16 mac_len, 340 __u16 mac_len,
@@ -354,8 +358,8 @@ struct sk_buff {
354 ipvs_property:1, 358 ipvs_property:1,
355 peeked:1, 359 peeked:1,
356 nf_trace:1; 360 nf_trace:1;
357 __be16 protocol:16;
358 kmemcheck_bitfield_end(flags1); 361 kmemcheck_bitfield_end(flags1);
362 __be16 protocol;
359 363
360 void (*destructor)(struct sk_buff *skb); 364 void (*destructor)(struct sk_buff *skb);
361#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 365#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
@@ -374,10 +378,15 @@ struct sk_buff {
374#endif 378#endif
375#endif 379#endif
376 380
381 __u32 rxhash;
382
377 kmemcheck_bitfield_begin(flags2); 383 kmemcheck_bitfield_begin(flags2);
378 __u16 queue_mapping:16; 384 __u16 queue_mapping:16;
379#ifdef CONFIG_IPV6_NDISC_NODETYPE 385#ifdef CONFIG_IPV6_NDISC_NODETYPE
380 __u8 ndisc_nodetype:2; 386 __u8 ndisc_nodetype:2,
387 deliver_no_wcard:1;
388#else
389 __u8 deliver_no_wcard:1;
381#endif 390#endif
382 kmemcheck_bitfield_end(flags2); 391 kmemcheck_bitfield_end(flags2);
383 392
@@ -416,14 +425,64 @@ struct sk_buff {
416 425
417#include <asm/system.h> 426#include <asm/system.h>
418 427
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 */
419static inline struct dst_entry *skb_dst(const struct sk_buff *skb) 441static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
420{ 442{
421 return (struct dst_entry *)skb->_skb_dst; 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);
422} 450}
423 451
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 */
424static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst) 460static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
425{ 461{
426 skb->_skb_dst = (unsigned long)dst; 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);
427} 486}
428 487
429static inline struct rtable *skb_rtable(const struct sk_buff *skb) 488static inline struct rtable *skb_rtable(const struct sk_buff *skb)
@@ -448,7 +507,7 @@ static inline struct sk_buff *alloc_skb_fclone(unsigned int size,
448 return __alloc_skb(size, priority, 1, -1); 507 return __alloc_skb(size, priority, 1, -1);
449} 508}
450 509
451extern int skb_recycle_check(struct sk_buff *skb, int skb_size); 510extern bool skb_recycle_check(struct sk_buff *skb, int skb_size);
452 511
453extern struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src); 512extern struct sk_buff *skb_morph(struct sk_buff *dst, struct sk_buff *src);
454extern struct sk_buff *skb_clone(struct sk_buff *skb, 513extern struct sk_buff *skb_clone(struct sk_buff *skb,
@@ -472,11 +531,6 @@ extern int skb_cow_data(struct sk_buff *skb, int tailbits,
472 struct sk_buff **trailer); 531 struct sk_buff **trailer);
473extern int skb_pad(struct sk_buff *skb, int pad); 532extern int skb_pad(struct sk_buff *skb, int pad);
474#define dev_kfree_skb(a) consume_skb(a) 533#define dev_kfree_skb(a) consume_skb(a)
475#define dev_consume_skb(a) kfree_skb_clean(a)
476extern void skb_over_panic(struct sk_buff *skb, int len,
477 void *here);
478extern void skb_under_panic(struct sk_buff *skb, int len,
479 void *here);
480 534
481extern int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb, 535extern int skb_append_datato_frags(struct sock *sk, struct sk_buff *skb,
482 int getfrag(void *from, char *to, int offset, 536 int getfrag(void *from, char *to, int offset,
@@ -738,7 +792,7 @@ static inline struct sk_buff *skb_unshare(struct sk_buff *skb,
738} 792}
739 793
740/** 794/**
741 * skb_peek 795 * skb_peek - peek at the head of an &sk_buff_head
742 * @list_: list to peek at 796 * @list_: list to peek at
743 * 797 *
744 * Peek an &sk_buff. Unlike most other operations you _MUST_ 798 * Peek an &sk_buff. Unlike most other operations you _MUST_
@@ -759,7 +813,7 @@ static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
759} 813}
760 814
761/** 815/**
762 * skb_peek_tail 816 * skb_peek_tail - peek at the tail of an &sk_buff_head
763 * @list_: list to peek at 817 * @list_: list to peek at
764 * 818 *
765 * Peek an &sk_buff. Unlike most other operations you _MUST_ 819 * Peek an &sk_buff. Unlike most other operations you _MUST_
@@ -1135,6 +1189,11 @@ static inline unsigned char *__skb_pull(struct sk_buff *skb, unsigned int len)
1135 return skb->data += len; 1189 return skb->data += len;
1136} 1190}
1137 1191
1192static inline unsigned char *skb_pull_inline(struct sk_buff *skb, unsigned int len)
1193{
1194 return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
1195}
1196
1138extern unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta); 1197extern unsigned char *__pskb_pull_tail(struct sk_buff *skb, int delta);
1139 1198
1140static inline unsigned char *__pskb_pull(struct sk_buff *skb, unsigned int len) 1199static inline unsigned char *__pskb_pull(struct sk_buff *skb, unsigned int len)
@@ -1320,6 +1379,11 @@ static inline int skb_network_offset(const struct sk_buff *skb)
1320 return skb_network_header(skb) - skb->data; 1379 return skb_network_header(skb) - skb->data;
1321} 1380}
1322 1381
1382static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
1383{
1384 return pskb_may_pull(skb, skb_network_offset(skb) + len);
1385}
1386
1323/* 1387/*
1324 * CPUs often take a performance hit when accessing unaligned memory 1388 * CPUs often take a performance hit when accessing unaligned memory
1325 * locations. The actual performance hit varies, it can be small if the 1389 * locations. The actual performance hit varies, it can be small if the
@@ -1358,9 +1422,14 @@ static inline int skb_network_offset(const struct sk_buff *skb)
1358 * 1422 *
1359 * Various parts of the networking layer expect at least 32 bytes of 1423 * Various parts of the networking layer expect at least 32 bytes of
1360 * headroom, you should not reduce this. 1424 * headroom, you should not reduce this.
1425 *
1426 * Using max(32, L1_CACHE_BYTES) makes sense (especially with RPS)
1427 * to reduce average number of cache lines per packet.
1428 * get_rps_cpus() for example only access one 64 bytes aligned block :
1429 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
1361 */ 1430 */
1362#ifndef NET_SKB_PAD 1431#ifndef NET_SKB_PAD
1363#define NET_SKB_PAD 32 1432#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
1364#endif 1433#endif
1365 1434
1366extern int ___pskb_trim(struct sk_buff *skb, unsigned int len); 1435extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
@@ -1872,6 +1941,36 @@ static inline ktime_t net_invalid_timestamp(void)
1872 return ktime_set(0, 0); 1941 return ktime_set(0, 0);
1873} 1942}
1874 1943
1944extern void skb_timestamping_init(void);
1945
1946#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
1947
1948extern void skb_clone_tx_timestamp(struct sk_buff *skb);
1949extern bool skb_defer_rx_timestamp(struct sk_buff *skb);
1950
1951#else /* CONFIG_NETWORK_PHY_TIMESTAMPING */
1952
1953static inline void skb_clone_tx_timestamp(struct sk_buff *skb)
1954{
1955}
1956
1957static inline bool skb_defer_rx_timestamp(struct sk_buff *skb)
1958{
1959 return false;
1960}
1961
1962#endif /* !CONFIG_NETWORK_PHY_TIMESTAMPING */
1963
1964/**
1965 * skb_complete_tx_timestamp() - deliver cloned skb with tx timestamps
1966 *
1967 * @skb: clone of the the original outgoing packet
1968 * @hwtstamps: hardware time stamps
1969 *
1970 */
1971void skb_complete_tx_timestamp(struct sk_buff *skb,
1972 struct skb_shared_hwtstamps *hwtstamps);
1973
1875/** 1974/**
1876 * skb_tstamp_tx - queue clone of skb with send time stamps 1975 * skb_tstamp_tx - queue clone of skb with send time stamps
1877 * @orig_skb: the original outgoing packet 1976 * @orig_skb: the original outgoing packet
@@ -1886,6 +1985,28 @@ static inline ktime_t net_invalid_timestamp(void)
1886extern void skb_tstamp_tx(struct sk_buff *orig_skb, 1985extern void skb_tstamp_tx(struct sk_buff *orig_skb,
1887 struct skb_shared_hwtstamps *hwtstamps); 1986 struct skb_shared_hwtstamps *hwtstamps);
1888 1987
1988static inline void sw_tx_timestamp(struct sk_buff *skb)
1989{
1990 union skb_shared_tx *shtx = skb_tx(skb);
1991 if (shtx->software && !shtx->in_progress)
1992 skb_tstamp_tx(skb, NULL);
1993}
1994
1995/**
1996 * skb_tx_timestamp() - Driver hook for transmit timestamping
1997 *
1998 * Ethernet MAC Drivers should call this function in their hard_xmit()
1999 * function as soon as possible after giving the sk_buff to the MAC
2000 * hardware, but before freeing the sk_buff.
2001 *
2002 * @skb: A socket buffer.
2003 */
2004static inline void skb_tx_timestamp(struct sk_buff *skb)
2005{
2006 skb_clone_tx_timestamp(skb);
2007 sw_tx_timestamp(skb);
2008}
2009
1889extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len); 2010extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len);
1890extern __sum16 __skb_checksum_complete(struct sk_buff *skb); 2011extern __sum16 __skb_checksum_complete(struct sk_buff *skb);
1891 2012
@@ -2073,7 +2194,8 @@ static inline bool skb_warn_if_lro(const struct sk_buff *skb)
2073 /* LRO sets gso_size but not gso_type, whereas if GSO is really 2194 /* LRO sets gso_size but not gso_type, whereas if GSO is really
2074 * wanted then gso_type will be set. */ 2195 * wanted then gso_type will be set. */
2075 struct skb_shared_info *shinfo = skb_shinfo(skb); 2196 struct skb_shared_info *shinfo = skb_shinfo(skb);
2076 if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) { 2197 if (skb_is_nonlinear(skb) && shinfo->gso_size != 0 &&
2198 unlikely(shinfo->gso_type == 0)) {
2077 __skb_warn_lro_forwarding(skb); 2199 __skb_warn_lro_forwarding(skb);
2078 return true; 2200 return true;
2079 } 2201 }