datapath: Fix warning building datapath on pre-2.6.24 kernels.
[sliver-openvswitch.git] / datapath / linux-2.6 / compat-2.6 / 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/version.h>
7
8 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
9 /* In version 2.6.24 the return type of skb_headroom() changed from 'int' to
10  * 'unsigned int'.  We use skb_headroom() as one arm of a min(a,b) invocation
11  * in make_writable() in actions.c, so we need the correct type. */
12 #define skb_headroom rpl_skb_headroom
13 static inline unsigned int rpl_skb_headroom(const struct sk_buff *skb)
14 {
15         return skb->data - skb->head;
16 }
17 #endif
18
19 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
20 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
21                                                     const int offset, void *to,
22                                                     const unsigned int len)
23 {
24         memcpy(to, skb->data + offset, len);
25 }
26
27 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
28                                                   const int offset,
29                                                   const void *from,
30                                                   const unsigned int len)
31 {
32         memcpy(skb->data + offset, from, len);
33 }
34
35 #endif  /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
36
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
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 */
78
79
80 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
81 /* Emulate Linux 2.6.17 and later behavior, in which kfree_skb silently ignores 
82  * null pointer arguments. */
83 #define kfree_skb(skb) kfree_skb_maybe_null(skb)
84 static inline void kfree_skb_maybe_null(struct sk_buff *skb)
85 {
86         if (likely(skb != NULL))
87                 (kfree_skb)(skb);
88 }
89 #endif
90
91
92 #ifndef CHECKSUM_PARTIAL
93 /* Note that CHECKSUM_PARTIAL is not implemented, but this allows us to at
94  * least test against it: see update_csum() in forward.c. */
95 #define CHECKSUM_PARTIAL 3
96 #endif
97 #ifndef CHECKSUM_COMPLETE
98 #define CHECKSUM_COMPLETE CHECKSUM_HW
99 #endif
100
101 #ifdef HAVE_MAC_RAW
102 #define mac_header mac.raw
103 #define network_header nh.raw
104 #endif
105
106 #ifndef HAVE_SKBUFF_HEADER_HELPERS
107 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
108 {
109         return skb->h.raw;
110 }
111
112 static inline void skb_reset_transport_header(struct sk_buff *skb)
113 {
114         skb->h.raw = skb->data;
115 }
116
117 static inline void skb_set_transport_header(struct sk_buff *skb,
118                         const int offset)
119 {
120         skb->h.raw = skb->data + offset;
121 }
122
123 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
124 {
125         return skb->nh.raw;
126 }
127
128 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
129 {
130         skb->nh.raw = skb->data + offset;
131 }
132
133 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
134 {
135         return skb->mac.raw;
136 }
137
138 static inline void skb_reset_mac_header(struct sk_buff *skb)
139 {
140         skb->mac_header = skb->data;
141 }
142
143 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
144 {
145         skb->mac.raw = skb->data + offset;
146 }
147
148 static inline int skb_transport_offset(const struct sk_buff *skb)
149 {
150     return skb_transport_header(skb) - skb->data;
151 }
152
153 static inline int skb_network_offset(const struct sk_buff *skb)
154 {
155         return skb_network_header(skb) - skb->data;
156 }
157
158 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
159                                            const void *from,
160                                            const unsigned int len)
161 {
162         memcpy(skb->data, from, len);
163 }
164 #endif  /* !HAVE_SKBUFF_HEADER_HELPERS */
165
166 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
167 #warning "TSO/UFO not supported on kernels earlier than 2.6.18"
168
169 static inline int skb_is_gso(const struct sk_buff *skb)
170 {
171         return 0;
172 }
173
174 static inline struct sk_buff *skb_gso_segment(struct sk_buff *skb,
175                                               int features)
176 {
177         return NULL;
178 }
179 #endif  /* before 2.6.18 */
180
181 #endif