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