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 | 320 | { |
f70161c6 | 321 | int new_value, ret; |
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); | |
f70161c6 | 329 | return -EINVAL; |
b76cdba9 | 330 | } |
53edee2c | 331 | |
f70161c6 | 332 | if (!rtnl_trylock()) |
333 | return restart_syscall(); | |
334 | ||
335 | ret = bond_option_xmit_hash_policy_set(bond, new_value); | |
336 | if (!ret) | |
337 | ret = count; | |
338 | ||
339 | rtnl_unlock(); | |
b76cdba9 MW |
340 | return ret; |
341 | } | |
3d632c3f SH |
342 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
343 | bonding_show_xmit_hash, bonding_store_xmit_hash); | |
b76cdba9 | 344 | |
f5b2b966 JV |
345 | /* |
346 | * Show and set arp_validate. | |
347 | */ | |
43cb76d9 GKH |
348 | static ssize_t bonding_show_arp_validate(struct device *d, |
349 | struct device_attribute *attr, | |
350 | char *buf) | |
f5b2b966 | 351 | { |
43cb76d9 | 352 | struct bonding *bond = to_bond(d); |
f5b2b966 JV |
353 | |
354 | return sprintf(buf, "%s %d\n", | |
355 | arp_validate_tbl[bond->params.arp_validate].modename, | |
7bd46508 | 356 | bond->params.arp_validate); |
f5b2b966 JV |
357 | } |
358 | ||
43cb76d9 GKH |
359 | static ssize_t bonding_store_arp_validate(struct device *d, |
360 | struct device_attribute *attr, | |
361 | const char *buf, size_t count) | |
f5b2b966 | 362 | { |
43cb76d9 | 363 | struct bonding *bond = to_bond(d); |
29c49482 | 364 | int new_value, ret; |
f5b2b966 | 365 | |
ece95f7f | 366 | new_value = bond_parse_parm(buf, arp_validate_tbl); |
f5b2b966 | 367 | if (new_value < 0) { |
a4aee5c8 | 368 | pr_err("%s: Ignoring invalid arp_validate value %s\n", |
f5b2b966 | 369 | bond->dev->name, buf); |
29c49482 | 370 | return -EINVAL; |
5bb9e0b5 | 371 | } |
29c49482 | 372 | if (!rtnl_trylock()) |
373 | return restart_syscall(); | |
374 | ||
375 | ret = bond_option_arp_validate_set(bond, new_value); | |
376 | if (!ret) | |
377 | ret = count; | |
378 | ||
5c5038dc | 379 | rtnl_unlock(); |
f5b2b966 | 380 | |
5c5038dc | 381 | return ret; |
f5b2b966 JV |
382 | } |
383 | ||
3d632c3f SH |
384 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
385 | bonding_store_arp_validate); | |
8599b52e VF |
386 | /* |
387 | * Show and set arp_all_targets. | |
388 | */ | |
389 | static ssize_t bonding_show_arp_all_targets(struct device *d, | |
390 | struct device_attribute *attr, | |
391 | char *buf) | |
392 | { | |
393 | struct bonding *bond = to_bond(d); | |
394 | int value = bond->params.arp_all_targets; | |
395 | ||
396 | return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename, | |
397 | value); | |
398 | } | |
399 | ||
400 | static ssize_t bonding_store_arp_all_targets(struct device *d, | |
401 | struct device_attribute *attr, | |
402 | const char *buf, size_t count) | |
403 | { | |
404 | struct bonding *bond = to_bond(d); | |
d5c84254 | 405 | int new_value, ret; |
8599b52e VF |
406 | |
407 | new_value = bond_parse_parm(buf, arp_all_targets_tbl); | |
408 | if (new_value < 0) { | |
409 | pr_err("%s: Ignoring invalid arp_all_targets value %s\n", | |
410 | bond->dev->name, buf); | |
411 | return -EINVAL; | |
412 | } | |
8599b52e | 413 | |
d5c84254 | 414 | if (!rtnl_trylock()) |
415 | return restart_syscall(); | |
8599b52e | 416 | |
d5c84254 | 417 | ret = bond_option_arp_all_targets_set(bond, new_value); |
418 | if (!ret) | |
419 | ret = count; | |
420 | ||
421 | rtnl_unlock(); | |
422 | ||
423 | return ret; | |
8599b52e VF |
424 | } |
425 | ||
426 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, | |
427 | bonding_show_arp_all_targets, bonding_store_arp_all_targets); | |
f5b2b966 | 428 | |
dd957c57 JV |
429 | /* |
430 | * Show and store fail_over_mac. User only allowed to change the | |
431 | * value when there are no slaves. | |
432 | */ | |
3d632c3f SH |
433 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
434 | struct device_attribute *attr, | |
435 | char *buf) | |
dd957c57 JV |
436 | { |
437 | struct bonding *bond = to_bond(d); | |
438 | ||
3915c1e8 JV |
439 | return sprintf(buf, "%s %d\n", |
440 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, | |
441 | bond->params.fail_over_mac); | |
dd957c57 JV |
442 | } |
443 | ||
3d632c3f SH |
444 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
445 | struct device_attribute *attr, | |
446 | const char *buf, size_t count) | |
dd957c57 | 447 | { |
89901972 | 448 | int new_value, ret; |
dd957c57 JV |
449 | struct bonding *bond = to_bond(d); |
450 | ||
3915c1e8 JV |
451 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
452 | if (new_value < 0) { | |
a4aee5c8 | 453 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
3915c1e8 | 454 | bond->dev->name, buf); |
89901972 | 455 | return -EINVAL; |
dd957c57 JV |
456 | } |
457 | ||
89901972 | 458 | if (!rtnl_trylock()) |
459 | return restart_syscall(); | |
460 | ||
461 | ret = bond_option_fail_over_mac_set(bond, new_value); | |
462 | if (!ret) | |
463 | ret = count; | |
3915c1e8 | 464 | |
9402b746 | 465 | rtnl_unlock(); |
466 | return ret; | |
dd957c57 JV |
467 | } |
468 | ||
3d632c3f SH |
469 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
470 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); | |
dd957c57 | 471 | |
b76cdba9 MW |
472 | /* |
473 | * Show and set the arp timer interval. There are two tricky bits | |
474 | * here. First, if ARP monitoring is activated, then we must disable | |
475 | * MII monitoring. Second, if the ARP timer isn't running, we must | |
476 | * start it. | |
477 | */ | |
43cb76d9 GKH |
478 | static ssize_t bonding_show_arp_interval(struct device *d, |
479 | struct device_attribute *attr, | |
480 | char *buf) | |
b76cdba9 | 481 | { |
43cb76d9 | 482 | struct bonding *bond = to_bond(d); |
b76cdba9 | 483 | |
7bd46508 | 484 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
b76cdba9 MW |
485 | } |
486 | ||
43cb76d9 GKH |
487 | static ssize_t bonding_store_arp_interval(struct device *d, |
488 | struct device_attribute *attr, | |
489 | const char *buf, size_t count) | |
b76cdba9 | 490 | { |
43cb76d9 | 491 | struct bonding *bond = to_bond(d); |
06151dbc | 492 | int new_value, ret; |
b76cdba9 MW |
493 | |
494 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 495 | pr_err("%s: no arp_interval value specified.\n", |
06151dbc | 496 | bond->dev->name); |
497 | return -EINVAL; | |
b76cdba9 | 498 | } |
06151dbc | 499 | |
500 | if (!rtnl_trylock()) | |
501 | return restart_syscall(); | |
502 | ||
503 | ret = bond_option_arp_interval_set(bond, new_value); | |
504 | if (!ret) | |
505 | ret = count; | |
506 | ||
fbb0c41b | 507 | rtnl_unlock(); |
b76cdba9 MW |
508 | return ret; |
509 | } | |
3d632c3f SH |
510 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
511 | bonding_show_arp_interval, bonding_store_arp_interval); | |
b76cdba9 MW |
512 | |
513 | /* | |
514 | * Show and set the arp targets. | |
515 | */ | |
43cb76d9 GKH |
516 | static ssize_t bonding_show_arp_targets(struct device *d, |
517 | struct device_attribute *attr, | |
518 | char *buf) | |
b76cdba9 MW |
519 | { |
520 | int i, res = 0; | |
43cb76d9 | 521 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
522 | |
523 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { | |
524 | if (bond->params.arp_targets[i]) | |
63779436 HH |
525 | res += sprintf(buf + res, "%pI4 ", |
526 | &bond->params.arp_targets[i]); | |
b76cdba9 | 527 | } |
1dcdcd69 WF |
528 | if (res) |
529 | buf[res-1] = '\n'; /* eat the leftover space */ | |
b76cdba9 MW |
530 | return res; |
531 | } | |
532 | ||
43cb76d9 GKH |
533 | static ssize_t bonding_store_arp_targets(struct device *d, |
534 | struct device_attribute *attr, | |
535 | const char *buf, size_t count) | |
b76cdba9 | 536 | { |
43cb76d9 | 537 | struct bonding *bond = to_bond(d); |
7f28fa10 | 538 | __be32 target; |
539 | int ret = -EPERM; | |
4d1ae5fb | 540 | |
7f28fa10 | 541 | if (!in4_pton(buf + 1, -1, (u8 *)&target, -1, NULL)) { |
542 | pr_err("%s: invalid ARP target %pI4 specified\n", | |
543 | bond->dev->name, &target); | |
544 | return -EPERM; | |
f9de11a1 | 545 | } |
8599b52e | 546 | |
7f28fa10 | 547 | if (!rtnl_trylock()) |
548 | return restart_syscall(); | |
8599b52e | 549 | |
7f28fa10 | 550 | if (buf[0] == '+') |
551 | ret = bond_option_arp_ip_target_add(bond, target); | |
552 | else if (buf[0] == '-') | |
553 | ret = bond_option_arp_ip_target_rem(bond, target); | |
554 | else | |
a4aee5c8 JP |
555 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
556 | bond->dev->name); | |
b76cdba9 | 557 | |
7f28fa10 | 558 | if (!ret) |
559 | ret = count; | |
560 | ||
4d1ae5fb | 561 | rtnl_unlock(); |
b76cdba9 MW |
562 | return ret; |
563 | } | |
43cb76d9 | 564 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); |
b76cdba9 MW |
565 | |
566 | /* | |
567 | * Show and set the up and down delays. These must be multiples of the | |
568 | * MII monitoring value, and are stored internally as the multiplier. | |
569 | * Thus, we must translate to MS for the real world. | |
570 | */ | |
43cb76d9 GKH |
571 | static ssize_t bonding_show_downdelay(struct device *d, |
572 | struct device_attribute *attr, | |
573 | char *buf) | |
b76cdba9 | 574 | { |
43cb76d9 | 575 | struct bonding *bond = to_bond(d); |
b76cdba9 | 576 | |
7bd46508 | 577 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
b76cdba9 MW |
578 | } |
579 | ||
43cb76d9 GKH |
580 | static ssize_t bonding_store_downdelay(struct device *d, |
581 | struct device_attribute *attr, | |
582 | const char *buf, size_t count) | |
b76cdba9 | 583 | { |
c7461f9b | 584 | int new_value, ret; |
43cb76d9 | 585 | struct bonding *bond = to_bond(d); |
b76cdba9 | 586 | |
b76cdba9 | 587 | if (sscanf(buf, "%d", &new_value) != 1) { |
a4aee5c8 | 588 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
c7461f9b | 589 | return -EINVAL; |
b76cdba9 | 590 | } |
b76cdba9 | 591 | |
c7461f9b | 592 | if (!rtnl_trylock()) |
593 | return restart_syscall(); | |
594 | ||
595 | ret = bond_option_downdelay_set(bond, new_value); | |
596 | if (!ret) | |
597 | ret = count; | |
b76cdba9 | 598 | |
b869ccfa | 599 | rtnl_unlock(); |
b76cdba9 MW |
600 | return ret; |
601 | } | |
3d632c3f SH |
602 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
603 | bonding_show_downdelay, bonding_store_downdelay); | |
b76cdba9 | 604 | |
43cb76d9 GKH |
605 | static ssize_t bonding_show_updelay(struct device *d, |
606 | struct device_attribute *attr, | |
607 | char *buf) | |
b76cdba9 | 608 | { |
43cb76d9 | 609 | struct bonding *bond = to_bond(d); |
b76cdba9 | 610 | |
7bd46508 | 611 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
b76cdba9 MW |
612 | |
613 | } | |
614 | ||
43cb76d9 GKH |
615 | static ssize_t bonding_store_updelay(struct device *d, |
616 | struct device_attribute *attr, | |
617 | const char *buf, size_t count) | |
b76cdba9 | 618 | { |
25852e29 | 619 | int new_value, ret; |
43cb76d9 | 620 | struct bonding *bond = to_bond(d); |
b76cdba9 | 621 | |
b76cdba9 | 622 | if (sscanf(buf, "%d", &new_value) != 1) { |
a4aee5c8 | 623 | pr_err("%s: no up delay value specified.\n", |
25852e29 | 624 | bond->dev->name); |
625 | return -EINVAL; | |
b76cdba9 MW |
626 | } |
627 | ||
25852e29 | 628 | if (!rtnl_trylock()) |
629 | return restart_syscall(); | |
630 | ||
631 | ret = bond_option_updelay_set(bond, new_value); | |
632 | if (!ret) | |
633 | ret = count; | |
634 | ||
b869ccfa | 635 | rtnl_unlock(); |
b76cdba9 MW |
636 | return ret; |
637 | } | |
3d632c3f SH |
638 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
639 | bonding_show_updelay, bonding_store_updelay); | |
b76cdba9 MW |
640 | |
641 | /* | |
642 | * Show and set the LACP interval. Interface must be down, and the mode | |
643 | * must be set to 802.3ad mode. | |
644 | */ | |
43cb76d9 GKH |
645 | static ssize_t bonding_show_lacp(struct device *d, |
646 | struct device_attribute *attr, | |
647 | char *buf) | |
b76cdba9 | 648 | { |
43cb76d9 | 649 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
650 | |
651 | return sprintf(buf, "%s %d\n", | |
652 | bond_lacp_tbl[bond->params.lacp_fast].modename, | |
7bd46508 | 653 | bond->params.lacp_fast); |
b76cdba9 MW |
654 | } |
655 | ||
43cb76d9 GKH |
656 | static ssize_t bonding_store_lacp(struct device *d, |
657 | struct device_attribute *attr, | |
658 | const char *buf, size_t count) | |
b76cdba9 | 659 | { |
43cb76d9 | 660 | struct bonding *bond = to_bond(d); |
c509316b | 661 | int new_value, ret = count; |
662 | ||
663 | if (!rtnl_trylock()) | |
664 | return restart_syscall(); | |
b76cdba9 MW |
665 | |
666 | if (bond->dev->flags & IFF_UP) { | |
a4aee5c8 | 667 | pr_err("%s: Unable to update LACP rate because interface is up.\n", |
b76cdba9 MW |
668 | bond->dev->name); |
669 | ret = -EPERM; | |
670 | goto out; | |
671 | } | |
672 | ||
673 | if (bond->params.mode != BOND_MODE_8023AD) { | |
a4aee5c8 | 674 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
b76cdba9 MW |
675 | bond->dev->name); |
676 | ret = -EPERM; | |
677 | goto out; | |
678 | } | |
679 | ||
ece95f7f | 680 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
b76cdba9 MW |
681 | |
682 | if ((new_value == 1) || (new_value == 0)) { | |
683 | bond->params.lacp_fast = new_value; | |
ba824a8b | 684 | bond_3ad_update_lacp_rate(bond); |
a4aee5c8 | 685 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
3d632c3f SH |
686 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
687 | new_value); | |
b76cdba9 | 688 | } else { |
a4aee5c8 | 689 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
3d632c3f | 690 | bond->dev->name, (int)strlen(buf) - 1, buf); |
b76cdba9 MW |
691 | ret = -EINVAL; |
692 | } | |
693 | out: | |
c509316b | 694 | rtnl_unlock(); |
695 | ||
b76cdba9 MW |
696 | return ret; |
697 | } | |
3d632c3f SH |
698 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
699 | bonding_show_lacp, bonding_store_lacp); | |
b76cdba9 | 700 | |
655f8919 | 701 | static ssize_t bonding_show_min_links(struct device *d, |
702 | struct device_attribute *attr, | |
703 | char *buf) | |
704 | { | |
705 | struct bonding *bond = to_bond(d); | |
706 | ||
707 | return sprintf(buf, "%d\n", bond->params.min_links); | |
708 | } | |
709 | ||
710 | static ssize_t bonding_store_min_links(struct device *d, | |
711 | struct device_attribute *attr, | |
712 | const char *buf, size_t count) | |
713 | { | |
714 | struct bonding *bond = to_bond(d); | |
715 | int ret; | |
716 | unsigned int new_value; | |
717 | ||
718 | ret = kstrtouint(buf, 0, &new_value); | |
719 | if (ret < 0) { | |
720 | pr_err("%s: Ignoring invalid min links value %s.\n", | |
721 | bond->dev->name, buf); | |
722 | return ret; | |
723 | } | |
724 | ||
725 | pr_info("%s: Setting min links value to %u\n", | |
726 | bond->dev->name, new_value); | |
727 | bond->params.min_links = new_value; | |
728 | return count; | |
729 | } | |
730 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, | |
731 | bonding_show_min_links, bonding_store_min_links); | |
732 | ||
fd989c83 JV |
733 | static ssize_t bonding_show_ad_select(struct device *d, |
734 | struct device_attribute *attr, | |
735 | char *buf) | |
736 | { | |
737 | struct bonding *bond = to_bond(d); | |
738 | ||
739 | return sprintf(buf, "%s %d\n", | |
740 | ad_select_tbl[bond->params.ad_select].modename, | |
741 | bond->params.ad_select); | |
742 | } | |
743 | ||
744 | ||
745 | static ssize_t bonding_store_ad_select(struct device *d, | |
746 | struct device_attribute *attr, | |
747 | const char *buf, size_t count) | |
748 | { | |
749 | int new_value, ret = count; | |
750 | struct bonding *bond = to_bond(d); | |
751 | ||
752 | if (bond->dev->flags & IFF_UP) { | |
a4aee5c8 JP |
753 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
754 | bond->dev->name); | |
fd989c83 JV |
755 | ret = -EPERM; |
756 | goto out; | |
757 | } | |
758 | ||
759 | new_value = bond_parse_parm(buf, ad_select_tbl); | |
760 | ||
761 | if (new_value != -1) { | |
762 | bond->params.ad_select = new_value; | |
a4aee5c8 JP |
763 | pr_info("%s: Setting ad_select to %s (%d).\n", |
764 | bond->dev->name, ad_select_tbl[new_value].modename, | |
765 | new_value); | |
fd989c83 | 766 | } else { |
a4aee5c8 | 767 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
fd989c83 JV |
768 | bond->dev->name, (int)strlen(buf) - 1, buf); |
769 | ret = -EINVAL; | |
770 | } | |
771 | out: | |
772 | return ret; | |
773 | } | |
3d632c3f SH |
774 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
775 | bonding_show_ad_select, bonding_store_ad_select); | |
fd989c83 | 776 | |
ad246c99 BH |
777 | /* |
778 | * Show and set the number of peer notifications to send after a failover event. | |
779 | */ | |
780 | static ssize_t bonding_show_num_peer_notif(struct device *d, | |
781 | struct device_attribute *attr, | |
782 | char *buf) | |
783 | { | |
784 | struct bonding *bond = to_bond(d); | |
785 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); | |
786 | } | |
787 | ||
788 | static ssize_t bonding_store_num_peer_notif(struct device *d, | |
789 | struct device_attribute *attr, | |
790 | const char *buf, size_t count) | |
791 | { | |
792 | struct bonding *bond = to_bond(d); | |
2c9839c1 | 793 | u8 new_value; |
794 | int ret; | |
795 | ||
796 | ret = kstrtou8(buf, 10, &new_value); | |
797 | if (!ret) { | |
798 | pr_err("%s: invalid value %s specified.\n", | |
799 | bond->dev->name, buf); | |
800 | return ret; | |
801 | } | |
802 | ||
803 | if (!rtnl_trylock()) | |
804 | return restart_syscall(); | |
805 | ||
806 | ret = bond_option_num_peer_notif_set(bond, new_value); | |
807 | if (!ret) | |
808 | ret = count; | |
809 | ||
810 | rtnl_unlock(); | |
811 | return ret; | |
ad246c99 BH |
812 | } |
813 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, | |
814 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
815 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, | |
816 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
817 | ||
b76cdba9 MW |
818 | /* |
819 | * Show and set the MII monitor interval. There are two tricky bits | |
820 | * here. First, if MII monitoring is activated, then we must disable | |
821 | * ARP monitoring. Second, if the timer isn't running, we must | |
822 | * start it. | |
823 | */ | |
43cb76d9 GKH |
824 | static ssize_t bonding_show_miimon(struct device *d, |
825 | struct device_attribute *attr, | |
826 | char *buf) | |
b76cdba9 | 827 | { |
43cb76d9 | 828 | struct bonding *bond = to_bond(d); |
b76cdba9 | 829 | |
7bd46508 | 830 | return sprintf(buf, "%d\n", bond->params.miimon); |
b76cdba9 MW |
831 | } |
832 | ||
43cb76d9 GKH |
833 | static ssize_t bonding_store_miimon(struct device *d, |
834 | struct device_attribute *attr, | |
835 | const char *buf, size_t count) | |
b76cdba9 | 836 | { |
eecdaa6e | 837 | int new_value, ret; |
43cb76d9 | 838 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
839 | |
840 | if (sscanf(buf, "%d", &new_value) != 1) { | |
a4aee5c8 | 841 | pr_err("%s: no miimon value specified.\n", |
b76cdba9 | 842 | bond->dev->name); |
eecdaa6e | 843 | return -EINVAL; |
b76cdba9 | 844 | } |
eecdaa6e | 845 | |
846 | if (!rtnl_trylock()) | |
847 | return restart_syscall(); | |
848 | ||
849 | ret = bond_option_miimon_set(bond, new_value); | |
850 | if (!ret) | |
851 | ret = count; | |
852 | ||
fbb0c41b | 853 | rtnl_unlock(); |
b76cdba9 MW |
854 | return ret; |
855 | } | |
3d632c3f SH |
856 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
857 | bonding_show_miimon, bonding_store_miimon); | |
b76cdba9 MW |
858 | |
859 | /* | |
860 | * Show and set the primary slave. The store function is much | |
861 | * simpler than bonding_store_slaves function because it only needs to | |
862 | * handle one interface name. | |
863 | * The bond must be a mode that supports a primary for this be | |
864 | * set. | |
865 | */ | |
43cb76d9 GKH |
866 | static ssize_t bonding_show_primary(struct device *d, |
867 | struct device_attribute *attr, | |
868 | char *buf) | |
b76cdba9 MW |
869 | { |
870 | int count = 0; | |
43cb76d9 | 871 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
872 | |
873 | if (bond->primary_slave) | |
7bd46508 | 874 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
b76cdba9 MW |
875 | |
876 | return count; | |
877 | } | |
878 | ||
43cb76d9 GKH |
879 | static ssize_t bonding_store_primary(struct device *d, |
880 | struct device_attribute *attr, | |
881 | const char *buf, size_t count) | |
b76cdba9 | 882 | { |
43cb76d9 | 883 | struct bonding *bond = to_bond(d); |
f4bb2e9c | 884 | char ifname[IFNAMSIZ]; |
0a98a0d1 | 885 | int ret; |
b76cdba9 | 886 | |
eb6e98a1 | 887 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
0a98a0d1 | 888 | if (ifname[0] == '\n') |
889 | ifname[0] = '\0'; | |
b76cdba9 | 890 | |
0a98a0d1 | 891 | if (!rtnl_trylock()) |
892 | return restart_syscall(); | |
f4bb2e9c | 893 | |
0a98a0d1 | 894 | ret = bond_option_primary_set(bond, ifname); |
895 | if (!ret) | |
896 | ret = count; | |
8a93664d | 897 | |
6603a6f2 | 898 | rtnl_unlock(); |
0a98a0d1 | 899 | return ret; |
b76cdba9 | 900 | } |
3d632c3f SH |
901 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
902 | bonding_show_primary, bonding_store_primary); | |
b76cdba9 | 903 | |
a549952a JP |
904 | /* |
905 | * Show and set the primary_reselect flag. | |
906 | */ | |
907 | static ssize_t bonding_show_primary_reselect(struct device *d, | |
908 | struct device_attribute *attr, | |
909 | char *buf) | |
910 | { | |
911 | struct bonding *bond = to_bond(d); | |
912 | ||
913 | return sprintf(buf, "%s %d\n", | |
914 | pri_reselect_tbl[bond->params.primary_reselect].modename, | |
915 | bond->params.primary_reselect); | |
916 | } | |
917 | ||
918 | static ssize_t bonding_store_primary_reselect(struct device *d, | |
919 | struct device_attribute *attr, | |
920 | const char *buf, size_t count) | |
921 | { | |
8a41ae44 | 922 | int new_value, ret; |
a549952a JP |
923 | struct bonding *bond = to_bond(d); |
924 | ||
a549952a JP |
925 | new_value = bond_parse_parm(buf, pri_reselect_tbl); |
926 | if (new_value < 0) { | |
a4aee5c8 | 927 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
a549952a JP |
928 | bond->dev->name, |
929 | (int) strlen(buf) - 1, buf); | |
8a41ae44 | 930 | return -EINVAL; |
a549952a JP |
931 | } |
932 | ||
8a41ae44 | 933 | if (!rtnl_trylock()) |
934 | return restart_syscall(); | |
935 | ||
936 | ret = bond_option_primary_reselect_set(bond, new_value); | |
937 | if (!ret) | |
938 | ret = count; | |
a549952a | 939 | |
a549952a JP |
940 | rtnl_unlock(); |
941 | return ret; | |
942 | } | |
943 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, | |
944 | bonding_show_primary_reselect, | |
945 | bonding_store_primary_reselect); | |
946 | ||
b76cdba9 MW |
947 | /* |
948 | * Show and set the use_carrier flag. | |
949 | */ | |
43cb76d9 GKH |
950 | static ssize_t bonding_show_carrier(struct device *d, |
951 | struct device_attribute *attr, | |
952 | char *buf) | |
b76cdba9 | 953 | { |
43cb76d9 | 954 | struct bonding *bond = to_bond(d); |
b76cdba9 | 955 | |
7bd46508 | 956 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
b76cdba9 MW |
957 | } |
958 | ||
43cb76d9 GKH |
959 | static ssize_t bonding_store_carrier(struct device *d, |
960 | struct device_attribute *attr, | |
961 | const char *buf, size_t count) | |
b76cdba9 | 962 | { |
9f53e14e | 963 | int new_value, ret; |
43cb76d9 | 964 | struct bonding *bond = to_bond(d); |
b76cdba9 | 965 | |
b76cdba9 | 966 | if (sscanf(buf, "%d", &new_value) != 1) { |
a4aee5c8 | 967 | pr_err("%s: no use_carrier value specified.\n", |
b76cdba9 | 968 | bond->dev->name); |
9f53e14e | 969 | return -EINVAL; |
b76cdba9 | 970 | } |
9f53e14e | 971 | |
972 | if (!rtnl_trylock()) | |
973 | return restart_syscall(); | |
974 | ||
975 | ret = bond_option_use_carrier_set(bond, new_value); | |
976 | if (!ret) | |
977 | ret = count; | |
978 | ||
979 | rtnl_unlock(); | |
672bda33 | 980 | return ret; |
b76cdba9 | 981 | } |
3d632c3f SH |
982 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
983 | bonding_show_carrier, bonding_store_carrier); | |
b76cdba9 MW |
984 | |
985 | ||
986 | /* | |
987 | * Show and set currently active_slave. | |
988 | */ | |
43cb76d9 GKH |
989 | static ssize_t bonding_show_active_slave(struct device *d, |
990 | struct device_attribute *attr, | |
991 | char *buf) | |
b76cdba9 | 992 | { |
43cb76d9 | 993 | struct bonding *bond = to_bond(d); |
752d48b5 | 994 | struct net_device *slave_dev; |
16cd0160 | 995 | int count = 0; |
b76cdba9 | 996 | |
278b2083 | 997 | rcu_read_lock(); |
752d48b5 JP |
998 | slave_dev = bond_option_active_slave_get_rcu(bond); |
999 | if (slave_dev) | |
1000 | count = sprintf(buf, "%s\n", slave_dev->name); | |
278b2083 | 1001 | rcu_read_unlock(); |
1002 | ||
b76cdba9 MW |
1003 | return count; |
1004 | } | |
1005 | ||
43cb76d9 GKH |
1006 | static ssize_t bonding_store_active_slave(struct device *d, |
1007 | struct device_attribute *attr, | |
1008 | const char *buf, size_t count) | |
b76cdba9 | 1009 | { |
d9e32b21 | 1010 | int ret; |
43cb76d9 | 1011 | struct bonding *bond = to_bond(d); |
f4bb2e9c | 1012 | char ifname[IFNAMSIZ]; |
d9e32b21 | 1013 | struct net_device *dev; |
b76cdba9 | 1014 | |
496a60cd EB |
1015 | if (!rtnl_trylock()) |
1016 | return restart_syscall(); | |
e843fa50 | 1017 | |
c84e1590 | 1018 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
f4bb2e9c | 1019 | if (!strlen(ifname) || buf[0] == '\n') { |
d9e32b21 JP |
1020 | dev = NULL; |
1021 | } else { | |
1022 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); | |
1023 | if (!dev) { | |
1024 | ret = -ENODEV; | |
1025 | goto out; | |
b76cdba9 | 1026 | } |
b76cdba9 | 1027 | } |
f4bb2e9c | 1028 | |
d9e32b21 JP |
1029 | ret = bond_option_active_slave_set(bond, dev); |
1030 | if (!ret) | |
1031 | ret = count; | |
e843fa50 | 1032 | |
d9e32b21 | 1033 | out: |
6603a6f2 JV |
1034 | rtnl_unlock(); |
1035 | ||
d9e32b21 | 1036 | return ret; |
b76cdba9 MW |
1037 | |
1038 | } | |
3d632c3f SH |
1039 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
1040 | bonding_show_active_slave, bonding_store_active_slave); | |
b76cdba9 MW |
1041 | |
1042 | ||
1043 | /* | |
1044 | * Show link status of the bond interface. | |
1045 | */ | |
43cb76d9 GKH |
1046 | static ssize_t bonding_show_mii_status(struct device *d, |
1047 | struct device_attribute *attr, | |
1048 | char *buf) | |
b76cdba9 | 1049 | { |
43cb76d9 | 1050 | struct bonding *bond = to_bond(d); |
b76cdba9 | 1051 | |
278b2083 | 1052 | return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down"); |
b76cdba9 | 1053 | } |
43cb76d9 | 1054 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
b76cdba9 | 1055 | |
b76cdba9 MW |
1056 | /* |
1057 | * Show current 802.3ad aggregator ID. | |
1058 | */ | |
43cb76d9 GKH |
1059 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
1060 | struct device_attribute *attr, | |
1061 | char *buf) | |
b76cdba9 MW |
1062 | { |
1063 | int count = 0; | |
43cb76d9 | 1064 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1065 | |
1066 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1067 | struct ad_info ad_info; | |
3d632c3f | 1068 | count = sprintf(buf, "%d\n", |
318debd8 | 1069 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1070 | ? 0 : ad_info.aggregator_id); |
b76cdba9 | 1071 | } |
b76cdba9 MW |
1072 | |
1073 | return count; | |
1074 | } | |
43cb76d9 | 1075 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
b76cdba9 MW |
1076 | |
1077 | ||
1078 | /* | |
1079 | * Show number of active 802.3ad ports. | |
1080 | */ | |
43cb76d9 GKH |
1081 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
1082 | struct device_attribute *attr, | |
1083 | char *buf) | |
b76cdba9 MW |
1084 | { |
1085 | int count = 0; | |
43cb76d9 | 1086 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1087 | |
1088 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1089 | struct ad_info ad_info; | |
3d632c3f | 1090 | count = sprintf(buf, "%d\n", |
318debd8 | 1091 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1092 | ? 0 : ad_info.ports); |
b76cdba9 | 1093 | } |
b76cdba9 MW |
1094 | |
1095 | return count; | |
1096 | } | |
43cb76d9 | 1097 | static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); |
b76cdba9 MW |
1098 | |
1099 | ||
1100 | /* | |
1101 | * Show current 802.3ad actor key. | |
1102 | */ | |
43cb76d9 GKH |
1103 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
1104 | struct device_attribute *attr, | |
1105 | char *buf) | |
b76cdba9 MW |
1106 | { |
1107 | int count = 0; | |
43cb76d9 | 1108 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1109 | |
1110 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1111 | struct ad_info ad_info; | |
3d632c3f | 1112 | count = sprintf(buf, "%d\n", |
318debd8 | 1113 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1114 | ? 0 : ad_info.actor_key); |
b76cdba9 | 1115 | } |
b76cdba9 MW |
1116 | |
1117 | return count; | |
1118 | } | |
43cb76d9 | 1119 | static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); |
b76cdba9 MW |
1120 | |
1121 | ||
1122 | /* | |
1123 | * Show current 802.3ad partner key. | |
1124 | */ | |
43cb76d9 GKH |
1125 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
1126 | struct device_attribute *attr, | |
1127 | char *buf) | |
b76cdba9 MW |
1128 | { |
1129 | int count = 0; | |
43cb76d9 | 1130 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1131 | |
1132 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1133 | struct ad_info ad_info; | |
3d632c3f | 1134 | count = sprintf(buf, "%d\n", |
318debd8 | 1135 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 1136 | ? 0 : ad_info.partner_key); |
b76cdba9 | 1137 | } |
b76cdba9 MW |
1138 | |
1139 | return count; | |
1140 | } | |
43cb76d9 | 1141 | static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); |
b76cdba9 MW |
1142 | |
1143 | ||
1144 | /* | |
1145 | * Show current 802.3ad partner mac. | |
1146 | */ | |
43cb76d9 GKH |
1147 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
1148 | struct device_attribute *attr, | |
1149 | char *buf) | |
b76cdba9 MW |
1150 | { |
1151 | int count = 0; | |
43cb76d9 | 1152 | struct bonding *bond = to_bond(d); |
b76cdba9 MW |
1153 | |
1154 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1155 | struct ad_info ad_info; | |
3d632c3f | 1156 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
e174961c | 1157 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
b76cdba9 | 1158 | } |
b76cdba9 MW |
1159 | |
1160 | return count; | |
1161 | } | |
43cb76d9 | 1162 | static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); |
b76cdba9 | 1163 | |
bb1d9123 AG |
1164 | /* |
1165 | * Show the queue_ids of the slaves in the current bond. | |
1166 | */ | |
1167 | static ssize_t bonding_show_queue_id(struct device *d, | |
1168 | struct device_attribute *attr, | |
1169 | char *buf) | |
1170 | { | |
bb1d9123 | 1171 | struct bonding *bond = to_bond(d); |
9caff1e7 | 1172 | struct list_head *iter; |
dec1e90e | 1173 | struct slave *slave; |
1174 | int res = 0; | |
bb1d9123 AG |
1175 | |
1176 | if (!rtnl_trylock()) | |
1177 | return restart_syscall(); | |
1178 | ||
9caff1e7 | 1179 | bond_for_each_slave(bond, slave, iter) { |
79236680 NP |
1180 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
1181 | /* not enough space for another interface_name:queue_id pair */ | |
bb1d9123 AG |
1182 | if ((PAGE_SIZE - res) > 10) |
1183 | res = PAGE_SIZE - 10; | |
1184 | res += sprintf(buf + res, "++more++ "); | |
1185 | break; | |
1186 | } | |
1187 | res += sprintf(buf + res, "%s:%d ", | |
1188 | slave->dev->name, slave->queue_id); | |
1189 | } | |
bb1d9123 AG |
1190 | if (res) |
1191 | buf[res-1] = '\n'; /* eat the leftover space */ | |
4d1ae5fb | 1192 | |
bb1d9123 | 1193 | rtnl_unlock(); |
dec1e90e | 1194 | |
bb1d9123 AG |
1195 | return res; |
1196 | } | |
1197 | ||
1198 | /* | |
1199 | * Set the queue_ids of the slaves in the current bond. The bond | |
1200 | * interface must be enslaved for this to work. | |
1201 | */ | |
1202 | static ssize_t bonding_store_queue_id(struct device *d, | |
1203 | struct device_attribute *attr, | |
1204 | const char *buffer, size_t count) | |
1205 | { | |
1206 | struct slave *slave, *update_slave; | |
1207 | struct bonding *bond = to_bond(d); | |
9caff1e7 | 1208 | struct list_head *iter; |
bb1d9123 | 1209 | u16 qid; |
dec1e90e | 1210 | int ret = count; |
bb1d9123 AG |
1211 | char *delim; |
1212 | struct net_device *sdev = NULL; | |
1213 | ||
1214 | if (!rtnl_trylock()) | |
1215 | return restart_syscall(); | |
1216 | ||
1217 | /* delim will point to queue id if successful */ | |
1218 | delim = strchr(buffer, ':'); | |
1219 | if (!delim) | |
1220 | goto err_no_cmd; | |
1221 | ||
1222 | /* | |
1223 | * Terminate string that points to device name and bump it | |
1224 | * up one, so we can read the queue id there. | |
1225 | */ | |
1226 | *delim = '\0'; | |
1227 | if (sscanf(++delim, "%hd\n", &qid) != 1) | |
1228 | goto err_no_cmd; | |
1229 | ||
1230 | /* Check buffer length, valid ifname and queue id */ | |
1231 | if (strlen(buffer) > IFNAMSIZ || | |
1232 | !dev_valid_name(buffer) || | |
8a540ff9 | 1233 | qid > bond->dev->real_num_tx_queues) |
bb1d9123 AG |
1234 | goto err_no_cmd; |
1235 | ||
1236 | /* Get the pointer to that interface if it exists */ | |
1237 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); | |
1238 | if (!sdev) | |
1239 | goto err_no_cmd; | |
1240 | ||
bb1d9123 AG |
1241 | /* Search for thes slave and check for duplicate qids */ |
1242 | update_slave = NULL; | |
9caff1e7 | 1243 | bond_for_each_slave(bond, slave, iter) { |
bb1d9123 AG |
1244 | if (sdev == slave->dev) |
1245 | /* | |
1246 | * We don't need to check the matching | |
1247 | * slave for dups, since we're overwriting it | |
1248 | */ | |
1249 | update_slave = slave; | |
1250 | else if (qid && qid == slave->queue_id) { | |
4d1ae5fb | 1251 | goto err_no_cmd; |
bb1d9123 AG |
1252 | } |
1253 | } | |
1254 | ||
1255 | if (!update_slave) | |
4d1ae5fb | 1256 | goto err_no_cmd; |
bb1d9123 AG |
1257 | |
1258 | /* Actually set the qids for the slave */ | |
1259 | update_slave->queue_id = qid; | |
1260 | ||
bb1d9123 AG |
1261 | out: |
1262 | rtnl_unlock(); | |
1263 | return ret; | |
1264 | ||
bb1d9123 AG |
1265 | err_no_cmd: |
1266 | pr_info("invalid input for queue_id set for %s.\n", | |
1267 | bond->dev->name); | |
1268 | ret = -EPERM; | |
1269 | goto out; | |
1270 | } | |
1271 | ||
1272 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, | |
1273 | bonding_store_queue_id); | |
1274 | ||
1275 | ||
ebd8e497 AG |
1276 | /* |
1277 | * Show and set the all_slaves_active flag. | |
1278 | */ | |
1279 | static ssize_t bonding_show_slaves_active(struct device *d, | |
1280 | struct device_attribute *attr, | |
1281 | char *buf) | |
1282 | { | |
1283 | struct bonding *bond = to_bond(d); | |
1284 | ||
1285 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); | |
1286 | } | |
1287 | ||
1288 | static ssize_t bonding_store_slaves_active(struct device *d, | |
1289 | struct device_attribute *attr, | |
1290 | const char *buf, size_t count) | |
1291 | { | |
ebd8e497 | 1292 | struct bonding *bond = to_bond(d); |
dec1e90e | 1293 | int new_value, ret = count; |
9caff1e7 | 1294 | struct list_head *iter; |
ebd8e497 AG |
1295 | struct slave *slave; |
1296 | ||
4d1ae5fb | 1297 | if (!rtnl_trylock()) |
1298 | return restart_syscall(); | |
1299 | ||
ebd8e497 AG |
1300 | if (sscanf(buf, "%d", &new_value) != 1) { |
1301 | pr_err("%s: no all_slaves_active value specified.\n", | |
1302 | bond->dev->name); | |
1303 | ret = -EINVAL; | |
1304 | goto out; | |
1305 | } | |
1306 | ||
1307 | if (new_value == bond->params.all_slaves_active) | |
1308 | goto out; | |
1309 | ||
1310 | if ((new_value == 0) || (new_value == 1)) { | |
1311 | bond->params.all_slaves_active = new_value; | |
1312 | } else { | |
1313 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", | |
1314 | bond->dev->name, new_value); | |
1315 | ret = -EINVAL; | |
1316 | goto out; | |
1317 | } | |
b76cdba9 | 1318 | |
9caff1e7 | 1319 | bond_for_each_slave(bond, slave, iter) { |
e30bc066 | 1320 | if (!bond_is_active_slave(slave)) { |
ebd8e497 | 1321 | if (new_value) |
2d7011ca | 1322 | slave->inactive = 0; |
ebd8e497 | 1323 | else |
2d7011ca | 1324 | slave->inactive = 1; |
ebd8e497 AG |
1325 | } |
1326 | } | |
1327 | out: | |
4d1ae5fb | 1328 | rtnl_unlock(); |
672bda33 | 1329 | return ret; |
ebd8e497 AG |
1330 | } |
1331 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, | |
1332 | bonding_show_slaves_active, bonding_store_slaves_active); | |
b76cdba9 | 1333 | |
c2952c31 FL |
1334 | /* |
1335 | * Show and set the number of IGMP membership reports to send on link failure | |
1336 | */ | |
1337 | static ssize_t bonding_show_resend_igmp(struct device *d, | |
94265cf5 FL |
1338 | struct device_attribute *attr, |
1339 | char *buf) | |
c2952c31 FL |
1340 | { |
1341 | struct bonding *bond = to_bond(d); | |
1342 | ||
1343 | return sprintf(buf, "%d\n", bond->params.resend_igmp); | |
1344 | } | |
1345 | ||
1346 | static ssize_t bonding_store_resend_igmp(struct device *d, | |
94265cf5 FL |
1347 | struct device_attribute *attr, |
1348 | const char *buf, size_t count) | |
c2952c31 FL |
1349 | { |
1350 | int new_value, ret = count; | |
1351 | struct bonding *bond = to_bond(d); | |
1352 | ||
1353 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1354 | pr_err("%s: no resend_igmp value specified.\n", | |
1355 | bond->dev->name); | |
d8838de7 | 1356 | return -EINVAL; |
c2952c31 FL |
1357 | } |
1358 | ||
d8838de7 | 1359 | if (!rtnl_trylock()) |
1360 | return restart_syscall(); | |
c2952c31 | 1361 | |
d8838de7 | 1362 | ret = bond_option_resend_igmp_set(bond, new_value); |
1363 | if (!ret) | |
1364 | ret = count; | |
1365 | ||
1366 | rtnl_unlock(); | |
c2952c31 FL |
1367 | return ret; |
1368 | } | |
1369 | ||
1370 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, | |
1371 | bonding_show_resend_igmp, bonding_store_resend_igmp); | |
1372 | ||
7eacd038 NH |
1373 | |
1374 | static ssize_t bonding_show_lp_interval(struct device *d, | |
1375 | struct device_attribute *attr, | |
1376 | char *buf) | |
1377 | { | |
1378 | struct bonding *bond = to_bond(d); | |
1379 | return sprintf(buf, "%d\n", bond->params.lp_interval); | |
1380 | } | |
1381 | ||
1382 | static ssize_t bonding_store_lp_interval(struct device *d, | |
1383 | struct device_attribute *attr, | |
1384 | const char *buf, size_t count) | |
1385 | { | |
1386 | struct bonding *bond = to_bond(d); | |
1387 | int new_value, ret = count; | |
1388 | ||
1389 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1390 | pr_err("%s: no lp interval value specified.\n", | |
1391 | bond->dev->name); | |
1392 | ret = -EINVAL; | |
1393 | goto out; | |
1394 | } | |
1395 | ||
1396 | if (new_value <= 0) { | |
1397 | pr_err ("%s: lp_interval must be between 1 and %d\n", | |
1398 | bond->dev->name, INT_MAX); | |
1399 | ret = -EINVAL; | |
1400 | goto out; | |
1401 | } | |
1402 | ||
1403 | bond->params.lp_interval = new_value; | |
1404 | out: | |
1405 | return ret; | |
1406 | } | |
1407 | ||
1408 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, | |
1409 | bonding_show_lp_interval, bonding_store_lp_interval); | |
1410 | ||
73958329 NA |
1411 | static ssize_t bonding_show_packets_per_slave(struct device *d, |
1412 | struct device_attribute *attr, | |
1413 | char *buf) | |
1414 | { | |
1415 | struct bonding *bond = to_bond(d); | |
a752a8b9 | 1416 | unsigned int packets_per_slave = bond->params.packets_per_slave; |
73958329 NA |
1417 | |
1418 | if (packets_per_slave > 1) | |
1419 | packets_per_slave = reciprocal_value(packets_per_slave); | |
1420 | ||
a752a8b9 | 1421 | return sprintf(buf, "%u\n", packets_per_slave); |
73958329 NA |
1422 | } |
1423 | ||
1424 | static ssize_t bonding_store_packets_per_slave(struct device *d, | |
1425 | struct device_attribute *attr, | |
1426 | const char *buf, size_t count) | |
1427 | { | |
1428 | struct bonding *bond = to_bond(d); | |
1429 | int new_value, ret = count; | |
1430 | ||
1431 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1432 | pr_err("%s: no packets_per_slave value specified.\n", | |
1433 | bond->dev->name); | |
1434 | ret = -EINVAL; | |
1435 | goto out; | |
1436 | } | |
1437 | if (new_value < 0 || new_value > USHRT_MAX) { | |
1438 | pr_err("%s: packets_per_slave must be between 0 and %u\n", | |
1439 | bond->dev->name, USHRT_MAX); | |
1440 | ret = -EINVAL; | |
1441 | goto out; | |
1442 | } | |
1443 | if (bond->params.mode != BOND_MODE_ROUNDROBIN) | |
1444 | pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n", | |
1445 | bond->dev->name); | |
1446 | if (new_value > 1) | |
1447 | bond->params.packets_per_slave = reciprocal_value(new_value); | |
1448 | else | |
1449 | bond->params.packets_per_slave = new_value; | |
1450 | out: | |
1451 | return ret; | |
1452 | } | |
1453 | ||
1454 | static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR, | |
1455 | bonding_show_packets_per_slave, | |
1456 | bonding_store_packets_per_slave); | |
1457 | ||
b76cdba9 | 1458 | static struct attribute *per_bond_attrs[] = { |
43cb76d9 GKH |
1459 | &dev_attr_slaves.attr, |
1460 | &dev_attr_mode.attr, | |
dd957c57 | 1461 | &dev_attr_fail_over_mac.attr, |
43cb76d9 | 1462 | &dev_attr_arp_validate.attr, |
8599b52e | 1463 | &dev_attr_arp_all_targets.attr, |
43cb76d9 GKH |
1464 | &dev_attr_arp_interval.attr, |
1465 | &dev_attr_arp_ip_target.attr, | |
1466 | &dev_attr_downdelay.attr, | |
1467 | &dev_attr_updelay.attr, | |
1468 | &dev_attr_lacp_rate.attr, | |
fd989c83 | 1469 | &dev_attr_ad_select.attr, |
43cb76d9 | 1470 | &dev_attr_xmit_hash_policy.attr, |
ad246c99 BH |
1471 | &dev_attr_num_grat_arp.attr, |
1472 | &dev_attr_num_unsol_na.attr, | |
43cb76d9 GKH |
1473 | &dev_attr_miimon.attr, |
1474 | &dev_attr_primary.attr, | |
a549952a | 1475 | &dev_attr_primary_reselect.attr, |
43cb76d9 GKH |
1476 | &dev_attr_use_carrier.attr, |
1477 | &dev_attr_active_slave.attr, | |
1478 | &dev_attr_mii_status.attr, | |
1479 | &dev_attr_ad_aggregator.attr, | |
1480 | &dev_attr_ad_num_ports.attr, | |
1481 | &dev_attr_ad_actor_key.attr, | |
1482 | &dev_attr_ad_partner_key.attr, | |
1483 | &dev_attr_ad_partner_mac.attr, | |
bb1d9123 | 1484 | &dev_attr_queue_id.attr, |
ebd8e497 | 1485 | &dev_attr_all_slaves_active.attr, |
c2952c31 | 1486 | &dev_attr_resend_igmp.attr, |
655f8919 | 1487 | &dev_attr_min_links.attr, |
7eacd038 | 1488 | &dev_attr_lp_interval.attr, |
73958329 | 1489 | &dev_attr_packets_per_slave.attr, |
b76cdba9 MW |
1490 | NULL, |
1491 | }; | |
1492 | ||
1493 | static struct attribute_group bonding_group = { | |
1494 | .name = "bonding", | |
1495 | .attrs = per_bond_attrs, | |
1496 | }; | |
1497 | ||
1498 | /* | |
1499 | * Initialize sysfs. This sets up the bonding_masters file in | |
1500 | * /sys/class/net. | |
1501 | */ | |
4c22400a | 1502 | int bond_create_sysfs(struct bond_net *bn) |
b76cdba9 | 1503 | { |
b8a9787e | 1504 | int ret; |
b76cdba9 | 1505 | |
4c22400a | 1506 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
01718e36 | 1507 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
4c22400a | 1508 | |
58292cbe TH |
1509 | ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, |
1510 | bn->net); | |
877cbd36 JV |
1511 | /* |
1512 | * Permit multiple loads of the module by ignoring failures to | |
1513 | * create the bonding_masters sysfs file. Bonding devices | |
1514 | * created by second or subsequent loads of the module will | |
1515 | * not be listed in, or controllable by, bonding_masters, but | |
1516 | * will have the usual "bonding" sysfs directory. | |
1517 | * | |
1518 | * This is done to preserve backwards compatibility for | |
1519 | * initscripts/sysconfig, which load bonding multiple times to | |
1520 | * configure multiple bonding devices. | |
1521 | */ | |
1522 | if (ret == -EEXIST) { | |
38d2f38b | 1523 | /* Is someone being kinky and naming a device bonding_master? */ |
4c22400a | 1524 | if (__dev_get_by_name(bn->net, |
38d2f38b | 1525 | class_attr_bonding_masters.attr.name)) |
a4aee5c8 | 1526 | pr_err("network device named %s already exists in sysfs", |
38d2f38b | 1527 | class_attr_bonding_masters.attr.name); |
130aa61a | 1528 | ret = 0; |
877cbd36 | 1529 | } |
b76cdba9 MW |
1530 | |
1531 | return ret; | |
1532 | ||
1533 | } | |
1534 | ||
1535 | /* | |
1536 | * Remove /sys/class/net/bonding_masters. | |
1537 | */ | |
4c22400a | 1538 | void bond_destroy_sysfs(struct bond_net *bn) |
b76cdba9 | 1539 | { |
58292cbe | 1540 | netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); |
b76cdba9 MW |
1541 | } |
1542 | ||
1543 | /* | |
1544 | * Initialize sysfs for each bond. This sets up and registers | |
1545 | * the 'bondctl' directory for each individual bond under /sys/class/net. | |
1546 | */ | |
6151b3d4 | 1547 | void bond_prepare_sysfs_group(struct bonding *bond) |
b76cdba9 | 1548 | { |
6151b3d4 | 1549 | bond->dev->sysfs_groups[0] = &bonding_group; |
b76cdba9 MW |
1550 | } |
1551 |