blob: 889f4ac4459abcf477210297b6572dc71cf25ca5 [file] [log] [blame]
Patrick McHardy7750f402008-07-08 03:23:36 -07001#include <linux/skbuff.h>
2#include <linux/netdevice.h>
3#include <linux/if_vlan.h>
Herbert Xu4ead4432009-03-01 00:11:52 -08004#include <linux/netpoll.h>
Patrick McHardy7750f402008-07-08 03:23:36 -07005#include "vlan.h"
6
7/* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
8int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
Patrick McHardy9bb85822008-07-08 03:24:44 -07009 u16 vlan_tci, int polling)
Patrick McHardy7750f402008-07-08 03:23:36 -070010{
Pedro Garciaad1afb02010-07-18 15:38:44 -070011 struct net_device *vlan_dev;
12 u16 vlan_id;
13
Herbert Xu4ead4432009-03-01 00:11:52 -080014 if (netpoll_rx(skb))
15 return NET_RX_DROP;
16
Eric Dumazet0641e4f2010-03-18 21:16:45 -070017 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
John Fastabend597a2642010-06-03 09:30:11 +000018 skb->deliver_no_wcard = 1;
Patrick McHardy7750f402008-07-08 03:23:36 -070019
Andy Gospodarek1f3c8802009-12-14 10:48:58 +000020 skb->skb_iif = skb->dev->ifindex;
Eric Dumazetb93ab832009-11-13 06:33:11 +000021 __vlan_hwaccel_put_tag(skb, vlan_tci);
Pedro Garciaad1afb02010-07-18 15:38:44 -070022 vlan_id = vlan_tci & VLAN_VID_MASK;
23 vlan_dev = vlan_group_get_device(grp, vlan_id);
Herbert Xue1c096e2009-01-06 10:50:09 -080024
Pedro Garciaad1afb02010-07-18 15:38:44 -070025 if (vlan_dev)
26 skb->dev = vlan_dev;
27 else if (vlan_id)
Herbert Xue1c096e2009-01-06 10:50:09 -080028 goto drop;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080029
30 return (polling ? netif_receive_skb(skb) : netif_rx(skb));
Herbert Xue1c096e2009-01-06 10:50:09 -080031
32drop:
33 dev_kfree_skb_any(skb);
34 return NET_RX_DROP;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080035}
36EXPORT_SYMBOL(__vlan_hwaccel_rx);
37
Changli Gao05532122010-08-22 21:03:33 -070038void vlan_hwaccel_do_receive(struct sk_buff *skb)
Patrick McHardy9b22ea52008-11-04 14:49:57 -080039{
Herbert Xue1c096e2009-01-06 10:50:09 -080040 struct net_device *dev = skb->dev;
Eric Dumazet97932412009-11-17 04:53:09 +000041 struct vlan_rx_stats *rx_stats;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080042
Jiri Pirko72ed62f2010-08-31 04:58:18 +000043 skb->dev = vlan_dev_real_dev(dev);
Patrick McHardybc1d0412008-07-14 22:49:30 -070044 netif_nit_deliver(skb);
45
Patrick McHardy9b22ea52008-11-04 14:49:57 -080046 skb->dev = dev;
47 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
Patrick McHardybc1d0412008-07-14 22:49:30 -070048 skb->vlan_tci = 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070049
Eric Dumazet9618e2f2010-06-24 00:55:06 +000050 rx_stats = this_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats);
Eric Dumazet97932412009-11-17 04:53:09 +000051
Eric Dumazet9618e2f2010-06-24 00:55:06 +000052 u64_stats_update_begin(&rx_stats->syncp);
Eric Dumazet97932412009-11-17 04:53:09 +000053 rx_stats->rx_packets++;
54 rx_stats->rx_bytes += skb->len;
Patrick McHardy7750f402008-07-08 03:23:36 -070055
Patrick McHardy7750f402008-07-08 03:23:36 -070056 switch (skb->pkt_type) {
57 case PACKET_BROADCAST:
58 break;
59 case PACKET_MULTICAST:
Eric Dumazet9618e2f2010-06-24 00:55:06 +000060 rx_stats->rx_multicast++;
Patrick McHardy7750f402008-07-08 03:23:36 -070061 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 McHardy9b22ea52008-11-04 14:49:57 -080067 dev->dev_addr))
Patrick McHardy7750f402008-07-08 03:23:36 -070068 skb->pkt_type = PACKET_HOST;
69 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +000070 }
Eric Dumazet9618e2f2010-06-24 00:55:06 +000071 u64_stats_update_end(&rx_stats->syncp);
Patrick McHardy7750f402008-07-08 03:23:36 -070072}
Patrick McHardy22d1ba72008-07-08 03:23:57 -070073
74struct net_device *vlan_dev_real_dev(const struct net_device *dev)
75{
76 return vlan_dev_info(dev)->real_dev;
77}
Ben Greear116cb422009-01-26 12:37:53 -080078EXPORT_SYMBOL(vlan_dev_real_dev);
Patrick McHardy22d1ba72008-07-08 03:23:57 -070079
80u16 vlan_dev_vlan_id(const struct net_device *dev)
81{
82 return vlan_dev_info(dev)->vlan_id;
83}
Ben Greear116cb422009-01-26 12:37:53 -080084EXPORT_SYMBOL(vlan_dev_vlan_id);
Herbert Xue1c096e2009-01-06 10:50:09 -080085
Ben Hutchings5b252f02009-10-29 07:17:09 +000086static gro_result_t
87vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
88 unsigned int vlan_tci, struct sk_buff *skb)
Herbert Xue1c096e2009-01-06 10:50:09 -080089{
90 struct sk_buff *p;
Pedro Garciaad1afb02010-07-18 15:38:44 -070091 struct net_device *vlan_dev;
92 u16 vlan_id;
Herbert Xue1c096e2009-01-06 10:50:09 -080093
Eric Dumazet0641e4f2010-03-18 21:16:45 -070094 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
John Fastabend597a2642010-06-03 09:30:11 +000095 skb->deliver_no_wcard = 1;
Herbert Xue1c096e2009-01-06 10:50:09 -080096
Andy Gospodarek1f3c8802009-12-14 10:48:58 +000097 skb->skb_iif = skb->dev->ifindex;
Eric Dumazetb93ab832009-11-13 06:33:11 +000098 __vlan_hwaccel_put_tag(skb, vlan_tci);
Pedro Garciaad1afb02010-07-18 15:38:44 -070099 vlan_id = vlan_tci & VLAN_VID_MASK;
100 vlan_dev = vlan_group_get_device(grp, vlan_id);
Herbert Xue1c096e2009-01-06 10:50:09 -0800101
Pedro Garciaad1afb02010-07-18 15:38:44 -0700102 if (vlan_dev)
103 skb->dev = vlan_dev;
104 else if (vlan_id)
Herbert Xue1c096e2009-01-06 10:50:09 -0800105 goto drop;
106
107 for (p = napi->gro_list; p; p = p->next) {
Eric Dumazet40d08022010-08-26 22:03:08 -0700108 unsigned long diffs;
109
110 diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev;
111 diffs |= compare_ether_header(skb_mac_header(p),
112 skb_gro_mac_header(skb));
113 NAPI_GRO_CB(p)->same_flow = !diffs;
Herbert Xue1c096e2009-01-06 10:50:09 -0800114 NAPI_GRO_CB(p)->flush = 0;
115 }
116
117 return dev_gro_receive(napi, skb);
118
119drop:
Herbert Xud1c76af2009-03-16 10:50:02 -0700120 return GRO_DROP;
Herbert Xue1c096e2009-01-06 10:50:09 -0800121}
122
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700123gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
124 unsigned int vlan_tci, struct sk_buff *skb)
Herbert Xue1c096e2009-01-06 10:50:09 -0800125{
Herbert Xu2ffb4552009-03-17 13:10:52 -0700126 if (netpoll_rx_on(skb))
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700127 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
128 ? GRO_DROP : GRO_NORMAL;
Herbert Xu2ffb4552009-03-17 13:10:52 -0700129
Herbert Xu86911732009-01-29 14:19:50 +0000130 skb_gro_reset_offset(skb);
131
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000132 return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
Herbert Xue1c096e2009-01-06 10:50:09 -0800133}
134EXPORT_SYMBOL(vlan_gro_receive);
135
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700136gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
137 unsigned int vlan_tci)
Herbert Xue1c096e2009-01-06 10:50:09 -0800138{
Herbert Xu76620aa2009-04-16 02:02:07 -0700139 struct sk_buff *skb = napi_frags_skb(napi);
Herbert Xue1c096e2009-01-06 10:50:09 -0800140
141 if (!skb)
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700142 return GRO_DROP;
Herbert Xue1c096e2009-01-06 10:50:09 -0800143
Herbert Xu1db9e292009-04-13 04:41:01 +0000144 if (netpoll_rx_on(skb)) {
145 skb->protocol = eth_type_trans(skb, skb->dev);
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700146 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
147 ? GRO_DROP : GRO_NORMAL;
Herbert Xu1db9e292009-04-13 04:41:01 +0000148 }
Herbert Xu2ffb4552009-03-17 13:10:52 -0700149
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000150 return napi_frags_finish(napi, skb,
151 vlan_gro_common(napi, grp, vlan_tci, skb));
Herbert Xue1c096e2009-01-06 10:50:09 -0800152}
153EXPORT_SYMBOL(vlan_gro_frags);