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