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_IGNORE_DF_RENAME
10 #define ignore_df local_df
13 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
14 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
15 const int offset, void *to,
16 const unsigned int len)
18 memcpy(to, skb->data + offset, len);
21 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
24 const unsigned int len)
26 memcpy(skb->data + offset, from, len);
29 #endif /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
31 #ifndef HAVE_SKB_RESET_TAIL_POINTER
32 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
34 skb->tail = skb->data;
38 * The networking layer reserves some headroom in skb data (via
39 * dev_alloc_skb). This is used to avoid having to reallocate skb data when
40 * the header has to grow. In the default case, if the header has to grow
41 * 16 bytes or less we avoid the reallocation.
43 * Unfortunately this headroom changes the DMA alignment of the resulting
44 * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
45 * on some architectures. An architecture can override this value,
46 * perhaps setting it to a cacheline in size (since that will maintain
47 * cacheline alignment of the DMA). It must be a power of 2.
49 * Various parts of the networking layer expect at least 16 bytes of
50 * headroom, you should not reduce this.
53 #define NET_SKB_PAD 16
56 #ifndef HAVE_SKB_COW_HEAD
57 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
62 if (headroom < NET_SKB_PAD)
63 headroom = NET_SKB_PAD;
64 if (headroom > skb_headroom(skb))
65 delta = headroom - skb_headroom(skb);
68 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
73 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
75 return __skb_cow(skb, headroom, skb_header_cloned(skb));
77 #endif /* !HAVE_SKB_COW_HEAD */
79 #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS
80 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
82 return (struct dst_entry *)skb->dst;
85 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
90 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
92 return (struct rtable *)skb->dst;
96 #ifndef CHECKSUM_PARTIAL
97 #define CHECKSUM_PARTIAL CHECKSUM_HW
99 #ifndef CHECKSUM_COMPLETE
100 #define CHECKSUM_COMPLETE CHECKSUM_HW
103 #ifndef HAVE_SKBUFF_HEADER_HELPERS
104 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
109 static inline void skb_reset_transport_header(struct sk_buff *skb)
111 skb->h.raw = skb->data;
114 static inline void skb_set_transport_header(struct sk_buff *skb,
117 skb->h.raw = skb->data + offset;
120 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
125 static inline void skb_reset_network_header(struct sk_buff *skb)
127 skb->nh.raw = skb->data;
130 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
132 skb->nh.raw = skb->data + offset;
135 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
140 static inline void skb_reset_mac_header(struct sk_buff *skb)
142 skb->mac_header = skb->data;
145 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
147 skb->mac.raw = skb->data + offset;
150 static inline int skb_transport_offset(const struct sk_buff *skb)
152 return skb_transport_header(skb) - skb->data;
155 static inline int skb_network_offset(const struct sk_buff *skb)
157 return skb_network_header(skb) - skb->data;
160 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
162 const unsigned int len)
164 memcpy(skb->data, from, len);
166 #endif /* !HAVE_SKBUFF_HEADER_HELPERS */
168 #ifndef HAVE_SKB_WARN_LRO
170 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
175 extern void __skb_warn_lro_forwarding(const struct sk_buff *skb);
177 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
179 /* LRO sets gso_size but not gso_type, whereas if GSO is really
180 * wanted then gso_type will be set. */
181 struct skb_shared_info *shinfo = skb_shinfo(skb);
182 if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) {
183 __skb_warn_lro_forwarding(skb);
188 #endif /* NETIF_F_LRO */
189 #endif /* HAVE_SKB_WARN_LRO */
191 #ifndef HAVE_CONSUME_SKB
192 #define consume_skb kfree_skb
195 #ifndef HAVE_SKB_FRAG_PAGE
196 #include <linux/mm.h>
198 static inline struct page *skb_frag_page(const skb_frag_t *frag)
203 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
207 static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size)
211 static inline void __skb_frag_ref(skb_frag_t *frag)
213 get_page(skb_frag_page(frag));
215 static inline void __skb_frag_unref(skb_frag_t *frag)
217 put_page(skb_frag_page(frag));
220 static inline void skb_frag_ref(struct sk_buff *skb, int f)
222 __skb_frag_ref(&skb_shinfo(skb)->frags[f]);
225 static inline void skb_frag_unref(struct sk_buff *skb, int f)
227 __skb_frag_unref(&skb_shinfo(skb)->frags[f]);
232 #ifndef HAVE_SKB_RESET_MAC_LEN
233 static inline void skb_reset_mac_len(struct sk_buff *skb)
235 skb->mac_len = skb->network_header - skb->mac_header;
239 #ifndef HAVE_SKB_UNCLONE
240 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
242 might_sleep_if(pri & __GFP_WAIT);
245 return pskb_expand_head(skb, 0, 0, pri);
251 #ifndef HAVE_SKB_ORPHAN_FRAGS
252 static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
258 #ifndef HAVE_SKB_GET_HASH
259 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
260 #define __skb_get_hash rpl__skb_get_rxhash
261 #define skb_get_hash rpl_skb_get_rxhash
263 extern u32 __skb_get_hash(struct sk_buff *skb);
264 static inline __u32 skb_get_hash(struct sk_buff *skb)
268 #ifndef HAVE_U16_RXHASH
271 return jhash_1word(skb->rxhash, 0);
274 return __skb_get_hash(skb);
278 #define skb_get_hash skb_get_rxhash
279 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
280 #endif /* HAVE_SKB_GET_HASH */
282 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
283 static inline void skb_tx_error(struct sk_buff *skb)
287 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
289 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
290 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
291 int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len,
295 #ifndef HAVE_SKB_CLEAR_HASH
296 static inline void skb_clear_hash(struct sk_buff *skb)
301 #ifdef HAVE_L4_RXHASH
307 #ifndef HAVE_SKB_HAS_FRAG_LIST
308 #define skb_has_frag_list skb_has_frags
311 #ifndef HAVE___SKB_FILL_PAGE_DESC
312 static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
313 struct page *page, int off, int size)
315 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
317 __skb_frag_set_page(frag, page);
318 frag->page_offset = off;
319 skb_frag_size_set(frag, size);