blob: bd537fc10254c9fbb6cf3872e8488bba1809781b [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{
Herbert Xu4ead4432009-03-01 00:11:52 -080011 if (netpoll_rx(skb))
12 return NET_RX_DROP;
13
Eric Dumazet0641e4f2010-03-18 21:16:45 -070014 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
Herbert Xue1c096e2009-01-06 10:50:09 -080015 goto drop;
Patrick McHardy7750f402008-07-08 03:23:36 -070016
Andy Gospodarek1f3c8802009-12-14 10:48:58 +000017 skb->skb_iif = skb->dev->ifindex;
Eric Dumazetb93ab832009-11-13 06:33:11 +000018 __vlan_hwaccel_put_tag(skb, vlan_tci);
Herbert Xue1c096e2009-01-06 10:50:09 -080019 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
20
21 if (!skb->dev)
22 goto drop;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080023
24 return (polling ? netif_receive_skb(skb) : netif_rx(skb));
Herbert Xue1c096e2009-01-06 10:50:09 -080025
26drop:
27 dev_kfree_skb_any(skb);
28 return NET_RX_DROP;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080029}
30EXPORT_SYMBOL(__vlan_hwaccel_rx);
31
32int vlan_hwaccel_do_receive(struct sk_buff *skb)
33{
Herbert Xue1c096e2009-01-06 10:50:09 -080034 struct net_device *dev = skb->dev;
Eric Dumazet97932412009-11-17 04:53:09 +000035 struct vlan_rx_stats *rx_stats;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080036
Herbert Xue1c096e2009-01-06 10:50:09 -080037 skb->dev = vlan_dev_info(dev)->real_dev;
Patrick McHardybc1d0412008-07-14 22:49:30 -070038 netif_nit_deliver(skb);
39
Patrick McHardy9b22ea52008-11-04 14:49:57 -080040 skb->dev = dev;
41 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
Patrick McHardybc1d0412008-07-14 22:49:30 -070042 skb->vlan_tci = 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070043
Eric Dumazet97932412009-11-17 04:53:09 +000044 rx_stats = per_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats,
45 smp_processor_id());
46
47 rx_stats->rx_packets++;
48 rx_stats->rx_bytes += skb->len;
Patrick McHardy7750f402008-07-08 03:23:36 -070049
Patrick McHardy7750f402008-07-08 03:23:36 -070050 switch (skb->pkt_type) {
51 case PACKET_BROADCAST:
52 break;
53 case PACKET_MULTICAST:
Eric Dumazet97932412009-11-17 04:53:09 +000054 rx_stats->multicast++;
Patrick McHardy7750f402008-07-08 03:23:36 -070055 break;
56 case PACKET_OTHERHOST:
57 /* Our lower layer thinks this is not local, let's make sure.
58 * This allows the VLAN to have a different MAC than the
59 * underlying device, and still route correctly. */
60 if (!compare_ether_addr(eth_hdr(skb)->h_dest,
Patrick McHardy9b22ea52008-11-04 14:49:57 -080061 dev->dev_addr))
Patrick McHardy7750f402008-07-08 03:23:36 -070062 skb->pkt_type = PACKET_HOST;
63 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +000064 }
Patrick McHardy9b22ea52008-11-04 14:49:57 -080065 return 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070066}
Patrick McHardy22d1ba72008-07-08 03:23:57 -070067
68struct net_device *vlan_dev_real_dev(const struct net_device *dev)
69{
70 return vlan_dev_info(dev)->real_dev;
71}
Ben Greear116cb422009-01-26 12:37:53 -080072EXPORT_SYMBOL(vlan_dev_real_dev);
Patrick McHardy22d1ba72008-07-08 03:23:57 -070073
74u16 vlan_dev_vlan_id(const struct net_device *dev)
75{
76 return vlan_dev_info(dev)->vlan_id;
77}
Ben Greear116cb422009-01-26 12:37:53 -080078EXPORT_SYMBOL(vlan_dev_vlan_id);
Herbert Xue1c096e2009-01-06 10:50:09 -080079
Ben Hutchings5b252f02009-10-29 07:17:09 +000080static gro_result_t
81vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
82 unsigned int vlan_tci, struct sk_buff *skb)
Herbert Xue1c096e2009-01-06 10:50:09 -080083{
84 struct sk_buff *p;
85
Eric Dumazet0641e4f2010-03-18 21:16:45 -070086 if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
Herbert Xue1c096e2009-01-06 10:50:09 -080087 goto drop;
88
Andy Gospodarek1f3c8802009-12-14 10:48:58 +000089 skb->skb_iif = skb->dev->ifindex;
Eric Dumazetb93ab832009-11-13 06:33:11 +000090 __vlan_hwaccel_put_tag(skb, vlan_tci);
Herbert Xue1c096e2009-01-06 10:50:09 -080091 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
92
93 if (!skb->dev)
94 goto drop;
95
96 for (p = napi->gro_list; p; p = p->next) {
Herbert Xuaa4b9f52009-02-08 18:00:37 +000097 NAPI_GRO_CB(p)->same_flow =
98 p->dev == skb->dev && !compare_ether_header(
99 skb_mac_header(p), skb_gro_mac_header(skb));
Herbert Xue1c096e2009-01-06 10:50:09 -0800100 NAPI_GRO_CB(p)->flush = 0;
101 }
102
103 return dev_gro_receive(napi, skb);
104
105drop:
Herbert Xud1c76af2009-03-16 10:50:02 -0700106 return GRO_DROP;
Herbert Xue1c096e2009-01-06 10:50:09 -0800107}
108
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700109gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
110 unsigned int vlan_tci, struct sk_buff *skb)
Herbert Xue1c096e2009-01-06 10:50:09 -0800111{
Herbert Xu2ffb4552009-03-17 13:10:52 -0700112 if (netpoll_rx_on(skb))
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700113 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
114 ? GRO_DROP : GRO_NORMAL;
Herbert Xu2ffb4552009-03-17 13:10:52 -0700115
Herbert Xu86911732009-01-29 14:19:50 +0000116 skb_gro_reset_offset(skb);
117
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000118 return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
Herbert Xue1c096e2009-01-06 10:50:09 -0800119}
120EXPORT_SYMBOL(vlan_gro_receive);
121
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700122gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
123 unsigned int vlan_tci)
Herbert Xue1c096e2009-01-06 10:50:09 -0800124{
Herbert Xu76620aa2009-04-16 02:02:07 -0700125 struct sk_buff *skb = napi_frags_skb(napi);
Herbert Xue1c096e2009-01-06 10:50:09 -0800126
127 if (!skb)
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700128 return GRO_DROP;
Herbert Xue1c096e2009-01-06 10:50:09 -0800129
Herbert Xu1db9e292009-04-13 04:41:01 +0000130 if (netpoll_rx_on(skb)) {
131 skb->protocol = eth_type_trans(skb, skb->dev);
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -0700132 return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
133 ? GRO_DROP : GRO_NORMAL;
Herbert Xu1db9e292009-04-13 04:41:01 +0000134 }
Herbert Xu2ffb4552009-03-17 13:10:52 -0700135
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000136 return napi_frags_finish(napi, skb,
137 vlan_gro_common(napi, grp, vlan_tci, skb));
Herbert Xue1c096e2009-01-06 10:50:09 -0800138}
139EXPORT_SYMBOL(vlan_gro_frags);