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.h159
1 files changed, 129 insertions, 30 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index abde271c18ae..f1bfa3781c75 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -47,11 +47,29 @@
47 * 47 *
48 * The hardware you're dealing with doesn't calculate the full checksum 48 * The hardware you're dealing with doesn't calculate the full checksum
49 * (as in CHECKSUM_COMPLETE), but it does parse headers and verify checksums 49 * (as in CHECKSUM_COMPLETE), but it does parse headers and verify checksums
50 * for specific protocols e.g. TCP/UDP/SCTP, then, for such packets it will 50 * for specific protocols. For such packets it will set CHECKSUM_UNNECESSARY
51 * set CHECKSUM_UNNECESSARY if their checksums are okay. skb->csum is still 51 * if their checksums are okay. skb->csum is still undefined in this case
52 * undefined in this case though. It is a bad option, but, unfortunately, 52 * though. It is a bad option, but, unfortunately, nowadays most vendors do
53 * nowadays most vendors do this. Apparently with the secret goal to sell 53 * this. Apparently with the secret goal to sell you new devices, when you
54 * you new devices, when you will add new protocol to your host, f.e. IPv6 8) 54 * will add new protocol to your host, f.e. IPv6 8)
55 *
56 * CHECKSUM_UNNECESSARY is applicable to following protocols:
57 * TCP: IPv6 and IPv4.
58 * UDP: IPv4 and IPv6. A device may apply CHECKSUM_UNNECESSARY to a
59 * zero UDP checksum for either IPv4 or IPv6, the networking stack
60 * may perform further validation in this case.
61 * GRE: only if the checksum is present in the header.
62 * SCTP: indicates the CRC in SCTP header has been validated.
63 *
64 * skb->csum_level indicates the number of consecutive checksums found in
65 * the packet minus one that have been verified as CHECKSUM_UNNECESSARY.
66 * For instance if a device receives an IPv6->UDP->GRE->IPv4->TCP packet
67 * and a device is able to verify the checksums for UDP (possibly zero),
68 * GRE (checksum flag is set), and TCP-- skb->csum_level would be set to
69 * two. If the device were only able to verify the UDP checksum and not
70 * GRE, either because it doesn't support GRE checksum of because GRE
71 * checksum is bad, skb->csum_level would be set to zero (TCP checksum is
72 * not considered in this case).
55 * 73 *
56 * CHECKSUM_COMPLETE: 74 * CHECKSUM_COMPLETE:
57 * 75 *
@@ -112,6 +130,9 @@
112#define CHECKSUM_COMPLETE 2 130#define CHECKSUM_COMPLETE 2
113#define CHECKSUM_PARTIAL 3 131#define CHECKSUM_PARTIAL 3
114 132
133/* Maximum value in skb->csum_level */
134#define SKB_MAX_CSUM_LEVEL 3
135
115#define SKB_DATA_ALIGN(X) ALIGN(X, SMP_CACHE_BYTES) 136#define SKB_DATA_ALIGN(X) ALIGN(X, SMP_CACHE_BYTES)
116#define SKB_WITH_OVERHEAD(X) \ 137#define SKB_WITH_OVERHEAD(X) \
117 ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) 138 ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
@@ -452,6 +473,7 @@ static inline u32 skb_mstamp_us_delta(const struct skb_mstamp *t1,
452 * @tc_verd: traffic control verdict 473 * @tc_verd: traffic control verdict
453 * @hash: the packet hash 474 * @hash: the packet hash
454 * @queue_mapping: Queue mapping for multiqueue devices 475 * @queue_mapping: Queue mapping for multiqueue devices
476 * @xmit_more: More SKBs are pending for this queue
455 * @ndisc_nodetype: router type (from link layer) 477 * @ndisc_nodetype: router type (from link layer)
456 * @ooo_okay: allow the mapping of a socket to a queue to be changed 478 * @ooo_okay: allow the mapping of a socket to a queue to be changed
457 * @l4_hash: indicate hash is a canonical 4-tuple hash over transport 479 * @l4_hash: indicate hash is a canonical 4-tuple hash over transport
@@ -526,6 +548,16 @@ struct sk_buff {
526 ip_summed:2, 548 ip_summed:2,
527 nohdr:1, 549 nohdr:1,
528 nfctinfo:3; 550 nfctinfo:3;
551
552/* if you move pkt_type around you also must adapt those constants */
553#ifdef __BIG_ENDIAN_BITFIELD
554#define PKT_TYPE_MAX (7 << 5)
555#else
556#define PKT_TYPE_MAX 7
557#endif
558#define PKT_TYPE_OFFSET() offsetof(struct sk_buff, __pkt_type_offset)
559
560 __u8 __pkt_type_offset[0];
529 __u8 pkt_type:3, 561 __u8 pkt_type:3,
530 fclone:2, 562 fclone:2,
531 ipvs_property:1, 563 ipvs_property:1,
@@ -558,6 +590,7 @@ struct sk_buff {
558 590
559 __u16 queue_mapping; 591 __u16 queue_mapping;
560 kmemcheck_bitfield_begin(flags2); 592 kmemcheck_bitfield_begin(flags2);
593 __u8 xmit_more:1;
561#ifdef CONFIG_IPV6_NDISC_NODETYPE 594#ifdef CONFIG_IPV6_NDISC_NODETYPE
562 __u8 ndisc_nodetype:2; 595 __u8 ndisc_nodetype:2;
563#endif 596#endif
@@ -569,16 +602,12 @@ struct sk_buff {
569 __u8 wifi_acked:1; 602 __u8 wifi_acked:1;
570 __u8 no_fcs:1; 603 __u8 no_fcs:1;
571 __u8 head_frag:1; 604 __u8 head_frag:1;
572 /* Encapsulation protocol and NIC drivers should use 605 /* Indicates the inner headers are valid in the skbuff. */
573 * this flag to indicate to each other if the skb contains
574 * encapsulated packet or not and maybe use the inner packet
575 * headers if needed
576 */
577 __u8 encapsulation:1; 606 __u8 encapsulation:1;
578 __u8 encap_hdr_csum:1; 607 __u8 encap_hdr_csum:1;
579 __u8 csum_valid:1; 608 __u8 csum_valid:1;
580 __u8 csum_complete_sw:1; 609 __u8 csum_complete_sw:1;
581 /* 2/4 bit hole (depending on ndisc_nodetype presence) */ 610 /* 1/3 bit hole (depending on ndisc_nodetype presence) */
582 kmemcheck_bitfield_end(flags2); 611 kmemcheck_bitfield_end(flags2);
583 612
584#if defined CONFIG_NET_DMA || defined CONFIG_NET_RX_BUSY_POLL 613#if defined CONFIG_NET_DMA || defined CONFIG_NET_RX_BUSY_POLL
@@ -596,6 +625,12 @@ struct sk_buff {
596 __u32 reserved_tailroom; 625 __u32 reserved_tailroom;
597 }; 626 };
598 627
628 kmemcheck_bitfield_begin(flags3);
629 __u8 csum_level:2;
630 __u8 csum_bad:1;
631 /* 13 bit hole */
632 kmemcheck_bitfield_end(flags3);
633
599 __be16 inner_protocol; 634 __be16 inner_protocol;
600 __u16 inner_transport_header; 635 __u16 inner_transport_header;
601 __u16 inner_network_header; 636 __u16 inner_network_header;
@@ -734,6 +769,12 @@ static inline struct sk_buff *alloc_skb(unsigned int size,
734 return __alloc_skb(size, priority, 0, NUMA_NO_NODE); 769 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
735} 770}
736 771
772struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
773 unsigned long data_len,
774 int max_page_order,
775 int *errcode,
776 gfp_t gfp_mask);
777
737static inline struct sk_buff *alloc_skb_fclone(unsigned int size, 778static inline struct sk_buff *alloc_skb_fclone(unsigned int size,
738 gfp_t priority) 779 gfp_t priority)
739{ 780{
@@ -1860,18 +1901,6 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
1860 return pskb_may_pull(skb, skb_network_offset(skb) + len); 1901 return pskb_may_pull(skb, skb_network_offset(skb) + len);
1861} 1902}
1862 1903
1863static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
1864{
1865 /* Only continue with checksum unnecessary if device indicated
1866 * it is valid across encapsulation (skb->encapsulation was set).
1867 */
1868 if (skb->ip_summed == CHECKSUM_UNNECESSARY && !skb->encapsulation)
1869 skb->ip_summed = CHECKSUM_NONE;
1870
1871 skb->encapsulation = 0;
1872 skb->csum_valid = 0;
1873}
1874
1875/* 1904/*
1876 * CPUs often take a performance hit when accessing unaligned memory 1905 * CPUs often take a performance hit when accessing unaligned memory
1877 * locations. The actual performance hit varies, it can be small if the 1906 * locations. The actual performance hit varies, it can be small if the
@@ -2567,20 +2596,26 @@ __wsum __skb_checksum(const struct sk_buff *skb, int offset, int len,
2567__wsum skb_checksum(const struct sk_buff *skb, int offset, int len, 2596__wsum skb_checksum(const struct sk_buff *skb, int offset, int len,
2568 __wsum csum); 2597 __wsum csum);
2569 2598
2570static inline void *skb_header_pointer(const struct sk_buff *skb, int offset, 2599static inline void *__skb_header_pointer(const struct sk_buff *skb, int offset,
2571 int len, void *buffer) 2600 int len, void *data, int hlen, void *buffer)
2572{ 2601{
2573 int hlen = skb_headlen(skb);
2574
2575 if (hlen - offset >= len) 2602 if (hlen - offset >= len)
2576 return skb->data + offset; 2603 return data + offset;
2577 2604
2578 if (skb_copy_bits(skb, offset, buffer, len) < 0) 2605 if (!skb ||
2606 skb_copy_bits(skb, offset, buffer, len) < 0)
2579 return NULL; 2607 return NULL;
2580 2608
2581 return buffer; 2609 return buffer;
2582} 2610}
2583 2611
2612static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
2613 int len, void *buffer)
2614{
2615 return __skb_header_pointer(skb, offset, len, skb->data,
2616 skb_headlen(skb), buffer);
2617}
2618
2584/** 2619/**
2585 * skb_needs_linearize - check if we need to linearize a given skb 2620 * skb_needs_linearize - check if we need to linearize a given skb
2586 * depending on the given device features. 2621 * depending on the given device features.
@@ -2671,6 +2706,8 @@ static inline ktime_t net_invalid_timestamp(void)
2671 return ktime_set(0, 0); 2706 return ktime_set(0, 0);
2672} 2707}
2673 2708
2709struct sk_buff *skb_clone_sk(struct sk_buff *skb);
2710
2674#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING 2711#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
2675 2712
2676void skb_clone_tx_timestamp(struct sk_buff *skb); 2713void skb_clone_tx_timestamp(struct sk_buff *skb);
@@ -2786,6 +2823,42 @@ static inline __sum16 skb_checksum_complete(struct sk_buff *skb)
2786 0 : __skb_checksum_complete(skb); 2823 0 : __skb_checksum_complete(skb);
2787} 2824}
2788 2825
2826static inline void __skb_decr_checksum_unnecessary(struct sk_buff *skb)
2827{
2828 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
2829 if (skb->csum_level == 0)
2830 skb->ip_summed = CHECKSUM_NONE;
2831 else
2832 skb->csum_level--;
2833 }
2834}
2835
2836static inline void __skb_incr_checksum_unnecessary(struct sk_buff *skb)
2837{
2838 if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
2839 if (skb->csum_level < SKB_MAX_CSUM_LEVEL)
2840 skb->csum_level++;
2841 } else if (skb->ip_summed == CHECKSUM_NONE) {
2842 skb->ip_summed = CHECKSUM_UNNECESSARY;
2843 skb->csum_level = 0;
2844 }
2845}
2846
2847static inline void __skb_mark_checksum_bad(struct sk_buff *skb)
2848{
2849 /* Mark current checksum as bad (typically called from GRO
2850 * path). In the case that ip_summed is CHECKSUM_NONE
2851 * this must be the first checksum encountered in the packet.
2852 * When ip_summed is CHECKSUM_UNNECESSARY, this is the first
2853 * checksum after the last one validated. For UDP, a zero
2854 * checksum can not be marked as bad.
2855 */
2856
2857 if (skb->ip_summed == CHECKSUM_NONE ||
2858 skb->ip_summed == CHECKSUM_UNNECESSARY)
2859 skb->csum_bad = 1;
2860}
2861
2789/* Check if we need to perform checksum complete validation. 2862/* Check if we need to perform checksum complete validation.
2790 * 2863 *
2791 * Returns true if checksum complete is needed, false otherwise 2864 * Returns true if checksum complete is needed, false otherwise
@@ -2797,6 +2870,7 @@ static inline bool __skb_checksum_validate_needed(struct sk_buff *skb,
2797{ 2870{
2798 if (skb_csum_unnecessary(skb) || (zero_okay && !check)) { 2871 if (skb_csum_unnecessary(skb) || (zero_okay && !check)) {
2799 skb->csum_valid = 1; 2872 skb->csum_valid = 1;
2873 __skb_decr_checksum_unnecessary(skb);
2800 return false; 2874 return false;
2801 } 2875 }
2802 2876
@@ -2826,6 +2900,9 @@ static inline __sum16 __skb_checksum_validate_complete(struct sk_buff *skb,
2826 skb->csum_valid = 1; 2900 skb->csum_valid = 1;
2827 return 0; 2901 return 0;
2828 } 2902 }
2903 } else if (skb->csum_bad) {
2904 /* ip_summed == CHECKSUM_NONE in this case */
2905 return 1;
2829 } 2906 }
2830 2907
2831 skb->csum = psum; 2908 skb->csum = psum;
@@ -2883,6 +2960,26 @@ static inline __wsum null_compute_pseudo(struct sk_buff *skb, int proto)
2883#define skb_checksum_simple_validate(skb) \ 2960#define skb_checksum_simple_validate(skb) \
2884 __skb_checksum_validate(skb, 0, true, false, 0, null_compute_pseudo) 2961 __skb_checksum_validate(skb, 0, true, false, 0, null_compute_pseudo)
2885 2962
2963static inline bool __skb_checksum_convert_check(struct sk_buff *skb)
2964{
2965 return (skb->ip_summed == CHECKSUM_NONE &&
2966 skb->csum_valid && !skb->csum_bad);
2967}
2968
2969static inline void __skb_checksum_convert(struct sk_buff *skb,
2970 __sum16 check, __wsum pseudo)
2971{
2972 skb->csum = ~pseudo;
2973 skb->ip_summed = CHECKSUM_COMPLETE;
2974}
2975
2976#define skb_checksum_try_convert(skb, proto, check, compute_pseudo) \
2977do { \
2978 if (__skb_checksum_convert_check(skb)) \
2979 __skb_checksum_convert(skb, check, \
2980 compute_pseudo(skb, proto)); \
2981} while (0)
2982
2886#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 2983#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
2887void nf_conntrack_destroy(struct nf_conntrack *nfct); 2984void nf_conntrack_destroy(struct nf_conntrack *nfct);
2888static inline void nf_conntrack_put(struct nf_conntrack *nfct) 2985static inline void nf_conntrack_put(struct nf_conntrack *nfct)
@@ -3137,7 +3234,9 @@ bool skb_partial_csum_set(struct sk_buff *skb, u16 start, u16 off);
3137 3234
3138int skb_checksum_setup(struct sk_buff *skb, bool recalculate); 3235int skb_checksum_setup(struct sk_buff *skb, bool recalculate);
3139 3236
3140u32 __skb_get_poff(const struct sk_buff *skb); 3237u32 skb_get_poff(const struct sk_buff *skb);
3238u32 __skb_get_poff(const struct sk_buff *skb, void *data,
3239 const struct flow_keys *keys, int hlen);
3141 3240
3142/** 3241/**
3143 * skb_head_is_locked - Determine if the skb->head is locked down 3242 * skb_head_is_locked - Determine if the skb->head is locked down