From: Jef Oliver Date: Sat, 27 Aug 2016 02:19:51 +0000 (-0700) Subject: lib/route: modify link/bridge to set attributes X-Git-Tag: libnl3_2_29rc1~19^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55bc931a7272e6ac8f555bcc2a373eb2b6b58377;p=libnl lib/route: modify link/bridge to set attributes 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 Signed-off-by: Thomas Haller --- 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)