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+
2327static 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+
3484struct 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 */
0 commit comments