1 #include <linux/netdevice.h>
2 #include <linux/if_vlan.h>
4 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
5 static bool can_checksum_protocol(unsigned long features, __be16 protocol)
7 return ((features & NETIF_F_GEN_CSUM) ||
8 ((features & NETIF_F_V4_CSUM) &&
9 protocol == htons(ETH_P_IP)) ||
10 ((features & NETIF_F_V6_CSUM) &&
11 protocol == htons(ETH_P_IPV6)) ||
12 ((features & NETIF_F_FCOE_CRC) &&
13 protocol == htons(ETH_P_FCOE)));
16 static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
21 if (dev->features & NETIF_F_HIGHDMA)
24 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
25 if (PageHighMem(skb_shinfo(skb)->frags[i].page))
32 static u32 harmonize_features(struct sk_buff *skb, __be16 protocol, u32 features)
34 if (!can_checksum_protocol(features, protocol)) {
35 features &= ~NETIF_F_ALL_CSUM;
36 features &= ~NETIF_F_SG;
37 } else if (illegal_highdma(skb->dev, skb)) {
38 features &= ~NETIF_F_SG;
44 u32 rpl_netif_skb_features(struct sk_buff *skb)
46 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
47 unsigned long vlan_features = 0;
49 unsigned long vlan_features = skb->dev->vlan_features;
50 #endif /* kernel version < 2.6.26 */
52 __be16 protocol = skb->protocol;
53 u32 features = skb->dev->features;
55 if (protocol == htons(ETH_P_8021Q)) {
56 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
57 protocol = veh->h_vlan_encapsulated_proto;
58 } else if (!vlan_tx_tag_present(skb)) {
59 return harmonize_features(skb, protocol, features);
62 features &= (vlan_features | NETIF_F_HW_VLAN_TX);
64 if (protocol != htons(ETH_P_8021Q)) {
65 return harmonize_features(skb, protocol, features);
67 features &= NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST |
68 NETIF_F_GEN_CSUM | NETIF_F_HW_VLAN_TX;
69 return harmonize_features(skb, protocol, features);
73 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb, u32 features)
75 int vlan_depth = ETH_HLEN;
76 __be16 type = skb->protocol;
78 struct sk_buff *skb_gso;
80 while (type == htons(ETH_P_8021Q)) {
83 if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
84 return ERR_PTR(-EINVAL);
86 vh = (struct vlan_hdr *)(skb->data + vlan_depth);
87 type = vh->h_vlan_encapsulated_proto;
88 vlan_depth += VLAN_HLEN;
91 /* this hack needed to get regular skb_gso_segment() */
92 #undef skb_gso_segment
93 skb_proto = skb->protocol;
96 skb_gso = skb_gso_segment(skb, features);
97 skb->protocol = skb_proto;
100 #endif /* kernel version < 2.6.38 */