2020-07-01 07:23:27

by Horatiu Vultur

[permalink] [raw]
Subject: [PATCH net-next v2 0/3] bridge: mrp: Add support for getting the status

This patch series extends the MRP netlink interface to allow the userspace
daemon to get the status of the MRP instances in the kernel.

v2:
- fix sparse warnings

Horatiu Vultur (3):
bridge: uapi: mrp: Extend MRP attributes to get the status
bridge: mrp: Add br_mrp_fill_info
bridge: Extend br_fill_ifinfo to return MPR status

include/uapi/linux/if_bridge.h | 17 +++++++++
include/uapi/linux/rtnetlink.h | 1 +
net/bridge/br_mrp_netlink.c | 64 ++++++++++++++++++++++++++++++++++
net/bridge/br_netlink.c | 29 ++++++++++++++-
net/bridge/br_private.h | 7 ++++
5 files changed, 117 insertions(+), 1 deletion(-)

--
2.27.0


2020-07-01 07:23:38

by Horatiu Vultur

[permalink] [raw]
Subject: [PATCH net-next v2 1/3] bridge: uapi: mrp: Extend MRP attributes to get the status

Add MRP attribute IFLA_BRIDGE_MRP_INFO to allow the userspace to get the
current state of the MRP instances. This is a nested attribute that
contains other attributes like, ring id, index of primary and secondary
port, priority, ring state, ring role.

Signed-off-by: Horatiu Vultur <[email protected]>
---
include/uapi/linux/if_bridge.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h
index caa6914a3e53a..c114c1c2bd533 100644
--- a/include/uapi/linux/if_bridge.h
+++ b/include/uapi/linux/if_bridge.h
@@ -166,6 +166,7 @@ enum {
IFLA_BRIDGE_MRP_RING_STATE,
IFLA_BRIDGE_MRP_RING_ROLE,
IFLA_BRIDGE_MRP_START_TEST,
+ IFLA_BRIDGE_MRP_INFO,
__IFLA_BRIDGE_MRP_MAX,
};

@@ -228,6 +229,22 @@ enum {

#define IFLA_BRIDGE_MRP_START_TEST_MAX (__IFLA_BRIDGE_MRP_START_TEST_MAX - 1)

+enum {
+ IFLA_BRIDGE_MRP_INFO_UNSPEC,
+ IFLA_BRIDGE_MRP_INFO_RING_ID,
+ IFLA_BRIDGE_MRP_INFO_P_IFINDEX,
+ IFLA_BRIDGE_MRP_INFO_S_IFINDEX,
+ IFLA_BRIDGE_MRP_INFO_PRIO,
+ IFLA_BRIDGE_MRP_INFO_RING_STATE,
+ IFLA_BRIDGE_MRP_INFO_RING_ROLE,
+ IFLA_BRIDGE_MRP_INFO_TEST_INTERVAL,
+ IFLA_BRIDGE_MRP_INFO_TEST_MAX_MISS,
+ IFLA_BRIDGE_MRP_INFO_TEST_MONITOR,
+ __IFLA_BRIDGE_MRP_INFO_MAX,
+};
+
+#define IFLA_BRIDGE_MRP_INFO_MAX (__IFLA_BRIDGE_MRP_INFO_MAX - 1)
+
struct br_mrp_instance {
__u32 ring_id;
__u32 p_ifindex;
--
2.27.0

2020-07-01 07:26:29

by Horatiu Vultur

[permalink] [raw]
Subject: [PATCH net-next v2 3/3] bridge: Extend br_fill_ifinfo to return MPR status

This patch extends the function br_fill_ifinfo to return also the MRP
status for each instance on a bridge. It also adds a new filter
RTEXT_FILTER_MRP to return the MRP status only when this is set, not to
interfer with the vlans. The MRP status is return only on the bridge
interfaces.

Signed-off-by: Horatiu Vultur <[email protected]>
---
include/uapi/linux/rtnetlink.h | 1 +
net/bridge/br_netlink.c | 29 ++++++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 879e64950a0a2..9b814c92de123 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -778,6 +778,7 @@ enum {
#define RTEXT_FILTER_BRVLAN (1 << 1)
#define RTEXT_FILTER_BRVLAN_COMPRESSED (1 << 2)
#define RTEXT_FILTER_SKIP_STATS (1 << 3)
+#define RTEXT_FILTER_MRP (1 << 4)

/* End of information exported to user level */

diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 240e260e3461c..6ecb7c7453dcb 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -453,6 +453,32 @@ static int br_fill_ifinfo(struct sk_buff *skb,
rcu_read_unlock();
if (err)
goto nla_put_failure;
+
+ nla_nest_end(skb, af);
+ }
+
+ if (filter_mask & RTEXT_FILTER_MRP) {
+ struct nlattr *af;
+ int err;
+
+ /* RCU needed because of the VLAN locking rules (rcu || rtnl) */
+ rcu_read_lock();
+ if (!br_mrp_enabled(br) || port) {
+ rcu_read_unlock();
+ goto done;
+ }
+ af = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
+ if (!af) {
+ rcu_read_unlock();
+ goto nla_put_failure;
+ }
+
+ err = br_mrp_fill_info(skb, br);
+
+ rcu_read_unlock();
+ if (err)
+ goto nla_put_failure;
+
nla_nest_end(skb, af);
}

@@ -516,7 +542,8 @@ int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
struct net_bridge_port *port = br_port_get_rtnl(dev);

if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) &&
- !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
+ !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) &&
+ !(filter_mask & RTEXT_FILTER_MRP))
return 0;

