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 | { |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 11 | struct net_device *vlan_dev; |
| 12 | u16 vlan_id; |
| 13 | |
Herbert Xu | 4ead443 | 2009-03-01 00:11:52 -0800 | [diff] [blame] | 14 | if (netpoll_rx(skb)) |
| 15 | return NET_RX_DROP; |
| 16 | |
Eric Dumazet | 0641e4f | 2010-03-18 21:16:45 -0700 | [diff] [blame] | 17 | if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master))) |
John Fastabend | 597a264 | 2010-06-03 09:30:11 +0000 | [diff] [blame] | 18 | skb->deliver_no_wcard = 1; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 19 | |
Andy Gospodarek | 1f3c880 | 2009-12-14 10:48:58 +0000 | [diff] [blame] | 20 | skb->skb_iif = skb->dev->ifindex; |
Eric Dumazet | b93ab83 | 2009-11-13 06:33:11 +0000 | [diff] [blame] | 21 | __vlan_hwaccel_put_tag(skb, vlan_tci); |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 22 | vlan_id = vlan_tci & VLAN_VID_MASK; |
| 23 | vlan_dev = vlan_group_get_device(grp, vlan_id); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 24 | |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 25 | if (vlan_dev) |
| 26 | skb->dev = vlan_dev; |
| 27 | else if (vlan_id) |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 28 | goto drop; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 29 | |
| 30 | return (polling ? netif_receive_skb(skb) : netif_rx(skb)); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 31 | |
| 32 | drop: |
| 33 | dev_kfree_skb_any(skb); |
| 34 | return NET_RX_DROP; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 35 | } |
| 36 | EXPORT_SYMBOL(__vlan_hwaccel_rx); |
| 37 | |
| 38 | int vlan_hwaccel_do_receive(struct sk_buff *skb) |
| 39 | { |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 40 | struct net_device *dev = skb->dev; |
Eric Dumazet | 9793241 | 2009-11-17 04:53:09 +0000 | [diff] [blame] | 41 | struct vlan_rx_stats *rx_stats; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 42 | |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 43 | skb->dev = vlan_dev_info(dev)->real_dev; |
Patrick McHardy | bc1d041 | 2008-07-14 22:49:30 -0700 | [diff] [blame] | 44 | netif_nit_deliver(skb); |
| 45 | |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 46 | skb->dev = dev; |
| 47 | skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci); |
Patrick McHardy | bc1d041 | 2008-07-14 22:49:30 -0700 | [diff] [blame] | 48 | skb->vlan_tci = 0; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 49 | |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 50 | rx_stats = this_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats); |
Eric Dumazet | 9793241 | 2009-11-17 04:53:09 +0000 | [diff] [blame] | 51 | |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 52 | u64_stats_update_begin(&rx_stats->syncp); |
Eric Dumazet | 9793241 | 2009-11-17 04:53:09 +0000 | [diff] [blame] | 53 | rx_stats->rx_packets++; |
| 54 | rx_stats->rx_bytes += skb->len; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 55 | |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 56 | switch (skb->pkt_type) { |
| 57 | case PACKET_BROADCAST: |
| 58 | break; |
| 59 | case PACKET_MULTICAST: |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 60 | rx_stats->rx_multicast++; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 61 | break; |
| 62 | case PACKET_OTHERHOST: |
| 63 | /* Our lower layer thinks this is not local, let's make sure. |
| 64 | * This allows the VLAN to have a different MAC than the |
| 65 | * underlying device, and still route correctly. */ |
| 66 | if (!compare_ether_addr(eth_hdr(skb)->h_dest, |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 67 | dev->dev_addr)) |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 68 | skb->pkt_type = PACKET_HOST; |
| 69 | break; |
Joe Perches | ccbd6a5 | 2010-05-14 10:58:26 +0000 | [diff] [blame] | 70 | } |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 71 | u64_stats_update_end(&rx_stats->syncp); |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 72 | return 0; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 73 | } |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 74 | |
| 75 | struct net_device *vlan_dev_real_dev(const struct net_device *dev) |
| 76 | { |
| 77 | return vlan_dev_info(dev)->real_dev; |
| 78 | } |
Ben Greear | 116cb42 | 2009-01-26 12:37:53 -0800 | [diff] [blame] | 79 | EXPORT_SYMBOL(vlan_dev_real_dev); |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 80 | |
| 81 | u16 vlan_dev_vlan_id(const struct net_device *dev) |
| 82 | { |
| 83 | return vlan_dev_info(dev)->vlan_id; |
| 84 | } |
Ben Greear | 116cb42 | 2009-01-26 12:37:53 -0800 | [diff] [blame] | 85 | EXPORT_SYMBOL(vlan_dev_vlan_id); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 86 | |
Ben Hutchings | 5b252f0 | 2009-10-29 07:17:09 +0000 | [diff] [blame] | 87 | static gro_result_t |
| 88 | vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp, |
| 89 | unsigned int vlan_tci, struct sk_buff *skb) |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 90 | { |
| 91 | struct sk_buff *p; |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 92 | struct net_device *vlan_dev; |
| 93 | u16 vlan_id; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 94 | |
Eric Dumazet | 0641e4f | 2010-03-18 21:16:45 -0700 | [diff] [blame] | 95 | if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master))) |
John Fastabend | 597a264 | 2010-06-03 09:30:11 +0000 | [diff] [blame] | 96 | skb->deliver_no_wcard = 1; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 97 | |
Andy Gospodarek | 1f3c880 | 2009-12-14 10:48:58 +0000 | [diff] [blame] | 98 | skb->skb_iif = skb->dev->ifindex; |
Eric Dumazet | b93ab83 | 2009-11-13 06:33:11 +0000 | [diff] [blame] | 99 | __vlan_hwaccel_put_tag(skb, vlan_tci); |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 100 | vlan_id = vlan_tci & VLAN_VID_MASK; |
| 101 | vlan_dev = vlan_group_get_device(grp, vlan_id); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 102 | |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 103 | if (vlan_dev) |
| 104 | skb->dev = vlan_dev; |
| 105 | else if (vlan_id) |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 106 | goto drop; |
| 107 | |
| 108 | for (p = napi->gro_list; p; p = p->next) { |
Herbert Xu | aa4b9f5 | 2009-02-08 18:00:37 +0000 | [diff] [blame] | 109 | NAPI_GRO_CB(p)->same_flow = |
| 110 | p->dev == skb->dev && !compare_ether_header( |
| 111 | skb_mac_header(p), skb_gro_mac_header(skb)); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 112 | NAPI_GRO_CB(p)->flush = 0; |
| 113 | } |
| 114 | |
| 115 | return dev_gro_receive(napi, skb); |
| 116 | |
| 117 | drop: |
Herbert Xu | d1c76af | 2009-03-16 10:50:02 -0700 | [diff] [blame] | 118 | return GRO_DROP; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Ben Hutchings | c7c4b3b | 2009-10-29 21:36:53 -0700 | [diff] [blame] | 121 | gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, |
| 122 | unsigned int vlan_tci, struct sk_buff *skb) |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 123 | { |
Herbert Xu | 2ffb455 | 2009-03-17 13:10:52 -0700 | [diff] [blame] | 124 | if (netpoll_rx_on(skb)) |
Ben Hutchings | c7c4b3b | 2009-10-29 21:36:53 -0700 | [diff] [blame] | 125 | return vlan_hwaccel_receive_skb(skb, grp, vlan_tci) |
| 126 | ? GRO_DROP : GRO_NORMAL; |
Herbert Xu | 2ffb455 | 2009-03-17 13:10:52 -0700 | [diff] [blame] | 127 | |
Herbert Xu | 8691173 | 2009-01-29 14:19:50 +0000 | [diff] [blame] | 128 | skb_gro_reset_offset(skb); |
| 129 | |
Herbert Xu | 5d0d9be | 2009-01-29 14:19:48 +0000 | [diff] [blame] | 130 | 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] | 131 | } |
| 132 | EXPORT_SYMBOL(vlan_gro_receive); |
| 133 | |
Ben Hutchings | c7c4b3b | 2009-10-29 21:36:53 -0700 | [diff] [blame] | 134 | gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp, |
| 135 | unsigned int vlan_tci) |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 136 | { |
Herbert Xu | 76620aa | 2009-04-16 02:02:07 -0700 | [diff] [blame] | 137 | struct sk_buff *skb = napi_frags_skb(napi); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 138 | |
| 139 | if (!skb) |
Ben Hutchings | c7c4b3b | 2009-10-29 21:36:53 -0700 | [diff] [blame] | 140 | return GRO_DROP; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 141 | |
Herbert Xu | 1db9e29 | 2009-04-13 04:41:01 +0000 | [diff] [blame] | 142 | if (netpoll_rx_on(skb)) { |
| 143 | skb->protocol = eth_type_trans(skb, skb->dev); |
Ben Hutchings | c7c4b3b | 2009-10-29 21:36:53 -0700 | [diff] [blame] | 144 | return vlan_hwaccel_receive_skb(skb, grp, vlan_tci) |
| 145 | ? GRO_DROP : GRO_NORMAL; |
Herbert Xu | 1db9e29 | 2009-04-13 04:41:01 +0000 | [diff] [blame] | 146 | } |
Herbert Xu | 2ffb455 | 2009-03-17 13:10:52 -0700 | [diff] [blame] | 147 | |
Herbert Xu | 5d0d9be | 2009-01-29 14:19:48 +0000 | [diff] [blame] | 148 | return napi_frags_finish(napi, skb, |
| 149 | vlan_gro_common(napi, grp, vlan_tci, skb)); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 150 | } |
| 151 | EXPORT_SYMBOL(vlan_gro_frags); |