17#include "nl-default.h"
19#include <netlink/netlink.h>
20#include <netlink/route/link/bonding.h>
25#define BOND_HAS_MODE (1 << 0)
26#define BOND_HAS_ACTIVE_SLAVE (1 << 1)
34static int bond_info_alloc(
struct rtnl_link *link)
39 memset(link->l_info, 0,
sizeof(*bn));
41 bn = calloc(1,
sizeof(*bn));
51static void bond_info_free(
struct rtnl_link *link)
53 _nl_clear_free(&link->l_info);
56static int bond_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
64 if (bn->bn_mask & BOND_HAS_MODE)
67 if (bn->bn_mask & BOND_HAS_ACTIVE_SLAVE)
68 NLA_PUT_U32(msg, IFLA_BOND_ACTIVE_SLAVE, bn->ifindex);
80 .io_alloc = bond_info_alloc,
81 .io_put_attrs = bond_put_attrs,
82 .io_free = bond_info_free,
85#define IS_BOND_INFO_ASSERT(link) \
87 if (link->l_info_ops != &bonding_info_ops) { \
88 APPBUG("Link is not a bond link. Set type \"bond\" first."); \
103 IS_BOND_INFO_ASSERT(link);
105 bn->ifindex = active_slave;
107 bn->bn_mask |= BOND_HAS_ACTIVE_SLAVE;
121 IS_BOND_INFO_ASSERT(link);
125 bn->bn_mask |= BOND_HAS_MODE;
235 err = -NLE_OPNOTSUPP;
313static void _nl_init bonding_init(
void)
318static void _nl_exit bonding_exit(
void)
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr)
Cancel the addition of a nested attribute.
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
void rtnl_link_bond_set_mode(struct rtnl_link *link, uint8_t mode)
Set bond mode.
void rtnl_link_bond_set_activeslave(struct rtnl_link *link, int active_slave)
Set active slave for bond.
int rtnl_link_bond_enslave_ifindex(struct nl_sock *sock, int master, int slave)
Add a link to a bond (enslave)
int rtnl_link_bond_add(struct nl_sock *sock, const char *name, struct rtnl_link *opts)
Create a new kernel bonding device.
struct rtnl_link * rtnl_link_bond_alloc(void)
Allocate link object of type bond.
int rtnl_link_bond_enslave(struct nl_sock *sock, struct rtnl_link *master, struct rtnl_link *slave)
Add a link to a bond (enslave)
int rtnl_link_bond_release(struct nl_sock *sock, struct rtnl_link *slave)
Release a link from a bond.
int rtnl_link_bond_release_ifindex(struct nl_sock *sock, int slave)
Release a link from a bond.
int rtnl_link_register_info(struct rtnl_link_info_ops *ops)
Register operations for a link info type.
int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops)
Unregister operations for a link info type.
int rtnl_link_add(struct nl_sock *sk, struct rtnl_link *link, int flags)
Add virtual link.
int rtnl_link_get_master(struct rtnl_link *link)
Return master link of link object.
struct rtnl_link * rtnl_link_alloc(void)
Allocate link object.
void rtnl_link_set_name(struct rtnl_link *link, const char *name)
Set name of link object.
int rtnl_link_get_kernel(struct nl_sock *sk, int ifindex, const char *name, struct rtnl_link **result)
Get a link object directly from kernel.
char * rtnl_link_get_name(struct rtnl_link *link)
Return name of link object.
void rtnl_link_put(struct rtnl_link *link)
Release a link object reference.
int rtnl_link_set_type(struct rtnl_link *link, const char *type)
Set type of link object.
void rtnl_link_set_master(struct rtnl_link *link, int ifindex)
Set master link of link object.
void rtnl_link_set_ifindex(struct rtnl_link *link, int ifindex)
Set interface index of link object.
int rtnl_link_get_ifindex(struct rtnl_link *link)
Return interface index of link object.
int rtnl_link_change(struct nl_sock *sk, struct rtnl_link *orig, struct rtnl_link *changes, int flags)
Change link.
Available operations to modules implementing a link info type.
char * io_name
Name of link info type, must match name on kernel side.