]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
bond: Provide rtnl_link_bond_alloc()
authorThomas Graf <tgraf@suug.ch>
Thu, 14 Feb 2013 11:48:00 +0000 (12:48 +0100)
committerThomas Graf <tgraf@suug.ch>
Thu, 14 Feb 2013 11:48:00 +0000 (12:48 +0100)
Signed-off-by: Thomas Graf <tgraf@suug.ch>
doc/route.txt
include/netlink/route/link/bonding.h
lib/route/link/bonding.c
tests/test-create-bond.c

index cd24eefa577f7b4350e072cf46562053ca396c14..c8f1735031fb93adc7c49d2218bb892df27b25c4 100644 (file)
@@ -645,9 +645,8 @@ This attribute is unused and obsoleted in all recent kernels.
 
 struct rtnl_link *link;
 
-link = rtnl_link_alloc();
+link = rtnl_link_bond_alloc();
 rtnl_link_set_name(link, "my_bond");
-rtnl_link_set_type(link, "bond");
 
 /* requires admin privileges */
 if (rtnl_link_add(sk, link, NLM_F_CREATE) < 0)
index 78ee6bd7f439377c08caf6e4461cd6ef1a67f499..5c34662df7b3c0e8cae5ab90a495674941542723 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2011 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2011-2013 Thomas Graf <tgraf@suug.ch>
  */
 
 #ifndef NETLINK_LINK_BONDING_H_
@@ -19,6 +19,8 @@
 extern "C" {
 #endif
 
+extern struct rtnl_link *rtnl_link_bond_alloc(void);
+
 extern int     rtnl_link_bond_add(struct nl_sock *, const char *,
                                   struct rtnl_link *);
 
index b060ee1c6a552174927cb0cae14dbb99fa5bf756..f4c520bcc25368f5e7387cf81d7ba594c65ab7f5 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2011 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2011-2013 Thomas Graf <tgraf@suug.ch>
  */
 
 /**
 #include <netlink/netlink.h>
 #include <netlink-private/route/link/api.h>
 
+/**
+ * Allocate link object of type bond
+ *
+ * @return Allocated link object or NULL.
+ */
+struct rtnl_link *rtnl_link_bond_alloc(void)
+{
+       struct rtnl_link *link;
+       int err;
+
+       if (!(link = rtnl_link_alloc()))
+               return NULL;
+
+       if ((err = rtnl_link_set_type(link, "bond")) < 0) {
+               rtnl_link_put(link);
+               return NULL;
+       }
+
+       return link;
+}
+
 /**
  * Create a new kernel bonding device
  * @arg sock           netlink socket
@@ -54,22 +75,17 @@ int rtnl_link_bond_add(struct nl_sock *sock, const char *name,
        struct rtnl_link *link;
        int err;
 
-       if (!(link = rtnl_link_alloc()))
+       if (!(link = rtnl_link_bond_alloc()))
                return -NLE_NOMEM;
 
-       if (!name) {
-               if (opts)
-                       name = rtnl_link_get_name(opts);
-       }
-
-       if ((err = rtnl_link_set_type(link, "bond")) < 0)
-               goto errout;
+       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);
-errout:
+
        rtnl_link_put(link);
 
        return err;
@@ -94,12 +110,9 @@ int rtnl_link_bond_enslave_ifindex(struct nl_sock *sock, int master,
        struct rtnl_link *link;
        int err;
 
-       if (!(link = rtnl_link_alloc()))
+       if (!(link = rtnl_link_bond_alloc()))
                return -NLE_NOMEM;
 
-       if ((err = rtnl_link_set_type(link, "bond")) < 0)
-               goto errout;
-
        rtnl_link_set_ifindex(link, slave);
        rtnl_link_set_master(link, master);
        
index e54b0e6eab3a3f55a1ff49602612fc48c0dad42a..11bc5b09f4220b85d2d520febbe6561e689c63c0 100644 (file)
@@ -1,5 +1,6 @@
 #include <netlink/netlink.h>
 #include <netlink/route/link.h>
+#include <netlink/route/link/bonding.h>
 
 int main(int argc, char *argv[])
 {
@@ -13,14 +14,9 @@ int main(int argc, char *argv[])
                return err;
        }
 
-       link = rtnl_link_alloc();
+       link = rtnl_link_bond_alloc();
        rtnl_link_set_name(link, "my_bond");
 
-       if ((err = rtnl_link_set_type(link, "bond")) < 0) {
-               nl_perror(err, "Unable to set link info type");
-               return err;
-       }
-
        if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
                nl_perror(err, "Unable to add link");
                return err;