Message ID | 20220409105857.803667-4-razor@blackwall.org (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net: bridge: add flush filtering support | expand |
On Sat, Apr 09, 2022 at 01:58:54PM +0300, Nikolay Aleksandrov wrote: > Add a new fdb flush call which parses the embedded attributes in > BRIDGE_FLUSH_FDB and fills in the fdb flush descriptor to delete only > matching entries. Currently it's a complete flush, support for more > fine-grained filtering will be added in the following patches. > > Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org> > --- > include/uapi/linux/if_bridge.h | 8 ++++++++ > net/bridge/br_fdb.c | 24 ++++++++++++++++++++++++ > net/bridge/br_netlink.c | 8 ++++++++ > net/bridge/br_private.h | 2 ++ > 4 files changed, 42 insertions(+) > > diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h > index 221a4256808f..2f3799cf14b2 100644 > --- a/include/uapi/linux/if_bridge.h > +++ b/include/uapi/linux/if_bridge.h > @@ -807,7 +807,15 @@ enum { > /* embedded in IFLA_BRIDGE_FLUSH */ > enum { > BRIDGE_FLUSH_UNSPEC, > + BRIDGE_FLUSH_FDB, > __BRIDGE_FLUSH_MAX > }; > #define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) > + > +/* embedded in BRIDGE_FLUSH_FDB */ > +enum { > + FDB_FLUSH_UNSPEC, > + __FDB_FLUSH_MAX > +}; > +#define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) > #endif /* _UAPI_LINUX_IF_BRIDGE_H */ > diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c > index 4b0bf88c4121..62f694a739e1 100644 > --- a/net/bridge/br_fdb.c > +++ b/net/bridge/br_fdb.c > @@ -594,6 +594,30 @@ void br_fdb_flush(struct net_bridge *br, > rcu_read_unlock(); > } > > +static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { > + [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, > +}; > + > +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, > + struct netlink_ext_ack *extack) > +{ > + struct nlattr *fdb_flush_tb[FDB_FLUSH_MAX + 1]; > + struct net_bridge_fdb_flush_desc desc = {}; > + int err; > + > + err = nla_parse_nested(fdb_flush_tb, FDB_FLUSH_MAX, fdb_flush_attr, > + br_fdb_flush_policy, extack); > + if (err) > + return err; > + > + br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", > + desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); > + > + br_fdb_flush(br, &desc); > + > + return 0; > +} > + > /* Flush all entries referring to a specific port. > * if do_all is set also flush static entries > * if vid is set delete all entries that match the vlan_id > diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c > index 6e6dce6880c9..bd2c91e5723d 100644 > --- a/net/bridge/br_netlink.c > +++ b/net/bridge/br_netlink.c > @@ -781,6 +781,7 @@ int br_process_vlan_info(struct net_bridge *br, > > static const struct nla_policy br_flush_policy[BRIDGE_FLUSH_MAX + 1] = { > [BRIDGE_FLUSH_UNSPEC] = { .type = NLA_REJECT }, > + [BRIDGE_FLUSH_FDB] = { .type = NLA_NESTED }, In a previous submission [1] Jakub suggested using NLA_POLICY_NESTED() [1] https://lore.kernel.org/netdev/20220224221447.6c7fa95d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/ > }; > > static int br_flush(struct net_bridge *br, int cmd, > @@ -804,6 +805,13 @@ static int br_flush(struct net_bridge *br, int cmd, > if (err) > return err; > > + if (flush_tb[BRIDGE_FLUSH_FDB]) { > + err = br_fdb_flush_nlattr(br, flush_tb[BRIDGE_FLUSH_FDB], > + extack); > + if (err) > + return err; > + } > + > return 0; > } > > diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h > index e6930e9ee69d..c7ea531d30ef 100644 > --- a/net/bridge/br_private.h > +++ b/net/bridge/br_private.h > @@ -768,6 +768,8 @@ int br_fdb_hash_init(struct net_bridge *br); > void br_fdb_hash_fini(struct net_bridge *br); > void br_fdb_flush(struct net_bridge *br, > const struct net_bridge_fdb_flush_desc *desc); > +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, > + struct netlink_ext_ack *extack); > void br_fdb_find_delete_local(struct net_bridge *br, > const struct net_bridge_port *p, > const unsigned char *addr, u16 vid); > -- > 2.35.1 >
On Sat, Apr 09, 2022 at 01:58:54PM +0300, Nikolay Aleksandrov wrote: > diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h > index 221a4256808f..2f3799cf14b2 100644 > --- a/include/uapi/linux/if_bridge.h > +++ b/include/uapi/linux/if_bridge.h > @@ -807,7 +807,15 @@ enum { > /* embedded in IFLA_BRIDGE_FLUSH */ > enum { > BRIDGE_FLUSH_UNSPEC, > + BRIDGE_FLUSH_FDB, > __BRIDGE_FLUSH_MAX > }; > #define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) > + > +/* embedded in BRIDGE_FLUSH_FDB */ > +enum { > + FDB_FLUSH_UNSPEC, BTW, is there a reason this is not called FLUSH_FDB_UNSPEC given it's embedded in BRIDGE_FLUSH_FDB, which is embedded in IFLA_BRIDGE_FLUSH ? Regardless, in the cover letter you have '[ BRIDGE_FDB_FLUSH ]', which is actually BRIDGE_FLUSH_FDB. I only noticed it because the code didn't match what I had in my notebook, which I copied from the cover letter :) > + __FDB_FLUSH_MAX > +}; > +#define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) > #endif /* _UAPI_LINUX_IF_BRIDGE_H */
On 11/04/2022 11:33, Ido Schimmel wrote: > On Sat, Apr 09, 2022 at 01:58:54PM +0300, Nikolay Aleksandrov wrote: >> Add a new fdb flush call which parses the embedded attributes in >> BRIDGE_FLUSH_FDB and fills in the fdb flush descriptor to delete only >> matching entries. Currently it's a complete flush, support for more >> fine-grained filtering will be added in the following patches. >> >> Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org> >> --- >> include/uapi/linux/if_bridge.h | 8 ++++++++ >> net/bridge/br_fdb.c | 24 ++++++++++++++++++++++++ >> net/bridge/br_netlink.c | 8 ++++++++ >> net/bridge/br_private.h | 2 ++ >> 4 files changed, 42 insertions(+) >> >> diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h >> index 221a4256808f..2f3799cf14b2 100644 >> --- a/include/uapi/linux/if_bridge.h >> +++ b/include/uapi/linux/if_bridge.h >> @@ -807,7 +807,15 @@ enum { >> /* embedded in IFLA_BRIDGE_FLUSH */ >> enum { >> BRIDGE_FLUSH_UNSPEC, >> + BRIDGE_FLUSH_FDB, >> __BRIDGE_FLUSH_MAX >> }; >> #define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) >> + >> +/* embedded in BRIDGE_FLUSH_FDB */ >> +enum { >> + FDB_FLUSH_UNSPEC, >> + __FDB_FLUSH_MAX >> +}; >> +#define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) >> #endif /* _UAPI_LINUX_IF_BRIDGE_H */ >> diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c >> index 4b0bf88c4121..62f694a739e1 100644 >> --- a/net/bridge/br_fdb.c >> +++ b/net/bridge/br_fdb.c >> @@ -594,6 +594,30 @@ void br_fdb_flush(struct net_bridge *br, >> rcu_read_unlock(); >> } >> >> +static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { >> + [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, >> +}; >> + >> +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, >> + struct netlink_ext_ack *extack) >> +{ >> + struct nlattr *fdb_flush_tb[FDB_FLUSH_MAX + 1]; >> + struct net_bridge_fdb_flush_desc desc = {}; >> + int err; >> + >> + err = nla_parse_nested(fdb_flush_tb, FDB_FLUSH_MAX, fdb_flush_attr, >> + br_fdb_flush_policy, extack); >> + if (err) >> + return err; >> + >> + br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", >> + desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); >> + >> + br_fdb_flush(br, &desc); >> + >> + return 0; >> +} >> + >> /* Flush all entries referring to a specific port. >> * if do_all is set also flush static entries >> * if vid is set delete all entries that match the vlan_id >> diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c >> index 6e6dce6880c9..bd2c91e5723d 100644 >> --- a/net/bridge/br_netlink.c >> +++ b/net/bridge/br_netlink.c >> @@ -781,6 +781,7 @@ int br_process_vlan_info(struct net_bridge *br, >> >> static const struct nla_policy br_flush_policy[BRIDGE_FLUSH_MAX + 1] = { >> [BRIDGE_FLUSH_UNSPEC] = { .type = NLA_REJECT }, >> + [BRIDGE_FLUSH_FDB] = { .type = NLA_NESTED }, > > In a previous submission [1] Jakub suggested using NLA_POLICY_NESTED() > > [1] https://lore.kernel.org/netdev/20220224221447.6c7fa95d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com/ > I didn't use it because I'll have to export the private object (fdb/mdb) policy structs, it will also require some ifdefs due to conditional mdb. They use nla_parse_nested internally, so they get validated properly. >> }; >> >> static int br_flush(struct net_bridge *br, int cmd, >> @@ -804,6 +805,13 @@ static int br_flush(struct net_bridge *br, int cmd, >> if (err) >> return err; >> >> + if (flush_tb[BRIDGE_FLUSH_FDB]) { >> + err = br_fdb_flush_nlattr(br, flush_tb[BRIDGE_FLUSH_FDB], >> + extack); >> + if (err) >> + return err; >> + } >> + >> return 0; >> } >> >> diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h >> index e6930e9ee69d..c7ea531d30ef 100644 >> --- a/net/bridge/br_private.h >> +++ b/net/bridge/br_private.h >> @@ -768,6 +768,8 @@ int br_fdb_hash_init(struct net_bridge *br); >> void br_fdb_hash_fini(struct net_bridge *br); >> void br_fdb_flush(struct net_bridge *br, >> const struct net_bridge_fdb_flush_desc *desc); >> +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, >> + struct netlink_ext_ack *extack); >> void br_fdb_find_delete_local(struct net_bridge *br, >> const struct net_bridge_port *p, >> const unsigned char *addr, u16 vid); >> -- >> 2.35.1 >>
On 11/04/2022 11:41, Ido Schimmel wrote: > On Sat, Apr 09, 2022 at 01:58:54PM +0300, Nikolay Aleksandrov wrote: >> diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h >> index 221a4256808f..2f3799cf14b2 100644 >> --- a/include/uapi/linux/if_bridge.h >> +++ b/include/uapi/linux/if_bridge.h >> @@ -807,7 +807,15 @@ enum { >> /* embedded in IFLA_BRIDGE_FLUSH */ >> enum { >> BRIDGE_FLUSH_UNSPEC, >> + BRIDGE_FLUSH_FDB, >> __BRIDGE_FLUSH_MAX >> }; >> #define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) >> + >> +/* embedded in BRIDGE_FLUSH_FDB */ >> +enum { >> + FDB_FLUSH_UNSPEC, > > BTW, is there a reason this is not called FLUSH_FDB_UNSPEC given it's > embedded in BRIDGE_FLUSH_FDB, which is embedded in IFLA_BRIDGE_FLUSH ? > > Regardless, in the cover letter you have '[ BRIDGE_FDB_FLUSH ]', which > is actually BRIDGE_FLUSH_FDB. I only noticed it because the code didn't > match what I had in my notebook, which I copied from the cover letter :) > Oops, that's a mismatch between an older version of the set and this one. :) >> + __FDB_FLUSH_MAX >> +}; >> +#define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) >> #endif /* _UAPI_LINUX_IF_BRIDGE_H */
diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 221a4256808f..2f3799cf14b2 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -807,7 +807,15 @@ enum { /* embedded in IFLA_BRIDGE_FLUSH */ enum { BRIDGE_FLUSH_UNSPEC, + BRIDGE_FLUSH_FDB, __BRIDGE_FLUSH_MAX }; #define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) + +/* embedded in BRIDGE_FLUSH_FDB */ +enum { + FDB_FLUSH_UNSPEC, + __FDB_FLUSH_MAX +}; +#define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) #endif /* _UAPI_LINUX_IF_BRIDGE_H */ diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 4b0bf88c4121..62f694a739e1 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -594,6 +594,30 @@ void br_fdb_flush(struct net_bridge *br, rcu_read_unlock(); } +static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { + [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, +}; + +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, + struct netlink_ext_ack *extack) +{ + struct nlattr *fdb_flush_tb[FDB_FLUSH_MAX + 1]; + struct net_bridge_fdb_flush_desc desc = {}; + int err; + + err = nla_parse_nested(fdb_flush_tb, FDB_FLUSH_MAX, fdb_flush_attr, + br_fdb_flush_policy, extack); + if (err) + return err; + + br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", + desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); + + br_fdb_flush(br, &desc); + + return 0; +} + /* Flush all entries referring to a specific port. * if do_all is set also flush static entries * if vid is set delete all entries that match the vlan_id diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 6e6dce6880c9..bd2c91e5723d 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -781,6 +781,7 @@ int br_process_vlan_info(struct net_bridge *br, static const struct nla_policy br_flush_policy[BRIDGE_FLUSH_MAX + 1] = { [BRIDGE_FLUSH_UNSPEC] = { .type = NLA_REJECT }, + [BRIDGE_FLUSH_FDB] = { .type = NLA_NESTED }, }; static int br_flush(struct net_bridge *br, int cmd, @@ -804,6 +805,13 @@ static int br_flush(struct net_bridge *br, int cmd, if (err) return err; + if (flush_tb[BRIDGE_FLUSH_FDB]) { + err = br_fdb_flush_nlattr(br, flush_tb[BRIDGE_FLUSH_FDB], + extack); + if (err) + return err; + } + return 0; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index e6930e9ee69d..c7ea531d30ef 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -768,6 +768,8 @@ int br_fdb_hash_init(struct net_bridge *br); void br_fdb_hash_fini(struct net_bridge *br); void br_fdb_flush(struct net_bridge *br, const struct net_bridge_fdb_flush_desc *desc); +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, + struct netlink_ext_ack *extack); void br_fdb_find_delete_local(struct net_bridge *br, const struct net_bridge_port *p, const unsigned char *addr, u16 vid);
Add a new fdb flush call which parses the embedded attributes in BRIDGE_FLUSH_FDB and fills in the fdb flush descriptor to delete only matching entries. Currently it's a complete flush, support for more fine-grained filtering will be added in the following patches. Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org> --- include/uapi/linux/if_bridge.h | 8 ++++++++ net/bridge/br_fdb.c | 24 ++++++++++++++++++++++++ net/bridge/br_netlink.c | 8 ++++++++ net/bridge/br_private.h | 2 ++ 4 files changed, 42 insertions(+)