blob: 7e9e151d4d6168821e28ef82e8c197b2c4666b87 [file] [log] [blame]
Mitch Williamsb76cdba2005-11-09 10:36:41 -08001/*
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
Jeff Kirsheradf8d3f2013-12-06 06:28:47 -080015 * with this program; if not, see <http://www.gnu.org/licenses/>.
Mitch Williamsb76cdba2005-11-09 10:36:41 -080016 *
17 * The full GNU General Public License is included in this distribution in the
18 * file called LICENSE.
19 *
Mitch Williamsb76cdba2005-11-09 10:36:41 -080020 */
Joe Perchesa4aee5c2009-12-13 20:06:07 -080021
22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Mitch Williamsb76cdba2005-11-09 10:36:41 -080024#include <linux/kernel.h>
25#include <linux/module.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080026#include <linux/device.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040027#include <linux/sched.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080028#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>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080035#include <linux/ctype.h>
36#include <linux/inet.h>
37#include <linux/rtnetlink.h>
Stephen Hemminger5c5129b2009-06-12 19:02:51 +000038#include <linux/etherdevice.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070039#include <net/net_namespace.h>
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000040#include <net/netns/generic.h>
41#include <linux/nsproxy.h>
Mitch Williamsb76cdba2005-11-09 10:36:41 -080042
David S. Miller1ef80192014-11-10 13:27:49 -050043#include <net/bonding.h>
Holger Eitzenberger5a03cdb2008-12-09 23:09:22 -080044
Stephen Hemminger3d632c32009-06-12 19:02:48 +000045#define to_dev(obj) container_of(obj, struct device, kobj)
Wang Chen454d7c92008-11-12 23:37:49 -080046#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
Mitch Williamsb76cdba2005-11-09 10:36:41 -080047
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +020048/* "show" function for the bond_masters attribute.
Mitch Williamsb76cdba2005-11-09 10:36:41 -080049 * The class parameter is ignored.
50 */
Andi Kleen28812fe2010-01-05 12:48:07 +010051static ssize_t bonding_show_bonds(struct class *cls,
52 struct class_attribute *attr,
53 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080054{
Eric W. Biederman4c224002011-10-12 21:56:25 +000055 struct bond_net *bn =
56 container_of(attr, struct bond_net, class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080057 int res = 0;
58 struct bonding *bond;
59
Stephen Hemminger7e083842009-06-12 19:02:46 +000060 rtnl_lock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -080061
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000062 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -080063 if (res > (PAGE_SIZE - IFNAMSIZ)) {
64 /* not enough space for another interface name */
65 if ((PAGE_SIZE - res) > 10)
66 res = PAGE_SIZE - 10;
Wagner Ferencb8843662007-12-06 23:40:30 -080067 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -080068 break;
69 }
Wagner Ferencb8843662007-12-06 23:40:30 -080070 res += sprintf(buf + res, "%s ", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080071 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -080072 if (res)
73 buf[res-1] = '\n'; /* eat the leftover space */
Stephen Hemminger7e083842009-06-12 19:02:46 +000074
75 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -080076 return res;
77}
78
Eric W. Biederman4c224002011-10-12 21:56:25 +000079static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
Stephen Hemminger373500d2009-06-12 19:02:50 +000080{
81 struct bonding *bond;
82
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000083 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Stephen Hemminger373500d2009-06-12 19:02:50 +000084 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
85 return bond->dev;
86 }
87 return NULL;
88}
89
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +020090/* "store" function for the bond_masters attribute. This is what
Mitch Williamsb76cdba2005-11-09 10:36:41 -080091 * creates and deletes entire bonds.
92 *
93 * The class parameter is ignored.
Mitch Williamsb76cdba2005-11-09 10:36:41 -080094 */
Stephen Hemminger3d632c32009-06-12 19:02:48 +000095static ssize_t bonding_store_bonds(struct class *cls,
Andi Kleen28812fe2010-01-05 12:48:07 +010096 struct class_attribute *attr,
Stephen Hemminger3d632c32009-06-12 19:02:48 +000097 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080098{
Eric W. Biederman4c224002011-10-12 21:56:25 +000099 struct bond_net *bn =
100 container_of(attr, struct bond_net, class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800101 char command[IFNAMSIZ + 1] = {0, };
102 char *ifname;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800103 int rv, res = count;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800104
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800105 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
106 ifname = command + 1;
107 if ((strlen(command) <= 1) ||
108 !dev_valid_name(ifname))
109 goto err_no_cmd;
110
111 if (command[0] == '+') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800112 pr_info("%s is being created...\n", ifname);
Eric W. Biederman4c224002011-10-12 21:56:25 +0000113 rv = bond_create(bn->net, ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800114 if (rv) {
Phil Oester5f86cad12011-03-14 06:22:06 +0000115 if (rv == -EEXIST)
Joe Perches90194262014-02-15 16:01:45 -0800116 pr_info("%s already exists\n", ifname);
Phil Oester5f86cad12011-03-14 06:22:06 +0000117 else
Joe Perches90194262014-02-15 16:01:45 -0800118 pr_info("%s creation failed\n", ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800119 res = rv;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800120 }
Stephen Hemminger373500d2009-06-12 19:02:50 +0000121 } else if (command[0] == '-') {
122 struct net_device *bond_dev;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800123
Jay Vosburgh027ea042008-01-17 16:25:02 -0800124 rtnl_lock();
Eric W. Biederman4c224002011-10-12 21:56:25 +0000125 bond_dev = bond_get_by_name(bn, ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000126 if (bond_dev) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800127 pr_info("%s is being deleted...\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000128 unregister_netdevice(bond_dev);
129 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800130 pr_err("unable to delete non-existent %s\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000131 res = -ENODEV;
132 }
133 rtnl_unlock();
134 } else
135 goto err_no_cmd;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800136
Stephen Hemminger373500d2009-06-12 19:02:50 +0000137 /* Always return either count or an error. If you return 0, you'll
138 * get called forever, which is bad.
139 */
140 return res;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800141
142err_no_cmd:
Joe Perches90194262014-02-15 16:01:45 -0800143 pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700144 return -EPERM;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800145}
Stephen Hemminger373500d2009-06-12 19:02:50 +0000146
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800147/* class attribute for bond_masters file. This ends up in /sys/class/net */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000148static const struct class_attribute class_attr_bonding_masters = {
149 .attr = {
150 .name = "bonding_masters",
151 .mode = S_IWUSR | S_IRUGO,
152 },
153 .show = bonding_show_bonds,
154 .store = bonding_store_bonds,
Eric W. Biederman4c224002011-10-12 21:56:25 +0000155};
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800156
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200157/* Generic "store" method for bonding sysfs option setting */
158static ssize_t bonding_sysfs_store_option(struct device *d,
159 struct device_attribute *attr,
160 const char *buffer, size_t count)
161{
162 struct bonding *bond = to_bond(d);
163 const struct bond_option *opt;
164 int ret;
165
166 opt = bond_opt_get_by_name(attr->attr.name);
167 if (WARN_ON(!opt))
168 return -ENOENT;
169 ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer);
170 if (!ret)
171 ret = count;
172
173 return ret;
174}
175
176/* Show the slaves in the current bond. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700177static ssize_t bonding_show_slaves(struct device *d,
178 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800179{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700180 struct bonding *bond = to_bond(d);
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200181 struct list_head *iter;
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200182 struct slave *slave;
183 int res = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800184
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800185 if (!rtnl_trylock())
186 return restart_syscall();
187
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200188 bond_for_each_slave(bond, slave, iter) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800189 if (res > (PAGE_SIZE - IFNAMSIZ)) {
190 /* not enough space for another interface name */
191 if ((PAGE_SIZE - res) > 10)
192 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800193 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800194 break;
195 }
196 res += sprintf(buf + res, "%s ", slave->dev->name);
197 }
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800198
199 rtnl_unlock();
200
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800201 if (res)
202 buf[res-1] = '\n'; /* eat the leftover space */
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200203
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800204 return res;
205}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000206static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200207 bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800208
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200209/* Show the bonding mode. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700210static ssize_t bonding_show_mode(struct device *d,
211 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800212{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700213 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800214 const struct bond_opt_value *val;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800215
Veaceslav Falico01844092014-05-15 21:39:55 +0200216 val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond));
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100217
Veaceslav Falico01844092014-05-15 21:39:55 +0200218 return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond));
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800219}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000220static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200221 bonding_show_mode, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800222
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200223/* Show the bonding transmit hash method. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700224static ssize_t bonding_show_xmit_hash(struct device *d,
225 struct device_attribute *attr,
226 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800227{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700228 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800229 const struct bond_opt_value *val;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800230
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100231 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
232
233 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800234}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000235static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200236 bonding_show_xmit_hash, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800237
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200238/* Show arp_validate. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700239static ssize_t bonding_show_arp_validate(struct device *d,
240 struct device_attribute *attr,
241 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700242{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700243 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800244 const struct bond_opt_value *val;
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700245
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100246 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
247 bond->params.arp_validate);
248
249 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700250}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000251static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200252 bonding_sysfs_store_option);
253
254/* Show arp_all_targets. */
Veaceslav Falico8599b522013-06-24 11:49:34 +0200255static ssize_t bonding_show_arp_all_targets(struct device *d,
256 struct device_attribute *attr,
257 char *buf)
258{
259 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800260 const struct bond_opt_value *val;
Veaceslav Falico8599b522013-06-24 11:49:34 +0200261
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100262 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
263 bond->params.arp_all_targets);
264 return sprintf(buf, "%s %d\n",
265 val->string, bond->params.arp_all_targets);
Veaceslav Falico8599b522013-06-24 11:49:34 +0200266}
Veaceslav Falico8599b522013-06-24 11:49:34 +0200267static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200268 bonding_show_arp_all_targets, bonding_sysfs_store_option);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700269
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200270/* Show fail_over_mac. */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000271static ssize_t bonding_show_fail_over_mac(struct device *d,
272 struct device_attribute *attr,
273 char *buf)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700274{
275 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800276 const struct bond_opt_value *val;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700277
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100278 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
279 bond->params.fail_over_mac);
280
281 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700282}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000283static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200284 bonding_show_fail_over_mac, bonding_sysfs_store_option);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700285
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200286/* Show the arp timer interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700287static ssize_t bonding_show_arp_interval(struct device *d,
288 struct device_attribute *attr,
289 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800290{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700291 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800292
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800293 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800294}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000295static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200296 bonding_show_arp_interval, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800297
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200298/* Show the arp targets. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700299static ssize_t bonding_show_arp_targets(struct device *d,
300 struct device_attribute *attr,
301 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800302{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700303 struct bonding *bond = to_bond(d);
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100304 int i, res = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800305
306 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
307 if (bond->params.arp_targets[i])
Harvey Harrison63779432008-10-31 00:56:00 -0700308 res += sprintf(buf + res, "%pI4 ",
309 &bond->params.arp_targets[i]);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800310 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800311 if (res)
312 buf[res-1] = '\n'; /* eat the leftover space */
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100313
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800314 return res;
315}
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200316static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR,
317 bonding_show_arp_targets, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800318
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200319/* Show the up and down delays. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700320static ssize_t bonding_show_downdelay(struct device *d,
321 struct device_attribute *attr,
322 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800323{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700324 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800325
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800326 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800327}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000328static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200329 bonding_show_downdelay, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800330
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700331static ssize_t bonding_show_updelay(struct device *d,
332 struct device_attribute *attr,
333 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800334{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700335 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800336
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800337 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800338
339}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000340static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200341 bonding_show_updelay, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800342
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200343/* Show the LACP interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700344static ssize_t bonding_show_lacp(struct device *d,
345 struct device_attribute *attr,
346 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800347{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700348 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800349 const struct bond_opt_value *val;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800350
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100351 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
352
353 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800354}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000355static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200356 bonding_show_lacp, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800357
stephen hemminger655f8912011-06-22 09:54:39 +0000358static ssize_t bonding_show_min_links(struct device *d,
359 struct device_attribute *attr,
360 char *buf)
361{
362 struct bonding *bond = to_bond(d);
363
Masanari Iida014f1b22014-04-29 00:41:21 +0900364 return sprintf(buf, "%u\n", bond->params.min_links);
stephen hemminger655f8912011-06-22 09:54:39 +0000365}
stephen hemminger655f8912011-06-22 09:54:39 +0000366static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200367 bonding_show_min_links, bonding_sysfs_store_option);
stephen hemminger655f8912011-06-22 09:54:39 +0000368
Jay Vosburghfd989c82008-11-04 17:51:16 -0800369static ssize_t bonding_show_ad_select(struct device *d,
370 struct device_attribute *attr,
371 char *buf)
372{
373 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800374 const struct bond_opt_value *val;
Jay Vosburghfd989c82008-11-04 17:51:16 -0800375
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100376 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
377
378 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800379}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000380static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200381 bonding_show_ad_select, bonding_sysfs_store_option);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800382
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200383/* Show and set the number of peer notifications to send after a failover event. */
Ben Hutchingsad246c92011-04-26 15:25:52 +0000384static ssize_t bonding_show_num_peer_notif(struct device *d,
385 struct device_attribute *attr,
386 char *buf)
387{
388 struct bonding *bond = to_bond(d);
389 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
390}
391
392static ssize_t bonding_store_num_peer_notif(struct device *d,
393 struct device_attribute *attr,
394 const char *buf, size_t count)
395{
396 struct bonding *bond = to_bond(d);
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800397 int ret;
398
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100399 ret = bond_opt_tryset_rtnl(bond, BOND_OPT_NUM_PEER_NOTIF, (char *)buf);
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800400 if (!ret)
401 ret = count;
402
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800403 return ret;
Ben Hutchingsad246c92011-04-26 15:25:52 +0000404}
405static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
406 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
407static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
408 bonding_show_num_peer_notif, bonding_store_num_peer_notif);
409
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200410/* Show the MII monitor interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700411static ssize_t bonding_show_miimon(struct device *d,
412 struct device_attribute *attr,
413 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800414{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700415 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800416
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800417 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800418}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000419static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200420 bonding_show_miimon, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800421
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200422/* Show the primary slave. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700423static ssize_t bonding_show_primary(struct device *d,
424 struct device_attribute *attr,
425 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800426{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700427 struct bonding *bond = to_bond(d);
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +0200428 struct slave *primary;
429 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800430
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +0200431 rcu_read_lock();
432 primary = rcu_dereference(bond->primary_slave);
433 if (primary)
434 count = sprintf(buf, "%s\n", primary->dev->name);
435 rcu_read_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800436
437 return count;
438}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000439static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200440 bonding_show_primary, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800441
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200442/* Show the primary_reselect flag. */
Jiri Pirkoa5499522009-09-25 03:28:09 +0000443static ssize_t bonding_show_primary_reselect(struct device *d,
444 struct device_attribute *attr,
445 char *buf)
446{
447 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800448 const struct bond_opt_value *val;
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100449
450 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
451 bond->params.primary_reselect);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000452
453 return sprintf(buf, "%s %d\n",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100454 val->string, bond->params.primary_reselect);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000455}
Jiri Pirkoa5499522009-09-25 03:28:09 +0000456static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200457 bonding_show_primary_reselect, bonding_sysfs_store_option);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000458
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200459/* Show the use_carrier flag. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700460static ssize_t bonding_show_carrier(struct device *d,
461 struct device_attribute *attr,
462 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800463{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700464 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800465
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800466 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800467}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000468static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200469 bonding_show_carrier, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800470
471
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200472/* Show currently active_slave. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700473static ssize_t bonding_show_active_slave(struct device *d,
474 struct device_attribute *attr,
475 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800476{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700477 struct bonding *bond = to_bond(d);
Jiri Pirko752d48b2013-10-18 17:43:37 +0200478 struct net_device *slave_dev;
Wagner Ferenc16cd0162007-12-06 23:40:29 -0800479 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800480
nikolay@redhat.com278b2082013-08-01 16:54:51 +0200481 rcu_read_lock();
Jiri Pirko752d48b2013-10-18 17:43:37 +0200482 slave_dev = bond_option_active_slave_get_rcu(bond);
483 if (slave_dev)
484 count = sprintf(buf, "%s\n", slave_dev->name);
nikolay@redhat.com278b2082013-08-01 16:54:51 +0200485 rcu_read_unlock();
486
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800487 return count;
488}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000489static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200490 bonding_show_active_slave, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800491
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200492/* Show link status of the bond interface. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700493static ssize_t bonding_show_mii_status(struct device *d,
494 struct device_attribute *attr,
495 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800496{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700497 struct bonding *bond = to_bond(d);
Eric Dumazetc2646b52014-07-15 06:56:54 -0700498 bool active = !!rcu_access_pointer(bond->curr_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800499
Eric Dumazetc2646b52014-07-15 06:56:54 -0700500 return sprintf(buf, "%s\n", active ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800501}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700502static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800503
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200504/* Show current 802.3ad aggregator ID. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700505static ssize_t bonding_show_ad_aggregator(struct device *d,
506 struct device_attribute *attr,
507 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800508{
509 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700510 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800511
Veaceslav Falico01844092014-05-15 21:39:55 +0200512 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800513 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000514 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000515 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000516 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800517 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800518
519 return count;
520}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700521static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800522
523
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200524/* Show number of active 802.3ad ports. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700525static ssize_t bonding_show_ad_num_ports(struct device *d,
526 struct device_attribute *attr,
527 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800528{
529 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700530 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800531
Veaceslav Falico01844092014-05-15 21:39:55 +0200532 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800533 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000534 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000535 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000536 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800537 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800538
539 return count;
540}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700541static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800542
543
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200544/* Show current 802.3ad actor key. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700545static ssize_t bonding_show_ad_actor_key(struct device *d,
546 struct device_attribute *attr,
547 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800548{
549 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700550 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800551
Veaceslav Falico01844092014-05-15 21:39:55 +0200552 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800553 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000554 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000555 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000556 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800557 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800558
559 return count;
560}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700561static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800562
563
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200564/* Show current 802.3ad partner key. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700565static ssize_t bonding_show_ad_partner_key(struct device *d,
566 struct device_attribute *attr,
567 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800568{
569 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700570 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800571
Veaceslav Falico01844092014-05-15 21:39:55 +0200572 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800573 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000574 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000575 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000576 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800577 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800578
579 return count;
580}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700581static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800582
583
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200584/* Show current 802.3ad partner mac. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700585static ssize_t bonding_show_ad_partner_mac(struct device *d,
586 struct device_attribute *attr,
587 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800588{
589 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700590 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800591
Veaceslav Falico01844092014-05-15 21:39:55 +0200592 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800593 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000594 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -0700595 count = sprintf(buf, "%pM\n", ad_info.partner_system);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800596 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800597
598 return count;
599}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700600static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800601
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200602/* Show the queue_ids of the slaves in the current bond. */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000603static ssize_t bonding_show_queue_id(struct device *d,
604 struct device_attribute *attr,
605 char *buf)
606{
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000607 struct bonding *bond = to_bond(d);
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200608 struct list_head *iter;
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200609 struct slave *slave;
610 int res = 0;
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000611
612 if (!rtnl_trylock())
613 return restart_syscall();
614
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200615 bond_for_each_slave(bond, slave, iter) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -0700616 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
617 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000618 if ((PAGE_SIZE - res) > 10)
619 res = PAGE_SIZE - 10;
620 res += sprintf(buf + res, "++more++ ");
621 break;
622 }
623 res += sprintf(buf + res, "%s:%d ",
624 slave->dev->name, slave->queue_id);
625 }
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000626 if (res)
627 buf[res-1] = '\n'; /* eat the leftover space */
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800628
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000629 rtnl_unlock();
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200630
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000631 return res;
632}
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000633static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200634 bonding_sysfs_store_option);
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000635
636
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200637/* Show the all_slaves_active flag. */
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000638static ssize_t bonding_show_slaves_active(struct device *d,
639 struct device_attribute *attr,
640 char *buf)
641{
642 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800643
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000644 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
645}
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000646static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200647 bonding_show_slaves_active, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800648
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200649/* Show the number of IGMP membership reports to send on link failure */
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000650static ssize_t bonding_show_resend_igmp(struct device *d,
Flavio Leitner94265cf2011-05-25 08:38:58 +0000651 struct device_attribute *attr,
652 char *buf)
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000653{
654 struct bonding *bond = to_bond(d);
655
656 return sprintf(buf, "%d\n", bond->params.resend_igmp);
657}
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000658static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200659 bonding_show_resend_igmp, bonding_sysfs_store_option);
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000660
Neil Horman7eacd032013-09-13 11:05:33 -0400661
662static ssize_t bonding_show_lp_interval(struct device *d,
663 struct device_attribute *attr,
664 char *buf)
665{
666 struct bonding *bond = to_bond(d);
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200667
Neil Horman7eacd032013-09-13 11:05:33 -0400668 return sprintf(buf, "%d\n", bond->params.lp_interval);
669}
Neil Horman7eacd032013-09-13 11:05:33 -0400670static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200671 bonding_show_lp_interval, bonding_sysfs_store_option);
Neil Horman7eacd032013-09-13 11:05:33 -0400672
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700673static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
674 struct device_attribute *attr,
675 char *buf)
676{
677 struct bonding *bond = to_bond(d);
678 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
679}
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700680static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200681 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700682
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100683static ssize_t bonding_show_packets_per_slave(struct device *d,
684 struct device_attribute *attr,
685 char *buf)
686{
687 struct bonding *bond = to_bond(d);
Nikolay Aleksandrova752a8b2013-12-05 11:36:58 +0100688 unsigned int packets_per_slave = bond->params.packets_per_slave;
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200689
Nikolay Aleksandrova752a8b2013-12-05 11:36:58 +0100690 return sprintf(buf, "%u\n", packets_per_slave);
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100691}
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100692static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200693 bonding_show_packets_per_slave, bonding_sysfs_store_option);
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100694
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800695static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700696 &dev_attr_slaves.attr,
697 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -0700698 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700699 &dev_attr_arp_validate.attr,
Veaceslav Falico8599b522013-06-24 11:49:34 +0200700 &dev_attr_arp_all_targets.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700701 &dev_attr_arp_interval.attr,
702 &dev_attr_arp_ip_target.attr,
703 &dev_attr_downdelay.attr,
704 &dev_attr_updelay.attr,
705 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -0800706 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700707 &dev_attr_xmit_hash_policy.attr,
Ben Hutchingsad246c92011-04-26 15:25:52 +0000708 &dev_attr_num_grat_arp.attr,
709 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700710 &dev_attr_miimon.attr,
711 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +0000712 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700713 &dev_attr_use_carrier.attr,
714 &dev_attr_active_slave.attr,
715 &dev_attr_mii_status.attr,
716 &dev_attr_ad_aggregator.attr,
717 &dev_attr_ad_num_ports.attr,
718 &dev_attr_ad_actor_key.attr,
719 &dev_attr_ad_partner_key.attr,
720 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000721 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000722 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000723 &dev_attr_resend_igmp.attr,
stephen hemminger655f8912011-06-22 09:54:39 +0000724 &dev_attr_min_links.attr,
Neil Horman7eacd032013-09-13 11:05:33 -0400725 &dev_attr_lp_interval.attr,
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100726 &dev_attr_packets_per_slave.attr,
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700727 &dev_attr_tlb_dynamic_lb.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800728 NULL,
729};
730
731static struct attribute_group bonding_group = {
732 .name = "bonding",
733 .attrs = per_bond_attrs,
734};
735
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200736/* Initialize sysfs. This sets up the bonding_masters file in
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800737 * /sys/class/net.
738 */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000739int bond_create_sysfs(struct bond_net *bn)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800740{
Jay Vosburghb8a97872008-06-13 18:12:04 -0700741 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800742
Eric W. Biederman4c224002011-10-12 21:56:25 +0000743 bn->class_attr_bonding_masters = class_attr_bonding_masters;
Eric W. Biederman01718e32011-10-21 22:43:07 +0000744 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
Eric W. Biederman4c224002011-10-12 21:56:25 +0000745
Tejun Heo58292cbe2013-09-11 22:29:04 -0400746 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
747 bn->net);
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200748 /* Permit multiple loads of the module by ignoring failures to
Jay Vosburgh877cbd32007-01-19 18:15:47 -0800749 * create the bonding_masters sysfs file. Bonding devices
750 * created by second or subsequent loads of the module will
751 * not be listed in, or controllable by, bonding_masters, but
752 * will have the usual "bonding" sysfs directory.
753 *
754 * This is done to preserve backwards compatibility for
755 * initscripts/sysconfig, which load bonding multiple times to
756 * configure multiple bonding devices.
757 */
758 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700759 /* Is someone being kinky and naming a device bonding_master? */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000760 if (__dev_get_by_name(bn->net,
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700761 class_attr_bonding_masters.attr.name))
Joe Perches90194262014-02-15 16:01:45 -0800762 pr_err("network device named %s already exists in sysfs\n",
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700763 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -0700764 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -0800765 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800766
767 return ret;
768
769}
770
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200771/* Remove /sys/class/net/bonding_masters. */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000772void bond_destroy_sysfs(struct bond_net *bn)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800773{
Tejun Heo58292cbe2013-09-11 22:29:04 -0400774 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800775}
776
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200777/* Initialize sysfs for each bond. This sets up and registers
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800778 * the 'bondctl' directory for each individual bond under /sys/class/net.
779 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +0000780void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800781{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +0000782 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800783}
784