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)
* 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_
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 *);
* 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
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;
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);
#include <netlink/netlink.h>
#include <netlink/route/link.h>
+#include <netlink/route/link/bonding.h>
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;