Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/netdevice.h> |
| 3 | #include <linux/rtnetlink.h> |
| 4 | #include <linux/slab.h> |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 5 | #include <net/switchdev.h> |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 6 | |
| 7 | #include "br_private.h" |
| 8 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 9 | static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg, |
| 10 | const void *ptr) |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 11 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 12 | const struct net_bridge_vlan *vle = ptr; |
| 13 | u16 vid = *(u16 *)arg->key; |
| 14 | |
| 15 | return vle->vid != vid; |
| 16 | } |
| 17 | |
| 18 | static const struct rhashtable_params br_vlan_rht_params = { |
| 19 | .head_offset = offsetof(struct net_bridge_vlan, vnode), |
| 20 | .key_offset = offsetof(struct net_bridge_vlan, vid), |
| 21 | .key_len = sizeof(u16), |
Nikolay Aleksandrov | 8af78b6 | 2015-09-30 20:16:51 +0200 | [diff] [blame] | 22 | .nelem_hint = 3, |
| 23 | .locks_mul = 1, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 24 | .max_size = VLAN_N_VID, |
| 25 | .obj_cmpfn = br_vlan_cmp, |
| 26 | .automatic_shrinking = true, |
| 27 | }; |
| 28 | |
| 29 | static struct net_bridge_vlan *br_vlan_lookup(struct rhashtable *tbl, u16 vid) |
| 30 | { |
| 31 | return rhashtable_lookup_fast(tbl, &vid, br_vlan_rht_params); |
| 32 | } |
| 33 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 34 | static void __vlan_add_pvid(struct net_bridge_vlan_group *vg, u16 vid) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 35 | { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 36 | if (vg->pvid == vid) |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 37 | return; |
| 38 | |
| 39 | smp_wmb(); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 40 | vg->pvid = vid; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 43 | static void __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid) |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 44 | { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 45 | if (vg->pvid != vid) |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 46 | return; |
| 47 | |
| 48 | smp_wmb(); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 49 | vg->pvid = 0; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 52 | static void __vlan_add_flags(struct net_bridge_vlan *v, u16 flags) |
Vlad Yasevich | 35e03f3 | 2013-02-13 12:00:20 +0000 | [diff] [blame] | 53 | { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 54 | struct net_bridge_vlan_group *vg; |
| 55 | |
| 56 | if (br_vlan_is_master(v)) |
| 57 | vg = v->br->vlgrp; |
| 58 | else |
| 59 | vg = v->port->vlgrp; |
| 60 | |
| 61 | if (flags & BRIDGE_VLAN_INFO_PVID) |
| 62 | __vlan_add_pvid(vg, v->vid); |
| 63 | else |
| 64 | __vlan_delete_pvid(vg, v->vid); |
Vlad Yasevich | 35e03f3 | 2013-02-13 12:00:20 +0000 | [diff] [blame] | 65 | |
| 66 | if (flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 67 | v->flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
Vlad Yasevich | 635126b | 2014-09-12 16:26:17 -0400 | [diff] [blame] | 68 | else |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 69 | v->flags &= ~BRIDGE_VLAN_INFO_UNTAGGED; |
Vlad Yasevich | 35e03f3 | 2013-02-13 12:00:20 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 72 | static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, |
| 73 | u16 vid, u16 flags) |
| 74 | { |
| 75 | const struct net_device_ops *ops = dev->netdev_ops; |
| 76 | int err; |
| 77 | |
| 78 | /* If driver uses VLAN ndo ops, use 8021q to install vid |
| 79 | * on device, otherwise try switchdev ops to install vid. |
| 80 | */ |
| 81 | |
| 82 | if (ops->ndo_vlan_rx_add_vid) { |
| 83 | err = vlan_vid_add(dev, br->vlan_proto, vid); |
| 84 | } else { |
Jiri Pirko | 8f24f30 | 2015-10-01 11:03:43 +0200 | [diff] [blame^] | 85 | struct switchdev_obj_port_vlan v = { |
Vivien Didelot | ab06900 | 2015-09-29 12:07:17 -0400 | [diff] [blame] | 86 | .flags = flags, |
| 87 | .vid_begin = vid, |
| 88 | .vid_end = vid, |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
Jiri Pirko | 57d8083 | 2015-10-01 11:03:41 +0200 | [diff] [blame] | 91 | err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, |
| 92 | &v); |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 93 | if (err == -EOPNOTSUPP) |
| 94 | err = 0; |
| 95 | } |
| 96 | |
| 97 | return err; |
| 98 | } |
| 99 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 100 | static void __vlan_add_list(struct net_bridge_vlan *v) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 101 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 102 | struct list_head *headp, *hpos; |
| 103 | struct net_bridge_vlan *vent; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 104 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 105 | headp = br_vlan_is_master(v) ? &v->br->vlgrp->vlan_list : |
| 106 | &v->port->vlgrp->vlan_list; |
| 107 | list_for_each_prev(hpos, headp) { |
| 108 | vent = list_entry(hpos, struct net_bridge_vlan, vlist); |
| 109 | if (v->vid < vent->vid) |
| 110 | continue; |
| 111 | else |
| 112 | break; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 113 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 114 | list_add(&v->vlist, hpos); |
| 115 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 116 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 117 | static void __vlan_del_list(struct net_bridge_vlan *v) |
| 118 | { |
| 119 | list_del(&v->vlist); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 122 | static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, |
| 123 | u16 vid) |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 124 | { |
| 125 | const struct net_device_ops *ops = dev->netdev_ops; |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 126 | int err = 0; |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 127 | |
| 128 | /* If driver uses VLAN ndo ops, use 8021q to delete vid |
| 129 | * on device, otherwise try switchdev ops to delete vid. |
| 130 | */ |
| 131 | |
| 132 | if (ops->ndo_vlan_rx_kill_vid) { |
| 133 | vlan_vid_del(dev, br->vlan_proto, vid); |
| 134 | } else { |
Jiri Pirko | 8f24f30 | 2015-10-01 11:03:43 +0200 | [diff] [blame^] | 135 | struct switchdev_obj_port_vlan v = { |
Vivien Didelot | ab06900 | 2015-09-29 12:07:17 -0400 | [diff] [blame] | 136 | .vid_begin = vid, |
| 137 | .vid_end = vid, |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Jiri Pirko | 57d8083 | 2015-10-01 11:03:41 +0200 | [diff] [blame] | 140 | err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_ID_PORT_VLAN, |
| 141 | &v); |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 142 | if (err == -EOPNOTSUPP) |
| 143 | err = 0; |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 144 | } |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 145 | |
| 146 | return err; |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 149 | /* This is the shared VLAN add function which works for both ports and bridge |
| 150 | * devices. There are four possible calls to this function in terms of the |
| 151 | * vlan entry type: |
| 152 | * 1. vlan is being added on a port (no master flags, global entry exists) |
| 153 | * 2. vlan is being added on a bridge (both master and brvlan flags) |
| 154 | * 3. vlan is being added on a port, but a global entry didn't exist which |
| 155 | * is being created right now (master flag set, brvlan flag unset), the |
| 156 | * global entry is used for global per-vlan features, but not for filtering |
| 157 | * 4. same as 3 but with both master and brvlan flags set so the entry |
| 158 | * will be used for filtering in both the port and the bridge |
| 159 | */ |
| 160 | static int __vlan_add(struct net_bridge_vlan *v, u16 flags) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 161 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 162 | struct net_bridge_vlan *masterv = NULL; |
| 163 | struct net_bridge_port *p = NULL; |
| 164 | struct rhashtable *tbl; |
| 165 | struct net_device *dev; |
| 166 | struct net_bridge *br; |
| 167 | int err; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 168 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 169 | if (br_vlan_is_master(v)) { |
| 170 | br = v->br; |
| 171 | dev = br->dev; |
| 172 | tbl = &br->vlgrp->vlan_hash; |
| 173 | } else { |
| 174 | p = v->port; |
| 175 | br = p->br; |
| 176 | dev = p->dev; |
| 177 | tbl = &p->vlgrp->vlan_hash; |
| 178 | } |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 179 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 180 | if (p) { |
| 181 | u16 master_flags = flags; |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 182 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 183 | /* Add VLAN to the device filter if it is supported. |
| 184 | * This ensures tagged traffic enters the bridge when |
| 185 | * promiscuous mode is disabled by br_manage_promisc(). |
| 186 | */ |
| 187 | err = __vlan_vid_add(dev, br, v->vid, flags); |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 188 | if (err) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 189 | goto out; |
| 190 | |
| 191 | /* need to work on the master vlan too */ |
| 192 | if (flags & BRIDGE_VLAN_INFO_MASTER) { |
| 193 | master_flags |= BRIDGE_VLAN_INFO_BRENTRY; |
| 194 | err = br_vlan_add(br, v->vid, master_flags); |
| 195 | if (err) |
| 196 | goto out_filt; |
| 197 | } |
| 198 | |
| 199 | masterv = br_vlan_find(br->vlgrp, v->vid); |
| 200 | if (!masterv) { |
| 201 | /* missing global ctx, create it now */ |
Nikolay Aleksandrov | 248234c | 2015-09-30 20:16:55 +0200 | [diff] [blame] | 202 | err = br_vlan_add(br, v->vid, 0); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 203 | if (err) |
| 204 | goto out_filt; |
| 205 | masterv = br_vlan_find(br->vlgrp, v->vid); |
| 206 | WARN_ON(!masterv); |
| 207 | } |
| 208 | atomic_inc(&masterv->refcnt); |
| 209 | v->brvlan = masterv; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 210 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 211 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 212 | /* Add the dev mac only if it's a usable vlan */ |
| 213 | if (br_vlan_should_use(v)) { |
| 214 | err = br_fdb_insert(br, p, dev->dev_addr, v->vid); |
| 215 | if (err) { |
| 216 | br_err(br, "failed insert local address into bridge forwarding table\n"); |
| 217 | goto out_filt; |
| 218 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 219 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 220 | |
| 221 | err = rhashtable_lookup_insert_fast(tbl, &v->vnode, br_vlan_rht_params); |
| 222 | if (err) |
| 223 | goto out_fdb_insert; |
| 224 | |
| 225 | __vlan_add_list(v); |
| 226 | __vlan_add_flags(v, flags); |
| 227 | if (br_vlan_is_master(v)) { |
| 228 | if (br_vlan_is_brentry(v)) |
| 229 | br->vlgrp->num_vlans++; |
| 230 | } else { |
| 231 | p->vlgrp->num_vlans++; |
| 232 | } |
| 233 | out: |
| 234 | return err; |
| 235 | |
| 236 | out_fdb_insert: |
| 237 | br_fdb_find_delete_local(br, p, br->dev->dev_addr, v->vid); |
| 238 | |
| 239 | out_filt: |
| 240 | if (p) { |
| 241 | __vlan_vid_del(dev, br, v->vid); |
| 242 | if (masterv) { |
| 243 | atomic_dec(&masterv->refcnt); |
| 244 | v->brvlan = NULL; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | goto out; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 251 | static int __vlan_del(struct net_bridge_vlan *v) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 252 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 253 | struct net_bridge_vlan *masterv = v; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 254 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 255 | struct net_bridge_port *p = NULL; |
| 256 | struct net_bridge *br; |
| 257 | int err = 0; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 258 | |
| 259 | if (br_vlan_is_master(v)) { |
| 260 | br = v->br; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 261 | vg = v->br->vlgrp; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 262 | } else { |
| 263 | p = v->port; |
| 264 | br = p->br; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 265 | vg = v->port->vlgrp; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 266 | masterv = v->brvlan; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 269 | __vlan_delete_pvid(vg, v->vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 270 | if (p) { |
| 271 | err = __vlan_vid_del(p->dev, p->br, v->vid); |
| 272 | if (err) |
| 273 | goto out; |
| 274 | } |
| 275 | |
| 276 | if (br_vlan_is_master(v)) { |
| 277 | if (br_vlan_is_brentry(v)) { |
| 278 | v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY; |
| 279 | br->vlgrp->num_vlans--; |
| 280 | } |
| 281 | } else { |
| 282 | p->vlgrp->num_vlans--; |
| 283 | } |
| 284 | |
| 285 | if (masterv != v) { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 286 | rhashtable_remove_fast(&vg->vlan_hash, &v->vnode, |
| 287 | br_vlan_rht_params); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 288 | __vlan_del_list(v); |
| 289 | kfree_rcu(v, rcu); |
| 290 | } |
| 291 | |
| 292 | if (atomic_dec_and_test(&masterv->refcnt)) { |
| 293 | rhashtable_remove_fast(&masterv->br->vlgrp->vlan_hash, |
| 294 | &masterv->vnode, br_vlan_rht_params); |
| 295 | __vlan_del_list(masterv); |
| 296 | kfree_rcu(masterv, rcu); |
| 297 | } |
| 298 | out: |
| 299 | return err; |
| 300 | } |
| 301 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 302 | static void __vlan_flush(struct net_bridge_vlan_group *vlgrp) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 303 | { |
| 304 | struct net_bridge_vlan *vlan, *tmp; |
| 305 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 306 | __vlan_delete_pvid(vlgrp, vlgrp->pvid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 307 | list_for_each_entry_safe(vlan, tmp, &vlgrp->vlan_list, vlist) |
| 308 | __vlan_del(vlan); |
| 309 | rhashtable_destroy(&vlgrp->vlan_hash); |
| 310 | kfree(vlgrp); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 313 | struct sk_buff *br_handle_vlan(struct net_bridge *br, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 314 | struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 315 | struct sk_buff *skb) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 316 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 317 | struct net_bridge_vlan *v; |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 318 | u16 vid; |
| 319 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 320 | /* If this packet was not filtered at input, let it pass */ |
| 321 | if (!BR_INPUT_SKB_CB(skb)->vlan_filtered) |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 322 | goto out; |
| 323 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 324 | /* At this point, we know that the frame was filtered and contains |
| 325 | * a valid vlan id. If the vlan id has untagged flag set, |
| 326 | * send untagged; otherwise, send tagged. |
| 327 | */ |
| 328 | br_vlan_get_tag(skb, &vid); |
| 329 | v = br_vlan_find(vg, vid); |
| 330 | /* Vlan entry must be configured at this point. The |
Vlad Yasevich | fc92f74 | 2014-03-27 21:51:18 -0400 | [diff] [blame] | 331 | * only exception is the bridge is set in promisc mode and the |
| 332 | * packet is destined for the bridge device. In this case |
| 333 | * pass the packet as is. |
| 334 | */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 335 | if (!v || !br_vlan_should_use(v)) { |
Vlad Yasevich | fc92f74 | 2014-03-27 21:51:18 -0400 | [diff] [blame] | 336 | if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) { |
| 337 | goto out; |
| 338 | } else { |
| 339 | kfree_skb(skb); |
| 340 | return NULL; |
| 341 | } |
| 342 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 343 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Toshiaki Makita | 99b192d | 2014-03-27 21:46:56 +0900 | [diff] [blame] | 344 | skb->vlan_tci = 0; |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 345 | |
| 346 | out: |
| 347 | return skb; |
| 348 | } |
| 349 | |
| 350 | /* Called under RCU */ |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 351 | static bool __allowed_ingress(struct net_bridge_vlan_group *vg, __be16 proto, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 352 | struct sk_buff *skb, u16 *vid) |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 353 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 354 | const struct net_bridge_vlan *v; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 355 | bool tagged; |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 356 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 357 | BR_INPUT_SKB_CB(skb)->vlan_filtered = true; |
Toshiaki Makita | 12464bb | 2014-03-27 21:46:55 +0900 | [diff] [blame] | 358 | /* If vlan tx offload is disabled on bridge device and frame was |
| 359 | * sent from vlan device on the bridge device, it does not have |
| 360 | * HW accelerated vlan tag. |
| 361 | */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 362 | if (unlikely(!skb_vlan_tag_present(skb) && |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 363 | skb->protocol == proto)) { |
Vlad Yasevich | 0d5501c | 2014-08-08 14:42:13 -0400 | [diff] [blame] | 364 | skb = skb_vlan_untag(skb); |
Toshiaki Makita | 12464bb | 2014-03-27 21:46:55 +0900 | [diff] [blame] | 365 | if (unlikely(!skb)) |
| 366 | return false; |
| 367 | } |
| 368 | |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 369 | if (!br_vlan_get_tag(skb, vid)) { |
| 370 | /* Tagged frame */ |
| 371 | if (skb->vlan_proto != proto) { |
| 372 | /* Protocol-mismatch, empty out vlan_tci for new tag */ |
| 373 | skb_push(skb, ETH_HLEN); |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 374 | skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 375 | skb_vlan_tag_get(skb)); |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 376 | if (unlikely(!skb)) |
| 377 | return false; |
| 378 | |
| 379 | skb_pull(skb, ETH_HLEN); |
| 380 | skb_reset_mac_len(skb); |
| 381 | *vid = 0; |
| 382 | tagged = false; |
| 383 | } else { |
| 384 | tagged = true; |
| 385 | } |
| 386 | } else { |
| 387 | /* Untagged frame */ |
| 388 | tagged = false; |
| 389 | } |
| 390 | |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 391 | if (!*vid) { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 392 | u16 pvid = br_get_pvid(vg); |
| 393 | |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 394 | /* Frame had a tag with VID 0 or did not have a tag. |
| 395 | * See if pvid is set on this port. That tells us which |
| 396 | * vlan untagged or priority-tagged traffic belongs to. |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 397 | */ |
Vlad Yasevich | 3df6bf4 | 2014-10-03 11:29:17 -0400 | [diff] [blame] | 398 | if (!pvid) |
Toshiaki Makita | eb70761 | 2014-04-09 17:00:30 +0900 | [diff] [blame] | 399 | goto drop; |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 400 | |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 401 | /* PVID is set on this port. Any untagged or priority-tagged |
| 402 | * ingress frame is considered to belong to this vlan. |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 403 | */ |
Toshiaki Makita | dfb5fa3 | 2013-10-16 17:07:16 +0900 | [diff] [blame] | 404 | *vid = pvid; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 405 | if (likely(!tagged)) |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 406 | /* Untagged Frame. */ |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 407 | __vlan_hwaccel_put_tag(skb, proto, pvid); |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 408 | else |
| 409 | /* Priority-tagged Frame. |
| 410 | * At this point, We know that skb->vlan_tci had |
| 411 | * VLAN_TAG_PRESENT bit and its VID field was 0x000. |
| 412 | * We update only VID field and preserve PCP field. |
| 413 | */ |
| 414 | skb->vlan_tci |= pvid; |
| 415 | |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 416 | return true; |
| 417 | } |
| 418 | |
| 419 | /* Frame had a valid vlan tag. See if vlan is allowed */ |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 420 | v = br_vlan_find(vg, *vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 421 | if (v && br_vlan_should_use(v)) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 422 | return true; |
Toshiaki Makita | eb70761 | 2014-04-09 17:00:30 +0900 | [diff] [blame] | 423 | drop: |
| 424 | kfree_skb(skb); |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 425 | return false; |
| 426 | } |
| 427 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 428 | bool br_allowed_ingress(const struct net_bridge *br, |
| 429 | struct net_bridge_vlan_group *vg, struct sk_buff *skb, |
| 430 | u16 *vid) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 431 | { |
| 432 | /* If VLAN filtering is disabled on the bridge, all packets are |
| 433 | * permitted. |
| 434 | */ |
| 435 | if (!br->vlan_enabled) { |
| 436 | BR_INPUT_SKB_CB(skb)->vlan_filtered = false; |
| 437 | return true; |
| 438 | } |
| 439 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 440 | return __allowed_ingress(vg, br->vlan_proto, skb, vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 443 | /* Called under RCU. */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 444 | bool br_allowed_egress(struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 445 | const struct sk_buff *skb) |
| 446 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 447 | const struct net_bridge_vlan *v; |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 448 | u16 vid; |
| 449 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 450 | /* If this packet was not filtered at input, let it pass */ |
| 451 | if (!BR_INPUT_SKB_CB(skb)->vlan_filtered) |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 452 | return true; |
| 453 | |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 454 | br_vlan_get_tag(skb, &vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 455 | v = br_vlan_find(vg, vid); |
| 456 | if (v && br_vlan_should_use(v)) |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 457 | return true; |
| 458 | |
| 459 | return false; |
| 460 | } |
| 461 | |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 462 | /* Called under RCU */ |
| 463 | bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) |
| 464 | { |
Nikolay Aleksandrov | 468e794 | 2015-09-30 20:16:52 +0200 | [diff] [blame] | 465 | struct net_bridge_vlan_group *vg; |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 466 | struct net_bridge *br = p->br; |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 467 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 468 | /* If filtering was disabled at input, let it pass. */ |
Vlad Yasevich | c095f24 | 2014-09-15 15:24:26 -0400 | [diff] [blame] | 469 | if (!br->vlan_enabled) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 470 | return true; |
| 471 | |
Nikolay Aleksandrov | 468e794 | 2015-09-30 20:16:52 +0200 | [diff] [blame] | 472 | vg = p->vlgrp; |
| 473 | if (!vg || !vg->num_vlans) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 474 | return false; |
| 475 | |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 476 | if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto) |
| 477 | *vid = 0; |
| 478 | |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 479 | if (!*vid) { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 480 | *vid = br_get_pvid(vg); |
Vlad Yasevich | 3df6bf4 | 2014-10-03 11:29:17 -0400 | [diff] [blame] | 481 | if (!*vid) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 482 | return false; |
| 483 | |
| 484 | return true; |
| 485 | } |
| 486 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 487 | if (br_vlan_find(vg, *vid)) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 488 | return true; |
| 489 | |
| 490 | return false; |
| 491 | } |
| 492 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 493 | /* Must be protected by RTNL. |
| 494 | * Must be called with vid in range from 1 to 4094 inclusive. |
| 495 | */ |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 496 | int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 497 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 498 | struct net_bridge_vlan *vlan; |
| 499 | int ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 500 | |
| 501 | ASSERT_RTNL(); |
| 502 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 503 | vlan = br_vlan_find(br->vlgrp, vid); |
| 504 | if (vlan) { |
| 505 | if (!br_vlan_is_brentry(vlan)) { |
| 506 | /* Trying to change flags of non-existent bridge vlan */ |
| 507 | if (!(flags & BRIDGE_VLAN_INFO_BRENTRY)) |
| 508 | return -EINVAL; |
| 509 | /* It was only kept for port vlans, now make it real */ |
| 510 | ret = br_fdb_insert(br, NULL, br->dev->dev_addr, |
| 511 | vlan->vid); |
| 512 | if (ret) { |
| 513 | br_err(br, "failed insert local address into bridge forwarding table\n"); |
| 514 | return ret; |
| 515 | } |
| 516 | atomic_inc(&vlan->refcnt); |
| 517 | vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY; |
| 518 | br->vlgrp->num_vlans++; |
| 519 | } |
| 520 | __vlan_add_flags(vlan, flags); |
| 521 | return 0; |
| 522 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 523 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 524 | vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); |
| 525 | if (!vlan) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 526 | return -ENOMEM; |
| 527 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 528 | vlan->vid = vid; |
| 529 | vlan->flags = flags | BRIDGE_VLAN_INFO_MASTER; |
| 530 | vlan->flags &= ~BRIDGE_VLAN_INFO_PVID; |
| 531 | vlan->br = br; |
| 532 | if (flags & BRIDGE_VLAN_INFO_BRENTRY) |
| 533 | atomic_set(&vlan->refcnt, 1); |
| 534 | ret = __vlan_add(vlan, flags); |
| 535 | if (ret) |
| 536 | kfree(vlan); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 537 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 538 | return ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 541 | /* Must be protected by RTNL. |
| 542 | * Must be called with vid in range from 1 to 4094 inclusive. |
| 543 | */ |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 544 | int br_vlan_delete(struct net_bridge *br, u16 vid) |
| 545 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 546 | struct net_bridge_vlan *v; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 547 | |
| 548 | ASSERT_RTNL(); |
| 549 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 550 | v = br_vlan_find(br->vlgrp, vid); |
| 551 | if (!v || !br_vlan_is_brentry(v)) |
| 552 | return -ENOENT; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 553 | |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame] | 554 | br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid); |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 555 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 556 | return __vlan_del(v); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | void br_vlan_flush(struct net_bridge *br) |
| 560 | { |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 561 | ASSERT_RTNL(); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 562 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 563 | __vlan_flush(br_vlan_group(br)); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 566 | struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid) |
Toshiaki Makita | 2b292fb | 2014-02-07 16:48:22 +0900 | [diff] [blame] | 567 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 568 | if (!vg) |
| 569 | return NULL; |
Toshiaki Makita | 2b292fb | 2014-02-07 16:48:22 +0900 | [diff] [blame] | 570 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 571 | return br_vlan_lookup(&vg->vlan_hash, vid); |
Toshiaki Makita | 2b292fb | 2014-02-07 16:48:22 +0900 | [diff] [blame] | 572 | } |
| 573 | |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 574 | /* Must be protected by RTNL. */ |
| 575 | static void recalculate_group_addr(struct net_bridge *br) |
| 576 | { |
| 577 | if (br->group_addr_set) |
| 578 | return; |
| 579 | |
| 580 | spin_lock_bh(&br->lock); |
| 581 | if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) { |
| 582 | /* Bridge Group Address */ |
| 583 | br->group_addr[5] = 0x00; |
| 584 | } else { /* vlan_enabled && ETH_P_8021AD */ |
| 585 | /* Provider Bridge Group Address */ |
| 586 | br->group_addr[5] = 0x08; |
| 587 | } |
| 588 | spin_unlock_bh(&br->lock); |
| 589 | } |
| 590 | |
| 591 | /* Must be protected by RTNL. */ |
| 592 | void br_recalculate_fwd_mask(struct net_bridge *br) |
| 593 | { |
| 594 | if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) |
| 595 | br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT; |
| 596 | else /* vlan_enabled && ETH_P_8021AD */ |
| 597 | br->group_fwd_mask_required = BR_GROUPFWD_8021AD & |
| 598 | ~(1u << br->group_addr[5]); |
| 599 | } |
| 600 | |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 601 | int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 602 | { |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 603 | if (br->vlan_enabled == val) |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 604 | return 0; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 605 | |
| 606 | br->vlan_enabled = val; |
Vlad Yasevich | 2796d0c | 2014-05-16 09:59:20 -0400 | [diff] [blame] | 607 | br_manage_promisc(br); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 608 | recalculate_group_addr(br); |
| 609 | br_recalculate_fwd_mask(br); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 610 | |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 611 | return 0; |
| 612 | } |
| 613 | |
| 614 | int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) |
| 615 | { |
| 616 | if (!rtnl_trylock()) |
| 617 | return restart_syscall(); |
| 618 | |
| 619 | __br_vlan_filter_toggle(br, val); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 620 | rtnl_unlock(); |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 621 | |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 622 | return 0; |
| 623 | } |
| 624 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 625 | int __br_vlan_set_proto(struct net_bridge *br, __be16 proto) |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 626 | { |
| 627 | int err = 0; |
| 628 | struct net_bridge_port *p; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 629 | struct net_bridge_vlan *vlan; |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 630 | __be16 oldproto; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 631 | |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 632 | if (br->vlan_proto == proto) |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 633 | return 0; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 634 | |
| 635 | /* Add VLANs for the new proto to the device filter. */ |
| 636 | list_for_each_entry(p, &br->port_list, list) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 637 | list_for_each_entry(vlan, &p->vlgrp->vlan_list, vlist) { |
| 638 | err = vlan_vid_add(p->dev, proto, vlan->vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 639 | if (err) |
| 640 | goto err_filt; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | oldproto = br->vlan_proto; |
| 645 | br->vlan_proto = proto; |
| 646 | |
| 647 | recalculate_group_addr(br); |
| 648 | br_recalculate_fwd_mask(br); |
| 649 | |
| 650 | /* Delete VLANs for the old proto from the device filter. */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 651 | list_for_each_entry(p, &br->port_list, list) |
| 652 | list_for_each_entry(vlan, &p->vlgrp->vlan_list, vlist) |
| 653 | vlan_vid_del(p->dev, oldproto, vlan->vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 654 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 655 | return 0; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 656 | |
| 657 | err_filt: |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 658 | list_for_each_entry_continue_reverse(vlan, &p->vlgrp->vlan_list, vlist) |
| 659 | vlan_vid_del(p->dev, proto, vlan->vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 660 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 661 | list_for_each_entry_continue_reverse(p, &br->port_list, list) |
| 662 | list_for_each_entry(vlan, &p->vlgrp->vlan_list, vlist) |
| 663 | vlan_vid_del(p->dev, proto, vlan->vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 664 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 665 | return err; |
| 666 | } |
| 667 | |
| 668 | int br_vlan_set_proto(struct net_bridge *br, unsigned long val) |
| 669 | { |
| 670 | int err; |
| 671 | |
| 672 | if (val != ETH_P_8021Q && val != ETH_P_8021AD) |
| 673 | return -EPROTONOSUPPORT; |
| 674 | |
| 675 | if (!rtnl_trylock()) |
| 676 | return restart_syscall(); |
| 677 | |
| 678 | err = __br_vlan_set_proto(br, htons(val)); |
| 679 | rtnl_unlock(); |
| 680 | |
| 681 | return err; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 682 | } |
| 683 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 684 | static bool vlan_default_pvid(struct net_bridge_vlan_group *vg, u16 vid) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 685 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 686 | struct net_bridge_vlan *v; |
| 687 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 688 | if (vid != vg->pvid) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 689 | return false; |
| 690 | |
| 691 | v = br_vlan_lookup(&vg->vlan_hash, vid); |
| 692 | if (v && br_vlan_should_use(v) && |
| 693 | (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)) |
| 694 | return true; |
| 695 | |
| 696 | return false; |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static void br_vlan_disable_default_pvid(struct net_bridge *br) |
| 700 | { |
| 701 | struct net_bridge_port *p; |
| 702 | u16 pvid = br->default_pvid; |
| 703 | |
| 704 | /* Disable default_pvid on all ports where it is still |
| 705 | * configured. |
| 706 | */ |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 707 | if (vlan_default_pvid(br->vlgrp, pvid)) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 708 | br_vlan_delete(br, pvid); |
| 709 | |
| 710 | list_for_each_entry(p, &br->port_list, list) { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 711 | if (vlan_default_pvid(p->vlgrp, pvid)) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 712 | nbp_vlan_delete(p, pvid); |
| 713 | } |
| 714 | |
| 715 | br->default_pvid = 0; |
| 716 | } |
| 717 | |
| 718 | static int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid) |
| 719 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 720 | const struct net_bridge_vlan *pvent; |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 721 | struct net_bridge_port *p; |
| 722 | u16 old_pvid; |
| 723 | int err = 0; |
| 724 | unsigned long *changed; |
| 725 | |
| 726 | changed = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long), |
| 727 | GFP_KERNEL); |
| 728 | if (!changed) |
| 729 | return -ENOMEM; |
| 730 | |
| 731 | old_pvid = br->default_pvid; |
| 732 | |
| 733 | /* Update default_pvid config only if we do not conflict with |
| 734 | * user configuration. |
| 735 | */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 736 | pvent = br_vlan_find(br->vlgrp, pvid); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 737 | if ((!old_pvid || vlan_default_pvid(br->vlgrp, old_pvid)) && |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 738 | (!pvent || !br_vlan_should_use(pvent))) { |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 739 | err = br_vlan_add(br, pvid, |
| 740 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 741 | BRIDGE_VLAN_INFO_UNTAGGED | |
| 742 | BRIDGE_VLAN_INFO_BRENTRY); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 743 | if (err) |
| 744 | goto out; |
| 745 | br_vlan_delete(br, old_pvid); |
| 746 | set_bit(0, changed); |
| 747 | } |
| 748 | |
| 749 | list_for_each_entry(p, &br->port_list, list) { |
| 750 | /* Update default_pvid config only if we do not conflict with |
| 751 | * user configuration. |
| 752 | */ |
| 753 | if ((old_pvid && |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 754 | !vlan_default_pvid(p->vlgrp, old_pvid)) || |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 755 | br_vlan_find(p->vlgrp, pvid)) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 756 | continue; |
| 757 | |
| 758 | err = nbp_vlan_add(p, pvid, |
| 759 | BRIDGE_VLAN_INFO_PVID | |
| 760 | BRIDGE_VLAN_INFO_UNTAGGED); |
| 761 | if (err) |
| 762 | goto err_port; |
| 763 | nbp_vlan_delete(p, old_pvid); |
| 764 | set_bit(p->port_no, changed); |
| 765 | } |
| 766 | |
| 767 | br->default_pvid = pvid; |
| 768 | |
| 769 | out: |
| 770 | kfree(changed); |
| 771 | return err; |
| 772 | |
| 773 | err_port: |
| 774 | list_for_each_entry_continue_reverse(p, &br->port_list, list) { |
| 775 | if (!test_bit(p->port_no, changed)) |
| 776 | continue; |
| 777 | |
| 778 | if (old_pvid) |
| 779 | nbp_vlan_add(p, old_pvid, |
| 780 | BRIDGE_VLAN_INFO_PVID | |
| 781 | BRIDGE_VLAN_INFO_UNTAGGED); |
| 782 | nbp_vlan_delete(p, pvid); |
| 783 | } |
| 784 | |
| 785 | if (test_bit(0, changed)) { |
| 786 | if (old_pvid) |
| 787 | br_vlan_add(br, old_pvid, |
| 788 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 789 | BRIDGE_VLAN_INFO_UNTAGGED | |
| 790 | BRIDGE_VLAN_INFO_BRENTRY); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 791 | br_vlan_delete(br, pvid); |
| 792 | } |
| 793 | goto out; |
| 794 | } |
| 795 | |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 796 | int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val) |
| 797 | { |
| 798 | u16 pvid = val; |
| 799 | int err = 0; |
| 800 | |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 801 | if (val >= VLAN_VID_MASK) |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 802 | return -EINVAL; |
| 803 | |
| 804 | if (!rtnl_trylock()) |
| 805 | return restart_syscall(); |
| 806 | |
| 807 | if (pvid == br->default_pvid) |
| 808 | goto unlock; |
| 809 | |
| 810 | /* Only allow default pvid change when filtering is disabled */ |
| 811 | if (br->vlan_enabled) { |
| 812 | pr_info_once("Please disable vlan filtering to change default_pvid\n"); |
| 813 | err = -EPERM; |
| 814 | goto unlock; |
| 815 | } |
| 816 | |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 817 | if (!pvid) |
| 818 | br_vlan_disable_default_pvid(br); |
| 819 | else |
| 820 | err = __br_vlan_set_default_pvid(br, pvid); |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 821 | |
| 822 | unlock: |
| 823 | rtnl_unlock(); |
| 824 | return err; |
| 825 | } |
| 826 | |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 827 | int br_vlan_init(struct net_bridge *br) |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 828 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 829 | int ret = -ENOMEM; |
| 830 | |
| 831 | br->vlgrp = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL); |
| 832 | if (!br->vlgrp) |
| 833 | goto out; |
| 834 | ret = rhashtable_init(&br->vlgrp->vlan_hash, &br_vlan_rht_params); |
| 835 | if (ret) |
| 836 | goto err_rhtbl; |
| 837 | INIT_LIST_HEAD(&br->vlgrp->vlan_list); |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 838 | br->vlan_proto = htons(ETH_P_8021Q); |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 839 | br->default_pvid = 1; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 840 | ret = br_vlan_add(br, 1, |
| 841 | BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED | |
| 842 | BRIDGE_VLAN_INFO_BRENTRY); |
| 843 | if (ret) |
| 844 | goto err_vlan_add; |
| 845 | |
| 846 | out: |
| 847 | return ret; |
| 848 | |
| 849 | err_vlan_add: |
| 850 | rhashtable_destroy(&br->vlgrp->vlan_hash); |
| 851 | err_rhtbl: |
| 852 | kfree(br->vlgrp); |
| 853 | |
| 854 | goto out; |
| 855 | } |
| 856 | |
| 857 | int nbp_vlan_init(struct net_bridge_port *p) |
| 858 | { |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 859 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 860 | int ret = -ENOMEM; |
| 861 | |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 862 | vg = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL); |
| 863 | if (!vg) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 864 | goto out; |
| 865 | |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 866 | ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 867 | if (ret) |
| 868 | goto err_rhtbl; |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 869 | INIT_LIST_HEAD(&vg->vlan_list); |
| 870 | /* Make sure everything's committed before publishing vg */ |
| 871 | smp_wmb(); |
| 872 | p->vlgrp = vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 873 | if (p->br->default_pvid) { |
| 874 | ret = nbp_vlan_add(p, p->br->default_pvid, |
| 875 | BRIDGE_VLAN_INFO_PVID | |
| 876 | BRIDGE_VLAN_INFO_UNTAGGED); |
| 877 | if (ret) |
| 878 | goto err_vlan_add; |
| 879 | } |
| 880 | out: |
| 881 | return ret; |
| 882 | |
| 883 | err_vlan_add: |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 884 | rhashtable_destroy(&vg->vlan_hash); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 885 | err_rhtbl: |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 886 | kfree(vg); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 887 | |
| 888 | goto out; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 889 | } |
| 890 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 891 | /* Must be protected by RTNL. |
| 892 | * Must be called with vid in range from 1 to 4094 inclusive. |
| 893 | */ |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 894 | int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 895 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 896 | struct net_bridge_vlan *vlan; |
| 897 | int ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 898 | |
| 899 | ASSERT_RTNL(); |
| 900 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 901 | vlan = br_vlan_find(port->vlgrp, vid); |
| 902 | if (vlan) { |
| 903 | __vlan_add_flags(vlan, flags); |
| 904 | return 0; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 907 | vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); |
| 908 | if (!vlan) |
| 909 | return -ENOMEM; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 910 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 911 | vlan->vid = vid; |
| 912 | vlan->port = port; |
| 913 | ret = __vlan_add(vlan, flags); |
| 914 | if (ret) |
| 915 | kfree(vlan); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 916 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 917 | return ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 918 | } |
| 919 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 920 | /* Must be protected by RTNL. |
| 921 | * Must be called with vid in range from 1 to 4094 inclusive. |
| 922 | */ |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 923 | int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) |
| 924 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 925 | struct net_bridge_vlan *v; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 926 | |
| 927 | ASSERT_RTNL(); |
| 928 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 929 | v = br_vlan_find(port->vlgrp, vid); |
| 930 | if (!v) |
| 931 | return -ENOENT; |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame] | 932 | br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid); |
Nikolay Aleksandrov | 1ea2d02 | 2015-06-23 05:28:16 -0700 | [diff] [blame] | 933 | br_fdb_delete_by_port(port->br, port, vid, 0); |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 934 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 935 | return __vlan_del(v); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | void nbp_vlan_flush(struct net_bridge_port *port) |
| 939 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 940 | struct net_bridge_vlan *vlan; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 941 | |
| 942 | ASSERT_RTNL(); |
| 943 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 944 | list_for_each_entry(vlan, &port->vlgrp->vlan_list, vlist) |
| 945 | vlan_vid_del(port->dev, port->br->vlan_proto, vlan->vid); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 946 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 947 | __vlan_flush(nbp_vlan_group(port)); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 948 | } |