xref: /openbmc/linux/drivers/net/bonding/bond_sysfs.c (revision 275876e2)
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, see <http://www.gnu.org/licenses/>.
16  *
17  * The full GNU General Public License is included in this distribution in the
18  * file called LICENSE.
19  *
20  */
21 
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/device.h>
27 #include <linux/sched.h>
28 #include <linux/fs.h>
29 #include <linux/types.h>
30 #include <linux/string.h>
31 #include <linux/netdevice.h>
32 #include <linux/inetdevice.h>
33 #include <linux/in.h>
34 #include <linux/sysfs.h>
35 #include <linux/ctype.h>
36 #include <linux/inet.h>
37 #include <linux/rtnetlink.h>
38 #include <linux/etherdevice.h>
39 #include <net/net_namespace.h>
40 #include <net/netns/generic.h>
41 #include <linux/nsproxy.h>
42 
43 #include "bonding.h"
44 
45 #define to_dev(obj)	container_of(obj, struct device, kobj)
46 #define to_bond(cd)	((struct bonding *)(netdev_priv(to_net_dev(cd))))
47 
48 /* "show" function for the bond_masters attribute.
49  * The class parameter is ignored.
50  */
51 static ssize_t bonding_show_bonds(struct class *cls,
52 				  struct class_attribute *attr,
53 				  char *buf)
54 {
55 	struct bond_net *bn =
56 		container_of(attr, struct bond_net, class_attr_bonding_masters);
57 	int res = 0;
58 	struct bonding *bond;
59 
60 	rtnl_lock();
61 
62 	list_for_each_entry(bond, &bn->dev_list, bond_list) {
63 		if (res > (PAGE_SIZE - IFNAMSIZ)) {
64 			/* not enough space for another interface name */
65 			if ((PAGE_SIZE - res) > 10)
66 				res = PAGE_SIZE - 10;
67 			res += sprintf(buf + res, "++more++ ");
68 			break;
69 		}
70 		res += sprintf(buf + res, "%s ", bond->dev->name);
71 	}
72 	if (res)
73 		buf[res-1] = '\n'; /* eat the leftover space */
74 
75 	rtnl_unlock();
76 	return res;
77 }
78 
79 static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
80 {
81 	struct bonding *bond;
82 
83 	list_for_each_entry(bond, &bn->dev_list, bond_list) {
84 		if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
85 			return bond->dev;
86 	}
87 	return NULL;
88 }
89 
90 /* "store" function for the bond_masters attribute.  This is what
91  * creates and deletes entire bonds.
92  *
93  * The class parameter is ignored.
94  *
95  */
96 static ssize_t bonding_store_bonds(struct class *cls,
97 				   struct class_attribute *attr,
98 				   const char *buffer, size_t count)
99 {
100 	struct bond_net *bn =
101 		container_of(attr, struct bond_net, class_attr_bonding_masters);
102 	char command[IFNAMSIZ + 1] = {0, };
103 	char *ifname;
104 	int rv, res = count;
105 
106 	sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
107 	ifname = command + 1;
108 	if ((strlen(command) <= 1) ||
109 	    !dev_valid_name(ifname))
110 		goto err_no_cmd;
111 
112 	if (command[0] == '+') {
113 		pr_info("%s is being created...\n", ifname);
114 		rv = bond_create(bn->net, ifname);
115 		if (rv) {
116 			if (rv == -EEXIST)
117 				pr_info("%s already exists\n", ifname);
118 			else
119 				pr_info("%s creation failed\n", ifname);
120 			res = rv;
121 		}
122 	} else if (command[0] == '-') {
123 		struct net_device *bond_dev;
124 
125 		rtnl_lock();
126 		bond_dev = bond_get_by_name(bn, ifname);
127 		if (bond_dev) {
128 			pr_info("%s is being deleted...\n", ifname);
129 			unregister_netdevice(bond_dev);
130 		} else {
131 			pr_err("unable to delete non-existent %s\n", ifname);
132 			res = -ENODEV;
133 		}
134 		rtnl_unlock();
135 	} else
136 		goto err_no_cmd;
137 
138 	/* Always return either count or an error.  If you return 0, you'll
139 	 * get called forever, which is bad.
140 	 */
141 	return res;
142 
143 err_no_cmd:
144 	pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
145 	return -EPERM;
146 }
147 
148 /* class attribute for bond_masters file.  This ends up in /sys/class/net */
149 static const struct class_attribute class_attr_bonding_masters = {
150 	.attr = {
151 		.name = "bonding_masters",
152 		.mode = S_IWUSR | S_IRUGO,
153 	},
154 	.show = bonding_show_bonds,
155 	.store = bonding_store_bonds,
156 };
157 
158 /* Generic "store" method for bonding sysfs option setting */
159 static ssize_t bonding_sysfs_store_option(struct device *d,
160 					  struct device_attribute *attr,
161 					  const char *buffer, size_t count)
162 {
163 	struct bonding *bond = to_bond(d);
164 	const struct bond_option *opt;
165 	int ret;
166 
167 	opt = bond_opt_get_by_name(attr->attr.name);
168 	if (WARN_ON(!opt))
169 		return -ENOENT;
170 	ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer);
171 	if (!ret)
172 		ret = count;
173 
174 	return ret;
175 }
176 
177 /* Show the slaves in the current bond. */
178 static ssize_t bonding_show_slaves(struct device *d,
179 				   struct device_attribute *attr, char *buf)
180 {
181 	struct bonding *bond = to_bond(d);
182 	struct list_head *iter;
183 	struct slave *slave;
184 	int res = 0;
185 
186 	if (!rtnl_trylock())
187 		return restart_syscall();
188 
189 	bond_for_each_slave(bond, slave, iter) {
190 		if (res > (PAGE_SIZE - IFNAMSIZ)) {
191 			/* not enough space for another interface name */
192 			if ((PAGE_SIZE - res) > 10)
193 				res = PAGE_SIZE - 10;
194 			res += sprintf(buf + res, "++more++ ");
195 			break;
196 		}
197 		res += sprintf(buf + res, "%s ", slave->dev->name);
198 	}
199 
200 	rtnl_unlock();
201 
202 	if (res)
203 		buf[res-1] = '\n'; /* eat the leftover space */
204 
205 	return res;
206 }
207 static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
208 		   bonding_sysfs_store_option);
209 
210 /* Show the bonding mode. */
211 static ssize_t bonding_show_mode(struct device *d,
212 				 struct device_attribute *attr, char *buf)
213 {
214 	struct bonding *bond = to_bond(d);
215 	const struct bond_opt_value *val;
216 
217 	val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond));
218 
219 	return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond));
220 }
221 static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
222 		   bonding_show_mode, bonding_sysfs_store_option);
223 
224 /* Show the bonding transmit hash method. */
225 static ssize_t bonding_show_xmit_hash(struct device *d,
226 				      struct device_attribute *attr,
227 				      char *buf)
228 {
229 	struct bonding *bond = to_bond(d);
230 	const struct bond_opt_value *val;
231 
232 	val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
233 
234 	return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
235 }
236 static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
237 		   bonding_show_xmit_hash, bonding_sysfs_store_option);
238 
239 /* Show arp_validate. */
240 static ssize_t bonding_show_arp_validate(struct device *d,
241 					 struct device_attribute *attr,
242 					 char *buf)
243 {
244 	struct bonding *bond = to_bond(d);
245 	const struct bond_opt_value *val;
246 
247 	val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
248 			       bond->params.arp_validate);
249 
250 	return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
251 }
252 static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
253 		   bonding_sysfs_store_option);
254 
255 /* Show arp_all_targets. */
256 static ssize_t bonding_show_arp_all_targets(struct device *d,
257 					 struct device_attribute *attr,
258 					 char *buf)
259 {
260 	struct bonding *bond = to_bond(d);
261 	const struct bond_opt_value *val;
262 
263 	val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
264 			       bond->params.arp_all_targets);
265 	return sprintf(buf, "%s %d\n",
266 		       val->string, bond->params.arp_all_targets);
267 }
268 static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
269 		   bonding_show_arp_all_targets, bonding_sysfs_store_option);
270 
271 /* Show fail_over_mac. */
272 static ssize_t bonding_show_fail_over_mac(struct device *d,
273 					  struct device_attribute *attr,
274 					  char *buf)
275 {
276 	struct bonding *bond = to_bond(d);
277 	const struct bond_opt_value *val;
278 
279 	val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
280 			       bond->params.fail_over_mac);
281 
282 	return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
283 }
284 static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
285 		   bonding_show_fail_over_mac, bonding_sysfs_store_option);
286 
287 /* Show the arp timer interval. */
288 static ssize_t bonding_show_arp_interval(struct device *d,
289 					 struct device_attribute *attr,
290 					 char *buf)
291 {
292 	struct bonding *bond = to_bond(d);
293 
294 	return sprintf(buf, "%d\n", bond->params.arp_interval);
295 }
296 static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
297 		   bonding_show_arp_interval, bonding_sysfs_store_option);
298 
299 /* Show the arp targets. */
300 static ssize_t bonding_show_arp_targets(struct device *d,
301 					struct device_attribute *attr,
302 					char *buf)
303 {
304 	struct bonding *bond = to_bond(d);
305 	int i, res = 0;
306 
307 	for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
308 		if (bond->params.arp_targets[i])
309 			res += sprintf(buf + res, "%pI4 ",
310 				       &bond->params.arp_targets[i]);
311 	}
312 	if (res)
313 		buf[res-1] = '\n'; /* eat the leftover space */
314 
315 	return res;
316 }
317 static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR,
318 		   bonding_show_arp_targets, bonding_sysfs_store_option);
319 
320 /* Show the up and down delays. */
321 static ssize_t bonding_show_downdelay(struct device *d,
322 				      struct device_attribute *attr,
323 				      char *buf)
324 {
325 	struct bonding *bond = to_bond(d);
326 
327 	return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
328 }
329 static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
330 		   bonding_show_downdelay, bonding_sysfs_store_option);
331 
332 static ssize_t bonding_show_updelay(struct device *d,
333 				    struct device_attribute *attr,
334 				    char *buf)
335 {
336 	struct bonding *bond = to_bond(d);
337 
338 	return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
339 
340 }
341 static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
342 		   bonding_show_updelay, bonding_sysfs_store_option);
343 
344 /* Show the LACP interval. */
345 static ssize_t bonding_show_lacp(struct device *d,
346 				 struct device_attribute *attr,
347 				 char *buf)
348 {
349 	struct bonding *bond = to_bond(d);
350 	const struct bond_opt_value *val;
351 
352 	val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
353 
354 	return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
355 }
356 static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
357 		   bonding_show_lacp, bonding_sysfs_store_option);
358 
359 static ssize_t bonding_show_min_links(struct device *d,
360 				      struct device_attribute *attr,
361 				      char *buf)
362 {
363 	struct bonding *bond = to_bond(d);
364 
365 	return sprintf(buf, "%u\n", bond->params.min_links);
366 }
367 static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
368 		   bonding_show_min_links, bonding_sysfs_store_option);
369 
370 static ssize_t bonding_show_ad_select(struct device *d,
371 				      struct device_attribute *attr,
372 				      char *buf)
373 {
374 	struct bonding *bond = to_bond(d);
375 	const struct bond_opt_value *val;
376 
377 	val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
378 
379 	return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
380 }
381 static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
382 		   bonding_show_ad_select, bonding_sysfs_store_option);
383 
384 /* Show and set the number of peer notifications to send after a failover event. */
385 static ssize_t bonding_show_num_peer_notif(struct device *d,
386 					   struct device_attribute *attr,
387 					   char *buf)
388 {
389 	struct bonding *bond = to_bond(d);
390 	return sprintf(buf, "%d\n", bond->params.num_peer_notif);
391 }
392 
393 static ssize_t bonding_store_num_peer_notif(struct device *d,
394 					    struct device_attribute *attr,
395 					    const char *buf, size_t count)
396 {
397 	struct bonding *bond = to_bond(d);
398 	int ret;
399 
400 	ret = bond_opt_tryset_rtnl(bond, BOND_OPT_NUM_PEER_NOTIF, (char *)buf);
401 	if (!ret)
402 		ret = count;
403 
404 	return ret;
405 }
406 static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
407 		   bonding_show_num_peer_notif, bonding_store_num_peer_notif);
408 static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
409 		   bonding_show_num_peer_notif, bonding_store_num_peer_notif);
410 
411 /* Show the MII monitor interval. */
412 static ssize_t bonding_show_miimon(struct device *d,
413 				   struct device_attribute *attr,
414 				   char *buf)
415 {
416 	struct bonding *bond = to_bond(d);
417 
418 	return sprintf(buf, "%d\n", bond->params.miimon);
419 }
420 static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
421 		   bonding_show_miimon, bonding_sysfs_store_option);
422 
423 /* Show the primary slave. */
424 static ssize_t bonding_show_primary(struct device *d,
425 				    struct device_attribute *attr,
426 				    char *buf)
427 {
428 	int count = 0;
429 	struct bonding *bond = to_bond(d);
430 
431 	if (bond->primary_slave)
432 		count = sprintf(buf, "%s\n", bond->primary_slave->dev->name);
433 
434 	return count;
435 }
436 static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
437 		   bonding_show_primary, bonding_sysfs_store_option);
438 
439 /* Show the primary_reselect flag. */
440 static ssize_t bonding_show_primary_reselect(struct device *d,
441 					     struct device_attribute *attr,
442 					     char *buf)
443 {
444 	struct bonding *bond = to_bond(d);
445 	const struct bond_opt_value *val;
446 
447 	val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
448 			       bond->params.primary_reselect);
449 
450 	return sprintf(buf, "%s %d\n",
451 		       val->string, bond->params.primary_reselect);
452 }
453 static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
454 		   bonding_show_primary_reselect, bonding_sysfs_store_option);
455 
456 /* Show the use_carrier flag. */
457 static ssize_t bonding_show_carrier(struct device *d,
458 				    struct device_attribute *attr,
459 				    char *buf)
460 {
461 	struct bonding *bond = to_bond(d);
462 
463 	return sprintf(buf, "%d\n", bond->params.use_carrier);
464 }
465 static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
466 		   bonding_show_carrier, bonding_sysfs_store_option);
467 
468 
469 /* Show currently active_slave. */
470 static ssize_t bonding_show_active_slave(struct device *d,
471 					 struct device_attribute *attr,
472 					 char *buf)
473 {
474 	struct bonding *bond = to_bond(d);
475 	struct net_device *slave_dev;
476 	int count = 0;
477 
478 	rcu_read_lock();
479 	slave_dev = bond_option_active_slave_get_rcu(bond);
480 	if (slave_dev)
481 		count = sprintf(buf, "%s\n", slave_dev->name);
482 	rcu_read_unlock();
483 
484 	return count;
485 }
486 static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
487 		   bonding_show_active_slave, bonding_sysfs_store_option);
488 
489 /* Show link status of the bond interface. */
490 static ssize_t bonding_show_mii_status(struct device *d,
491 				       struct device_attribute *attr,
492 				       char *buf)
493 {
494 	struct bonding *bond = to_bond(d);
495 	bool active = !!rcu_access_pointer(bond->curr_active_slave);
496 
497 	return sprintf(buf, "%s\n", active ? "up" : "down");
498 }
499 static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
500 
501 /* Show current 802.3ad aggregator ID. */
502 static ssize_t bonding_show_ad_aggregator(struct device *d,
503 					  struct device_attribute *attr,
504 					  char *buf)
505 {
506 	int count = 0;
507 	struct bonding *bond = to_bond(d);
508 
509 	if (BOND_MODE(bond) == BOND_MODE_8023AD) {
510 		struct ad_info ad_info;
511 		count = sprintf(buf, "%d\n",
512 				bond_3ad_get_active_agg_info(bond, &ad_info)
513 				?  0 : ad_info.aggregator_id);
514 	}
515 
516 	return count;
517 }
518 static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
519 
520 
521 /* Show number of active 802.3ad ports. */
522 static ssize_t bonding_show_ad_num_ports(struct device *d,
523 					 struct device_attribute *attr,
524 					 char *buf)
525 {
526 	int count = 0;
527 	struct bonding *bond = to_bond(d);
528 
529 	if (BOND_MODE(bond) == BOND_MODE_8023AD) {
530 		struct ad_info ad_info;
531 		count = sprintf(buf, "%d\n",
532 				bond_3ad_get_active_agg_info(bond, &ad_info)
533 				?  0 : ad_info.ports);
534 	}
535 
536 	return count;
537 }
538 static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
539 
540 
541 /* Show current 802.3ad actor key. */
542 static ssize_t bonding_show_ad_actor_key(struct device *d,
543 					 struct device_attribute *attr,
544 					 char *buf)
545 {
546 	int count = 0;
547 	struct bonding *bond = to_bond(d);
548 
549 	if (BOND_MODE(bond) == BOND_MODE_8023AD) {
550 		struct ad_info ad_info;
551 		count = sprintf(buf, "%d\n",
552 				bond_3ad_get_active_agg_info(bond, &ad_info)
553 				?  0 : ad_info.actor_key);
554 	}
555 
556 	return count;
557 }
558 static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
559 
560 
561 /* Show current 802.3ad partner key. */
562 static ssize_t bonding_show_ad_partner_key(struct device *d,
563 					   struct device_attribute *attr,
564 					   char *buf)
565 {
566 	int count = 0;
567 	struct bonding *bond = to_bond(d);
568 
569 	if (BOND_MODE(bond) == BOND_MODE_8023AD) {
570 		struct ad_info ad_info;
571 		count = sprintf(buf, "%d\n",
572 				bond_3ad_get_active_agg_info(bond, &ad_info)
573 				?  0 : ad_info.partner_key);
574 	}
575 
576 	return count;
577 }
578 static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
579 
580 
581 /* Show current 802.3ad partner mac. */
582 static ssize_t bonding_show_ad_partner_mac(struct device *d,
583 					   struct device_attribute *attr,
584 					   char *buf)
585 {
586 	int count = 0;
587 	struct bonding *bond = to_bond(d);
588 
589 	if (BOND_MODE(bond) == BOND_MODE_8023AD) {
590 		struct ad_info ad_info;
591 		if (!bond_3ad_get_active_agg_info(bond, &ad_info))
592 			count = sprintf(buf, "%pM\n", ad_info.partner_system);
593 	}
594 
595 	return count;
596 }
597 static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
598 
599 /* Show the queue_ids of the slaves in the current bond. */
600 static ssize_t bonding_show_queue_id(struct device *d,
601 				     struct device_attribute *attr,
602 				     char *buf)
603 {
604 	struct bonding *bond = to_bond(d);
605 	struct list_head *iter;
606 	struct slave *slave;
607 	int res = 0;
608 
609 	if (!rtnl_trylock())
610 		return restart_syscall();
611 
612 	bond_for_each_slave(bond, slave, iter) {
613 		if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
614 			/* not enough space for another interface_name:queue_id pair */
615 			if ((PAGE_SIZE - res) > 10)
616 				res = PAGE_SIZE - 10;
617 			res += sprintf(buf + res, "++more++ ");
618 			break;
619 		}
620 		res += sprintf(buf + res, "%s:%d ",
621 			       slave->dev->name, slave->queue_id);
622 	}
623 	if (res)
624 		buf[res-1] = '\n'; /* eat the leftover space */
625 
626 	rtnl_unlock();
627 
628 	return res;
629 }
630 static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
631 		   bonding_sysfs_store_option);
632 
633 
634 /* Show the all_slaves_active flag. */
635 static ssize_t bonding_show_slaves_active(struct device *d,
636 					  struct device_attribute *attr,
637 					  char *buf)
638 {
639 	struct bonding *bond = to_bond(d);
640 
641 	return sprintf(buf, "%d\n", bond->params.all_slaves_active);
642 }
643 static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
644 		   bonding_show_slaves_active, bonding_sysfs_store_option);
645 
646 /* Show the number of IGMP membership reports to send on link failure */
647 static ssize_t bonding_show_resend_igmp(struct device *d,
648 					struct device_attribute *attr,
649 					char *buf)
650 {
651 	struct bonding *bond = to_bond(d);
652 
653 	return sprintf(buf, "%d\n", bond->params.resend_igmp);
654 }
655 static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
656 		   bonding_show_resend_igmp, bonding_sysfs_store_option);
657 
658 
659 static ssize_t bonding_show_lp_interval(struct device *d,
660 					struct device_attribute *attr,
661 					char *buf)
662 {
663 	struct bonding *bond = to_bond(d);
664 
665 	return sprintf(buf, "%d\n", bond->params.lp_interval);
666 }
667 static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
668 		   bonding_show_lp_interval, bonding_sysfs_store_option);
669 
670 static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
671 					   struct device_attribute *attr,
672 					   char *buf)
673 {
674 	struct bonding *bond = to_bond(d);
675 	return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
676 }
677 static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR,
678 		   bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
679 
680 static ssize_t bonding_show_packets_per_slave(struct device *d,
681 					      struct device_attribute *attr,
682 					      char *buf)
683 {
684 	struct bonding *bond = to_bond(d);
685 	unsigned int packets_per_slave = bond->params.packets_per_slave;
686 
687 	return sprintf(buf, "%u\n", packets_per_slave);
688 }
689 static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
690 		   bonding_show_packets_per_slave, bonding_sysfs_store_option);
691 
692 static struct attribute *per_bond_attrs[] = {
693 	&dev_attr_slaves.attr,
694 	&dev_attr_mode.attr,
695 	&dev_attr_fail_over_mac.attr,
696 	&dev_attr_arp_validate.attr,
697 	&dev_attr_arp_all_targets.attr,
698 	&dev_attr_arp_interval.attr,
699 	&dev_attr_arp_ip_target.attr,
700 	&dev_attr_downdelay.attr,
701 	&dev_attr_updelay.attr,
702 	&dev_attr_lacp_rate.attr,
703 	&dev_attr_ad_select.attr,
704 	&dev_attr_xmit_hash_policy.attr,
705 	&dev_attr_num_grat_arp.attr,
706 	&dev_attr_num_unsol_na.attr,
707 	&dev_attr_miimon.attr,
708 	&dev_attr_primary.attr,
709 	&dev_attr_primary_reselect.attr,
710 	&dev_attr_use_carrier.attr,
711 	&dev_attr_active_slave.attr,
712 	&dev_attr_mii_status.attr,
713 	&dev_attr_ad_aggregator.attr,
714 	&dev_attr_ad_num_ports.attr,
715 	&dev_attr_ad_actor_key.attr,
716 	&dev_attr_ad_partner_key.attr,
717 	&dev_attr_ad_partner_mac.attr,
718 	&dev_attr_queue_id.attr,
719 	&dev_attr_all_slaves_active.attr,
720 	&dev_attr_resend_igmp.attr,
721 	&dev_attr_min_links.attr,
722 	&dev_attr_lp_interval.attr,
723 	&dev_attr_packets_per_slave.attr,
724 	&dev_attr_tlb_dynamic_lb.attr,
725 	NULL,
726 };
727 
728 static struct attribute_group bonding_group = {
729 	.name = "bonding",
730 	.attrs = per_bond_attrs,
731 };
732 
733 /* Initialize sysfs.  This sets up the bonding_masters file in
734  * /sys/class/net.
735  */
736 int bond_create_sysfs(struct bond_net *bn)
737 {
738 	int ret;
739 
740 	bn->class_attr_bonding_masters = class_attr_bonding_masters;
741 	sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
742 
743 	ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
744 					  bn->net);
745 	/* Permit multiple loads of the module by ignoring failures to
746 	 * create the bonding_masters sysfs file.  Bonding devices
747 	 * created by second or subsequent loads of the module will
748 	 * not be listed in, or controllable by, bonding_masters, but
749 	 * will have the usual "bonding" sysfs directory.
750 	 *
751 	 * This is done to preserve backwards compatibility for
752 	 * initscripts/sysconfig, which load bonding multiple times to
753 	 * configure multiple bonding devices.
754 	 */
755 	if (ret == -EEXIST) {
756 		/* Is someone being kinky and naming a device bonding_master? */
757 		if (__dev_get_by_name(bn->net,
758 				      class_attr_bonding_masters.attr.name))
759 			pr_err("network device named %s already exists in sysfs\n",
760 			       class_attr_bonding_masters.attr.name);
761 		ret = 0;
762 	}
763 
764 	return ret;
765 
766 }
767 
768 /* Remove /sys/class/net/bonding_masters. */
769 void bond_destroy_sysfs(struct bond_net *bn)
770 {
771 	netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
772 }
773 
774 /* Initialize sysfs for each bond.  This sets up and registers
775  * the 'bondctl' directory for each individual bond under /sys/class/net.
776  */
777 void bond_prepare_sysfs_group(struct bonding *bond)
778 {
779 	bond->dev->sysfs_groups[0] = &bonding_group;
780 }
781 
782