Import from old repository commit 61ef2b42a9c4ba8e1600f15bb0236765edc2ad45.
[cascardo/ovs.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 #ifndef HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET
9 static inline void skb_copy_from_linear_data_offset(const struct sk_buff *skb,
10                                                     const int offset, void *to,
11                                                     const unsigned int len)
12 {
13         memcpy(to, skb->data + offset, len);
14 }
15
16 static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb,
17                                                   const int offset,
18                                                   const void *from,
19                                                   const unsigned int len)
20 {
21         memcpy(skb->data + offset, from, len);
22 }
23
24 #endif  /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */
25
26 /*
27  * The networking layer reserves some headroom in skb data (via
28  * dev_alloc_skb). This is used to avoid having to reallocate skb data when
29  * the header has to grow. In the default case, if the header has to grow
30  * 16 bytes or less we avoid the reallocation.
31  *
32  * Unfortunately this headroom changes the DMA alignment of the resulting
33  * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive
34  * on some architectures. An architecture can override this value,
35  * perhaps setting it to a cacheline in size (since that will maintain
36  * cacheline alignment of the DMA). It must be a power of 2.
37  *
38  * Various parts of the networking layer expect at least 16 bytes of
39  * headroom, you should not reduce this.
40  */
41 #ifndef NET_SKB_PAD
42 #define NET_SKB_PAD     16
43 #endif
44
45 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
46 static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom,
47                             int cloned)
48 {
49         int delta = 0;
50
51         if (headroom < NET_SKB_PAD)
52                 headroom = NET_SKB_PAD;
53         if (headroom > skb_headroom(skb))
54                 delta = headroom - skb_headroom(skb);
55
56         if (delta || cloned)
57                 return pskb_expand_head(skb, ALIGN(delta, NET_SKB_PAD), 0,
58                                         GFP_ATOMIC);
59         return 0;
60 }
61
62 static inline int skb_cow_head(struct sk_buff *skb, unsigned int headroom)
63 {
64         return __skb_cow(skb, headroom, skb_header_cloned(skb));
65 }
66 #endif  /* linux < 2.6.23 */
67
68
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
70 /* Emulate Linux 2.6.17 and later behavior, in which kfree_skb silently ignores 
71  * null pointer arguments. */
72 #define kfree_skb(skb) kfree_skb_maybe_null(skb)
73 static inline void kfree_skb_maybe_null(struct sk_buff *skb)
74 {
75         if (likely(skb != NULL))
76                 (kfree_skb)(skb);
77 }
78 #endif
79
80
81 #ifndef CHECKSUM_PARTIAL
82 /* Note that CHECKSUM_PARTIAL is not implemented, but this allows us to at
83  * least test against it: see update_csum() in forward.c. */
84 #define CHECKSUM_PARTIAL 3
85 #endif
86 #ifndef CHECKSUM_COMPLETE
87 #define CHECKSUM_COMPLETE CHECKSUM_HW
88 #endif
89
90 #ifdef HAVE_MAC_RAW
91 #define mac_header mac.raw
92 #define network_header nh.raw
93 #endif
94
95 #ifndef HAVE_SKBUFF_HEADER_HELPERS
96 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
97 {
98         return skb->h.raw;
99 }
100
101 static inline void skb_reset_transport_header(struct sk_buff *skb)
102 {
103         skb->h.raw = skb->data;
104 }
105
106 static inline void skb_set_transport_header(struct sk_buff *skb,
107                         const int offset)
108 {
109         skb->h.raw = skb->data + offset;
110 }
111
112 static inline unsigned char *skb_network_header(const struct sk_buff *skb)
113 {
114         return skb->nh.raw;
115 }
116
117 static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
118 {
119         skb->nh.raw = skb->data + offset;
120 }
121
122 static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
123 {
124         return skb->mac.raw;
125 }
126
127 static inline void skb_reset_mac_header(struct sk_buff *skb)
128 {
129         skb->mac_header = skb->data;
130 }
131
132 static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
133 {
134         skb->mac.raw = skb->data + offset;
135 }
136
137 static inline int skb_transport_offset(const struct sk_buff *skb)
138 {
139     return skb_transport_header(skb) - skb->data;
140 }
141
142 static inline int skb_network_offset(const struct sk_buff *skb)
143 {
144         return skb_network_header(skb) - skb->data;
145 }
146
147 static inline void skb_copy_to_linear_data(struct sk_buff *skb,
148                                            const void *from,
149                                            const unsigned int len)
150 {
151         memcpy(skb->data, from, len);
152 }
153 #endif  /* !HAVE_SKBUFF_HEADER_HELPERS */
154
155 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
156 #warning "TSO/UFO not supported on kernels earlier than 2.6.18"
157
158 static inline int skb_is_gso(const struct sk_buff *skb)
159 {
160         return 0;
161 }
162
163 static inline struct sk_buff *skb_gso_segment(struct sk_buff *skb,
164                                               int features)
165 {
166         return NULL;
167 }
168 #endif  /* before 2.6.18 */
169
170 #endif