From 5979fcb0a6855ddc8fa3b3a20d6ba37c1856d040 Mon Sep 17 00:00:00 2001 From: Lokesh Dhoundiyal Date: Thu, 28 Sep 2023 12:04:57 +1300 Subject: route/link: add bonding interface options set rtnl apis [thaller@redhat.com: fixed wrong variable name in code and reworded commit message.] https://github.com/thom311/libnl/pull/363 --- include/netlink/route/link/bonding.h | 3 ++ lib/route/link/bonding.c | 70 ++++++++++++++++++++++++++++++++++++ libnl-route-3.sym | 7 ++++ 3 files changed, 80 insertions(+) diff --git a/include/netlink/route/link/bonding.h b/include/netlink/route/link/bonding.h index e85b44a..e12d8a5 100644 --- a/include/netlink/route/link/bonding.h +++ b/include/netlink/route/link/bonding.h @@ -27,6 +27,9 @@ extern int rtnl_link_bond_release(struct nl_sock *, struct rtnl_link *); extern void rtnl_link_bond_set_mode(struct rtnl_link *link, uint8_t mode); extern void rtnl_link_bond_set_activeslave(struct rtnl_link *link, int active_slave); +extern void rtnl_link_bond_set_hashing_type (struct rtnl_link *link, uint8_t type); +extern void rtnl_link_bond_set_miimon (struct rtnl_link *link, uint32_t miimon); +extern void rtnl_link_bond_set_min_links (struct rtnl_link *link, uint32_t min_links); #ifdef __cplusplus } diff --git a/lib/route/link/bonding.c b/lib/route/link/bonding.c index 640a62c..63fd474 100644 --- a/lib/route/link/bonding.c +++ b/lib/route/link/bonding.c @@ -24,11 +24,17 @@ #define BOND_HAS_MODE (1 << 0) #define BOND_HAS_ACTIVE_SLAVE (1 << 1) +#define BOND_HAS_HASHING_TYPE (1 << 2) +#define BOND_HAS_MIIMON (1 << 3) +#define BOND_HAS_MIN_LINKS (1 << 4) struct bond_info { uint8_t bn_mode; + uint8_t hashing_type; uint32_t ifindex; uint32_t bn_mask; + uint32_t miimon; + uint32_t min_links; }; static int bond_info_alloc(struct rtnl_link *link) @@ -67,6 +73,15 @@ static int bond_put_attrs(struct nl_msg *msg, struct rtnl_link *link) if (bn->bn_mask & BOND_HAS_ACTIVE_SLAVE) NLA_PUT_U32(msg, IFLA_BOND_ACTIVE_SLAVE, bn->ifindex); + if (bn->bn_mask & BOND_HAS_HASHING_TYPE) + NLA_PUT_U8(msg, IFLA_BOND_XMIT_HASH_POLICY, bn->hashing_type); + + if (bn->bn_mask & BOND_HAS_MIIMON) + NLA_PUT_U32(msg, IFLA_BOND_MIIMON, bn->miimon); + + if (bn->bn_mask & BOND_HAS_MIN_LINKS) + NLA_PUT_U32(msg, IFLA_BOND_MIN_LINKS, bn->min_links); + nla_nest_end(msg, data); return 0; @@ -126,6 +141,61 @@ void rtnl_link_bond_set_mode(struct rtnl_link *link, uint8_t mode) } /** + * Set hashing type + * @arg link Link object of type bond + * @arg type bond hashing type to set + * + * @return void + */ +void rtnl_link_bond_set_hashing_type (struct rtnl_link *link, uint8_t type) +{ + struct bond_info *bn = link->l_info; + + IS_BOND_INFO_ASSERT(link); + + bn->hashing_type = type; + + bn->bn_mask |= BOND_HAS_HASHING_TYPE; +} + +/** + * Set MII monitoring interval + * @arg link Link object of type bond + * @arg miimon interval in milliseconds + * + * @return void + */ +void rtnl_link_bond_set_miimon (struct rtnl_link *link, uint32_t miimon) +{ + struct bond_info *bn = link->l_info; + + IS_BOND_INFO_ASSERT(link); + + bn->miimon = miimon; + + bn->bn_mask |= BOND_HAS_MIIMON; +} + +/** + * Set the minimum number of member ports that must be up before + * marking the bond device as up + * @arg link Link object of type bond + * @arg min_links Number of links + * + * @return void + */ +void rtnl_link_bond_set_min_links (struct rtnl_link *link, uint32_t min_links) +{ + struct bond_info *bn = link->l_info; + + IS_BOND_INFO_ASSERT(link); + + bn->min_links = min_links; + + bn->bn_mask |= BOND_HAS_MIN_LINKS; +} + +/** * Allocate link object of type bond * * @return Allocated link object or NULL. diff --git a/libnl-route-3.sym b/libnl-route-3.sym index 7e36de1..294d9f9 100644 --- a/libnl-route-3.sym +++ b/libnl-route-3.sym @@ -1306,3 +1306,10 @@ global: rtnl_nh_set_fdb; rtnl_nh_set_gateway; } libnl_3_7; + +libnl_3_9 { +global: + rtnl_link_bond_set_hashing_type; + rtnl_link_bond_set_miimon; + rtnl_link_bond_set_min_links; +} libnl_3_8; -- cgit v0.12