vlan_core.c 2.9 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 80 81

static int vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
			   unsigned int vlan_tci, struct sk_buff *skb)
{
	struct sk_buff *p;

82 83 84
	if (netpoll_rx_on(skb))
		return GRO_NORMAL;

H
Herbert Xu 已提交
85 86 87 88 89 90 91 92 93 94
	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) {
95 96 97
		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 已提交
98 99 100 101 102 103
		NAPI_GRO_CB(p)->flush = 0;
	}

	return dev_gro_receive(napi, skb);

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

int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
		     unsigned int vlan_tci, struct sk_buff *skb)
{
110 111
	skb_gro_reset_offset(skb);

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

int vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
		   unsigned int vlan_tci, struct napi_gro_fraginfo *info)
{
	struct sk_buff *skb = napi_fraginfo_skb(napi, info);

	if (!skb)
122
		return NET_RX_DROP;
H
Herbert Xu 已提交
123

124 125
	return napi_frags_finish(napi, skb,
				 vlan_gro_common(napi, grp, vlan_tci, skb));
H
Herbert Xu 已提交
126 127
}
EXPORT_SYMBOL(vlan_gro_frags);