return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
--
2.27.0

2020-07-01 07:26:40

by Horatiu Vultur

[permalink] [raw]
Subject: [PATCH net-next v2 2/3] bridge: mrp: Add br_mrp_fill_info

Add the function br_mrp_fill_info which populates the MRP attributes
regarding the status of each MRP instance.

Signed-off-by: Horatiu Vultur <[email protected]>
---
net/bridge/br_mrp_netlink.c | 64 +++++++++++++++++++++++++++++++++++++
net/bridge/br_private.h | 7 ++++
2 files changed, 71 insertions(+)

diff --git a/net/bridge/br_mrp_netlink.c b/net/bridge/br_mrp_netlink.c
index 34b3a8776991f..c4e80844e53bd 100644
--- a/net/bridge/br_mrp_netlink.c
+++ b/net/bridge/br_mrp_netlink.c
@@ -304,6 +304,70 @@ int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
return 0;
}

+int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
+{
+ struct nlattr *tb, *mrp_tb;
+ struct br_mrp *mrp;
+
+ mrp_tb = nla_nest_start_noflag(skb, IFLA_BRIDGE_MRP);
+ if (!mrp_tb)
+ return -EMSGSIZE;
+
+ list_for_each_entry(mrp, &br->mrp_list, list) {
+ struct net_bridge_port *p;
+
+ tb = nla_nest_start_noflag(skb, IFLA_BRIDGE_MRP_INFO);
+ if (!tb)
+ goto nla_info_failure;
+
+ if (nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_RING_ID,
+ mrp->ring_id))
+ goto nla_put_failure;
+
+ p = rtnl_dereference(mrp->p_port);
+ if (p && nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_P_IFINDEX,
+ p->dev->ifindex))
+ goto nla_put_failure;
+
+ p = rtnl_dereference(mrp->s_port);
+ if (p && nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_S_IFINDEX,
+ p->dev->ifindex))
+ goto nla_put_failure;
+
+ if (nla_put_u16(skb, IFLA_BRIDGE_MRP_INFO_PRIO,
+ mrp->prio))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_RING_STATE,
+ mrp->ring_state))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_RING_ROLE,
+ mrp->ring_role))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_TEST_INTERVAL,
+ mrp->test_interval))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_TEST_MAX_MISS,
+ mrp->test_max_miss))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_TEST_MONITOR,
+ mrp->test_monitor))
+ goto nla_put_failure;
+
+ nla_nest_end(skb, tb);
+ }
+ nla_nest_end(skb, mrp_tb);
+
+ return 0;
+
+nla_put_failure:
+ nla_nest_cancel(skb, tb);
+
+nla_info_failure:
+ nla_nest_cancel(skb, mrp_tb);
+
+ return -EMSGSIZE;
+}
+
int br_mrp_port_open(struct net_device *dev, u8 loc)
{
struct net_bridge_port *p;
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 6a7d8e218ae7e..65d2c163a24ab 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1317,6 +1317,7 @@ int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
int br_mrp_process(struct net_bridge_port *p, struct sk_buff *skb);
bool br_mrp_enabled(struct net_bridge *br);
void br_mrp_port_del(struct net_bridge *br, struct net_bridge_port *p);
+int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br);
#else
static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p,
struct nlattr *attr, int cmd,
@@ -1339,6 +1340,12 @@ static inline void br_mrp_port_del(struct net_bridge *br,
struct net_bridge_port *p)
{
}
+
+static inline int br_mrp_fill_info(struct sk_buff *skb, struct net_bridge *br)
+{
+ return 0;
+}
+
#endif

