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" |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 8 | #include "br_private_tunnel.h" |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 9 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 10 | static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg, |
| 11 | const void *ptr) |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 12 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 13 | const struct net_bridge_vlan *vle = ptr; |
| 14 | u16 vid = *(u16 *)arg->key; |
| 15 | |
| 16 | return vle->vid != vid; |
| 17 | } |
| 18 | |
| 19 | static const struct rhashtable_params br_vlan_rht_params = { |
| 20 | .head_offset = offsetof(struct net_bridge_vlan, vnode), |
| 21 | .key_offset = offsetof(struct net_bridge_vlan, vid), |
| 22 | .key_len = sizeof(u16), |
Nikolay Aleksandrov | 8af78b6 | 2015-09-30 20:16:51 +0200 | [diff] [blame] | 23 | .nelem_hint = 3, |
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 | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 34 | static bool __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) |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 37 | return false; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 38 | |
| 39 | smp_wmb(); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 40 | vg->pvid = vid; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 41 | |
| 42 | return true; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 45 | static bool __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid) |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 46 | { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 47 | if (vg->pvid != vid) |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 48 | return false; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 49 | |
| 50 | smp_wmb(); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 51 | vg->pvid = 0; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 52 | |
| 53 | return true; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 56 | /* return true if anything changed, false otherwise */ |
| 57 | static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags) |
Vlad Yasevich | 35e03f3 | 2013-02-13 12:00:20 +0000 | [diff] [blame] | 58 | { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 59 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 60 | u16 old_flags = v->flags; |
| 61 | bool ret; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 62 | |
| 63 | if (br_vlan_is_master(v)) |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 64 | vg = br_vlan_group(v->br); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 65 | else |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 66 | vg = nbp_vlan_group(v->port); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 67 | |
| 68 | if (flags & BRIDGE_VLAN_INFO_PVID) |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 69 | ret = __vlan_add_pvid(vg, v->vid); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 70 | else |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 71 | ret = __vlan_delete_pvid(vg, v->vid); |
Vlad Yasevich | 35e03f3 | 2013-02-13 12:00:20 +0000 | [diff] [blame] | 72 | |
| 73 | if (flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 74 | v->flags |= BRIDGE_VLAN_INFO_UNTAGGED; |
Vlad Yasevich | 635126b | 2014-09-12 16:26:17 -0400 | [diff] [blame] | 75 | else |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 76 | v->flags &= ~BRIDGE_VLAN_INFO_UNTAGGED; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 77 | |
| 78 | return ret || !!(old_flags ^ v->flags); |
Vlad Yasevich | 35e03f3 | 2013-02-13 12:00:20 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 81 | static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 82 | struct net_bridge_vlan *v, u16 flags, |
| 83 | struct netlink_ext_ack *extack) |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 84 | { |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 85 | int err; |
| 86 | |
Jiri Pirko | 0944d6b | 2015-10-09 13:54:11 +0200 | [diff] [blame] | 87 | /* Try switchdev op first. In case it is not supported, fallback to |
| 88 | * 8021q add. |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 89 | */ |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 90 | err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack); |
Jiri Pirko | 0944d6b | 2015-10-09 13:54:11 +0200 | [diff] [blame] | 91 | if (err == -EOPNOTSUPP) |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 92 | return vlan_vid_add(dev, br->vlan_proto, v->vid); |
| 93 | v->priv_flags |= BR_VLFLAG_ADDED_BY_SWITCHDEV; |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 94 | return err; |
| 95 | } |
| 96 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 97 | static void __vlan_add_list(struct net_bridge_vlan *v) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 98 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 99 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 100 | struct list_head *headp, *hpos; |
| 101 | struct net_bridge_vlan *vent; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 102 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 103 | if (br_vlan_is_master(v)) |
| 104 | vg = br_vlan_group(v->br); |
| 105 | else |
| 106 | vg = nbp_vlan_group(v->port); |
| 107 | |
| 108 | headp = &vg->vlan_list; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 109 | list_for_each_prev(hpos, headp) { |
| 110 | vent = list_entry(hpos, struct net_bridge_vlan, vlist); |
| 111 | if (v->vid < vent->vid) |
| 112 | continue; |
| 113 | else |
| 114 | break; |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 115 | } |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 116 | list_add_rcu(&v->vlist, hpos); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 117 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 118 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 119 | static void __vlan_del_list(struct net_bridge_vlan *v) |
| 120 | { |
Nikolay Aleksandrov | 586c2b5 | 2015-10-02 15:05:10 +0200 | [diff] [blame] | 121 | list_del_rcu(&v->vlist); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 124 | static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 125 | const struct net_bridge_vlan *v) |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 126 | { |
Jiri Pirko | 0944d6b | 2015-10-09 13:54:11 +0200 | [diff] [blame] | 127 | int err; |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 128 | |
Jiri Pirko | 0944d6b | 2015-10-09 13:54:11 +0200 | [diff] [blame] | 129 | /* Try switchdev op first. In case it is not supported, fallback to |
| 130 | * 8021q del. |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 131 | */ |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 132 | err = br_switchdev_port_vlan_del(dev, v->vid); |
| 133 | if (!(v->priv_flags & BR_VLFLAG_ADDED_BY_SWITCHDEV)) |
| 134 | vlan_vid_del(dev, br->vlan_proto, v->vid); |
| 135 | return err == -EOPNOTSUPP ? 0 : err; |
Scott Feldman | 7f10953 | 2015-06-12 17:39:50 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 138 | /* Returns a master vlan, if it didn't exist it gets created. In all cases a |
| 139 | * a reference is taken to the master vlan before returning. |
| 140 | */ |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 141 | static struct net_bridge_vlan * |
| 142 | br_vlan_get_master(struct net_bridge *br, u16 vid, |
| 143 | struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 144 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 145 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 146 | struct net_bridge_vlan *masterv; |
| 147 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 148 | vg = br_vlan_group(br); |
| 149 | masterv = br_vlan_find(vg, vid); |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 150 | if (!masterv) { |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 151 | bool changed; |
| 152 | |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 153 | /* missing global ctx, create it now */ |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 154 | if (br_vlan_add(br, vid, 0, &changed, extack)) |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 155 | return NULL; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 156 | masterv = br_vlan_find(vg, vid); |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 157 | if (WARN_ON(!masterv)) |
| 158 | return NULL; |
Ido Schimmel | 0e5a82e | 2018-02-25 21:59:06 +0200 | [diff] [blame] | 159 | refcount_set(&masterv->refcnt, 1); |
| 160 | return masterv; |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 161 | } |
Reshetova, Elena | 2512775 | 2017-07-04 15:53:05 +0300 | [diff] [blame] | 162 | refcount_inc(&masterv->refcnt); |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 163 | |
| 164 | return masterv; |
| 165 | } |
| 166 | |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 167 | static void br_master_vlan_rcu_free(struct rcu_head *rcu) |
| 168 | { |
| 169 | struct net_bridge_vlan *v; |
| 170 | |
| 171 | v = container_of(rcu, struct net_bridge_vlan, rcu); |
| 172 | WARN_ON(!br_vlan_is_master(v)); |
| 173 | free_percpu(v->stats); |
| 174 | v->stats = NULL; |
| 175 | kfree(v); |
| 176 | } |
| 177 | |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 178 | static void br_vlan_put_master(struct net_bridge_vlan *masterv) |
| 179 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 180 | struct net_bridge_vlan_group *vg; |
| 181 | |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 182 | if (!br_vlan_is_master(masterv)) |
| 183 | return; |
| 184 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 185 | vg = br_vlan_group(masterv->br); |
Reshetova, Elena | 2512775 | 2017-07-04 15:53:05 +0300 | [diff] [blame] | 186 | if (refcount_dec_and_test(&masterv->refcnt)) { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 187 | rhashtable_remove_fast(&vg->vlan_hash, |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 188 | &masterv->vnode, br_vlan_rht_params); |
| 189 | __vlan_del_list(masterv); |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 190 | call_rcu(&masterv->rcu, br_master_vlan_rcu_free); |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 194 | static void nbp_vlan_rcu_free(struct rcu_head *rcu) |
| 195 | { |
| 196 | struct net_bridge_vlan *v; |
| 197 | |
| 198 | v = container_of(rcu, struct net_bridge_vlan, rcu); |
| 199 | WARN_ON(br_vlan_is_master(v)); |
| 200 | /* if we had per-port stats configured then free them here */ |
Nikolay Aleksandrov | 9d332e69c | 2018-11-16 18:50:01 +0200 | [diff] [blame] | 201 | if (v->priv_flags & BR_VLFLAG_PER_PORT_STATS) |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 202 | free_percpu(v->stats); |
| 203 | v->stats = NULL; |
| 204 | kfree(v); |
| 205 | } |
| 206 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 207 | /* This is the shared VLAN add function which works for both ports and bridge |
| 208 | * devices. There are four possible calls to this function in terms of the |
| 209 | * vlan entry type: |
| 210 | * 1. vlan is being added on a port (no master flags, global entry exists) |
Ido Schimmel | ddd611d | 2015-10-30 17:46:20 +0100 | [diff] [blame] | 211 | * 2. vlan is being added on a bridge (both master and brentry flags) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 212 | * 3. vlan is being added on a port, but a global entry didn't exist which |
Ido Schimmel | ddd611d | 2015-10-30 17:46:20 +0100 | [diff] [blame] | 213 | * is being created right now (master flag set, brentry flag unset), the |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 214 | * global entry is used for global per-vlan features, but not for filtering |
Ido Schimmel | ddd611d | 2015-10-30 17:46:20 +0100 | [diff] [blame] | 215 | * 4. same as 3 but with both master and brentry flags set so the entry |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 216 | * will be used for filtering in both the port and the bridge |
| 217 | */ |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 218 | static int __vlan_add(struct net_bridge_vlan *v, u16 flags, |
| 219 | struct netlink_ext_ack *extack) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 220 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 221 | struct net_bridge_vlan *masterv = NULL; |
| 222 | struct net_bridge_port *p = NULL; |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 223 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 224 | struct net_device *dev; |
| 225 | struct net_bridge *br; |
| 226 | int err; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 227 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 228 | if (br_vlan_is_master(v)) { |
| 229 | br = v->br; |
| 230 | dev = br->dev; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 231 | vg = br_vlan_group(br); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 232 | } else { |
| 233 | p = v->port; |
| 234 | br = p->br; |
| 235 | dev = p->dev; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 236 | vg = nbp_vlan_group(p); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 237 | } |
Vlad Yasevich | 552406c | 2013-02-13 12:00:15 +0000 | [diff] [blame] | 238 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 239 | if (p) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 240 | /* Add VLAN to the device filter if it is supported. |
| 241 | * This ensures tagged traffic enters the bridge when |
| 242 | * promiscuous mode is disabled by br_manage_promisc(). |
| 243 | */ |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 244 | err = __vlan_vid_add(dev, br, v, flags, extack); |
Vivien Didelot | bf361ad | 2015-09-05 21:27:57 -0400 | [diff] [blame] | 245 | if (err) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 246 | goto out; |
| 247 | |
| 248 | /* need to work on the master vlan too */ |
| 249 | if (flags & BRIDGE_VLAN_INFO_MASTER) { |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 250 | bool changed; |
| 251 | |
| 252 | err = br_vlan_add(br, v->vid, |
| 253 | flags | BRIDGE_VLAN_INFO_BRENTRY, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 254 | &changed, extack); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 255 | if (err) |
| 256 | goto out_filt; |
| 257 | } |
| 258 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 259 | masterv = br_vlan_get_master(br, v->vid, extack); |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 260 | if (!masterv) |
| 261 | goto out_filt; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 262 | v->brvlan = masterv; |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 263 | if (br_opt_get(br, BROPT_VLAN_STATS_PER_PORT)) { |
| 264 | v->stats = netdev_alloc_pcpu_stats(struct br_vlan_stats); |
| 265 | if (!v->stats) { |
| 266 | err = -ENOMEM; |
| 267 | goto out_filt; |
| 268 | } |
Nikolay Aleksandrov | 9d332e69c | 2018-11-16 18:50:01 +0200 | [diff] [blame] | 269 | v->priv_flags |= BR_VLFLAG_PER_PORT_STATS; |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 270 | } else { |
| 271 | v->stats = masterv->stats; |
| 272 | } |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 273 | } else { |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 274 | err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack); |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 275 | if (err && err != -EOPNOTSUPP) |
| 276 | goto out; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 277 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 278 | |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 279 | /* Add the dev mac and count the vlan only if it's usable */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 280 | if (br_vlan_should_use(v)) { |
| 281 | err = br_fdb_insert(br, p, dev->dev_addr, v->vid); |
| 282 | if (err) { |
| 283 | br_err(br, "failed insert local address into bridge forwarding table\n"); |
| 284 | goto out_filt; |
| 285 | } |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 286 | vg->num_vlans++; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 287 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 288 | |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 289 | err = rhashtable_lookup_insert_fast(&vg->vlan_hash, &v->vnode, |
| 290 | br_vlan_rht_params); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 291 | if (err) |
| 292 | goto out_fdb_insert; |
| 293 | |
| 294 | __vlan_add_list(v); |
| 295 | __vlan_add_flags(v, flags); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 296 | out: |
| 297 | return err; |
| 298 | |
| 299 | out_fdb_insert: |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 300 | if (br_vlan_should_use(v)) { |
| 301 | br_fdb_find_delete_local(br, p, dev->dev_addr, v->vid); |
| 302 | vg->num_vlans--; |
| 303 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 304 | |
| 305 | out_filt: |
| 306 | if (p) { |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 307 | __vlan_vid_del(dev, br, v); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 308 | if (masterv) { |
Li RongQing | 1a3aea2 | 2018-10-15 19:00:31 +0800 | [diff] [blame] | 309 | if (v->stats && masterv->stats != v->stats) |
| 310 | free_percpu(v->stats); |
| 311 | v->stats = NULL; |
| 312 | |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 313 | br_vlan_put_master(masterv); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 314 | v->brvlan = NULL; |
| 315 | } |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 316 | } else { |
| 317 | br_switchdev_port_vlan_del(dev, v->vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | goto out; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 323 | static int __vlan_del(struct net_bridge_vlan *v) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 324 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 325 | struct net_bridge_vlan *masterv = v; |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 326 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 327 | struct net_bridge_port *p = NULL; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 328 | int err = 0; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 329 | |
| 330 | if (br_vlan_is_master(v)) { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 331 | vg = br_vlan_group(v->br); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 332 | } else { |
| 333 | p = v->port; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 334 | vg = nbp_vlan_group(v->port); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 335 | masterv = v->brvlan; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 338 | __vlan_delete_pvid(vg, v->vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 339 | if (p) { |
Ido Schimmel | 2797379 | 2019-01-08 16:48:11 +0000 | [diff] [blame] | 340 | err = __vlan_vid_del(p->dev, p->br, v); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 341 | if (err) |
| 342 | goto out; |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 343 | } else { |
| 344 | err = br_switchdev_port_vlan_del(v->br->dev, v->vid); |
| 345 | if (err && err != -EOPNOTSUPP) |
| 346 | goto out; |
| 347 | err = 0; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Nikolay Aleksandrov | 6be144f | 2015-10-02 15:05:13 +0200 | [diff] [blame] | 350 | if (br_vlan_should_use(v)) { |
| 351 | v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY; |
| 352 | vg->num_vlans--; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | if (masterv != v) { |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 356 | vlan_tunnel_info_del(vg, v); |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 357 | rhashtable_remove_fast(&vg->vlan_hash, &v->vnode, |
| 358 | br_vlan_rht_params); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 359 | __vlan_del_list(v); |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 360 | call_rcu(&v->rcu, nbp_vlan_rcu_free); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Nikolay Aleksandrov | f8ed289 | 2015-10-02 15:05:11 +0200 | [diff] [blame] | 363 | br_vlan_put_master(masterv); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 364 | out: |
| 365 | return err; |
| 366 | } |
| 367 | |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 368 | static void __vlan_group_free(struct net_bridge_vlan_group *vg) |
| 369 | { |
| 370 | WARN_ON(!list_empty(&vg->vlan_list)); |
| 371 | rhashtable_destroy(&vg->vlan_hash); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 372 | vlan_tunnel_deinit(vg); |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 373 | kfree(vg); |
| 374 | } |
| 375 | |
| 376 | static void __vlan_flush(struct net_bridge_vlan_group *vg) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 377 | { |
| 378 | struct net_bridge_vlan *vlan, *tmp; |
| 379 | |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 380 | __vlan_delete_pvid(vg, vg->pvid); |
| 381 | list_for_each_entry_safe(vlan, tmp, &vg->vlan_list, vlist) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 382 | __vlan_del(vlan); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 385 | struct sk_buff *br_handle_vlan(struct net_bridge *br, |
Roopa Prabhu | 11538d0 | 2017-01-31 22:59:55 -0800 | [diff] [blame] | 386 | const struct net_bridge_port *p, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 387 | struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 388 | struct sk_buff *skb) |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 389 | { |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 390 | struct br_vlan_stats *stats; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 391 | struct net_bridge_vlan *v; |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 392 | u16 vid; |
| 393 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 394 | /* If this packet was not filtered at input, let it pass */ |
| 395 | if (!BR_INPUT_SKB_CB(skb)->vlan_filtered) |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 396 | goto out; |
| 397 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 398 | /* At this point, we know that the frame was filtered and contains |
| 399 | * a valid vlan id. If the vlan id has untagged flag set, |
| 400 | * send untagged; otherwise, send tagged. |
| 401 | */ |
| 402 | br_vlan_get_tag(skb, &vid); |
| 403 | v = br_vlan_find(vg, vid); |
| 404 | /* Vlan entry must be configured at this point. The |
Vlad Yasevich | fc92f74 | 2014-03-27 21:51:18 -0400 | [diff] [blame] | 405 | * only exception is the bridge is set in promisc mode and the |
| 406 | * packet is destined for the bridge device. In this case |
| 407 | * pass the packet as is. |
| 408 | */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 409 | if (!v || !br_vlan_should_use(v)) { |
Vlad Yasevich | fc92f74 | 2014-03-27 21:51:18 -0400 | [diff] [blame] | 410 | if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) { |
| 411 | goto out; |
| 412 | } else { |
| 413 | kfree_skb(skb); |
| 414 | return NULL; |
| 415 | } |
| 416 | } |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 417 | if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) { |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 418 | stats = this_cpu_ptr(v->stats); |
| 419 | u64_stats_update_begin(&stats->syncp); |
| 420 | stats->tx_bytes += skb->len; |
| 421 | stats->tx_packets++; |
| 422 | u64_stats_update_end(&stats->syncp); |
| 423 | } |
| 424 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 425 | if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) |
Michał Mirosław | 5978f8a | 2018-11-09 00:18:03 +0100 | [diff] [blame] | 426 | __vlan_hwaccel_clear_tag(skb); |
Roopa Prabhu | 11538d0 | 2017-01-31 22:59:55 -0800 | [diff] [blame] | 427 | |
| 428 | if (p && (p->flags & BR_VLAN_TUNNEL) && |
| 429 | br_handle_egress_vlan_tunnel(skb, v)) { |
| 430 | kfree_skb(skb); |
| 431 | return NULL; |
| 432 | } |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 433 | out: |
| 434 | return skb; |
| 435 | } |
| 436 | |
| 437 | /* Called under RCU */ |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 438 | static bool __allowed_ingress(const struct net_bridge *br, |
| 439 | struct net_bridge_vlan_group *vg, |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 440 | struct sk_buff *skb, u16 *vid) |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 441 | { |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 442 | struct br_vlan_stats *stats; |
| 443 | struct net_bridge_vlan *v; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 444 | bool tagged; |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 445 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 446 | BR_INPUT_SKB_CB(skb)->vlan_filtered = true; |
Toshiaki Makita | 12464bb | 2014-03-27 21:46:55 +0900 | [diff] [blame] | 447 | /* If vlan tx offload is disabled on bridge device and frame was |
| 448 | * sent from vlan device on the bridge device, it does not have |
| 449 | * HW accelerated vlan tag. |
| 450 | */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 451 | if (unlikely(!skb_vlan_tag_present(skb) && |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 452 | skb->protocol == br->vlan_proto)) { |
Vlad Yasevich | 0d5501c | 2014-08-08 14:42:13 -0400 | [diff] [blame] | 453 | skb = skb_vlan_untag(skb); |
Toshiaki Makita | 12464bb | 2014-03-27 21:46:55 +0900 | [diff] [blame] | 454 | if (unlikely(!skb)) |
| 455 | return false; |
| 456 | } |
| 457 | |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 458 | if (!br_vlan_get_tag(skb, vid)) { |
| 459 | /* Tagged frame */ |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 460 | if (skb->vlan_proto != br->vlan_proto) { |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 461 | /* Protocol-mismatch, empty out vlan_tci for new tag */ |
| 462 | skb_push(skb, ETH_HLEN); |
Jiri Pirko | 62749e2 | 2014-11-19 14:04:58 +0100 | [diff] [blame] | 463 | skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 464 | skb_vlan_tag_get(skb)); |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 465 | if (unlikely(!skb)) |
| 466 | return false; |
| 467 | |
| 468 | skb_pull(skb, ETH_HLEN); |
| 469 | skb_reset_mac_len(skb); |
| 470 | *vid = 0; |
| 471 | tagged = false; |
| 472 | } else { |
| 473 | tagged = true; |
| 474 | } |
| 475 | } else { |
| 476 | /* Untagged frame */ |
| 477 | tagged = false; |
| 478 | } |
| 479 | |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 480 | if (!*vid) { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 481 | u16 pvid = br_get_pvid(vg); |
| 482 | |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 483 | /* Frame had a tag with VID 0 or did not have a tag. |
| 484 | * See if pvid is set on this port. That tells us which |
| 485 | * vlan untagged or priority-tagged traffic belongs to. |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 486 | */ |
Vlad Yasevich | 3df6bf4 | 2014-10-03 11:29:17 -0400 | [diff] [blame] | 487 | if (!pvid) |
Toshiaki Makita | eb70761 | 2014-04-09 17:00:30 +0900 | [diff] [blame] | 488 | goto drop; |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 489 | |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 490 | /* PVID is set on this port. Any untagged or priority-tagged |
| 491 | * ingress frame is considered to belong to this vlan. |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 492 | */ |
Toshiaki Makita | dfb5fa3 | 2013-10-16 17:07:16 +0900 | [diff] [blame] | 493 | *vid = pvid; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 494 | if (likely(!tagged)) |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 495 | /* Untagged Frame. */ |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 496 | __vlan_hwaccel_put_tag(skb, br->vlan_proto, pvid); |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 497 | else |
| 498 | /* Priority-tagged Frame. |
Michał Mirosław | 5978f8a | 2018-11-09 00:18:03 +0100 | [diff] [blame] | 499 | * At this point, we know that skb->vlan_tci VID |
| 500 | * field was 0. |
Toshiaki Makita | b90356ce | 2013-10-16 17:07:14 +0900 | [diff] [blame] | 501 | * We update only VID field and preserve PCP field. |
| 502 | */ |
| 503 | skb->vlan_tci |= pvid; |
| 504 | |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 505 | /* if stats are disabled we can avoid the lookup */ |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 506 | if (!br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 507 | return true; |
| 508 | } |
| 509 | v = br_vlan_find(vg, *vid); |
| 510 | if (!v || !br_vlan_should_use(v)) |
| 511 | goto drop; |
| 512 | |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 513 | if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) { |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 514 | stats = this_cpu_ptr(v->stats); |
| 515 | u64_stats_update_begin(&stats->syncp); |
| 516 | stats->rx_bytes += skb->len; |
| 517 | stats->rx_packets++; |
| 518 | u64_stats_update_end(&stats->syncp); |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 521 | return true; |
| 522 | |
Toshiaki Makita | eb70761 | 2014-04-09 17:00:30 +0900 | [diff] [blame] | 523 | drop: |
| 524 | kfree_skb(skb); |
Vlad Yasevich | a37b85c | 2013-02-13 12:00:10 +0000 | [diff] [blame] | 525 | return false; |
| 526 | } |
| 527 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 528 | bool br_allowed_ingress(const struct net_bridge *br, |
| 529 | struct net_bridge_vlan_group *vg, struct sk_buff *skb, |
| 530 | u16 *vid) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 531 | { |
| 532 | /* If VLAN filtering is disabled on the bridge, all packets are |
| 533 | * permitted. |
| 534 | */ |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 535 | if (!br_opt_get(br, BROPT_VLAN_ENABLED)) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 536 | BR_INPUT_SKB_CB(skb)->vlan_filtered = false; |
| 537 | return true; |
| 538 | } |
| 539 | |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 540 | return __allowed_ingress(br, vg, skb, vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 543 | /* Called under RCU. */ |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 544 | bool br_allowed_egress(struct net_bridge_vlan_group *vg, |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 545 | const struct sk_buff *skb) |
| 546 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 547 | const struct net_bridge_vlan *v; |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 548 | u16 vid; |
| 549 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 550 | /* If this packet was not filtered at input, let it pass */ |
| 551 | if (!BR_INPUT_SKB_CB(skb)->vlan_filtered) |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 552 | return true; |
| 553 | |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 554 | br_vlan_get_tag(skb, &vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 555 | v = br_vlan_find(vg, vid); |
| 556 | if (v && br_vlan_should_use(v)) |
Vlad Yasevich | 85f46c6 | 2013-02-13 12:00:11 +0000 | [diff] [blame] | 557 | return true; |
| 558 | |
| 559 | return false; |
| 560 | } |
| 561 | |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 562 | /* Called under RCU */ |
| 563 | bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) |
| 564 | { |
Nikolay Aleksandrov | 468e794 | 2015-09-30 20:16:52 +0200 | [diff] [blame] | 565 | struct net_bridge_vlan_group *vg; |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 566 | struct net_bridge *br = p->br; |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 567 | |
Vlad Yasevich | 20adfa1 | 2014-09-12 16:26:16 -0400 | [diff] [blame] | 568 | /* If filtering was disabled at input, let it pass. */ |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 569 | if (!br_opt_get(br, BROPT_VLAN_ENABLED)) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 570 | return true; |
| 571 | |
Ido Schimmel | eca1e00 | 2015-11-01 18:31:45 +0200 | [diff] [blame] | 572 | vg = nbp_vlan_group_rcu(p); |
Nikolay Aleksandrov | 468e794 | 2015-09-30 20:16:52 +0200 | [diff] [blame] | 573 | if (!vg || !vg->num_vlans) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 574 | return false; |
| 575 | |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 576 | if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto) |
| 577 | *vid = 0; |
| 578 | |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 579 | if (!*vid) { |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 580 | *vid = br_get_pvid(vg); |
Vlad Yasevich | 3df6bf4 | 2014-10-03 11:29:17 -0400 | [diff] [blame] | 581 | if (!*vid) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 582 | return false; |
| 583 | |
| 584 | return true; |
| 585 | } |
| 586 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 587 | if (br_vlan_find(vg, *vid)) |
Toshiaki Makita | e0d7968 | 2014-05-26 15:15:53 +0900 | [diff] [blame] | 588 | return true; |
| 589 | |
| 590 | return false; |
| 591 | } |
| 592 | |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 593 | static int br_vlan_add_existing(struct net_bridge *br, |
| 594 | struct net_bridge_vlan_group *vg, |
| 595 | struct net_bridge_vlan *vlan, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 596 | u16 flags, bool *changed, |
| 597 | struct netlink_ext_ack *extack) |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 598 | { |
| 599 | int err; |
| 600 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 601 | err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags, extack); |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 602 | if (err && err != -EOPNOTSUPP) |
| 603 | return err; |
| 604 | |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 605 | if (!br_vlan_is_brentry(vlan)) { |
| 606 | /* Trying to change flags of non-existent bridge vlan */ |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 607 | if (!(flags & BRIDGE_VLAN_INFO_BRENTRY)) { |
| 608 | err = -EINVAL; |
| 609 | goto err_flags; |
| 610 | } |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 611 | /* It was only kept for port vlans, now make it real */ |
| 612 | err = br_fdb_insert(br, NULL, br->dev->dev_addr, |
| 613 | vlan->vid); |
| 614 | if (err) { |
| 615 | br_err(br, "failed to insert local address into bridge forwarding table\n"); |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 616 | goto err_fdb_insert; |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | refcount_inc(&vlan->refcnt); |
| 620 | vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY; |
| 621 | vg->num_vlans++; |
| 622 | *changed = true; |
| 623 | } |
| 624 | |
| 625 | if (__vlan_add_flags(vlan, flags)) |
| 626 | *changed = true; |
| 627 | |
| 628 | return 0; |
Petr Machata | 9c86ce2 | 2018-05-30 03:00:45 +0200 | [diff] [blame] | 629 | |
| 630 | err_fdb_insert: |
| 631 | err_flags: |
| 632 | br_switchdev_port_vlan_del(br->dev, vlan->vid); |
| 633 | return err; |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 634 | } |
| 635 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 636 | /* Must be protected by RTNL. |
| 637 | * Must be called with vid in range from 1 to 4094 inclusive. |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 638 | * changed must be true only if the vlan was created or updated |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 639 | */ |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 640 | int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, bool *changed, |
| 641 | struct netlink_ext_ack *extack) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 642 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 643 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 644 | struct net_bridge_vlan *vlan; |
| 645 | int ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 646 | |
| 647 | ASSERT_RTNL(); |
| 648 | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 649 | *changed = false; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 650 | vg = br_vlan_group(br); |
| 651 | vlan = br_vlan_find(vg, vid); |
Petr Machata | dbd6dc7 | 2018-05-30 02:56:55 +0200 | [diff] [blame] | 652 | if (vlan) |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 653 | return br_vlan_add_existing(br, vg, vlan, flags, changed, |
| 654 | extack); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 655 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 656 | vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); |
| 657 | if (!vlan) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 658 | return -ENOMEM; |
| 659 | |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 660 | vlan->stats = netdev_alloc_pcpu_stats(struct br_vlan_stats); |
| 661 | if (!vlan->stats) { |
| 662 | kfree(vlan); |
| 663 | return -ENOMEM; |
| 664 | } |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 665 | vlan->vid = vid; |
| 666 | vlan->flags = flags | BRIDGE_VLAN_INFO_MASTER; |
| 667 | vlan->flags &= ~BRIDGE_VLAN_INFO_PVID; |
| 668 | vlan->br = br; |
| 669 | if (flags & BRIDGE_VLAN_INFO_BRENTRY) |
Reshetova, Elena | 2512775 | 2017-07-04 15:53:05 +0300 | [diff] [blame] | 670 | refcount_set(&vlan->refcnt, 1); |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 671 | ret = __vlan_add(vlan, flags, extack); |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 672 | if (ret) { |
| 673 | free_percpu(vlan->stats); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 674 | kfree(vlan); |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 675 | } else { |
| 676 | *changed = true; |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 677 | } |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 678 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 679 | return ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 682 | /* Must be protected by RTNL. |
| 683 | * Must be called with vid in range from 1 to 4094 inclusive. |
| 684 | */ |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 685 | int br_vlan_delete(struct net_bridge *br, u16 vid) |
| 686 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 687 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 688 | struct net_bridge_vlan *v; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 689 | |
| 690 | ASSERT_RTNL(); |
| 691 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 692 | vg = br_vlan_group(br); |
| 693 | v = br_vlan_find(vg, vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 694 | if (!v || !br_vlan_is_brentry(v)) |
| 695 | return -ENOENT; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 696 | |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame] | 697 | br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid); |
Roopa Prabhu | 3741873 | 2015-10-08 10:38:52 -0700 | [diff] [blame] | 698 | br_fdb_delete_by_port(br, NULL, vid, 0); |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 699 | |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 700 | vlan_tunnel_info_del(vg, v); |
| 701 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 702 | return __vlan_del(v); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | void br_vlan_flush(struct net_bridge *br) |
| 706 | { |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 707 | struct net_bridge_vlan_group *vg; |
| 708 | |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 709 | ASSERT_RTNL(); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 710 | |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 711 | vg = br_vlan_group(br); |
| 712 | __vlan_flush(vg); |
| 713 | RCU_INIT_POINTER(br->vlgrp, NULL); |
| 714 | synchronize_rcu(); |
| 715 | __vlan_group_free(vg); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 718 | 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] | 719 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 720 | if (!vg) |
| 721 | return NULL; |
Toshiaki Makita | 2b292fb | 2014-02-07 16:48:22 +0900 | [diff] [blame] | 722 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 723 | return br_vlan_lookup(&vg->vlan_hash, vid); |
Toshiaki Makita | 2b292fb | 2014-02-07 16:48:22 +0900 | [diff] [blame] | 724 | } |
| 725 | |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 726 | /* Must be protected by RTNL. */ |
| 727 | static void recalculate_group_addr(struct net_bridge *br) |
| 728 | { |
Nikolay Aleksandrov | be3664a | 2018-09-26 17:01:02 +0300 | [diff] [blame] | 729 | if (br_opt_get(br, BROPT_GROUP_ADDR_SET)) |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 730 | return; |
| 731 | |
| 732 | spin_lock_bh(&br->lock); |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 733 | if (!br_opt_get(br, BROPT_VLAN_ENABLED) || |
| 734 | br->vlan_proto == htons(ETH_P_8021Q)) { |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 735 | /* Bridge Group Address */ |
| 736 | br->group_addr[5] = 0x00; |
| 737 | } else { /* vlan_enabled && ETH_P_8021AD */ |
| 738 | /* Provider Bridge Group Address */ |
| 739 | br->group_addr[5] = 0x08; |
| 740 | } |
| 741 | spin_unlock_bh(&br->lock); |
| 742 | } |
| 743 | |
| 744 | /* Must be protected by RTNL. */ |
| 745 | void br_recalculate_fwd_mask(struct net_bridge *br) |
| 746 | { |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 747 | if (!br_opt_get(br, BROPT_VLAN_ENABLED) || |
| 748 | br->vlan_proto == htons(ETH_P_8021Q)) |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 749 | br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT; |
| 750 | else /* vlan_enabled && ETH_P_8021AD */ |
| 751 | br->group_fwd_mask_required = BR_GROUPFWD_8021AD & |
| 752 | ~(1u << br->group_addr[5]); |
| 753 | } |
| 754 | |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 755 | int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 756 | { |
Elad Raz | 6b72a77 | 2016-01-06 13:01:06 +0100 | [diff] [blame] | 757 | struct switchdev_attr attr = { |
| 758 | .orig_dev = br->dev, |
| 759 | .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, |
| 760 | .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP, |
| 761 | .u.vlan_filtering = val, |
| 762 | }; |
| 763 | int err; |
| 764 | |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 765 | if (br_opt_get(br, BROPT_VLAN_ENABLED) == !!val) |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 766 | return 0; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 767 | |
Elad Raz | 6b72a77 | 2016-01-06 13:01:06 +0100 | [diff] [blame] | 768 | err = switchdev_port_attr_set(br->dev, &attr); |
| 769 | if (err && err != -EOPNOTSUPP) |
| 770 | return err; |
| 771 | |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 772 | br_opt_toggle(br, BROPT_VLAN_ENABLED, !!val); |
Vlad Yasevich | 2796d0c | 2014-05-16 09:59:20 -0400 | [diff] [blame] | 773 | br_manage_promisc(br); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 774 | recalculate_group_addr(br); |
| 775 | br_recalculate_fwd_mask(br); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 776 | |
Nikolay Aleksandrov | a785403 | 2015-08-07 19:40:45 +0300 | [diff] [blame] | 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) |
| 781 | { |
Xin Long | 047831a | 2016-04-09 00:03:31 +0800 | [diff] [blame] | 782 | return __br_vlan_filter_toggle(br, val); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Ido Schimmel | 1f51445 | 2017-05-26 08:37:23 +0200 | [diff] [blame] | 785 | bool br_vlan_enabled(const struct net_device *dev) |
| 786 | { |
| 787 | struct net_bridge *br = netdev_priv(dev); |
| 788 | |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 789 | return br_opt_get(br, BROPT_VLAN_ENABLED); |
Ido Schimmel | 1f51445 | 2017-05-26 08:37:23 +0200 | [diff] [blame] | 790 | } |
| 791 | EXPORT_SYMBOL_GPL(br_vlan_enabled); |
| 792 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 793 | int __br_vlan_set_proto(struct net_bridge *br, __be16 proto) |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 794 | { |
| 795 | int err = 0; |
| 796 | struct net_bridge_port *p; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 797 | struct net_bridge_vlan *vlan; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 798 | struct net_bridge_vlan_group *vg; |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 799 | __be16 oldproto; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 800 | |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 801 | if (br->vlan_proto == proto) |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 802 | return 0; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 803 | |
| 804 | /* Add VLANs for the new proto to the device filter. */ |
| 805 | list_for_each_entry(p, &br->port_list, list) { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 806 | vg = nbp_vlan_group(p); |
| 807 | list_for_each_entry(vlan, &vg->vlan_list, vlist) { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 808 | err = vlan_vid_add(p->dev, proto, vlan->vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 809 | if (err) |
| 810 | goto err_filt; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | oldproto = br->vlan_proto; |
| 815 | br->vlan_proto = proto; |
| 816 | |
| 817 | recalculate_group_addr(br); |
| 818 | br_recalculate_fwd_mask(br); |
| 819 | |
| 820 | /* Delete VLANs for the old proto from the device filter. */ |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 821 | list_for_each_entry(p, &br->port_list, list) { |
| 822 | vg = nbp_vlan_group(p); |
| 823 | list_for_each_entry(vlan, &vg->vlan_list, vlist) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 824 | vlan_vid_del(p->dev, oldproto, vlan->vid); |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 825 | } |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 826 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 827 | return 0; |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 828 | |
| 829 | err_filt: |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 830 | list_for_each_entry_continue_reverse(vlan, &vg->vlan_list, vlist) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 831 | vlan_vid_del(p->dev, proto, vlan->vid); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 832 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 833 | list_for_each_entry_continue_reverse(p, &br->port_list, list) { |
| 834 | vg = nbp_vlan_group(p); |
| 835 | list_for_each_entry(vlan, &vg->vlan_list, vlist) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 836 | vlan_vid_del(p->dev, proto, vlan->vid); |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 837 | } |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 838 | |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 839 | return err; |
| 840 | } |
| 841 | |
| 842 | int br_vlan_set_proto(struct net_bridge *br, unsigned long val) |
| 843 | { |
Toshiaki Makita | d2d427b | 2015-08-27 15:32:26 +0900 | [diff] [blame] | 844 | if (val != ETH_P_8021Q && val != ETH_P_8021AD) |
| 845 | return -EPROTONOSUPPORT; |
| 846 | |
Xin Long | 047831a | 2016-04-09 00:03:31 +0800 | [diff] [blame] | 847 | return __br_vlan_set_proto(br, htons(val)); |
Toshiaki Makita | 204177f | 2014-06-10 20:59:25 +0900 | [diff] [blame] | 848 | } |
| 849 | |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 850 | int br_vlan_set_stats(struct net_bridge *br, unsigned long val) |
| 851 | { |
| 852 | switch (val) { |
| 853 | case 0: |
| 854 | case 1: |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 855 | br_opt_toggle(br, BROPT_VLAN_STATS_ENABLED, !!val); |
Nikolay Aleksandrov | 6dada9b | 2016-04-30 10:25:28 +0200 | [diff] [blame] | 856 | break; |
| 857 | default: |
| 858 | return -EINVAL; |
| 859 | } |
| 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
Nikolay Aleksandrov | 9163a0f | 2018-10-12 13:41:16 +0300 | [diff] [blame] | 864 | int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val) |
| 865 | { |
| 866 | struct net_bridge_port *p; |
| 867 | |
| 868 | /* allow to change the option if there are no port vlans configured */ |
| 869 | list_for_each_entry(p, &br->port_list, list) { |
| 870 | struct net_bridge_vlan_group *vg = nbp_vlan_group(p); |
| 871 | |
| 872 | if (vg->num_vlans) |
| 873 | return -EBUSY; |
| 874 | } |
| 875 | |
| 876 | switch (val) { |
| 877 | case 0: |
| 878 | case 1: |
| 879 | br_opt_toggle(br, BROPT_VLAN_STATS_PER_PORT, !!val); |
| 880 | break; |
| 881 | default: |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 888 | 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] | 889 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 890 | struct net_bridge_vlan *v; |
| 891 | |
Nikolay Aleksandrov | 77751ee | 2015-09-30 20:16:53 +0200 | [diff] [blame] | 892 | if (vid != vg->pvid) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 893 | return false; |
| 894 | |
| 895 | v = br_vlan_lookup(&vg->vlan_hash, vid); |
| 896 | if (v && br_vlan_should_use(v) && |
| 897 | (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)) |
| 898 | return true; |
| 899 | |
| 900 | return false; |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | static void br_vlan_disable_default_pvid(struct net_bridge *br) |
| 904 | { |
| 905 | struct net_bridge_port *p; |
| 906 | u16 pvid = br->default_pvid; |
| 907 | |
| 908 | /* Disable default_pvid on all ports where it is still |
| 909 | * configured. |
| 910 | */ |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 911 | if (vlan_default_pvid(br_vlan_group(br), pvid)) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 912 | br_vlan_delete(br, pvid); |
| 913 | |
| 914 | list_for_each_entry(p, &br->port_list, list) { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 915 | if (vlan_default_pvid(nbp_vlan_group(p), pvid)) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 916 | nbp_vlan_delete(p, pvid); |
| 917 | } |
| 918 | |
| 919 | br->default_pvid = 0; |
| 920 | } |
| 921 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 922 | int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid, |
| 923 | struct netlink_ext_ack *extack) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 924 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 925 | const struct net_bridge_vlan *pvent; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 926 | struct net_bridge_vlan_group *vg; |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 927 | struct net_bridge_port *p; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 928 | unsigned long *changed; |
| 929 | bool vlchange; |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 930 | u16 old_pvid; |
| 931 | int err = 0; |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 932 | |
Nikolay Aleksandrov | 0f963b7 | 2015-10-04 14:23:47 +0200 | [diff] [blame] | 933 | if (!pvid) { |
| 934 | br_vlan_disable_default_pvid(br); |
| 935 | return 0; |
| 936 | } |
| 937 | |
Andy Shevchenko | 459479d | 2018-08-30 13:33:18 +0300 | [diff] [blame] | 938 | changed = bitmap_zalloc(BR_MAX_PORTS, GFP_KERNEL); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 939 | if (!changed) |
| 940 | return -ENOMEM; |
| 941 | |
| 942 | old_pvid = br->default_pvid; |
| 943 | |
| 944 | /* Update default_pvid config only if we do not conflict with |
| 945 | * user configuration. |
| 946 | */ |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 947 | vg = br_vlan_group(br); |
| 948 | pvent = br_vlan_find(vg, pvid); |
| 949 | if ((!old_pvid || vlan_default_pvid(vg, old_pvid)) && |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 950 | (!pvent || !br_vlan_should_use(pvent))) { |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 951 | err = br_vlan_add(br, pvid, |
| 952 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 953 | BRIDGE_VLAN_INFO_UNTAGGED | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 954 | BRIDGE_VLAN_INFO_BRENTRY, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 955 | &vlchange, extack); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 956 | if (err) |
| 957 | goto out; |
| 958 | br_vlan_delete(br, old_pvid); |
| 959 | set_bit(0, changed); |
| 960 | } |
| 961 | |
| 962 | list_for_each_entry(p, &br->port_list, list) { |
| 963 | /* Update default_pvid config only if we do not conflict with |
| 964 | * user configuration. |
| 965 | */ |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 966 | vg = nbp_vlan_group(p); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 967 | if ((old_pvid && |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 968 | !vlan_default_pvid(vg, old_pvid)) || |
| 969 | br_vlan_find(vg, pvid)) |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 970 | continue; |
| 971 | |
| 972 | err = nbp_vlan_add(p, pvid, |
| 973 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 974 | BRIDGE_VLAN_INFO_UNTAGGED, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 975 | &vlchange, extack); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 976 | if (err) |
| 977 | goto err_port; |
| 978 | nbp_vlan_delete(p, old_pvid); |
| 979 | set_bit(p->port_no, changed); |
| 980 | } |
| 981 | |
| 982 | br->default_pvid = pvid; |
| 983 | |
| 984 | out: |
Andy Shevchenko | 459479d | 2018-08-30 13:33:18 +0300 | [diff] [blame] | 985 | bitmap_free(changed); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 986 | return err; |
| 987 | |
| 988 | err_port: |
| 989 | list_for_each_entry_continue_reverse(p, &br->port_list, list) { |
| 990 | if (!test_bit(p->port_no, changed)) |
| 991 | continue; |
| 992 | |
| 993 | if (old_pvid) |
| 994 | nbp_vlan_add(p, old_pvid, |
| 995 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 996 | BRIDGE_VLAN_INFO_UNTAGGED, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 997 | &vlchange, NULL); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 998 | nbp_vlan_delete(p, pvid); |
| 999 | } |
| 1000 | |
| 1001 | if (test_bit(0, changed)) { |
| 1002 | if (old_pvid) |
| 1003 | br_vlan_add(br, old_pvid, |
| 1004 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1005 | BRIDGE_VLAN_INFO_UNTAGGED | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1006 | BRIDGE_VLAN_INFO_BRENTRY, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1007 | &vlchange, NULL); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1008 | br_vlan_delete(br, pvid); |
| 1009 | } |
| 1010 | goto out; |
| 1011 | } |
| 1012 | |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1013 | int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val) |
| 1014 | { |
| 1015 | u16 pvid = val; |
| 1016 | int err = 0; |
| 1017 | |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1018 | if (val >= VLAN_VID_MASK) |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1019 | return -EINVAL; |
| 1020 | |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1021 | if (pvid == br->default_pvid) |
Xin Long | 047831a | 2016-04-09 00:03:31 +0800 | [diff] [blame] | 1022 | goto out; |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1023 | |
| 1024 | /* Only allow default pvid change when filtering is disabled */ |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 1025 | if (br_opt_get(br, BROPT_VLAN_ENABLED)) { |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1026 | pr_info_once("Please disable vlan filtering to change default_pvid\n"); |
| 1027 | err = -EPERM; |
Xin Long | 047831a | 2016-04-09 00:03:31 +0800 | [diff] [blame] | 1028 | goto out; |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1029 | } |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1030 | err = __br_vlan_set_default_pvid(br, pvid, NULL); |
Xin Long | 047831a | 2016-04-09 00:03:31 +0800 | [diff] [blame] | 1031 | out: |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1032 | return err; |
| 1033 | } |
| 1034 | |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1035 | int br_vlan_init(struct net_bridge *br) |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 1036 | { |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1037 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1038 | int ret = -ENOMEM; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1039 | bool changed; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1040 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1041 | vg = kzalloc(sizeof(*vg), GFP_KERNEL); |
| 1042 | if (!vg) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1043 | goto out; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1044 | ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1045 | if (ret) |
| 1046 | goto err_rhtbl; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 1047 | ret = vlan_tunnel_init(vg); |
| 1048 | if (ret) |
| 1049 | goto err_tunnel_init; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1050 | INIT_LIST_HEAD(&vg->vlan_list); |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 1051 | br->vlan_proto = htons(ETH_P_8021Q); |
Vlad Yasevich | 96a20d9 | 2014-10-03 11:29:16 -0400 | [diff] [blame] | 1052 | br->default_pvid = 1; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1053 | rcu_assign_pointer(br->vlgrp, vg); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1054 | ret = br_vlan_add(br, 1, |
| 1055 | BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1056 | BRIDGE_VLAN_INFO_BRENTRY, &changed, NULL); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1057 | if (ret) |
| 1058 | goto err_vlan_add; |
| 1059 | |
| 1060 | out: |
| 1061 | return ret; |
| 1062 | |
| 1063 | err_vlan_add: |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 1064 | vlan_tunnel_deinit(vg); |
| 1065 | err_tunnel_init: |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1066 | rhashtable_destroy(&vg->vlan_hash); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1067 | err_rhtbl: |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1068 | kfree(vg); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1069 | |
| 1070 | goto out; |
| 1071 | } |
| 1072 | |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1073 | int nbp_vlan_init(struct net_bridge_port *p, struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1074 | { |
Elad Raz | 404cdbf | 2016-01-06 13:01:07 +0100 | [diff] [blame] | 1075 | struct switchdev_attr attr = { |
| 1076 | .orig_dev = p->br->dev, |
| 1077 | .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, |
| 1078 | .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP, |
Nikolay Aleksandrov | ae75767 | 2018-09-26 17:01:00 +0300 | [diff] [blame] | 1079 | .u.vlan_filtering = br_opt_get(p->br, BROPT_VLAN_ENABLED), |
Elad Raz | 404cdbf | 2016-01-06 13:01:07 +0100 | [diff] [blame] | 1080 | }; |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 1081 | struct net_bridge_vlan_group *vg; |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1082 | int ret = -ENOMEM; |
| 1083 | |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 1084 | vg = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL); |
| 1085 | if (!vg) |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1086 | goto out; |
| 1087 | |
Elad Raz | 404cdbf | 2016-01-06 13:01:07 +0100 | [diff] [blame] | 1088 | ret = switchdev_port_attr_set(p->dev, &attr); |
| 1089 | if (ret && ret != -EOPNOTSUPP) |
| 1090 | goto err_vlan_enabled; |
| 1091 | |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 1092 | ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1093 | if (ret) |
| 1094 | goto err_rhtbl; |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 1095 | ret = vlan_tunnel_init(vg); |
| 1096 | if (ret) |
| 1097 | goto err_tunnel_init; |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 1098 | INIT_LIST_HEAD(&vg->vlan_list); |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1099 | rcu_assign_pointer(p->vlgrp, vg); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1100 | if (p->br->default_pvid) { |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1101 | bool changed; |
| 1102 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1103 | ret = nbp_vlan_add(p, p->br->default_pvid, |
| 1104 | BRIDGE_VLAN_INFO_PVID | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1105 | BRIDGE_VLAN_INFO_UNTAGGED, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1106 | &changed, extack); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1107 | if (ret) |
| 1108 | goto err_vlan_add; |
| 1109 | } |
| 1110 | out: |
| 1111 | return ret; |
| 1112 | |
| 1113 | err_vlan_add: |
Ido Schimmel | 07bc588 | 2015-10-30 17:46:19 +0100 | [diff] [blame] | 1114 | RCU_INIT_POINTER(p->vlgrp, NULL); |
| 1115 | synchronize_rcu(); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 1116 | vlan_tunnel_deinit(vg); |
Roopa Prabhu | efa5356 | 2017-01-31 22:59:54 -0800 | [diff] [blame] | 1117 | err_tunnel_init: |
| 1118 | rhashtable_destroy(&vg->vlan_hash); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1119 | err_rhtbl: |
Yotam Gigi | df2c433 | 2017-03-01 16:50:45 +0200 | [diff] [blame] | 1120 | err_vlan_enabled: |
Nikolay Aleksandrov | 263344e | 2015-09-30 20:16:54 +0200 | [diff] [blame] | 1121 | kfree(vg); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1122 | |
| 1123 | goto out; |
Toshiaki Makita | 8580e21 | 2014-06-10 20:59:23 +0900 | [diff] [blame] | 1124 | } |
| 1125 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 1126 | /* Must be protected by RTNL. |
| 1127 | * Must be called with vid in range from 1 to 4094 inclusive. |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1128 | * changed must be true only if the vlan was created or updated |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 1129 | */ |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1130 | int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1131 | bool *changed, struct netlink_ext_ack *extack) |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1132 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1133 | struct net_bridge_vlan *vlan; |
| 1134 | int ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1135 | |
| 1136 | ASSERT_RTNL(); |
| 1137 | |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1138 | *changed = false; |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1139 | vlan = br_vlan_find(nbp_vlan_group(port), vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1140 | if (vlan) { |
Ido Schimmel | 7fbac98 | 2016-02-18 14:01:46 +0100 | [diff] [blame] | 1141 | /* Pass the flags to the hardware bridge */ |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1142 | ret = br_switchdev_port_vlan_add(port->dev, vid, flags, extack); |
Ido Schimmel | 7fbac98 | 2016-02-18 14:01:46 +0100 | [diff] [blame] | 1143 | if (ret && ret != -EOPNOTSUPP) |
| 1144 | return ret; |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1145 | *changed = __vlan_add_flags(vlan, flags); |
| 1146 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1147 | return 0; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1150 | vlan = kzalloc(sizeof(*vlan), GFP_KERNEL); |
| 1151 | if (!vlan) |
| 1152 | return -ENOMEM; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1153 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1154 | vlan->vid = vid; |
| 1155 | vlan->port = port; |
Petr Machata | 169327d | 2018-12-12 17:02:50 +0000 | [diff] [blame] | 1156 | ret = __vlan_add(vlan, flags, extack); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1157 | if (ret) |
| 1158 | kfree(vlan); |
Nikolay Aleksandrov | f418af6 | 2017-10-27 13:19:37 +0300 | [diff] [blame] | 1159 | else |
| 1160 | *changed = true; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1161 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1162 | return ret; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Toshiaki Makita | 8adff41 | 2013-10-16 17:07:13 +0900 | [diff] [blame] | 1165 | /* Must be protected by RTNL. |
| 1166 | * Must be called with vid in range from 1 to 4094 inclusive. |
| 1167 | */ |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1168 | int nbp_vlan_delete(struct net_bridge_port *port, u16 vid) |
| 1169 | { |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1170 | struct net_bridge_vlan *v; |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1171 | |
| 1172 | ASSERT_RTNL(); |
| 1173 | |
Nikolay Aleksandrov | 907b1e6 | 2015-10-12 21:47:02 +0200 | [diff] [blame] | 1174 | v = br_vlan_find(nbp_vlan_group(port), vid); |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1175 | if (!v) |
| 1176 | return -ENOENT; |
Toshiaki Makita | 424bb9c | 2014-02-07 16:48:25 +0900 | [diff] [blame] | 1177 | 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] | 1178 | br_fdb_delete_by_port(port->br, port, vid, 0); |
Vlad Yasevich | bc9a25d | 2013-02-13 12:00:19 +0000 | [diff] [blame] | 1179 | |
Nikolay Aleksandrov | 2594e906 | 2015-09-25 19:00:11 +0200 | [diff] [blame] | 1180 | return __vlan_del(v); |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | void nbp_vlan_flush(struct net_bridge_port *port) |
| 1184 | { |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 1185 | struct net_bridge_vlan_group *vg; |
| 1186 | |
Vlad Yasevich | 243a2e6 | 2013-02-13 12:00:09 +0000 | [diff] [blame] | 1187 | ASSERT_RTNL(); |
| 1188 | |
Nikolay Aleksandrov | f409d0e | 2015-10-12 21:47:05 +0200 | [diff] [blame] | 1189 | vg = nbp_vlan_group(port); |
| 1190 | __vlan_flush(vg); |
| 1191 | RCU_INIT_POINTER(port->vlgrp, NULL); |
| 1192 | synchronize_rcu(); |
| 1193 | __vlan_group_free(vg); |
Vlad Yasevich | 5be5a2d | 2014-10-03 11:29:18 -0400 | [diff] [blame] | 1194 | } |
Nikolay Aleksandrov | a60c090 | 2016-04-30 10:25:29 +0200 | [diff] [blame] | 1195 | |
| 1196 | void br_vlan_get_stats(const struct net_bridge_vlan *v, |
| 1197 | struct br_vlan_stats *stats) |
| 1198 | { |
| 1199 | int i; |
| 1200 | |
| 1201 | memset(stats, 0, sizeof(*stats)); |
| 1202 | for_each_possible_cpu(i) { |
| 1203 | u64 rxpackets, rxbytes, txpackets, txbytes; |
| 1204 | struct br_vlan_stats *cpu_stats; |
| 1205 | unsigned int start; |
| 1206 | |
| 1207 | cpu_stats = per_cpu_ptr(v->stats, i); |
| 1208 | do { |
| 1209 | start = u64_stats_fetch_begin_irq(&cpu_stats->syncp); |
| 1210 | rxpackets = cpu_stats->rx_packets; |
| 1211 | rxbytes = cpu_stats->rx_bytes; |
| 1212 | txbytes = cpu_stats->tx_bytes; |
| 1213 | txpackets = cpu_stats->tx_packets; |
| 1214 | } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start)); |
| 1215 | |
| 1216 | stats->rx_packets += rxpackets; |
| 1217 | stats->rx_bytes += rxbytes; |
| 1218 | stats->tx_bytes += txbytes; |
| 1219 | stats->tx_packets += txpackets; |
| 1220 | } |
| 1221 | } |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 1222 | |
| 1223 | int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid) |
| 1224 | { |
| 1225 | struct net_bridge_vlan_group *vg; |
Ido Schimmel | 5a6db04 | 2018-11-28 20:06:58 +0000 | [diff] [blame] | 1226 | struct net_bridge_port *p; |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 1227 | |
| 1228 | ASSERT_RTNL(); |
Ido Schimmel | 5a6db04 | 2018-11-28 20:06:58 +0000 | [diff] [blame] | 1229 | p = br_port_get_check_rtnl(dev); |
| 1230 | if (p) |
| 1231 | vg = nbp_vlan_group(p); |
| 1232 | else if (netif_is_bridge_master(dev)) |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 1233 | vg = br_vlan_group(netdev_priv(dev)); |
| 1234 | else |
| 1235 | return -EINVAL; |
| 1236 | |
| 1237 | *p_pvid = br_get_pvid(vg); |
| 1238 | return 0; |
| 1239 | } |
| 1240 | EXPORT_SYMBOL_GPL(br_vlan_get_pvid); |
| 1241 | |
| 1242 | int br_vlan_get_info(const struct net_device *dev, u16 vid, |
| 1243 | struct bridge_vlan_info *p_vinfo) |
| 1244 | { |
| 1245 | struct net_bridge_vlan_group *vg; |
| 1246 | struct net_bridge_vlan *v; |
| 1247 | struct net_bridge_port *p; |
| 1248 | |
| 1249 | ASSERT_RTNL(); |
| 1250 | p = br_port_get_check_rtnl(dev); |
| 1251 | if (p) |
| 1252 | vg = nbp_vlan_group(p); |
Petr Machata | 2b18d79 | 2018-05-10 13:13:03 +0300 | [diff] [blame] | 1253 | else if (netif_is_bridge_master(dev)) |
| 1254 | vg = br_vlan_group(netdev_priv(dev)); |
Petr Machata | 4d4fd36 | 2018-04-29 10:56:08 +0300 | [diff] [blame] | 1255 | else |
| 1256 | return -EINVAL; |
| 1257 | |
| 1258 | v = br_vlan_find(vg, vid); |
| 1259 | if (!v) |
| 1260 | return -ENOENT; |
| 1261 | |
| 1262 | p_vinfo->vid = vid; |
| 1263 | p_vinfo->flags = v->flags; |
| 1264 | return 0; |
| 1265 | } |
| 1266 | EXPORT_SYMBOL_GPL(br_vlan_get_info); |
Mike Manning | 9c0ec2e | 2019-04-18 18:35:33 +0100 | [diff] [blame^] | 1267 | |
| 1268 | static int br_vlan_is_bind_vlan_dev(const struct net_device *dev) |
| 1269 | { |
| 1270 | return is_vlan_dev(dev) && |
| 1271 | !!(vlan_dev_priv(dev)->flags & VLAN_FLAG_BRIDGE_BINDING); |
| 1272 | } |
| 1273 | |
| 1274 | static int br_vlan_is_bind_vlan_dev_fn(struct net_device *dev, |
| 1275 | __always_unused void *data) |
| 1276 | { |
| 1277 | return br_vlan_is_bind_vlan_dev(dev); |
| 1278 | } |
| 1279 | |
| 1280 | static bool br_vlan_has_upper_bind_vlan_dev(struct net_device *dev) |
| 1281 | { |
| 1282 | int found; |
| 1283 | |
| 1284 | rcu_read_lock(); |
| 1285 | found = netdev_walk_all_upper_dev_rcu(dev, br_vlan_is_bind_vlan_dev_fn, |
| 1286 | NULL); |
| 1287 | rcu_read_unlock(); |
| 1288 | |
| 1289 | return !!found; |
| 1290 | } |
| 1291 | |
| 1292 | struct br_vlan_bind_walk_data { |
| 1293 | u16 vid; |
| 1294 | struct net_device *result; |
| 1295 | }; |
| 1296 | |
| 1297 | static int br_vlan_match_bind_vlan_dev_fn(struct net_device *dev, |
| 1298 | void *data_in) |
| 1299 | { |
| 1300 | struct br_vlan_bind_walk_data *data = data_in; |
| 1301 | int found = 0; |
| 1302 | |
| 1303 | if (br_vlan_is_bind_vlan_dev(dev) && |
| 1304 | vlan_dev_priv(dev)->vlan_id == data->vid) { |
| 1305 | data->result = dev; |
| 1306 | found = 1; |
| 1307 | } |
| 1308 | |
| 1309 | return found; |
| 1310 | } |
| 1311 | |
| 1312 | static struct net_device * |
| 1313 | br_vlan_get_upper_bind_vlan_dev(struct net_device *dev, u16 vid) |
| 1314 | { |
| 1315 | struct br_vlan_bind_walk_data data = { |
| 1316 | .vid = vid, |
| 1317 | }; |
| 1318 | |
| 1319 | rcu_read_lock(); |
| 1320 | netdev_walk_all_upper_dev_rcu(dev, br_vlan_match_bind_vlan_dev_fn, |
| 1321 | &data); |
| 1322 | rcu_read_unlock(); |
| 1323 | |
| 1324 | return data.result; |
| 1325 | } |
| 1326 | |
| 1327 | static bool br_vlan_is_dev_up(const struct net_device *dev) |
| 1328 | { |
| 1329 | return !!(dev->flags & IFF_UP) && netif_oper_up(dev); |
| 1330 | } |
| 1331 | |
| 1332 | static void br_vlan_set_vlan_dev_state(const struct net_bridge *br, |
| 1333 | struct net_device *vlan_dev) |
| 1334 | { |
| 1335 | u16 vid = vlan_dev_priv(vlan_dev)->vlan_id; |
| 1336 | struct net_bridge_vlan_group *vg; |
| 1337 | struct net_bridge_port *p; |
| 1338 | bool has_carrier = false; |
| 1339 | |
| 1340 | list_for_each_entry(p, &br->port_list, list) { |
| 1341 | vg = nbp_vlan_group(p); |
| 1342 | if (br_vlan_find(vg, vid) && br_vlan_is_dev_up(p->dev)) { |
| 1343 | has_carrier = true; |
| 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (has_carrier) |
| 1349 | netif_carrier_on(vlan_dev); |
| 1350 | else |
| 1351 | netif_carrier_off(vlan_dev); |
| 1352 | } |
| 1353 | |
| 1354 | static void br_vlan_set_all_vlan_dev_state(struct net_bridge_port *p) |
| 1355 | { |
| 1356 | struct net_bridge_vlan_group *vg = nbp_vlan_group(p); |
| 1357 | struct net_bridge_vlan *vlan; |
| 1358 | struct net_device *vlan_dev; |
| 1359 | |
| 1360 | list_for_each_entry(vlan, &vg->vlan_list, vlist) { |
| 1361 | vlan_dev = br_vlan_get_upper_bind_vlan_dev(p->br->dev, |
| 1362 | vlan->vid); |
| 1363 | if (vlan_dev) { |
| 1364 | if (br_vlan_is_dev_up(p->dev)) |
| 1365 | netif_carrier_on(vlan_dev); |
| 1366 | else |
| 1367 | br_vlan_set_vlan_dev_state(p->br, vlan_dev); |
| 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | static void br_vlan_upper_change(struct net_device *dev, |
| 1373 | struct net_device *upper_dev, |
| 1374 | bool linking) |
| 1375 | { |
| 1376 | struct net_bridge *br = netdev_priv(dev); |
| 1377 | |
| 1378 | if (!br_vlan_is_bind_vlan_dev(upper_dev)) |
| 1379 | return; |
| 1380 | |
| 1381 | if (linking) { |
| 1382 | br_vlan_set_vlan_dev_state(br, upper_dev); |
| 1383 | br_opt_toggle(br, BROPT_VLAN_BRIDGE_BINDING, true); |
| 1384 | } else { |
| 1385 | br_opt_toggle(br, BROPT_VLAN_BRIDGE_BINDING, |
| 1386 | br_vlan_has_upper_bind_vlan_dev(dev)); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | /* Must be protected by RTNL. */ |
| 1391 | void br_vlan_bridge_event(struct net_device *dev, unsigned long event, |
| 1392 | void *ptr) |
| 1393 | { |
| 1394 | struct netdev_notifier_changeupper_info *info; |
| 1395 | |
| 1396 | switch (event) { |
| 1397 | case NETDEV_CHANGEUPPER: |
| 1398 | info = ptr; |
| 1399 | br_vlan_upper_change(dev, info->upper_dev, info->linking); |
| 1400 | break; |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | /* Must be protected by RTNL. */ |
| 1405 | void br_vlan_port_event(struct net_bridge_port *p, unsigned long event) |
| 1406 | { |
| 1407 | if (!br_opt_get(p->br, BROPT_VLAN_BRIDGE_BINDING)) |
| 1408 | return; |
| 1409 | |
| 1410 | switch (event) { |
| 1411 | case NETDEV_CHANGE: |
| 1412 | case NETDEV_DOWN: |
| 1413 | case NETDEV_UP: |
| 1414 | br_vlan_set_all_vlan_dev_state(p); |
| 1415 | break; |
| 1416 | } |
| 1417 | } |