vlan_core.c 2.3 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
#include "vlan.h"

7
bool vlan_hwaccel_do_receive(struct sk_buff **skbp)
8
{
9 10
	struct sk_buff *skb = *skbp;
	u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK;
11
	struct net_device *vlan_dev;
12
	struct vlan_rx_stats *rx_stats;
13

14 15 16 17 18
	vlan_dev = vlan_find_dev(skb->dev, vlan_id);
	if (!vlan_dev) {
		if (vlan_id)
			skb->pkt_type = PACKET_OTHERHOST;
		return false;
19
	}
20

21 22 23
	skb = *skbp = skb_share_check(skb, GFP_ATOMIC);
	if (unlikely(!skb))
		return false;
H
Herbert Xu 已提交
24

25 26
	skb->dev = vlan_dev;
	skb->priority = vlan_get_ingress_priority(vlan_dev, skb->vlan_tci);
27
	skb->vlan_tci = 0;
28

29
	rx_stats = this_cpu_ptr(vlan_dev_info(vlan_dev)->vlan_rx_stats);
E
Eric Dumazet 已提交
30

E
Eric Dumazet 已提交
31
	u64_stats_update_begin(&rx_stats->syncp);
E
Eric Dumazet 已提交
32 33
	rx_stats->rx_packets++;
	rx_stats->rx_bytes += skb->len;
34 35 36 37 38

	switch (skb->pkt_type) {
	case PACKET_BROADCAST:
		break;
	case PACKET_MULTICAST:
E
Eric Dumazet 已提交
39
		rx_stats->rx_multicast++;
40 41 42 43 44 45
		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,
46
					vlan_dev->dev_addr))
47 48
			skb->pkt_type = PACKET_HOST;
		break;
49
	}
E
Eric Dumazet 已提交
50
	u64_stats_update_end(&rx_stats->syncp);
51 52

	return true;
53
}
54 55 56 57 58

struct net_device *vlan_dev_real_dev(const struct net_device *dev)
{
	return vlan_dev_info(dev)->real_dev;
}
59
EXPORT_SYMBOL(vlan_dev_real_dev);
60 61 62 63 64

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

67 68 69
/* VLAN rx hw acceleration helper.  This acts like netif_{rx,receive_skb}(). */
int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
		      u16 vlan_tci, int polling)
H
Herbert Xu 已提交
70
{
71
	__vlan_hwaccel_put_tag(skb, vlan_tci);
72
	return polling ? netif_receive_skb(skb) : netif_rx(skb);
H
Herbert Xu 已提交
73
}
74
EXPORT_SYMBOL(__vlan_hwaccel_rx);
H
Herbert Xu 已提交
75

76 77
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 已提交
78
{
79 80
	__vlan_hwaccel_put_tag(skb, vlan_tci);
	return napi_gro_receive(napi, skb);
H
Herbert Xu 已提交
81 82 83
}
EXPORT_SYMBOL(vlan_gro_receive);

84 85
gro_result_t vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
			    unsigned int vlan_tci)
H
Herbert Xu 已提交
86
{
87 88
	__vlan_hwaccel_put_tag(napi->skb, vlan_tci);
	return napi_gro_frags(napi);
H
Herbert Xu 已提交
89 90
}
EXPORT_SYMBOL(vlan_gro_frags);