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