Subject: Re: [RFC PATCH net-next 1/2] net: bridge: add switchdev attr for port bridging

From: Sergei Shtylyov <[email-masked]>
Date: Wed, 9 Mar 2016 22:26:35 +0300

Hello.

On 03/09/2016 08:42 PM, Vivien Didelot wrote:

> Add a new SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF switchdev attribute which is
> set before adding a port to a bridge and deleting a port from a bridge.
>
> The main purpose for this attribute is to provide switchdev users a
> simple and common way to retrieve bridging information, instead of
> implementing complex notifier blocks to listen to global netdev events.
>
> We can also imagine a switchdev user returning an error different from
> -EOPNOTSUPP in the prepare phase to prevent a port from being bridged.
>
> Signed-off-by: Vivien Didelot <[email-masked]>
> ---
>   include/net/switchdev.h |  2 ++
>   net/bridge/br_if.c      | 27 +++++++++++++++++++++++++++
>   2 files changed, 29 insertions(+)
>
[...]
> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index a73df33..105b9fd 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -28,6 +28,24 @@
>
>   #include "br_private.h"
>
> +static int switchdev_bridge_if(struct net_device *dev, struct net_bridge *br,
> +			       bool join)
> +{
> +	struct switchdev_attr attr = {
> +		.orig_dev = br->dev,
> +		.id = SWITCHDEV_ATTR_ID_PORT_BRIDGE_IF,
> +		.flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
> +		.u.join = join,
> +	};
> +	int err;
> +
> +	err = switchdev_port_attr_set(dev, &attr);
> +	if (err && err != -EOPNOTSUPP)

    Enough to only do the latter comparison.

> +		return err;
> +
> +	return 0;
> +}
> +
>   /*
>    * Determine initial path cost based on speed.
>    * using recommendations from 802.1d standard
[...]

MBR, Sergei