summaryrefslogtreecommitdiffstats
path: root/lib/route
diff options
context:
space:
mode:
authorJonas Johansson <jonas.johansson@westermo.se>2015-04-21 07:00:58 (GMT)
committerVolodymyr Bendiuga <volodymyr.bendiuga@westermo.se>2022-03-10 11:53:12 (GMT)
commit831f125996b695786ee5c041b5d69f1efb9ccd88 (patch)
tree15c3af6c95c74c04a5a87f9ae83af095fd8b140f /lib/route
parent6c595805e139b6fe186a4f53e04915b62d1221f1 (diff)
downloadlibnl-831f125996b695786ee5c041b5d69f1efb9ccd88.zip
libnl-831f125996b695786ee5c041b5d69f1efb9ccd88.tar.gz
libnl-831f125996b695786ee5c041b5d69f1efb9ccd88.tar.bz2
route/link: add support for team device
Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
Diffstat (limited to 'lib/route')
-rw-r--r--lib/route/link/team.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/route/link/team.c b/lib/route/link/team.c
new file mode 100644
index 0000000..5e35be2
--- /dev/null
+++ b/lib/route/link/team.c
@@ -0,0 +1,109 @@
+/*
+ * lib/route/link/team.c Team Link Module
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2015 Jonas Johansson <jonasj76@gmail.com>
+ */
+
+/**
+ * @ingroup link
+ * @defgroup team Team
+ *
+ * @details
+ * \b Link Type Name: "team"
+ *
+ * @route_doc{link_team, Team Documentation}
+ * @{
+ */
+
+#include <netlink-private/netlink.h>
+#include <netlink/netlink.h>
+#include <netlink-private/route/link/api.h>
+#include <netlink/route/link/team.h>
+
+/**
+ * Allocate link object of type team
+ *
+ * @return Allocated link object or NULL.
+ */
+struct rtnl_link *rtnl_link_team_alloc(void)
+{
+ struct rtnl_link *link;
+ int err;
+
+ if (!(link = rtnl_link_alloc()))
+ return NULL;
+
+ if ((err = rtnl_link_set_type(link, "team")) < 0) {
+ rtnl_link_put(link);
+ return NULL;
+ }
+
+ return link;
+}
+
+/**
+ * Create a new kernel team device
+ * @arg sock netlink socket
+ * @arg name name of team device or NULL
+ * @arg opts team options (currently unused)
+ *
+ * Creates a new team device in the kernel. If no name is
+ * provided, the kernel will automatically pick a name of the
+ * form "type%d" (e.g. team0, vlan1, etc.)
+ *
+ * The \a opts argument is currently unused. In the future, it
+ * may be used to carry additional team options to be set
+ * when creating the team device.
+ *
+ * @note When letting the kernel assign a name, it will become
+ * difficult to retrieve the interface afterwards because
+ * you have to guess the name the kernel has chosen. It is
+ * therefore not recommended to not provide a device name.
+ *
+ * @see rtnl_link_team_enslave()
+ * @see rtnl_link_team_release()
+ *
+ * @return 0 on success or a negative error code
+ */
+int rtnl_link_team_add(struct nl_sock *sock, const char *name,
+ struct rtnl_link *opts)
+{
+ struct rtnl_link *link;
+ int err;
+
+ if (!(link = rtnl_link_team_alloc()))
+ return -NLE_NOMEM;
+
+ if (!name && opts)
+ name = rtnl_link_get_name(opts);
+
+ if (name)
+ rtnl_link_set_name(link, name);
+
+ err = rtnl_link_add(sock, link, NLM_F_CREATE);
+
+ rtnl_link_put(link);
+
+ return err;
+}
+
+static struct rtnl_link_info_ops team_info_ops = {
+ .io_name = "team",
+};
+
+static void __init team_init(void)
+{
+ rtnl_link_register_info(&team_info_ops);
+}
+
+static void __exit team_exit(void)
+{
+ rtnl_link_unregister_info(&team_info_ops);
+}
+
+/** @} */