Commit | Line | Data |
---|---|---|
b76cdba9 MW |
1 | |
2 | /* | |
3 | * Copyright(c) 2004-2005 Intel Corporation. All rights reserved. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License as published by the | |
7 | * Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 | * for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | * | |
19 | * The full GNU General Public License is included in this distribution in the | |
20 | * file called LICENSE. | |
21 | * | |
b76cdba9 MW |
22 | */ |
23 | #include <linux/config.h> | |
24 | #include <linux/kernel.h> | |
25 | #include <linux/module.h> | |
26 | #include <linux/sched.h> | |
27 | #include <linux/device.h> | |
28 | #include <linux/sysdev.h> | |
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> | |
36 | #include <linux/string.h> | |
37 | #include <linux/ctype.h> | |
38 | #include <linux/inet.h> | |
39 | #include <linux/rtnetlink.h> | |
40 | ||
41 | /* #define BONDING_DEBUG 1 */ | |
42 | #include "bonding.h" | |
43 | #define to_class_dev(obj) container_of(obj,struct class_device,kobj) | |
44 | #define to_net_dev(class) container_of(class, struct net_device, class_dev) | |
45 | #define to_bond(cd) ((struct bonding *)(to_net_dev(cd)->priv)) | |
46 | ||
47 | /*---------------------------- Declarations -------------------------------*/ | |
48 | ||
49 | ||
50 | extern struct list_head bond_dev_list; | |
51 | extern struct bond_params bonding_defaults; | |
52 | extern struct bond_parm_tbl bond_mode_tbl[]; | |
53 | extern struct bond_parm_tbl bond_lacp_tbl[]; | |
54 | extern struct bond_parm_tbl xmit_hashtype_tbl[]; | |
55 | ||
56 | static int expected_refcount = -1; | |
57 | static struct class *netdev_class; | |
58 | /*--------------------------- Data Structures -----------------------------*/ | |
59 | ||
60 | /* Bonding sysfs lock. Why can't we just use the subsytem lock? | |
61 | * Because kobject_register tries to acquire the subsystem lock. If | |
62 | * we already hold the lock (which we would if the user was creating | |
63 | * a new bond through the sysfs interface), we deadlock. | |
64 | * This lock is only needed when deleting a bond - we need to make sure | |
65 | * that we don't collide with an ongoing ioctl. | |
66 | */ | |
67 | ||
68 | struct rw_semaphore bonding_rwsem; | |
69 | ||
70 | ||
71 | ||
72 | ||
73 | /*------------------------------ Functions --------------------------------*/ | |
74 | ||
75 | /* | |
76 | * "show" function for the bond_masters attribute. | |
77 | * The class parameter is ignored. | |
78 | */ | |
79 | static ssize_t bonding_show_bonds(struct class *cls, char *buffer) | |
80 | { | |
81 | int res = 0; | |
82 | struct bonding *bond; | |
83 | ||
84 | down_read(&(bonding_rwsem)); | |
85 | ||
86 | list_for_each_entry(bond, &bond_dev_list, bond_list) { | |
87 | if (res > (PAGE_SIZE - IFNAMSIZ)) { | |
88 | /* not enough space for another interface name */ | |
89 | if ((PAGE_SIZE - res) > 10) | |
90 | res = PAGE_SIZE - 10; | |
91 | res += sprintf(buffer + res, "++more++"); | |
92 | break; | |
93 | } | |
94 | res += sprintf(buffer + res, "%s ", | |
95 | bond->dev->name); | |
96 | } | |
97 | res += sprintf(buffer + res, "\n"); | |
98 | res++; | |
99 | up_read(&(bonding_rwsem)); | |
100 | return res; | |
101 | } | |
102 | ||
103 | /* | |
104 | * "store" function for the bond_masters attribute. This is what | |
105 | * creates and deletes entire bonds. | |
106 | * | |
107 | * The class parameter is ignored. | |
108 | * | |
109 | */ | |
110 | ||
111 | static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t count) | |
112 | { | |
113 | char command[IFNAMSIZ + 1] = {0, }; | |
114 | char *ifname; | |
115 | int res = count; | |
116 | struct bonding *bond; | |
117 | struct bonding *nxt; | |
118 | ||
119 | down_write(&(bonding_rwsem)); | |
120 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ | |
121 | ifname = command + 1; | |
122 | if ((strlen(command) <= 1) || | |
123 | !dev_valid_name(ifname)) | |
124 | goto err_no_cmd; | |
125 | ||
126 | if (command[0] == '+') { | |
127 | ||
128 | /* Check to see if the bond already exists. */ | |
129 | list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) | |
130 | if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) { | |
131 | printk(KERN_ERR DRV_NAME | |
132 | ": cannot add bond %s; it already exists\n", | |
133 | ifname); | |
134 | res = -EPERM; | |
135 | goto out; | |
136 | } | |
137 | ||
138 | printk(KERN_INFO DRV_NAME | |
139 | ": %s is being created...\n", ifname); | |
140 | if (bond_create(ifname, &bonding_defaults, &bond)) { | |
141 | printk(KERN_INFO DRV_NAME | |
142 | ": %s interface already exists. Bond creation failed.\n", | |
143 | ifname); | |
144 | res = -EPERM; | |
145 | } | |
146 | goto out; | |
147 | } | |
148 | ||
149 | if (command[0] == '-') { | |
150 | list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) | |
151 | if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) { | |
152 | rtnl_lock(); | |
153 | /* check the ref count on the bond's kobject. | |
154 | * If it's > expected, then there's a file open, | |
155 | * and we have to fail. | |
156 | */ | |
157 | if (atomic_read(&bond->dev->class_dev.kobj.kref.refcount) | |
158 | > expected_refcount){ | |
159 | rtnl_unlock(); | |
160 | printk(KERN_INFO DRV_NAME | |
161 | ": Unable remove bond %s due to open references.\n", | |
162 | ifname); | |
163 | res = -EPERM; | |
164 | goto out; | |
165 | } | |
166 | printk(KERN_INFO DRV_NAME | |
167 | ": %s is being deleted...\n", | |
168 | bond->dev->name); | |
169 | unregister_netdevice(bond->dev); | |
170 | bond_deinit(bond->dev); | |
171 | bond_destroy_sysfs_entry(bond); | |
172 | rtnl_unlock(); | |
173 | goto out; | |
174 | } | |
175 | ||
176 | printk(KERN_ERR DRV_NAME | |
177 | ": unable to delete non-existent bond %s\n", ifname); | |
178 | res = -ENODEV; | |
179 | goto out; | |
180 | } | |
181 | ||
182 | err_no_cmd: | |
183 | printk(KERN_ERR DRV_NAME | |
184 | ": no command found in bonding_masters. Use +ifname or -ifname.\n"); | |
185 | res = -EPERM; | |
186 | ||
187 | /* Always return either count or an error. If you return 0, you'll | |
188 | * get called forever, which is bad. | |
189 | */ | |
190 | out: | |
191 | up_write(&(bonding_rwsem)); | |
192 | return res; | |
193 | } | |
194 | /* class attribute for bond_masters file. This ends up in /sys/class/net */ | |
195 | static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO, | |
196 | bonding_show_bonds, bonding_store_bonds); | |
197 | ||
198 | int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave) | |
199 | { | |
200 | char linkname[IFNAMSIZ+7]; | |
201 | int ret = 0; | |
202 | ||
203 | /* first, create a link from the slave back to the master */ | |
204 | ret = sysfs_create_link(&(slave->class_dev.kobj), &(master->class_dev.kobj), | |
205 | "master"); | |
206 | if (ret) | |
207 | return ret; | |
208 | /* next, create a link from the master to the slave */ | |
209 | sprintf(linkname,"slave_%s",slave->name); | |
210 | ret = sysfs_create_link(&(master->class_dev.kobj), &(slave->class_dev.kobj), | |
211 | linkname); | |
212 | return ret; | |
213 | ||
214 | } | |
215 | ||
216 | void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave) | |
217 | { | |
218 | char linkname[IFNAMSIZ+7]; | |
219 | ||
220 | sysfs_remove_link(&(slave->class_dev.kobj), "master"); | |
221 | sprintf(linkname,"slave_%s",slave->name); | |
222 | sysfs_remove_link(&(master->class_dev.kobj), linkname); | |
223 | } | |
224 | ||
225 | ||
226 | /* | |
227 | * Show the slaves in the current bond. | |
228 | */ | |
229 | static ssize_t bonding_show_slaves(struct class_device *cd, char *buf) | |
230 | { | |
231 | struct slave *slave; | |
232 | int i, res = 0; | |
233 | struct bonding *bond = to_bond(cd); | |
234 | ||
235 | read_lock_bh(&bond->lock); | |
236 | bond_for_each_slave(bond, slave, i) { | |
237 | if (res > (PAGE_SIZE - IFNAMSIZ)) { | |
238 | /* not enough space for another interface name */ | |
239 | if ((PAGE_SIZE - res) > 10) | |
240 | res = PAGE_SIZE - 10; | |
241 | res += sprintf(buf + res, "++more++"); | |
242 | break; | |
243 | } | |
244 | res += sprintf(buf + res, "%s ", slave->dev->name); | |
245 | } | |
246 | read_unlock_bh(&bond->lock); | |
247 | res += sprintf(buf + res, "\n"); | |
248 | res++; | |
249 | return res; | |
250 | } | |
251 | ||
252 | /* | |
253 | * Set the slaves in the current bond. The bond interface must be | |
254 | * up for this to succeed. | |
255 | * This function is largely the same flow as bonding_update_bonds(). | |
256 | */ | |
257 | static ssize_t bonding_store_slaves(struct class_device *cd, const char *buffer, size_t count) | |
258 | { | |
259 | char command[IFNAMSIZ + 1] = { 0, }; | |
260 | char *ifname; | |
261 | int i, res, found, ret = count; | |
262 | struct slave *slave; | |
3418db7c | 263 | struct net_device *dev = NULL; |
b76cdba9 MW |
264 | struct bonding *bond = to_bond(cd); |
265 | ||
266 | /* Quick sanity check -- is the bond interface up? */ | |
267 | if (!(bond->dev->flags & IFF_UP)) { | |
268 | printk(KERN_ERR DRV_NAME | |
269 | ": %s: Unable to update slaves because interface is down.\n", | |
270 | bond->dev->name); | |
271 | ret = -EPERM; | |
272 | goto out; | |
273 | } | |
274 | ||
275 | /* Note: We can't hold bond->lock here, as bond_create grabs it. */ | |
276 | ||
277 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ | |
278 | ifname = command + 1; | |
279 | if ((strlen(command) <= 1) || | |
280 | !dev_valid_name(ifname)) | |
281 | goto err_no_cmd; | |
282 | ||
283 | if (command[0] == '+') { | |
284 | ||
285 | /* Got a slave name in ifname. Is it already in the list? */ | |
286 | found = 0; | |
287 | read_lock_bh(&bond->lock); | |
288 | bond_for_each_slave(bond, slave, i) | |
289 | if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | |
290 | printk(KERN_ERR DRV_NAME | |
291 | ": %s: Interface %s is already enslaved!\n", | |
292 | bond->dev->name, ifname); | |
293 | ret = -EPERM; | |
294 | read_unlock_bh(&bond->lock); | |
295 | goto out; | |
296 | } | |
297 | ||
298 | read_unlock_bh(&bond->lock); | |
299 | printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n", | |
300 | bond->dev->name, ifname); | |
301 | dev = dev_get_by_name(ifname); | |
302 | if (!dev) { | |
303 | printk(KERN_INFO DRV_NAME | |
304 | ": %s: Interface %s does not exist!\n", | |
305 | bond->dev->name, ifname); | |
306 | ret = -EPERM; | |
307 | goto out; | |
308 | } | |
309 | else | |
310 | dev_put(dev); | |
311 | ||
312 | if (dev->flags & IFF_UP) { | |
313 | printk(KERN_ERR DRV_NAME | |
314 | ": %s: Error: Unable to enslave %s " | |
315 | "because it is already up.\n", | |
316 | bond->dev->name, dev->name); | |
317 | ret = -EPERM; | |
318 | goto out; | |
319 | } | |
320 | /* If this is the first slave, then we need to set | |
321 | the master's hardware address to be the same as the | |
322 | slave's. */ | |
323 | if (!(*((u32 *) & (bond->dev->dev_addr[0])))) { | |
324 | memcpy(bond->dev->dev_addr, dev->dev_addr, | |
325 | dev->addr_len); | |
326 | } | |
327 | ||
328 | /* Set the slave's MTU to match the bond */ | |
329 | if (dev->mtu != bond->dev->mtu) { | |
330 | if (dev->change_mtu) { | |
331 | res = dev->change_mtu(dev, | |
332 | bond->dev->mtu); | |
333 | if (res) { | |
334 | ret = res; | |
335 | goto out; | |
336 | } | |
337 | } else { | |
338 | dev->mtu = bond->dev->mtu; | |
339 | } | |
340 | } | |
341 | rtnl_lock(); | |
342 | res = bond_enslave(bond->dev, dev); | |
343 | rtnl_unlock(); | |
344 | if (res) { | |
345 | ret = res; | |
346 | } | |
347 | goto out; | |
348 | } | |
349 | ||
350 | if (command[0] == '-') { | |
351 | dev = NULL; | |
352 | bond_for_each_slave(bond, slave, i) | |
353 | if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { | |
354 | dev = slave->dev; | |
355 | break; | |
356 | } | |
357 | if (dev) { | |
358 | printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n", | |
359 | bond->dev->name, dev->name); | |
360 | rtnl_lock(); | |
361 | res = bond_release(bond->dev, dev); | |
362 | rtnl_unlock(); | |
363 | if (res) { | |
364 | ret = res; | |
365 | goto out; | |
366 | } | |
367 | /* set the slave MTU to the default */ | |
368 | if (dev->change_mtu) { | |
369 | dev->change_mtu(dev, 1500); | |
370 | } else { | |
371 | dev->mtu = 1500; | |
372 | } | |
373 | } | |
374 | else { | |
375 | printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n", | |
376 | ifname, bond->dev->name); | |
377 | ret = -ENODEV; | |
378 | } | |
379 | goto out; | |
380 | } | |
381 | ||
382 | err_no_cmd: | |
383 | printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name); | |
384 | ret = -EPERM; | |
385 | ||
386 | out: | |
387 | return ret; | |
388 | } | |
389 | ||
390 | static CLASS_DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves); | |
391 | ||
392 | /* | |
393 | * Show and set the bonding mode. The bond interface must be down to | |
394 | * change the mode. | |
395 | */ | |
396 | static ssize_t bonding_show_mode(struct class_device *cd, char *buf) | |
397 | { | |
398 | struct bonding *bond = to_bond(cd); | |
399 | ||
400 | return sprintf(buf, "%s %d\n", | |
401 | bond_mode_tbl[bond->params.mode].modename, | |
402 | bond->params.mode) + 1; | |
403 | } | |
404 | ||
405 | static ssize_t bonding_store_mode(struct class_device *cd, const char *buf, size_t count) | |
406 | { | |
407 | int new_value, ret = count; | |
408 | struct bonding *bond = to_bond(cd); | |
409 | ||
410 | if (bond->dev->flags & IFF_UP) { | |
411 | printk(KERN_ERR DRV_NAME | |
412 | ": unable to update mode of %s because interface is up.\n", | |
413 | bond->dev->name); | |
414 | ret = -EPERM; | |
415 | goto out; | |
416 | } | |
417 | ||
418 | new_value = bond_parse_parm((char *)buf, bond_mode_tbl); | |
419 | if (new_value < 0) { | |
420 | printk(KERN_ERR DRV_NAME | |
421 | ": %s: Ignoring invalid mode value %.*s.\n", | |
422 | bond->dev->name, | |
423 | (int)strlen(buf) - 1, buf); | |
424 | ret = -EINVAL; | |
425 | goto out; | |
426 | } else { | |
427 | bond->params.mode = new_value; | |
428 | bond_set_mode_ops(bond, bond->params.mode); | |
429 | printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n", | |
430 | bond->dev->name, bond_mode_tbl[new_value].modename, new_value); | |
431 | } | |
432 | out: | |
433 | return ret; | |
434 | } | |
435 | static CLASS_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode); | |
436 | ||
437 | /* | |
438 | * Show and set the bonding transmit hash method. The bond interface must be down to | |
439 | * change the xmit hash policy. | |
440 | */ | |
441 | static ssize_t bonding_show_xmit_hash(struct class_device *cd, char *buf) | |
442 | { | |
443 | int count; | |
444 | struct bonding *bond = to_bond(cd); | |
445 | ||
446 | if ((bond->params.mode != BOND_MODE_XOR) && | |
447 | (bond->params.mode != BOND_MODE_8023AD)) { | |
448 | // Not Applicable | |
449 | count = sprintf(buf, "NA\n") + 1; | |
450 | } else { | |
451 | count = sprintf(buf, "%s %d\n", | |
452 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, | |
453 | bond->params.xmit_policy) + 1; | |
454 | } | |
455 | ||
456 | return count; | |
457 | } | |
458 | ||
459 | static ssize_t bonding_store_xmit_hash(struct class_device *cd, const char *buf, size_t count) | |
460 | { | |
461 | int new_value, ret = count; | |
462 | struct bonding *bond = to_bond(cd); | |
463 | ||
464 | if (bond->dev->flags & IFF_UP) { | |
465 | printk(KERN_ERR DRV_NAME | |
466 | "%s: Interface is up. Unable to update xmit policy.\n", | |
467 | bond->dev->name); | |
468 | ret = -EPERM; | |
469 | goto out; | |
470 | } | |
471 | ||
472 | if ((bond->params.mode != BOND_MODE_XOR) && | |
473 | (bond->params.mode != BOND_MODE_8023AD)) { | |
474 | printk(KERN_ERR DRV_NAME | |
475 | "%s: Transmit hash policy is irrelevant in this mode.\n", | |
476 | bond->dev->name); | |
477 | ret = -EPERM; | |
478 | goto out; | |
479 | } | |
480 | ||
481 | new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl); | |
482 | if (new_value < 0) { | |
483 | printk(KERN_ERR DRV_NAME | |
484 | ": %s: Ignoring invalid xmit hash policy value %.*s.\n", | |
485 | bond->dev->name, | |
486 | (int)strlen(buf) - 1, buf); | |
487 | ret = -EINVAL; | |
488 | goto out; | |
489 | } else { | |
490 | bond->params.xmit_policy = new_value; | |
491 | bond_set_mode_ops(bond, bond->params.mode); | |
492 | printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n", | |
493 | bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value); | |
494 | } | |
495 | out: | |
496 | return ret; | |
497 | } | |
498 | static CLASS_DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash); | |
499 | ||
500 | /* | |
501 | * Show and set the arp timer interval. There are two tricky bits | |
502 | * here. First, if ARP monitoring is activated, then we must disable | |
503 | * MII monitoring. Second, if the ARP timer isn't running, we must | |
504 | * start it. | |
505 | */ | |
506 | static ssize_t bonding_show_arp_interval(struct class_device *cd, char *buf) | |
507 | { | |
508 | struct bonding *bond = to_bond(cd); | |
509 | ||
510 | return sprintf(buf, "%d\n", bond->params.arp_interval) + 1; | |
511 | } | |
512 | ||
513 | static ssize_t bonding_store_arp_interval(struct class_device *cd, const char *buf, size_t count) | |
514 | { | |
515 | int new_value, ret = count; | |
516 | struct bonding *bond = to_bond(cd); | |
517 | ||
518 | if (sscanf(buf, "%d", &new_value) != 1) { | |
519 | printk(KERN_ERR DRV_NAME | |
520 | ": %s: no arp_interval value specified.\n", | |
521 | bond->dev->name); | |
522 | ret = -EINVAL; | |
523 | goto out; | |
524 | } | |
525 | if (new_value < 0) { | |
526 | printk(KERN_ERR DRV_NAME | |
527 | ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n", | |
528 | bond->dev->name, new_value, INT_MAX); | |
529 | ret = -EINVAL; | |
530 | goto out; | |
531 | } | |
532 | ||
533 | printk(KERN_INFO DRV_NAME | |
534 | ": %s: Setting ARP monitoring interval to %d.\n", | |
535 | bond->dev->name, new_value); | |
536 | bond->params.arp_interval = new_value; | |
537 | if (bond->params.miimon) { | |
538 | printk(KERN_INFO DRV_NAME | |
539 | ": %s: ARP monitoring cannot be used with MII monitoring. " | |
540 | "%s Disabling MII monitoring.\n", | |
541 | bond->dev->name, bond->dev->name); | |
542 | bond->params.miimon = 0; | |
543 | /* Kill MII timer, else it brings bond's link down */ | |
544 | if (bond->arp_timer.function) { | |
545 | printk(KERN_INFO DRV_NAME | |
546 | ": %s: Kill MII timer, else it brings bond's link down...\n", | |
547 | bond->dev->name); | |
548 | del_timer_sync(&bond->mii_timer); | |
549 | } | |
550 | } | |
551 | if (!bond->params.arp_targets[0]) { | |
552 | printk(KERN_INFO DRV_NAME | |
553 | ": %s: ARP monitoring has been set up, " | |
554 | "but no ARP targets have been specified.\n", | |
555 | bond->dev->name); | |
556 | } | |
557 | if (bond->dev->flags & IFF_UP) { | |
558 | /* If the interface is up, we may need to fire off | |
559 | * the ARP timer. If the interface is down, the | |
560 | * timer will get fired off when the open function | |
561 | * is called. | |
562 | */ | |
563 | if (bond->arp_timer.function) { | |
564 | /* The timer's already set up, so fire it off */ | |
565 | mod_timer(&bond->arp_timer, jiffies + 1); | |
566 | } else { | |
567 | /* Set up the timer. */ | |
568 | init_timer(&bond->arp_timer); | |
569 | bond->arp_timer.expires = jiffies + 1; | |
570 | bond->arp_timer.data = | |
571 | (unsigned long) bond->dev; | |
572 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { | |
573 | bond->arp_timer.function = | |
574 | (void *) | |
575 | &bond_activebackup_arp_mon; | |
576 | } else { | |
577 | bond->arp_timer.function = | |
578 | (void *) | |
579 | &bond_loadbalance_arp_mon; | |
580 | } | |
581 | add_timer(&bond->arp_timer); | |
582 | } | |
583 | } | |
584 | ||
585 | out: | |
586 | return ret; | |
587 | } | |
588 | static CLASS_DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval); | |
589 | ||
590 | /* | |
591 | * Show and set the arp targets. | |
592 | */ | |
593 | static ssize_t bonding_show_arp_targets(struct class_device *cd, char *buf) | |
594 | { | |
595 | int i, res = 0; | |
596 | struct bonding *bond = to_bond(cd); | |
597 | ||
598 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { | |
599 | if (bond->params.arp_targets[i]) | |
600 | res += sprintf(buf + res, "%u.%u.%u.%u ", | |
601 | NIPQUAD(bond->params.arp_targets[i])); | |
602 | } | |
603 | if (res) | |
604 | res--; /* eat the leftover space */ | |
605 | res += sprintf(buf + res, "\n"); | |
606 | res++; | |
607 | return res; | |
608 | } | |
609 | ||
610 | static ssize_t bonding_store_arp_targets(struct class_device *cd, const char *buf, size_t count) | |
611 | { | |
612 | u32 newtarget; | |
613 | int i = 0, done = 0, ret = count; | |
614 | struct bonding *bond = to_bond(cd); | |
615 | u32 *targets; | |
616 | ||
617 | targets = bond->params.arp_targets; | |
618 | newtarget = in_aton(buf + 1); | |
619 | /* look for adds */ | |
620 | if (buf[0] == '+') { | |
621 | if ((newtarget == 0) || (newtarget == INADDR_BROADCAST)) { | |
622 | printk(KERN_ERR DRV_NAME | |
623 | ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n", | |
624 | bond->dev->name, NIPQUAD(newtarget)); | |
625 | ret = -EINVAL; | |
626 | goto out; | |
627 | } | |
628 | /* look for an empty slot to put the target in, and check for dupes */ | |
629 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { | |
630 | if (targets[i] == newtarget) { /* duplicate */ | |
631 | printk(KERN_ERR DRV_NAME | |
632 | ": %s: ARP target %u.%u.%u.%u is already present\n", | |
633 | bond->dev->name, NIPQUAD(newtarget)); | |
634 | if (done) | |
635 | targets[i] = 0; | |
636 | ret = -EINVAL; | |
637 | goto out; | |
638 | } | |
639 | if (targets[i] == 0 && !done) { | |
640 | printk(KERN_INFO DRV_NAME | |
641 | ": %s: adding ARP target %d.%d.%d.%d.\n", | |
642 | bond->dev->name, NIPQUAD(newtarget)); | |
643 | done = 1; | |
644 | targets[i] = newtarget; | |
645 | } | |
646 | } | |
647 | if (!done) { | |
648 | printk(KERN_ERR DRV_NAME | |
649 | ": %s: ARP target table is full!\n", | |
650 | bond->dev->name); | |
651 | ret = -EINVAL; | |
652 | goto out; | |
653 | } | |
654 | ||
655 | } | |
656 | else if (buf[0] == '-') { | |
657 | if ((newtarget == 0) || (newtarget == INADDR_BROADCAST)) { | |
658 | printk(KERN_ERR DRV_NAME | |
659 | ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n", | |
660 | bond->dev->name, NIPQUAD(newtarget)); | |
661 | ret = -EINVAL; | |
662 | goto out; | |
663 | } | |
664 | ||
665 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { | |
666 | if (targets[i] == newtarget) { | |
667 | printk(KERN_INFO DRV_NAME | |
668 | ": %s: removing ARP target %d.%d.%d.%d.\n", | |
669 | bond->dev->name, NIPQUAD(newtarget)); | |
670 | targets[i] = 0; | |
671 | done = 1; | |
672 | } | |
673 | } | |
674 | if (!done) { | |
675 | printk(KERN_INFO DRV_NAME | |
676 | ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n", | |
677 | bond->dev->name, NIPQUAD(newtarget)); | |
678 | ret = -EINVAL; | |
679 | goto out; | |
680 | } | |
681 | } | |
682 | else { | |
683 | printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", | |
684 | bond->dev->name); | |
685 | ret = -EPERM; | |
686 | goto out; | |
687 | } | |
688 | ||
689 | out: | |
690 | return ret; | |
691 | } | |
692 | static CLASS_DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); | |
693 | ||
694 | /* | |
695 | * Show and set the up and down delays. These must be multiples of the | |
696 | * MII monitoring value, and are stored internally as the multiplier. | |
697 | * Thus, we must translate to MS for the real world. | |
698 | */ | |
699 | static ssize_t bonding_show_downdelay(struct class_device *cd, char *buf) | |
700 | { | |
701 | struct bonding *bond = to_bond(cd); | |
702 | ||
703 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon) + 1; | |
704 | } | |
705 | ||
706 | static ssize_t bonding_store_downdelay(struct class_device *cd, const char *buf, size_t count) | |
707 | { | |
708 | int new_value, ret = count; | |
709 | struct bonding *bond = to_bond(cd); | |
710 | ||
711 | if (!(bond->params.miimon)) { | |
712 | printk(KERN_ERR DRV_NAME | |
713 | ": %s: Unable to set down delay as MII monitoring is disabled\n", | |
714 | bond->dev->name); | |
715 | ret = -EPERM; | |
716 | goto out; | |
717 | } | |
718 | ||
719 | if (sscanf(buf, "%d", &new_value) != 1) { | |
720 | printk(KERN_ERR DRV_NAME | |
721 | ": %s: no down delay value specified.\n", | |
722 | bond->dev->name); | |
723 | ret = -EINVAL; | |
724 | goto out; | |
725 | } | |
726 | if (new_value < 0) { | |
727 | printk(KERN_ERR DRV_NAME | |
728 | ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n", | |
729 | bond->dev->name, new_value, 1, INT_MAX); | |
730 | ret = -EINVAL; | |
731 | goto out; | |
732 | } else { | |
733 | if ((new_value % bond->params.miimon) != 0) { | |
734 | printk(KERN_WARNING DRV_NAME | |
735 | ": %s: Warning: down delay (%d) is not a multiple " | |
736 | "of miimon (%d), delay rounded to %d ms\n", | |
737 | bond->dev->name, new_value, bond->params.miimon, | |
738 | (new_value / bond->params.miimon) * | |
739 | bond->params.miimon); | |
740 | } | |
741 | bond->params.downdelay = new_value / bond->params.miimon; | |
742 | printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n", | |
743 | bond->dev->name, bond->params.downdelay * bond->params.miimon); | |
744 | ||
745 | } | |
746 | ||
747 | out: | |
748 | return ret; | |
749 | } | |
750 | static CLASS_DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay); | |
751 | ||
752 | static ssize_t bonding_show_updelay(struct class_device *cd, char *buf) | |
753 | { | |
754 | struct bonding *bond = to_bond(cd); | |
755 | ||
756 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon) + 1; | |
757 | ||
758 | } | |
759 | ||
760 | static ssize_t bonding_store_updelay(struct class_device *cd, const char *buf, size_t count) | |
761 | { | |
762 | int new_value, ret = count; | |
763 | struct bonding *bond = to_bond(cd); | |
764 | ||
765 | if (!(bond->params.miimon)) { | |
766 | printk(KERN_ERR DRV_NAME | |
767 | ": %s: Unable to set up delay as MII monitoring is disabled\n", | |
768 | bond->dev->name); | |
769 | ret = -EPERM; | |
770 | goto out; | |
771 | } | |
772 | ||
773 | if (sscanf(buf, "%d", &new_value) != 1) { | |
774 | printk(KERN_ERR DRV_NAME | |
775 | ": %s: no up delay value specified.\n", | |
776 | bond->dev->name); | |
777 | ret = -EINVAL; | |
778 | goto out; | |
779 | } | |
780 | if (new_value < 0) { | |
781 | printk(KERN_ERR DRV_NAME | |
782 | ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n", | |
783 | bond->dev->name, new_value, 1, INT_MAX); | |
784 | ret = -EINVAL; | |
785 | goto out; | |
786 | } else { | |
787 | if ((new_value % bond->params.miimon) != 0) { | |
788 | printk(KERN_WARNING DRV_NAME | |
789 | ": %s: Warning: up delay (%d) is not a multiple " | |
790 | "of miimon (%d), updelay rounded to %d ms\n", | |
791 | bond->dev->name, new_value, bond->params.miimon, | |
792 | (new_value / bond->params.miimon) * | |
793 | bond->params.miimon); | |
794 | } | |
795 | bond->params.updelay = new_value / bond->params.miimon; | |
796 | printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n", | |
797 | bond->dev->name, bond->params.updelay * bond->params.miimon); | |
798 | ||
799 | } | |
800 | ||
801 | out: | |
802 | return ret; | |
803 | } | |
804 | static CLASS_DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay); | |
805 | ||
806 | /* | |
807 | * Show and set the LACP interval. Interface must be down, and the mode | |
808 | * must be set to 802.3ad mode. | |
809 | */ | |
810 | static ssize_t bonding_show_lacp(struct class_device *cd, char *buf) | |
811 | { | |
812 | struct bonding *bond = to_bond(cd); | |
813 | ||
814 | return sprintf(buf, "%s %d\n", | |
815 | bond_lacp_tbl[bond->params.lacp_fast].modename, | |
816 | bond->params.lacp_fast) + 1; | |
817 | } | |
818 | ||
819 | static ssize_t bonding_store_lacp(struct class_device *cd, const char *buf, size_t count) | |
820 | { | |
821 | int new_value, ret = count; | |
822 | struct bonding *bond = to_bond(cd); | |
823 | ||
824 | if (bond->dev->flags & IFF_UP) { | |
825 | printk(KERN_ERR DRV_NAME | |
826 | ": %s: Unable to update LACP rate because interface is up.\n", | |
827 | bond->dev->name); | |
828 | ret = -EPERM; | |
829 | goto out; | |
830 | } | |
831 | ||
832 | if (bond->params.mode != BOND_MODE_8023AD) { | |
833 | printk(KERN_ERR DRV_NAME | |
834 | ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", | |
835 | bond->dev->name); | |
836 | ret = -EPERM; | |
837 | goto out; | |
838 | } | |
839 | ||
840 | new_value = bond_parse_parm((char *)buf, bond_lacp_tbl); | |
841 | ||
842 | if ((new_value == 1) || (new_value == 0)) { | |
843 | bond->params.lacp_fast = new_value; | |
844 | printk(KERN_INFO DRV_NAME | |
845 | ": %s: Setting LACP rate to %s (%d).\n", | |
846 | bond->dev->name, bond_lacp_tbl[new_value].modename, new_value); | |
847 | } else { | |
848 | printk(KERN_ERR DRV_NAME | |
849 | ": %s: Ignoring invalid LACP rate value %.*s.\n", | |
850 | bond->dev->name, (int)strlen(buf) - 1, buf); | |
851 | ret = -EINVAL; | |
852 | } | |
853 | out: | |
854 | return ret; | |
855 | } | |
856 | static CLASS_DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp); | |
857 | ||
858 | /* | |
859 | * Show and set the MII monitor interval. There are two tricky bits | |
860 | * here. First, if MII monitoring is activated, then we must disable | |
861 | * ARP monitoring. Second, if the timer isn't running, we must | |
862 | * start it. | |
863 | */ | |
864 | static ssize_t bonding_show_miimon(struct class_device *cd, char *buf) | |
865 | { | |
866 | struct bonding *bond = to_bond(cd); | |
867 | ||
868 | return sprintf(buf, "%d\n", bond->params.miimon) + 1; | |
869 | } | |
870 | ||
871 | static ssize_t bonding_store_miimon(struct class_device *cd, const char *buf, size_t count) | |
872 | { | |
873 | int new_value, ret = count; | |
874 | struct bonding *bond = to_bond(cd); | |
875 | ||
876 | if (sscanf(buf, "%d", &new_value) != 1) { | |
877 | printk(KERN_ERR DRV_NAME | |
878 | ": %s: no miimon value specified.\n", | |
879 | bond->dev->name); | |
880 | ret = -EINVAL; | |
881 | goto out; | |
882 | } | |
883 | if (new_value < 0) { | |
884 | printk(KERN_ERR DRV_NAME | |
885 | ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n", | |
886 | bond->dev->name, new_value, 1, INT_MAX); | |
887 | ret = -EINVAL; | |
888 | goto out; | |
889 | } else { | |
890 | printk(KERN_INFO DRV_NAME | |
891 | ": %s: Setting MII monitoring interval to %d.\n", | |
892 | bond->dev->name, new_value); | |
893 | bond->params.miimon = new_value; | |
894 | if(bond->params.updelay) | |
895 | printk(KERN_INFO DRV_NAME | |
896 | ": %s: Note: Updating updelay (to %d) " | |
897 | "since it is a multiple of the miimon value.\n", | |
898 | bond->dev->name, | |
899 | bond->params.updelay * bond->params.miimon); | |
900 | if(bond->params.downdelay) | |
901 | printk(KERN_INFO DRV_NAME | |
902 | ": %s: Note: Updating downdelay (to %d) " | |
903 | "since it is a multiple of the miimon value.\n", | |
904 | bond->dev->name, | |
905 | bond->params.downdelay * bond->params.miimon); | |
906 | if (bond->params.arp_interval) { | |
907 | printk(KERN_INFO DRV_NAME | |
908 | ": %s: MII monitoring cannot be used with " | |
909 | "ARP monitoring. Disabling ARP monitoring...\n", | |
910 | bond->dev->name); | |
911 | bond->params.arp_interval = 0; | |
912 | /* Kill ARP timer, else it brings bond's link down */ | |
913 | if (bond->mii_timer.function) { | |
914 | printk(KERN_INFO DRV_NAME | |
915 | ": %s: Kill ARP timer, else it brings bond's link down...\n", | |
916 | bond->dev->name); | |
917 | del_timer_sync(&bond->arp_timer); | |
918 | } | |
919 | } | |
920 | ||
921 | if (bond->dev->flags & IFF_UP) { | |
922 | /* If the interface is up, we may need to fire off | |
923 | * the MII timer. If the interface is down, the | |
924 | * timer will get fired off when the open function | |
925 | * is called. | |
926 | */ | |
927 | if (bond->mii_timer.function) { | |
928 | /* The timer's already set up, so fire it off */ | |
929 | mod_timer(&bond->mii_timer, jiffies + 1); | |
930 | } else { | |
931 | /* Set up the timer. */ | |
932 | init_timer(&bond->mii_timer); | |
933 | bond->mii_timer.expires = jiffies + 1; | |
934 | bond->mii_timer.data = | |
935 | (unsigned long) bond->dev; | |
936 | bond->mii_timer.function = | |
937 | (void *) &bond_mii_monitor; | |
938 | add_timer(&bond->mii_timer); | |
939 | } | |
940 | } | |
941 | } | |
942 | out: | |
943 | return ret; | |
944 | } | |
945 | static CLASS_DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon); | |
946 | ||
947 | /* | |
948 | * Show and set the primary slave. The store function is much | |
949 | * simpler than bonding_store_slaves function because it only needs to | |
950 | * handle one interface name. | |
951 | * The bond must be a mode that supports a primary for this be | |
952 | * set. | |
953 | */ | |
954 | static ssize_t bonding_show_primary(struct class_device *cd, char *buf) | |
955 | { | |
956 | int count = 0; | |
957 | struct bonding *bond = to_bond(cd); | |
958 | ||
959 | if (bond->primary_slave) | |
960 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name) + 1; | |
961 | else | |
962 | count = sprintf(buf, "\n") + 1; | |
963 | ||
964 | return count; | |
965 | } | |
966 | ||
967 | static ssize_t bonding_store_primary(struct class_device *cd, const char *buf, size_t count) | |
968 | { | |
969 | int i; | |
970 | struct slave *slave; | |
971 | struct bonding *bond = to_bond(cd); | |
972 | ||
973 | write_lock_bh(&bond->lock); | |
974 | if (!USES_PRIMARY(bond->params.mode)) { | |
975 | printk(KERN_INFO DRV_NAME | |
976 | ": %s: Unable to set primary slave; %s is in mode %d\n", | |
977 | bond->dev->name, bond->dev->name, bond->params.mode); | |
978 | } else { | |
979 | bond_for_each_slave(bond, slave, i) { | |
980 | if (strnicmp | |
981 | (slave->dev->name, buf, | |
982 | strlen(slave->dev->name)) == 0) { | |
983 | printk(KERN_INFO DRV_NAME | |
984 | ": %s: Setting %s as primary slave.\n", | |
985 | bond->dev->name, slave->dev->name); | |
986 | bond->primary_slave = slave; | |
987 | bond_select_active_slave(bond); | |
988 | goto out; | |
989 | } | |
990 | } | |
991 | ||
992 | /* if we got here, then we didn't match the name of any slave */ | |
993 | ||
994 | if (strlen(buf) == 0 || buf[0] == '\n') { | |
995 | printk(KERN_INFO DRV_NAME | |
996 | ": %s: Setting primary slave to None.\n", | |
997 | bond->dev->name); | |
3418db7c | 998 | bond->primary_slave = NULL; |
b76cdba9 MW |
999 | bond_select_active_slave(bond); |
1000 | } else { | |
1001 | printk(KERN_INFO DRV_NAME | |
1002 | ": %s: Unable to set %.*s as primary slave as it is not a slave.\n", | |
1003 | bond->dev->name, (int)strlen(buf) - 1, buf); | |
1004 | } | |
1005 | } | |
1006 | out: | |
1007 | write_unlock_bh(&bond->lock); | |
1008 | return count; | |
1009 | } | |
1010 | static CLASS_DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary); | |
1011 | ||
1012 | /* | |
1013 | * Show and set the use_carrier flag. | |
1014 | */ | |
1015 | static ssize_t bonding_show_carrier(struct class_device *cd, char *buf) | |
1016 | { | |
1017 | struct bonding *bond = to_bond(cd); | |
1018 | ||
1019 | return sprintf(buf, "%d\n", bond->params.use_carrier) + 1; | |
1020 | } | |
1021 | ||
1022 | static ssize_t bonding_store_carrier(struct class_device *cd, const char *buf, size_t count) | |
1023 | { | |
1024 | int new_value, ret = count; | |
1025 | struct bonding *bond = to_bond(cd); | |
1026 | ||
1027 | ||
1028 | if (sscanf(buf, "%d", &new_value) != 1) { | |
1029 | printk(KERN_ERR DRV_NAME | |
1030 | ": %s: no use_carrier value specified.\n", | |
1031 | bond->dev->name); | |
1032 | ret = -EINVAL; | |
1033 | goto out; | |
1034 | } | |
1035 | if ((new_value == 0) || (new_value == 1)) { | |
1036 | bond->params.use_carrier = new_value; | |
1037 | printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n", | |
1038 | bond->dev->name, new_value); | |
1039 | } else { | |
1040 | printk(KERN_INFO DRV_NAME | |
1041 | ": %s: Ignoring invalid use_carrier value %d.\n", | |
1042 | bond->dev->name, new_value); | |
1043 | } | |
1044 | out: | |
1045 | return count; | |
1046 | } | |
1047 | static CLASS_DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier); | |
1048 | ||
1049 | ||
1050 | /* | |
1051 | * Show and set currently active_slave. | |
1052 | */ | |
1053 | static ssize_t bonding_show_active_slave(struct class_device *cd, char *buf) | |
1054 | { | |
1055 | struct slave *curr; | |
1056 | struct bonding *bond = to_bond(cd); | |
1057 | int count; | |
1058 | ||
1059 | ||
1060 | read_lock(&bond->curr_slave_lock); | |
1061 | curr = bond->curr_active_slave; | |
1062 | read_unlock(&bond->curr_slave_lock); | |
1063 | ||
1064 | if (USES_PRIMARY(bond->params.mode) && curr) | |
1065 | count = sprintf(buf, "%s\n", curr->dev->name) + 1; | |
1066 | else | |
1067 | count = sprintf(buf, "\n") + 1; | |
1068 | return count; | |
1069 | } | |
1070 | ||
1071 | static ssize_t bonding_store_active_slave(struct class_device *cd, const char *buf, size_t count) | |
1072 | { | |
1073 | int i; | |
1074 | struct slave *slave; | |
1075 | struct slave *old_active = NULL; | |
1076 | struct slave *new_active = NULL; | |
1077 | struct bonding *bond = to_bond(cd); | |
1078 | ||
1079 | write_lock_bh(&bond->lock); | |
1080 | if (!USES_PRIMARY(bond->params.mode)) { | |
1081 | printk(KERN_INFO DRV_NAME | |
1082 | ": %s: Unable to change active slave; %s is in mode %d\n", | |
1083 | bond->dev->name, bond->dev->name, bond->params.mode); | |
1084 | } else { | |
1085 | bond_for_each_slave(bond, slave, i) { | |
1086 | if (strnicmp | |
1087 | (slave->dev->name, buf, | |
1088 | strlen(slave->dev->name)) == 0) { | |
1089 | old_active = bond->curr_active_slave; | |
1090 | new_active = slave; | |
1091 | if (new_active && (new_active == old_active)) { | |
1092 | /* do nothing */ | |
1093 | printk(KERN_INFO DRV_NAME | |
1094 | ": %s: %s is already the current active slave.\n", | |
1095 | bond->dev->name, slave->dev->name); | |
1096 | goto out; | |
1097 | } | |
1098 | else { | |
1099 | if ((new_active) && | |
1100 | (old_active) && | |
1101 | (new_active->link == BOND_LINK_UP) && | |
1102 | IS_UP(new_active->dev)) { | |
1103 | printk(KERN_INFO DRV_NAME | |
1104 | ": %s: Setting %s as active slave.\n", | |
1105 | bond->dev->name, slave->dev->name); | |
1106 | bond_change_active_slave(bond, new_active); | |
1107 | } | |
1108 | else { | |
1109 | printk(KERN_INFO DRV_NAME | |
1110 | ": %s: Could not set %s as active slave; " | |
1111 | "either %s is down or the link is down.\n", | |
1112 | bond->dev->name, slave->dev->name, | |
1113 | slave->dev->name); | |
1114 | } | |
1115 | goto out; | |
1116 | } | |
1117 | } | |
1118 | } | |
1119 | ||
1120 | /* if we got here, then we didn't match the name of any slave */ | |
1121 | ||
1122 | if (strlen(buf) == 0 || buf[0] == '\n') { | |
1123 | printk(KERN_INFO DRV_NAME | |
1124 | ": %s: Setting active slave to None.\n", | |
1125 | bond->dev->name); | |
3418db7c | 1126 | bond->primary_slave = NULL; |
b76cdba9 MW |
1127 | bond_select_active_slave(bond); |
1128 | } else { | |
1129 | printk(KERN_INFO DRV_NAME | |
1130 | ": %s: Unable to set %.*s as active slave as it is not a slave.\n", | |
1131 | bond->dev->name, (int)strlen(buf) - 1, buf); | |
1132 | } | |
1133 | } | |
1134 | out: | |
1135 | write_unlock_bh(&bond->lock); | |
1136 | return count; | |
1137 | ||
1138 | } | |
1139 | static CLASS_DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave); | |
1140 | ||
1141 | ||
1142 | /* | |
1143 | * Show link status of the bond interface. | |
1144 | */ | |
1145 | static ssize_t bonding_show_mii_status(struct class_device *cd, char *buf) | |
1146 | { | |
1147 | struct slave *curr; | |
1148 | struct bonding *bond = to_bond(cd); | |
1149 | ||
1150 | read_lock(&bond->curr_slave_lock); | |
1151 | curr = bond->curr_active_slave; | |
1152 | read_unlock(&bond->curr_slave_lock); | |
1153 | ||
1154 | return sprintf(buf, "%s\n", (curr) ? "up" : "down") + 1; | |
1155 | } | |
1156 | static CLASS_DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); | |
1157 | ||
1158 | ||
1159 | /* | |
1160 | * Show current 802.3ad aggregator ID. | |
1161 | */ | |
1162 | static ssize_t bonding_show_ad_aggregator(struct class_device *cd, char *buf) | |
1163 | { | |
1164 | int count = 0; | |
1165 | struct bonding *bond = to_bond(cd); | |
1166 | ||
1167 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1168 | struct ad_info ad_info; | |
1169 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id) + 1; | |
1170 | } | |
1171 | else | |
1172 | count = sprintf(buf, "\n") + 1; | |
1173 | ||
1174 | return count; | |
1175 | } | |
1176 | static CLASS_DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); | |
1177 | ||
1178 | ||
1179 | /* | |
1180 | * Show number of active 802.3ad ports. | |
1181 | */ | |
1182 | static ssize_t bonding_show_ad_num_ports(struct class_device *cd, char *buf) | |
1183 | { | |
1184 | int count = 0; | |
1185 | struct bonding *bond = to_bond(cd); | |
1186 | ||
1187 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1188 | struct ad_info ad_info; | |
1189 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports) + 1; | |
1190 | } | |
1191 | else | |
1192 | count = sprintf(buf, "\n") + 1; | |
1193 | ||
1194 | return count; | |
1195 | } | |
1196 | static CLASS_DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); | |
1197 | ||
1198 | ||
1199 | /* | |
1200 | * Show current 802.3ad actor key. | |
1201 | */ | |
1202 | static ssize_t bonding_show_ad_actor_key(struct class_device *cd, char *buf) | |
1203 | { | |
1204 | int count = 0; | |
1205 | struct bonding *bond = to_bond(cd); | |
1206 | ||
1207 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1208 | struct ad_info ad_info; | |
1209 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key) + 1; | |
1210 | } | |
1211 | else | |
1212 | count = sprintf(buf, "\n") + 1; | |
1213 | ||
1214 | return count; | |
1215 | } | |
1216 | static CLASS_DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); | |
1217 | ||
1218 | ||
1219 | /* | |
1220 | * Show current 802.3ad partner key. | |
1221 | */ | |
1222 | static ssize_t bonding_show_ad_partner_key(struct class_device *cd, char *buf) | |
1223 | { | |
1224 | int count = 0; | |
1225 | struct bonding *bond = to_bond(cd); | |
1226 | ||
1227 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1228 | struct ad_info ad_info; | |
1229 | count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key) + 1; | |
1230 | } | |
1231 | else | |
1232 | count = sprintf(buf, "\n") + 1; | |
1233 | ||
1234 | return count; | |
1235 | } | |
1236 | static CLASS_DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); | |
1237 | ||
1238 | ||
1239 | /* | |
1240 | * Show current 802.3ad partner mac. | |
1241 | */ | |
1242 | static ssize_t bonding_show_ad_partner_mac(struct class_device *cd, char *buf) | |
1243 | { | |
1244 | int count = 0; | |
1245 | struct bonding *bond = to_bond(cd); | |
1246 | ||
1247 | if (bond->params.mode == BOND_MODE_8023AD) { | |
1248 | struct ad_info ad_info; | |
1249 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) { | |
1250 | count = sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x\n", | |
1251 | ad_info.partner_system[0], | |
1252 | ad_info.partner_system[1], | |
1253 | ad_info.partner_system[2], | |
1254 | ad_info.partner_system[3], | |
1255 | ad_info.partner_system[4], | |
1256 | ad_info.partner_system[5]) + 1; | |
1257 | } | |
1258 | } | |
1259 | else | |
1260 | count = sprintf(buf, "\n") + 1; | |
1261 | ||
1262 | return count; | |
1263 | } | |
1264 | static CLASS_DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); | |
1265 | ||
1266 | ||
1267 | ||
1268 | static struct attribute *per_bond_attrs[] = { | |
1269 | &class_device_attr_slaves.attr, | |
1270 | &class_device_attr_mode.attr, | |
1271 | &class_device_attr_arp_interval.attr, | |
1272 | &class_device_attr_arp_ip_target.attr, | |
1273 | &class_device_attr_downdelay.attr, | |
1274 | &class_device_attr_updelay.attr, | |
1275 | &class_device_attr_lacp_rate.attr, | |
1276 | &class_device_attr_xmit_hash_policy.attr, | |
1277 | &class_device_attr_miimon.attr, | |
1278 | &class_device_attr_primary.attr, | |
1279 | &class_device_attr_use_carrier.attr, | |
1280 | &class_device_attr_active_slave.attr, | |
1281 | &class_device_attr_mii_status.attr, | |
1282 | &class_device_attr_ad_aggregator.attr, | |
1283 | &class_device_attr_ad_num_ports.attr, | |
1284 | &class_device_attr_ad_actor_key.attr, | |
1285 | &class_device_attr_ad_partner_key.attr, | |
1286 | &class_device_attr_ad_partner_mac.attr, | |
1287 | NULL, | |
1288 | }; | |
1289 | ||
1290 | static struct attribute_group bonding_group = { | |
1291 | .name = "bonding", | |
1292 | .attrs = per_bond_attrs, | |
1293 | }; | |
1294 | ||
1295 | /* | |
1296 | * Initialize sysfs. This sets up the bonding_masters file in | |
1297 | * /sys/class/net. | |
1298 | */ | |
1299 | int bond_create_sysfs(void) | |
1300 | { | |
1301 | int ret = 0; | |
1302 | struct bonding *firstbond; | |
1303 | ||
1304 | init_rwsem(&bonding_rwsem); | |
1305 | ||
1306 | /* get the netdev class pointer */ | |
1307 | firstbond = container_of(bond_dev_list.next, struct bonding, bond_list); | |
1308 | if (!firstbond) | |
1309 | return -ENODEV; | |
1310 | ||
1311 | netdev_class = firstbond->dev->class_dev.class; | |
1312 | if (!netdev_class) | |
1313 | return -ENODEV; | |
1314 | ||
1315 | ret = class_create_file(netdev_class, &class_attr_bonding_masters); | |
1316 | ||
1317 | return ret; | |
1318 | ||
1319 | } | |
1320 | ||
1321 | /* | |
1322 | * Remove /sys/class/net/bonding_masters. | |
1323 | */ | |
1324 | void bond_destroy_sysfs(void) | |
1325 | { | |
1326 | if (netdev_class) | |
1327 | class_remove_file(netdev_class, &class_attr_bonding_masters); | |
1328 | } | |
1329 | ||
1330 | /* | |
1331 | * Initialize sysfs for each bond. This sets up and registers | |
1332 | * the 'bondctl' directory for each individual bond under /sys/class/net. | |
1333 | */ | |
1334 | int bond_create_sysfs_entry(struct bonding *bond) | |
1335 | { | |
1336 | struct net_device *dev = bond->dev; | |
1337 | int err; | |
1338 | ||
1339 | err = sysfs_create_group(&(dev->class_dev.kobj), &bonding_group); | |
1340 | if (err) { | |
1341 | printk(KERN_EMERG "eek! didn't create group!\n"); | |
1342 | } | |
1343 | ||
1344 | if (expected_refcount < 1) | |
1345 | expected_refcount = atomic_read(&bond->dev->class_dev.kobj.kref.refcount); | |
1346 | ||
1347 | return err; | |
1348 | } | |
1349 | /* | |
1350 | * Remove sysfs entries for each bond. | |
1351 | */ | |
1352 | void bond_destroy_sysfs_entry(struct bonding *bond) | |
1353 | { | |
1354 | struct net_device *dev = bond->dev; | |
1355 | ||
1356 | sysfs_remove_group(&(dev->class_dev.kobj), &bonding_group); | |
1357 | } | |
1358 |