Skip to content

Commit ec76aa4

Browse files
jpirkodavem330
authored andcommitted
bonding: add Netlink support active_slave option
Signed-off-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 90af231 commit ec76aa4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

drivers/net/bonding/bond_netlink.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
2424
[IFLA_BOND_MODE] = { .type = NLA_U8 },
25+
[IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
2526
};
2627

2728
static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -48,6 +49,22 @@ static int bond_changelink(struct net_device *bond_dev,
4849
if (err)
4950
return err;
5051
}
52+
if (data && data[IFLA_BOND_ACTIVE_SLAVE]) {
53+
int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
54+
struct net_device *slave_dev;
55+
56+
if (ifindex == 0) {
57+
slave_dev = NULL;
58+
} else {
59+
slave_dev = __dev_get_by_index(dev_net(bond_dev),
60+
ifindex);
61+
if (!slave_dev)
62+
return -ENODEV;
63+
}
64+
err = bond_option_active_slave_set(bond, slave_dev);
65+
if (err)
66+
return err;
67+
}
5168
return 0;
5269
}
5370

@@ -66,14 +83,18 @@ static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
6683
static size_t bond_get_size(const struct net_device *bond_dev)
6784
{
6885
return nla_total_size(sizeof(u8)); /* IFLA_BOND_MODE */
86+
+ nla_total_size(sizeof(u32)); /* IFLA_BOND_ACTIVE_SLAVE */
6987
}
7088

7189
static int bond_fill_info(struct sk_buff *skb,
7290
const struct net_device *bond_dev)
7391
{
7492
struct bonding *bond = netdev_priv(bond_dev);
93+
struct net_device *slave_dev = bond_option_active_slave_get(bond);
7594

76-
if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
95+
if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode) ||
96+
(slave_dev &&
97+
nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)))
7798
goto nla_put_failure;
7899
return 0;
79100

include/uapi/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ struct ifla_vxlan_port_range {
330330
enum {
331331
IFLA_BOND_UNSPEC,
332332
IFLA_BOND_MODE,
333+
IFLA_BOND_ACTIVE_SLAVE,
333334
__IFLA_BOND_MAX,
334335
};
335336

0 commit comments

Comments
 (0)