blob: 69b2f79800a52c3e07e0f7c668daa1028025931e [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
Jesse Gross3701e5132010-10-20 13:56:06 +00007bool vlan_hwaccel_do_receive(struct sk_buff **skbp)
Patrick McHardy7750f402008-07-08 03:23:36 -07008{
Jesse Gross3701e5132010-10-20 13:56:06 +00009 struct sk_buff *skb = *skbp;
10 u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK;
Pedro Garciaad1afb02010-07-18 15:38:44 -070011 struct net_device *vlan_dev;
Jesse Gross3701e5132010-10-20 13:56:06 +000012 struct vlan_rx_stats *rx_stats;
Pedro Garciaad1afb02010-07-18 15:38:44 -070013
Jesse Gross3701e5132010-10-20 13:56:06 +000014 vlan_dev = vlan_find_dev(skb->dev, vlan_id);
15 if (!vlan_dev) {
16 if (vlan_id)
17 skb->pkt_type = PACKET_OTHERHOST;
18 return false;
Eric Dumazet173e79f2010-09-30 02:16:44 +000019 }
Patrick McHardy9b22ea52008-11-04 14:49:57 -080020
Jesse Gross3701e5132010-10-20 13:56:06 +000021 skb = *skbp = skb_share_check(skb, GFP_ATOMIC);
22 if (unlikely(!skb))
23 return false;
Herbert Xue1c096e2009-01-06 10:50:09 -080024
Jesse Gross3701e5132010-10-20 13:56:06 +000025 skb->dev = vlan_dev;
26 skb->priority = vlan_get_ingress_priority(vlan_dev, skb->vlan_tci);
Patrick McHardybc1d0412008-07-14 22:49:30 -070027 skb->vlan_tci = 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070028
Jesse Gross3701e5132010-10-20 13:56:06 +000029 rx_stats = this_cpu_ptr(vlan_dev_info(vlan_dev)->vlan_rx_stats);
Eric Dumazet97932412009-11-17 04:53:09 +000030
Eric Dumazet9618e2f2010-06-24 00:55:06 +000031 u64_stats_update_begin(&rx_stats->syncp);
Eric Dumazet97932412009-11-17 04:53:09 +000032 rx_stats->rx_packets++;
33 rx_stats->rx_bytes += skb->len;
Patrick McHardy7750f402008-07-08 03:23:36 -070034
Patrick McHardy7750f402008-07-08 03:23:36 -070035 switch (skb->pkt_type) {
36 case PACKET_BROADCAST:
37 break;
38 case PACKET_MULTICAST:
Eric Dumazet9618e2f2010-06-24 00:55:06 +000039 rx_stats->rx_multicast++;
Patrick McHardy7750f402008-07-08 03:23:36 -070040 break;
41 case PACKET_OTHERHOST:
42 /* Our lower layer thinks this is not local, let's make sure.
43 * This allows the VLAN to have a different MAC than the
44 * underlying device, and still route correctly. */
45 if (!compare_ether_addr(eth_hdr(skb)->h_dest,
Jesse Gross3701e5132010-10-20 13:56:06 +000046 vlan_dev->dev_addr))
Patrick McHardy7750f402008-07-08 03:23:36 -070047 skb->pkt_type = PACKET_HOST;
48 break;
Joe Perchesccbd6a52010-05-14 10:58:26 +000049 }
Eric Dumazet9618e2f2010-06-24 00:55:06 +000050 u64_stats_update_end(&rx_stats->syncp);
Jesse Gross3701e5132010-10-20 13:56:06 +000051
52 return true;
Patrick McHardy7750f402008-07-08 03:23:36 -070053}
Patrick McHardy22d1ba72008-07-08 03:23:57 -070054
55struct net_device *vlan_dev_real_dev(const struct net_device *dev)
56{
57 return vlan_dev_info(dev)->real_dev;
58}
Ben Greear116cb422009-01-26 12:37:53 -080059EXPORT_SYMBOL(vlan_dev_real_dev);
Patrick McHardy22d1ba72008-07-08 03:23:57 -070060
61u16 vlan_dev_vlan_id(const struct net_device *dev)
62{
63 return vlan_dev_info(dev)->vlan_id;
64}
Ben Greear116cb422009-01-26 12:37:53 -080065EXPORT_SYMBOL(vlan_dev_vlan_id);
Herbert Xue1c096e2009-01-06 10:50:09 -080066
Jesse Gross3701e5132010-10-20 13:56:06 +000067/* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
68int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
69 u16 vlan_tci, int polling)
Herbert Xue1c096e2009-01-06 10:50:09 -080070{
Eric Dumazetb93ab832009-11-13 06:33:11 +000071 __vlan_hwaccel_put_tag(skb, vlan_tci);
Jesse Gross3701e5132010-10-20 13:56:06 +000072 return polling ? netif_receive_skb(skb) : netif_rx(skb);
Herbert Xue1c096e2009-01-06 10:50:09 -080073}
Jesse Gross3701e5132010-10-20 13:56:06 +000074EXPORT_SYMBOL(__vlan_hwaccel_rx);
Herbert Xue1c096e2009-01-06 10:50:09 -080075
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -070076gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
77 unsigned int vlan_tci, struct sk_buff *skb)
Herbert Xue1c096e2009-01-06 10:50:09 -080078{
Jesse Gross3701e5132010-10-20 13:56:06 +000079 __vlan_hwaccel_put_tag(skb, vlan_tci);
80 return napi_gro_receive(napi, skb);
Herbert Xue1c096e2009-01-06 10:50:09 -080081}
82EXPORT_SYMBOL(vlan_gro_receive);
83
Ben Hutchingsc7c4b3b2009-10-29 21:36:53 -070084gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
85 unsigned int vlan_tci)
Herbert Xue1c096e2009-01-06 10:50:09 -080086{
Jesse Gross3701e5132010-10-20 13:56:06 +000087 __vlan_hwaccel_put_tag(napi->skb, vlan_tci);
88 return napi_gro_frags(napi);
Herbert Xue1c096e2009-01-06 10:50:09 -080089}
90EXPORT_SYMBOL(vlan_gro_frags);