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