]>
Commit | Line | Data |
---|---|---|
064af421 BP |
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 | ||
e8cf6733 BP |
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 | ||
064af421 BP |
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 | ||
4eb26d3c | 56 | #ifndef HAVE_SKB_COW_HEAD |
064af421 BP |
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 | } | |
4eb26d3c | 77 | #endif /* !HAVE_SKB_COW_HEAD */ |
064af421 | 78 | |
db12f2fc JG |
79 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) |
80 | static inline int skb_clone_writable(struct sk_buff *skb, int len) | |
81 | { | |
82 | return false; | |
83 | } | |
84 | #endif | |
85 | ||
85444c3f | 86 | #ifndef HAVE_SKB_DST_ACCESSOR_FUNCS |
db12f2fc JG |
87 | static inline struct dst_entry *skb_dst(const struct sk_buff *skb) |
88 | { | |
89 | return (struct dst_entry *)skb->dst; | |
90 | } | |
91 | ||
92 | static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst) | |
93 | { | |
94 | skb->dst = dst; | |
95 | } | |
96 | ||
97 | static inline struct rtable *skb_rtable(const struct sk_buff *skb) | |
98 | { | |
99 | return (struct rtable *)skb->dst; | |
100 | } | |
101 | #endif | |
064af421 BP |
102 | |
103 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17) | |
d295e8e9 | 104 | /* Emulate Linux 2.6.17 and later behavior, in which kfree_skb silently ignores |
064af421 BP |
105 | * null pointer arguments. */ |
106 | #define kfree_skb(skb) kfree_skb_maybe_null(skb) | |
107 | static inline void kfree_skb_maybe_null(struct sk_buff *skb) | |
108 | { | |
109 | if (likely(skb != NULL)) | |
110 | (kfree_skb)(skb); | |
111 | } | |
112 | #endif | |
113 | ||
114 | ||
115 | #ifndef CHECKSUM_PARTIAL | |
1cdb82b9 | 116 | #define CHECKSUM_PARTIAL CHECKSUM_HW |
064af421 BP |
117 | #endif |
118 | #ifndef CHECKSUM_COMPLETE | |
119 | #define CHECKSUM_COMPLETE CHECKSUM_HW | |
120 | #endif | |
121 | ||
122 | #ifdef HAVE_MAC_RAW | |
123 | #define mac_header mac.raw | |
124 | #define network_header nh.raw | |
db12f2fc | 125 | #define transport_header h.raw |
064af421 BP |
126 | #endif |
127 | ||
128 | #ifndef HAVE_SKBUFF_HEADER_HELPERS | |
129 | static inline unsigned char *skb_transport_header(const struct sk_buff *skb) | |
130 | { | |
131 | return skb->h.raw; | |
132 | } | |
133 | ||
134 | static inline void skb_reset_transport_header(struct sk_buff *skb) | |
135 | { | |
136 | skb->h.raw = skb->data; | |
137 | } | |
138 | ||
139 | static inline void skb_set_transport_header(struct sk_buff *skb, | |
140 | const int offset) | |
141 | { | |
142 | skb->h.raw = skb->data + offset; | |
143 | } | |
144 | ||
145 | static inline unsigned char *skb_network_header(const struct sk_buff *skb) | |
146 | { | |
147 | return skb->nh.raw; | |
148 | } | |
149 | ||
8f3a29be JP |
150 | static inline void skb_reset_network_header(struct sk_buff *skb) |
151 | { | |
152 | skb->nh.raw = skb->data; | |
153 | } | |
154 | ||
064af421 BP |
155 | static inline void skb_set_network_header(struct sk_buff *skb, const int offset) |
156 | { | |
157 | skb->nh.raw = skb->data + offset; | |
158 | } | |
159 | ||
160 | static inline unsigned char *skb_mac_header(const struct sk_buff *skb) | |
161 | { | |
162 | return skb->mac.raw; | |
163 | } | |
164 | ||
165 | static inline void skb_reset_mac_header(struct sk_buff *skb) | |
166 | { | |
167 | skb->mac_header = skb->data; | |
168 | } | |
169 | ||
170 | static inline void skb_set_mac_header(struct sk_buff *skb, const int offset) | |
171 | { | |
172 | skb->mac.raw = skb->data + offset; | |
173 | } | |
174 | ||
175 | static inline int skb_transport_offset(const struct sk_buff *skb) | |
176 | { | |
177 | return skb_transport_header(skb) - skb->data; | |
178 | } | |
179 | ||
180 | static inline int skb_network_offset(const struct sk_buff *skb) | |
181 | { | |
182 | return skb_network_header(skb) - skb->data; | |
183 | } | |
184 | ||
185 | static inline void skb_copy_to_linear_data(struct sk_buff *skb, | |
186 | const void *from, | |
187 | const unsigned int len) | |
188 | { | |
189 | memcpy(skb->data, from, len); | |
190 | } | |
191 | #endif /* !HAVE_SKBUFF_HEADER_HELPERS */ | |
192 | ||
193 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) | |
194 | #warning "TSO/UFO not supported on kernels earlier than 2.6.18" | |
195 | ||
196 | static inline int skb_is_gso(const struct sk_buff *skb) | |
197 | { | |
198 | return 0; | |
199 | } | |
200 | ||
201 | static inline struct sk_buff *skb_gso_segment(struct sk_buff *skb, | |
202 | int features) | |
203 | { | |
204 | return NULL; | |
205 | } | |
206 | #endif /* before 2.6.18 */ | |
207 | ||
14cf356b | 208 | #ifndef HAVE_SKB_WARN_LRO |
2de32079 JG |
209 | #ifndef NETIF_F_LRO |
210 | static inline bool skb_warn_if_lro(const struct sk_buff *skb) | |
211 | { | |
212 | return false; | |
213 | } | |
214 | #else | |
14cf356b JG |
215 | extern void __skb_warn_lro_forwarding(const struct sk_buff *skb); |
216 | ||
2de32079 JG |
217 | static inline bool skb_warn_if_lro(const struct sk_buff *skb) |
218 | { | |
219 | /* LRO sets gso_size but not gso_type, whereas if GSO is really | |
220 | * wanted then gso_type will be set. */ | |
221 | struct skb_shared_info *shinfo = skb_shinfo(skb); | |
222 | if (shinfo->gso_size != 0 && unlikely(shinfo->gso_type == 0)) { | |
223 | __skb_warn_lro_forwarding(skb); | |
224 | return true; | |
225 | } | |
226 | return false; | |
227 | } | |
228 | #endif /* NETIF_F_LRO */ | |
14cf356b | 229 | #endif /* HAVE_SKB_WARN_LRO */ |
2de32079 | 230 | |
82d6256a JG |
231 | #ifndef HAVE_CONSUME_SKB |
232 | #define consume_skb kfree_skb | |
233 | #endif | |
234 | ||
064af421 | 235 | #endif |