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(netdev_features_t 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 netdev_features_t harmonize_features(struct sk_buff *skb,
36 netdev_features_t features)
38 if (!can_checksum_protocol(features, protocol)) {
39 features &= ~NETIF_F_ALL_CSUM;
40 features &= ~NETIF_F_SG;
41 } else if (illegal_highdma(skb->dev, skb)) {
42 features &= ~NETIF_F_SG;
48 netdev_features_t rpl_netif_skb_features(struct sk_buff *skb)
50 unsigned long vlan_features = skb->dev->vlan_features;
52 __be16 protocol = skb->protocol;
53 netdev_features_t 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,
74 netdev_features_t features)
76 int vlan_depth = ETH_HLEN;
77 __be16 type = skb->protocol;
79 struct sk_buff *skb_gso;
81 while (type == htons(ETH_P_8021Q)) {
84 if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
85 return ERR_PTR(-EINVAL);
87 vh = (struct vlan_hdr *)(skb->data + vlan_depth);
88 type = vh->h_vlan_encapsulated_proto;
89 vlan_depth += VLAN_HLEN;
92 /* this hack needed to get regular skb_gso_segment() */
93 #undef skb_gso_segment
94 skb_proto = skb->protocol;
97 skb_gso = skb_gso_segment(skb, features);
98 skb->protocol = skb_proto;
101 #endif /* kernel version < 2.6.38 */