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(netdev_features_t 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 netdev_features_t harmonize_features(struct sk_buff *skb,
40 netdev_features_t features)
42 if (!can_checksum_protocol(features, protocol)) {
43 features &= ~NETIF_F_ALL_CSUM;
44 features &= ~NETIF_F_SG;
45 } else if (illegal_highdma(skb->dev, skb)) {
46 features &= ~NETIF_F_SG;
52 netdev_features_t rpl_netif_skb_features(struct sk_buff *skb)
54 unsigned long vlan_features = skb->dev->vlan_features;
56 __be16 protocol = skb->protocol;
57 netdev_features_t features = skb->dev->features;
59 if (protocol == htons(ETH_P_8021Q)) {
60 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
61 protocol = veh->h_vlan_encapsulated_proto;
62 } else if (!vlan_tx_tag_present(skb)) {
63 return harmonize_features(skb, protocol, features);
66 features &= (vlan_features | NETIF_F_HW_VLAN_TX);
68 if (protocol != htons(ETH_P_8021Q)) {
69 return harmonize_features(skb, protocol, features);
71 features &= NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST |
72 NETIF_F_GEN_CSUM | NETIF_F_HW_VLAN_TX;
73 return harmonize_features(skb, protocol, features);
77 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb,
78 netdev_features_t features)
80 int vlan_depth = ETH_HLEN;
81 __be16 type = skb->protocol;
83 struct sk_buff *skb_gso;
85 while (type == htons(ETH_P_8021Q)) {
88 if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
89 return ERR_PTR(-EINVAL);
91 vh = (struct vlan_hdr *)(skb->data + vlan_depth);
92 type = vh->h_vlan_encapsulated_proto;
93 vlan_depth += VLAN_HLEN;
96 /* this hack needed to get regular skb_gso_segment() */
97 #undef skb_gso_segment
98 skb_proto = skb->protocol;
101 skb_gso = skb_gso_segment(skb, features);
102 skb->protocol = skb_proto;
105 #endif /* kernel version < 2.6.38 */