]>
Commit | Line | Data |
---|---|---|
b76cdba9 MW |
1 | /* |
2 | * Copyright(c) 2004-2005 Intel Corporation. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License as published by the | |
6 | * Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
11 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 | * for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | * | |
18 | * The full GNU General Public License is included in this distribution in the | |
19 | * file called LICENSE. | |
20 | * | |
b76cdba9 | 21 | */ |
a4aee5c8 JP |
22 | |
23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
24 | ||
b76cdba9 MW |
25 | #include <linux/kernel.h> |
26 | #include <linux/module.h> | |
b76cdba9 | 27 | #include <linux/device.h> |
d43c36dc | 28 | #include <linux/sched.h> |
b76cdba9 MW |
29 | #include <linux/fs.h> |
30 | #include <linux/types.h> | |
31 | #include <linux/string.h> | |
32 | #include <linux/netdevice.h> | |
33 | #include <linux/inetdevice.h> | |
34 | #include <linux/in.h> | |
35 | #include <linux/sysfs.h> | |
b76cdba9 MW |
36 | #include <linux/ctype.h> |
37 | #include <linux/inet.h> | |
38 | #include <linux/rtnetlink.h> | |
5c5129b5 | 39 | #include <linux/etherdevice.h> |
881d966b | 40 | #include <net/net_namespace.h> |
ec87fd3b EB |
41 | #include <net/netns/generic.h> |
42 | #include <linux/nsproxy.h> | |
b76cdba9 | 43 | |
b76cdba9 | 44 | #include "bonding.h" |
5a03cdb7 | 45 | |
3d632c3f | 46 | #define to_dev(obj) container_of(obj, struct device, kobj) |
454d7c9b | 47 | #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) |
b76cdba9 | 48 | |
b76cdba9 MW |
49 | /* |
50 | * "show" function for the bond_masters attribute. | |
51 | * The class parameter is ignored. | |
52 | */ | |
28812fe1 AK |
53 | static ssize_t bonding_show_bonds(struct class *cls, |
54 | struct class_attribute *attr, | |
55 | char *buf) | |
b76cdba9 | 56 | { |
4c22400a EB |
57 | struct bond_net *bn = |
58 | container_of(attr, struct bond_net, class_attr_bonding_masters); | |
b76cdba9 MW |
59 | int res = 0; |
60 | struct bonding *bond; | |
61 | ||
7e083840 | 62 | rtnl_lock(); |
b76cdba9 | 63 | |
ec87fd3b | 64 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
b76cdba9 MW |
65 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
66 | /* not enough space for another interface name */ | |
67 | if ((PAGE_SIZE - res) > 10) | |
68 | res = PAGE_SIZE - 10; | |
b8843665 | 69 | res += sprintf(buf + res, "++more++ "); |
b76cdba9 MW |
70 | break; |
71 | } | |
b8843665 | 72 | res += sprintf(buf + res, "%s ", bond->dev->name); |
b76cdba9 | 73 | } |
1dcdcd69 WF |
74 | if (res) |
75 | buf[res-1] = '\n'; /* eat the leftover space */ | |
7e083840 SH |
76 | |
77 | rtnl_unlock(); | |
b76cdba9 MW |
78 | return res; |
79 | } | |
80 | ||
4c22400a | 81 | static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname) |
373500db SH |
82 | { |
83 | struct bonding *bond; | |
84 | ||
ec87fd3b | 85 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
373500db SH |
86 | if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) |
87 | return bond->dev; | |
88 | } | |
89 | return NULL; | |
90 | } | |
91 | ||
b76cdba9 MW |
92 | /* |
93 | * "store" function for the bond_masters attribute. This is what | |
94 | * creates and deletes entire bonds. | |
95 | * | |
96 | * The class parameter is ignored. | |
97 | * | |
98 | */ | |
99 | ||
3d632c3f | 100 | static ssize_t bonding_store_bonds(struct class *cls, |
28812fe1 | 101 | struct class_attribute *attr, |
3d632c3f | 102 | const char *buffer, size_t count) |
b76cdba9 | 103 | { |
4c22400a EB |
104 | struct bond_net *bn = |
105 | container_of(attr, struct bond_net, class_attr_bonding_masters); | |
b76cdba9 MW |
106 | char command[IFNAMSIZ + 1] = {0, }; |
107 | char *ifname; | |
027ea041 | 108 | int rv, res = count; |
b76cdba9 | 109 | |
b76cdba9 MW |
110 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
111 | ifname = command + 1; | |
112 | if ((strlen(command) <= 1) || | |
113 | !dev_valid_name(ifname)) | |
114 | goto err_no_cmd; | |
115 | ||
116 | if (command[0] == '+') { | |
a4aee5c8 | 117 | pr_info("%s is being created...\n", ifname); |
4c22400a | 118 | rv = bond_create(bn->net, ifname); |
027ea041 | 119 | if (rv) { |
5f86cad1 PO |
120 | if (rv == -EEXIST) |
121 | pr_info("%s already exists.\n", ifname); | |
122 | else | |
123 | pr_info("%s creation failed.\n", ifname); | |
027ea041 | 124 | res = rv; |
b76cdba9 | 125 | } |
373500db SH |
126 | } else if (command[0] == '-') { |
127 | struct net_device *bond_dev; | |
b76cdba9 | 128 | |
027ea041 | 129 | rtnl_lock(); |
4c22400a | 130 | bond_dev = bond_get_by_name(bn, ifname); |
373500db | 131 | if (bond_dev) { |
a4aee5c8 | 132 | pr_info("%s is being deleted...\n", ifname); |
373500db SH |
133 | unregister_netdevice(bond_dev); |
134 | } else { | |
a4aee5c8 | 135 | pr_err("unable to delete non-existent %s\n", ifname); |
373500db SH |
136 | res = -ENODEV; |
137 | } | |
138 | rtnl_unlock(); | |
139 | } else | |
140 | goto err_no_cmd; | |
027ea041 | 141 | |
373500db SH |
142 | /* Always return either count or an error. If you return 0, you'll |
143 | * get called forever, which is bad. | |
144 | */ | |
145 | return res; | |
b76cdba9 MW |
146 | |
147 | err_no_cmd: | |
a4aee5c8 | 148 | pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n"); |
c4ebc66a | 149 | return -EPERM; |
b76cdba9 | 150 | } |
373500db | 151 | |
4c22400a EB |
152 | static const void *bonding_namespace(struct class *cls, |
153 | const struct class_attribute *attr) | |
154 | { | |
155 | const struct bond_net *bn = | |
156 | container_of(attr, struct bond_net, class_attr_bonding_masters); | |
157 | return bn->net; | |
158 | } | |
159 | ||
b76cdba9 | 160 | /* class attribute for bond_masters file. This ends up in /sys/class/net */ |
4c22400a EB |
161 | static const struct class_attribute class_attr_bonding_masters = { |
162 | .attr = { | |
163 | .name = "bonding_masters", | |
164 | .mode = S_IWUSR | S_IRUGO, | |
165 | }, | |
166 | .show = bonding_show_bonds, | |
167 | .store = bonding_store_bonds, | |
168 | .namespace = bonding_namespace, | |
169 | }; | |
b76cdba9 | 170 | |
3d632c3f SH |
171 | int bond_create_slave_symlinks(struct net_device *master, |
172 | struct net_device *slave) | |
b76cdba9 MW |
173 | { |
174 | char linkname[IFNAMSIZ+7]; | |
175 | int ret = 0; | |
176 | ||
177 | /* first, create a link from the slave back to the master */ | |
43cb76d9 | 178 | ret = sysfs_create_link(&(slave->dev.kobj), &(master->dev.kobj), |
b76cdba9 MW |
179 | "master"); |
180 | if (ret) | |
181 | return ret; | |
182 | /* next, create a link from the master to the slave */ | |
3d632c3f | 183 | sprintf(linkname, "slave_%s", slave->name); |
43cb76d9 | 184 | ret = sysfs_create_link(&(master->dev.kobj), &(slave->dev.kobj), |
b76cdba9 | 185 | linkname); |
9fe16b78 VF |
186 | |
187 | /* free the master link created earlier in case of error */ | |
188 | if (ret) | |
189 | sysfs_remove_link(&(slave->dev.kobj), "master"); | |
190 | ||
b76cdba9 MW |
191 | return ret; |
192 | ||
193 | } | |
194 | ||
3d632c3f SH |
195 | void bond_destroy_slave_symlinks(struct net_device *master, |
196 | struct net_device *slave) | |
b76cdba9 MW |
197 | { |
198 | char linkname[IFNAMSIZ+7]; | |
199 | ||
43cb76d9 | 200 | sysfs_remove_link(&(slave->dev.kobj), "master"); |
3d632c3f | 201 | sprintf(linkname, "slave_%s", slave->name); |
43cb76d9 | 202 | sysfs_remove_link(&(master->dev.kobj), linkname); |
b76cdba9 MW |
203 | } |
204 | ||
205 | ||
206 | /* | |
207 | * Show the slaves in the current bond. | |
208 | */ | |
43cb76d9 GKH |
209 | static ssize_t bonding_show_slaves(struct device *d, |
210 | struct device_attribute *attr, char *buf) | |
b76cdba9 MW |
211 | { |
212 | struct slave *slave; | |
213 | int i, res = 0; | |
43cb76d9 | 214 | struct bonding *bond = to_bond(d); |
b76cdba9 | 215 | |
6603a6f2 | 216 | read_lock(&bond->lock); |
b76cdba9 MW |
217 | bond_for_each_slave(bond, slave, i) { |
218 | if (res > (PAGE_SIZE - IFNAMSIZ)) { | |
219 | /* not enough space for another interface name */ | |
220 | if ((PAGE_SIZE - res) > 10) | |
221 | res = PAGE_SIZE - 10; | |
7bd46508 | 222 | res += sprintf(buf + res, "++more++ "); |
b76cdba9 MW |
223 | break; |
224 | } | |
225 | res += sprintf(buf + res, "%s ", slave->dev->name); | |
226 | } | |
6603a6f2 | 227 | read_unlock(&bond->lock); |
1dcdcd69 WF |
228 | if (res) |
229 | buf[res-1] = '\n'; /* eat the leftover space */ | |
b76cdba9 MW |
230 | return res; |
231 | } | |
232 | ||
233 | /* | |
d6641ccf | 234 | * Set the slaves in the current bond. |
f9f3545e JP |
235 | * This is supposed to be only thin wrapper for bond_enslave and bond_release. |
236 | * All hard work should be done there. | |
b76cdba9 | 237 | */ |
43cb76d9 GKH |
238 | static ssize_t bonding_store_slaves(struct device *d, |
239 | struct device_attribute *attr, | |
240 | const char *buffer, size_t count) | |
b76cdba9 MW |
241 | { |
242 | char command[IFNAMSIZ + 1] = { 0, }; | |
243 | char *ifname; | |
f9f3545e JP |
244 | int res, ret = count; |
245 | struct net_device *dev; | |
43cb76d9 | 246 | struct bonding *bond = to_bond(d); |
b76cdba9 | 247 | |
496a60cd EB |
248 | if (!rtnl_trylock()) |
249 | return restart_syscall(); | |
027ea041 | 250 | |
b76cdba9 MW |
251 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
252 | ifname = command + 1; | |
253 | if ((strlen(command) <= 1) || | |
254 | !dev_valid_name(ifname)) | |
255 | goto err_no_cmd; | |
256 | ||
f9f3545e JP |
257 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
258 | if (!dev) { | |
259 | pr_info("%s: Interface %s does not exist!\n", | |
260 | bond->dev->name, ifname); | |
261 | ret = -ENODEV; | |
262 | goto out; | |
263 | } | |
b76cdba9 | 264 | |
f9f3545e JP |
265 | switch (command[0]) { |
266 | case '+': | |
267 | pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name); | |
b76cdba9 | 268 | res = bond_enslave(bond->dev, dev); |
f9f3545e | 269 | break; |
3d632c3f | 270 | |
f9f3545e JP |
271 | case '-': |
272 | pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name); | |
273 | res = bond_release(bond->dev, dev); | |
274 | break; | |
b76cdba9 | 275 | |
f9f3545e JP |
276 | default: |
277 | goto err_no_cmd; | |
b76cdba9 MW |
278 | } |
279 | ||
f9f3545e JP |
280 | if (res) |
281 | ret = res; | |
282 | goto out; | |
283 | ||
b76cdba9 | 284 | err_no_cmd: |
a4aee5c8 JP |
285 | pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n", |
286 | bond->dev->name); | |
b76cdba9 MW |
287 | ret = -EPERM; |
288 | ||
289 | out: | |
027ea041 | 290 | rtnl_unlock(); |
b76cdba9 MW |
291 | return ret; |
292 | } | |
293 | ||
3d632c3f SH |
294 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, |
295 | bonding_store_slaves); | |
b76cdba9 MW |
296 | |
297 | /* | |
298 | * Show and set the bonding mode. The bond interface must be down to | |
299 | * change the mode. | |
300 | */ | |
43cb76d9 GKH |
301 | static ssize_t bonding_show_mode(struct device *d, |
302 | struct device_attribute *attr, char *buf) | |
b76cdba9 | 303 | { |
43cb76d9 | 304 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
305 | |
306 | return sprintf(buf, "%s %d\n", | |
307 | bond_mode_tbl[bond->params.mode].modename, | |
7bd46508 | 308 | bond->params.mode); |
b76cdba9 MW |
309 | } |
310 | ||
43cb76d9 GKH |
311 | static ssize_t bonding_store_mode(struct device *d, |
312 | struct device_attribute *attr, | |
313 | const char *buf, size_t count) | |
b76cdba9 MW |
314 | { |
315 | int new_value, ret = count; | |
43cb76d9 | 316 | struct bonding *bond = to_bond(d); |
b76cdba9 | 317 | |
ea6836dd | 318 | if (!rtnl_trylock()) |
319 | return restart_syscall(); | |
320 | ||
b76cdba9 | 321 | if (bond->dev->flags & IFF_UP) { |
a4aee5c8 JP |
322 | pr_err("unable to update mode of %s because interface is up.\n", |
323 | bond->dev->name); | |
b76cdba9 MW |
324 | ret = -EPERM; |
325 | goto out; | |
326 | } | |
327 | ||
4a8bb7e2 VF |
328 | if (bond->slave_cnt > 0) { |
329 | pr_err("unable to update mode of %s because it has slaves.\n", | |
330 | bond->dev->name); | |
331 | ret = -EPERM; | |
332 | goto out; | |
333 | } | |
334 | ||
ece95f7f | 335 | new_value = bond_parse_parm(buf, bond_mode_tbl); |
b76cdba9 | 336 | if (new_value < 0) { |
a4aee5c8 JP |
337 | pr_err("%s: Ignoring invalid mode value %.*s.\n", |
338 | bond->dev->name, (int)strlen(buf) - 1, buf); | |
b76cdba9 MW |
339 | ret = -EINVAL; |
340 | goto out; | |
c5cb002f AG |
341 | } |
342 | if ((new_value == BOND_MODE_ALB || | |
343 | new_value == BOND_MODE_TLB) && | |
344 | bond->params.arp_interval) { | |
345 | pr_err("%s: %s mode is incompatible with arp monitoring.\n", | |
346 | bond->dev->name, bond_mode_tbl[new_value].modename); | |
347 | ret = -EINVAL; | |
348 | goto out; | |
349 | } | |
8f903c70 | 350 | |
c5cb002f AG |
351 | bond->params.mode = new_value; |
352 | bond_set_mode_ops(bond, bond->params.mode); | |
353 | pr_info("%s: setting mode to %s (%d).\n", | |
354 | bond->dev->name, bond_mode_tbl[new_value].modename, | |
355 | new_value); | |
b76cdba9 | 356 | out: |
ea6836dd | 357 | rtnl_unlock(); |
b76cdba9 MW |
358 | return ret; |
359 | } | |
3d632c3f SH |
360 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
361 | bonding_show_mode, bonding_store_mode); | |
b76cdba9 MW |
362 | |
363 | /* | |
3d632c3f | 364 | * Show and set the bonding transmit hash method. |
b76cdba9 | 365 | */ |
43cb76d9 GKH |
366 | static ssize_t bonding_show_xmit_hash(struct device *d, |
367 | struct device_attribute *attr, | |
368 | char *buf) | |
b76cdba9 | 369 | { |
43cb76d9 | 370 | struct bonding *bond = to_bond(d); |
b76cdba9 | 371 | |
8e4b9329 WF |
372 | return sprintf(buf, "%s %d\n", |
373 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, | |
374 | bond->params.xmit_policy); | |
b76cdba9 MW |
375 | } |
376 | ||
43cb76d9 GKH |
377 | static ssize_t bonding_store_xmit_hash(struct device *d, |
378 | struct device_attribute *attr, | |
379 | const char *buf, size_t count) | |
b76cdba9 MW |
380 | { |
381 | int new_value, ret = count; | |
43cb76d9 | 382 | struct bonding *bond = to_bond(d); |
b76cdba9 | 383 | |
ece95f7f | 384 | new_value = bond_parse_parm(buf, xmit_hashtype_tbl); |
b76cdba9 | 385 | if (new_value < 0) { |
a4aee5c8 | 386 | pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n", |
b76cdba9 MW |
387 | bond->dev->name, |
388 | (int)strlen(buf) - 1, buf); | |
389 | ret = -EINVAL; | |
b76cdba9 MW |
390 | } else { |
391 | bond->params.xmit_policy = new_value; | |
392 | bond_set_mode_ops(bond, bond->params.mode); | |
a4aee5c8 | 393 | pr_info("%s: setting xmit hash policy to %s (%d).\n", |
3d632c3f SH |
394 | bond->dev->name, |
395 | xmit_hashtype_tbl[new_value].modename, new_value); | |
b76cdba9 | 396 | } |
53edee2c | 397 | |
b76cdba9 MW |
398 | return ret; |
399 | } | |
3d632c3f SH |
400 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
401 | bonding_show_xmit_hash, bonding_store_xmit_hash); | |
b76cdba9 | 402 | |
f5b2b966 JV |
403 | /* |
404 | * Show and set arp_validate. | |
405 | */ | |
43cb76d9 GKH |
406 | static ssize_t bonding_show_arp_validate(struct device *d, |
407 | struct device_attribute *attr, | |
408 | char *buf) | |
f5b2b966 | 409 | { |
43cb76d9 | 410 | struct bonding *bond = to_bond(d); |
f5b2b966 JV |
411 | |
412 | return sprintf(buf, "%s %d\n", | |
413 | arp_validate_tbl[bond->params.arp_validate].modename, | |
7bd46508 | 414 | bond->params.arp_validate); |
f5b2b966 JV |
415 | } |
416 | ||
43cb76d9 GKH |
417 | static ssize_t bonding_store_arp_validate(struct device *d, |
418 | struct device_attribute *attr, | |
419 | const char *buf, size_t count) | |
f5b2b966 JV |
420 | { |
421 | int new_value; | |
43cb76d9 | 422 | struct bonding *bond = to_bond(d); |
f5b2b966 | 423 | |
ece95f7f | 424 | new_value = bond_parse_parm(buf, arp_validate_tbl); |
f5b2b966 | 425 | if (new_value < 0) { |
a4aee5c8 | 426 | pr_err("%s: Ignoring invalid arp_validate value %s\n", |
f5b2b966 JV |
427 | bond->dev->name, buf); |
428 | return -EINVAL; | |
429 | } | |
430 | if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) { | |
a4aee5c8 | 431 | pr_err("%s: arp_validate only supported in active-backup mode.\n", |
f5b2b966 JV |
432 | bond->dev->name); |
433 | return -EINVAL; | |
434 | } | |
a4aee5c8 JP |
435 | pr_info("%s: setting arp_validate to %s (%d).\n", |
436 | bond->dev->name, arp_validate_tbl[new_value].modename, | |
437 | new_value); | |
f5b2b966 | 438 | |
f5b2b966 JV |
439 | bond->params.arp_validate = new_value; |
440 | ||
441 | return count; | |
442 | } | |
443 | ||
3d632c3f SH |
444 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
445 | bonding_store_arp_validate); | |
f5b2b966 | 446 | |
dd957c57 JV |
447 | /* |
448 | * Show and store fail_over_mac. User only allowed to change the | |
449 | * value when there are no slaves. | |
450 | */ | |
3d632c3f SH |
451 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
452 | struct device_attribute *attr, | |
453 | char *buf) | |
dd957c57 JV |
454 | { |
455 | struct bonding *bond = to_bond(d); | |
456 | ||
3915c1e8 JV |
457 | return sprintf(buf, "%s %d\n", |
458 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, | |
459 | bond->params.fail_over_mac); | |
dd957c57 JV |
460 | } |
461 | ||
3d632c3f SH |
462 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
463 | struct device_attribute *attr, | |
464 | const char *buf, size_t count) | |
dd957c57 JV |
465 | { |
466 | int new_value; | |
dd957c57 JV |
467 | struct bonding *bond = to_bond(d); |
468 | ||
469 | if (bond->slave_cnt != 0) { | |
a4aee5c8 | 470 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", |
dd957c57 | 471 | bond->dev->name); |
3915c1e8 | 472 | return -EPERM; |
dd957c57 JV |
473 | } |
474 | ||
3915c1e8 JV |
475 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
476 | if (new_value < 0) { | |
a4aee5c8 | 477 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
3915c1e8 JV |
478 | bond->dev->name, buf); |
479 | return -EINVAL; | |
dd957c57 JV |
480 | } |
481 | ||
3915c1e8 | 482 | bond->params.fail_over_mac = new_value; |
a4aee5c8 JP |
483 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", |
484 | bond->dev->name, fail_over_mac_tbl[new_value].modename, | |
485 | new_value); | |
3915c1e8 JV |
486 | |
487 | return count; | |
dd957c57 JV |
488 | } |
489 | ||
3d632c3f SH |
490 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
491 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); | |
dd957c57 | 492 | |
b76cdba9 MW |
493 | /* |
494 | * Show and set the arp timer interval. There are two tricky bits | |
495 | * here. First, if ARP monitoring is activated, then we must disable | |
496 | * MII monitoring. Second, if the ARP timer isn't running, we must | |
497 | * start it. | |
498 | */ | |
43cb76d9 GKH |
499 | static ssize_t bonding_show_arp_interval(struct device *d, |
500 | struct device_attribute *attr, | |
501 | char *buf) | |
b76cdba9 | 502 | { |
43cb76d9 | 503 | struct bonding *bond = to_bond(d); |
b76cdba9 | 504 | |
7bd46508 | 505 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
b76cdba9 MW |
506 | } |
507 | ||
43cb76d9 GKH |
508 | static ssize_t bonding_store_arp_interval(struct device *d, |
509 | struct device_attribute *attr, | |
510 | const char *buf, size_t count) | |
b76cdba9 MW |
511 | { |
512 | int new_value, ret = count; | |
43cb76d9 | 513 | struct bonding *bond = to_bond(d); |
b76cdba9 | 514 | |
fbb0c41b | 515 | if (!rtnl_trylock()) |
516 | return restart_syscall(); | |
b76cdba9 | 517 | if (sscanf(buf, "%d", &new_value) != 1) { |
a4aee5c8 | 518 | pr_err("%s: no arp_interval value specified.\n", |
b76cdba9 MW |
519 | bond->dev->name); |
520 | ret = -EINVAL; | |
521 | goto out; | |
522 | } | |
523 | if (new_value < 0) { | |
1bc7db16 | 524 | pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n", |
b76cdba9 MW |
525 | bond->dev->name, new_value, INT_MAX); |
526 | ret = -EINVAL; | |
527 | goto out; | |
528 | } | |
c5cb002f AG |
529 | if (bond->params.mode == BOND_MODE_ALB || |
530 | bond->params.mode == BOND_MODE_TLB) { | |
531 | pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n", | |
532 | bond->dev->name, bond->dev->name); | |
533 | ret = -EINVAL; | |
534 | goto out; | |
535 | } | |
a4aee5c8 JP |
536 | pr_info("%s: Setting ARP monitoring interval to %d.\n", |
537 | bond->dev->name, new_value); | |
b76cdba9 | 538 | bond->params.arp_interval = new_value; |
1bc7db16 | 539 | if (new_value) { |
540 | if (bond->params.miimon) { | |
541 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", | |
542 | bond->dev->name, bond->dev->name); | |
543 | bond->params.miimon = 0; | |
544 | } | |
545 | if (!bond->params.arp_targets[0]) | |
546 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", | |
547 | bond->dev->name); | |
b76cdba9 MW |
548 | } |
549 | if (bond->dev->flags & IFF_UP) { | |
550 | /* If the interface is up, we may need to fire off | |
551 | * the ARP timer. If the interface is down, the | |
552 | * timer will get fired off when the open function | |
553 | * is called. | |
554 | */ | |
1bc7db16 | 555 | if (!new_value) { |
556 | cancel_delayed_work_sync(&bond->arp_work); | |
557 | } else { | |
558 | cancel_delayed_work_sync(&bond->mii_work); | |
559 | queue_delayed_work(bond->wq, &bond->arp_work, 0); | |
560 | } | |
b76cdba9 | 561 | } |
b76cdba9 | 562 | out: |
fbb0c41b | 563 | rtnl_unlock(); |
b76cdba9 MW |
564 | return ret; |
565 | } | |
3d632c3f SH |
566 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
567 | bonding_show_arp_interval, bonding_store_arp_interval); | |
b76cdba9 MW |
568 | |
569 | /* | |
570 | * Show and set the arp targets. | |
571 | */ | |
43cb76d9 GKH |
572 | static ssize_t bonding_show_arp_targets(struct device *d, |
573 | struct device_attribute *attr, | |
574 | char *buf) | |
b76cdba9 MW |
575 | { |
576 | int i, res = 0; | |
43cb76d9 | 577 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
578 | |
579 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { | |
580 | if (bond->params.arp_targets[i]) | |
63779436 HH |
581 | res += sprintf(buf + res, "%pI4 ", |
582 | &bond->params.arp_targets[i]); | |
b76cdba9 | 583 | } |
1dcdcd69 WF |
584 | if (res) |
585 | buf[res-1] = '\n'; /* eat the leftover space */ | |
b76cdba9 MW |
586 | return res; |
587 | } | |
588 | ||
43cb76d9 GKH |
589 | static ssize_t bonding_store_arp_targets(struct device *d, |
590 | struct device_attribute *attr, | |
591 | const char *buf, size_t count) | |
b76cdba9 | 592 | { |
d3bb52b0 | 593 | __be32 newtarget; |
87a7b84b | 594 | int i = 0, ret = -EINVAL; |
43cb76d9 | 595 | struct bonding *bond = to_bond(d); |
d3bb52b0 | 596 | __be32 *targets; |
b76cdba9 MW |
597 | |
598 | targets = bond->params.arp_targets; | |
599 | newtarget = in_aton(buf + 1); | |
600 | /* look for adds */ | |
601 | if (buf[0] == '+') { | |
d3bb52b0 | 602 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
a4aee5c8 | 603 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
63779436 | 604 | bond->dev->name, &newtarget); |
b76cdba9 MW |
605 | goto out; |
606 | } | |
87a7b84b VF |
607 | |
608 | if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */ | |
609 | pr_err("%s: ARP target %pI4 is already present\n", | |
610 | bond->dev->name, &newtarget); | |
611 | goto out; | |
b76cdba9 | 612 | } |
87a7b84b VF |
613 | |
614 | i = bond_get_targets_ip(targets, 0); /* first free slot */ | |
615 | if (i == -1) { | |
a4aee5c8 | 616 | pr_err("%s: ARP target table is full!\n", |
b76cdba9 | 617 | bond->dev->name); |
b76cdba9 MW |
618 | goto out; |
619 | } | |
620 | ||
87a7b84b VF |
621 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, |
622 | &newtarget); | |
623 | targets[i] = newtarget; | |
3d632c3f | 624 | } else if (buf[0] == '-') { |
d3bb52b0 | 625 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
a4aee5c8 | 626 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
63779436 | 627 | bond->dev->name, &newtarget); |
b76cdba9 MW |
628 | goto out; |
629 | } | |
630 | ||
87a7b84b VF |
631 | i = bond_get_targets_ip(targets, newtarget); |
632 | if (i == -1) { | |
a4aee5c8 JP |
633 | pr_info("%s: unable to remove nonexistent ARP target %pI4.\n", |
634 | bond->dev->name, &newtarget); | |
b76cdba9 MW |
635 | goto out; |
636 | } | |
87a7b84b VF |
637 | |
638 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, | |
639 | &newtarget); | |
640 | for (; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
641 | targets[i] = targets[i+1]; | |
642 | targets[i] = 0; | |
3d632c3f | 643 | } else { |
a4aee5c8 JP |
644 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
645 | bond->dev->name); | |
b76cdba9 MW |
646 | ret = -EPERM; |
647 | goto out; | |
648 | } | |
649 | ||
87a7b84b | 650 | ret = count; |
b76cdba9 MW |
651 | out: |
652 | return ret; | |
653 | } | |
43cb76d9 | 654 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); |
b76cdba9 MW |
655 | |
656 | /* | |
657 | * Show and set the up and down delays. These must be multiples of the | |
658 | * MII monitoring value, and are stored internally as the multiplier. | |
659 | * Thus, we must translate to MS for the real world. | |
660 | */ | |
43cb76d9 GKH |
661 | static ssize_t bonding_show_downdelay(struct device *d, |
662 | struct device_attribute *attr, | |
663 | char *buf) | |
b76cdba9 | 664 | { |
43cb76d9 | 665 | struct bonding *bond = to_bond(d); |
b76cdba9 | 666 | |
7bd46508 | 667 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
b76cdba9 MW |
668 | } |
669 | ||
43cb76d9 GKH |
670 | static ssize_t bonding_store_downdelay(struct device *d, |
671 | struct device_attribute *attr, | |
672 | const char *buf, size_t count) | |
b76cdba9 MW |
673 | { |
674 | int new_value, ret = count; | |
43cb76d9 | 675 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
676 | |
677 | if (!(bond->params.miimon)) { | |
a4aee5c8 | 678 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
b76cdba9 MW |
679 | bond->dev->name); |
680 | ret = -EPERM; | |
681 | goto out; | |
682 | } | |
683 | ||
684 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 685 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
b76cdba9 MW |
686 | ret = -EINVAL; |
687 | goto out; | |
688 | } | |
689 | if (new_value < 0) { | |
a4aee5c8 | 690 | pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
1bc7db16 | 691 | bond->dev->name, new_value, 0, INT_MAX); |
b76cdba9 MW |
692 | ret = -EINVAL; |
693 | goto out; | |
694 | } else { | |
695 | if ((new_value % bond->params.miimon) != 0) { | |
a4aee5c8 | 696 | pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
e5e2a8fd JP |
697 | bond->dev->name, new_value, |
698 | bond->params.miimon, | |
699 | (new_value / bond->params.miimon) * | |
700 | bond->params.miimon); | |
b76cdba9 MW |
701 | } |
702 | bond->params.downdelay = new_value / bond->params.miimon; | |
a4aee5c8 JP |
703 | pr_info("%s: Setting down delay to %d.\n", |
704 | bond->dev->name, | |
705 | bond->params.downdelay * bond->params.miimon); | |
b76cdba9 MW |
706 | |
707 | } | |
708 | ||
709 | out: | |
710 | return ret; | |
711 | } | |
3d632c3f SH |
712 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
713 | bonding_show_downdelay, bonding_store_downdelay); | |
b76cdba9 | 714 | |
43cb76d9 GKH |
715 | static ssize_t bonding_show_updelay(struct device *d, |
716 | struct device_attribute *attr, | |
717 | char *buf) | |
b76cdba9 | 718 | { |
43cb76d9 | 719 | struct bonding *bond = to_bond(d); |
b76cdba9 | 720 | |
7bd46508 | 721 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
b76cdba9 MW |
722 | |
723 | } | |
724 | ||
43cb76d9 GKH |
725 | static ssize_t bonding_store_updelay(struct device *d, |
726 | struct device_attribute *attr, | |
727 | const char *buf, size_t count) | |
b76cdba9 MW |
728 | { |
729 | int new_value, ret = count; | |
43cb76d9 | 730 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
731 | |
732 | if (!(bond->params.miimon)) { | |
a4aee5c8 | 733 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
b76cdba9 MW |
734 | bond->dev->name); |
735 | ret = -EPERM; | |
736 | goto out; | |
737 | } | |
738 | ||
739 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 740 | pr_err("%s: no up delay value specified.\n", |
b76cdba9 MW |
741 | bond->dev->name); |
742 | ret = -EINVAL; | |
743 | goto out; | |
744 | } | |
745 | if (new_value < 0) { | |
1bc7db16 | 746 | pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n", |
747 | bond->dev->name, new_value, 0, INT_MAX); | |
b76cdba9 MW |
748 | ret = -EINVAL; |
749 | goto out; | |
750 | } else { | |
751 | if ((new_value % bond->params.miimon) != 0) { | |
a4aee5c8 | 752 | pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
e5e2a8fd JP |
753 | bond->dev->name, new_value, |
754 | bond->params.miimon, | |
755 | (new_value / bond->params.miimon) * | |
756 | bond->params.miimon); | |
b76cdba9 MW |
757 | } |
758 | bond->params.updelay = new_value / bond->params.miimon; | |
a4aee5c8 JP |
759 | pr_info("%s: Setting up delay to %d.\n", |
760 | bond->dev->name, | |
761 | bond->params.updelay * bond->params.miimon); | |
b76cdba9 MW |
762 | } |
763 | ||
764 | out: | |
765 | return ret; | |
766 | } | |
3d632c3f SH |
767 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
768 | bonding_show_updelay, bonding_store_updelay); | |
b76cdba9 MW |
769 | |
770 | /* | |
771 | * Show and set the LACP interval. Interface must be down, and the mode | |
772 | * must be set to 802.3ad mode. | |
773 | */ | |
43cb76d9 GKH |
774 | static ssize_t bonding_show_lacp(struct device *d, |
775 | struct device_attribute *attr, | |
776 | char *buf) | |
b76cdba9 | 777 | { |
43cb76d9 | 778 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
779 | |
780 | return sprintf(buf, "%s %d\n", | |
781 | bond_lacp_tbl[bond->params.lacp_fast].modename, | |
7bd46508 | 782 | bond->params.lacp_fast); |
b76cdba9 MW |
783 | } |
784 | ||
43cb76d9 GKH |
785 | static ssize_t bonding_store_lacp(struct device *d, |
786 | struct device_attribute *attr, | |
787 | const char *buf, size_t count) | |
b76cdba9 MW |
788 | { |
789 | int new_value, ret = count; | |
43cb76d9 | 790 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
791 | |
792 | if (bond->dev->flags & IFF_UP) { | |
a4aee5c8 | 793 | pr_err("%s: Unable to update LACP rate because interface is up.\n", |
b76cdba9 MW |
794 | bond->dev->name); |
795 | ret = -EPERM; | |
796 | goto out; | |
797 | } | |
798 | ||
799 | if (bond->params.mode != BOND_MODE_8023AD) { | |
a4aee5c8 | 800 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
b76cdba9 MW |
801 | bond->dev->name); |
802 | ret = -EPERM; | |
803 | goto out; | |
804 | } | |
805 | ||
ece95f7f | 806 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
b76cdba9 MW |
807 | |
808 | if ((new_value == 1) || (new_value == 0)) { | |
809 | bond->params.lacp_fast = new_value; | |
ba824a8b | 810 | bond_3ad_update_lacp_rate(bond); |
a4aee5c8 | 811 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
3d632c3f SH |
812 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
813 | new_value); | |
b76cdba9 | 814 | } else { |
a4aee5c8 | 815 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
3d632c3f | 816 | bond->dev->name, (int)strlen(buf) - 1, buf); |
b76cdba9 MW |
817 | ret = -EINVAL; |
818 | } | |
819 | out: | |
820 | return ret; | |
821 | } | |
3d632c3f SH |
822 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
823 | bonding_show_lacp, bonding_store_lacp); | |
b76cdba9 | 824 | |
655f8919 | 825 | static ssize_t bonding_show_min_links(struct device *d, |
826 | struct device_attribute *attr, | |
827 | char *buf) | |
828 | { | |
829 | struct bonding *bond = to_bond(d); | |
830 | ||
831 | return sprintf(buf, "%d\n", bond->params.min_links); | |
832 | } | |
833 | ||
834 | static ssize_t bonding_store_min_links(struct device *d, | |
835 | struct device_attribute *attr, | |
836 | const char *buf, size_t count) | |
837 | { | |
838 | struct bonding *bond = to_bond(d); | |
839 | int ret; | |
840 | unsigned int new_value; | |
841 | ||
842 | ret = kstrtouint(buf, 0, &new_value); | |
843 | if (ret < 0) { | |
844 | pr_err("%s: Ignoring invalid min links value %s.\n", | |
845 | bond->dev->name, buf); | |
846 | return ret; | |
847 | } | |
848 | ||
849 | pr_info("%s: Setting min links value to %u\n", | |
850 | bond->dev->name, new_value); | |
851 | bond->params.min_links = new_value; | |
852 | return count; | |
853 | } | |
854 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, | |
855 | bonding_show_min_links, bonding_store_min_links); | |
856 | ||
fd989c83 JV |
857 | static ssize_t bonding_show_ad_select(struct device *d, |
858 | struct device_attribute *attr, | |
859 | char *buf) | |
860 | { | |
861 | struct bonding *bond = to_bond(d); | |
862 | ||
863 | return sprintf(buf, "%s %d\n", | |
864 | ad_select_tbl[bond->params.ad_select].modename, | |
865 | bond->params.ad_select); | |
866 | } | |
867 | ||
868 | ||
869 | static ssize_t bonding_store_ad_select(struct device *d, | |
870 | struct device_attribute *attr, | |
871 | const char *buf, size_t count) | |
872 | { | |
873 | int new_value, ret = count; | |
874 | struct bonding *bond = to_bond(d); | |
875 | ||
876 | if (bond->dev->flags & IFF_UP) { | |
a4aee5c8 JP |
877 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
878 | bond->dev->name); | |
fd989c83 JV |
879 | ret = -EPERM; |
880 | goto out; | |
881 | } | |
882 | ||
883 | new_value = bond_parse_parm(buf, ad_select_tbl); | |
884 | ||
885 | if (new_value != -1) { | |
886 | bond->params.ad_select = new_value; | |
a4aee5c8 JP |
887 | pr_info("%s: Setting ad_select to %s (%d).\n", |
888 | bond->dev->name, ad_select_tbl[new_value].modename, | |
889 | new_value); | |
fd989c83 | 890 | } else { |
a4aee5c8 | 891 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
fd989c83 JV |
892 | bond->dev->name, (int)strlen(buf) - 1, buf); |
893 | ret = -EINVAL; | |
894 | } | |
895 | out: | |
896 | return ret; | |
897 | } | |
3d632c3f SH |
898 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
899 | bonding_show_ad_select, bonding_store_ad_select); | |
fd989c83 | 900 | |
ad246c99 BH |
901 | /* |
902 | * Show and set the number of peer notifications to send after a failover event. | |
903 | */ | |
904 | static ssize_t bonding_show_num_peer_notif(struct device *d, | |
905 | struct device_attribute *attr, | |
906 | char *buf) | |
907 | { | |
908 | struct bonding *bond = to_bond(d); | |
909 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); | |
910 | } | |
911 | ||
912 | static ssize_t bonding_store_num_peer_notif(struct device *d, | |
913 | struct device_attribute *attr, | |
914 | const char *buf, size_t count) | |
915 | { | |
916 | struct bonding *bond = to_bond(d); | |
917 | int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); | |
918 | return err ? err : count; | |
919 | } | |
920 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, | |
921 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
922 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, | |
923 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
924 | ||
b76cdba9 MW |
925 | /* |
926 | * Show and set the MII monitor interval. There are two tricky bits | |
927 | * here. First, if MII monitoring is activated, then we must disable | |
928 | * ARP monitoring. Second, if the timer isn't running, we must | |
929 | * start it. | |
930 | */ | |
43cb76d9 GKH |
931 | static ssize_t bonding_show_miimon(struct device *d, |
932 | struct device_attribute *attr, | |
933 | char *buf) | |
b76cdba9 | 934 | { |
43cb76d9 | 935 | struct bonding *bond = to_bond(d); |
b76cdba9 | 936 | |
7bd46508 | 937 | return sprintf(buf, "%d\n", bond->params.miimon); |
b76cdba9 MW |
938 | } |
939 | ||
43cb76d9 GKH |
940 | static ssize_t bonding_store_miimon(struct device *d, |
941 | struct device_attribute *attr, | |
942 | const char *buf, size_t count) | |
b76cdba9 MW |
943 | { |
944 | int new_value, ret = count; | |
43cb76d9 | 945 | struct bonding *bond = to_bond(d); |
b76cdba9 | 946 | |
fbb0c41b | 947 | if (!rtnl_trylock()) |
948 | return restart_syscall(); | |
b76cdba9 | 949 | if (sscanf(buf, "%d", &new_value) != 1) { |
a4aee5c8 | 950 | pr_err("%s: no miimon value specified.\n", |
b76cdba9 MW |
951 | bond->dev->name); |
952 | ret = -EINVAL; | |
953 | goto out; | |
954 | } | |
955 | if (new_value < 0) { | |
a4aee5c8 | 956 | pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n", |
1bc7db16 | 957 | bond->dev->name, new_value, 0, INT_MAX); |
b76cdba9 MW |
958 | ret = -EINVAL; |
959 | goto out; | |
1bc7db16 | 960 | } |
961 | pr_info("%s: Setting MII monitoring interval to %d.\n", | |
962 | bond->dev->name, new_value); | |
963 | bond->params.miimon = new_value; | |
964 | if (bond->params.updelay) | |
965 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", | |
966 | bond->dev->name, | |
967 | bond->params.updelay * bond->params.miimon); | |
968 | if (bond->params.downdelay) | |
969 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", | |
970 | bond->dev->name, | |
971 | bond->params.downdelay * bond->params.miimon); | |
972 | if (new_value && bond->params.arp_interval) { | |
973 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", | |
974 | bond->dev->name); | |
975 | bond->params.arp_interval = 0; | |
976 | if (bond->params.arp_validate) | |
977 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
978 | } | |
979 | if (bond->dev->flags & IFF_UP) { | |
980 | /* If the interface is up, we may need to fire off | |
981 | * the MII timer. If the interface is down, the | |
982 | * timer will get fired off when the open function | |
983 | * is called. | |
984 | */ | |
985 | if (!new_value) { | |
986 | cancel_delayed_work_sync(&bond->mii_work); | |
987 | } else { | |
fbb0c41b | 988 | cancel_delayed_work_sync(&bond->arp_work); |
989 | queue_delayed_work(bond->wq, &bond->mii_work, 0); | |
b76cdba9 MW |
990 | } |
991 | } | |
992 | out: | |
fbb0c41b | 993 | rtnl_unlock(); |
b76cdba9 MW |
994 | return ret; |
995 | } | |
3d632c3f SH |
996 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
997 | bonding_show_miimon, bonding_store_miimon); | |
b76cdba9 MW |
998 | |
999 | /* | |
1000 | * Show and set the primary slave. The store function is much | |
1001 | * simpler than bonding_store_slaves function because it only needs to | |
1002 | * handle one interface name. | |
1003 | * The bond must be a mode that supports a primary for this be | |
1004 | * set. | |
1005 | */ | |
43cb76d9 GKH |
1006 | static ssize_t bonding_show_primary(struct device *d, |
1007 | struct device_attribute *attr, | |
1008 | char *buf) | |
b76cdba9 MW |
1009 | { |
1010 | int count = 0; | |
43cb76d9 | 1011 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1012 | |
1013 | if (bond->primary_slave) | |
7bd46508 | 1014 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
b76cdba9 MW |
1015 | |
1016 | return count; | |
1017 | } | |
1018 | ||
43cb76d9 GKH |
1019 | static ssize_t bonding_store_primary(struct device *d, |
1020 | struct device_attribute *attr, | |
1021 | const char *buf, size_t count) | |
b76cdba9 MW |
1022 | { |
1023 | int i; | |
1024 | struct slave *slave; | |
43cb76d9 | 1025 | struct bonding *bond = to_bond(d); |
f4bb2e9c | 1026 | char ifname[IFNAMSIZ]; |
b76cdba9 | 1027 | |
496a60cd EB |
1028 | if (!rtnl_trylock()) |
1029 | return restart_syscall(); | |
e843fa50 | 1030 | block_netpoll_tx(); |
e934dd78 JV |
1031 | read_lock(&bond->lock); |
1032 | write_lock_bh(&bond->curr_slave_lock); | |
1033 | ||
b76cdba9 | 1034 | if (!USES_PRIMARY(bond->params.mode)) { |
a4aee5c8 JP |
1035 | pr_info("%s: Unable to set primary slave; %s is in mode %d\n", |
1036 | bond->dev->name, bond->dev->name, bond->params.mode); | |
f4bb2e9c AG |
1037 | goto out; |
1038 | } | |
b76cdba9 | 1039 | |
eb6e98a1 | 1040 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
b76cdba9 | 1041 | |
f4bb2e9c AG |
1042 | /* check to see if we are clearing primary */ |
1043 | if (!strlen(ifname) || buf[0] == '\n') { | |
1044 | pr_info("%s: Setting primary slave to None.\n", | |
1045 | bond->dev->name); | |
1046 | bond->primary_slave = NULL; | |
eb492f74 | 1047 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
f4bb2e9c AG |
1048 | bond_select_active_slave(bond); |
1049 | goto out; | |
1050 | } | |
1051 | ||
1052 | bond_for_each_slave(bond, slave, i) { | |
1053 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | |
1054 | pr_info("%s: Setting %s as primary slave.\n", | |
1055 | bond->dev->name, slave->dev->name); | |
1056 | bond->primary_slave = slave; | |
1057 | strcpy(bond->params.primary, slave->dev->name); | |
1058 | bond_select_active_slave(bond); | |
1059 | goto out; | |
b76cdba9 MW |
1060 | } |
1061 | } | |
f4bb2e9c | 1062 | |
8a93664d WP |
1063 | strncpy(bond->params.primary, ifname, IFNAMSIZ); |
1064 | bond->params.primary[IFNAMSIZ - 1] = 0; | |
1065 | ||
1066 | pr_info("%s: Recording %s as primary, " | |
1067 | "but it has not been enslaved to %s yet.\n", | |
1068 | bond->dev->name, ifname, bond->dev->name); | |
b76cdba9 | 1069 | out: |
e934dd78 JV |
1070 | write_unlock_bh(&bond->curr_slave_lock); |
1071 | read_unlock(&bond->lock); | |
e843fa50 | 1072 | unblock_netpoll_tx(); |
6603a6f2 JV |
1073 | rtnl_unlock(); |
1074 | ||
b76cdba9 MW |
1075 | return count; |
1076 | } | |
3d632c3f SH |
1077 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
1078 | bonding_show_primary, bonding_store_primary); | |
b76cdba9 | 1079 | |
a549952a JP |
1080 | /* |
1081 | * Show and set the primary_reselect flag. | |
1082 | */ | |
1083 | static ssize_t bonding_show_primary_reselect(struct device *d, | |
1084 | struct device_attribute *attr, | |
1085 | char *buf) | |
1086 | { | |
1087 | struct bonding *bond = to_bond(d); | |
1088 | ||
1089 | return sprintf(buf, "%s %d\n", | |
1090 | pri_reselect_tbl[bond->params.primary_reselect].modename, | |
1091 | bond->params.primary_reselect); | |
1092 | } | |
1093 | ||
1094 | static ssize_t bonding_store_primary_reselect(struct device *d, | |
1095 | struct device_attribute *attr, | |
1096 | const char *buf, size_t count) | |
1097 | { | |
1098 | int new_value, ret = count; | |
1099 | struct bonding *bond = to_bond(d); | |
1100 | ||
1101 | if (!rtnl_trylock()) | |
1102 | return restart_syscall(); | |
1103 | ||
1104 | new_value = bond_parse_parm(buf, pri_reselect_tbl); | |
1105 | if (new_value < 0) { | |
a4aee5c8 | 1106 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
a549952a JP |
1107 | bond->dev->name, |
1108 | (int) strlen(buf) - 1, buf); | |
1109 | ret = -EINVAL; | |
1110 | goto out; | |
1111 | } | |
1112 | ||
1113 | bond->params.primary_reselect = new_value; | |
a4aee5c8 | 1114 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
a549952a JP |
1115 | bond->dev->name, pri_reselect_tbl[new_value].modename, |
1116 | new_value); | |
1117 | ||
e843fa50 | 1118 | block_netpoll_tx(); |
a549952a JP |
1119 | read_lock(&bond->lock); |
1120 | write_lock_bh(&bond->curr_slave_lock); | |
1121 | bond_select_active_slave(bond); | |
1122 | write_unlock_bh(&bond->curr_slave_lock); | |
1123 | read_unlock(&bond->lock); | |
e843fa50 | 1124 | unblock_netpoll_tx(); |
a549952a JP |
1125 | out: |
1126 | rtnl_unlock(); | |
1127 | return ret; | |
1128 | } | |
1129 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, | |
1130 | bonding_show_primary_reselect, | |
1131 | bonding_store_primary_reselect); | |
1132 | ||
b76cdba9 MW |
1133 | /* |
1134 | * Show and set the use_carrier flag. | |
1135 | */ | |
43cb76d9 GKH |
1136 | static ssize_t bonding_show_carrier(struct device *d, |
1137 | struct device_attribute *attr, | |
1138 | char *buf) | |
b76cdba9 | 1139 | { |
43cb76d9 | 1140 | struct bonding *bond = to_bond(d); |
b76cdba9 | 1141 | |
7bd46508 | 1142 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
b76cdba9 MW |
1143 | } |
1144 | ||
43cb76d9 GKH |
1145 | static ssize_t bonding_store_carrier(struct device *d, |
1146 | struct device_attribute *attr, | |
1147 | const char *buf, size_t count) | |
b76cdba9 MW |
1148 | { |
1149 | int new_value, ret = count; | |
43cb76d9 | 1150 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1151 | |
1152 | ||
1153 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 1154 | pr_err("%s: no use_carrier value specified.\n", |
b76cdba9 MW |
1155 | bond->dev->name); |
1156 | ret = -EINVAL; | |
1157 | goto out; | |
1158 | } | |
1159 | if ((new_value == 0) || (new_value == 1)) { | |
1160 | bond->params.use_carrier = new_value; | |
a4aee5c8 JP |
1161 | pr_info("%s: Setting use_carrier to %d.\n", |
1162 | bond->dev->name, new_value); | |
b76cdba9 | 1163 | } else { |
a4aee5c8 JP |
1164 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
1165 | bond->dev->name, new_value); | |
b76cdba9 MW |
1166 | } |
1167 | out: | |
672bda33 | 1168 | return ret; |
b76cdba9 | 1169 | } |
3d632c3f SH |
1170 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
1171 | bonding_show_carrier, bonding_store_carrier); | |
b76cdba9 MW |
1172 | |
1173 | ||
1174 | /* | |
1175 | * Show and set currently active_slave. | |
1176 | */ | |
43cb76d9 GKH |
1177 | static ssize_t bonding_show_active_slave(struct device *d, |
1178 | struct device_attribute *attr, | |
1179 | char *buf) | |
b76cdba9 MW |
1180 | { |
1181 | struct slave *curr; | |
43cb76d9 | 1182 | struct bonding *bond = to_bond(d); |
16cd0160 | 1183 | int count = 0; |
b76cdba9 | 1184 | |
b76cdba9 MW |
1185 | read_lock(&bond->curr_slave_lock); |
1186 | curr = bond->curr_active_slave; | |
1187 | read_unlock(&bond->curr_slave_lock); | |
1188 | ||
1189 | if (USES_PRIMARY(bond->params.mode) && curr) | |
7bd46508 | 1190 | count = sprintf(buf, "%s\n", curr->dev->name); |
b76cdba9 MW |
1191 | return count; |
1192 | } | |
1193 | ||
43cb76d9 GKH |
1194 | static ssize_t bonding_store_active_slave(struct device *d, |
1195 | struct device_attribute *attr, | |
1196 | const char *buf, size_t count) | |
b76cdba9 MW |
1197 | { |
1198 | int i; | |
1199 | struct slave *slave; | |
3d632c3f SH |
1200 | struct slave *old_active = NULL; |
1201 | struct slave *new_active = NULL; | |
43cb76d9 | 1202 | struct bonding *bond = to_bond(d); |
f4bb2e9c | 1203 | char ifname[IFNAMSIZ]; |
b76cdba9 | 1204 | |
496a60cd EB |
1205 | if (!rtnl_trylock()) |
1206 | return restart_syscall(); | |
e843fa50 NH |
1207 | |
1208 | block_netpoll_tx(); | |
e934dd78 JV |
1209 | read_lock(&bond->lock); |
1210 | write_lock_bh(&bond->curr_slave_lock); | |
1466a219 | 1211 | |
f4bb2e9c | 1212 | if (!USES_PRIMARY(bond->params.mode)) { |
a4aee5c8 | 1213 | pr_info("%s: Unable to change active slave; %s is in mode %d\n", |
3d632c3f | 1214 | bond->dev->name, bond->dev->name, bond->params.mode); |
f4bb2e9c AG |
1215 | goto out; |
1216 | } | |
1217 | ||
c84e1590 | 1218 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
f4bb2e9c AG |
1219 | |
1220 | /* check to see if we are clearing active */ | |
1221 | if (!strlen(ifname) || buf[0] == '\n') { | |
1222 | pr_info("%s: Clearing current active slave.\n", | |
1223 | bond->dev->name); | |
1224 | bond->curr_active_slave = NULL; | |
1225 | bond_select_active_slave(bond); | |
1226 | goto out; | |
1227 | } | |
1228 | ||
1229 | bond_for_each_slave(bond, slave, i) { | |
1230 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | |
1231 | old_active = bond->curr_active_slave; | |
1232 | new_active = slave; | |
1233 | if (new_active == old_active) { | |
1234 | /* do nothing */ | |
1235 | pr_info("%s: %s is already the current" | |
1236 | " active slave.\n", | |
1237 | bond->dev->name, | |
1238 | slave->dev->name); | |
1239 | goto out; | |
1240 | } | |
1241 | else { | |
1242 | if ((new_active) && | |
1243 | (old_active) && | |
1244 | (new_active->link == BOND_LINK_UP) && | |
1245 | IS_UP(new_active->dev)) { | |
1246 | pr_info("%s: Setting %s as active" | |
1247 | " slave.\n", | |
a4aee5c8 JP |
1248 | bond->dev->name, |
1249 | slave->dev->name); | |
f4bb2e9c AG |
1250 | bond_change_active_slave(bond, |
1251 | new_active); | |
b76cdba9 MW |
1252 | } |
1253 | else { | |
f4bb2e9c AG |
1254 | pr_info("%s: Could not set %s as" |
1255 | " active slave; either %s is" | |
1256 | " down or the link is down.\n", | |
1257 | bond->dev->name, | |
1258 | slave->dev->name, | |
1259 | slave->dev->name); | |
b76cdba9 | 1260 | } |
f4bb2e9c | 1261 | goto out; |
b76cdba9 MW |
1262 | } |
1263 | } | |
b76cdba9 | 1264 | } |
f4bb2e9c AG |
1265 | |
1266 | pr_info("%s: Unable to set %.*s as active slave.\n", | |
1267 | bond->dev->name, (int)strlen(buf) - 1, buf); | |
3d632c3f | 1268 | out: |
e934dd78 JV |
1269 | write_unlock_bh(&bond->curr_slave_lock); |
1270 | read_unlock(&bond->lock); | |
e843fa50 NH |
1271 | unblock_netpoll_tx(); |
1272 | ||
6603a6f2 JV |
1273 | rtnl_unlock(); |
1274 | ||
b76cdba9 MW |
1275 | return count; |
1276 | ||
1277 | } | |
3d632c3f SH |
1278 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
1279 | bonding_show_active_slave, bonding_store_active_slave); | |
b76cdba9 MW |
1280 | |
1281 | ||
1282 | /* | |
1283 | * Show link status of the bond interface. | |
1284 | */ | |
43cb76d9 GKH |
1285 | static ssize_t bonding_show_mii_status(struct device *d, |
1286 | struct device_attribute *attr, | |
1287 | char *buf) | |
b76cdba9 MW |
1288 | { |
1289 | struct slave *curr; | |
43cb76d9 | 1290 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1291 | |
1292 | read_lock(&bond->curr_slave_lock); | |
1293 | curr = bond->curr_active_slave; | |
1294 | read_unlock(&bond->curr_slave_lock); | |
1295 | ||
3d632c3f | 1296 | return sprintf(buf, "%s\n", curr ? "up" : "down"); |
b76cdba9 | 1297 | } |
43cb76d9 | 1298 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
b76cdba9 | 1299 | |
b76cdba9 MW |
1300 | /* |
1301 | * Show current 802.3ad aggregator ID. | |
1302 | */ | |
43cb76d9 GKH |
1303 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
1304 | struct device_attribute *attr, | |
1305 | char *buf) | |
b76cdba9 MW |
1306 | { |
1307 | int count = 0; | |
43cb76d9 | 1308 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1309 | |
1310 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1311 | struct ad_info ad_info; | |
3d632c3f | 1312 | count = sprintf(buf, "%d\n", |
318debd8 | 1313 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1314 | ? 0 : ad_info.aggregator_id); |
b76cdba9 | 1315 | } |
b76cdba9 MW |
1316 | |
1317 | return count; | |
1318 | } | |
43cb76d9 | 1319 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
b76cdba9 MW |
1320 | |
1321 | ||
1322 | /* | |
1323 | * Show number of active 802.3ad ports. | |
1324 | */ | |
43cb76d9 GKH |
1325 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
1326 | struct device_attribute *attr, | |
1327 | char *buf) | |
b76cdba9 MW |
1328 | { |
1329 | int count = 0; | |
43cb76d9 | 1330 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1331 | |
1332 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1333 | struct ad_info ad_info; | |
3d632c3f | 1334 | count = sprintf(buf, "%d\n", |
318debd8 | 1335 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1336 | ? 0 : ad_info.ports); |
b76cdba9 | 1337 | } |
b76cdba9 MW |
1338 | |
1339 | return count; | |
1340 | } | |
43cb76d9 | 1341 | static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); |
b76cdba9 MW |
1342 | |
1343 | ||
1344 | /* | |
1345 | * Show current 802.3ad actor key. | |
1346 | */ | |
43cb76d9 GKH |
1347 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
1348 | struct device_attribute *attr, | |
1349 | char *buf) | |
b76cdba9 MW |
1350 | { |
1351 | int count = 0; | |
43cb76d9 | 1352 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1353 | |
1354 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1355 | struct ad_info ad_info; | |
3d632c3f | 1356 | count = sprintf(buf, "%d\n", |
318debd8 | 1357 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1358 | ? 0 : ad_info.actor_key); |
b76cdba9 | 1359 | } |
b76cdba9 MW |
1360 | |
1361 | return count; | |
1362 | } | |
43cb76d9 | 1363 | static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); |
b76cdba9 MW |
1364 | |
1365 | ||
1366 | /* | |
1367 | * Show current 802.3ad partner key. | |
1368 | */ | |
43cb76d9 GKH |
1369 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
1370 | struct device_attribute *attr, | |
1371 | char *buf) | |
b76cdba9 MW |
1372 | { |
1373 | int count = 0; | |
43cb76d9 | 1374 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1375 | |
1376 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1377 | struct ad_info ad_info; | |
3d632c3f | 1378 | count = sprintf(buf, "%d\n", |
318debd8 | 1379 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1380 | ? 0 : ad_info.partner_key); |
b76cdba9 | 1381 | } |
b76cdba9 MW |
1382 | |
1383 | return count; | |
1384 | } | |
43cb76d9 | 1385 | static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); |
b76cdba9 MW |
1386 | |
1387 | ||
1388 | /* | |
1389 | * Show current 802.3ad partner mac. | |
1390 | */ | |
43cb76d9 GKH |
1391 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
1392 | struct device_attribute *attr, | |
1393 | char *buf) | |
b76cdba9 MW |
1394 | { |
1395 | int count = 0; | |
43cb76d9 | 1396 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1397 | |
1398 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1399 | struct ad_info ad_info; | |
3d632c3f | 1400 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
e174961c | 1401 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
b76cdba9 | 1402 | } |
b76cdba9 MW |
1403 | |
1404 | return count; | |
1405 | } | |
43cb76d9 | 1406 | static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); |
b76cdba9 | 1407 | |
bb1d9123 AG |
1408 | /* |
1409 | * Show the queue_ids of the slaves in the current bond. | |
1410 | */ | |
1411 | static ssize_t bonding_show_queue_id(struct device *d, | |
1412 | struct device_attribute *attr, | |
1413 | char *buf) | |
1414 | { | |
1415 | struct slave *slave; | |
1416 | int i, res = 0; | |
1417 | struct bonding *bond = to_bond(d); | |
1418 | ||
1419 | if (!rtnl_trylock()) | |
1420 | return restart_syscall(); | |
1421 | ||
1422 | read_lock(&bond->lock); | |
1423 | bond_for_each_slave(bond, slave, i) { | |
79236680 NP |
1424 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
1425 | /* not enough space for another interface_name:queue_id pair */ | |
bb1d9123 AG |
1426 | if ((PAGE_SIZE - res) > 10) |
1427 | res = PAGE_SIZE - 10; | |
1428 | res += sprintf(buf + res, "++more++ "); | |
1429 | break; | |
1430 | } | |
1431 | res += sprintf(buf + res, "%s:%d ", | |
1432 | slave->dev->name, slave->queue_id); | |
1433 | } | |
1434 | read_unlock(&bond->lock); | |
1435 | if (res) | |
1436 | buf[res-1] = '\n'; /* eat the leftover space */ | |
1437 | rtnl_unlock(); | |
1438 | return res; | |
1439 | } | |
1440 | ||
1441 | /* | |
1442 | * Set the queue_ids of the slaves in the current bond. The bond | |
1443 | * interface must be enslaved for this to work. | |
1444 | */ | |
1445 | static ssize_t bonding_store_queue_id(struct device *d, | |
1446 | struct device_attribute *attr, | |
1447 | const char *buffer, size_t count) | |
1448 | { | |
1449 | struct slave *slave, *update_slave; | |
1450 | struct bonding *bond = to_bond(d); | |
1451 | u16 qid; | |
1452 | int i, ret = count; | |
1453 | char *delim; | |
1454 | struct net_device *sdev = NULL; | |
1455 | ||
1456 | if (!rtnl_trylock()) | |
1457 | return restart_syscall(); | |
1458 | ||
1459 | /* delim will point to queue id if successful */ | |
1460 | delim = strchr(buffer, ':'); | |
1461 | if (!delim) | |
1462 | goto err_no_cmd; | |
1463 | ||
1464 | /* | |
1465 | * Terminate string that points to device name and bump it | |
1466 | * up one, so we can read the queue id there. | |
1467 | */ | |
1468 | *delim = '\0'; | |
1469 | if (sscanf(++delim, "%hd\n", &qid) != 1) | |
1470 | goto err_no_cmd; | |
1471 | ||
1472 | /* Check buffer length, valid ifname and queue id */ | |
1473 | if (strlen(buffer) > IFNAMSIZ || | |
1474 | !dev_valid_name(buffer) || | |
8a540ff9 | 1475 | qid > bond->dev->real_num_tx_queues) |
bb1d9123 AG |
1476 | goto err_no_cmd; |
1477 | ||
1478 | /* Get the pointer to that interface if it exists */ | |
1479 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); | |
1480 | if (!sdev) | |
1481 | goto err_no_cmd; | |
1482 | ||
1483 | read_lock(&bond->lock); | |
1484 | ||
1485 | /* Search for thes slave and check for duplicate qids */ | |
1486 | update_slave = NULL; | |
1487 | bond_for_each_slave(bond, slave, i) { | |
1488 | if (sdev == slave->dev) | |
1489 | /* | |
1490 | * We don't need to check the matching | |
1491 | * slave for dups, since we're overwriting it | |
1492 | */ | |
1493 | update_slave = slave; | |
1494 | else if (qid && qid == slave->queue_id) { | |
1495 | goto err_no_cmd_unlock; | |
1496 | } | |
1497 | } | |
1498 | ||
1499 | if (!update_slave) | |
1500 | goto err_no_cmd_unlock; | |
1501 | ||
1502 | /* Actually set the qids for the slave */ | |
1503 | update_slave->queue_id = qid; | |
1504 | ||
1505 | read_unlock(&bond->lock); | |
1506 | out: | |
1507 | rtnl_unlock(); | |
1508 | return ret; | |
1509 | ||
1510 | err_no_cmd_unlock: | |
1511 | read_unlock(&bond->lock); | |
1512 | err_no_cmd: | |
1513 | pr_info("invalid input for queue_id set for %s.\n", | |
1514 | bond->dev->name); | |
1515 | ret = -EPERM; | |
1516 | goto out; | |
1517 | } | |
1518 | ||
1519 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, | |
1520 | bonding_store_queue_id); | |
1521 | ||
1522 | ||
ebd8e497 AG |
1523 | /* |
1524 | * Show and set the all_slaves_active flag. | |
1525 | */ | |
1526 | static ssize_t bonding_show_slaves_active(struct device *d, | |
1527 | struct device_attribute *attr, | |
1528 | char *buf) | |
1529 | { | |
1530 | struct bonding *bond = to_bond(d); | |
1531 | ||
1532 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); | |
1533 | } | |
1534 | ||
1535 | static ssize_t bonding_store_slaves_active(struct device *d, | |
1536 | struct device_attribute *attr, | |
1537 | const char *buf, size_t count) | |
1538 | { | |
1539 | int i, new_value, ret = count; | |
1540 | struct bonding *bond = to_bond(d); | |
1541 | struct slave *slave; | |
1542 | ||
1543 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1544 | pr_err("%s: no all_slaves_active value specified.\n", | |
1545 | bond->dev->name); | |
1546 | ret = -EINVAL; | |
1547 | goto out; | |
1548 | } | |
1549 | ||
1550 | if (new_value == bond->params.all_slaves_active) | |
1551 | goto out; | |
1552 | ||
1553 | if ((new_value == 0) || (new_value == 1)) { | |
1554 | bond->params.all_slaves_active = new_value; | |
1555 | } else { | |
1556 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", | |
1557 | bond->dev->name, new_value); | |
1558 | ret = -EINVAL; | |
1559 | goto out; | |
1560 | } | |
b76cdba9 | 1561 | |
e196c0e5 | 1562 | read_lock(&bond->lock); |
ebd8e497 | 1563 | bond_for_each_slave(bond, slave, i) { |
e30bc066 | 1564 | if (!bond_is_active_slave(slave)) { |
ebd8e497 | 1565 | if (new_value) |
2d7011ca | 1566 | slave->inactive = 0; |
ebd8e497 | 1567 | else |
2d7011ca | 1568 | slave->inactive = 1; |
ebd8e497 AG |
1569 | } |
1570 | } | |
e196c0e5 | 1571 | read_unlock(&bond->lock); |
ebd8e497 | 1572 | out: |
672bda33 | 1573 | return ret; |
ebd8e497 AG |
1574 | } |
1575 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, | |
1576 | bonding_show_slaves_active, bonding_store_slaves_active); | |
b76cdba9 | 1577 | |
c2952c31 FL |
1578 | /* |
1579 | * Show and set the number of IGMP membership reports to send on link failure | |
1580 | */ | |
1581 | static ssize_t bonding_show_resend_igmp(struct device *d, | |
94265cf5 FL |
1582 | struct device_attribute *attr, |
1583 | char *buf) | |
c2952c31 FL |
1584 | { |
1585 | struct bonding *bond = to_bond(d); | |
1586 | ||
1587 | return sprintf(buf, "%d\n", bond->params.resend_igmp); | |
1588 | } | |
1589 | ||
1590 | static ssize_t bonding_store_resend_igmp(struct device *d, | |
94265cf5 FL |
1591 | struct device_attribute *attr, |
1592 | const char *buf, size_t count) | |
c2952c31 FL |
1593 | { |
1594 | int new_value, ret = count; | |
1595 | struct bonding *bond = to_bond(d); | |
1596 | ||
1597 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1598 | pr_err("%s: no resend_igmp value specified.\n", | |
1599 | bond->dev->name); | |
1600 | ret = -EINVAL; | |
1601 | goto out; | |
1602 | } | |
1603 | ||
94265cf5 | 1604 | if (new_value < 0 || new_value > 255) { |
c2952c31 FL |
1605 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
1606 | bond->dev->name, new_value); | |
1607 | ret = -EINVAL; | |
1608 | goto out; | |
1609 | } | |
1610 | ||
1611 | pr_info("%s: Setting resend_igmp to %d.\n", | |
1612 | bond->dev->name, new_value); | |
1613 | bond->params.resend_igmp = new_value; | |
1614 | out: | |
1615 | return ret; | |
1616 | } | |
1617 | ||
1618 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, | |
1619 | bonding_show_resend_igmp, bonding_store_resend_igmp); | |
1620 | ||
b76cdba9 | 1621 | static struct attribute *per_bond_attrs[] = { |
43cb76d9 GKH |
1622 | &dev_attr_slaves.attr, |
1623 | &dev_attr_mode.attr, | |
dd957c57 | 1624 | &dev_attr_fail_over_mac.attr, |
43cb76d9 GKH |
1625 | &dev_attr_arp_validate.attr, |
1626 | &dev_attr_arp_interval.attr, | |
1627 | &dev_attr_arp_ip_target.attr, | |
1628 | &dev_attr_downdelay.attr, | |
1629 | &dev_attr_updelay.attr, | |
1630 | &dev_attr_lacp_rate.attr, | |
fd989c83 | 1631 | &dev_attr_ad_select.attr, |
43cb76d9 | 1632 | &dev_attr_xmit_hash_policy.attr, |
ad246c99 BH |
1633 | &dev_attr_num_grat_arp.attr, |
1634 | &dev_attr_num_unsol_na.attr, | |
43cb76d9 GKH |
1635 | &dev_attr_miimon.attr, |
1636 | &dev_attr_primary.attr, | |
a549952a | 1637 | &dev_attr_primary_reselect.attr, |
43cb76d9 GKH |
1638 | &dev_attr_use_carrier.attr, |
1639 | &dev_attr_active_slave.attr, | |
1640 | &dev_attr_mii_status.attr, | |
1641 | &dev_attr_ad_aggregator.attr, | |
1642 | &dev_attr_ad_num_ports.attr, | |
1643 | &dev_attr_ad_actor_key.attr, | |
1644 | &dev_attr_ad_partner_key.attr, | |
1645 | &dev_attr_ad_partner_mac.attr, | |
bb1d9123 | 1646 | &dev_attr_queue_id.attr, |
ebd8e497 | 1647 | &dev_attr_all_slaves_active.attr, |
c2952c31 | 1648 | &dev_attr_resend_igmp.attr, |
655f8919 | 1649 | &dev_attr_min_links.attr, |
b76cdba9 MW |
1650 | NULL, |
1651 | }; | |
1652 | ||
1653 | static struct attribute_group bonding_group = { | |
1654 | .name = "bonding", | |
1655 | .attrs = per_bond_attrs, | |
1656 | }; | |
1657 | ||
1658 | /* | |
1659 | * Initialize sysfs. This sets up the bonding_masters file in | |
1660 | * /sys/class/net. | |
1661 | */ | |
4c22400a | 1662 | int bond_create_sysfs(struct bond_net *bn) |
b76cdba9 | 1663 | { |
b8a9787e | 1664 | int ret; |
b76cdba9 | 1665 | |
4c22400a | 1666 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
01718e36 | 1667 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
4c22400a EB |
1668 | |
1669 | ret = netdev_class_create_file(&bn->class_attr_bonding_masters); | |
877cbd36 JV |
1670 | /* |
1671 | * Permit multiple loads of the module by ignoring failures to | |
1672 | * create the bonding_masters sysfs file. Bonding devices | |
1673 | * created by second or subsequent loads of the module will | |
1674 | * not be listed in, or controllable by, bonding_masters, but | |
1675 | * will have the usual "bonding" sysfs directory. | |
1676 | * | |
1677 | * This is done to preserve backwards compatibility for | |
1678 | * initscripts/sysconfig, which load bonding multiple times to | |
1679 | * configure multiple bonding devices. | |
1680 | */ | |
1681 | if (ret == -EEXIST) { | |
38d2f38b | 1682 | /* Is someone being kinky and naming a device bonding_master? */ |
4c22400a | 1683 | if (__dev_get_by_name(bn->net, |
38d2f38b | 1684 | class_attr_bonding_masters.attr.name)) |
a4aee5c8 | 1685 | pr_err("network device named %s already exists in sysfs", |
38d2f38b | 1686 | class_attr_bonding_masters.attr.name); |
130aa61a | 1687 | ret = 0; |
877cbd36 | 1688 | } |
b76cdba9 MW |
1689 | |
1690 | return ret; | |
1691 | ||
1692 | } | |
1693 | ||
1694 | /* | |
1695 | * Remove /sys/class/net/bonding_masters. | |
1696 | */ | |
4c22400a | 1697 | void bond_destroy_sysfs(struct bond_net *bn) |
b76cdba9 | 1698 | { |
4c22400a | 1699 | netdev_class_remove_file(&bn->class_attr_bonding_masters); |
b76cdba9 MW |
1700 | } |
1701 | ||
1702 | /* | |
1703 | * Initialize sysfs for each bond. This sets up and registers | |
1704 | * the 'bondctl' directory for each individual bond under /sys/class/net. | |
1705 | */ | |
6151b3d4 | 1706 | void bond_prepare_sysfs_group(struct bonding *bond) |
b76cdba9 | 1707 | { |
6151b3d4 | 1708 | bond->dev->sysfs_groups[0] = &bonding_group; |
b76cdba9 MW |
1709 | } |
1710 |