blob: dd86a1dc4cd00f597ceb58cccefe2625bb1541fa [file] [log] [blame]
Patrick McHardy7750f402008-07-08 03:23:36 -07001#include <linux/skbuff.h>
2#include <linux/netdevice.h>
3#include <linux/if_vlan.h>
4#include "vlan.h"
5
Patrick McHardy9b22ea52008-11-04 14:49:57 -08006struct vlan_hwaccel_cb {
7 struct net_device *dev;
8};
9
10static inline struct vlan_hwaccel_cb *vlan_hwaccel_cb(struct sk_buff *skb)
11{
12 return (struct vlan_hwaccel_cb *)skb->cb;
13}
14
Patrick McHardy7750f402008-07-08 03:23:36 -070015/* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
16int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
Patrick McHardy9bb85822008-07-08 03:24:44 -070017 u16 vlan_tci, int polling)
Patrick McHardy7750f402008-07-08 03:23:36 -070018{
Patrick McHardy9b22ea52008-11-04 14:49:57 -080019 struct vlan_hwaccel_cb *cb = vlan_hwaccel_cb(skb);
Patrick McHardy7750f402008-07-08 03:23:36 -070020
21 if (skb_bond_should_drop(skb)) {
22 dev_kfree_skb_any(skb);
23 return NET_RX_DROP;
24 }
25
Patrick McHardybc1d0412008-07-14 22:49:30 -070026 skb->vlan_tci = vlan_tci;
Patrick McHardy9b22ea52008-11-04 14:49:57 -080027 cb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
28
29 return (polling ? netif_receive_skb(skb) : netif_rx(skb));
30}
31EXPORT_SYMBOL(__vlan_hwaccel_rx);
32
33int vlan_hwaccel_do_receive(struct sk_buff *skb)
34{
35 struct vlan_hwaccel_cb *cb = vlan_hwaccel_cb(skb);
36 struct net_device *dev = cb->dev;
37 struct net_device_stats *stats;
38
Patrick McHardybc1d0412008-07-14 22:49:30 -070039 netif_nit_deliver(skb);
40
Patrick McHardy9b22ea52008-11-04 14:49:57 -080041 if (dev == NULL) {
42 kfree_skb(skb);
43 return -1;
Patrick McHardy7750f402008-07-08 03:23:36 -070044 }
Patrick McHardy9b22ea52008-11-04 14:49:57 -080045
46 skb->dev = dev;
47 skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
Patrick McHardybc1d0412008-07-14 22:49:30 -070048 skb->vlan_tci = 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070049
Patrick McHardy9b22ea52008-11-04 14:49:57 -080050 stats = &dev->stats;
Patrick McHardy7750f402008-07-08 03:23:36 -070051 stats->rx_packets++;
52 stats->rx_bytes += skb->len;
53
Patrick McHardy7750f402008-07-08 03:23:36 -070054 switch (skb->pkt_type) {
55 case PACKET_BROADCAST:
56 break;
57 case PACKET_MULTICAST:
58 stats->multicast++;
59 break;
60 case PACKET_OTHERHOST:
61 /* Our lower layer thinks this is not local, let's make sure.
62 * This allows the VLAN to have a different MAC than the
63 * underlying device, and still route correctly. */
64 if (!compare_ether_addr(eth_hdr(skb)->h_dest,
Patrick McHardy9b22ea52008-11-04 14:49:57 -080065 dev->dev_addr))
Patrick McHardy7750f402008-07-08 03:23:36 -070066 skb->pkt_type = PACKET_HOST;
67 break;
68 };
Patrick McHardy9b22ea52008-11-04 14:49:57 -080069 return 0;
Patrick McHardy7750f402008-07-08 03:23:36 -070070}
Patrick McHardy22d1ba72008-07-08 03:23:57 -070071
72struct net_device *vlan_dev_real_dev(const struct net_device *dev)
73{
74 return vlan_dev_info(dev)->real_dev;
75}
76EXPORT_SYMBOL_GPL(vlan_dev_real_dev);
77
78u16 vlan_dev_vlan_id(const struct net_device *dev)
79{
80 return vlan_dev_info(dev)->vlan_id;
81}
82EXPORT_SYMBOL_GPL(vlan_dev_vlan_id);