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