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