^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <net/switchdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "br_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "br_private_tunnel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) static void nbp_vlan_set_vlan_dev_state(struct net_bridge_port *p, u16 vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) const void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) const struct net_bridge_vlan *vle = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) u16 vid = *(u16 *)arg->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return vle->vid != vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static const struct rhashtable_params br_vlan_rht_params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .head_offset = offsetof(struct net_bridge_vlan, vnode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .key_offset = offsetof(struct net_bridge_vlan, vid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .key_len = sizeof(u16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .nelem_hint = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) .max_size = VLAN_N_VID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .obj_cmpfn = br_vlan_cmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) .automatic_shrinking = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static struct net_bridge_vlan *br_vlan_lookup(struct rhashtable *tbl, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) return rhashtable_lookup_fast(tbl, &vid, br_vlan_rht_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static bool __vlan_add_pvid(struct net_bridge_vlan_group *vg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) const struct net_bridge_vlan *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (vg->pvid == v->vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) br_vlan_set_pvid_state(vg, v->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) vg->pvid = v->vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static bool __vlan_delete_pvid(struct net_bridge_vlan_group *vg, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (vg->pvid != vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) vg->pvid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) /* return true if anything changed, false otherwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u16 old_flags = v->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (br_vlan_is_master(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) vg = br_vlan_group(v->br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) vg = nbp_vlan_group(v->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (flags & BRIDGE_VLAN_INFO_PVID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ret = __vlan_add_pvid(vg, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ret = __vlan_delete_pvid(vg, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) v->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) v->flags &= ~BRIDGE_VLAN_INFO_UNTAGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return ret || !!(old_flags ^ v->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct net_bridge_vlan *v, u16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* Try switchdev op first. In case it is not supported, fallback to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * 8021q add.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (err == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return vlan_vid_add(dev, br->vlan_proto, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) v->priv_flags |= BR_VLFLAG_ADDED_BY_SWITCHDEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static void __vlan_add_list(struct net_bridge_vlan *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct list_head *headp, *hpos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct net_bridge_vlan *vent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (br_vlan_is_master(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) vg = br_vlan_group(v->br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) vg = nbp_vlan_group(v->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) headp = &vg->vlan_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) list_for_each_prev(hpos, headp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) vent = list_entry(hpos, struct net_bridge_vlan, vlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (v->vid < vent->vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) list_add_rcu(&v->vlist, hpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void __vlan_del_list(struct net_bridge_vlan *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) list_del_rcu(&v->vlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) const struct net_bridge_vlan *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Try switchdev op first. In case it is not supported, fallback to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * 8021q del.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) err = br_switchdev_port_vlan_del(dev, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!(v->priv_flags & BR_VLFLAG_ADDED_BY_SWITCHDEV))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) vlan_vid_del(dev, br->vlan_proto, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return err == -EOPNOTSUPP ? 0 : err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) /* Returns a master vlan, if it didn't exist it gets created. In all cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * a reference is taken to the master vlan before returning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static struct net_bridge_vlan *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) br_vlan_get_master(struct net_bridge *br, u16 vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct net_bridge_vlan *masterv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) masterv = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!masterv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* missing global ctx, create it now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (br_vlan_add(br, vid, 0, &changed, extack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) masterv = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (WARN_ON(!masterv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) refcount_set(&masterv->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return masterv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) refcount_inc(&masterv->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return masterv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static void br_master_vlan_rcu_free(struct rcu_head *rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) v = container_of(rcu, struct net_bridge_vlan, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) WARN_ON(!br_vlan_is_master(v));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) free_percpu(v->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) v->stats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) kfree(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void br_vlan_put_master(struct net_bridge_vlan *masterv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (!br_vlan_is_master(masterv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) vg = br_vlan_group(masterv->br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (refcount_dec_and_test(&masterv->refcnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) rhashtable_remove_fast(&vg->vlan_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) &masterv->vnode, br_vlan_rht_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) __vlan_del_list(masterv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) call_rcu(&masterv->rcu, br_master_vlan_rcu_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void nbp_vlan_rcu_free(struct rcu_head *rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) v = container_of(rcu, struct net_bridge_vlan, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) WARN_ON(br_vlan_is_master(v));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* if we had per-port stats configured then free them here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (v->priv_flags & BR_VLFLAG_PER_PORT_STATS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) free_percpu(v->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) v->stats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) kfree(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* This is the shared VLAN add function which works for both ports and bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * devices. There are four possible calls to this function in terms of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * vlan entry type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * 1. vlan is being added on a port (no master flags, global entry exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * 2. vlan is being added on a bridge (both master and brentry flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * 3. vlan is being added on a port, but a global entry didn't exist which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * is being created right now (master flag set, brentry flag unset), the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * global entry is used for global per-vlan features, but not for filtering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * 4. same as 3 but with both master and brentry flags set so the entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * will be used for filtering in both the port and the bridge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int __vlan_add(struct net_bridge_vlan *v, u16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct net_bridge_vlan *masterv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct net_bridge_port *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct net_bridge *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (br_vlan_is_master(v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) br = v->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) dev = br->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) p = v->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) br = p->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) dev = p->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /* Add VLAN to the device filter if it is supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * This ensures tagged traffic enters the bridge when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * promiscuous mode is disabled by br_manage_promisc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) err = __vlan_vid_add(dev, br, v, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* need to work on the master vlan too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (flags & BRIDGE_VLAN_INFO_MASTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) err = br_vlan_add(br, v->vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) flags | BRIDGE_VLAN_INFO_BRENTRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) &changed, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) goto out_filt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) br_vlan_notify(br, NULL, v->vid, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) masterv = br_vlan_get_master(br, v->vid, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (!masterv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) goto out_filt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) v->brvlan = masterv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (br_opt_get(br, BROPT_VLAN_STATS_PER_PORT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) v->stats = netdev_alloc_pcpu_stats(struct br_vlan_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!v->stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) goto out_filt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) v->priv_flags |= BR_VLFLAG_PER_PORT_STATS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) v->stats = masterv->stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (err && err != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* Add the dev mac and count the vlan only if it's usable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (br_vlan_should_use(v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) err = br_fdb_insert(br, p, dev->dev_addr, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) br_err(br, "failed insert local address into bridge forwarding table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) goto out_filt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) vg->num_vlans++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* set the state before publishing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) v->state = BR_STATE_FORWARDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) err = rhashtable_lookup_insert_fast(&vg->vlan_hash, &v->vnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) br_vlan_rht_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) goto out_fdb_insert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) __vlan_add_list(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) __vlan_add_flags(v, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) nbp_vlan_set_vlan_dev_state(p, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) out_fdb_insert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (br_vlan_should_use(v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) br_fdb_find_delete_local(br, p, dev->dev_addr, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) vg->num_vlans--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) out_filt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) __vlan_vid_del(dev, br, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (masterv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (v->stats && masterv->stats != v->stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) free_percpu(v->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) v->stats = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) br_vlan_put_master(masterv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) v->brvlan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) br_switchdev_port_vlan_del(dev, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static int __vlan_del(struct net_bridge_vlan *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct net_bridge_vlan *masterv = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct net_bridge_port *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (br_vlan_is_master(v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) vg = br_vlan_group(v->br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) p = v->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) vg = nbp_vlan_group(v->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) masterv = v->brvlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) __vlan_delete_pvid(vg, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) err = __vlan_vid_del(p->dev, p->br, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) err = br_switchdev_port_vlan_del(v->br->dev, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (err && err != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (br_vlan_should_use(v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) vg->num_vlans--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (masterv != v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) vlan_tunnel_info_del(vg, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) rhashtable_remove_fast(&vg->vlan_hash, &v->vnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) br_vlan_rht_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) __vlan_del_list(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) nbp_vlan_set_vlan_dev_state(p, v->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) call_rcu(&v->rcu, nbp_vlan_rcu_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) br_vlan_put_master(masterv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static void __vlan_group_free(struct net_bridge_vlan_group *vg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) WARN_ON(!list_empty(&vg->vlan_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) rhashtable_destroy(&vg->vlan_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) vlan_tunnel_deinit(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) kfree(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static void __vlan_flush(const struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) const struct net_bridge_port *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct net_bridge_vlan_group *vg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct net_bridge_vlan *vlan, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) u16 v_start = 0, v_end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) __vlan_delete_pvid(vg, vg->pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) list_for_each_entry_safe(vlan, tmp, &vg->vlan_list, vlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* take care of disjoint ranges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!v_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) v_start = vlan->vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) } else if (vlan->vid - v_end != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* found range end, notify and start next one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) br_vlan_notify(br, p, v_start, v_end, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) v_start = vlan->vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) v_end = vlan->vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) __vlan_del(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /* notify about the last/whole vlan range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (v_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) br_vlan_notify(br, p, v_start, v_end, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct sk_buff *br_handle_vlan(struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) const struct net_bridge_port *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct net_bridge_vlan_group *vg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) struct br_vlan_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) u16 vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* If this packet was not filtered at input, let it pass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /* At this point, we know that the frame was filtered and contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * a valid vlan id. If the vlan id has untagged flag set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * send untagged; otherwise, send tagged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) br_vlan_get_tag(skb, &vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) v = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* Vlan entry must be configured at this point. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * only exception is the bridge is set in promisc mode and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * packet is destined for the bridge device. In this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * pass the packet as is.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (!v || !br_vlan_should_use(v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) stats = this_cpu_ptr(v->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) u64_stats_update_begin(&stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) stats->tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) stats->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) u64_stats_update_end(&stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) __vlan_hwaccel_clear_tag(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (p && (p->flags & BR_VLAN_TUNNEL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) br_handle_egress_vlan_tunnel(skb, v)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* Called under RCU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static bool __allowed_ingress(const struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct net_bridge_vlan_group *vg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct sk_buff *skb, u16 *vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) u8 *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct br_vlan_stats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) bool tagged;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) BR_INPUT_SKB_CB(skb)->vlan_filtered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /* If vlan tx offload is disabled on bridge device and frame was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * sent from vlan device on the bridge device, it does not have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * HW accelerated vlan tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (unlikely(!skb_vlan_tag_present(skb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) skb->protocol == br->vlan_proto)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) skb = skb_vlan_untag(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (!br_vlan_get_tag(skb, vid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* Tagged frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (skb->vlan_proto != br->vlan_proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /* Protocol-mismatch, empty out vlan_tci for new tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) skb_push(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) skb_vlan_tag_get(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) skb_pull(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) skb_reset_mac_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) *vid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) tagged = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) tagged = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /* Untagged frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) tagged = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (!*vid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) u16 pvid = br_get_pvid(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /* Frame had a tag with VID 0 or did not have a tag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * See if pvid is set on this port. That tells us which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * vlan untagged or priority-tagged traffic belongs to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (!pvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /* PVID is set on this port. Any untagged or priority-tagged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * ingress frame is considered to belong to this vlan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) *vid = pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (likely(!tagged))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* Untagged Frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) __vlan_hwaccel_put_tag(skb, br->vlan_proto, pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* Priority-tagged Frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * At this point, we know that skb->vlan_tci VID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * field was 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * We update only VID field and preserve PCP field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) skb->vlan_tci |= pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* if stats are disabled we can avoid the lookup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (!br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (*state == BR_STATE_FORWARDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) *state = br_vlan_get_pvid_state(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (!br_vlan_state_allowed(*state, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) v = br_vlan_find(vg, *vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (!v || !br_vlan_should_use(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (*state == BR_STATE_FORWARDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) *state = br_vlan_get_state(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (!br_vlan_state_allowed(*state, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) stats = this_cpu_ptr(v->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) u64_stats_update_begin(&stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) stats->rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) stats->rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) u64_stats_update_end(&stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) bool br_allowed_ingress(const struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct net_bridge_vlan_group *vg, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) u16 *vid, u8 *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) /* If VLAN filtering is disabled on the bridge, all packets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * permitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (!br_opt_get(br, BROPT_VLAN_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return __allowed_ingress(br, vg, skb, vid, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /* Called under RCU. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) bool br_allowed_egress(struct net_bridge_vlan_group *vg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) const struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) u16 vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* If this packet was not filtered at input, let it pass */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) br_vlan_get_tag(skb, &vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) v = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (v && br_vlan_should_use(v) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) br_vlan_state_allowed(br_vlan_get_state(v), false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) /* Called under RCU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct net_bridge *br = p->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) /* If filtering was disabled at input, let it pass. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (!br_opt_get(br, BROPT_VLAN_ENABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) vg = nbp_vlan_group_rcu(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (!vg || !vg->num_vlans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) *vid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (!*vid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) *vid = br_get_pvid(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (!*vid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) !br_vlan_state_allowed(br_vlan_get_pvid_state(vg), true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) v = br_vlan_find(vg, *vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (v && br_vlan_state_allowed(br_vlan_get_state(v), true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static int br_vlan_add_existing(struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) struct net_bridge_vlan_group *vg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct net_bridge_vlan *vlan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) u16 flags, bool *changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (err && err != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) if (!br_vlan_is_brentry(vlan)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) /* Trying to change flags of non-existent bridge vlan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (!(flags & BRIDGE_VLAN_INFO_BRENTRY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) goto err_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) /* It was only kept for port vlans, now make it real */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) err = br_fdb_insert(br, NULL, br->dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) br_err(br, "failed to insert local address into bridge forwarding table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) goto err_fdb_insert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) refcount_inc(&vlan->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) vg->num_vlans++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) *changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (__vlan_add_flags(vlan, flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) *changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) err_fdb_insert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) err_flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) br_switchdev_port_vlan_del(br->dev, vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) /* Must be protected by RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) * Must be called with vid in range from 1 to 4094 inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * changed must be true only if the vlan was created or updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, bool *changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) struct net_bridge_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) *changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) vlan = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if (vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return br_vlan_add_existing(br, vg, vlan, flags, changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) vlan->stats = netdev_alloc_pcpu_stats(struct br_vlan_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!vlan->stats) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) kfree(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) vlan->vid = vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) vlan->flags = flags | BRIDGE_VLAN_INFO_MASTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) vlan->flags &= ~BRIDGE_VLAN_INFO_PVID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) vlan->br = br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (flags & BRIDGE_VLAN_INFO_BRENTRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) refcount_set(&vlan->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) ret = __vlan_add(vlan, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) free_percpu(vlan->stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) kfree(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) *changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) /* Must be protected by RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * Must be called with vid in range from 1 to 4094 inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) int br_vlan_delete(struct net_bridge *br, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) v = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) if (!v || !br_vlan_is_brentry(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) br_fdb_delete_by_port(br, NULL, vid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) vlan_tunnel_info_del(vg, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) return __vlan_del(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) void br_vlan_flush(struct net_bridge *br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) __vlan_flush(br, NULL, vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) RCU_INIT_POINTER(br->vlgrp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) __vlan_group_free(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) if (!vg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) return br_vlan_lookup(&vg->vlan_hash, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* Must be protected by RTNL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) static void recalculate_group_addr(struct net_bridge *br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if (br_opt_get(br, BROPT_GROUP_ADDR_SET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) spin_lock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (!br_opt_get(br, BROPT_VLAN_ENABLED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) br->vlan_proto == htons(ETH_P_8021Q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) /* Bridge Group Address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) br->group_addr[5] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) } else { /* vlan_enabled && ETH_P_8021AD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /* Provider Bridge Group Address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) br->group_addr[5] = 0x08;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) spin_unlock_bh(&br->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) /* Must be protected by RTNL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) void br_recalculate_fwd_mask(struct net_bridge *br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) if (!br_opt_get(br, BROPT_VLAN_ENABLED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) br->vlan_proto == htons(ETH_P_8021Q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) else /* vlan_enabled && ETH_P_8021AD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) br->group_fwd_mask_required = BR_GROUPFWD_8021AD &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) ~(1u << br->group_addr[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) struct switchdev_attr attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) .orig_dev = br->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) .u.vlan_filtering = val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) if (br_opt_get(br, BROPT_VLAN_ENABLED) == !!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) err = switchdev_port_attr_set(br->dev, &attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) if (err && err != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) br_opt_toggle(br, BROPT_VLAN_ENABLED, !!val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) br_manage_promisc(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) recalculate_group_addr(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) br_recalculate_fwd_mask(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return __br_vlan_filter_toggle(br, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) bool br_vlan_enabled(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) return br_opt_get(br, BROPT_VLAN_ENABLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) EXPORT_SYMBOL_GPL(br_vlan_enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) *p_proto = ntohs(br->vlan_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) EXPORT_SYMBOL_GPL(br_vlan_get_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) int __br_vlan_set_proto(struct net_bridge *br, __be16 proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) struct net_bridge_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) __be16 oldproto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (br->vlan_proto == proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) /* Add VLANs for the new proto to the device filter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) list_for_each_entry(vlan, &vg->vlan_list, vlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) err = vlan_vid_add(p->dev, proto, vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) goto err_filt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) oldproto = br->vlan_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) br->vlan_proto = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) recalculate_group_addr(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) br_recalculate_fwd_mask(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* Delete VLANs for the old proto from the device filter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) list_for_each_entry(vlan, &vg->vlan_list, vlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) vlan_vid_del(p->dev, oldproto, vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) err_filt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) list_for_each_entry_continue_reverse(vlan, &vg->vlan_list, vlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) vlan_vid_del(p->dev, proto, vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) list_for_each_entry_continue_reverse(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) list_for_each_entry(vlan, &vg->vlan_list, vlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) vlan_vid_del(p->dev, proto, vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (val != ETH_P_8021Q && val != ETH_P_8021AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return __br_vlan_set_proto(br, htons(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) int br_vlan_set_stats(struct net_bridge *br, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) br_opt_toggle(br, BROPT_VLAN_STATS_ENABLED, !!val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) int br_vlan_set_stats_per_port(struct net_bridge *br, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) /* allow to change the option if there are no port vlans configured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) struct net_bridge_vlan_group *vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (vg->num_vlans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) switch (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) br_opt_toggle(br, BROPT_VLAN_STATS_PER_PORT, !!val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) static bool vlan_default_pvid(struct net_bridge_vlan_group *vg, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (vid != vg->pvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) v = br_vlan_lookup(&vg->vlan_hash, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (v && br_vlan_should_use(v) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) (v->flags & BRIDGE_VLAN_INFO_UNTAGGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) static void br_vlan_disable_default_pvid(struct net_bridge *br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) u16 pvid = br->default_pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) /* Disable default_pvid on all ports where it is still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) * configured.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) if (vlan_default_pvid(br_vlan_group(br), pvid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) if (!br_vlan_delete(br, pvid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) br_vlan_notify(br, NULL, pvid, 0, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) if (vlan_default_pvid(nbp_vlan_group(p), pvid) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) !nbp_vlan_delete(p, pvid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) br_vlan_notify(br, p, pvid, 0, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) br->default_pvid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) const struct net_bridge_vlan *pvent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) unsigned long *changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) bool vlchange;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) u16 old_pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) if (!pvid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) br_vlan_disable_default_pvid(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) changed = bitmap_zalloc(BR_MAX_PORTS, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (!changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) old_pvid = br->default_pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) /* Update default_pvid config only if we do not conflict with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) * user configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) pvent = br_vlan_find(vg, pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if ((!old_pvid || vlan_default_pvid(vg, old_pvid)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) (!pvent || !br_vlan_should_use(pvent))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) err = br_vlan_add(br, pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) BRIDGE_VLAN_INFO_PVID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) BRIDGE_VLAN_INFO_UNTAGGED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) BRIDGE_VLAN_INFO_BRENTRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) &vlchange, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (br_vlan_delete(br, old_pvid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) br_vlan_notify(br, NULL, old_pvid, 0, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) br_vlan_notify(br, NULL, pvid, 0, RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) set_bit(0, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) /* Update default_pvid config only if we do not conflict with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) * user configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if ((old_pvid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) !vlan_default_pvid(vg, old_pvid)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) br_vlan_find(vg, pvid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) err = nbp_vlan_add(p, pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) BRIDGE_VLAN_INFO_PVID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) BRIDGE_VLAN_INFO_UNTAGGED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) &vlchange, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) goto err_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (nbp_vlan_delete(p, old_pvid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) br_vlan_notify(br, p, old_pvid, 0, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) br_vlan_notify(p->br, p, pvid, 0, RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) set_bit(p->port_no, changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) br->default_pvid = pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) bitmap_free(changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) err_port:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) list_for_each_entry_continue_reverse(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) if (!test_bit(p->port_no, changed))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (old_pvid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) nbp_vlan_add(p, old_pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) BRIDGE_VLAN_INFO_PVID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) BRIDGE_VLAN_INFO_UNTAGGED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) &vlchange, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) br_vlan_notify(p->br, p, old_pvid, 0, RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) nbp_vlan_delete(p, pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) br_vlan_notify(br, p, pvid, 0, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) if (test_bit(0, changed)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (old_pvid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) br_vlan_add(br, old_pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) BRIDGE_VLAN_INFO_PVID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) BRIDGE_VLAN_INFO_UNTAGGED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) BRIDGE_VLAN_INFO_BRENTRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) &vlchange, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) br_vlan_notify(br, NULL, old_pvid, 0, RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) br_vlan_delete(br, pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) br_vlan_notify(br, NULL, pvid, 0, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) u16 pvid = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (val >= VLAN_VID_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (pvid == br->default_pvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* Only allow default pvid change when filtering is disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (br_opt_get(br, BROPT_VLAN_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) pr_info_once("Please disable vlan filtering to change default_pvid\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) err = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) err = __br_vlan_set_default_pvid(br, pvid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) int br_vlan_init(struct net_bridge *br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) vg = kzalloc(sizeof(*vg), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (!vg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) goto err_rhtbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) ret = vlan_tunnel_init(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) goto err_tunnel_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) INIT_LIST_HEAD(&vg->vlan_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) br->vlan_proto = htons(ETH_P_8021Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) br->default_pvid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) rcu_assign_pointer(br->vlgrp, vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) err_tunnel_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) rhashtable_destroy(&vg->vlan_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) err_rhtbl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) kfree(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) int nbp_vlan_init(struct net_bridge_port *p, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) struct switchdev_attr attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) .orig_dev = p->br->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) .u.vlan_filtering = br_opt_get(p->br, BROPT_VLAN_ENABLED),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) vg = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) if (!vg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) ret = switchdev_port_attr_set(p->dev, &attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (ret && ret != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) goto err_vlan_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) goto err_rhtbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) ret = vlan_tunnel_init(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) goto err_tunnel_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) INIT_LIST_HEAD(&vg->vlan_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) rcu_assign_pointer(p->vlgrp, vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) if (p->br->default_pvid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) bool changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) ret = nbp_vlan_add(p, p->br->default_pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) BRIDGE_VLAN_INFO_PVID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) BRIDGE_VLAN_INFO_UNTAGGED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) &changed, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) goto err_vlan_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) br_vlan_notify(p->br, p, p->br->default_pvid, 0, RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) err_vlan_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) RCU_INIT_POINTER(p->vlgrp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) vlan_tunnel_deinit(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) err_tunnel_init:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) rhashtable_destroy(&vg->vlan_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) err_rhtbl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) err_vlan_enabled:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) kfree(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) /* Must be protected by RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) * Must be called with vid in range from 1 to 4094 inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) * changed must be true only if the vlan was created or updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) bool *changed, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) struct net_bridge_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) *changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) vlan = br_vlan_find(nbp_vlan_group(port), vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) if (vlan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) /* Pass the flags to the hardware bridge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) ret = br_switchdev_port_vlan_add(port->dev, vid, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (ret && ret != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) *changed = __vlan_add_flags(vlan, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if (!vlan)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) vlan->vid = vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) vlan->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) ret = __vlan_add(vlan, flags, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) kfree(vlan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) *changed = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) /* Must be protected by RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) * Must be called with vid in range from 1 to 4094 inclusive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) v = br_vlan_find(nbp_vlan_group(port), vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (!v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) br_fdb_delete_by_port(port->br, port, vid, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) return __vlan_del(v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) void nbp_vlan_flush(struct net_bridge_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) vg = nbp_vlan_group(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) __vlan_flush(port->br, port, vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) RCU_INIT_POINTER(port->vlgrp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) __vlan_group_free(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) void br_vlan_get_stats(const struct net_bridge_vlan *v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) struct br_vlan_stats *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) memset(stats, 0, sizeof(*stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) for_each_possible_cpu(i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) u64 rxpackets, rxbytes, txpackets, txbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) struct br_vlan_stats *cpu_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) unsigned int start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) cpu_stats = per_cpu_ptr(v->stats, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) rxpackets = cpu_stats->rx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) rxbytes = cpu_stats->rx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) txbytes = cpu_stats->tx_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) txpackets = cpu_stats->tx_packets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) stats->rx_packets += rxpackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) stats->rx_bytes += rxbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) stats->tx_bytes += txbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) stats->tx_packets += txpackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) int br_vlan_get_pvid(const struct net_device *dev, u16 *p_pvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) p = br_port_get_check_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) else if (netif_is_bridge_master(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) vg = br_vlan_group(netdev_priv(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) *p_pvid = br_get_pvid(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) EXPORT_SYMBOL_GPL(br_vlan_get_pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) int br_vlan_get_pvid_rcu(const struct net_device *dev, u16 *p_pvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) p = br_port_get_check_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) vg = nbp_vlan_group_rcu(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) else if (netif_is_bridge_master(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) vg = br_vlan_group_rcu(netdev_priv(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) *p_pvid = br_get_pvid(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) EXPORT_SYMBOL_GPL(br_vlan_get_pvid_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) int br_vlan_get_info(const struct net_device *dev, u16 vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) struct bridge_vlan_info *p_vinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) struct net_bridge_vlan *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) p = br_port_get_check_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) if (p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) else if (netif_is_bridge_master(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) vg = br_vlan_group(netdev_priv(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) v = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) if (!v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) p_vinfo->vid = vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) p_vinfo->flags = v->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) if (vid == br_get_pvid(vg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) p_vinfo->flags |= BRIDGE_VLAN_INFO_PVID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) EXPORT_SYMBOL_GPL(br_vlan_get_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static int br_vlan_is_bind_vlan_dev(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) return is_vlan_dev(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) !!(vlan_dev_priv(dev)->flags & VLAN_FLAG_BRIDGE_BINDING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) static int br_vlan_is_bind_vlan_dev_fn(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) __always_unused struct netdev_nested_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) return br_vlan_is_bind_vlan_dev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) static bool br_vlan_has_upper_bind_vlan_dev(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) int found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) found = netdev_walk_all_upper_dev_rcu(dev, br_vlan_is_bind_vlan_dev_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) return !!found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) struct br_vlan_bind_walk_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) u16 vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) struct net_device *result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) static int br_vlan_match_bind_vlan_dev_fn(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) struct netdev_nested_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) struct br_vlan_bind_walk_data *data = priv->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) if (br_vlan_is_bind_vlan_dev(dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) vlan_dev_priv(dev)->vlan_id == data->vid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) data->result = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) static struct net_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) br_vlan_get_upper_bind_vlan_dev(struct net_device *dev, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) struct br_vlan_bind_walk_data data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) .vid = vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) struct netdev_nested_priv priv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) .data = (void *)&data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) netdev_walk_all_upper_dev_rcu(dev, br_vlan_match_bind_vlan_dev_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) &priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) return data.result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) static bool br_vlan_is_dev_up(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) return !!(dev->flags & IFF_UP) && netif_oper_up(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) static void br_vlan_set_vlan_dev_state(const struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) struct net_device *vlan_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) u16 vid = vlan_dev_priv(vlan_dev)->vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) bool has_carrier = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) if (!netif_carrier_ok(br->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) netif_carrier_off(vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) list_for_each_entry(p, &br->port_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (br_vlan_find(vg, vid) && br_vlan_is_dev_up(p->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) has_carrier = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) if (has_carrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) netif_carrier_on(vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) netif_carrier_off(vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) static void br_vlan_set_all_vlan_dev_state(struct net_bridge_port *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) struct net_bridge_vlan_group *vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) struct net_bridge_vlan *vlan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) struct net_device *vlan_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) list_for_each_entry(vlan, &vg->vlan_list, vlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) vlan_dev = br_vlan_get_upper_bind_vlan_dev(p->br->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) vlan->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) if (vlan_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (br_vlan_is_dev_up(p->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) if (netif_carrier_ok(p->br->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) netif_carrier_on(vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) br_vlan_set_vlan_dev_state(p->br, vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) static void br_vlan_upper_change(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) struct net_device *upper_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) bool linking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) if (!br_vlan_is_bind_vlan_dev(upper_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) if (linking) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) br_vlan_set_vlan_dev_state(br, upper_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) br_opt_toggle(br, BROPT_VLAN_BRIDGE_BINDING, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) br_opt_toggle(br, BROPT_VLAN_BRIDGE_BINDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) br_vlan_has_upper_bind_vlan_dev(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) struct br_vlan_link_state_walk_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) struct net_bridge *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) static int br_vlan_link_state_change_fn(struct net_device *vlan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) struct netdev_nested_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) struct br_vlan_link_state_walk_data *data = priv->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (br_vlan_is_bind_vlan_dev(vlan_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) br_vlan_set_vlan_dev_state(data->br, vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) static void br_vlan_link_state_change(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) struct net_bridge *br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) struct br_vlan_link_state_walk_data data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) .br = br
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) struct netdev_nested_priv priv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) .data = (void *)&data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) netdev_walk_all_upper_dev_rcu(dev, br_vlan_link_state_change_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) &priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) /* Must be protected by RTNL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) static void nbp_vlan_set_vlan_dev_state(struct net_bridge_port *p, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) struct net_device *vlan_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) if (!br_opt_get(p->br, BROPT_VLAN_BRIDGE_BINDING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) vlan_dev = br_vlan_get_upper_bind_vlan_dev(p->br->dev, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) if (vlan_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) br_vlan_set_vlan_dev_state(p->br, vlan_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) /* Must be protected by RTNL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) int br_vlan_bridge_event(struct net_device *dev, unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) struct netdev_notifier_changeupper_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) struct net_bridge *br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) int vlcmd = 0, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) bool changed = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) case NETDEV_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) ret = br_vlan_add(br, br->default_pvid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) BRIDGE_VLAN_INFO_PVID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) BRIDGE_VLAN_INFO_UNTAGGED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) BRIDGE_VLAN_INFO_BRENTRY, &changed, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) vlcmd = RTM_NEWVLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) case NETDEV_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) changed = !br_vlan_delete(br, br->default_pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) vlcmd = RTM_DELVLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) case NETDEV_CHANGEUPPER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) info = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) br_vlan_upper_change(dev, info->upper_dev, info->linking);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) if (!br_opt_get(br, BROPT_VLAN_BRIDGE_BINDING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) br_vlan_link_state_change(dev, br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) br_vlan_notify(br, NULL, br->default_pvid, 0, vlcmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) /* Must be protected by RTNL. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) void br_vlan_port_event(struct net_bridge_port *p, unsigned long event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) if (!br_opt_get(p->br, BROPT_VLAN_BRIDGE_BINDING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) br_vlan_set_all_vlan_dev_state(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) static bool br_vlan_stats_fill(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) const struct net_bridge_vlan *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) struct br_vlan_stats stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) nest = nla_nest_start(skb, BRIDGE_VLANDB_ENTRY_STATS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) if (!nest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) br_vlan_get_stats(v, &stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) if (nla_put_u64_64bit(skb, BRIDGE_VLANDB_STATS_RX_BYTES, stats.rx_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) BRIDGE_VLANDB_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) nla_put_u64_64bit(skb, BRIDGE_VLANDB_STATS_RX_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) stats.rx_packets, BRIDGE_VLANDB_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) nla_put_u64_64bit(skb, BRIDGE_VLANDB_STATS_TX_BYTES, stats.tx_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) BRIDGE_VLANDB_STATS_PAD) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) nla_put_u64_64bit(skb, BRIDGE_VLANDB_STATS_TX_PACKETS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) stats.tx_packets, BRIDGE_VLANDB_STATS_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) nla_nest_cancel(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) /* v_opts is used to dump the options which must be equal in the whole range */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) static bool br_vlan_fill_vids(struct sk_buff *skb, u16 vid, u16 vid_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) const struct net_bridge_vlan *v_opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) u16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) bool dump_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) struct bridge_vlan_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) nest = nla_nest_start(skb, BRIDGE_VLANDB_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) if (!nest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) memset(&info, 0, sizeof(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) info.vid = vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) info.flags |= BRIDGE_VLAN_INFO_UNTAGGED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) if (flags & BRIDGE_VLAN_INFO_PVID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) info.flags |= BRIDGE_VLAN_INFO_PVID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) if (nla_put(skb, BRIDGE_VLANDB_ENTRY_INFO, sizeof(info), &info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) if (vid_range && vid < vid_range &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) !(flags & BRIDGE_VLAN_INFO_PVID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) nla_put_u16(skb, BRIDGE_VLANDB_ENTRY_RANGE, vid_range))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) if (v_opts) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) if (!br_vlan_opts_fill(skb, v_opts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) if (dump_stats && !br_vlan_stats_fill(skb, v_opts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) nla_nest_cancel(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) static size_t rtnl_vlan_nlmsg_size(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) return NLMSG_ALIGN(sizeof(struct br_vlan_msg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) + nla_total_size(0) /* BRIDGE_VLANDB_ENTRY */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) + nla_total_size(sizeof(u16)) /* BRIDGE_VLANDB_ENTRY_RANGE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) + nla_total_size(sizeof(struct bridge_vlan_info)) /* BRIDGE_VLANDB_ENTRY_INFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) + br_vlan_opts_nl_size(); /* bridge vlan options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) void br_vlan_notify(const struct net_bridge *br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) const struct net_bridge_port *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) u16 vid, u16 vid_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) struct net_bridge_vlan *v = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) struct br_vlan_msg *bvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) struct nlmsghdr *nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) int err = -ENOBUFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) u16 flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) int ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) /* right now notifications are done only with rtnl held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) ifindex = p->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) net = dev_net(p->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) ifindex = br->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) net = dev_net(br->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) skb = nlmsg_new(rtnl_vlan_nlmsg_size(), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) nlh = nlmsg_put(skb, 0, 0, cmd, sizeof(*bvm), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) bvm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) memset(bvm, 0, sizeof(*bvm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) bvm->family = AF_BRIDGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) bvm->ifindex = ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) case RTM_NEWVLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) /* need to find the vlan due to flags/options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) v = br_vlan_find(vg, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) if (!v || !br_vlan_should_use(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) flags = v->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if (br_get_pvid(vg) == v->vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) flags |= BRIDGE_VLAN_INFO_PVID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) case RTM_DELVLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) if (!br_vlan_fill_vids(skb, vid, vid_range, v, flags, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) rtnl_notify(skb, net, 0, RTNLGRP_BRVLAN, NULL, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) rtnl_set_sk_err(net, RTNLGRP_BRVLAN, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) out_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) /* check if v_curr can enter a range ending in range_end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) bool br_vlan_can_enter_range(const struct net_bridge_vlan *v_curr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) const struct net_bridge_vlan *range_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) return v_curr->vid - range_end->vid == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) range_end->flags == v_curr->flags &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) br_vlan_opts_eq_range(v_curr, range_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) static int br_vlan_dump_dev(const struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) struct netlink_callback *cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) u32 dump_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) struct net_bridge_vlan *v, *range_start = NULL, *range_end = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) bool dump_stats = !!(dump_flags & BRIDGE_VLANDB_DUMPF_STATS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) int idx = 0, s_idx = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) struct nlmsghdr *nlh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) struct net_bridge_port *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) struct br_vlan_msg *bvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) struct net_bridge *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) u16 pvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) if (!netif_is_bridge_master(dev) && !netif_is_bridge_port(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) if (netif_is_bridge_master(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) vg = br_vlan_group_rcu(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) p = br_port_get_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) if (WARN_ON(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) vg = nbp_vlan_group_rcu(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) br = p->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) if (!vg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) RTM_NEWVLAN, sizeof(*bvm), NLM_F_MULTI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) if (!nlh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) bvm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) memset(bvm, 0, sizeof(*bvm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) bvm->family = PF_BRIDGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) bvm->ifindex = dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) pvid = br_get_pvid(vg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) /* idx must stay at range's beginning until it is filled in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) list_for_each_entry_rcu(v, &vg->vlan_list, vlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) if (!br_vlan_should_use(v))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) if (idx < s_idx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) if (!range_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) range_start = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) range_end = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) if (dump_stats || v->vid == pvid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) !br_vlan_can_enter_range(v, range_end)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) u16 vlan_flags = br_vlan_flags(range_start, pvid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) if (!br_vlan_fill_vids(skb, range_start->vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) range_end->vid, range_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) vlan_flags, dump_stats)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) /* advance number of filled vlans */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) idx += range_end->vid - range_start->vid + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) range_start = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) range_end = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) /* err will be 0 and range_start will be set in 3 cases here:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) * - first vlan (range_start == range_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) * - last vlan (range_start == range_end, not in range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) * - last vlan range (range_start != range_end, in range)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) if (!err && range_start &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) !br_vlan_fill_vids(skb, range_start->vid, range_end->vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) range_start, br_vlan_flags(range_start, pvid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) dump_stats))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) cb->args[1] = err ? idx : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) nlmsg_end(skb, nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) static const struct nla_policy br_vlan_db_dump_pol[BRIDGE_VLANDB_DUMP_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) [BRIDGE_VLANDB_DUMP_FLAGS] = { .type = NLA_U32 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) static int br_vlan_rtm_dump(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) struct nlattr *dtb[BRIDGE_VLANDB_DUMP_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) int idx = 0, err = 0, s_idx = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) struct br_vlan_msg *bvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) u32 dump_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) err = nlmsg_parse(cb->nlh, sizeof(*bvm), dtb, BRIDGE_VLANDB_DUMP_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) br_vlan_db_dump_pol, cb->extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) bvm = nlmsg_data(cb->nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) if (dtb[BRIDGE_VLANDB_DUMP_FLAGS])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) dump_flags = nla_get_u32(dtb[BRIDGE_VLANDB_DUMP_FLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) if (bvm->ifindex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) dev = dev_get_by_index_rcu(net, bvm->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) err = br_vlan_dump_dev(dev, skb, cb, dump_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) /* if the dump completed without an error we return 0 here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) if (err != -EMSGSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) for_each_netdev_rcu(net, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) if (idx < s_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) err = br_vlan_dump_dev(dev, skb, cb, dump_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) if (err == -EMSGSIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) idx++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) cb->args[0] = idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) return skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) static const struct nla_policy br_vlan_db_policy[BRIDGE_VLANDB_ENTRY_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) [BRIDGE_VLANDB_ENTRY_INFO] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) NLA_POLICY_EXACT_LEN(sizeof(struct bridge_vlan_info)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) [BRIDGE_VLANDB_ENTRY_RANGE] = { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) [BRIDGE_VLANDB_ENTRY_STATE] = { .type = NLA_U8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) [BRIDGE_VLANDB_ENTRY_TUNNEL_INFO] = { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) static int br_vlan_rtm_process_one(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) const struct nlattr *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) int cmd, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) struct bridge_vlan_info *vinfo, vrange_end, *vinfo_last = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) struct nlattr *tb[BRIDGE_VLANDB_ENTRY_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) bool changed = false, skip_processing = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) struct net_bridge_vlan_group *vg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) struct net_bridge_port *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) int err = 0, cmdmap = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) struct net_bridge *br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) if (netif_is_bridge_master(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) br = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) vg = br_vlan_group(br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) p = br_port_get_rtnl(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) if (WARN_ON(!p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) br = p->br;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) vg = nbp_vlan_group(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) if (WARN_ON(!vg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) err = nla_parse_nested(tb, BRIDGE_VLANDB_ENTRY_MAX, attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) br_vlan_db_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) if (!tb[BRIDGE_VLANDB_ENTRY_INFO]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) NL_SET_ERR_MSG_MOD(extack, "Missing vlan entry info");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) memset(&vrange_end, 0, sizeof(vrange_end));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) vinfo = nla_data(tb[BRIDGE_VLANDB_ENTRY_INFO]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) if (vinfo->flags & (BRIDGE_VLAN_INFO_RANGE_BEGIN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) BRIDGE_VLAN_INFO_RANGE_END)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) NL_SET_ERR_MSG_MOD(extack, "Old-style vlan ranges are not allowed when using RTM vlan calls");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) if (!br_vlan_valid_id(vinfo->vid, extack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) if (tb[BRIDGE_VLANDB_ENTRY_RANGE]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) vrange_end.vid = nla_get_u16(tb[BRIDGE_VLANDB_ENTRY_RANGE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) /* validate user-provided flags without RANGE_BEGIN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) vrange_end.flags = BRIDGE_VLAN_INFO_RANGE_END | vinfo->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) vinfo->flags |= BRIDGE_VLAN_INFO_RANGE_BEGIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) /* vinfo_last is the range start, vinfo the range end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) vinfo_last = vinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) vinfo = &vrange_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) if (!br_vlan_valid_id(vinfo->vid, extack) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) !br_vlan_valid_range(vinfo, vinfo_last, extack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) case RTM_NEWVLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) cmdmap = RTM_SETLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) skip_processing = !!(vinfo->flags & BRIDGE_VLAN_INFO_ONLY_OPTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) case RTM_DELVLAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) cmdmap = RTM_DELLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) if (!skip_processing) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) struct bridge_vlan_info *tmp_last = vinfo_last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) /* br_process_vlan_info may overwrite vinfo_last */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) err = br_process_vlan_info(br, p, cmdmap, vinfo, &tmp_last,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) &changed, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) /* notify first if anything changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) if (changed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) br_ifinfo_notify(cmdmap, br, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) /* deal with options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) if (cmd == RTM_NEWVLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) struct net_bridge_vlan *range_start, *range_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) if (vinfo_last) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) range_start = br_vlan_find(vg, vinfo_last->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) range_end = br_vlan_find(vg, vinfo->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) range_start = br_vlan_find(vg, vinfo->vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) range_end = range_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) err = br_vlan_process_options(br, p, range_start, range_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) tb, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) static int br_vlan_rtm_process(struct sk_buff *skb, struct nlmsghdr *nlh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) struct br_vlan_msg *bvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) int err, vlans = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) int rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) /* this should validate the header and check for remaining bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) err = nlmsg_parse(nlh, sizeof(*bvm), NULL, BRIDGE_VLANDB_MAX, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) bvm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) dev = __dev_get_by_index(net, bvm->ifindex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) if (!netif_is_bridge_master(dev) && !netif_is_bridge_port(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) NL_SET_ERR_MSG_MOD(extack, "The device is not a valid bridge or bridge port");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) nlmsg_for_each_attr(attr, nlh, sizeof(*bvm), rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (nla_type(attr) != BRIDGE_VLANDB_ENTRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) vlans++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) err = br_vlan_rtm_process_one(dev, attr, nlh->nlmsg_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (!vlans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) NL_SET_ERR_MSG_MOD(extack, "No vlans found to process");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) void br_vlan_rtnl_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_GETVLAN, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) br_vlan_rtm_dump, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_NEWVLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) br_vlan_rtm_process, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) rtnl_register_module(THIS_MODULE, PF_BRIDGE, RTM_DELVLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) br_vlan_rtm_process, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) void br_vlan_rtnl_uninit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) rtnl_unregister(PF_BRIDGE, RTM_GETVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) rtnl_unregister(PF_BRIDGE, RTM_NEWVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) rtnl_unregister(PF_BRIDGE, RTM_DELVLAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) }