Skip to content

Commit 90af231

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

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

drivers/net/bonding/bond_netlink.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
#include <net/rtnetlink.h>
2121
#include "bonding.h"
2222

23+
static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
24+
[IFLA_BOND_MODE] = { .type = NLA_U8 },
25+
};
26+
2327
static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
2428
{
2529
if (tb[IFLA_ADDRESS]) {
@@ -31,11 +35,63 @@ static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
3135
return 0;
3236
}
3337

38+
static int bond_changelink(struct net_device *bond_dev,
39+
struct nlattr *tb[], struct nlattr *data[])
40+
{
41+
struct bonding *bond = netdev_priv(bond_dev);
42+
int err;
43+
44+
if (data && data[IFLA_BOND_MODE]) {
45+
int mode = nla_get_u8(data[IFLA_BOND_MODE]);
46+
47+
err = bond_option_mode_set(bond, mode);
48+
if (err)
49+
return err;
50+
}
51+
return 0;
52+
}
53+
54+
static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
55+
struct nlattr *tb[], struct nlattr *data[])
56+
{
57+
int err;
58+
59+
err = bond_changelink(bond_dev, tb, data);
60+
if (err < 0)
61+
return err;
62+
63+
return register_netdevice(bond_dev);
64+
}
65+
66+
static size_t bond_get_size(const struct net_device *bond_dev)
67+
{
68+
return nla_total_size(sizeof(u8)); /* IFLA_BOND_MODE */
69+
}
70+
71+
static int bond_fill_info(struct sk_buff *skb,
72+
const struct net_device *bond_dev)
73+
{
74+
struct bonding *bond = netdev_priv(bond_dev);
75+
76+
if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
77+
goto nla_put_failure;
78+
return 0;
79+
80+
nla_put_failure:
81+
return -EMSGSIZE;
82+
}
83+
3484
struct rtnl_link_ops bond_link_ops __read_mostly = {
3585
.kind = "bond",
3686
.priv_size = sizeof(struct bonding),
3787
.setup = bond_setup,
88+
.maxtype = IFLA_BOND_MAX,
89+
.policy = bond_policy,
3890
.validate = bond_validate,
91+
.newlink = bond_newlink,
92+
.changelink = bond_changelink,
93+
.get_size = bond_get_size,
94+
.fill_info = bond_fill_info,
3995
.get_num_tx_queues = bond_get_num_tx_queues,
4096
.get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
4197
as for TX queues */

include/uapi/linux/if_link.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,16 @@ struct ifla_vxlan_port_range {
325325
__be16 high;
326326
};
327327

328+
/* Bonding section */
329+
330+
enum {
331+
IFLA_BOND_UNSPEC,
332+
IFLA_BOND_MODE,
333+
__IFLA_BOND_MAX,
334+
};
335+
336+
#define IFLA_BOND_MAX (__IFLA_BOND_MAX - 1)
337+
328338
/* SR-IOV virtual function management section */
329339

330340
enum {

0 commit comments

Comments
 (0)