dect
/
libnl
Archived
13
0
Fork 0

bond: Provide rtnl_link_bond_alloc()

Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
Thomas Graf 2013-02-14 12:48:00 +01:00
parent ee4122a12e
commit 1ecf98a23e
4 changed files with 33 additions and 23 deletions

View 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)

View 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 *);

View 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>
*/
/**
@ -24,6 +24,27 @@
#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);

View 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;