summaryrefslogtreecommitdiffstats
path: root/lib/route/link/bonding.c
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2013-02-14 11:48:00 (GMT)
committerThomas Graf <tgraf@suug.ch>2013-02-14 11:48:00 (GMT)
commit1ecf98a23e4ba309eb1f94b824d5f973d3fee0d2 (patch)
treeb74b1115024866c5b27d8b986229fc70041ca0b8 /lib/route/link/bonding.c
parentee4122a12edcf7f10f03fbb7e35fe1388a8c3399 (diff)
downloadlibnl-1ecf98a23e4ba309eb1f94b824d5f973d3fee0d2.zip
libnl-1ecf98a23e4ba309eb1f94b824d5f973d3fee0d2.tar.gz
libnl-1ecf98a23e4ba309eb1f94b824d5f973d3fee0d2.tar.bz2
bond: Provide rtnl_link_bond_alloc()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Diffstat (limited to 'lib/route/link/bonding.c')
-rw-r--r--lib/route/link/bonding.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/lib/route/link/bonding.c b/lib/route/link/bonding.c
index b060ee1..f4c520b 100644
--- a/lib/route/link/bonding.c
+++ b/lib/route/link/bonding.c
@@ -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>
*/
/**
@@ -25,6 +25,27 @@
#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
* @arg name name of bonding device or NULL
@@ -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);