vlan_core.c 3.1 KB
Newer Older
1 2 3
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/if_vlan.h>
4
#include <linux/netpoll.h>
5 6 7 8
#include "vlan.h"

/* VLAN rx hw acceleration helper.  This acts like netif_{rx,receive_skb}(). */
int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
9
		      u16 vlan_tci, int polling)
10
{
11 12 13
	if (netpoll_rx(skb))
		return NET_RX_DROP;

H
Herbert Xu 已提交
14 15
	if (skb_bond_should_drop(skb))
		goto drop;
16

17
	skb->vlan_tci = vlan_tci;
H
Herbert Xu 已提交
18 19 20 21
	skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);

	if (!skb->dev)
		goto drop;
22 23

	return (polling ? netif_receive_skb(skb) : netif_rx(skb));
H
Herbert Xu 已提交
24 25 26 27

drop:
	dev_kfree_skb_any(skb);
	return NET_RX_DROP;
28 29 30 31 32
}
EXPORT_SYMBOL(__vlan_hwaccel_rx);

int vlan_hwaccel_do_receive(struct sk_buff *skb)
{
H
Herbert Xu 已提交
33
	struct net_device *dev = skb->dev;
34 35
	struct net_device_stats *stats;

H
Herbert Xu 已提交
36
	skb->dev = vlan_dev_info(dev)->real_dev;
37 38
	netif_nit_deliver(skb);

39 40
	skb->dev = dev;
	skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
41
	skb->vlan_tci = 0;
42

43
	stats = &dev->stats;
44 45 46 47 48 49 50 51 52 53 54 55 56 57
	stats->rx_packets++;
	stats->rx_bytes += skb->len;

	switch (skb->pkt_type) {
	case PACKET_BROADCAST:
		break;
	case PACKET_MULTICAST:
		stats->multicast++;
		break;
	case PACKET_OTHERHOST:
		/* Our lower layer thinks this is not local, let's make sure.
		 * This allows the VLAN to have a different MAC than the
		 * underlying device, and still route correctly. */
		if (!compare_ether_addr(eth_hdr(skb)->h_dest,
58
					dev->dev_addr))
59 60 61
			skb->pkt_type = PACKET_HOST;
		break;
	};
62
	return 0;
63
}
64 65 66 67 68

struct net_device *vlan_dev_real_dev(const struct net_device *dev)
{
	return vlan_dev_info(dev)->real_dev;
}
69
EXPORT_SYMBOL(vlan_dev_real_dev);
70 71 72 73 74

u16 vlan_dev_vlan_id(const struct net_device *dev)
{
	return vlan_dev_info(dev)->vlan_id;
}
75
EXPORT_SYMBOL(vlan_dev_vlan_id);
H
Herbert Xu 已提交
76

77 78 79
static gro_result_t
vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
		unsigned int vlan_tci, struct sk_buff *skb)
H
Herbert Xu 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92
{
	struct sk_buff *p;

	if (skb_bond_should_drop(skb))
		goto drop;

	skb->vlan_tci = vlan_tci;
	skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);

	if (!skb->dev)
		goto drop;

	for (p = napi->gro_list; p; p = p->next) {
93 94 95
		NAPI_GRO_CB(p)->same_flow =
			p->dev == skb->dev && !compare_ether_header(
				skb_mac_header(p), skb_gro_mac_header(skb));
H
Herbert Xu 已提交
96 97 98 99 100 101
		NAPI_GRO_CB(p)->flush = 0;
	}

	return dev_gro_receive(napi, skb);

drop:
102
	return GRO_DROP;
H
Herbert Xu 已提交
103 104
}

105 106
gro_result_t vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
			      unsigned int vlan_tci, struct sk_buff *skb)
H
Herbert Xu 已提交
107
{
H
Herbert Xu 已提交
108
	if (netpoll_rx_on(skb))
109 110
		return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
			? GRO_DROP : GRO_NORMAL;
H
Herbert Xu 已提交
111

112 113
	skb_gro_reset_offset(skb);

114
	return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
H
Herbert Xu 已提交
115 116 117
}
EXPORT_SYMBOL(vlan_gro_receive);

118 119
gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
			    unsigned int vlan_tci)
H
Herbert Xu 已提交
120
{
121
	struct sk_buff *skb = napi_frags_skb(napi);
H
Herbert Xu 已提交
122 123

	if (!skb)
124
		return GRO_DROP;
H
Herbert Xu 已提交
125

126 127
	if (netpoll_rx_on(skb)) {
		skb->protocol = eth_type_trans(skb, skb->dev);
128 129
		return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
			? GRO_DROP : GRO_NORMAL;
130
	}
H
Herbert Xu 已提交
131

132 133
	return napi_frags_finish(napi, skb,
				 vlan_gro_common(napi, grp, vlan_tci, skb));
H
Herbert Xu 已提交
134 135
}
EXPORT_SYMBOL(vlan_gro_frags);