78d84cc2bb0aa69aaea0cfb1c3e9adee1155e107
[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 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,16,0)
18 #define SKB_GSO_GRE_CSUM 0
19 #define SKB_GSO_UDP_TUNNEL_CSUM 0
20 #endif
21
22 #ifndef HAVE_IGNORE_DF_RENAME
23 #define ignore_df local_df
24 #endif
25
26 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
27 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
28                                                     const int offset, void *to,
29                                                     const unsigned int len)
30 {
31         memcpy(to, skb->data + offset, len);
32 }
33
34 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
35                                                   const int offset,
36                                                   const void *from,
37                                                   const unsigned int len)
38 {
39         memcpy(skb->data + offset, from, len);
40 }
41
42 #endif  /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
43
44 #ifndef HAVE_SKB_RESET_TAIL_POINTER
45 static inline void skb_reset_tail_pointer(struct sk_buff *skb)
46 {
47         skb->tail = skb->data;
48 }
49 #endif
50 /*
51  * The networking layer reserves some headroom in skb data (via
52  * dev_alloc_skb). This is used to avoid having to reallocate skb data when
53  * the header has to grow. In the default case, if the header has to grow
54  * 16 bytes or less we avoid the reallocation.
55  *
56  * Unfortunately this headroom changes the DMA alignment of the resulting
57  * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
58  * on some architectures. An architecture can override this value,
59  * perhaps setting it to a cacheline in size (since that will maintain
60  * cacheline alignment of the DMA). It must be a power of 2.
61  *
62  * Various parts of the networking layer expect at least 16 bytes of
63  * headroom, you should not reduce this.
64  */
65 #ifndef NET_SKB_PAD
66 #define NET_SKB_PAD     16
67 #endif
68
69 #ifndef HAVE_SKB_COW_HEAD
70 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
71                             int cloned)
72 {
73         int delta = 0;
74
75         if (headroom < NET_SKB_PAD)
76                 headroom = NET_SKB_PAD;
77         if (headroom > skb_headroom(skb))
78                 delta = headroom - skb_headroom(skb);
79
80         if (delta || cloned)
81                 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
82                                         GFP_ATOMIC);
83         return 0;
84 }
85
86 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
87 {
88         return __skb_cow(skb, headroom, skb_header_cloned(skb));
89 }
90 #endif  /* !HAVE_SKB_COW_HEAD */
91
92 #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS
93 static inline struct dst_entry *skb_dst(const struct sk_buff *skb)
94 {
95         return (struct dst_entry *)skb->dst;
96 }
97
98 static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst)
99 {
100         skb->dst = dst;
101 }
102
103 static inline struct rtable *skb_rtable(const struct sk_buff *skb)
104 {
105         return (struct rtable *)skb->dst;
106 }
107 #endif
108
109 #ifndef CHECKSUM_PARTIAL
110 #define CHECKSUM_PARTIAL CHECKSUM_HW
111 #endif
112 #ifndef CHECKSUM_COMPLETE
113 #define CHECKSUM_COMPLETE CHECKSUM_HW
114 #endif
115
116 #ifndef HAVE_SKBUFF_HEADER_HELPERS
117 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
118 {
119         return skb->h.raw;
120 }
121
122 static inline void skb_reset_transport_header(struct sk_buff *skb)
123 {
124         skb->h.raw = skb->data;
125 }
126
127 static inline void skb_set_transport_header(struct sk_buff *skb,
128                         const int offset)
129 {
130         skb->h.raw = skb->data + offset;
131 }
132
133 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
134 {
135         return skb->nh.raw;
136 }
137
138 static inline void skb_reset_network_header(struct sk_buff *skb)
139 {
140         skb->nh.raw = skb->data;
141 }
142
143 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
144 {
145         skb->nh.raw = skb->data + offset;
146 }
147
148 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
149 {
150         return skb->mac.raw;
151 }
152
153 static inline void skb_reset_mac_header(struct sk_buff *skb)
154 {
155         skb->mac_header = skb->data;
156 }
157
158 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
159 {
160         skb->mac.raw = skb->data + offset;
161 }
162
163 static inline int skb_transport_offset(const struct sk_buff *skb)
164 {
165         return skb_transport_header(skb) - skb->data;
166 }
167
168 static inline int skb_network_offset(const struct sk_buff *skb)
169 {
170         return skb_network_header(skb) - skb->data;
171 }
172
173 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
174                                            const void *from,
175                                            const unsigned int len)
176 {
177         memcpy(skb->data, from, len);
178 }
179 #endif  /* !HAVE_SKBUFF_HEADER_HELPERS */
180
181 #ifndef HAVE_SKB_WARN_LRO
182 #ifndef NETIF_F_LRO
183 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
184 {
185         return false;
186 }
187 #else
188 extern void __skb_warn_lro_forwarding(const struct sk_buff *skb);
189
190 static inline bool skb_warn_if_lro(const struct sk_buff *skb)
191 {
192         /* LRO sets gso_size but not gso_type, whereas if GSO is really
193          * wanted then gso_type will be set. */
194         struct skb_shared_info *shinfo = skb_shinfo(skb);
195         if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) {
196                 __skb_warn_lro_forwarding(skb);
197                 return true;
198         }
199         return false;
200 }
201 #endif /* NETIF_F_LRO */
202 #endif /* HAVE_SKB_WARN_LRO */
203
204 #ifndef HAVE_CONSUME_SKB
205 #define consume_skb kfree_skb
206 #endif
207
208 #ifndef HAVE_SKB_FRAG_PAGE
209 #include <linux/mm.h>
210
211 static inline struct page *skb_frag_page(const skb_frag_t *frag)
212 {
213         return frag->page;
214 }
215
216 static inline void __skb_frag_set_page(skb_frag_t *frag, struct page *page)
217 {
218         frag->page = page;
219 }
220 static inline void skb_frag_size_set(skb_frag_t *frag, unsigned int size)
221 {
222         frag->size = size;
223 }
224 static inline void __skb_frag_ref(skb_frag_t *frag)
225 {
226         get_page(skb_frag_page(frag));
227 }
228 static inline void __skb_frag_unref(skb_frag_t *frag)
229 {
230         put_page(skb_frag_page(frag));
231 }
232
233 static inline void skb_frag_ref(struct sk_buff *skb, int f)
234 {
235         __skb_frag_ref(&skb_shinfo(skb)->frags[f]);
236 }
237
238 static inline void skb_frag_unref(struct sk_buff *skb, int f)
239 {
240         __skb_frag_unref(&skb_shinfo(skb)->frags[f]);
241 }
242
243 #endif
244
245 #ifndef HAVE_SKB_RESET_MAC_LEN
246 static inline void skb_reset_mac_len(struct sk_buff *skb)
247 {
248         skb->mac_len = skb->network_header - skb->mac_header;
249 }
250 #endif
251
252 #ifndef HAVE_SKB_UNCLONE
253 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
254 {
255         might_sleep_if(pri & __GFP_WAIT);
256
257         if (skb_cloned(skb))
258                 return pskb_expand_head(skb, 0, 0, pri);
259
260         return 0;
261 }
262 #endif
263
264 #ifndef HAVE_SKB_ORPHAN_FRAGS
265 static inline int skb_orphan_frags(struct sk_buff *skb, gfp_t gfp_mask)
266 {
267         return 0;
268 }
269 #endif
270
271 #ifndef HAVE_SKB_GET_HASH
272 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
273 #define __skb_get_hash rpl__skb_get_rxhash
274 #define skb_get_hash rpl_skb_get_rxhash
275
276 extern u32 __skb_get_hash(struct sk_buff *skb);
277 static inline __u32 skb_get_hash(struct sk_buff *skb)
278 {
279 #ifdef HAVE_RXHASH
280         if (skb->rxhash)
281 #ifndef HAVE_U16_RXHASH
282                 return skb->rxhash;
283 #else
284                 return jhash_1word(skb->rxhash, 0);
285 #endif
286 #endif
287         return __skb_get_hash(skb);
288 }
289
290 #else
291 #define skb_get_hash skb_get_rxhash
292 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
293 #endif /* HAVE_SKB_GET_HASH */
294
295 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
296 static inline void skb_tx_error(struct sk_buff *skb)
297 {
298         return;
299 }
300 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) */
301
302 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
303 unsigned int skb_zerocopy_headlen(const struct sk_buff *from);
304 #endif
305
306 #ifndef HAVE_SKB_ZEROCOPY
307 #define skb_zerocopy rpl_skb_zerocopy
308 int skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len,
309                   int hlen);
310 #endif
311
312 #ifndef HAVE_SKB_CLEAR_HASH
313 static inline void skb_clear_hash(struct sk_buff *skb)
314 {
315 #ifdef HAVE_RXHASH
316         skb->rxhash = 0;
317 #endif
318 #if defined(HAVE_L4_RXHASH) && !defined(HAVE_RHEL_OVS_HOOK)
319         skb->l4_rxhash = 0;
320 #endif
321 }
322 #endif
323
324 #ifndef HAVE_SKB_HAS_FRAG_LIST
325 #define skb_has_frag_list skb_has_frags
326 #endif
327
328 #ifndef HAVE___SKB_FILL_PAGE_DESC
329 static inline void __skb_fill_page_desc(struct sk_buff *skb, int i,
330                                         struct page *page, int off, int size)
331 {
332         skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
333
334         __skb_frag_set_page(frag, page);
335         frag->page_offset       = off;
336         skb_frag_size_set(frag, size);
337 }
338 #endif
339
340 #ifndef HAVE_SKB_ENSURE_WRITABLE
341 #define skb_ensure_writable rpl_skb_ensure_writable
342 int skb_ensure_writable(struct sk_buff *skb, int write_len);
343 #endif
344
345 #ifndef HAVE_SKB_VLAN_POP
346 #define skb_vlan_pop rpl_skb_vlan_pop
347 int skb_vlan_pop(struct sk_buff *skb);
348 #endif
349
350 #ifndef HAVE_SKB_VLAN_PUSH
351 #define skb_vlan_push rpl_skb_vlan_push
352 int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
353 #endif
354
355 #endif