vlan_core.c 3.7 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
	struct net_device *vlan_dev;
	u16 vlan_id;

14 15 16
	if (netpoll_rx(skb))
		return NET_RX_DROP;

17
	if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
18
		skb->deliver_no_wcard = 1;
19

20
	skb->skb_iif = skb->dev->ifindex;
21
	__vlan_hwaccel_put_tag(skb, vlan_tci);
22 23
	vlan_id = vlan_tci & VLAN_VID_MASK;
	vlan_dev = vlan_group_get_device(grp, vlan_id);
H
Herbert Xu 已提交
24

25 26 27
	if (vlan_dev)
		skb->dev = vlan_dev;
	else if (vlan_id)
H
Herbert Xu 已提交
28
		goto drop;
29 30

	return (polling ? netif_receive_skb(skb) : netif_rx(skb));
H
Herbert Xu 已提交
31 32 33 34

drop:
	dev_kfree_skb_any(skb);
	return NET_RX_DROP;
35 36 37 38 39
}
EXPORT_SYMBOL(__vlan_hwaccel_rx);

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

H
Herbert Xu 已提交
43
	skb->dev = vlan_dev_info(dev)->real_dev;
44 45
	netif_nit_deliver(skb);

46 47
	skb->dev = dev;
	skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
48
	skb->vlan_tci = 0;
49

E
Eric Dumazet 已提交
50
	rx_stats = this_cpu_ptr(vlan_dev_info(dev)->vlan_rx_stats);
E
Eric Dumazet 已提交
51

E
Eric Dumazet 已提交
52
	u64_stats_update_begin(&rx_stats->syncp);
E
Eric Dumazet 已提交
53 54
	rx_stats->rx_packets++;
	rx_stats->rx_bytes += skb->len;
55 56 57 58 59

	switch (skb->pkt_type) {
	case PACKET_BROADCAST:
		break;
	case PACKET_MULTICAST:
E
Eric Dumazet 已提交
60
		rx_stats->rx_multicast++;
61 62 63 64 65 66
		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,
67
					dev->dev_addr))
68 69
			skb->pkt_type = PACKET_HOST;
		break;
70
	}
E
Eric Dumazet 已提交
71
	u64_stats_update_end(&rx_stats->syncp);
72
	return 0;
73
}
74 75 76 77 78

struct net_device *vlan_dev_real_dev(const struct net_device *dev)
{
	return vlan_dev_info(dev)->real_dev;
}
79
EXPORT_SYMBOL(vlan_dev_real_dev);
80 81 82 83 84

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

87 88 89
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 已提交
90 91
{
	struct sk_buff *p;
92 93
	struct net_device *vlan_dev;
	u16 vlan_id;
H
Herbert Xu 已提交
94

95
	if (skb_bond_should_drop(skb, ACCESS_ONCE(skb->dev->master)))
96
		skb->deliver_no_wcard = 1;
H
Herbert Xu 已提交
97

98
	skb->skb_iif = skb->dev->ifindex;
99
	__vlan_hwaccel_put_tag(skb, vlan_tci);
100 101
	vlan_id = vlan_tci & VLAN_VID_MASK;
	vlan_dev = vlan_group_get_device(grp, vlan_id);
H
Herbert Xu 已提交
102

103 104 105
	if (vlan_dev)
		skb->dev = vlan_dev;
	else if (vlan_id)
H
Herbert Xu 已提交
106 107 108
		goto drop;

	for (p = napi->gro_list; p; p = p->next) {
109 110 111
		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 已提交
112 113 114 115 116 117
		NAPI_GRO_CB(p)->flush = 0;
	}

	return dev_gro_receive(napi, skb);

drop:
118
	return GRO_DROP;
H
Herbert Xu 已提交
119 120
}

121 122
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 已提交
123
{
H
Herbert Xu 已提交
124
	if (netpoll_rx_on(skb))
125 126
		return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
			? GRO_DROP : GRO_NORMAL;
H
Herbert Xu 已提交
127

128 129
	skb_gro_reset_offset(skb);

130
	return napi_skb_finish(vlan_gro_common(napi, grp, vlan_tci, skb), skb);
H
Herbert Xu 已提交
131 132 133
}
EXPORT_SYMBOL(vlan_gro_receive);

134 135
gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
			    unsigned int vlan_tci)
H
Herbert Xu 已提交
136
{
137
	struct sk_buff *skb = napi_frags_skb(napi);
H
Herbert Xu 已提交
138 139

	if (!skb)
140
		return GRO_DROP;
H
Herbert Xu 已提交
141

142 143
	if (netpoll_rx_on(skb)) {
		skb->protocol = eth_type_trans(skb, skb->dev);
144 145
		return vlan_hwaccel_receive_skb(skb, grp, vlan_tci)
			? GRO_DROP : GRO_NORMAL;
146
	}
H
Herbert Xu 已提交
147

148 149
	return napi_frags_finish(napi, skb,
				 vlan_gro_common(napi, grp, vlan_tci, skb));
H
Herbert Xu 已提交
150 151
}
EXPORT_SYMBOL(vlan_gro_frags);