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)))
15
		skb->deliver_no_wcard = 1;
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
	rx_stats = this_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats);
E
Eric Dumazet 已提交
45

E
Eric Dumazet 已提交
46
	u64_stats_update_begin(&rx_stats->syncp);
E
Eric Dumazet 已提交
47 48
	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->rx_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
			skb->pkt_type = PACKET_HOST;
		break;
64
	}
E
Eric Dumazet 已提交
65
	u64_stats_update_end(&rx_stats->syncp);
66
	return 0;
67
}
68 69 70 71 72

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

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

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

87
	if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
88
		skb->deliver_no_wcard = 1;
H
Herbert Xu 已提交
89

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

	return dev_gro_receive(napi, skb);

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

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

117 118
	skb_gro_reset_offset(skb);

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

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

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

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

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