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)
27#define BOND_HAS_HASHING_TYPE (1 << 2)
28#define BOND_HAS_MIIMON (1 << 3)
29#define BOND_HAS_MIN_LINKS (1 << 4)
40static int bond_info_alloc(
struct rtnl_link *link)
45 memset(link->l_info, 0,
sizeof(*bn));
47 bn = calloc(1,
sizeof(*bn));
57static void bond_info_free(
struct rtnl_link *link)
59 _nl_clear_free(&link->l_info);
62static int bond_put_attrs(
struct nl_msg *msg,
struct rtnl_link *link)
70 if (bn->bn_mask & BOND_HAS_MODE)
73 if (bn->bn_mask & BOND_HAS_ACTIVE_SLAVE)
74 NLA_PUT_U32(msg, IFLA_BOND_ACTIVE_SLAVE, bn->ifindex);
76 if (bn->bn_mask & BOND_HAS_HASHING_TYPE)
77 NLA_PUT_U8(msg, IFLA_BOND_XMIT_HASH_POLICY, bn->hashing_type);
79 if (bn->bn_mask & BOND_HAS_MIIMON)
82 if (bn->bn_mask & BOND_HAS_MIN_LINKS)
83 NLA_PUT_U32(msg, IFLA_BOND_MIN_LINKS, bn->min_links);
95 .io_alloc = bond_info_alloc,
96 .io_put_attrs = bond_put_attrs,
97 .io_free = bond_info_free,
100#define IS_BOND_INFO_ASSERT(link) \
102 if (link->l_info_ops != &bonding_info_ops) { \
103 APPBUG("Link is not a bond link. Set type \"bond\" first."); \
118 IS_BOND_INFO_ASSERT(link);
120 bn->ifindex = active_slave;
122 bn->bn_mask |= BOND_HAS_ACTIVE_SLAVE;
136 IS_BOND_INFO_ASSERT(link);
140 bn->bn_mask |= BOND_HAS_MODE;
154 IS_BOND_INFO_ASSERT(link);
156 bn->hashing_type = type;
158 bn->bn_mask |= BOND_HAS_HASHING_TYPE;
172 IS_BOND_INFO_ASSERT(link);
176 bn->bn_mask |= BOND_HAS_MIIMON;
191 IS_BOND_INFO_ASSERT(link);
193 bn->min_links = min_links;
195 bn->bn_mask |= BOND_HAS_MIN_LINKS;
305 err = -NLE_OPNOTSUPP;
383static void _nl_init bonding_init(
void)
388static 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_min_links(struct rtnl_link *link, uint32_t min_links)
Set the minimum number of member ports that must be up before marking the bond device as up.
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.
void rtnl_link_bond_set_hashing_type(struct rtnl_link *link, uint8_t type)
Set hashing type.
int rtnl_link_bond_release_ifindex(struct nl_sock *sock, int slave)
Release a link from a bond.
void rtnl_link_bond_set_miimon(struct rtnl_link *link, uint32_t miimon)
Set MII monitoring interval.
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.