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