/* br_netlink.c */
--
2.27.0

2020-07-01 09:52:37

by Nikolay Aleksandrov

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/3] bridge: Extend br_fill_ifinfo to return MPR status

On 01/07/2020 10:22, Horatiu Vultur wrote:
> This patch extends the function br_fill_ifinfo to return also the MRP
> status for each instance on a bridge. It also adds a new filter
> RTEXT_FILTER_MRP to return the MRP status only when this is set, not to
> interfer with the vlans. The MRP status is return only on the bridge
> interfaces.
>
> Signed-off-by: Horatiu Vultur <[email protected]>
> ---
> include/uapi/linux/rtnetlink.h | 1 +
> net/bridge/br_netlink.c | 29 ++++++++++++++++++++++++++++-
> 2 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> index 879e64950a0a2..9b814c92de123 100644
> --- a/include/uapi/linux/rtnetlink.h
> +++ b/include/uapi/linux/rtnetlink.h
> @@ -778,6 +778,7 @@ enum {
> #define RTEXT_FILTER_BRVLAN (1 << 1)
> #define RTEXT_FILTER_BRVLAN_COMPRESSED (1 << 2)
> #define RTEXT_FILTER_SKIP_STATS (1 << 3)
> +#define RTEXT_FILTER_MRP (1 << 4)
>
> /* End of information exported to user level */
>
> diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
> index 240e260e3461c..6ecb7c7453dcb 100644
> --- a/net/bridge/br_netlink.c
> +++ b/net/bridge/br_netlink.c
> @@ -453,6 +453,32 @@ static int br_fill_ifinfo(struct sk_buff *skb,
> rcu_read_unlock();
> if (err)
> goto nla_put_failure;
> +
> + nla_nest_end(skb, af);
> + }
> +
> + if (filter_mask & RTEXT_FILTER_MRP) {
> + struct nlattr *af;
> + int err;
> +
> + /* RCU needed because of the VLAN locking rules (rcu || rtnl) */
> + rcu_read_lock();

If you're using RCU, then in the previous patch (02) you should be using RCU primitives
to walk the list and deref the ports.
Alternatively if you rely on rtnl only then drop these RCU locks here as they're misleading.

I'd prefer to just use RCU for it in case we drop rtnl one day when dumping.

> + if (!br_mrp_enabled(br) || port) {
> + rcu_read_unlock();
> + goto done;
> + }
> + af = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
> + if (!af) {
> + rcu_read_unlock();
> + goto nla_put_failure;
> + }
> +
> + err = br_mrp_fill_info(skb, br);
> +
> + rcu_read_unlock();
> + if (err)
> + goto nla_put_failure;
> +
> nla_nest_end(skb, af);
> }
>
> @@ -516,7 +542,8 @@ int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
> struct net_bridge_port *port = br_port_get_rtnl(dev);
>
> if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) &&
> - !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
> + !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) &&
> + !(filter_mask & RTEXT_FILTER_MRP))
> return 0;
>
> return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
>

