On 11/04/2022 11:47, Ido Schimmel wrote: > On Sat, Apr 09, 2022 at 01:58:55PM +0300, Nikolay Aleksandrov wrote: >> Add support for fdb flush filtering based on ndm flags and state. The >> new attributes allow users to specify a mask and value which are mapped >> to bridge-specific flags. NTF_USE is used to represent added_by_user >> flag since it sets it on fdb add and we don't have a 1:1 mapping for it. >> >> Signed-off-by: Nikolay Aleksandrov <razor@xxxxxxxxxxxxx> >> --- >> include/uapi/linux/if_bridge.h | 4 +++ >> net/bridge/br_fdb.c | 55 ++++++++++++++++++++++++++++++++++ >> 2 files changed, 59 insertions(+) >> >> diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h >> index 2f3799cf14b2..4638d7e39f2a 100644 >> --- a/include/uapi/linux/if_bridge.h >> +++ b/include/uapi/linux/if_bridge.h >> @@ -815,6 +815,10 @@ enum { >> /* embedded in BRIDGE_FLUSH_FDB */ >> enum { >> FDB_FLUSH_UNSPEC, >> + FDB_FLUSH_NDM_STATE, >> + FDB_FLUSH_NDM_STATE_MASK, >> + FDB_FLUSH_NDM_FLAGS, >> + FDB_FLUSH_NDM_FLAGS_MASK, >> __FDB_FLUSH_MAX >> }; >> #define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) >> diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c >> index 62f694a739e1..340a2ace1d5e 100644 >> --- a/net/bridge/br_fdb.c >> +++ b/net/bridge/br_fdb.c >> @@ -594,8 +594,40 @@ void br_fdb_flush(struct net_bridge *br, >> rcu_read_unlock(); >> } >> >> +static unsigned long __ndm_state_to_fdb_flags(u16 ndm_state) >> +{ >> + unsigned long flags = 0; >> + >> + if (ndm_state & NUD_PERMANENT) >> + __set_bit(BR_FDB_LOCAL, &flags); >> + if (ndm_state & NUD_NOARP) >> + __set_bit(BR_FDB_STATIC, &flags); >> + >> + return flags; >> +} >> + >> +static unsigned long __ndm_flags_to_fdb_flags(u16 ndm_flags) >> +{ >> + unsigned long flags = 0; >> + >> + if (ndm_flags & NTF_USE) >> + __set_bit(BR_FDB_ADDED_BY_USER, &flags); >> + if (ndm_flags & NTF_EXT_LEARNED) >> + __set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &flags); >> + if (ndm_flags & NTF_OFFLOADED) >> + __set_bit(BR_FDB_OFFLOADED, &flags); >> + if (ndm_flags & NTF_STICKY) >> + __set_bit(BR_FDB_STICKY, &flags); >> + >> + return flags; >> +} >> + >> static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { >> [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, >> + [FDB_FLUSH_NDM_STATE] = { .type = NLA_U16 }, >> + [FDB_FLUSH_NDM_FLAGS] = { .type = NLA_U16 }, >> + [FDB_FLUSH_NDM_STATE_MASK] = { .type = NLA_U16 }, >> + [FDB_FLUSH_NDM_FLAGS_MASK] = { .type = NLA_U16 }, > > Might be better to use NLA_POLICY_MASK(NLA_U16, mask) and reject > unsupported states / flags instead of just ignoring them? > Yep, forgot about that one. Good point!