1 #include <linux/netdevice.h>
2 #include <linux/if_vlan.h>
4 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38)
5 #ifndef HAVE_CAN_CHECKSUM_PROTOCOL
6 static bool can_checksum_protocol(unsigned long features, __be16 protocol)
8 return ((features & NETIF_F_GEN_CSUM) ||
9 ((features & NETIF_F_V4_CSUM) &&
10 protocol == htons(ETH_P_IP)) ||
11 ((features & NETIF_F_V6_CSUM) &&
12 protocol == htons(ETH_P_IPV6)) ||
13 ((features & NETIF_F_FCOE_CRC) &&
14 protocol == htons(ETH_P_FCOE)));
18 static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
23 if (dev->features & NETIF_F_HIGHDMA)
26 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
27 if (PageHighMem(skb_shinfo(skb)->frags[i].page))
34 static u32 harmonize_features(struct sk_buff *skb, __be16 protocol, u32 features)
36 if (!can_checksum_protocol(features, protocol)) {
37 features &= ~NETIF_F_ALL_CSUM;
38 features &= ~NETIF_F_SG;
39 } else if (illegal_highdma(skb->dev, skb)) {
40 features &= ~NETIF_F_SG;
46 u32 rpl_netif_skb_features(struct sk_buff *skb)
48 unsigned long vlan_features = skb->dev->vlan_features;
50 __be16 protocol = skb->protocol;
51 u32 features = skb->dev->features;
53 if (protocol == htons(ETH_P_8021Q)) {
54 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
55 protocol = veh->h_vlan_encapsulated_proto;
56 } else if (!vlan_tx_tag_present(skb)) {
57 return harmonize_features(skb, protocol, features);
60 features &= (vlan_features | NETIF_F_HW_VLAN_TX);
62 if (protocol != htons(ETH_P_8021Q)) {
63 return harmonize_features(skb, protocol, features);
65 features &= NETIF_F_SG | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST |
66 NETIF_F_GEN_CSUM | NETIF_F_HW_VLAN_TX;
67 return harmonize_features(skb, protocol, features);
71 struct sk_buff *rpl_skb_gso_segment(struct sk_buff *skb, u32 features)
73 int vlan_depth = ETH_HLEN;
74 __be16 type = skb->protocol;
76 struct sk_buff *skb_gso;
78 while (type == htons(ETH_P_8021Q)) {
81 if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
82 return ERR_PTR(-EINVAL);
84 vh = (struct vlan_hdr *)(skb->data + vlan_depth);
85 type = vh->h_vlan_encapsulated_proto;
86 vlan_depth += VLAN_HLEN;
89 /* this hack needed to get regular skb_gso_segment() */
90 #undef skb_gso_segment
91 skb_proto = skb->protocol;
94 skb_gso = skb_gso_segment(skb, features);
95 skb->protocol = skb_proto;
98 #endif /* kernel version < 2.6.38 */