compat: Fix RHEL7 build.
[cascardo/ovs.git] / datapath / linux / compat / include / linux / skbuff.h
1 #ifndef __LINUX_SKBUFF_WRAPPER_H
2 #define __LINUX_SKBUFF_WRAPPER_H 1
3
4 #include_next <linux/skbuff.h>
5
6 #include <linux/jhash.h>
7 #include <linux/version.h>
8
9 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
10 #define SKB_GSO_GRE 0
11 #endif
12
13 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
14 #define SKB_GSO_UDP_TUNNEL 0
15 #endif
16
17 #ifndef HAVE_SKB_GSO_GRE_CSUM
18 #define SKB_GSO_GRE_CSUM 0
19 #endif
20
21 #ifndef HAVE_SKB_GSO_UDP_TUNNEL_CSUM
22 #define SKB_GSO_UDP_TUNNEL_CSUM 0
23 #endif
24
25 #ifndef HAVE_IGNORE_DF_RENAME
26 #define ignore_df local_df
27 #endif
28
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)
33 {
34         memcpy(to, skb->data + offset, len);
35 }
36
37 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
38                                                   const int offset,
39                                                   const void *from,
40                                                   const unsigned int len)
41 {
42         memcpy(skb->data + offset, from, len);
43 }
44
45 #endif  /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
46
47 #ifndef HAVE_SKB_RESET_TAIL_POINTER
48 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
49 {
50         skb->tail = skb->data;
51 }
52 #endif
53 /*
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.
58  *
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.
64  *
65  * Various parts of the networking layer expect at least 16 bytes of
66  * headroom, you should not reduce this.
67  */
68 #ifndef NET_SKB_PAD
69 #define NET_SKB_PAD     16
70 #endif
71
72 #ifndef HAVE_SKB_COW_HEAD
73 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
74                             int cloned)
75 {
76         int delta = 0;
77
78         if (headroom < NET_SKB_PAD)
79                 headroom = NET_SKB_PAD;
80         if (headroom > skb_headroom(skb))
81                 delta = headroom - skb_headroom(skb);
82
83         if (delta || cloned)
84                 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
85                                         GFP_ATOMIC);
86         return 0;
87 }
88
89 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
90 {
91         return __skb_cow(skb, headroom, skb_header_cloned(skb));
92 }
93 #endif  /* !HAVE_SKB_COW_HEAD */
94
95 #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS
96 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
97 {
98         return (struct dst_entry *)skb->dst;
99 }
100
101 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
102 {
103         skb->dst = dst;
104 }
105
106 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
107 {
108         return (struct rtable *)skb->dst;
109 }
110 #endif
111
112 #ifndef CHECKSUM_PARTIAL
113 #define CHECKSUM_PARTIAL CHECKSUM_HW
114 #endif
115 #ifndef CHECKSUM_COMPLETE
116 #define CHECKSUM_COMPLETE CHECKSUM_HW
117 #endif
118
119 #ifndef HAVE_SKBUFF_HEADER_HELPERS
120 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
121 {
122         return skb->h.raw;
123 }
124
125 static inline void skb_reset_transport_header(struct sk_buff *skb)
126 {
127         skb->h.raw = skb->data;
128 }
129
130 static inline void skb_set_transport_header(struct sk_buff *skb,
131                         const int offset)
132 {
133         skb->h.raw = skb->data + offset;
134 }
135
136 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
137 {
138         return skb->nh.raw;
139 }
140
141 static inline void skb_reset_network_header(struct sk_buff *skb)
142 {
143         skb->nh.raw = skb->data;
144 }
145
146 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
147 {
148         skb->nh.raw = skb->data + offset;
149 }
150
151 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
152 {
153         return skb->mac.raw;
154 }
155
156 static inline void skb_reset_mac_header(struct sk_buff *skb)
157 {
158         skb->mac_header = skb->data;
159 }
160
161 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
162 {
163         skb->mac.raw = skb->data + offset;
164 }
165
166 static inline int skb_transport_offset(const struct sk_buff *skb)
167 {
168         return skb_transport_header(skb) - skb->data;
169 }
170
171 static inline int skb_network_offset(const struct sk_buff *skb)
172 {
173         return skb_network_header(skb) - skb->data;
174 }
175
176 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
177                                            const void *from,
178                                            const unsigned int len)
179 {
180         memcpy(skb->data, from, len);
181 }
182 #endif  /* !HAVE_SKBUFF_HEADER_HELPERS */
183
184 #ifndef HAVE_SKB_WARN_LRO
185 #ifndef NETIF_F_LRO
186 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
187 {
188         return false;
189 }
190 #else
191 extern void __skb_warn_lro_forwarding(const struct sk_buff *skb);
192
193 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
194 {
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);
200                 return true;
201         }
202         return false;
203 }
204 #endif /* NETIF_F_LRO */
205 #endif /* HAVE_SKB_WARN_LRO */
206
207 #ifndef HAVE_CONSUME_SKB
208 #define consume_skb kfree_skb
209 #endif
210
211 #ifndef HAVE_SKB_FRAG_PAGE
212 #include <linux/mm.h>
213
214 static inline struct page *skb_frag_page(const skb_frag_t *frag)
215 {
216         return frag->page;
217 }
218
219 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
220 {
221         frag->page = page;
222 }
223 static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size)
224 {
225         frag->size = size;
226 }
227 static inline void __skb_frag_ref(skb_frag_t *frag)
228 {
229         get_page(skb_frag_page(frag));
230 }
231 static inline void __skb_frag_unref(skb_frag_t *frag)
232 {
233         put_page(skb_frag_page(frag));
234 }
235
236 static inline void skb_frag_ref(struct sk_buff *skb, int f)
237 {
238         __skb_frag_ref(&skb_shinfo(skb)->frags[f]);
239 }
240
241 static inline void skb_frag_unref(struct sk_buff *skb, int f)
242 {
243         __skb_frag_unref(&skb_shinfo(skb)->frags[f]);
244 }
245
246 #endif
247
248 #ifndef HAVE_SKB_RESET_MAC_LEN
249 static inline void skb_reset_mac_len(struct sk_buff *skb)
250 {
251         skb->mac_len = skb->network_header - skb->mac_header;
252 }
253 #endif
254
255 #ifndef HAVE_SKB_UNCLONE
256 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
257 {
258         might_sleep_if(pri & __GFP_WAIT);
259
260         if (skb_cloned(skb))
261                 return pskb_expand_head(skb, 0, 0, pri);
262
263         return 0;
264 }
265 #endif
266
267 #ifndef HAVE_SKB_ORPHAN_FRAGS
268 static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
269 {
270         return 0;
271 }
272 #endif
273
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
278
279 extern u32 __skb_get_hash(struct sk_buff *skb);
280 static inline __u32 skb_get_hash(struct sk_buff *skb)
281 {
282 #ifdef HAVE_RXHASH
283         if (skb->rxhash)
284 #ifndef HAVE_U16_RXHASH
285                 return skb->rxhash;
286 #else
287                 return jhash_1word(skb->rxhash, 0);
288 #endif
289 #endif
290         return __skb_get_hash(skb);
291 }
292
293 #else
294 #define skb_get_hash skb_get_rxhash
295 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
296 #endif /* HAVE_SKB_GET_HASH */
297
298 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
299 static inline void skb_tx_error(struct sk_buff *skb)
300 {
301         return;
302 }
303 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
304
305 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
306 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
307 #endif
308
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,
312                   int hlen);
313 #endif
314
315 #ifndef HAVE_SKB_CLEAR_HASH
316 static inline void skb_clear_hash(struct sk_buff *skb)
317 {
318 #ifdef HAVE_RXHASH
319         skb->rxhash = 0;
320 #endif
321 #if defined(HAVE_L4_RXHASH) && !defined(HAVE_RHEL_OVS_HOOK)
322         skb->l4_rxhash = 0;
323 #endif
324 }
325 #endif
326
327 #ifndef HAVE_SKB_HAS_FRAG_LIST
328 #define skb_has_frag_list skb_has_frags
329 #endif
330
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)
334 {
335         skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
336
337         __skb_frag_set_page(frag, page);
338         frag->page_offset       = off;
339         skb_frag_size_set(frag, size);
340 }
341 #endif
342
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);
346 #endif
347
348 #ifndef HAVE_SKB_VLAN_POP
349 #define skb_vlan_pop rpl_skb_vlan_pop
350 int skb_vlan_pop(struct sk_buff *skb);
351 #endif
352
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);
356 #endif
357
358 #endif