Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 1 | #include <linux/skbuff.h> |
| 2 | #include <linux/netdevice.h> |
| 3 | #include <linux/if_vlan.h> |
Herbert Xu | 4ead443 | 2009-03-01 00:11:52 -0800 | [diff] [blame] | 4 | #include <linux/netpoll.h> |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 5 | #include "vlan.h" |
| 6 | |
| 7 | /* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */ |
| 8 | int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, |
Patrick McHardy | 9bb8582 | 2008-07-08 03:24:44 -0700 | [diff] [blame] | 9 | u16 vlan_tci, int polling) |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 10 | { |
Herbert Xu | 4ead443 | 2009-03-01 00:11:52 -0800 | [diff] [blame] | 11 | if (netpoll_rx(skb)) |
| 12 | return NET_RX_DROP; |
| 13 | |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 14 | if (skb_bond_should_drop(skb)) |
| 15 | goto drop; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 16 | |
Patrick McHardy | bc1d041 | 2008-07-14 22:49:30 -0700 | [diff] [blame] | 17 | skb->vlan_tci = vlan_tci; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 18 | skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK); |
| 19 | |
| 20 | if (!skb->dev) |
| 21 | goto drop; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 22 | |
| 23 | return (polling ? netif_receive_skb(skb) : netif_rx(skb)); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 24 | |
| 25 | drop: |
| 26 | dev_kfree_skb_any(skb); |
| 27 | return NET_RX_DROP; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 28 | } |
| 29 | EXPORT_SYMBOL(__vlan_hwaccel_rx); |
| 30 | |
| 31 | int vlan_hwaccel_do_receive(struct sk_buff *skb) |
| 32 | { |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 33 | struct net_device *dev = skb->dev; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 34 | struct net_device_stats *stats; |
| 35 | |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 36 | skb->dev = vlan_dev_info(dev)->real_dev; |
Patrick McHardy | bc1d041 | 2008-07-14 22:49:30 -0700 | [diff] [blame] | 37 | netif_nit_deliver(skb); |
| 38 | |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 39 | skb->dev = dev; |
| 40 | skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci); |
Patrick McHardy | bc1d041 | 2008-07-14 22:49:30 -0700 | [diff] [blame] | 41 | skb->vlan_tci = 0; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 42 | |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 43 | stats = &dev->stats; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 44 | stats->rx_packets++; |
| 45 | stats->rx_bytes += skb->len; |
| 46 | |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 47 | switch (skb->pkt_type) { |
| 48 | case PACKET_BROADCAST: |
| 49 | break; |
| 50 | case PACKET_MULTICAST: |
| 51 | stats->multicast++; |
| 52 | break; |
| 53 | case PACKET_OTHERHOST: |
| 54 | /* Our lower layer thinks this is not local, let's make sure. |
| 55 | * This allows the VLAN to have a different MAC than the |
| 56 | * underlying device, and still route correctly. */ |
| 57 | if (!compare_ether_addr(eth_hdr(skb)->h_dest, |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 58 | dev->dev_addr)) |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 59 | skb->pkt_type = PACKET_HOST; |
| 60 | break; |
| 61 | }; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 62 | return 0; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 63 | } |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 64 | |
| 65 | struct net_device *vlan_dev_real_dev(const struct net_device *dev) |
| 66 | { |
| 67 | return vlan_dev_info(dev)->real_dev; |
| 68 | } |
Ben Greear | 116cb42 | 2009-01-26 12:37:53 -0800 | [diff] [blame] | 69 | EXPORT_SYMBOL(vlan_dev_real_dev); |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 70 | |
| 71 | u16 vlan_dev_vlan_id(const struct net_device *dev) |
| 72 | { |
| 73 | return vlan_dev_info(dev)->vlan_id; |
| 74 | } |
Ben Greear | 116cb42 | 2009-01-26 12:37:53 -0800 | [diff] [blame] | 75 | EXPORT_SYMBOL(vlan_dev_vlan_id); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 76 | |
| 77 | static int vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp, |
| 78 | unsigned int vlan_tci, struct sk_buff *skb) |
| 79 | { |
| 80 | struct sk_buff *p; |
| 81 | |
| 82 | if (skb_bond_should_drop(skb)) |
| 83 | goto drop; |
| 84 | |
| 85 | skb->vlan_tci = vlan_tci; |
| 86 | skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK); |
| 87 | |
| 88 | if (!skb->dev) |
| 89 | goto drop; |
| 90 | |
| 91 | for (p = napi->gro_list; p; p = p->next) { |
Herbert Xu | aa4b9f5 | 2009-02-08 18:00:37 +0000 | [diff] [blame] | 92 | NAPI_GRO_CB(p)->same_flow = |
| 93 | p->dev == skb->dev && !compare_ether_header( |
| 94 | skb_mac_header(p), skb_gro_mac_header(skb)); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 95 | NAPI_GRO_CB(p)->flush = 0; |
| 96 | } |
| 97 | |
| 98 | return dev_gro_receive(napi, skb); |
| 99 | |
| 100 | drop: |
Herbert Xu | d1c76af | 2009-03-16 10:50:02 -0700 | [diff] [blame] | 101 | return GRO_DROP; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, |
| 105 | unsigned int vlan_tci, struct sk_buff *skb) |
| 106 | { |
Herbert Xu | 2ffb455 | 2009-03-17 13:10:52 -0700 | [diff] [blame] | 107 | if (netpoll_rx_on(skb)) |
| 108 | return vlan_hwaccel_receive_skb(skb, grp, vlan_tci); |
| 109 | |
Herbert Xu | 8691173 | 2009-01-29 14:19:50 +0000 | [diff] [blame] | 110 | skb_gro_reset_offset(skb); |
| 111 | |
Herbert Xu | 5d0d9be | 2009-01-29 14:19:48 +0000 | [diff] [blame] | 112 | return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 113 | } |
| 114 | EXPORT_SYMBOL(vlan_gro_receive); |
| 115 | |
| 116 | int vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp, |
Herbert Xu | 76620aa | 2009-04-16 02:02:07 -0700 | [diff] [blame] | 117 | unsigned int vlan_tci) |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 118 | { |
Herbert Xu | 76620aa | 2009-04-16 02:02:07 -0700 | [diff] [blame] | 119 | struct sk_buff *skb = napi_frags_skb(napi); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 120 | |
| 121 | if (!skb) |
Herbert Xu | 5d0d9be | 2009-01-29 14:19:48 +0000 | [diff] [blame] | 122 | return NET_RX_DROP; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 123 | |
Herbert Xu | 1db9e29 | 2009-04-13 04:41:01 +0000 | [diff] [blame] | 124 | if (netpoll_rx_on(skb)) { |
| 125 | skb->protocol = eth_type_trans(skb, skb->dev); |
Herbert Xu | 2ffb455 | 2009-03-17 13:10:52 -0700 | [diff] [blame] | 126 | return vlan_hwaccel_receive_skb(skb, grp, vlan_tci); |
Herbert Xu | 1db9e29 | 2009-04-13 04:41:01 +0000 | [diff] [blame] | 127 | } |
Herbert Xu | 2ffb455 | 2009-03-17 13:10:52 -0700 | [diff] [blame] | 128 | |
Herbert Xu | 5d0d9be | 2009-01-29 14:19:48 +0000 | [diff] [blame] | 129 | return napi_frags_finish(napi, skb, |
| 130 | vlan_gro_common(napi, grp, vlan_tci, skb)); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 131 | } |
| 132 | EXPORT_SYMBOL(vlan_gro_frags); |