blob: 9896f4975353db00af2ebf7432633c5e84ff7f7d [file] [log] [blame]
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001#include <linux/kernel.h>
2#include <linux/netdevice.h>
3#include <linux/rtnetlink.h>
4#include <linux/slab.h>
Scott Feldman7f109532015-06-12 17:39:50 -07005#include <net/switchdev.h>
Vlad Yasevich243a2e62013-02-13 12:00:09 +00006
7#include "br_private.h"
Roopa Prabhuefa53562017-01-31 22:59:54 -08008#include "br_private_tunnel.h"
Vlad Yasevich243a2e62013-02-13 12:00:09 +00009
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020010static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg,
11 const void *ptr)
Vlad Yasevich552406c2013-02-13 12:00:15 +000012{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020013 const struct net_bridge_vlan *vle = ptr;
14 u16 vid = *(u16 *)arg->key;
15
16 return vle->vid != vid;
17}
18
19static const struct rhashtable_params br_vlan_rht_params = {
20 .head_offset = offsetof(struct net_bridge_vlan, vnode),
21 .key_offset = offsetof(struct net_bridge_vlan, vid),
22 .key_len = sizeof(u16),
Nikolay Aleksandrov8af78b62015-09-30 20:16:51 +020023 .nelem_hint = 3,
24 .locks_mul = 1,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020025 .max_size = VLAN_N_VID,
26 .obj_cmpfn = br_vlan_cmp,
27 .automatic_shrinking = true,
28};
29
30static struct net_bridge_vlan *br_vlan_lookup(struct rhashtable *tbl, u16 vid)
31{
32 return rhashtable_lookup_fast(tbl, &vid, br_vlan_rht_params);
33}
34
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030035static bool __vlan_add_pvid(struct net_bridge_vlan_group *vg, u16 vid)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020036{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020037 if (vg->pvid == vid)
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030038 return false;
Vlad Yasevich552406c2013-02-13 12:00:15 +000039
40 smp_wmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020041 vg->pvid = vid;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030042
43 return true;
Vlad Yasevich552406c2013-02-13 12:00:15 +000044}
45
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030046static bool __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid)
Vlad Yasevich552406c2013-02-13 12:00:15 +000047{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020048 if (vg->pvid != vid)
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030049 return false;
Vlad Yasevich552406c2013-02-13 12:00:15 +000050
51 smp_wmb();
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020052 vg->pvid = 0;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030053
54 return true;
Vlad Yasevich552406c2013-02-13 12:00:15 +000055}
56
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030057/* return true if anything changed, false otherwise */
58static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags)
Vlad Yasevich35e03f32013-02-13 12:00:20 +000059{
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020060 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030061 u16 old_flags = v->flags;
62 bool ret;
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020063
64 if (br_vlan_is_master(v))
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +020065 vg = br_vlan_group(v->br);
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020066 else
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +020067 vg = nbp_vlan_group(v->port);
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020068
69 if (flags & BRIDGE_VLAN_INFO_PVID)
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030070 ret = __vlan_add_pvid(vg, v->vid);
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +020071 else
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030072 ret = __vlan_delete_pvid(vg, v->vid);
Vlad Yasevich35e03f32013-02-13 12:00:20 +000073
74 if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020075 v->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
Vlad Yasevich635126b2014-09-12 16:26:17 -040076 else
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020077 v->flags &= ~BRIDGE_VLAN_INFO_UNTAGGED;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +030078
79 return ret || !!(old_flags ^ v->flags);
Vlad Yasevich35e03f32013-02-13 12:00:20 +000080}
81
Scott Feldman7f109532015-06-12 17:39:50 -070082static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
83 u16 vid, u16 flags)
84{
Jiri Pirko0944d6b2015-10-09 13:54:11 +020085 struct switchdev_obj_port_vlan v = {
Ido Schimmel6ff64f62015-12-15 16:03:35 +010086 .obj.orig_dev = dev,
Jiri Pirko0944d6b2015-10-09 13:54:11 +020087 .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
88 .flags = flags,
89 .vid_begin = vid,
90 .vid_end = vid,
91 };
Scott Feldman7f109532015-06-12 17:39:50 -070092 int err;
93
Jiri Pirko0944d6b2015-10-09 13:54:11 +020094 /* Try switchdev op first. In case it is not supported, fallback to
95 * 8021q add.
Scott Feldman7f109532015-06-12 17:39:50 -070096 */
Jiri Pirko0944d6b2015-10-09 13:54:11 +020097 err = switchdev_port_obj_add(dev, &v.obj);
98 if (err == -EOPNOTSUPP)
99 return vlan_vid_add(dev, br->vlan_proto, vid);
Scott Feldman7f109532015-06-12 17:39:50 -0700100 return err;
101}
102
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200103static void __vlan_add_list(struct net_bridge_vlan *v)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000104{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200105 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200106 struct list_head *headp, *hpos;
107 struct net_bridge_vlan *vent;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000108
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200109 if (br_vlan_is_master(v))
110 vg = br_vlan_group(v->br);
111 else
112 vg = nbp_vlan_group(v->port);
113
114 headp = &vg->vlan_list;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200115 list_for_each_prev(hpos, headp) {
116 vent = list_entry(hpos, struct net_bridge_vlan, vlist);
117 if (v->vid < vent->vid)
118 continue;
119 else
120 break;
Vlad Yasevich552406c2013-02-13 12:00:15 +0000121 }
Nikolay Aleksandrov586c2b52015-10-02 15:05:10 +0200122 list_add_rcu(&v->vlist, hpos);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200123}
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000124
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200125static void __vlan_del_list(struct net_bridge_vlan *v)
126{
Nikolay Aleksandrov586c2b52015-10-02 15:05:10 +0200127 list_del_rcu(&v->vlist);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000128}
129
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400130static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
131 u16 vid)
Scott Feldman7f109532015-06-12 17:39:50 -0700132{
Jiri Pirko0944d6b2015-10-09 13:54:11 +0200133 struct switchdev_obj_port_vlan v = {
Ido Schimmel6ff64f62015-12-15 16:03:35 +0100134 .obj.orig_dev = dev,
Jiri Pirko0944d6b2015-10-09 13:54:11 +0200135 .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
136 .vid_begin = vid,
137 .vid_end = vid,
138 };
139 int err;
Scott Feldman7f109532015-06-12 17:39:50 -0700140
Jiri Pirko0944d6b2015-10-09 13:54:11 +0200141 /* Try switchdev op first. In case it is not supported, fallback to
142 * 8021q del.
Scott Feldman7f109532015-06-12 17:39:50 -0700143 */
Jiri Pirko0944d6b2015-10-09 13:54:11 +0200144 err = switchdev_port_obj_del(dev, &v.obj);
145 if (err == -EOPNOTSUPP) {
Scott Feldman7f109532015-06-12 17:39:50 -0700146 vlan_vid_del(dev, br->vlan_proto, vid);
Jiri Pirko0944d6b2015-10-09 13:54:11 +0200147 return 0;
Scott Feldman7f109532015-06-12 17:39:50 -0700148 }
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400149 return err;
Scott Feldman7f109532015-06-12 17:39:50 -0700150}
151
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200152/* Returns a master vlan, if it didn't exist it gets created. In all cases a
153 * a reference is taken to the master vlan before returning.
154 */
155static struct net_bridge_vlan *br_vlan_get_master(struct net_bridge *br, u16 vid)
156{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200157 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200158 struct net_bridge_vlan *masterv;
159
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200160 vg = br_vlan_group(br);
161 masterv = br_vlan_find(vg, vid);
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200162 if (!masterv) {
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300163 bool changed;
164
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200165 /* missing global ctx, create it now */
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300166 if (br_vlan_add(br, vid, 0, &changed))
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200167 return NULL;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200168 masterv = br_vlan_find(vg, vid);
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200169 if (WARN_ON(!masterv))
170 return NULL;
Ido Schimmel0e5a82e2018-02-25 21:59:06 +0200171 refcount_set(&masterv->refcnt, 1);
172 return masterv;
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200173 }
Reshetova, Elena25127752017-07-04 15:53:05 +0300174 refcount_inc(&masterv->refcnt);
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200175
176 return masterv;
177}
178
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200179static void br_master_vlan_rcu_free(struct rcu_head *rcu)
180{
181 struct net_bridge_vlan *v;
182
183 v = container_of(rcu, struct net_bridge_vlan, rcu);
184 WARN_ON(!br_vlan_is_master(v));
185 free_percpu(v->stats);
186 v->stats = NULL;
187 kfree(v);
188}
189
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200190static void br_vlan_put_master(struct net_bridge_vlan *masterv)
191{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200192 struct net_bridge_vlan_group *vg;
193
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200194 if (!br_vlan_is_master(masterv))
195 return;
196
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200197 vg = br_vlan_group(masterv->br);
Reshetova, Elena25127752017-07-04 15:53:05 +0300198 if (refcount_dec_and_test(&masterv->refcnt)) {
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200199 rhashtable_remove_fast(&vg->vlan_hash,
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200200 &masterv->vnode, br_vlan_rht_params);
201 __vlan_del_list(masterv);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200202 call_rcu(&masterv->rcu, br_master_vlan_rcu_free);
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200203 }
204}
205
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200206/* This is the shared VLAN add function which works for both ports and bridge
207 * devices. There are four possible calls to this function in terms of the
208 * vlan entry type:
209 * 1. vlan is being added on a port (no master flags, global entry exists)
Ido Schimmelddd611d2015-10-30 17:46:20 +0100210 * 2. vlan is being added on a bridge (both master and brentry flags)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200211 * 3. vlan is being added on a port, but a global entry didn't exist which
Ido Schimmelddd611d2015-10-30 17:46:20 +0100212 * is being created right now (master flag set, brentry flag unset), the
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200213 * global entry is used for global per-vlan features, but not for filtering
Ido Schimmelddd611d2015-10-30 17:46:20 +0100214 * 4. same as 3 but with both master and brentry flags set so the entry
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200215 * will be used for filtering in both the port and the bridge
216 */
217static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000218{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200219 struct net_bridge_vlan *masterv = NULL;
220 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200221 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200222 struct net_device *dev;
223 struct net_bridge *br;
224 int err;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000225
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200226 if (br_vlan_is_master(v)) {
227 br = v->br;
228 dev = br->dev;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200229 vg = br_vlan_group(br);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200230 } else {
231 p = v->port;
232 br = p->br;
233 dev = p->dev;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200234 vg = nbp_vlan_group(p);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200235 }
Vlad Yasevich552406c2013-02-13 12:00:15 +0000236
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200237 if (p) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200238 /* Add VLAN to the device filter if it is supported.
239 * This ensures tagged traffic enters the bridge when
240 * promiscuous mode is disabled by br_manage_promisc().
241 */
242 err = __vlan_vid_add(dev, br, v->vid, flags);
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400243 if (err)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200244 goto out;
245
246 /* need to work on the master vlan too */
247 if (flags & BRIDGE_VLAN_INFO_MASTER) {
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300248 bool changed;
249
250 err = br_vlan_add(br, v->vid,
251 flags | BRIDGE_VLAN_INFO_BRENTRY,
252 &changed);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200253 if (err)
254 goto out_filt;
255 }
256
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200257 masterv = br_vlan_get_master(br, v->vid);
258 if (!masterv)
259 goto out_filt;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200260 v->brvlan = masterv;
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200261 v->stats = masterv->stats;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900262 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000263
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200264 /* Add the dev mac and count the vlan only if it's usable */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200265 if (br_vlan_should_use(v)) {
266 err = br_fdb_insert(br, p, dev->dev_addr, v->vid);
267 if (err) {
268 br_err(br, "failed insert local address into bridge forwarding table\n");
269 goto out_filt;
270 }
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200271 vg->num_vlans++;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000272 }
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200273
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200274 err = rhashtable_lookup_insert_fast(&vg->vlan_hash, &v->vnode,
275 br_vlan_rht_params);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200276 if (err)
277 goto out_fdb_insert;
278
279 __vlan_add_list(v);
280 __vlan_add_flags(v, flags);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200281out:
282 return err;
283
284out_fdb_insert:
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200285 if (br_vlan_should_use(v)) {
286 br_fdb_find_delete_local(br, p, dev->dev_addr, v->vid);
287 vg->num_vlans--;
288 }
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200289
290out_filt:
291 if (p) {
292 __vlan_vid_del(dev, br, v->vid);
293 if (masterv) {
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200294 br_vlan_put_master(masterv);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200295 v->brvlan = NULL;
296 }
297 }
298
299 goto out;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000300}
301
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200302static int __vlan_del(struct net_bridge_vlan *v)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000303{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200304 struct net_bridge_vlan *masterv = v;
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200305 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200306 struct net_bridge_port *p = NULL;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200307 int err = 0;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200308
309 if (br_vlan_is_master(v)) {
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200310 vg = br_vlan_group(v->br);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200311 } else {
312 p = v->port;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200313 vg = nbp_vlan_group(v->port);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200314 masterv = v->brvlan;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200315 }
316
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200317 __vlan_delete_pvid(vg, v->vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200318 if (p) {
319 err = __vlan_vid_del(p->dev, p->br, v->vid);
320 if (err)
321 goto out;
322 }
323
Nikolay Aleksandrov6be144f2015-10-02 15:05:13 +0200324 if (br_vlan_should_use(v)) {
325 v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY;
326 vg->num_vlans--;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200327 }
328
329 if (masterv != v) {
Roopa Prabhuefa53562017-01-31 22:59:54 -0800330 vlan_tunnel_info_del(vg, v);
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200331 rhashtable_remove_fast(&vg->vlan_hash, &v->vnode,
332 br_vlan_rht_params);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200333 __vlan_del_list(v);
334 kfree_rcu(v, rcu);
335 }
336
Nikolay Aleksandrovf8ed2892015-10-02 15:05:11 +0200337 br_vlan_put_master(masterv);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200338out:
339 return err;
340}
341
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +0200342static void __vlan_group_free(struct net_bridge_vlan_group *vg)
343{
344 WARN_ON(!list_empty(&vg->vlan_list));
345 rhashtable_destroy(&vg->vlan_hash);
Roopa Prabhuefa53562017-01-31 22:59:54 -0800346 vlan_tunnel_deinit(vg);
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +0200347 kfree(vg);
348}
349
350static void __vlan_flush(struct net_bridge_vlan_group *vg)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200351{
352 struct net_bridge_vlan *vlan, *tmp;
353
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +0200354 __vlan_delete_pvid(vg, vg->pvid);
355 list_for_each_entry_safe(vlan, tmp, &vg->vlan_list, vlist)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200356 __vlan_del(vlan);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000357}
358
Vlad Yasevich78851982013-02-13 12:00:14 +0000359struct sk_buff *br_handle_vlan(struct net_bridge *br,
Roopa Prabhu11538d02017-01-31 22:59:55 -0800360 const struct net_bridge_port *p,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200361 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000362 struct sk_buff *skb)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000363{
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200364 struct br_vlan_stats *stats;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200365 struct net_bridge_vlan *v;
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000366 u16 vid;
367
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400368 /* If this packet was not filtered at input, let it pass */
369 if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
Vlad Yasevich78851982013-02-13 12:00:14 +0000370 goto out;
371
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200372 /* At this point, we know that the frame was filtered and contains
373 * a valid vlan id. If the vlan id has untagged flag set,
374 * send untagged; otherwise, send tagged.
375 */
376 br_vlan_get_tag(skb, &vid);
377 v = br_vlan_find(vg, vid);
378 /* Vlan entry must be configured at this point. The
Vlad Yasevichfc92f742014-03-27 21:51:18 -0400379 * only exception is the bridge is set in promisc mode and the
380 * packet is destined for the bridge device. In this case
381 * pass the packet as is.
382 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200383 if (!v || !br_vlan_should_use(v)) {
Vlad Yasevichfc92f742014-03-27 21:51:18 -0400384 if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) {
385 goto out;
386 } else {
387 kfree_skb(skb);
388 return NULL;
389 }
390 }
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200391 if (br->vlan_stats_enabled) {
392 stats = this_cpu_ptr(v->stats);
393 u64_stats_update_begin(&stats->syncp);
394 stats->tx_bytes += skb->len;
395 stats->tx_packets++;
396 u64_stats_update_end(&stats->syncp);
397 }
398
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200399 if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
Toshiaki Makita99b192d2014-03-27 21:46:56 +0900400 skb->vlan_tci = 0;
Roopa Prabhu11538d02017-01-31 22:59:55 -0800401
402 if (p && (p->flags & BR_VLAN_TUNNEL) &&
403 br_handle_egress_vlan_tunnel(skb, v)) {
404 kfree_skb(skb);
405 return NULL;
406 }
Vlad Yasevich78851982013-02-13 12:00:14 +0000407out:
408 return skb;
409}
410
411/* Called under RCU */
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200412static bool __allowed_ingress(const struct net_bridge *br,
413 struct net_bridge_vlan_group *vg,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200414 struct sk_buff *skb, u16 *vid)
Vlad Yasevich78851982013-02-13 12:00:14 +0000415{
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200416 struct br_vlan_stats *stats;
417 struct net_bridge_vlan *v;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900418 bool tagged;
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000419
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400420 BR_INPUT_SKB_CB(skb)->vlan_filtered = true;
Toshiaki Makita12464bb2014-03-27 21:46:55 +0900421 /* If vlan tx offload is disabled on bridge device and frame was
422 * sent from vlan device on the bridge device, it does not have
423 * HW accelerated vlan tag.
424 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100425 if (unlikely(!skb_vlan_tag_present(skb) &&
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200426 skb->protocol == br->vlan_proto)) {
Vlad Yasevich0d5501c2014-08-08 14:42:13 -0400427 skb = skb_vlan_untag(skb);
Toshiaki Makita12464bb2014-03-27 21:46:55 +0900428 if (unlikely(!skb))
429 return false;
430 }
431
Toshiaki Makita8580e212014-06-10 20:59:23 +0900432 if (!br_vlan_get_tag(skb, vid)) {
433 /* Tagged frame */
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200434 if (skb->vlan_proto != br->vlan_proto) {
Toshiaki Makita8580e212014-06-10 20:59:23 +0900435 /* Protocol-mismatch, empty out vlan_tci for new tag */
436 skb_push(skb, ETH_HLEN);
Jiri Pirko62749e22014-11-19 14:04:58 +0100437 skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100438 skb_vlan_tag_get(skb));
Toshiaki Makita8580e212014-06-10 20:59:23 +0900439 if (unlikely(!skb))
440 return false;
441
442 skb_pull(skb, ETH_HLEN);
443 skb_reset_mac_len(skb);
444 *vid = 0;
445 tagged = false;
446 } else {
447 tagged = true;
448 }
449 } else {
450 /* Untagged frame */
451 tagged = false;
452 }
453
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900454 if (!*vid) {
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200455 u16 pvid = br_get_pvid(vg);
456
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900457 /* Frame had a tag with VID 0 or did not have a tag.
458 * See if pvid is set on this port. That tells us which
459 * vlan untagged or priority-tagged traffic belongs to.
Vlad Yasevich78851982013-02-13 12:00:14 +0000460 */
Vlad Yasevich3df6bf42014-10-03 11:29:17 -0400461 if (!pvid)
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900462 goto drop;
Vlad Yasevich78851982013-02-13 12:00:14 +0000463
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900464 /* PVID is set on this port. Any untagged or priority-tagged
465 * ingress frame is considered to belong to this vlan.
Vlad Yasevich78851982013-02-13 12:00:14 +0000466 */
Toshiaki Makitadfb5fa32013-10-16 17:07:16 +0900467 *vid = pvid;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900468 if (likely(!tagged))
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900469 /* Untagged Frame. */
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200470 __vlan_hwaccel_put_tag(skb, br->vlan_proto, pvid);
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900471 else
472 /* Priority-tagged Frame.
473 * At this point, We know that skb->vlan_tci had
474 * VLAN_TAG_PRESENT bit and its VID field was 0x000.
475 * We update only VID field and preserve PCP field.
476 */
477 skb->vlan_tci |= pvid;
478
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200479 /* if stats are disabled we can avoid the lookup */
480 if (!br->vlan_stats_enabled)
481 return true;
482 }
483 v = br_vlan_find(vg, *vid);
484 if (!v || !br_vlan_should_use(v))
485 goto drop;
486
487 if (br->vlan_stats_enabled) {
488 stats = this_cpu_ptr(v->stats);
489 u64_stats_update_begin(&stats->syncp);
490 stats->rx_bytes += skb->len;
491 stats->rx_packets++;
492 u64_stats_update_end(&stats->syncp);
Vlad Yasevich78851982013-02-13 12:00:14 +0000493 }
494
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200495 return true;
496
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900497drop:
498 kfree_skb(skb);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000499 return false;
500}
501
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200502bool br_allowed_ingress(const struct net_bridge *br,
503 struct net_bridge_vlan_group *vg, struct sk_buff *skb,
504 u16 *vid)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200505{
506 /* If VLAN filtering is disabled on the bridge, all packets are
507 * permitted.
508 */
509 if (!br->vlan_enabled) {
510 BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
511 return true;
512 }
513
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200514 return __allowed_ingress(br, vg, skb, vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200515}
516
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000517/* Called under RCU. */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200518bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000519 const struct sk_buff *skb)
520{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200521 const struct net_bridge_vlan *v;
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000522 u16 vid;
523
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400524 /* If this packet was not filtered at input, let it pass */
525 if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000526 return true;
527
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000528 br_vlan_get_tag(skb, &vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200529 v = br_vlan_find(vg, vid);
530 if (v && br_vlan_should_use(v))
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000531 return true;
532
533 return false;
534}
535
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900536/* Called under RCU */
537bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
538{
Nikolay Aleksandrov468e7942015-09-30 20:16:52 +0200539 struct net_bridge_vlan_group *vg;
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900540 struct net_bridge *br = p->br;
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900541
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400542 /* If filtering was disabled at input, let it pass. */
Vlad Yasevichc095f242014-09-15 15:24:26 -0400543 if (!br->vlan_enabled)
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900544 return true;
545
Ido Schimmeleca1e002015-11-01 18:31:45 +0200546 vg = nbp_vlan_group_rcu(p);
Nikolay Aleksandrov468e7942015-09-30 20:16:52 +0200547 if (!vg || !vg->num_vlans)
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900548 return false;
549
Toshiaki Makita8580e212014-06-10 20:59:23 +0900550 if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto)
551 *vid = 0;
552
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900553 if (!*vid) {
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200554 *vid = br_get_pvid(vg);
Vlad Yasevich3df6bf42014-10-03 11:29:17 -0400555 if (!*vid)
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900556 return false;
557
558 return true;
559 }
560
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200561 if (br_vlan_find(vg, *vid))
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900562 return true;
563
564 return false;
565}
566
Toshiaki Makita8adff412013-10-16 17:07:13 +0900567/* Must be protected by RTNL.
568 * Must be called with vid in range from 1 to 4094 inclusive.
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300569 * changed must be true only if the vlan was created or updated
Toshiaki Makita8adff412013-10-16 17:07:13 +0900570 */
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300571int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, bool *changed)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000572{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200573 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200574 struct net_bridge_vlan *vlan;
575 int ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000576
577 ASSERT_RTNL();
578
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300579 *changed = false;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200580 vg = br_vlan_group(br);
581 vlan = br_vlan_find(vg, vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200582 if (vlan) {
583 if (!br_vlan_is_brentry(vlan)) {
584 /* Trying to change flags of non-existent bridge vlan */
585 if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
586 return -EINVAL;
587 /* It was only kept for port vlans, now make it real */
588 ret = br_fdb_insert(br, NULL, br->dev->dev_addr,
589 vlan->vid);
590 if (ret) {
591 br_err(br, "failed insert local address into bridge forwarding table\n");
592 return ret;
593 }
Reshetova, Elena25127752017-07-04 15:53:05 +0300594 refcount_inc(&vlan->refcnt);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200595 vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200596 vg->num_vlans++;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300597 *changed = true;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200598 }
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300599 if (__vlan_add_flags(vlan, flags))
600 *changed = true;
601
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200602 return 0;
603 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000604
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200605 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
606 if (!vlan)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000607 return -ENOMEM;
608
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200609 vlan->stats = netdev_alloc_pcpu_stats(struct br_vlan_stats);
610 if (!vlan->stats) {
611 kfree(vlan);
612 return -ENOMEM;
613 }
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200614 vlan->vid = vid;
615 vlan->flags = flags | BRIDGE_VLAN_INFO_MASTER;
616 vlan->flags &= ~BRIDGE_VLAN_INFO_PVID;
617 vlan->br = br;
618 if (flags & BRIDGE_VLAN_INFO_BRENTRY)
Reshetova, Elena25127752017-07-04 15:53:05 +0300619 refcount_set(&vlan->refcnt, 1);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200620 ret = __vlan_add(vlan, flags);
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200621 if (ret) {
622 free_percpu(vlan->stats);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200623 kfree(vlan);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300624 } else {
625 *changed = true;
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200626 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000627
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200628 return ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000629}
630
Toshiaki Makita8adff412013-10-16 17:07:13 +0900631/* Must be protected by RTNL.
632 * Must be called with vid in range from 1 to 4094 inclusive.
633 */
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000634int br_vlan_delete(struct net_bridge *br, u16 vid)
635{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200636 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200637 struct net_bridge_vlan *v;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000638
639 ASSERT_RTNL();
640
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200641 vg = br_vlan_group(br);
642 v = br_vlan_find(vg, vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200643 if (!v || !br_vlan_is_brentry(v))
644 return -ENOENT;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000645
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900646 br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid);
Roopa Prabhu37418732015-10-08 10:38:52 -0700647 br_fdb_delete_by_port(br, NULL, vid, 0);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000648
Roopa Prabhuefa53562017-01-31 22:59:54 -0800649 vlan_tunnel_info_del(vg, v);
650
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200651 return __vlan_del(v);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000652}
653
654void br_vlan_flush(struct net_bridge *br)
655{
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +0200656 struct net_bridge_vlan_group *vg;
657
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000658 ASSERT_RTNL();
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000659
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +0200660 vg = br_vlan_group(br);
661 __vlan_flush(vg);
662 RCU_INIT_POINTER(br->vlgrp, NULL);
663 synchronize_rcu();
664 __vlan_group_free(vg);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000665}
666
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200667struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid)
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900668{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200669 if (!vg)
670 return NULL;
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900671
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200672 return br_vlan_lookup(&vg->vlan_hash, vid);
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900673}
674
Toshiaki Makita204177f2014-06-10 20:59:25 +0900675/* Must be protected by RTNL. */
676static void recalculate_group_addr(struct net_bridge *br)
677{
678 if (br->group_addr_set)
679 return;
680
681 spin_lock_bh(&br->lock);
682 if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) {
683 /* Bridge Group Address */
684 br->group_addr[5] = 0x00;
685 } else { /* vlan_enabled && ETH_P_8021AD */
686 /* Provider Bridge Group Address */
687 br->group_addr[5] = 0x08;
688 }
689 spin_unlock_bh(&br->lock);
690}
691
692/* Must be protected by RTNL. */
693void br_recalculate_fwd_mask(struct net_bridge *br)
694{
695 if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q))
696 br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT;
697 else /* vlan_enabled && ETH_P_8021AD */
698 br->group_fwd_mask_required = BR_GROUPFWD_8021AD &
699 ~(1u << br->group_addr[5]);
700}
701
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300702int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000703{
Elad Raz6b72a772016-01-06 13:01:06 +0100704 struct switchdev_attr attr = {
705 .orig_dev = br->dev,
706 .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
707 .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
708 .u.vlan_filtering = val,
709 };
710 int err;
711
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000712 if (br->vlan_enabled == val)
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300713 return 0;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000714
Elad Raz6b72a772016-01-06 13:01:06 +0100715 err = switchdev_port_attr_set(br->dev, &attr);
716 if (err && err != -EOPNOTSUPP)
717 return err;
718
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000719 br->vlan_enabled = val;
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400720 br_manage_promisc(br);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900721 recalculate_group_addr(br);
722 br_recalculate_fwd_mask(br);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000723
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300724 return 0;
725}
726
727int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
728{
Xin Long047831a2016-04-09 00:03:31 +0800729 return __br_vlan_filter_toggle(br, val);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000730}
731
Ido Schimmel1f514452017-05-26 08:37:23 +0200732bool br_vlan_enabled(const struct net_device *dev)
733{
734 struct net_bridge *br = netdev_priv(dev);
735
736 return !!br->vlan_enabled;
737}
738EXPORT_SYMBOL_GPL(br_vlan_enabled);
739
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900740int __br_vlan_set_proto(struct net_bridge *br, __be16 proto)
Toshiaki Makita204177f2014-06-10 20:59:25 +0900741{
742 int err = 0;
743 struct net_bridge_port *p;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200744 struct net_bridge_vlan *vlan;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200745 struct net_bridge_vlan_group *vg;
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900746 __be16 oldproto;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900747
Toshiaki Makita204177f2014-06-10 20:59:25 +0900748 if (br->vlan_proto == proto)
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900749 return 0;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900750
751 /* Add VLANs for the new proto to the device filter. */
752 list_for_each_entry(p, &br->port_list, list) {
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200753 vg = nbp_vlan_group(p);
754 list_for_each_entry(vlan, &vg->vlan_list, vlist) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200755 err = vlan_vid_add(p->dev, proto, vlan->vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900756 if (err)
757 goto err_filt;
758 }
759 }
760
761 oldproto = br->vlan_proto;
762 br->vlan_proto = proto;
763
764 recalculate_group_addr(br);
765 br_recalculate_fwd_mask(br);
766
767 /* Delete VLANs for the old proto from the device filter. */
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200768 list_for_each_entry(p, &br->port_list, list) {
769 vg = nbp_vlan_group(p);
770 list_for_each_entry(vlan, &vg->vlan_list, vlist)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200771 vlan_vid_del(p->dev, oldproto, vlan->vid);
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200772 }
Toshiaki Makita204177f2014-06-10 20:59:25 +0900773
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900774 return 0;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900775
776err_filt:
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200777 list_for_each_entry_continue_reverse(vlan, &vg->vlan_list, vlist)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200778 vlan_vid_del(p->dev, proto, vlan->vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900779
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200780 list_for_each_entry_continue_reverse(p, &br->port_list, list) {
781 vg = nbp_vlan_group(p);
782 list_for_each_entry(vlan, &vg->vlan_list, vlist)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200783 vlan_vid_del(p->dev, proto, vlan->vid);
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200784 }
Toshiaki Makita204177f2014-06-10 20:59:25 +0900785
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900786 return err;
787}
788
789int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
790{
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900791 if (val != ETH_P_8021Q && val != ETH_P_8021AD)
792 return -EPROTONOSUPPORT;
793
Xin Long047831a2016-04-09 00:03:31 +0800794 return __br_vlan_set_proto(br, htons(val));
Toshiaki Makita204177f2014-06-10 20:59:25 +0900795}
796
Nikolay Aleksandrov6dada9b2016-04-30 10:25:28 +0200797int br_vlan_set_stats(struct net_bridge *br, unsigned long val)
798{
799 switch (val) {
800 case 0:
801 case 1:
802 br->vlan_stats_enabled = val;
803 break;
804 default:
805 return -EINVAL;
806 }
807
808 return 0;
809}
810
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200811static bool vlan_default_pvid(struct net_bridge_vlan_group *vg, u16 vid)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400812{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200813 struct net_bridge_vlan *v;
814
Nikolay Aleksandrov77751ee2015-09-30 20:16:53 +0200815 if (vid != vg->pvid)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200816 return false;
817
818 v = br_vlan_lookup(&vg->vlan_hash, vid);
819 if (v && br_vlan_should_use(v) &&
820 (v->flags & BRIDGE_VLAN_INFO_UNTAGGED))
821 return true;
822
823 return false;
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400824}
825
826static void br_vlan_disable_default_pvid(struct net_bridge *br)
827{
828 struct net_bridge_port *p;
829 u16 pvid = br->default_pvid;
830
831 /* Disable default_pvid on all ports where it is still
832 * configured.
833 */
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200834 if (vlan_default_pvid(br_vlan_group(br), pvid))
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400835 br_vlan_delete(br, pvid);
836
837 list_for_each_entry(p, &br->port_list, list) {
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200838 if (vlan_default_pvid(nbp_vlan_group(p), pvid))
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400839 nbp_vlan_delete(p, pvid);
840 }
841
842 br->default_pvid = 0;
843}
844
Nikolay Aleksandrov0f963b72015-10-04 14:23:47 +0200845int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400846{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200847 const struct net_bridge_vlan *pvent;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200848 struct net_bridge_vlan_group *vg;
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400849 struct net_bridge_port *p;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300850 unsigned long *changed;
851 bool vlchange;
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400852 u16 old_pvid;
853 int err = 0;
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400854
Nikolay Aleksandrov0f963b72015-10-04 14:23:47 +0200855 if (!pvid) {
856 br_vlan_disable_default_pvid(br);
857 return 0;
858 }
859
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400860 changed = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long),
861 GFP_KERNEL);
862 if (!changed)
863 return -ENOMEM;
864
865 old_pvid = br->default_pvid;
866
867 /* Update default_pvid config only if we do not conflict with
868 * user configuration.
869 */
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200870 vg = br_vlan_group(br);
871 pvent = br_vlan_find(vg, pvid);
872 if ((!old_pvid || vlan_default_pvid(vg, old_pvid)) &&
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200873 (!pvent || !br_vlan_should_use(pvent))) {
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400874 err = br_vlan_add(br, pvid,
875 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200876 BRIDGE_VLAN_INFO_UNTAGGED |
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300877 BRIDGE_VLAN_INFO_BRENTRY,
878 &vlchange);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400879 if (err)
880 goto out;
881 br_vlan_delete(br, old_pvid);
882 set_bit(0, changed);
883 }
884
885 list_for_each_entry(p, &br->port_list, list) {
886 /* Update default_pvid config only if we do not conflict with
887 * user configuration.
888 */
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200889 vg = nbp_vlan_group(p);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400890 if ((old_pvid &&
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200891 !vlan_default_pvid(vg, old_pvid)) ||
892 br_vlan_find(vg, pvid))
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400893 continue;
894
895 err = nbp_vlan_add(p, pvid,
896 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300897 BRIDGE_VLAN_INFO_UNTAGGED,
898 &vlchange);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400899 if (err)
900 goto err_port;
901 nbp_vlan_delete(p, old_pvid);
902 set_bit(p->port_no, changed);
903 }
904
905 br->default_pvid = pvid;
906
907out:
908 kfree(changed);
909 return err;
910
911err_port:
912 list_for_each_entry_continue_reverse(p, &br->port_list, list) {
913 if (!test_bit(p->port_no, changed))
914 continue;
915
916 if (old_pvid)
917 nbp_vlan_add(p, old_pvid,
918 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300919 BRIDGE_VLAN_INFO_UNTAGGED,
920 &vlchange);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400921 nbp_vlan_delete(p, pvid);
922 }
923
924 if (test_bit(0, changed)) {
925 if (old_pvid)
926 br_vlan_add(br, old_pvid,
927 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200928 BRIDGE_VLAN_INFO_UNTAGGED |
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300929 BRIDGE_VLAN_INFO_BRENTRY,
930 &vlchange);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400931 br_vlan_delete(br, pvid);
932 }
933 goto out;
934}
935
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400936int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val)
937{
938 u16 pvid = val;
939 int err = 0;
940
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400941 if (val >= VLAN_VID_MASK)
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400942 return -EINVAL;
943
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400944 if (pvid == br->default_pvid)
Xin Long047831a2016-04-09 00:03:31 +0800945 goto out;
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400946
947 /* Only allow default pvid change when filtering is disabled */
948 if (br->vlan_enabled) {
949 pr_info_once("Please disable vlan filtering to change default_pvid\n");
950 err = -EPERM;
Xin Long047831a2016-04-09 00:03:31 +0800951 goto out;
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400952 }
Nikolay Aleksandrov0f963b72015-10-04 14:23:47 +0200953 err = __br_vlan_set_default_pvid(br, pvid);
Xin Long047831a2016-04-09 00:03:31 +0800954out:
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400955 return err;
956}
957
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400958int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +0900959{
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200960 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200961 int ret = -ENOMEM;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300962 bool changed;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200963
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200964 vg = kzalloc(sizeof(*vg), GFP_KERNEL);
965 if (!vg)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200966 goto out;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200967 ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200968 if (ret)
969 goto err_rhtbl;
Roopa Prabhuefa53562017-01-31 22:59:54 -0800970 ret = vlan_tunnel_init(vg);
971 if (ret)
972 goto err_tunnel_init;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200973 INIT_LIST_HEAD(&vg->vlan_list);
Toshiaki Makita8580e212014-06-10 20:59:23 +0900974 br->vlan_proto = htons(ETH_P_8021Q);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400975 br->default_pvid = 1;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200976 rcu_assign_pointer(br->vlgrp, vg);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200977 ret = br_vlan_add(br, 1,
978 BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED |
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +0300979 BRIDGE_VLAN_INFO_BRENTRY, &changed);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200980 if (ret)
981 goto err_vlan_add;
982
983out:
984 return ret;
985
986err_vlan_add:
Roopa Prabhuefa53562017-01-31 22:59:54 -0800987 vlan_tunnel_deinit(vg);
988err_tunnel_init:
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200989 rhashtable_destroy(&vg->vlan_hash);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200990err_rhtbl:
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +0200991 kfree(vg);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200992
993 goto out;
994}
995
996int nbp_vlan_init(struct net_bridge_port *p)
997{
Elad Raz404cdbf2016-01-06 13:01:07 +0100998 struct switchdev_attr attr = {
999 .orig_dev = p->br->dev,
1000 .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
1001 .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
1002 .u.vlan_filtering = p->br->vlan_enabled,
1003 };
Nikolay Aleksandrov263344e2015-09-30 20:16:54 +02001004 struct net_bridge_vlan_group *vg;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001005 int ret = -ENOMEM;
1006
Nikolay Aleksandrov263344e2015-09-30 20:16:54 +02001007 vg = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL);
1008 if (!vg)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001009 goto out;
1010
Elad Raz404cdbf2016-01-06 13:01:07 +01001011 ret = switchdev_port_attr_set(p->dev, &attr);
1012 if (ret && ret != -EOPNOTSUPP)
1013 goto err_vlan_enabled;
1014
Nikolay Aleksandrov263344e2015-09-30 20:16:54 +02001015 ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001016 if (ret)
1017 goto err_rhtbl;
Roopa Prabhuefa53562017-01-31 22:59:54 -08001018 ret = vlan_tunnel_init(vg);
1019 if (ret)
1020 goto err_tunnel_init;
Nikolay Aleksandrov263344e2015-09-30 20:16:54 +02001021 INIT_LIST_HEAD(&vg->vlan_list);
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001022 rcu_assign_pointer(p->vlgrp, vg);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001023 if (p->br->default_pvid) {
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001024 bool changed;
1025
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001026 ret = nbp_vlan_add(p, p->br->default_pvid,
1027 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001028 BRIDGE_VLAN_INFO_UNTAGGED,
1029 &changed);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001030 if (ret)
1031 goto err_vlan_add;
1032 }
1033out:
1034 return ret;
1035
1036err_vlan_add:
Ido Schimmel07bc5882015-10-30 17:46:19 +01001037 RCU_INIT_POINTER(p->vlgrp, NULL);
1038 synchronize_rcu();
Roopa Prabhuefa53562017-01-31 22:59:54 -08001039 vlan_tunnel_deinit(vg);
Roopa Prabhuefa53562017-01-31 22:59:54 -08001040err_tunnel_init:
1041 rhashtable_destroy(&vg->vlan_hash);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001042err_rhtbl:
Yotam Gigidf2c4332017-03-01 16:50:45 +02001043err_vlan_enabled:
Nikolay Aleksandrov263344e2015-09-30 20:16:54 +02001044 kfree(vg);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001045
1046 goto out;
Toshiaki Makita8580e212014-06-10 20:59:23 +09001047}
1048
Toshiaki Makita8adff412013-10-16 17:07:13 +09001049/* Must be protected by RTNL.
1050 * Must be called with vid in range from 1 to 4094 inclusive.
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001051 * changed must be true only if the vlan was created or updated
Toshiaki Makita8adff412013-10-16 17:07:13 +09001052 */
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001053int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
1054 bool *changed)
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001055{
Ido Schimmel7fbac982016-02-18 14:01:46 +01001056 struct switchdev_obj_port_vlan v = {
1057 .obj.orig_dev = port->dev,
1058 .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN,
1059 .flags = flags,
1060 .vid_begin = vid,
1061 .vid_end = vid,
1062 };
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001063 struct net_bridge_vlan *vlan;
1064 int ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001065
1066 ASSERT_RTNL();
1067
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001068 *changed = false;
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001069 vlan = br_vlan_find(nbp_vlan_group(port), vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001070 if (vlan) {
Ido Schimmel7fbac982016-02-18 14:01:46 +01001071 /* Pass the flags to the hardware bridge */
1072 ret = switchdev_port_obj_add(port->dev, &v.obj);
1073 if (ret && ret != -EOPNOTSUPP)
1074 return ret;
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001075 *changed = __vlan_add_flags(vlan, flags);
1076
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001077 return 0;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001078 }
1079
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001080 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
1081 if (!vlan)
1082 return -ENOMEM;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001083
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001084 vlan->vid = vid;
1085 vlan->port = port;
1086 ret = __vlan_add(vlan, flags);
1087 if (ret)
1088 kfree(vlan);
Nikolay Aleksandrovf418af62017-10-27 13:19:37 +03001089 else
1090 *changed = true;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001091
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001092 return ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001093}
1094
Toshiaki Makita8adff412013-10-16 17:07:13 +09001095/* Must be protected by RTNL.
1096 * Must be called with vid in range from 1 to 4094 inclusive.
1097 */
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001098int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
1099{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001100 struct net_bridge_vlan *v;
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001101
1102 ASSERT_RTNL();
1103
Nikolay Aleksandrov907b1e62015-10-12 21:47:02 +02001104 v = br_vlan_find(nbp_vlan_group(port), vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001105 if (!v)
1106 return -ENOENT;
Toshiaki Makita424bb9c2014-02-07 16:48:25 +09001107 br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid);
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -07001108 br_fdb_delete_by_port(port->br, port, vid, 0);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +00001109
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02001110 return __vlan_del(v);
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001111}
1112
1113void nbp_vlan_flush(struct net_bridge_port *port)
1114{
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +02001115 struct net_bridge_vlan_group *vg;
1116
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001117 ASSERT_RTNL();
1118
Nikolay Aleksandrovf409d0e2015-10-12 21:47:05 +02001119 vg = nbp_vlan_group(port);
1120 __vlan_flush(vg);
1121 RCU_INIT_POINTER(port->vlgrp, NULL);
1122 synchronize_rcu();
1123 __vlan_group_free(vg);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -04001124}
Nikolay Aleksandrova60c0902016-04-30 10:25:29 +02001125
1126void br_vlan_get_stats(const struct net_bridge_vlan *v,
1127 struct br_vlan_stats *stats)
1128{
1129 int i;
1130
1131 memset(stats, 0, sizeof(*stats));
1132 for_each_possible_cpu(i) {
1133 u64 rxpackets, rxbytes, txpackets, txbytes;
1134 struct br_vlan_stats *cpu_stats;
1135 unsigned int start;
1136
1137 cpu_stats = per_cpu_ptr(v->stats, i);
1138 do {
1139 start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
1140 rxpackets = cpu_stats->rx_packets;
1141 rxbytes = cpu_stats->rx_bytes;
1142 txbytes = cpu_stats->tx_bytes;
1143 txpackets = cpu_stats->tx_packets;
1144 } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
1145
1146 stats->rx_packets += rxpackets;
1147 stats->rx_bytes += rxbytes;
1148 stats->tx_bytes += txbytes;
1149 stats->tx_packets += txpackets;
1150 }
1151}