]>
Commit | Line | Data |
---|---|---|
0a2a78c4 JP |
1 | /* |
2 | * drivers/net/bond/bond_netlink.c - Netlink interface for bonding | |
3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> | |
eecdaa6e | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
0a2a78c4 JP |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
13 | ||
14 | #include <linux/module.h> | |
15 | #include <linux/errno.h> | |
16 | #include <linux/netdevice.h> | |
17 | #include <linux/etherdevice.h> | |
18 | #include <linux/if_link.h> | |
19 | #include <linux/if_ether.h> | |
20 | #include <net/netlink.h> | |
21 | #include <net/rtnetlink.h> | |
22 | #include "bonding.h" | |
23 | ||
90af2311 JP |
24 | static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { |
25 | [IFLA_BOND_MODE] = { .type = NLA_U8 }, | |
ec76aa49 | 26 | [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 }, |
eecdaa6e | 27 | [IFLA_BOND_MIIMON] = { .type = NLA_U32 }, |
25852e29 | 28 | [IFLA_BOND_UPDELAY] = { .type = NLA_U32 }, |
c7461f9b | 29 | [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 }, |
9f53e14e | 30 | [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 }, |
06151dbc | 31 | [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 }, |
90af2311 JP |
32 | }; |
33 | ||
0a2a78c4 JP |
34 | static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) |
35 | { | |
36 | if (tb[IFLA_ADDRESS]) { | |
37 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) | |
38 | return -EINVAL; | |
39 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) | |
40 | return -EADDRNOTAVAIL; | |
41 | } | |
42 | return 0; | |
43 | } | |
44 | ||
90af2311 JP |
45 | static int bond_changelink(struct net_device *bond_dev, |
46 | struct nlattr *tb[], struct nlattr *data[]) | |
47 | { | |
48 | struct bonding *bond = netdev_priv(bond_dev); | |
06151dbc | 49 | int miimon = 0; |
90af2311 JP |
50 | int err; |
51 | ||
eecdaa6e | 52 | if (!data) |
53 | return 0; | |
54 | ||
55 | if (data[IFLA_BOND_MODE]) { | |
90af2311 JP |
56 | int mode = nla_get_u8(data[IFLA_BOND_MODE]); |
57 | ||
58 | err = bond_option_mode_set(bond, mode); | |
59 | if (err) | |
60 | return err; | |
61 | } | |
eecdaa6e | 62 | if (data[IFLA_BOND_ACTIVE_SLAVE]) { |
ec76aa49 JP |
63 | int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]); |
64 | struct net_device *slave_dev; | |
65 | ||
66 | if (ifindex == 0) { | |
67 | slave_dev = NULL; | |
68 | } else { | |
69 | slave_dev = __dev_get_by_index(dev_net(bond_dev), | |
70 | ifindex); | |
71 | if (!slave_dev) | |
72 | return -ENODEV; | |
73 | } | |
74 | err = bond_option_active_slave_set(bond, slave_dev); | |
75 | if (err) | |
76 | return err; | |
77 | } | |
eecdaa6e | 78 | if (data[IFLA_BOND_MIIMON]) { |
06151dbc | 79 | miimon = nla_get_u32(data[IFLA_BOND_MIIMON]); |
eecdaa6e | 80 | |
81 | err = bond_option_miimon_set(bond, miimon); | |
82 | if (err) | |
83 | return err; | |
84 | } | |
25852e29 | 85 | if (data[IFLA_BOND_UPDELAY]) { |
86 | int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]); | |
87 | ||
88 | err = bond_option_updelay_set(bond, updelay); | |
89 | if (err) | |
90 | return err; | |
91 | } | |
c7461f9b | 92 | if (data[IFLA_BOND_DOWNDELAY]) { |
93 | int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]); | |
94 | ||
95 | err = bond_option_downdelay_set(bond, downdelay); | |
96 | if (err) | |
97 | return err; | |
98 | } | |
9f53e14e | 99 | if (data[IFLA_BOND_USE_CARRIER]) { |
100 | int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]); | |
101 | ||
102 | err = bond_option_use_carrier_set(bond, use_carrier); | |
103 | if (err) | |
104 | return err; | |
105 | } | |
06151dbc | 106 | if (data[IFLA_BOND_ARP_INTERVAL]) { |
107 | int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]); | |
108 | ||
109 | if (arp_interval && miimon) { | |
110 | pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n", | |
111 | bond->dev->name); | |
112 | return -EINVAL; | |
113 | } | |
114 | ||
115 | err = bond_option_arp_interval_set(bond, arp_interval); | |
116 | if (err) | |
117 | return err; | |
118 | } | |
90af2311 JP |
119 | return 0; |
120 | } | |
121 | ||
122 | static int bond_newlink(struct net *src_net, struct net_device *bond_dev, | |
123 | struct nlattr *tb[], struct nlattr *data[]) | |
124 | { | |
125 | int err; | |
126 | ||
127 | err = bond_changelink(bond_dev, tb, data); | |
128 | if (err < 0) | |
129 | return err; | |
130 | ||
131 | return register_netdevice(bond_dev); | |
132 | } | |
133 | ||
134 | static size_t bond_get_size(const struct net_device *bond_dev) | |
135 | { | |
e139862e | 136 | return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */ |
eecdaa6e | 137 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */ |
138 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */ | |
25852e29 | 139 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */ |
c7461f9b | 140 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */ |
9f53e14e | 141 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */ |
06151dbc | 142 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */ |
eecdaa6e | 143 | 0; |
90af2311 JP |
144 | } |
145 | ||
146 | static int bond_fill_info(struct sk_buff *skb, | |
147 | const struct net_device *bond_dev) | |
148 | { | |
149 | struct bonding *bond = netdev_priv(bond_dev); | |
ec76aa49 | 150 | struct net_device *slave_dev = bond_option_active_slave_get(bond); |
90af2311 | 151 | |
eecdaa6e | 152 | if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode)) |
90af2311 | 153 | goto nla_put_failure; |
eecdaa6e | 154 | |
155 | if (slave_dev && | |
156 | nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)) | |
157 | goto nla_put_failure; | |
158 | ||
159 | if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon)) | |
160 | goto nla_put_failure; | |
161 | ||
25852e29 | 162 | if (nla_put_u32(skb, IFLA_BOND_UPDELAY, |
163 | bond->params.updelay * bond->params.miimon)) | |
164 | goto nla_put_failure; | |
165 | ||
c7461f9b | 166 | if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY, |
167 | bond->params.downdelay * bond->params.miimon)) | |
168 | goto nla_put_failure; | |
169 | ||
9f53e14e | 170 | if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier)) |
171 | goto nla_put_failure; | |
172 | ||
06151dbc | 173 | if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval)) |
174 | goto nla_put_failure; | |
175 | ||
90af2311 JP |
176 | return 0; |
177 | ||
178 | nla_put_failure: | |
179 | return -EMSGSIZE; | |
180 | } | |
181 | ||
0a2a78c4 JP |
182 | struct rtnl_link_ops bond_link_ops __read_mostly = { |
183 | .kind = "bond", | |
184 | .priv_size = sizeof(struct bonding), | |
185 | .setup = bond_setup, | |
90af2311 JP |
186 | .maxtype = IFLA_BOND_MAX, |
187 | .policy = bond_policy, | |
0a2a78c4 | 188 | .validate = bond_validate, |
90af2311 JP |
189 | .newlink = bond_newlink, |
190 | .changelink = bond_changelink, | |
191 | .get_size = bond_get_size, | |
192 | .fill_info = bond_fill_info, | |
0a2a78c4 JP |
193 | .get_num_tx_queues = bond_get_num_tx_queues, |
194 | .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number | |
195 | as for TX queues */ | |
196 | }; | |
197 | ||
198 | int __init bond_netlink_init(void) | |
199 | { | |
200 | return rtnl_link_register(&bond_link_ops); | |
201 | } | |
202 | ||
a729e83a | 203 | void bond_netlink_fini(void) |
0a2a78c4 JP |
204 | { |
205 | rtnl_link_unregister(&bond_link_ops); | |
206 | } | |
207 | ||
208 | MODULE_ALIAS_RTNL_LINK("bond"); |