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