2020-07-01 13:22:39

by Horatiu Vultur

[permalink] [raw]
Subject: Re: [PATCH net-next v2 3/3] bridge: Extend br_fill_ifinfo to return MPR status

The 07/01/2020 12:51, Nikolay Aleksandrov wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> On 01/07/2020 10:22, Horatiu Vultur wrote:
> > This patch extends the function br_fill_ifinfo to return also the MRP
> > status for each instance on a bridge. It also adds a new filter
> > RTEXT_FILTER_MRP to return the MRP status only when this is set, not to
> > interfer with the vlans. The MRP status is return only on the bridge
> > interfaces.
> >
> > Signed-off-by: Horatiu Vultur <[email protected]>
> > ---
> > include/uapi/linux/rtnetlink.h | 1 +
> > net/bridge/br_netlink.c | 29 ++++++++++++++++++++++++++++-
> > 2 files changed, 29 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> > index 879e64950a0a2..9b814c92de123 100644
> > --- a/include/uapi/linux/rtnetlink.h
> > +++ b/include/uapi/linux/rtnetlink.h
> > @@ -778,6 +778,7 @@ enum {
> > #define RTEXT_FILTER_BRVLAN (1 << 1)
> > #define RTEXT_FILTER_BRVLAN_COMPRESSED (1 << 2)
> > #define RTEXT_FILTER_SKIP_STATS (1 << 3)
> > +#define RTEXT_FILTER_MRP (1 << 4)
> >
> > /* End of information exported to user level */
> >
> > diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
> > index 240e260e3461c..6ecb7c7453dcb 100644
> > --- a/net/bridge/br_netlink.c
> > +++ b/net/bridge/br_netlink.c
> > @@ -453,6 +453,32 @@ static int br_fill_ifinfo(struct sk_buff *skb,
> > rcu_read_unlock();
> > if (err)
> > goto nla_put_failure;
> > +
> > + nla_nest_end(skb, af);
> > + }
> > +
> > + if (filter_mask & RTEXT_FILTER_MRP) {
> > + struct nlattr *af;
> > + int err;
> > +
> > + /* RCU needed because of the VLAN locking rules (rcu || rtnl) */
> > + rcu_read_lock();

Hi Nik,
>
> If you're using RCU, then in the previous patch (02) you should be using RCU primitives
> to walk the list and deref the ports.
> Alternatively if you rely on rtnl only then drop these RCU locks here as they're misleading.
>
> I'd prefer to just use RCU for it in case we drop rtnl one day when dumping.

Thanks for the comments. I will create a new series where I will use the
RCU.

>
> > + if (!br_mrp_enabled(br) || port) {
> > + rcu_read_unlock();
> > + goto done;
> > + }
> > + af = nla_nest_start_noflag(skb, IFLA_AF_SPEC);
> > + if (!af) {
> > + rcu_read_unlock();
> > + goto nla_put_failure;
> > + }
> > +
> > + err = br_mrp_fill_info(skb, br);
> > +
> > + rcu_read_unlock();
> > + if (err)
> > + goto nla_put_failure;
> > +
> > nla_nest_end(skb, af);
> > }
> >
> > @@ -516,7 +542,8 @@ int br_getlink(struct sk_buff *skb, u32 pid, u32 seq,
> > struct net_bridge_port *port = br_port_get_rtnl(dev);
> >
> > if (!port && !(filter_mask & RTEXT_FILTER_BRVLAN) &&
> > - !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED))
> > + !(filter_mask & RTEXT_FILTER_BRVLAN_COMPRESSED) &&
> > + !(filter_mask & RTEXT_FILTER_MRP))
> > return 0;
> >
> > return br_fill_ifinfo(skb, port, pid, seq, RTM_NEWLINK, nlflags,
> >
>

--
/Horatiu