summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMallikarjun Nemagoudar <MallikarjunRamappa.Nemagoudar@infineon.com>2023-06-30 11:00:00 (GMT)
committerThomas Haller <thaller@redhat.com>2023-07-27 07:34:00 (GMT)
commitfc805c566c902b738238ef1632bc6bbeef65eb06 (patch)
tree5a1dd5036b65708f2573c678a1a27de0f82199f5
parent6af26981e727149e2e3fdfac85e2ef86b3828b11 (diff)
downloadlibnl-fc805c566c902b738238ef1632bc6bbeef65eb06.zip
libnl-fc805c566c902b738238ef1632bc6bbeef65eb06.tar.gz
libnl-fc805c566c902b738238ef1632bc6bbeef65eb06.tar.bz2
route/bond: Add support for link_info for bond
following API has been added to bonding bond_alloc bond_free rtnl_link_bond_set_activeslave rtnl_link_bond_set_mode bond_put_attrs Signed-off-by: Mallikarjun Nemagoudar <MallikarjunRamappa.Nemagoudar@infineon.com> https://github.com/thom311/libnl/pull/349
-rw-r--r--include/netlink/route/link/bonding.h3
-rw-r--r--lib/route/link/bonding.c107
-rw-r--r--libnl-route-3.sym2
3 files changed, 108 insertions, 4 deletions
diff --git a/include/netlink/route/link/bonding.h b/include/netlink/route/link/bonding.h
index 09d495e..e85b44a 100644
--- a/include/netlink/route/link/bonding.h
+++ b/include/netlink/route/link/bonding.h
@@ -25,6 +25,9 @@ extern int rtnl_link_bond_enslave(struct nl_sock *, struct rtnl_link *,
extern int rtnl_link_bond_release_ifindex(struct nl_sock *, int);
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);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/route/link/bonding.c b/lib/route/link/bonding.c
index 90e6470..10a186c 100644
--- a/lib/route/link/bonding.c
+++ b/lib/route/link/bonding.c
@@ -19,6 +19,109 @@
#include <netlink/route/link/bonding.h>
#include <netlink-private/route/link/api.h>
+#define BOND_HAS_MODE (1 << 0)
+#define BOND_HAS_ACTIVE_SLAVE (1 << 1)
+
+struct bond_info {
+ uint8_t bn_mode;
+ uint32_t ifindex;
+ uint32_t bn_mask;
+};
+
+static int bond_info_alloc(struct rtnl_link *link)
+{
+ struct bond_info *bn;
+
+ if (link->l_info)
+ memset(link->l_info, 0, sizeof(*bn));
+ else {
+ bn = calloc(1, sizeof(*bn));
+ if (!bn)
+ return -NLE_NOMEM;
+
+ link->l_info = bn;
+ }
+
+ return 0;
+}
+
+static void bond_info_free(struct rtnl_link *link)
+{
+ _nl_clear_free(&link->l_info);
+}
+
+static int bond_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
+{
+ struct bond_info *bn = link->l_info;
+ struct nlattr *data;
+
+ data = nla_nest_start(msg, IFLA_INFO_DATA);
+ if (!data)
+ return -NLE_MSGSIZE;
+ if (bn->bn_mask & BOND_HAS_MODE)
+ NLA_PUT_U8(msg, IFLA_BOND_MODE, bn->bn_mode);
+
+ if (bn->bn_mask & BOND_HAS_ACTIVE_SLAVE)
+ NLA_PUT_U32(msg, IFLA_BOND_ACTIVE_SLAVE, bn->ifindex);
+
+ nla_nest_end(msg, data);
+ return 0;
+
+nla_put_failure:
+ nla_nest_cancel(msg, data);
+ return -NLE_MSGSIZE;
+}
+
+static struct rtnl_link_info_ops bonding_info_ops = {
+ .io_name = "bond",
+ .io_alloc = bond_info_alloc,
+ .io_put_attrs = bond_put_attrs,
+ .io_free = bond_info_free,
+};
+
+#define IS_BOND_INFO_ASSERT(link) \
+ do { \
+ if (link->l_info_ops != &bonding_info_ops) { \
+ APPBUG("Link is not a bond link. Set type \"bond\" first."); \
+ } \
+ } while (0)
+
+/**
+ * Set active slave for bond
+ * @arg link Link object of type bond
+ * @arg active ifindex of active slave to set
+ *
+ * @return void
+ */
+void rtnl_link_bond_set_activeslave(struct rtnl_link *link, int active_slave)
+{
+ struct bond_info *bn = link->l_info;
+
+ IS_BOND_INFO_ASSERT(link);
+
+ bn->ifindex = active_slave;
+
+ bn->bn_mask |= BOND_HAS_ACTIVE_SLAVE;
+}
+
+/**
+ * Set bond mode
+ * @arg link Link object of type bond
+ * @arg mode bond mode to set
+ *
+ * @return void
+ */
+void rtnl_link_bond_set_mode(struct rtnl_link *link, uint8_t mode)
+{
+ struct bond_info *bn = link->l_info;
+
+ IS_BOND_INFO_ASSERT(link);
+
+ bn->bn_mode = mode;
+
+ bn->bn_mask |= BOND_HAS_MODE;
+}
+
/**
* Allocate link object of type bond
*
@@ -204,10 +307,6 @@ int rtnl_link_bond_release(struct nl_sock *sock, struct rtnl_link *slave)
rtnl_link_get_ifindex(slave));
}
-static struct rtnl_link_info_ops bonding_info_ops = {
- .io_name = "bond",
-};
-
static void __init bonding_init(void)
{
rtnl_link_register_info(&bonding_info_ops);
diff --git a/libnl-route-3.sym b/libnl-route-3.sym
index 01c8e1c..62cd423 100644
--- a/libnl-route-3.sym
+++ b/libnl-route-3.sym
@@ -1284,4 +1284,6 @@ global:
rtnl_link_bridge_set_vlan_protocol;
rtnl_link_bridge_set_vlan_stats_enabled;
rtnl_link_inet6_get_conf;
+ rtnl_link_bond_set_activeslave;
+ rtnl_link_bond_set_mode;
} libnl_3_7;