2 * Copyright (c) 2010 Nicira Networks.
3 * Distributed under the terms of the GNU GPL version 2.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
12 #include <linux/skbuff.h>
13 #include <linux/version.h>
15 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) || \
16 (defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID))
17 #define NEED_CSUM_NORMALIZE
20 /* These are the same values as the checksum constants in 2.6.22+. */
23 OVS_CSUM_UNNECESSARY = 1,
24 OVS_CSUM_COMPLETE = 2,
28 #ifdef NEED_CSUM_NORMALIZE
29 void compute_ip_summed(struct sk_buff *skb, bool xmit);
30 u8 get_ip_summed(struct sk_buff *skb);
32 static inline void compute_ip_summed(struct sk_buff *skb, bool xmit) { }
33 static inline u8 get_ip_summed(struct sk_buff *skb)
35 return skb->ip_summed;
39 /* This function closely resembles skb_forward_csum() used by the bridge. It
40 * is slightly different because we are only concerned with bridging and not
41 * other types of forwarding and can get away with slightly more optimal
44 static inline void forward_ip_summed(struct sk_buff *skb)
47 if (get_ip_summed(skb) == OVS_CSUM_COMPLETE)
48 skb->ip_summed = CHECKSUM_NONE;
52 #if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID)
53 int vswitch_skb_checksum_setup(struct sk_buff *skb);
55 static inline int vswitch_skb_checksum_setup(struct sk_buff *skb)
61 static inline void set_skb_csum_bits(const struct sk_buff *old_skb,
62 struct sk_buff *new_skb)
64 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
65 /* Before 2.6.24 these fields were not copied when
66 * doing an skb_copy_expand. */
67 new_skb->ip_summed = old_skb->ip_summed;
68 new_skb->csum = old_skb->csum;
70 #if defined(CONFIG_XEN) && defined(HAVE_PROTO_DATA_VALID)
71 /* These fields are copied in skb_clone but not in
72 * skb_copy or related functions. We need to manually
73 * copy them over here. */
74 new_skb->proto_data_valid = old_skb->proto_data_valid;
75 new_skb->proto_csum_blank = old_skb->proto_csum_blank;
79 static inline void get_skb_csum_pointers(const struct sk_buff *skb,
80 u16 *csum_start, u16 *csum_offset)
82 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
83 *csum_start = skb->csum_start - skb_headroom(skb);
84 *csum_offset = skb->csum_offset;
86 *csum_start = skb_transport_header(skb) - skb->data;
87 *csum_offset = skb->csum;
91 static inline void set_skb_csum_pointers(struct sk_buff *skb, u16 csum_start,
94 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
95 skb->csum_start = csum_start;
96 skb->csum_offset = csum_offset;
98 skb_set_transport_header(skb, csum_start - skb_headroom(skb));
99 skb->csum = csum_offset;
103 #endif /* checksum.h */