Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx
[linux-2.6] / net / 8021q / vlan_core.c
1 #include <linux/skbuff.h>
2 #include <linux/netdevice.h>
3 #include <linux/if_vlan.h>
4 #include "vlan.h"
5
6 /* VLAN rx hw acceleration helper.  This acts like netif_{rx,receive_skb}(). */
7 int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
8                       u16 vlan_tci, int polling)
9 {
10         if (skb_bond_should_drop(skb))
11                 goto drop;
12
13         skb->vlan_tci = vlan_tci;
14         skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
15
16         if (!skb->dev)
17                 goto drop;
18
19         return (polling ? netif_receive_skb(skb) : netif_rx(skb));
20
21 drop:
22         dev_kfree_skb_any(skb);
23         return NET_RX_DROP;
24 }
25 EXPORT_SYMBOL(__vlan_hwaccel_rx);
26
27 int vlan_hwaccel_do_receive(struct sk_buff *skb)
28 {
29         struct net_device *dev = skb->dev;
30         struct net_device_stats *stats;
31
32         skb->dev = vlan_dev_info(dev)->real_dev;
33         netif_nit_deliver(skb);
34
35         skb->dev = dev;
36         skb->priority = vlan_get_ingress_priority(dev, skb->vlan_tci);
37         skb->vlan_tci = 0;
38
39         stats = &dev->stats;
40         stats->rx_packets++;
41         stats->rx_bytes += skb->len;
42
43         switch (skb->pkt_type) {
44         case PACKET_BROADCAST:
45                 break;
46         case PACKET_MULTICAST:
47                 stats->multicast++;
48                 break;
49         case PACKET_OTHERHOST:
50                 /* Our lower layer thinks this is not local, let's make sure.
51                  * This allows the VLAN to have a different MAC than the
52                  * underlying device, and still route correctly. */
53                 if (!compare_ether_addr(eth_hdr(skb)->h_dest,
54                                         dev->dev_addr))
55                         skb->pkt_type = PACKET_HOST;
56                 break;
57         };
58         return 0;
59 }
60
61 struct net_device *vlan_dev_real_dev(const struct net_device *dev)
62 {
63         return vlan_dev_info(dev)->real_dev;
64 }
65 EXPORT_SYMBOL_GPL(vlan_dev_real_dev);
66
67 u16 vlan_dev_vlan_id(const struct net_device *dev)
68 {
69         return vlan_dev_info(dev)->vlan_id;
70 }
71 EXPORT_SYMBOL_GPL(vlan_dev_vlan_id);
72
73 static int vlan_gro_common(struct napi_struct *napi, struct vlan_group *grp,
74                            unsigned int vlan_tci, struct sk_buff *skb)
75 {
76         struct sk_buff *p;
77
78         if (skb_bond_should_drop(skb))
79                 goto drop;
80
81         skb->vlan_tci = vlan_tci;
82         skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
83
84         if (!skb->dev)
85                 goto drop;
86
87         for (p = napi->gro_list; p; p = p->next) {
88                 NAPI_GRO_CB(p)->same_flow = p->dev == skb->dev;
89                 NAPI_GRO_CB(p)->flush = 0;
90         }
91
92         return dev_gro_receive(napi, skb);
93
94 drop:
95         return 2;
96 }
97
98 int vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp,
99                      unsigned int vlan_tci, struct sk_buff *skb)
100 {
101         int err = NET_RX_SUCCESS;
102
103         switch (vlan_gro_common(napi, grp, vlan_tci, skb)) {
104         case -1:
105                 return netif_receive_skb(skb);
106
107         case 2:
108                 err = NET_RX_DROP;
109                 /* fall through */
110
111         case 1:
112                 kfree_skb(skb);
113                 break;
114         }
115
116         return err;
117 }
118 EXPORT_SYMBOL(vlan_gro_receive);
119
120 int vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp,
121                    unsigned int vlan_tci, struct napi_gro_fraginfo *info)
122 {
123         struct sk_buff *skb = napi_fraginfo_skb(napi, info);
124         int err = NET_RX_DROP;
125
126         if (!skb)
127                 goto out;
128
129         err = NET_RX_SUCCESS;
130
131         switch (vlan_gro_common(napi, grp, vlan_tci, skb)) {
132         case -1:
133                 return netif_receive_skb(skb);
134
135         case 2:
136                 err = NET_RX_DROP;
137                 /* fall through */
138
139         case 1:
140                 napi_reuse_skb(napi, skb);
141                 break;
142         }
143
144 out:
145         return err;
146 }
147 EXPORT_SYMBOL(vlan_gro_frags);