blob: 70435af153f24c56b6dba620a0b44852e2580ad9 [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>
4#include "vlan.h"
5
6/* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
7int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
Patrick McHardy9bb85822008-07-08 03:24:44 -07008 u16 vlan_tci, int polling)
Patrick McHardy7750f402008-07-08 03:23:36 -07009{
Herbert Xue1c096e2009-01-06 10:50:09 -080010 if (skb_bond_should_drop(skb))
11 goto drop;
Patrick McHardy7750f402008-07-08 03:23:36 -070012
Patrick McHardybc1d0412008-07-14 22:49:30 -070013 skb->vlan_tci = vlan_tci;
Herbert Xue1c096e2009-01-06 10:50:09 -080014 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
15
16 if (!skb->dev)
17 goto drop;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080018
19 return (polling ? netif_receive_skb(skb) : netif_rx(skb));
Herbert Xue1c096e2009-01-06 10:50:09 -080020
21drop:
22 dev_kfree_skb_any(skb);
23 return NET_RX_DROP;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080024}
25EXPORT_SYMBOL(__vlan_hwaccel_rx);
26
27int vlan_hwaccel_do_receive(struct sk_buff *skb)
28{
Herbert Xue1c096e2009-01-06 10:50:09 -080029 struct net_device *dev = skb->dev;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080030 struct net_device_stats *stats;
31
Herbert Xue1c096e2009-01-06 10:50:09 -080032 skb->dev = vlan_dev_info(dev)->real_dev;
Patrick McHardybc1d0412008-07-14 22:49:30 -070033 netif_nit_deliver(skb);
34
Patrick McHardy9b22ea52008-11-04 14:49:57 -080035 skb->dev = dev;
36 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
Patrick McHardybc1d0412008-07-14 22:49:30 -070037 skb->vlan_tci = 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070038
Patrick McHardy9b22ea52008-11-04 14:49:57 -080039 stats = &dev->stats;
Patrick McHardy7750f402008-07-08 03:23:36 -070040 stats->rx_packets++;
41 stats->rx_bytes += skb->len;
42
Patrick McHardy7750f402008-07-08 03:23:36 -070043 switch (skb->pkt_type) {
44 case PACKET_BROADCAST:
45 break;
46 case PACKET_MULTICAST:
47 stats->multicast++;
48 break;
49 case PACKET_OTHERHOST:
50 /* Our lower layer thinks this is not local, let's make sure.
51 * This allows the VLAN to have a different MAC than the
52 * underlying device, and still route correctly. */
53 if (!compare_ether_addr(eth_hdr(skb)->h_dest,
Patrick McHardy9b22ea52008-11-04 14:49:57 -080054 dev->dev_addr))
Patrick McHardy7750f402008-07-08 03:23:36 -070055 skb->pkt_type = PACKET_HOST;
56 break;
57 };
Patrick McHardy9b22ea52008-11-04 14:49:57 -080058 return 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070059}
Patrick McHardy22d1ba72008-07-08 03:23:57 -070060
61struct net_device *vlan_dev_real_dev(const struct net_device *dev)
62{
63 return vlan_dev_info(dev)->real_dev;
64}
Ben Greear116cb422009-01-26 12:37:53 -080065EXPORT_SYMBOL(vlan_dev_real_dev);
Patrick McHardy22d1ba72008-07-08 03:23:57 -070066
67u16 vlan_dev_vlan_id(const struct net_device *dev)
68{
69 return vlan_dev_info(dev)->vlan_id;
70}
Ben Greear116cb422009-01-26 12:37:53 -080071EXPORT_SYMBOL(vlan_dev_vlan_id);
Herbert Xue1c096e2009-01-06 10:50:09 -080072
73static int vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
74 unsigned int vlan_tci, struct sk_buff *skb)
75{
76 struct sk_buff *p;
77
78 if (skb_bond_should_drop(skb))
79 goto drop;
80
81 skb->vlan_tci = vlan_tci;
82 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
83
84 if (!skb->dev)
85 goto drop;
86
87 for (p = napi->gro_list; p; p = p->next) {
Herbert Xuaa4b9f52009-02-08 18:00:37 +000088 NAPI_GRO_CB(p)->same_flow =
89 p->dev == skb->dev && !compare_ether_header(
90 skb_mac_header(p), skb_gro_mac_header(skb));
Herbert Xue1c096e2009-01-06 10:50:09 -080091 NAPI_GRO_CB(p)->flush = 0;
92 }
93
94 return dev_gro_receive(napi, skb);
95
96drop:
97 return 2;
98}
99
100int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
101 unsigned int vlan_tci, struct sk_buff *skb)
102{
Herbert Xu86911732009-01-29 14:19:50 +0000103 skb_gro_reset_offset(skb);
104
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000105 return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
Herbert Xue1c096e2009-01-06 10:50:09 -0800106}
107EXPORT_SYMBOL(vlan_gro_receive);
108
109int vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
110 unsigned int vlan_tci, struct napi_gro_fraginfo *info)
111{
112 struct sk_buff *skb = napi_fraginfo_skb(napi, info);
Herbert Xue1c096e2009-01-06 10:50:09 -0800113
114 if (!skb)
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000115 return NET_RX_DROP;
Herbert Xue1c096e2009-01-06 10:50:09 -0800116
Herbert Xu5d0d9be2009-01-29 14:19:48 +0000117 return napi_frags_finish(napi, skb,
118 vlan_gro_common(napi, grp, vlan_tci, skb));
Herbert Xue1c096e2009-01-06 10:50:09 -0800119}
120EXPORT_SYMBOL(vlan_gro_frags);