bridge: mrp: Add br_mrp_fill_info
authorHoratiu Vultur <horatiu.vultur@microchip.com>
Thu, 2 Jul 2020 08:13:06 +0000 (10:13 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 2 Jul 2020 21:19:15 +0000 (14:19 -0700)
Add the function br_mrp_fill_info which populates the MRP attributes
regarding the status of each MRP instance.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/bridge/br_mrp_netlink.c
net/bridge/br_private.h

index 34b3a87..c4f5c35 100644 (file)
@@ -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_rcu(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 = rcu_dereference(mrp->p_port);
+               if (p && nla_put_u32(skb, IFLA_BRIDGE_MRP_INFO_P_IFINDEX,
+                                    p->dev->ifindex))
+                       goto nla_put_failure;
+
+               p = rcu_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;
index 6a7d8e2..65d2c16 100644 (file)
@@ -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 */