1 #include <linux/netdevice.h>
2 #include <linux/if_vlan.h>
4 #ifdef HAVE_RHEL_OVS_HOOK
8 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
9 #ifndef HAVE_CAN_CHECKSUM_PROTOCOL
10 static bool can_checksum_protocol(unsigned long features, __be16 protocol)
12 return ((features & NETIF_F_GEN_CSUM) ||
13 ((features & NETIF_F_V4_CSUM) &&
14 protocol == htons(ETH_P_IP)) ||
15 ((features & NETIF_F_V6_CSUM) &&
16 protocol == htons(ETH_P_IPV6)) ||
17 ((features & NETIF_F_FCOE_CRC) &&
18 protocol == htons(ETH_P_FCOE)));
22 static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
27 if (dev->features & NETIF_F_HIGHDMA)
30 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
31 if (PageHighMem(skb_shinfo(skb)->frags[i].page))
38 static u32 harmonize_features(struct sk_buff *skb, __be16 protocol, u32 features)
40 if (!can_checksum_protocol(features, protocol)) {
41 features &= ~NETIF_F_ALL_CSUM;
42 features &= ~NETIF_F_SG;
43 } else if (illegal_highdma(skb->dev, skb)) {
44 features &= ~NETIF_F_SG;
50 u32 rpl_netif_skb_features(struct sk_buff *skb)
52 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
53 unsigned long vlan_features = 0;
55 unsigned long vlan_features = skb->dev->vlan_features;
56 #endif /* kernel version < 2.6.26 */
58 __be16 protocol = skb->protocol;
59 u32 features = skb->dev->features;
61 if (protocol == htons(ETH_P_8021Q)) {
62 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
63 protocol = veh->h_vlan_encapsulated_proto;
64 } else if (!vlan_tx_tag_present(skb)) {
65 return harmonize_features(skb, protocol, features);
68 features &= (vlan_features | NETIF_F_HW_VLAN_TX);
70 if (protocol != htons(ETH_P_8021Q)) {
71 return harmonize_features(skb, protocol, features);
73 features &= NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST |
74 NETIF_F_GEN_CSUM | NETIF_F_HW_VLAN_TX;
75 return harmonize_features(skb, protocol, features);
79 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb, u32 features)
81 int vlan_depth = ETH_HLEN;
82 __be16 type = skb->protocol;
84 struct sk_buff *skb_gso;
86 while (type == htons(ETH_P_8021Q)) {
89 if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
90 return ERR_PTR(-EINVAL);
92 vh = (struct vlan_hdr *)(skb->data + vlan_depth);
93 type = vh->h_vlan_encapsulated_proto;
94 vlan_depth += VLAN_HLEN;
97 /* this hack needed to get regular skb_gso_segment() */
98 #undef skb_gso_segment
99 skb_proto = skb->protocol;
100 skb->protocol = type;
102 skb_gso = skb_gso_segment(skb, features);
103 skb->protocol = skb_proto;
106 #endif /* kernel version < 2.6.38 */