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,16,0)
14 #define SKB_GSO_GRE_CSUM 0
17 #ifndef HAVE_IGNORE_DF_RENAME
18 #define ignore_df local_df
21 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
22 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
23 const int offset, void *to,
24 const unsigned int len)
26 memcpy(to, skb->data + offset, len);
29 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
32 const unsigned int len)
34 memcpy(skb->data + offset, from, len);
37 #endif /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
39 #ifndef HAVE_SKB_RESET_TAIL_POINTER
40 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
42 skb->tail = skb->data;
46 * The networking layer reserves some headroom in skb data (via
47 * dev_alloc_skb). This is used to avoid having to reallocate skb data when
48 * the header has to grow. In the default case, if the header has to grow
49 * 16 bytes or less we avoid the reallocation.
51 * Unfortunately this headroom changes the DMA alignment of the resulting
52 * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
53 * on some architectures. An architecture can override this value,
54 * perhaps setting it to a cacheline in size (since that will maintain
55 * cacheline alignment of the DMA). It must be a power of 2.
57 * Various parts of the networking layer expect at least 16 bytes of
58 * headroom, you should not reduce this.
61 #define NET_SKB_PAD 16
64 #ifndef HAVE_SKB_COW_HEAD
65 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
70 if (headroom < NET_SKB_PAD)
71 headroom = NET_SKB_PAD;
72 if (headroom > skb_headroom(skb))
73 delta = headroom - skb_headroom(skb);
76 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
81 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
83 return __skb_cow(skb, headroom, skb_header_cloned(skb));
85 #endif /* !HAVE_SKB_COW_HEAD */
87 #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS
88 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
90 return (struct dst_entry *)skb->dst;
93 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
98 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
100 return (struct rtable *)skb->dst;
104 #ifndef CHECKSUM_PARTIAL
105 #define CHECKSUM_PARTIAL CHECKSUM_HW
107 #ifndef CHECKSUM_COMPLETE
108 #define CHECKSUM_COMPLETE CHECKSUM_HW
111 #ifndef HAVE_SKBUFF_HEADER_HELPERS
112 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
117 static inline void skb_reset_transport_header(struct sk_buff *skb)
119 skb->h.raw = skb->data;
122 static inline void skb_set_transport_header(struct sk_buff *skb,
125 skb->h.raw = skb->data + offset;
128 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
133 static inline void skb_reset_network_header(struct sk_buff *skb)
135 skb->nh.raw = skb->data;
138 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
140 skb->nh.raw = skb->data + offset;
143 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
148 static inline void skb_reset_mac_header(struct sk_buff *skb)
150 skb->mac_header = skb->data;
153 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
155 skb->mac.raw = skb->data + offset;
158 static inline int skb_transport_offset(const struct sk_buff *skb)
160 return skb_transport_header(skb) - skb->data;
163 static inline int skb_network_offset(const struct sk_buff *skb)
165 return skb_network_header(skb) - skb->data;
168 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
170 const unsigned int len)
172 memcpy(skb->data, from, len);
174 #endif /* !HAVE_SKBUFF_HEADER_HELPERS */
176 #ifndef HAVE_SKB_WARN_LRO
178 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
183 extern void __skb_warn_lro_forwarding(const struct sk_buff *skb);
185 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
187 /* LRO sets gso_size but not gso_type, whereas if GSO is really
188 * wanted then gso_type will be set. */
189 struct skb_shared_info *shinfo = skb_shinfo(skb);
190 if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) {
191 __skb_warn_lro_forwarding(skb);
196 #endif /* NETIF_F_LRO */
197 #endif /* HAVE_SKB_WARN_LRO */
199 #ifndef HAVE_CONSUME_SKB
200 #define consume_skb kfree_skb
203 #ifndef HAVE_SKB_FRAG_PAGE
204 #include <linux/mm.h>
206 static inline struct page *skb_frag_page(const skb_frag_t *frag)
211 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
215 static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size)
219 static inline void __skb_frag_ref(skb_frag_t *frag)
221 get_page(skb_frag_page(frag));
223 static inline void __skb_frag_unref(skb_frag_t *frag)
225 put_page(skb_frag_page(frag));
228 static inline void skb_frag_ref(struct sk_buff *skb, int f)
230 __skb_frag_ref(&skb_shinfo(skb)->frags[f]);
233 static inline void skb_frag_unref(struct sk_buff *skb, int f)
235 __skb_frag_unref(&skb_shinfo(skb)->frags[f]);
240 #ifndef HAVE_SKB_RESET_MAC_LEN
241 static inline void skb_reset_mac_len(struct sk_buff *skb)
243 skb->mac_len = skb->network_header - skb->mac_header;
247 #ifndef HAVE_SKB_UNCLONE
248 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
250 might_sleep_if(pri & __GFP_WAIT);
253 return pskb_expand_head(skb, 0, 0, pri);
259 #ifndef HAVE_SKB_ORPHAN_FRAGS
260 static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
266 #ifndef HAVE_SKB_GET_HASH
267 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
268 #define __skb_get_hash rpl__skb_get_rxhash
269 #define skb_get_hash rpl_skb_get_rxhash
271 extern u32 __skb_get_hash(struct sk_buff *skb);
272 static inline __u32 skb_get_hash(struct sk_buff *skb)
276 #ifndef HAVE_U16_RXHASH
279 return jhash_1word(skb->rxhash, 0);
282 return __skb_get_hash(skb);
286 #define skb_get_hash skb_get_rxhash
287 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
288 #endif /* HAVE_SKB_GET_HASH */
290 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
291 static inline void skb_tx_error(struct sk_buff *skb)
295 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
297 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
298 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
301 #ifndef HAVE_SKB_ZEROCOPY
302 #define skb_zerocopy rpl_skb_zerocopy
303 int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len,
307 #ifndef HAVE_SKB_CLEAR_HASH
308 static inline void skb_clear_hash(struct sk_buff *skb)
313 #if defined(HAVE_L4_RXHASH) && !defined(HAVE_RHEL_OVS_HOOK)
319 #ifndef HAVE_SKB_HAS_FRAG_LIST
320 #define skb_has_frag_list skb_has_frags
323 #ifndef HAVE___SKB_FILL_PAGE_DESC
324 static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
325 struct page *page, int off, int size)
327 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
329 __skb_frag_set_page(frag, page);
330 frag->page_offset = off;
331 skb_frag_size_set(frag, size);
335 #ifndef HAVE_SKB_ENSURE_WRITABLE
336 #define skb_ensure_writable rpl_skb_ensure_writable
337 int skb_ensure_writable(struct sk_buff *skb, int write_len);
340 #ifndef HAVE_SKB_VLAN_POP
341 #define skb_vlan_pop rpl_skb_vlan_pop
342 int skb_vlan_pop(struct sk_buff *skb);
345 #ifndef HAVE_SKB_VLAN_PUSH
346 #define skb_vlan_push rpl_skb_vlan_push
347 int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);