[PATCH 3/3] Modify link/bridge to set attributes

Jef Oliver jef.oliver at intel.com
Fri Aug 26 19:19:51 PDT 2016


This patch modifies link/bridge to set link attributes in a
request message. It adds set support for currently implemented
functionality.

This patch adds bridge_fill_pi, a function to fill in the
IFLA_PROTINFO nested attribute.

This patch modifies the bridge_ops structure to support
modifications made to properly set RTM_SETLINK during modifcation
of a link, append the NLA_F_NESTED flag to IFLA_PROTINFO, and
to call the newly added bridge_fill_pi.

Signed-off-by: Jef Oliver <jef.oliver at intel.com>
---
 lib/route/link/bridge.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c
index 330ac53..91e6c3c 100644
--- a/lib/route/link/bridge.c
+++ b/lib/route/link/bridge.c
@@ -224,6 +224,45 @@ static int bridge_parse_af_full(struct rtnl_link *link, struct nlattr *attr_full
 	return 0;
 }
 
+static int bridge_fill_pi(struct rtnl_link *link, struct nl_msg *msg,
+		   void *data)
+{
+	struct bridge_data *bd = data;
+
+	if (bd->ce_mask & BRIDGE_ATTR_FLAGS) {
+		if (bd->b_flags_mask & RTNL_BRIDGE_BPDU_GUARD) {
+			NLA_PUT_U8(msg, IFLA_BRPORT_GUARD,
+						bd->b_flags & RTNL_BRIDGE_BPDU_GUARD);
+		}
+		if (bd->b_flags_mask & RTNL_BRIDGE_HAIRPIN_MODE) {
+			NLA_PUT_U8(msg, IFLA_BRPORT_MODE,
+						bd->b_flags & RTNL_BRIDGE_HAIRPIN_MODE);
+		}
+		if (bd->b_flags_mask & RTNL_BRIDGE_FAST_LEAVE) {
+			NLA_PUT_U8(msg, IFLA_BRPORT_MODE,
+						bd->b_flags & RTNL_BRIDGE_FAST_LEAVE);
+		}
+		if (bd->b_flags_mask & RTNL_BRIDGE_ROOT_BLOCK) {
+			NLA_PUT_U8(msg, IFLA_BRPORT_PROTECT,
+						bd->b_flags & RTNL_BRIDGE_ROOT_BLOCK);
+		}
+	}
+
+	if (bd->ce_mask & BRIDGE_ATTR_COST)
+		NLA_PUT_U32(msg, IFLA_BRPORT_COST, bd->b_cost);
+
+	if (bd->ce_mask & BRIDGE_ATTR_PRIORITY)
+		NLA_PUT_U16(msg, IFLA_BRPORT_PRIORITY, bd->b_priority);
+
+	if (bd->ce_mask & BRIDGE_ATTR_PORT_STATE)
+		NLA_PUT_U8(msg, IFLA_BRPORT_STATE, bd->b_port_state);
+
+	return 0;
+
+nla_put_failure:
+	return -NLE_MSGSIZE;
+}
+
 static int bridge_get_af(struct nl_msg *msg, uint32_t *ext_filter_mask)
 {
 	*ext_filter_mask |= RTEXT_FILTER_BRVLAN;
@@ -728,6 +767,9 @@ static struct rtnl_link_af_ops bridge_ops = {
 	.ao_compare			= &bridge_compare,
 	.ao_parse_af_full		= &bridge_parse_af_full,
 	.ao_get_af			= &bridge_get_af,
+	.ao_fill_pi			= &bridge_fill_pi,
+	.ao_fill_pi_flags	= NLA_F_NESTED,
+	.ao_override_rtm	= 1,
 };
 
 static void __init bridge_init(void)
-- 
2.9.3




More information about the libnl mailing list