vlan_core.c 3.4 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;

14
	if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
H
Herbert Xu 已提交
15
		goto drop;
16

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

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

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

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

int vlan_hwaccel_do_receive(struct sk_buff *skb)
{
H
Herbert Xu 已提交
34
	struct net_device *dev = skb->dev;
E
Eric Dumazet 已提交
35
	struct vlan_rx_stats     *rx_stats;
36

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

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

E
Eric Dumazet 已提交
44 45 46 47 48
	rx_stats = per_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats,
			       smp_processor_id());

	rx_stats->rx_packets++;
	rx_stats->rx_bytes += skb->len;
49 50 51 52 53

	switch (skb->pkt_type) {
	case PACKET_BROADCAST:
		break;
	case PACKET_MULTICAST:
E
Eric Dumazet 已提交
54
		rx_stats->multicast++;
55 56 57 58 59 60
		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,
61
					dev->dev_addr))
62 63 64
			skb->pkt_type = PACKET_HOST;
		break;
	};
65
	return 0;
66
}
67 68 69 70 71

struct net_device *vlan_dev_real_dev(const struct net_device *dev)
{
	return vlan_dev_info(dev)->real_dev;
}
72
EXPORT_SYMBOL(vlan_dev_real_dev);
73 74 75 76 77

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

80 81 82
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 已提交
83 84 85
{
	struct sk_buff *p;

86
	if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
H
Herbert Xu 已提交
87 88
		goto drop;

89
	skb->skb_iif = skb->dev->ifindex;
90
	__vlan_hwaccel_put_tag(skb, vlan_tci);
H
Herbert Xu 已提交
91 92 93 94 95 96
	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) {
97 98 99
		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 已提交
100 101 102 103 104 105
		NAPI_GRO_CB(p)->flush = 0;
	}

	return dev_gro_receive(napi, skb);

drop:
106
	return GRO_DROP;
H
Herbert Xu 已提交
107 108
}

109 110
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 已提交
111
{
H
Herbert Xu 已提交
112
	if (netpoll_rx_on(skb))
113 114
		return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
			? GRO_DROP : GRO_NORMAL;
H
Herbert Xu 已提交
115

116 117
	skb_gro_reset_offset(skb);

118
	return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
H
Herbert Xu 已提交
119 120 121
}
EXPORT_SYMBOL(vlan_gro_receive);

122 123
gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
			    unsigned int vlan_tci)
H
Herbert Xu 已提交
124
{
125
	struct sk_buff *skb = napi_frags_skb(napi);
H
Herbert Xu 已提交
126 127

	if (!skb)
128
		return GRO_DROP;
H
Herbert Xu 已提交
129

130 131
	if (netpoll_rx_on(skb)) {
		skb->protocol = eth_type_trans(skb, skb->dev);
132 133
		return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
			? GRO_DROP : GRO_NORMAL;
134
	}
H
Herbert Xu 已提交
135

136 137
	return napi_frags_finish(napi, skb,
				 vlan_gro_common(napi, grp, vlan_tci, skb));
H
Herbert Xu 已提交
138 139
}
EXPORT_SYMBOL(vlan_gro_frags);