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; |
b76cdba9 | 594 | int i = 0, done = 0, ret = count; |
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 | ret = -EINVAL; |
606 | goto out; | |
607 | } | |
608 | /* look for an empty slot to put the target in, and check for dupes */ | |
5a31bec0 | 609 | for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { |
b76cdba9 | 610 | if (targets[i] == newtarget) { /* duplicate */ |
a4aee5c8 | 611 | pr_err("%s: ARP target %pI4 is already present\n", |
63779436 | 612 | bond->dev->name, &newtarget); |
b76cdba9 MW |
613 | ret = -EINVAL; |
614 | goto out; | |
615 | } | |
5a31bec0 | 616 | if (targets[i] == 0) { |
a4aee5c8 JP |
617 | pr_info("%s: adding ARP target %pI4.\n", |
618 | bond->dev->name, &newtarget); | |
b76cdba9 MW |
619 | done = 1; |
620 | targets[i] = newtarget; | |
621 | } | |
622 | } | |
623 | if (!done) { | |
a4aee5c8 | 624 | pr_err("%s: ARP target table is full!\n", |
b76cdba9 MW |
625 | bond->dev->name); |
626 | ret = -EINVAL; | |
627 | goto out; | |
628 | } | |
629 | ||
3d632c3f | 630 | } else if (buf[0] == '-') { |
d3bb52b0 | 631 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
a4aee5c8 | 632 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
63779436 | 633 | bond->dev->name, &newtarget); |
b76cdba9 MW |
634 | ret = -EINVAL; |
635 | goto out; | |
636 | } | |
637 | ||
5a31bec0 | 638 | for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { |
b76cdba9 | 639 | if (targets[i] == newtarget) { |
5a31bec0 | 640 | int j; |
a4aee5c8 JP |
641 | pr_info("%s: removing ARP target %pI4.\n", |
642 | bond->dev->name, &newtarget); | |
5a31bec0 BH |
643 | for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++) |
644 | targets[j] = targets[j+1]; | |
645 | ||
646 | targets[j] = 0; | |
b76cdba9 MW |
647 | done = 1; |
648 | } | |
649 | } | |
650 | if (!done) { | |
a4aee5c8 JP |
651 | pr_info("%s: unable to remove nonexistent ARP target %pI4.\n", |
652 | bond->dev->name, &newtarget); | |
b76cdba9 MW |
653 | ret = -EINVAL; |
654 | goto out; | |
655 | } | |
3d632c3f | 656 | } else { |
a4aee5c8 JP |
657 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
658 | bond->dev->name); | |
b76cdba9 MW |
659 | ret = -EPERM; |
660 | goto out; | |
661 | } | |
662 | ||
663 | out: | |
664 | return ret; | |
665 | } | |
43cb76d9 | 666 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); |
b76cdba9 MW |
667 | |
668 | /* | |
669 | * Show and set the up and down delays. These must be multiples of the | |
670 | * MII monitoring value, and are stored internally as the multiplier. | |
671 | * Thus, we must translate to MS for the real world. | |
672 | */ | |
43cb76d9 GKH |
673 | static ssize_t bonding_show_downdelay(struct device *d, |
674 | struct device_attribute *attr, | |
675 | char *buf) | |
b76cdba9 | 676 | { |
43cb76d9 | 677 | struct bonding *bond = to_bond(d); |
b76cdba9 | 678 | |
7bd46508 | 679 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
b76cdba9 MW |
680 | } |
681 | ||
43cb76d9 GKH |
682 | static ssize_t bonding_store_downdelay(struct device *d, |
683 | struct device_attribute *attr, | |
684 | const char *buf, size_t count) | |
b76cdba9 MW |
685 | { |
686 | int new_value, ret = count; | |
43cb76d9 | 687 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
688 | |
689 | if (!(bond->params.miimon)) { | |
a4aee5c8 | 690 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
b76cdba9 MW |
691 | bond->dev->name); |
692 | ret = -EPERM; | |
693 | goto out; | |
694 | } | |
695 | ||
696 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 697 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
b76cdba9 MW |
698 | ret = -EINVAL; |
699 | goto out; | |
700 | } | |
701 | if (new_value < 0) { | |
a4aee5c8 | 702 | pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
1bc7db16 | 703 | bond->dev->name, new_value, 0, INT_MAX); |
b76cdba9 MW |
704 | ret = -EINVAL; |
705 | goto out; | |
706 | } else { | |
707 | if ((new_value % bond->params.miimon) != 0) { | |
a4aee5c8 | 708 | pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
e5e2a8fd JP |
709 | bond->dev->name, new_value, |
710 | bond->params.miimon, | |
711 | (new_value / bond->params.miimon) * | |
712 | bond->params.miimon); | |
b76cdba9 MW |
713 | } |
714 | bond->params.downdelay = new_value / bond->params.miimon; | |
a4aee5c8 JP |
715 | pr_info("%s: Setting down delay to %d.\n", |
716 | bond->dev->name, | |
717 | bond->params.downdelay * bond->params.miimon); | |
b76cdba9 MW |
718 | |
719 | } | |
720 | ||
721 | out: | |
722 | return ret; | |
723 | } | |
3d632c3f SH |
724 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
725 | bonding_show_downdelay, bonding_store_downdelay); | |
b76cdba9 | 726 | |
43cb76d9 GKH |
727 | static ssize_t bonding_show_updelay(struct device *d, |
728 | struct device_attribute *attr, | |
729 | char *buf) | |
b76cdba9 | 730 | { |
43cb76d9 | 731 | struct bonding *bond = to_bond(d); |
b76cdba9 | 732 | |
7bd46508 | 733 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
b76cdba9 MW |
734 | |
735 | } | |
736 | ||
43cb76d9 GKH |
737 | static ssize_t bonding_store_updelay(struct device *d, |
738 | struct device_attribute *attr, | |
739 | const char *buf, size_t count) | |
b76cdba9 MW |
740 | { |
741 | int new_value, ret = count; | |
43cb76d9 | 742 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
743 | |
744 | if (!(bond->params.miimon)) { | |
a4aee5c8 | 745 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
b76cdba9 MW |
746 | bond->dev->name); |
747 | ret = -EPERM; | |
748 | goto out; | |
749 | } | |
750 | ||
751 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 752 | pr_err("%s: no up delay value specified.\n", |
b76cdba9 MW |
753 | bond->dev->name); |
754 | ret = -EINVAL; | |
755 | goto out; | |
756 | } | |
757 | if (new_value < 0) { | |
1bc7db16 | 758 | pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n", |
759 | bond->dev->name, new_value, 0, INT_MAX); | |
b76cdba9 MW |
760 | ret = -EINVAL; |
761 | goto out; | |
762 | } else { | |
763 | if ((new_value % bond->params.miimon) != 0) { | |
a4aee5c8 | 764 | pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
e5e2a8fd JP |
765 | bond->dev->name, new_value, |
766 | bond->params.miimon, | |
767 | (new_value / bond->params.miimon) * | |
768 | bond->params.miimon); | |
b76cdba9 MW |
769 | } |
770 | bond->params.updelay = new_value / bond->params.miimon; | |
a4aee5c8 JP |
771 | pr_info("%s: Setting up delay to %d.\n", |
772 | bond->dev->name, | |
773 | bond->params.updelay * bond->params.miimon); | |
b76cdba9 MW |
774 | } |
775 | ||
776 | out: | |
777 | return ret; | |
778 | } | |
3d632c3f SH |
779 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
780 | bonding_show_updelay, bonding_store_updelay); | |
b76cdba9 MW |
781 | |
782 | /* | |
783 | * Show and set the LACP interval. Interface must be down, and the mode | |
784 | * must be set to 802.3ad mode. | |
785 | */ | |
43cb76d9 GKH |
786 | static ssize_t bonding_show_lacp(struct device *d, |
787 | struct device_attribute *attr, | |
788 | char *buf) | |
b76cdba9 | 789 | { |
43cb76d9 | 790 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
791 | |
792 | return sprintf(buf, "%s %d\n", | |
793 | bond_lacp_tbl[bond->params.lacp_fast].modename, | |
7bd46508 | 794 | bond->params.lacp_fast); |
b76cdba9 MW |
795 | } |
796 | ||
43cb76d9 GKH |
797 | static ssize_t bonding_store_lacp(struct device *d, |
798 | struct device_attribute *attr, | |
799 | const char *buf, size_t count) | |
b76cdba9 MW |
800 | { |
801 | int new_value, ret = count; | |
43cb76d9 | 802 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
803 | |
804 | if (bond->dev->flags & IFF_UP) { | |
a4aee5c8 | 805 | pr_err("%s: Unable to update LACP rate because interface is up.\n", |
b76cdba9 MW |
806 | bond->dev->name); |
807 | ret = -EPERM; | |
808 | goto out; | |
809 | } | |
810 | ||
811 | if (bond->params.mode != BOND_MODE_8023AD) { | |
a4aee5c8 | 812 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
b76cdba9 MW |
813 | bond->dev->name); |
814 | ret = -EPERM; | |
815 | goto out; | |
816 | } | |
817 | ||
ece95f7f | 818 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
b76cdba9 MW |
819 | |
820 | if ((new_value == 1) || (new_value == 0)) { | |
821 | bond->params.lacp_fast = new_value; | |
ba824a8b | 822 | bond_3ad_update_lacp_rate(bond); |
a4aee5c8 | 823 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
3d632c3f SH |
824 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
825 | new_value); | |
b76cdba9 | 826 | } else { |
a4aee5c8 | 827 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
3d632c3f | 828 | bond->dev->name, (int)strlen(buf) - 1, buf); |
b76cdba9 MW |
829 | ret = -EINVAL; |
830 | } | |
831 | out: | |
832 | return ret; | |
833 | } | |
3d632c3f SH |
834 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
835 | bonding_show_lacp, bonding_store_lacp); | |
b76cdba9 | 836 | |
655f8919 | 837 | static ssize_t bonding_show_min_links(struct device *d, |
838 | struct device_attribute *attr, | |
839 | char *buf) | |
840 | { | |
841 | struct bonding *bond = to_bond(d); | |
842 | ||
843 | return sprintf(buf, "%d\n", bond->params.min_links); | |
844 | } | |
845 | ||
846 | static ssize_t bonding_store_min_links(struct device *d, | |
847 | struct device_attribute *attr, | |
848 | const char *buf, size_t count) | |
849 | { | |
850 | struct bonding *bond = to_bond(d); | |
851 | int ret; | |
852 | unsigned int new_value; | |
853 | ||
854 | ret = kstrtouint(buf, 0, &new_value); | |
855 | if (ret < 0) { | |
856 | pr_err("%s: Ignoring invalid min links value %s.\n", | |
857 | bond->dev->name, buf); | |
858 | return ret; | |
859 | } | |
860 | ||
861 | pr_info("%s: Setting min links value to %u\n", | |
862 | bond->dev->name, new_value); | |
863 | bond->params.min_links = new_value; | |
864 | return count; | |
865 | } | |
866 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, | |
867 | bonding_show_min_links, bonding_store_min_links); | |
868 | ||
fd989c83 JV |
869 | static ssize_t bonding_show_ad_select(struct device *d, |
870 | struct device_attribute *attr, | |
871 | char *buf) | |
872 | { | |
873 | struct bonding *bond = to_bond(d); | |
874 | ||
875 | return sprintf(buf, "%s %d\n", | |
876 | ad_select_tbl[bond->params.ad_select].modename, | |
877 | bond->params.ad_select); | |
878 | } | |
879 | ||
880 | ||
881 | static ssize_t bonding_store_ad_select(struct device *d, | |
882 | struct device_attribute *attr, | |
883 | const char *buf, size_t count) | |
884 | { | |
885 | int new_value, ret = count; | |
886 | struct bonding *bond = to_bond(d); | |
887 | ||
888 | if (bond->dev->flags & IFF_UP) { | |
a4aee5c8 JP |
889 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
890 | bond->dev->name); | |
fd989c83 JV |
891 | ret = -EPERM; |
892 | goto out; | |
893 | } | |
894 | ||
895 | new_value = bond_parse_parm(buf, ad_select_tbl); | |
896 | ||
897 | if (new_value != -1) { | |
898 | bond->params.ad_select = new_value; | |
a4aee5c8 JP |
899 | pr_info("%s: Setting ad_select to %s (%d).\n", |
900 | bond->dev->name, ad_select_tbl[new_value].modename, | |
901 | new_value); | |
fd989c83 | 902 | } else { |
a4aee5c8 | 903 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
fd989c83 JV |
904 | bond->dev->name, (int)strlen(buf) - 1, buf); |
905 | ret = -EINVAL; | |
906 | } | |
907 | out: | |
908 | return ret; | |
909 | } | |
3d632c3f SH |
910 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
911 | bonding_show_ad_select, bonding_store_ad_select); | |
fd989c83 | 912 | |
ad246c99 BH |
913 | /* |
914 | * Show and set the number of peer notifications to send after a failover event. | |
915 | */ | |
916 | static ssize_t bonding_show_num_peer_notif(struct device *d, | |
917 | struct device_attribute *attr, | |
918 | char *buf) | |
919 | { | |
920 | struct bonding *bond = to_bond(d); | |
921 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); | |
922 | } | |
923 | ||
924 | static ssize_t bonding_store_num_peer_notif(struct device *d, | |
925 | struct device_attribute *attr, | |
926 | const char *buf, size_t count) | |
927 | { | |
928 | struct bonding *bond = to_bond(d); | |
929 | int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); | |
930 | return err ? err : count; | |
931 | } | |
932 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, | |
933 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
934 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, | |
935 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
936 | ||
b76cdba9 MW |
937 | /* |
938 | * Show and set the MII monitor interval. There are two tricky bits | |
939 | * here. First, if MII monitoring is activated, then we must disable | |
940 | * ARP monitoring. Second, if the timer isn't running, we must | |
941 | * start it. | |
942 | */ | |
43cb76d9 GKH |
943 | static ssize_t bonding_show_miimon(struct device *d, |
944 | struct device_attribute *attr, | |
945 | char *buf) | |
b76cdba9 | 946 | { |
43cb76d9 | 947 | struct bonding *bond = to_bond(d); |
b76cdba9 | 948 | |
7bd46508 | 949 | return sprintf(buf, "%d\n", bond->params.miimon); |
b76cdba9 MW |
950 | } |
951 | ||
43cb76d9 GKH |
952 | static ssize_t bonding_store_miimon(struct device *d, |
953 | struct device_attribute *attr, | |
954 | const char *buf, size_t count) | |
b76cdba9 MW |
955 | { |
956 | int new_value, ret = count; | |
43cb76d9 | 957 | struct bonding *bond = to_bond(d); |
b76cdba9 | 958 | |
fbb0c41b | 959 | if (!rtnl_trylock()) |
960 | return restart_syscall(); | |
b76cdba9 | 961 | if (sscanf(buf, "%d", &new_value) != 1) { |
a4aee5c8 | 962 | pr_err("%s: no miimon value specified.\n", |
b76cdba9 MW |
963 | bond->dev->name); |
964 | ret = -EINVAL; | |
965 | goto out; | |
966 | } | |
967 | if (new_value < 0) { | |
a4aee5c8 | 968 | pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n", |
1bc7db16 | 969 | bond->dev->name, new_value, 0, INT_MAX); |
b76cdba9 MW |
970 | ret = -EINVAL; |
971 | goto out; | |
1bc7db16 | 972 | } |
973 | pr_info("%s: Setting MII monitoring interval to %d.\n", | |
974 | bond->dev->name, new_value); | |
975 | bond->params.miimon = new_value; | |
976 | if (bond->params.updelay) | |
977 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", | |
978 | bond->dev->name, | |
979 | bond->params.updelay * bond->params.miimon); | |
980 | if (bond->params.downdelay) | |
981 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", | |
982 | bond->dev->name, | |
983 | bond->params.downdelay * bond->params.miimon); | |
984 | if (new_value && bond->params.arp_interval) { | |
985 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", | |
986 | bond->dev->name); | |
987 | bond->params.arp_interval = 0; | |
988 | if (bond->params.arp_validate) | |
989 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
990 | } | |
991 | if (bond->dev->flags & IFF_UP) { | |
992 | /* If the interface is up, we may need to fire off | |
993 | * the MII timer. If the interface is down, the | |
994 | * timer will get fired off when the open function | |
995 | * is called. | |
996 | */ | |
997 | if (!new_value) { | |
998 | cancel_delayed_work_sync(&bond->mii_work); | |
999 | } else { | |
fbb0c41b | 1000 | cancel_delayed_work_sync(&bond->arp_work); |
1001 | queue_delayed_work(bond->wq, &bond->mii_work, 0); | |
b76cdba9 MW |
1002 | } |
1003 | } | |
1004 | out: | |
fbb0c41b | 1005 | rtnl_unlock(); |
b76cdba9 MW |
1006 | return ret; |
1007 | } | |
3d632c3f SH |
1008 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
1009 | bonding_show_miimon, bonding_store_miimon); | |
b76cdba9 MW |
1010 | |
1011 | /* | |
1012 | * Show and set the primary slave. The store function is much | |
1013 | * simpler than bonding_store_slaves function because it only needs to | |
1014 | * handle one interface name. | |
1015 | * The bond must be a mode that supports a primary for this be | |
1016 | * set. | |
1017 | */ | |
43cb76d9 GKH |
1018 | static ssize_t bonding_show_primary(struct device *d, |
1019 | struct device_attribute *attr, | |
1020 | char *buf) | |
b76cdba9 MW |
1021 | { |
1022 | int count = 0; | |
43cb76d9 | 1023 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1024 | |
1025 | if (bond->primary_slave) | |
7bd46508 | 1026 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
b76cdba9 MW |
1027 | |
1028 | return count; | |
1029 | } | |
1030 | ||
43cb76d9 GKH |
1031 | static ssize_t bonding_store_primary(struct device *d, |
1032 | struct device_attribute *attr, | |
1033 | const char *buf, size_t count) | |
b76cdba9 MW |
1034 | { |
1035 | int i; | |
1036 | struct slave *slave; | |
43cb76d9 | 1037 | struct bonding *bond = to_bond(d); |
f4bb2e9c | 1038 | char ifname[IFNAMSIZ]; |
b76cdba9 | 1039 | |
496a60cd EB |
1040 | if (!rtnl_trylock()) |
1041 | return restart_syscall(); | |
e843fa50 | 1042 | block_netpoll_tx(); |
e934dd78 JV |
1043 | read_lock(&bond->lock); |
1044 | write_lock_bh(&bond->curr_slave_lock); | |
1045 | ||
b76cdba9 | 1046 | if (!USES_PRIMARY(bond->params.mode)) { |
a4aee5c8 JP |
1047 | pr_info("%s: Unable to set primary slave; %s is in mode %d\n", |
1048 | bond->dev->name, bond->dev->name, bond->params.mode); | |
f4bb2e9c AG |
1049 | goto out; |
1050 | } | |
b76cdba9 | 1051 | |
eb6e98a1 | 1052 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
b76cdba9 | 1053 | |
f4bb2e9c AG |
1054 | /* check to see if we are clearing primary */ |
1055 | if (!strlen(ifname) || buf[0] == '\n') { | |
1056 | pr_info("%s: Setting primary slave to None.\n", | |
1057 | bond->dev->name); | |
1058 | bond->primary_slave = NULL; | |
eb492f74 | 1059 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
f4bb2e9c AG |
1060 | bond_select_active_slave(bond); |
1061 | goto out; | |
1062 | } | |
1063 | ||
1064 | bond_for_each_slave(bond, slave, i) { | |
1065 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | |
1066 | pr_info("%s: Setting %s as primary slave.\n", | |
1067 | bond->dev->name, slave->dev->name); | |
1068 | bond->primary_slave = slave; | |
1069 | strcpy(bond->params.primary, slave->dev->name); | |
1070 | bond_select_active_slave(bond); | |
1071 | goto out; | |
b76cdba9 MW |
1072 | } |
1073 | } | |
f4bb2e9c | 1074 | |
8a93664d WP |
1075 | strncpy(bond->params.primary, ifname, IFNAMSIZ); |
1076 | bond->params.primary[IFNAMSIZ - 1] = 0; | |
1077 | ||
1078 | pr_info("%s: Recording %s as primary, " | |
1079 | "but it has not been enslaved to %s yet.\n", | |
1080 | bond->dev->name, ifname, bond->dev->name); | |
b76cdba9 | 1081 | out: |
e934dd78 JV |
1082 | write_unlock_bh(&bond->curr_slave_lock); |
1083 | read_unlock(&bond->lock); | |
e843fa50 | 1084 | unblock_netpoll_tx(); |
6603a6f2 JV |
1085 | rtnl_unlock(); |
1086 | ||
b76cdba9 MW |
1087 | return count; |
1088 | } | |
3d632c3f SH |
1089 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
1090 | bonding_show_primary, bonding_store_primary); | |
b76cdba9 | 1091 | |
a549952a JP |
1092 | /* |
1093 | * Show and set the primary_reselect flag. | |
1094 | */ | |
1095 | static ssize_t bonding_show_primary_reselect(struct device *d, | |
1096 | struct device_attribute *attr, | |
1097 | char *buf) | |
1098 | { | |
1099 | struct bonding *bond = to_bond(d); | |
1100 | ||
1101 | return sprintf(buf, "%s %d\n", | |
1102 | pri_reselect_tbl[bond->params.primary_reselect].modename, | |
1103 | bond->params.primary_reselect); | |
1104 | } | |
1105 | ||
1106 | static ssize_t bonding_store_primary_reselect(struct device *d, | |
1107 | struct device_attribute *attr, | |
1108 | const char *buf, size_t count) | |
1109 | { | |
1110 | int new_value, ret = count; | |
1111 | struct bonding *bond = to_bond(d); | |
1112 | ||
1113 | if (!rtnl_trylock()) | |
1114 | return restart_syscall(); | |
1115 | ||
1116 | new_value = bond_parse_parm(buf, pri_reselect_tbl); | |
1117 | if (new_value < 0) { | |
a4aee5c8 | 1118 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
a549952a JP |
1119 | bond->dev->name, |
1120 | (int) strlen(buf) - 1, buf); | |
1121 | ret = -EINVAL; | |
1122 | goto out; | |
1123 | } | |
1124 | ||
1125 | bond->params.primary_reselect = new_value; | |
a4aee5c8 | 1126 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
a549952a JP |
1127 | bond->dev->name, pri_reselect_tbl[new_value].modename, |
1128 | new_value); | |
1129 | ||
e843fa50 | 1130 | block_netpoll_tx(); |
a549952a JP |
1131 | read_lock(&bond->lock); |
1132 | write_lock_bh(&bond->curr_slave_lock); | |
1133 | bond_select_active_slave(bond); | |
1134 | write_unlock_bh(&bond->curr_slave_lock); | |
1135 | read_unlock(&bond->lock); | |
e843fa50 | 1136 | unblock_netpoll_tx(); |
a549952a JP |
1137 | out: |
1138 | rtnl_unlock(); | |
1139 | return ret; | |
1140 | } | |
1141 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, | |
1142 | bonding_show_primary_reselect, | |
1143 | bonding_store_primary_reselect); | |
1144 | ||
b76cdba9 MW |
1145 | /* |
1146 | * Show and set the use_carrier flag. | |
1147 | */ | |
43cb76d9 GKH |
1148 | static ssize_t bonding_show_carrier(struct device *d, |
1149 | struct device_attribute *attr, | |
1150 | char *buf) | |
b76cdba9 | 1151 | { |
43cb76d9 | 1152 | struct bonding *bond = to_bond(d); |
b76cdba9 | 1153 | |
7bd46508 | 1154 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
b76cdba9 MW |
1155 | } |
1156 | ||
43cb76d9 GKH |
1157 | static ssize_t bonding_store_carrier(struct device *d, |
1158 | struct device_attribute *attr, | |
1159 | const char *buf, size_t count) | |
b76cdba9 MW |
1160 | { |
1161 | int new_value, ret = count; | |
43cb76d9 | 1162 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1163 | |
1164 | ||
1165 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 1166 | pr_err("%s: no use_carrier value specified.\n", |
b76cdba9 MW |
1167 | bond->dev->name); |
1168 | ret = -EINVAL; | |
1169 | goto out; | |
1170 | } | |
1171 | if ((new_value == 0) || (new_value == 1)) { | |
1172 | bond->params.use_carrier = new_value; | |
a4aee5c8 JP |
1173 | pr_info("%s: Setting use_carrier to %d.\n", |
1174 | bond->dev->name, new_value); | |
b76cdba9 | 1175 | } else { |
a4aee5c8 JP |
1176 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
1177 | bond->dev->name, new_value); | |
b76cdba9 MW |
1178 | } |
1179 | out: | |
672bda33 | 1180 | return ret; |
b76cdba9 | 1181 | } |
3d632c3f SH |
1182 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
1183 | bonding_show_carrier, bonding_store_carrier); | |
b76cdba9 MW |
1184 | |
1185 | ||
1186 | /* | |
1187 | * Show and set currently active_slave. | |
1188 | */ | |
43cb76d9 GKH |
1189 | static ssize_t bonding_show_active_slave(struct device *d, |
1190 | struct device_attribute *attr, | |
1191 | char *buf) | |
b76cdba9 MW |
1192 | { |
1193 | struct slave *curr; | |
43cb76d9 | 1194 | struct bonding *bond = to_bond(d); |
16cd0160 | 1195 | int count = 0; |
b76cdba9 | 1196 | |
b76cdba9 MW |
1197 | read_lock(&bond->curr_slave_lock); |
1198 | curr = bond->curr_active_slave; | |
1199 | read_unlock(&bond->curr_slave_lock); | |
1200 | ||
1201 | if (USES_PRIMARY(bond->params.mode) && curr) | |
7bd46508 | 1202 | count = sprintf(buf, "%s\n", curr->dev->name); |
b76cdba9 MW |
1203 | return count; |
1204 | } | |
1205 | ||
43cb76d9 GKH |
1206 | static ssize_t bonding_store_active_slave(struct device *d, |
1207 | struct device_attribute *attr, | |
1208 | const char *buf, size_t count) | |
b76cdba9 MW |
1209 | { |
1210 | int i; | |
1211 | struct slave *slave; | |
3d632c3f SH |
1212 | struct slave *old_active = NULL; |
1213 | struct slave *new_active = NULL; | |
43cb76d9 | 1214 | struct bonding *bond = to_bond(d); |
f4bb2e9c | 1215 | char ifname[IFNAMSIZ]; |
b76cdba9 | 1216 | |
496a60cd EB |
1217 | if (!rtnl_trylock()) |
1218 | return restart_syscall(); | |
e843fa50 NH |
1219 | |
1220 | block_netpoll_tx(); | |
e934dd78 JV |
1221 | read_lock(&bond->lock); |
1222 | write_lock_bh(&bond->curr_slave_lock); | |
1466a219 | 1223 | |
f4bb2e9c | 1224 | if (!USES_PRIMARY(bond->params.mode)) { |
a4aee5c8 | 1225 | pr_info("%s: Unable to change active slave; %s is in mode %d\n", |
3d632c3f | 1226 | bond->dev->name, bond->dev->name, bond->params.mode); |
f4bb2e9c AG |
1227 | goto out; |
1228 | } | |
1229 | ||
c84e1590 | 1230 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
f4bb2e9c AG |
1231 | |
1232 | /* check to see if we are clearing active */ | |
1233 | if (!strlen(ifname) || buf[0] == '\n') { | |
1234 | pr_info("%s: Clearing current active slave.\n", | |
1235 | bond->dev->name); | |
1236 | bond->curr_active_slave = NULL; | |
1237 | bond_select_active_slave(bond); | |
1238 | goto out; | |
1239 | } | |
1240 | ||
1241 | bond_for_each_slave(bond, slave, i) { | |
1242 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | |
1243 | old_active = bond->curr_active_slave; | |
1244 | new_active = slave; | |
1245 | if (new_active == old_active) { | |
1246 | /* do nothing */ | |
1247 | pr_info("%s: %s is already the current" | |
1248 | " active slave.\n", | |
1249 | bond->dev->name, | |
1250 | slave->dev->name); | |
1251 | goto out; | |
1252 | } | |
1253 | else { | |
1254 | if ((new_active) && | |
1255 | (old_active) && | |
1256 | (new_active->link == BOND_LINK_UP) && | |
1257 | IS_UP(new_active->dev)) { | |
1258 | pr_info("%s: Setting %s as active" | |
1259 | " slave.\n", | |
a4aee5c8 JP |
1260 | bond->dev->name, |
1261 | slave->dev->name); | |
f4bb2e9c AG |
1262 | bond_change_active_slave(bond, |
1263 | new_active); | |
b76cdba9 MW |
1264 | } |
1265 | else { | |
f4bb2e9c AG |
1266 | pr_info("%s: Could not set %s as" |
1267 | " active slave; either %s is" | |
1268 | " down or the link is down.\n", | |
1269 | bond->dev->name, | |
1270 | slave->dev->name, | |
1271 | slave->dev->name); | |
b76cdba9 | 1272 | } |
f4bb2e9c | 1273 | goto out; |
b76cdba9 MW |
1274 | } |
1275 | } | |
b76cdba9 | 1276 | } |
f4bb2e9c AG |
1277 | |
1278 | pr_info("%s: Unable to set %.*s as active slave.\n", | |
1279 | bond->dev->name, (int)strlen(buf) - 1, buf); | |
3d632c3f | 1280 | out: |
e934dd78 JV |
1281 | write_unlock_bh(&bond->curr_slave_lock); |
1282 | read_unlock(&bond->lock); | |
e843fa50 NH |
1283 | unblock_netpoll_tx(); |
1284 | ||
6603a6f2 JV |
1285 | rtnl_unlock(); |
1286 | ||
b76cdba9 MW |
1287 | return count; |
1288 | ||
1289 | } | |
3d632c3f SH |
1290 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
1291 | bonding_show_active_slave, bonding_store_active_slave); | |
b76cdba9 MW |
1292 | |
1293 | ||
1294 | /* | |
1295 | * Show link status of the bond interface. | |
1296 | */ | |
43cb76d9 GKH |
1297 | static ssize_t bonding_show_mii_status(struct device *d, |
1298 | struct device_attribute *attr, | |
1299 | char *buf) | |
b76cdba9 MW |
1300 | { |
1301 | struct slave *curr; | |
43cb76d9 | 1302 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1303 | |
1304 | read_lock(&bond->curr_slave_lock); | |
1305 | curr = bond->curr_active_slave; | |
1306 | read_unlock(&bond->curr_slave_lock); | |
1307 | ||
3d632c3f | 1308 | return sprintf(buf, "%s\n", curr ? "up" : "down"); |
b76cdba9 | 1309 | } |
43cb76d9 | 1310 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
b76cdba9 | 1311 | |
b76cdba9 MW |
1312 | /* |
1313 | * Show current 802.3ad aggregator ID. | |
1314 | */ | |
43cb76d9 GKH |
1315 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
1316 | struct device_attribute *attr, | |
1317 | char *buf) | |
b76cdba9 MW |
1318 | { |
1319 | int count = 0; | |
43cb76d9 | 1320 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1321 | |
1322 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1323 | struct ad_info ad_info; | |
3d632c3f | 1324 | count = sprintf(buf, "%d\n", |
318debd8 | 1325 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1326 | ? 0 : ad_info.aggregator_id); |
b76cdba9 | 1327 | } |
b76cdba9 MW |
1328 | |
1329 | return count; | |
1330 | } | |
43cb76d9 | 1331 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
b76cdba9 MW |
1332 | |
1333 | ||
1334 | /* | |
1335 | * Show number of active 802.3ad ports. | |
1336 | */ | |
43cb76d9 GKH |
1337 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
1338 | struct device_attribute *attr, | |
1339 | char *buf) | |
b76cdba9 MW |
1340 | { |
1341 | int count = 0; | |
43cb76d9 | 1342 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1343 | |
1344 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1345 | struct ad_info ad_info; | |
3d632c3f | 1346 | count = sprintf(buf, "%d\n", |
318debd8 | 1347 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1348 | ? 0 : ad_info.ports); |
b76cdba9 | 1349 | } |
b76cdba9 MW |
1350 | |
1351 | return count; | |
1352 | } | |
43cb76d9 | 1353 | static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); |
b76cdba9 MW |
1354 | |
1355 | ||
1356 | /* | |
1357 | * Show current 802.3ad actor key. | |
1358 | */ | |
43cb76d9 GKH |
1359 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
1360 | struct device_attribute *attr, | |
1361 | char *buf) | |
b76cdba9 MW |
1362 | { |
1363 | int count = 0; | |
43cb76d9 | 1364 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1365 | |
1366 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1367 | struct ad_info ad_info; | |
3d632c3f | 1368 | count = sprintf(buf, "%d\n", |
318debd8 | 1369 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1370 | ? 0 : ad_info.actor_key); |
b76cdba9 | 1371 | } |
b76cdba9 MW |
1372 | |
1373 | return count; | |
1374 | } | |
43cb76d9 | 1375 | static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); |
b76cdba9 MW |
1376 | |
1377 | ||
1378 | /* | |
1379 | * Show current 802.3ad partner key. | |
1380 | */ | |
43cb76d9 GKH |
1381 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
1382 | struct device_attribute *attr, | |
1383 | char *buf) | |
b76cdba9 MW |
1384 | { |
1385 | int count = 0; | |
43cb76d9 | 1386 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1387 | |
1388 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1389 | struct ad_info ad_info; | |
3d632c3f | 1390 | count = sprintf(buf, "%d\n", |
318debd8 | 1391 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1392 | ? 0 : ad_info.partner_key); |
b76cdba9 | 1393 | } |
b76cdba9 MW |
1394 | |
1395 | return count; | |
1396 | } | |
43cb76d9 | 1397 | static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); |
b76cdba9 MW |
1398 | |
1399 | ||
1400 | /* | |
1401 | * Show current 802.3ad partner mac. | |
1402 | */ | |
43cb76d9 GKH |
1403 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
1404 | struct device_attribute *attr, | |
1405 | char *buf) | |
b76cdba9 MW |
1406 | { |
1407 | int count = 0; | |
43cb76d9 | 1408 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1409 | |
1410 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1411 | struct ad_info ad_info; | |
3d632c3f | 1412 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
e174961c | 1413 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
b76cdba9 | 1414 | } |
b76cdba9 MW |
1415 | |
1416 | return count; | |
1417 | } | |
43cb76d9 | 1418 | static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); |
b76cdba9 | 1419 | |
bb1d9123 AG |
1420 | /* |
1421 | * Show the queue_ids of the slaves in the current bond. | |
1422 | */ | |
1423 | static ssize_t bonding_show_queue_id(struct device *d, | |
1424 | struct device_attribute *attr, | |
1425 | char *buf) | |
1426 | { | |
1427 | struct slave *slave; | |
1428 | int i, res = 0; | |
1429 | struct bonding *bond = to_bond(d); | |
1430 | ||
1431 | if (!rtnl_trylock()) | |
1432 | return restart_syscall(); | |
1433 | ||
1434 | read_lock(&bond->lock); | |
1435 | bond_for_each_slave(bond, slave, i) { | |
79236680 NP |
1436 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
1437 | /* not enough space for another interface_name:queue_id pair */ | |
bb1d9123 AG |
1438 | if ((PAGE_SIZE - res) > 10) |
1439 | res = PAGE_SIZE - 10; | |
1440 | res += sprintf(buf + res, "++more++ "); | |
1441 | break; | |
1442 | } | |
1443 | res += sprintf(buf + res, "%s:%d ", | |
1444 | slave->dev->name, slave->queue_id); | |
1445 | } | |
1446 | read_unlock(&bond->lock); | |
1447 | if (res) | |
1448 | buf[res-1] = '\n'; /* eat the leftover space */ | |
1449 | rtnl_unlock(); | |
1450 | return res; | |
1451 | } | |
1452 | ||
1453 | /* | |
1454 | * Set the queue_ids of the slaves in the current bond. The bond | |
1455 | * interface must be enslaved for this to work. | |
1456 | */ | |
1457 | static ssize_t bonding_store_queue_id(struct device *d, | |
1458 | struct device_attribute *attr, | |
1459 | const char *buffer, size_t count) | |
1460 | { | |
1461 | struct slave *slave, *update_slave; | |
1462 | struct bonding *bond = to_bond(d); | |
1463 | u16 qid; | |
1464 | int i, ret = count; | |
1465 | char *delim; | |
1466 | struct net_device *sdev = NULL; | |
1467 | ||
1468 | if (!rtnl_trylock()) | |
1469 | return restart_syscall(); | |
1470 | ||
1471 | /* delim will point to queue id if successful */ | |
1472 | delim = strchr(buffer, ':'); | |
1473 | if (!delim) | |
1474 | goto err_no_cmd; | |
1475 | ||
1476 | /* | |
1477 | * Terminate string that points to device name and bump it | |
1478 | * up one, so we can read the queue id there. | |
1479 | */ | |
1480 | *delim = '\0'; | |
1481 | if (sscanf(++delim, "%hd\n", &qid) != 1) | |
1482 | goto err_no_cmd; | |
1483 | ||
1484 | /* Check buffer length, valid ifname and queue id */ | |
1485 | if (strlen(buffer) > IFNAMSIZ || | |
1486 | !dev_valid_name(buffer) || | |
8a540ff9 | 1487 | qid > bond->dev->real_num_tx_queues) |
bb1d9123 AG |
1488 | goto err_no_cmd; |
1489 | ||
1490 | /* Get the pointer to that interface if it exists */ | |
1491 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); | |
1492 | if (!sdev) | |
1493 | goto err_no_cmd; | |
1494 | ||
1495 | read_lock(&bond->lock); | |
1496 | ||
1497 | /* Search for thes slave and check for duplicate qids */ | |
1498 | update_slave = NULL; | |
1499 | bond_for_each_slave(bond, slave, i) { | |
1500 | if (sdev == slave->dev) | |
1501 | /* | |
1502 | * We don't need to check the matching | |
1503 | * slave for dups, since we're overwriting it | |
1504 | */ | |
1505 | update_slave = slave; | |
1506 | else if (qid && qid == slave->queue_id) { | |
1507 | goto err_no_cmd_unlock; | |
1508 | } | |
1509 | } | |
1510 | ||
1511 | if (!update_slave) | |
1512 | goto err_no_cmd_unlock; | |
1513 | ||
1514 | /* Actually set the qids for the slave */ | |
1515 | update_slave->queue_id = qid; | |
1516 | ||
1517 | read_unlock(&bond->lock); | |
1518 | out: | |
1519 | rtnl_unlock(); | |
1520 | return ret; | |
1521 | ||
1522 | err_no_cmd_unlock: | |
1523 | read_unlock(&bond->lock); | |
1524 | err_no_cmd: | |
1525 | pr_info("invalid input for queue_id set for %s.\n", | |
1526 | bond->dev->name); | |
1527 | ret = -EPERM; | |
1528 | goto out; | |
1529 | } | |
1530 | ||
1531 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, | |
1532 | bonding_store_queue_id); | |
1533 | ||
1534 | ||
ebd8e497 AG |
1535 | /* |
1536 | * Show and set the all_slaves_active flag. | |
1537 | */ | |
1538 | static ssize_t bonding_show_slaves_active(struct device *d, | |
1539 | struct device_attribute *attr, | |
1540 | char *buf) | |
1541 | { | |
1542 | struct bonding *bond = to_bond(d); | |
1543 | ||
1544 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); | |
1545 | } | |
1546 | ||
1547 | static ssize_t bonding_store_slaves_active(struct device *d, | |
1548 | struct device_attribute *attr, | |
1549 | const char *buf, size_t count) | |
1550 | { | |
1551 | int i, new_value, ret = count; | |
1552 | struct bonding *bond = to_bond(d); | |
1553 | struct slave *slave; | |
1554 | ||
1555 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1556 | pr_err("%s: no all_slaves_active value specified.\n", | |
1557 | bond->dev->name); | |
1558 | ret = -EINVAL; | |
1559 | goto out; | |
1560 | } | |
1561 | ||
1562 | if (new_value == bond->params.all_slaves_active) | |
1563 | goto out; | |
1564 | ||
1565 | if ((new_value == 0) || (new_value == 1)) { | |
1566 | bond->params.all_slaves_active = new_value; | |
1567 | } else { | |
1568 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", | |
1569 | bond->dev->name, new_value); | |
1570 | ret = -EINVAL; | |
1571 | goto out; | |
1572 | } | |
b76cdba9 | 1573 | |
e196c0e5 | 1574 | read_lock(&bond->lock); |
ebd8e497 | 1575 | bond_for_each_slave(bond, slave, i) { |
e30bc066 | 1576 | if (!bond_is_active_slave(slave)) { |
ebd8e497 | 1577 | if (new_value) |
2d7011ca | 1578 | slave->inactive = 0; |
ebd8e497 | 1579 | else |
2d7011ca | 1580 | slave->inactive = 1; |
ebd8e497 AG |
1581 | } |
1582 | } | |
e196c0e5 | 1583 | read_unlock(&bond->lock); |
ebd8e497 | 1584 | out: |
672bda33 | 1585 | return ret; |
ebd8e497 AG |
1586 | } |
1587 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, | |
1588 | bonding_show_slaves_active, bonding_store_slaves_active); | |
b76cdba9 | 1589 | |
c2952c31 FL |
1590 | /* |
1591 | * Show and set the number of IGMP membership reports to send on link failure | |
1592 | */ | |
1593 | static ssize_t bonding_show_resend_igmp(struct device *d, | |
94265cf5 FL |
1594 | struct device_attribute *attr, |
1595 | char *buf) | |
c2952c31 FL |
1596 | { |
1597 | struct bonding *bond = to_bond(d); | |
1598 | ||
1599 | return sprintf(buf, "%d\n", bond->params.resend_igmp); | |
1600 | } | |
1601 | ||
1602 | static ssize_t bonding_store_resend_igmp(struct device *d, | |
94265cf5 FL |
1603 | struct device_attribute *attr, |
1604 | const char *buf, size_t count) | |
c2952c31 FL |
1605 | { |
1606 | int new_value, ret = count; | |
1607 | struct bonding *bond = to_bond(d); | |
1608 | ||
1609 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1610 | pr_err("%s: no resend_igmp value specified.\n", | |
1611 | bond->dev->name); | |
1612 | ret = -EINVAL; | |
1613 | goto out; | |
1614 | } | |
1615 | ||
94265cf5 | 1616 | if (new_value < 0 || new_value > 255) { |
c2952c31 FL |
1617 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
1618 | bond->dev->name, new_value); | |
1619 | ret = -EINVAL; | |
1620 | goto out; | |
1621 | } | |
1622 | ||
1623 | pr_info("%s: Setting resend_igmp to %d.\n", | |
1624 | bond->dev->name, new_value); | |
1625 | bond->params.resend_igmp = new_value; | |
1626 | out: | |
1627 | return ret; | |
1628 | } | |
1629 | ||
1630 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, | |
1631 | bonding_show_resend_igmp, bonding_store_resend_igmp); | |
1632 | ||
b76cdba9 | 1633 | static struct attribute *per_bond_attrs[] = { |
43cb76d9 GKH |
1634 | &dev_attr_slaves.attr, |
1635 | &dev_attr_mode.attr, | |
dd957c57 | 1636 | &dev_attr_fail_over_mac.attr, |
43cb76d9 GKH |
1637 | &dev_attr_arp_validate.attr, |
1638 | &dev_attr_arp_interval.attr, | |
1639 | &dev_attr_arp_ip_target.attr, | |
1640 | &dev_attr_downdelay.attr, | |
1641 | &dev_attr_updelay.attr, | |
1642 | &dev_attr_lacp_rate.attr, | |
fd989c83 | 1643 | &dev_attr_ad_select.attr, |
43cb76d9 | 1644 | &dev_attr_xmit_hash_policy.attr, |
ad246c99 BH |
1645 | &dev_attr_num_grat_arp.attr, |
1646 | &dev_attr_num_unsol_na.attr, | |
43cb76d9 GKH |
1647 | &dev_attr_miimon.attr, |
1648 | &dev_attr_primary.attr, | |
a549952a | 1649 | &dev_attr_primary_reselect.attr, |
43cb76d9 GKH |
1650 | &dev_attr_use_carrier.attr, |
1651 | &dev_attr_active_slave.attr, | |
1652 | &dev_attr_mii_status.attr, | |
1653 | &dev_attr_ad_aggregator.attr, | |
1654 | &dev_attr_ad_num_ports.attr, | |
1655 | &dev_attr_ad_actor_key.attr, | |
1656 | &dev_attr_ad_partner_key.attr, | |
1657 | &dev_attr_ad_partner_mac.attr, | |
bb1d9123 | 1658 | &dev_attr_queue_id.attr, |
ebd8e497 | 1659 | &dev_attr_all_slaves_active.attr, |
c2952c31 | 1660 | &dev_attr_resend_igmp.attr, |
655f8919 | 1661 | &dev_attr_min_links.attr, |
b76cdba9 MW |
1662 | NULL, |
1663 | }; | |
1664 | ||
1665 | static struct attribute_group bonding_group = { | |
1666 | .name = "bonding", | |
1667 | .attrs = per_bond_attrs, | |
1668 | }; | |
1669 | ||
1670 | /* | |
1671 | * Initialize sysfs. This sets up the bonding_masters file in | |
1672 | * /sys/class/net. | |
1673 | */ | |
4c22400a | 1674 | int bond_create_sysfs(struct bond_net *bn) |
b76cdba9 | 1675 | { |
b8a9787e | 1676 | int ret; |
b76cdba9 | 1677 | |
4c22400a | 1678 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
01718e36 | 1679 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
4c22400a EB |
1680 | |
1681 | ret = netdev_class_create_file(&bn->class_attr_bonding_masters); | |
877cbd36 JV |
1682 | /* |
1683 | * Permit multiple loads of the module by ignoring failures to | |
1684 | * create the bonding_masters sysfs file. Bonding devices | |
1685 | * created by second or subsequent loads of the module will | |
1686 | * not be listed in, or controllable by, bonding_masters, but | |
1687 | * will have the usual "bonding" sysfs directory. | |
1688 | * | |
1689 | * This is done to preserve backwards compatibility for | |
1690 | * initscripts/sysconfig, which load bonding multiple times to | |
1691 | * configure multiple bonding devices. | |
1692 | */ | |
1693 | if (ret == -EEXIST) { | |
38d2f38b | 1694 | /* Is someone being kinky and naming a device bonding_master? */ |
4c22400a | 1695 | if (__dev_get_by_name(bn->net, |
38d2f38b | 1696 | class_attr_bonding_masters.attr.name)) |
a4aee5c8 | 1697 | pr_err("network device named %s already exists in sysfs", |
38d2f38b | 1698 | class_attr_bonding_masters.attr.name); |
130aa61a | 1699 | ret = 0; |
877cbd36 | 1700 | } |
b76cdba9 MW |
1701 | |
1702 | return ret; | |
1703 | ||
1704 | } | |
1705 | ||
1706 | /* | |
1707 | * Remove /sys/class/net/bonding_masters. | |
1708 | */ | |
4c22400a | 1709 | void bond_destroy_sysfs(struct bond_net *bn) |
b76cdba9 | 1710 | { |
4c22400a | 1711 | netdev_class_remove_file(&bn->class_attr_bonding_masters); |
b76cdba9 MW |
1712 | } |
1713 | ||
1714 | /* | |
1715 | * Initialize sysfs for each bond. This sets up and registers | |
1716 | * the 'bondctl' directory for each individual bond under /sys/class/net. | |
1717 | */ | |
6151b3d4 | 1718 | void bond_prepare_sysfs_group(struct bonding *bond) |
b76cdba9 | 1719 | { |
6151b3d4 | 1720 | bond->dev->sysfs_groups[0] = &bonding_group; |
b76cdba9 MW |
1721 | } |
1722 |