Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / 8021q / vlan_core.c
blobce8e3ab3e7a5ab6d0f0000e699fbca27f4629d9b
1 #include <linux/skbuff.h>
2 #include <linux/netdevice.h>
3 #include <linux/if_vlan.h>
4 #include <linux/netpoll.h>
5 #include "vlan.h"
7 bool vlan_hwaccel_do_receive(struct sk_buff **skbp)
9 struct sk_buff *skb = *skbp;
10 u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK;
11 struct net_device *vlan_dev;
12 struct vlan_pcpu_stats *rx_stats;
14 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;
21 skb = *skbp = skb_share_check(skb, GFP_ATOMIC);
22 if (unlikely(!skb))
23 return false;
25 skb->dev = vlan_dev;
26 skb->priority = vlan_get_ingress_priority(vlan_dev, skb->vlan_tci);
27 skb->vlan_tci = 0;
29 rx_stats = this_cpu_ptr(vlan_dev_info(vlan_dev)->vlan_pcpu_stats);
31 u64_stats_update_begin(&rx_stats->syncp);
32 rx_stats->rx_packets++;
33 rx_stats->rx_bytes += skb->len;
35 switch (skb->pkt_type) {
36 case PACKET_BROADCAST:
37 break;
38 case PACKET_MULTICAST:
39 rx_stats->rx_multicast++;
40 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,
46 vlan_dev->dev_addr))
47 skb->pkt_type = PACKET_HOST;
48 break;
50 u64_stats_update_end(&rx_stats->syncp);
52 return true;
55 struct net_device *vlan_dev_real_dev(const struct net_device *dev)
57 return vlan_dev_info(dev)->real_dev;
59 EXPORT_SYMBOL(vlan_dev_real_dev);
61 u16 vlan_dev_vlan_id(const struct net_device *dev)
63 return vlan_dev_info(dev)->vlan_id;
65 EXPORT_SYMBOL(vlan_dev_vlan_id);
67 /* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
68 int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
69 u16 vlan_tci, int polling)
71 __vlan_hwaccel_put_tag(skb, vlan_tci);
72 return polling ? netif_receive_skb(skb) : netif_rx(skb);
74 EXPORT_SYMBOL(__vlan_hwaccel_rx);
76 gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
77 unsigned int vlan_tci, struct sk_buff *skb)
79 __vlan_hwaccel_put_tag(skb, vlan_tci);
80 return napi_gro_receive(napi, skb);
82 EXPORT_SYMBOL(vlan_gro_receive);
84 gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
85 unsigned int vlan_tci)
87 __vlan_hwaccel_put_tag(napi->skb, vlan_tci);
88 return napi_gro_frags(napi);
90 EXPORT_SYMBOL(vlan_gro_frags);