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 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
13 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
14 #define SKB_GSO_UDP_TUNNEL 0
17 #ifndef HAVE_SKB_GSO_GRE_CSUM
18 #define SKB_GSO_GRE_CSUM 0
21 #ifndef HAVE_SKB_GSO_UDP_TUNNEL_CSUM
22 #define SKB_GSO_UDP_TUNNEL_CSUM 0
25 #ifndef HAVE_IGNORE_DF_RENAME
26 #define ignore_df local_df
29 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
30 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
31 const int offset, void *to,
32 const unsigned int len)
34 memcpy(to, skb->data + offset, len);
37 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
40 const unsigned int len)
42 memcpy(skb->data + offset, from, len);
45 #endif /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
47 #ifndef HAVE_SKB_RESET_TAIL_POINTER
48 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
50 skb->tail = skb->data;
54 * The networking layer reserves some headroom in skb data (via
55 * dev_alloc_skb). This is used to avoid having to reallocate skb data when
56 * the header has to grow. In the default case, if the header has to grow
57 * 16 bytes or less we avoid the reallocation.
59 * Unfortunately this headroom changes the DMA alignment of the resulting
60 * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
61 * on some architectures. An architecture can override this value,
62 * perhaps setting it to a cacheline in size (since that will maintain
63 * cacheline alignment of the DMA). It must be a power of 2.
65 * Various parts of the networking layer expect at least 16 bytes of
66 * headroom, you should not reduce this.
69 #define NET_SKB_PAD 16
72 #ifndef HAVE_SKB_COW_HEAD
73 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
78 if (headroom < NET_SKB_PAD)
79 headroom = NET_SKB_PAD;
80 if (headroom > skb_headroom(skb))
81 delta = headroom - skb_headroom(skb);
84 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
89 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
91 return __skb_cow(skb, headroom, skb_header_cloned(skb));
93 #endif /* !HAVE_SKB_COW_HEAD */
95 #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS
96 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
98 return (struct dst_entry *)skb->dst;
101 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
106 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
108 return (struct rtable *)skb->dst;
112 #ifndef CHECKSUM_PARTIAL
113 #define CHECKSUM_PARTIAL CHECKSUM_HW
115 #ifndef CHECKSUM_COMPLETE
116 #define CHECKSUM_COMPLETE CHECKSUM_HW
119 #ifndef HAVE_SKBUFF_HEADER_HELPERS
120 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
125 static inline void skb_reset_transport_header(struct sk_buff *skb)
127 skb->h.raw = skb->data;
130 static inline void skb_set_transport_header(struct sk_buff *skb,
133 skb->h.raw = skb->data + offset;
136 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
141 static inline void skb_reset_network_header(struct sk_buff *skb)
143 skb->nh.raw = skb->data;
146 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
148 skb->nh.raw = skb->data + offset;
151 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
156 static inline void skb_reset_mac_header(struct sk_buff *skb)
158 skb->mac_header = skb->data;
161 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
163 skb->mac.raw = skb->data + offset;
166 static inline int skb_transport_offset(const struct sk_buff *skb)
168 return skb_transport_header(skb) - skb->data;
171 static inline int skb_network_offset(const struct sk_buff *skb)
173 return skb_network_header(skb) - skb->data;
176 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
178 const unsigned int len)
180 memcpy(skb->data, from, len);
182 #endif /* !HAVE_SKBUFF_HEADER_HELPERS */
184 #ifndef HAVE_SKB_WARN_LRO
186 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
191 extern void __skb_warn_lro_forwarding(const struct sk_buff *skb);
193 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
195 /* LRO sets gso_size but not gso_type, whereas if GSO is really
196 * wanted then gso_type will be set. */
197 struct skb_shared_info *shinfo = skb_shinfo(skb);
198 if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) {
199 __skb_warn_lro_forwarding(skb);
204 #endif /* NETIF_F_LRO */
205 #endif /* HAVE_SKB_WARN_LRO */
207 #ifndef HAVE_CONSUME_SKB
208 #define consume_skb kfree_skb
211 #ifndef HAVE_SKB_FRAG_PAGE
212 #include <linux/mm.h>
214 static inline struct page *skb_frag_page(const skb_frag_t *frag)
219 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
223 static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size)
227 static inline void __skb_frag_ref(skb_frag_t *frag)
229 get_page(skb_frag_page(frag));
231 static inline void __skb_frag_unref(skb_frag_t *frag)
233 put_page(skb_frag_page(frag));
236 static inline void skb_frag_ref(struct sk_buff *skb, int f)
238 __skb_frag_ref(&skb_shinfo(skb)->frags[f]);
241 static inline void skb_frag_unref(struct sk_buff *skb, int f)
243 __skb_frag_unref(&skb_shinfo(skb)->frags[f]);
248 #ifndef HAVE_SKB_RESET_MAC_LEN
249 static inline void skb_reset_mac_len(struct sk_buff *skb)
251 skb->mac_len = skb->network_header - skb->mac_header;
255 #ifndef HAVE_SKB_UNCLONE
256 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
258 might_sleep_if(pri & __GFP_WAIT);
261 return pskb_expand_head(skb, 0, 0, pri);
267 #ifndef HAVE_SKB_ORPHAN_FRAGS
268 static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
274 #ifndef HAVE_SKB_GET_HASH
275 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
276 #define __skb_get_hash rpl__skb_get_rxhash
277 #define skb_get_hash rpl_skb_get_rxhash
279 extern u32 __skb_get_hash(struct sk_buff *skb);
280 static inline __u32 skb_get_hash(struct sk_buff *skb)
284 #ifndef HAVE_U16_RXHASH
287 return jhash_1word(skb->rxhash, 0);
290 return __skb_get_hash(skb);
294 #define skb_get_hash skb_get_rxhash
295 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
296 #endif /* HAVE_SKB_GET_HASH */
298 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
299 static inline void skb_tx_error(struct sk_buff *skb)
303 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
305 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
306 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
309 #ifndef HAVE_SKB_ZEROCOPY
310 #define skb_zerocopy rpl_skb_zerocopy
311 int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len,
315 #ifndef HAVE_SKB_CLEAR_HASH
316 static inline void skb_clear_hash(struct sk_buff *skb)
321 #if defined(HAVE_L4_RXHASH) && !defined(HAVE_RHEL_OVS_HOOK)
327 #ifndef HAVE_SKB_HAS_FRAG_LIST
328 #define skb_has_frag_list skb_has_frags
331 #ifndef HAVE___SKB_FILL_PAGE_DESC
332 static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
333 struct page *page, int off, int size)
335 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
337 __skb_frag_set_page(frag, page);
338 frag->page_offset = off;
339 skb_frag_size_set(frag, size);
343 #ifndef HAVE_SKB_ENSURE_WRITABLE
344 #define skb_ensure_writable rpl_skb_ensure_writable
345 int skb_ensure_writable(struct sk_buff *skb, int write_len);
348 #ifndef HAVE_SKB_VLAN_POP
349 #define skb_vlan_pop rpl_skb_vlan_pop
350 int skb_vlan_pop(struct sk_buff *skb);
353 #ifndef HAVE_SKB_VLAN_PUSH
354 #define skb_vlan_push rpl_skb_vlan_push
355 int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);