summaryrefslogtreecommitdiffstats
path: root/src/nl-link-enslave.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@redhat.com>2011-09-16 10:57:52 (GMT)
committerThomas Graf <tgraf@redhat.com>2011-09-16 10:57:52 (GMT)
commit96f17ce146b35fda3f745a418352d731c522265e (patch)
treeebe42825cd376471ec8c0dc3326a29ff0a85cdb0 /src/nl-link-enslave.c
parent5151cbc2f6e5ca81cfc66eeb1d4a5c6c4e886108 (diff)
downloadlibnl-96f17ce146b35fda3f745a418352d731c522265e.zip
libnl-96f17ce146b35fda3f745a418352d731c522265e.tar.gz
libnl-96f17ce146b35fda3f745a418352d731c522265e.tar.bz2
bonding: API to create/enslave/release
Although it has been possible to create bonding devices, enslave and release using the regular link API. The added API simplifies usage and hides some of the compatibility logic. F.e. enslave() and release() will both verify that the master assignment has in fact been changed and return -NLE_OPNOTSUPP if it did not. Also the API will make sure to use RTM_NEWLINK or RTM_SETLINK depending on what is availble. Examples are provided in src/ as nl-link-enslave.c and nl-link-release.c
Diffstat (limited to 'src/nl-link-enslave.c')
-rw-r--r--src/nl-link-enslave.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/nl-link-enslave.c b/src/nl-link-enslave.c
new file mode 100644
index 0000000..2b5d47d
--- /dev/null
+++ b/src/nl-link-enslave.c
@@ -0,0 +1,50 @@
+/*
+ * src/nl-link-enslave.c Enslave a link
+ *
+ * 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) 2011 Thomas Graf <tgraf@suug.ch>
+ */
+
+#include <netlink/cli/utils.h>
+#include <netlink/cli/link.h>
+#include <netlink/route/link/bonding.h>
+
+int main(int argc, char *argv[])
+{
+ struct nl_sock *sock;
+ struct nl_cache *link_cache;
+ struct rtnl_link *master, *slave;
+ int err;
+
+ if (argc < 3) {
+ fprintf(stderr, "Usage: nl-link-enslave master slave\n");
+ return 1;
+ }
+
+ sock = nl_cli_alloc_socket();
+ nl_cli_connect(sock, NETLINK_ROUTE);
+ link_cache = nl_cli_link_alloc_cache(sock);
+
+ if (!(master = rtnl_link_get_by_name(link_cache, argv[1]))) {
+ fprintf(stderr, "Unknown link: %s\n", argv[1]);
+ return 1;
+ }
+
+ if (!(slave = rtnl_link_get_by_name(link_cache, argv[2]))) {
+ fprintf(stderr, "Unknown link: %s\n", argv[2]);
+ return 1;
+ }
+
+ if ((err = rtnl_link_bond_enslave(sock, master, slave)) < 0) {
+ fprintf(stderr, "Unable to enslave %s to %s: %s\n",
+ argv[2], argv[1], nl_geterror(err));
+ return 1;
+ }
+
+ return 0;
+}
+