Re: [PATCH net-next 3/6] net: bridge: fdb: add new nl attribute-based flush call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
>> ---
>>  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@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
> 

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
>>




[Index of Archives]     [Netdev]     [AoE Tools]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux