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