1 #ifndef __LINUX_SKBUFF_WRAPPER_H
2 #define __LINUX_SKBUFF_WRAPPER_H 1
4 #include_next <linux/skbuff.h>
6 #include <linux/jhash.h>
7 #include <linux/version.h>
9 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
10 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
11 const int offset, void *to,
12 const unsigned int len)
14 memcpy(to, skb->data + offset, len);
17 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
20 const unsigned int len)
22 memcpy(skb->data + offset, from, len);
25 #endif /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
27 #ifndef HAVE_SKB_RESET_TAIL_POINTER
28 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
30 skb->tail = skb->data;
34 * The networking layer reserves some headroom in skb data (via
35 * dev_alloc_skb). This is used to avoid having to reallocate skb data when
36 * the header has to grow. In the default case, if the header has to grow
37 * 16 bytes or less we avoid the reallocation.
39 * Unfortunately this headroom changes the DMA alignment of the resulting
40 * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
41 * on some architectures. An architecture can override this value,
42 * perhaps setting it to a cacheline in size (since that will maintain
43 * cacheline alignment of the DMA). It must be a power of 2.
45 * Various parts of the networking layer expect at least 16 bytes of
46 * headroom, you should not reduce this.
49 #define NET_SKB_PAD 16
52 #ifndef HAVE_SKB_COW_HEAD
53 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
58 if (headroom < NET_SKB_PAD)
59 headroom = NET_SKB_PAD;
60 if (headroom > skb_headroom(skb))
61 delta = headroom - skb_headroom(skb);
64 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
69 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
71 return __skb_cow(skb, headroom, skb_header_cloned(skb));
73 #endif /* !HAVE_SKB_COW_HEAD */
75 #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS
76 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
78 return (struct dst_entry *)skb->dst;
81 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
86 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
88 return (struct rtable *)skb->dst;
92 #ifndef CHECKSUM_PARTIAL
93 #define CHECKSUM_PARTIAL CHECKSUM_HW
95 #ifndef CHECKSUM_COMPLETE
96 #define CHECKSUM_COMPLETE CHECKSUM_HW
99 #ifndef HAVE_SKBUFF_HEADER_HELPERS
100 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
105 static inline void skb_reset_transport_header(struct sk_buff *skb)
107 skb->h.raw = skb->data;
110 static inline void skb_set_transport_header(struct sk_buff *skb,
113 skb->h.raw = skb->data + offset;
116 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
121 static inline void skb_reset_network_header(struct sk_buff *skb)
123 skb->nh.raw = skb->data;
126 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
128 skb->nh.raw = skb->data + offset;
131 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
136 static inline void skb_reset_mac_header(struct sk_buff *skb)
138 skb->mac_header = skb->data;
141 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
143 skb->mac.raw = skb->data + offset;
146 static inline int skb_transport_offset(const struct sk_buff *skb)
148 return skb_transport_header(skb) - skb->data;
151 static inline int skb_network_offset(const struct sk_buff *skb)
153 return skb_network_header(skb) - skb->data;
156 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
158 const unsigned int len)
160 memcpy(skb->data, from, len);
162 #endif /* !HAVE_SKBUFF_HEADER_HELPERS */
164 #ifndef HAVE_SKB_WARN_LRO
166 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
171 extern void __skb_warn_lro_forwarding(const struct sk_buff *skb);
173 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
175 /* LRO sets gso_size but not gso_type, whereas if GSO is really
176 * wanted then gso_type will be set. */
177 struct skb_shared_info *shinfo = skb_shinfo(skb);
178 if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) {
179 __skb_warn_lro_forwarding(skb);
184 #endif /* NETIF_F_LRO */
185 #endif /* HAVE_SKB_WARN_LRO */
187 #ifndef HAVE_CONSUME_SKB
188 #define consume_skb kfree_skb
191 #ifndef HAVE_SKB_FRAG_PAGE
192 #include <linux/mm.h>
194 static inline struct page *skb_frag_page(const skb_frag_t *frag)
199 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
203 static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size)
207 static inline void __skb_frag_ref(skb_frag_t *frag)
209 get_page(skb_frag_page(frag));
211 static inline void __skb_frag_unref(skb_frag_t *frag)
213 put_page(skb_frag_page(frag));
216 static inline void skb_frag_ref(struct sk_buff *skb, int f)
218 __skb_frag_ref(&skb_shinfo(skb)->frags[f]);
221 static inline void skb_frag_unref(struct sk_buff *skb, int f)
223 __skb_frag_unref(&skb_shinfo(skb)->frags[f]);
228 #ifndef HAVE_SKB_RESET_MAC_LEN
229 static inline void skb_reset_mac_len(struct sk_buff *skb)
231 skb->mac_len = skb->network_header - skb->mac_header;
235 #ifndef HAVE_SKB_UNCLONE
236 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
238 might_sleep_if(pri & __GFP_WAIT);
241 return pskb_expand_head(skb, 0, 0, pri);
247 #ifndef HAVE_SKB_ORPHAN_FRAGS
248 static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
254 #ifndef HAVE_SKB_GET_HASH
255 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
256 #define __skb_get_hash rpl__skb_get_rxhash
257 #define skb_get_hash rpl_skb_get_rxhash
259 extern u32 __skb_get_hash(struct sk_buff *skb);
260 static inline __u32 skb_get_hash(struct sk_buff *skb)
264 #ifndef HAVE_U16_RXHASH
267 return jhash_1word(skb->rxhash, 0);
270 return __skb_get_hash(skb);
274 #define skb_get_hash skb_get_rxhash
275 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
276 #endif /* HAVE_SKB_GET_HASH */
278 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
279 static inline void skb_tx_error(struct sk_buff *skb)
283 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
285 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
286 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
287 int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len,
291 #ifndef HAVE_SKB_CLEAR_HASH
292 static inline void skb_clear_hash(struct sk_buff *skb)
297 #ifdef HAVE_L4_RXHASH
303 #ifndef HAVE_SKB_HAS_FRAG_LIST
304 #define skb_has_frag_list skb_has_frags
307 #ifndef HAVE___SKB_FILL_PAGE_DESC
308 static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
309 struct page *page, int off, int size)
311 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
313 __skb_frag_set_page(frag, page);
314 frag->page_offset = off;
315 skb_frag_size_set(frag, size);