blob: e23c3ed737deefc7d3ca200b545a6c4b590afc01 [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
Wang Chen454d7c92008-11-12 23:37:49 -080045#define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd))))
Mitch Williamsb76cdba2005-11-09 10:36:41 -080046
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +020047/* "show" function for the bond_masters attribute.
Mitch Williamsb76cdba2005-11-09 10:36:41 -080048 * The class parameter is ignored.
49 */
Andi Kleen28812fe2010-01-05 12:48:07 +010050static ssize_t bonding_show_bonds(struct class *cls,
51 struct class_attribute *attr,
52 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080053{
Eric W. Biederman4c224002011-10-12 21:56:25 +000054 struct bond_net *bn =
55 container_of(attr, struct bond_net, class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080056 int res = 0;
57 struct bonding *bond;
58
Stephen Hemminger7e083842009-06-12 19:02:46 +000059 rtnl_lock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -080060
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000061 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -080062 if (res > (PAGE_SIZE - IFNAMSIZ)) {
63 /* not enough space for another interface name */
64 if ((PAGE_SIZE - res) > 10)
65 res = PAGE_SIZE - 10;
Wagner Ferencb8843662007-12-06 23:40:30 -080066 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -080067 break;
68 }
Wagner Ferencb8843662007-12-06 23:40:30 -080069 res += sprintf(buf + res, "%s ", bond->dev->name);
Mitch Williamsb76cdba2005-11-09 10:36:41 -080070 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -080071 if (res)
72 buf[res-1] = '\n'; /* eat the leftover space */
Stephen Hemminger7e083842009-06-12 19:02:46 +000073
74 rtnl_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -080075 return res;
76}
77
Eric W. Biederman4c224002011-10-12 21:56:25 +000078static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname)
Stephen Hemminger373500d2009-06-12 19:02:50 +000079{
80 struct bonding *bond;
81
Eric W. Biedermanec87fd32009-10-29 14:18:26 +000082 list_for_each_entry(bond, &bn->dev_list, bond_list) {
Stephen Hemminger373500d2009-06-12 19:02:50 +000083 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
84 return bond->dev;
85 }
86 return NULL;
87}
88
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +020089/* "store" function for the bond_masters attribute. This is what
Mitch Williamsb76cdba2005-11-09 10:36:41 -080090 * creates and deletes entire bonds.
91 *
92 * The class parameter is ignored.
Mitch Williamsb76cdba2005-11-09 10:36:41 -080093 */
Stephen Hemminger3d632c32009-06-12 19:02:48 +000094static ssize_t bonding_store_bonds(struct class *cls,
Andi Kleen28812fe2010-01-05 12:48:07 +010095 struct class_attribute *attr,
Stephen Hemminger3d632c32009-06-12 19:02:48 +000096 const char *buffer, size_t count)
Mitch Williamsb76cdba2005-11-09 10:36:41 -080097{
Eric W. Biederman4c224002011-10-12 21:56:25 +000098 struct bond_net *bn =
99 container_of(attr, struct bond_net, class_attr_bonding_masters);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800100 char command[IFNAMSIZ + 1] = {0, };
101 char *ifname;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800102 int rv, res = count;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800103
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800104 sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
105 ifname = command + 1;
106 if ((strlen(command) <= 1) ||
107 !dev_valid_name(ifname))
108 goto err_no_cmd;
109
110 if (command[0] == '+') {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800111 pr_info("%s is being created...\n", ifname);
Eric W. Biederman4c224002011-10-12 21:56:25 +0000112 rv = bond_create(bn->net, ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800113 if (rv) {
Phil Oester5f86cad12011-03-14 06:22:06 +0000114 if (rv == -EEXIST)
Joe Perches90194262014-02-15 16:01:45 -0800115 pr_info("%s already exists\n", ifname);
Phil Oester5f86cad12011-03-14 06:22:06 +0000116 else
Joe Perches90194262014-02-15 16:01:45 -0800117 pr_info("%s creation failed\n", ifname);
Jay Vosburgh027ea042008-01-17 16:25:02 -0800118 res = rv;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800119 }
Stephen Hemminger373500d2009-06-12 19:02:50 +0000120 } else if (command[0] == '-') {
121 struct net_device *bond_dev;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800122
Jay Vosburgh027ea042008-01-17 16:25:02 -0800123 rtnl_lock();
Eric W. Biederman4c224002011-10-12 21:56:25 +0000124 bond_dev = bond_get_by_name(bn, ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000125 if (bond_dev) {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800126 pr_info("%s is being deleted...\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000127 unregister_netdevice(bond_dev);
128 } else {
Joe Perchesa4aee5c2009-12-13 20:06:07 -0800129 pr_err("unable to delete non-existent %s\n", ifname);
Stephen Hemminger373500d2009-06-12 19:02:50 +0000130 res = -ENODEV;
131 }
132 rtnl_unlock();
133 } else
134 goto err_no_cmd;
Jay Vosburgh027ea042008-01-17 16:25:02 -0800135
Stephen Hemminger373500d2009-06-12 19:02:50 +0000136 /* Always return either count or an error. If you return 0, you'll
137 * get called forever, which is bad.
138 */
139 return res;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800140
141err_no_cmd:
Joe Perches90194262014-02-15 16:01:45 -0800142 pr_err("no command found in bonding_masters - use +ifname or -ifname\n");
Jay Vosburghc4ebc662008-05-02 17:49:38 -0700143 return -EPERM;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800144}
Stephen Hemminger373500d2009-06-12 19:02:50 +0000145
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800146/* class attribute for bond_masters file. This ends up in /sys/class/net */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000147static const struct class_attribute class_attr_bonding_masters = {
148 .attr = {
149 .name = "bonding_masters",
150 .mode = S_IWUSR | S_IRUGO,
151 },
152 .show = bonding_show_bonds,
153 .store = bonding_store_bonds,
Eric W. Biederman4c224002011-10-12 21:56:25 +0000154};
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800155
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200156/* Generic "store" method for bonding sysfs option setting */
157static ssize_t bonding_sysfs_store_option(struct device *d,
158 struct device_attribute *attr,
159 const char *buffer, size_t count)
160{
161 struct bonding *bond = to_bond(d);
162 const struct bond_option *opt;
163 int ret;
164
165 opt = bond_opt_get_by_name(attr->attr.name);
166 if (WARN_ON(!opt))
167 return -ENOENT;
168 ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer);
169 if (!ret)
170 ret = count;
171
172 return ret;
173}
174
175/* Show the slaves in the current bond. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700176static ssize_t bonding_show_slaves(struct device *d,
177 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800178{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700179 struct bonding *bond = to_bond(d);
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200180 struct list_head *iter;
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200181 struct slave *slave;
182 int res = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800183
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800184 if (!rtnl_trylock())
185 return restart_syscall();
186
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200187 bond_for_each_slave(bond, slave, iter) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800188 if (res > (PAGE_SIZE - IFNAMSIZ)) {
189 /* not enough space for another interface name */
190 if ((PAGE_SIZE - res) > 10)
191 res = PAGE_SIZE - 10;
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800192 res += sprintf(buf + res, "++more++ ");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800193 break;
194 }
195 res += sprintf(buf + res, "%s ", slave->dev->name);
196 }
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800197
198 rtnl_unlock();
199
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800200 if (res)
201 buf[res-1] = '\n'; /* eat the leftover space */
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200202
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800203 return res;
204}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000205static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200206 bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800207
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200208/* Show the bonding mode. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700209static ssize_t bonding_show_mode(struct device *d,
210 struct device_attribute *attr, char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800211{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700212 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800213 const struct bond_opt_value *val;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800214
Veaceslav Falico01844092014-05-15 21:39:55 +0200215 val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond));
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100216
Veaceslav Falico01844092014-05-15 21:39:55 +0200217 return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond));
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800218}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000219static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200220 bonding_show_mode, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800221
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200222/* Show the bonding transmit hash method. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700223static ssize_t bonding_show_xmit_hash(struct device *d,
224 struct device_attribute *attr,
225 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800226{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700227 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800228 const struct bond_opt_value *val;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800229
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100230 val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy);
231
232 return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800233}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000234static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200235 bonding_show_xmit_hash, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800236
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200237/* Show arp_validate. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700238static ssize_t bonding_show_arp_validate(struct device *d,
239 struct device_attribute *attr,
240 char *buf)
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700241{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700242 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800243 const struct bond_opt_value *val;
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700244
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100245 val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
246 bond->params.arp_validate);
247
248 return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700249}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000250static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200251 bonding_sysfs_store_option);
252
253/* Show arp_all_targets. */
Veaceslav Falico8599b522013-06-24 11:49:34 +0200254static ssize_t bonding_show_arp_all_targets(struct device *d,
255 struct device_attribute *attr,
256 char *buf)
257{
258 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800259 const struct bond_opt_value *val;
Veaceslav Falico8599b522013-06-24 11:49:34 +0200260
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100261 val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS,
262 bond->params.arp_all_targets);
263 return sprintf(buf, "%s %d\n",
264 val->string, bond->params.arp_all_targets);
Veaceslav Falico8599b522013-06-24 11:49:34 +0200265}
Veaceslav Falico8599b522013-06-24 11:49:34 +0200266static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200267 bonding_show_arp_all_targets, bonding_sysfs_store_option);
Jay Vosburghf5b2b962006-09-22 21:54:53 -0700268
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200269/* Show fail_over_mac. */
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000270static ssize_t bonding_show_fail_over_mac(struct device *d,
271 struct device_attribute *attr,
272 char *buf)
Jay Vosburghdd957c52007-10-09 19:57:24 -0700273{
274 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800275 const struct bond_opt_value *val;
Jay Vosburghdd957c52007-10-09 19:57:24 -0700276
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100277 val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC,
278 bond->params.fail_over_mac);
279
280 return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700281}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000282static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200283 bonding_show_fail_over_mac, bonding_sysfs_store_option);
Jay Vosburghdd957c52007-10-09 19:57:24 -0700284
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200285/* Show the arp timer interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700286static ssize_t bonding_show_arp_interval(struct device *d,
287 struct device_attribute *attr,
288 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800289{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700290 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800291
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800292 return sprintf(buf, "%d\n", bond->params.arp_interval);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800293}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000294static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200295 bonding_show_arp_interval, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800296
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200297/* Show the arp targets. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700298static ssize_t bonding_show_arp_targets(struct device *d,
299 struct device_attribute *attr,
300 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800301{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700302 struct bonding *bond = to_bond(d);
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100303 int i, res = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800304
305 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
306 if (bond->params.arp_targets[i])
Harvey Harrison63779432008-10-31 00:56:00 -0700307 res += sprintf(buf + res, "%pI4 ",
308 &bond->params.arp_targets[i]);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800309 }
Wagner Ferenc1dcdcd62007-12-06 23:40:31 -0800310 if (res)
311 buf[res-1] = '\n'; /* eat the leftover space */
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100312
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800313 return res;
314}
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200315static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR,
316 bonding_show_arp_targets, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800317
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200318/* Show the up and down delays. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700319static ssize_t bonding_show_downdelay(struct device *d,
320 struct device_attribute *attr,
321 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800322{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700323 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800324
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800325 return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800326}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000327static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200328 bonding_show_downdelay, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800329
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700330static ssize_t bonding_show_updelay(struct device *d,
331 struct device_attribute *attr,
332 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800333{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700334 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800335
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800336 return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800337
338}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000339static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200340 bonding_show_updelay, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800341
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200342/* Show the LACP interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700343static ssize_t bonding_show_lacp(struct device *d,
344 struct device_attribute *attr,
345 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800346{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700347 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800348 const struct bond_opt_value *val;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800349
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100350 val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast);
351
352 return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800353}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000354static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200355 bonding_show_lacp, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800356
stephen hemminger655f8912011-06-22 09:54:39 +0000357static ssize_t bonding_show_min_links(struct device *d,
358 struct device_attribute *attr,
359 char *buf)
360{
361 struct bonding *bond = to_bond(d);
362
Masanari Iida014f1b22014-04-29 00:41:21 +0900363 return sprintf(buf, "%u\n", bond->params.min_links);
stephen hemminger655f8912011-06-22 09:54:39 +0000364}
stephen hemminger655f8912011-06-22 09:54:39 +0000365static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200366 bonding_show_min_links, bonding_sysfs_store_option);
stephen hemminger655f8912011-06-22 09:54:39 +0000367
Jay Vosburghfd989c82008-11-04 17:51:16 -0800368static ssize_t bonding_show_ad_select(struct device *d,
369 struct device_attribute *attr,
370 char *buf)
371{
372 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800373 const struct bond_opt_value *val;
Jay Vosburghfd989c82008-11-04 17:51:16 -0800374
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100375 val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select);
376
377 return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800378}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000379static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200380 bonding_show_ad_select, bonding_sysfs_store_option);
Jay Vosburghfd989c82008-11-04 17:51:16 -0800381
Nikolay Aleksandrov205845a2015-07-24 15:50:31 +0200382/* Show the number of peer notifications to send after a failover event. */
Ben Hutchingsad246c92011-04-26 15:25:52 +0000383static ssize_t bonding_show_num_peer_notif(struct device *d,
384 struct device_attribute *attr,
385 char *buf)
386{
387 struct bonding *bond = to_bond(d);
388 return sprintf(buf, "%d\n", bond->params.num_peer_notif);
389}
Ben Hutchingsad246c92011-04-26 15:25:52 +0000390static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
Nikolay Aleksandrov205845a2015-07-24 15:50:31 +0200391 bonding_show_num_peer_notif, bonding_sysfs_store_option);
Ben Hutchingsad246c92011-04-26 15:25:52 +0000392static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
Nikolay Aleksandrov205845a2015-07-24 15:50:31 +0200393 bonding_show_num_peer_notif, bonding_sysfs_store_option);
Ben Hutchingsad246c92011-04-26 15:25:52 +0000394
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200395/* Show the MII monitor interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700396static ssize_t bonding_show_miimon(struct device *d,
397 struct device_attribute *attr,
398 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800399{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700400 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800401
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800402 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800403}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000404static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200405 bonding_show_miimon, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800406
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200407/* Show the primary slave. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700408static ssize_t bonding_show_primary(struct device *d,
409 struct device_attribute *attr,
410 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800411{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700412 struct bonding *bond = to_bond(d);
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +0200413 struct slave *primary;
414 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800415
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +0200416 rcu_read_lock();
417 primary = rcu_dereference(bond->primary_slave);
418 if (primary)
419 count = sprintf(buf, "%s\n", primary->dev->name);
420 rcu_read_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800421
422 return count;
423}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000424static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200425 bonding_show_primary, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800426
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200427/* Show the primary_reselect flag. */
Jiri Pirkoa5499522009-09-25 03:28:09 +0000428static ssize_t bonding_show_primary_reselect(struct device *d,
429 struct device_attribute *attr,
430 char *buf)
431{
432 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800433 const struct bond_opt_value *val;
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100434
435 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
436 bond->params.primary_reselect);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000437
438 return sprintf(buf, "%s %d\n",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100439 val->string, bond->params.primary_reselect);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000440}
Jiri Pirkoa5499522009-09-25 03:28:09 +0000441static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200442 bonding_show_primary_reselect, bonding_sysfs_store_option);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000443
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200444/* Show the use_carrier flag. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700445static ssize_t bonding_show_carrier(struct device *d,
446 struct device_attribute *attr,
447 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800448{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700449 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800450
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800451 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800452}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000453static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200454 bonding_show_carrier, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800455
456
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200457/* Show currently active_slave. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700458static ssize_t bonding_show_active_slave(struct device *d,
459 struct device_attribute *attr,
460 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800461{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700462 struct bonding *bond = to_bond(d);
Jiri Pirko752d48b2013-10-18 17:43:37 +0200463 struct net_device *slave_dev;
Wagner Ferenc16cd0162007-12-06 23:40:29 -0800464 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800465
nikolay@redhat.com278b2082013-08-01 16:54:51 +0200466 rcu_read_lock();
Jiri Pirko752d48b2013-10-18 17:43:37 +0200467 slave_dev = bond_option_active_slave_get_rcu(bond);
468 if (slave_dev)
469 count = sprintf(buf, "%s\n", slave_dev->name);
nikolay@redhat.com278b2082013-08-01 16:54:51 +0200470 rcu_read_unlock();
471
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800472 return count;
473}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000474static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200475 bonding_show_active_slave, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800476
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200477/* Show link status of the bond interface. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700478static ssize_t bonding_show_mii_status(struct device *d,
479 struct device_attribute *attr,
480 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800481{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700482 struct bonding *bond = to_bond(d);
Jarod Wilsonc8086f62016-01-08 20:35:36 -0500483 bool active = netif_carrier_ok(bond->dev);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800484
Eric Dumazetc2646b52014-07-15 06:56:54 -0700485 return sprintf(buf, "%s\n", active ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800486}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700487static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800488
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200489/* Show current 802.3ad aggregator ID. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700490static ssize_t bonding_show_ad_aggregator(struct device *d,
491 struct device_attribute *attr,
492 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800493{
494 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700495 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800496
Veaceslav Falico01844092014-05-15 21:39:55 +0200497 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800498 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000499 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000500 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000501 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800502 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800503
504 return count;
505}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700506static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800507
508
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200509/* Show number of active 802.3ad ports. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700510static ssize_t bonding_show_ad_num_ports(struct device *d,
511 struct device_attribute *attr,
512 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800513{
514 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700515 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800516
Veaceslav Falico01844092014-05-15 21:39:55 +0200517 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800518 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000519 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000520 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000521 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800522 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800523
524 return count;
525}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700526static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800527
528
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200529/* Show current 802.3ad actor key. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700530static ssize_t bonding_show_ad_actor_key(struct device *d,
531 struct device_attribute *attr,
532 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800533{
534 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700535 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800536
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700537 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800538 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000539 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000540 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000541 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800542 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800543
544 return count;
545}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700546static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800547
548
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200549/* Show current 802.3ad partner key. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700550static ssize_t bonding_show_ad_partner_key(struct device *d,
551 struct device_attribute *attr,
552 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800553{
554 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700555 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800556
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700557 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800558 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000559 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000560 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000561 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800562 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800563
564 return count;
565}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700566static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800567
568
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200569/* Show current 802.3ad partner mac. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700570static ssize_t bonding_show_ad_partner_mac(struct device *d,
571 struct device_attribute *attr,
572 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800573{
574 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700575 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800576
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700577 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800578 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000579 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -0700580 count = sprintf(buf, "%pM\n", ad_info.partner_system);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800581 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800582
583 return count;
584}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700585static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800586
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200587/* Show the queue_ids of the slaves in the current bond. */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000588static ssize_t bonding_show_queue_id(struct device *d,
589 struct device_attribute *attr,
590 char *buf)
591{
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000592 struct bonding *bond = to_bond(d);
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200593 struct list_head *iter;
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200594 struct slave *slave;
595 int res = 0;
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000596
597 if (!rtnl_trylock())
598 return restart_syscall();
599
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200600 bond_for_each_slave(bond, slave, iter) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -0700601 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
602 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000603 if ((PAGE_SIZE - res) > 10)
604 res = PAGE_SIZE - 10;
605 res += sprintf(buf + res, "++more++ ");
606 break;
607 }
608 res += sprintf(buf + res, "%s:%d ",
609 slave->dev->name, slave->queue_id);
610 }
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000611 if (res)
612 buf[res-1] = '\n'; /* eat the leftover space */
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800613
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000614 rtnl_unlock();
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200615
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000616 return res;
617}
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000618static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200619 bonding_sysfs_store_option);
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000620
621
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200622/* Show the all_slaves_active flag. */
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000623static ssize_t bonding_show_slaves_active(struct device *d,
624 struct device_attribute *attr,
625 char *buf)
626{
627 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800628
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000629 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
630}
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000631static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200632 bonding_show_slaves_active, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800633
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200634/* Show the number of IGMP membership reports to send on link failure */
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000635static ssize_t bonding_show_resend_igmp(struct device *d,
Flavio Leitner94265cf2011-05-25 08:38:58 +0000636 struct device_attribute *attr,
637 char *buf)
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000638{
639 struct bonding *bond = to_bond(d);
640
641 return sprintf(buf, "%d\n", bond->params.resend_igmp);
642}
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000643static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200644 bonding_show_resend_igmp, bonding_sysfs_store_option);
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000645
Neil Horman7eacd032013-09-13 11:05:33 -0400646
647static ssize_t bonding_show_lp_interval(struct device *d,
648 struct device_attribute *attr,
649 char *buf)
650{
651 struct bonding *bond = to_bond(d);
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200652
Neil Horman7eacd032013-09-13 11:05:33 -0400653 return sprintf(buf, "%d\n", bond->params.lp_interval);
654}
Neil Horman7eacd032013-09-13 11:05:33 -0400655static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200656 bonding_show_lp_interval, bonding_sysfs_store_option);
Neil Horman7eacd032013-09-13 11:05:33 -0400657
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700658static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
659 struct device_attribute *attr,
660 char *buf)
661{
662 struct bonding *bond = to_bond(d);
663 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
664}
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700665static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200666 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700667
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100668static ssize_t bonding_show_packets_per_slave(struct device *d,
669 struct device_attribute *attr,
670 char *buf)
671{
672 struct bonding *bond = to_bond(d);
Nikolay Aleksandrova752a8b2013-12-05 11:36:58 +0100673 unsigned int packets_per_slave = bond->params.packets_per_slave;
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200674
Nikolay Aleksandrova752a8b2013-12-05 11:36:58 +0100675 return sprintf(buf, "%u\n", packets_per_slave);
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100676}
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100677static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200678 bonding_show_packets_per_slave, bonding_sysfs_store_option);
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100679
Mahesh Bandewar6791e462015-05-09 00:01:55 -0700680static ssize_t bonding_show_ad_actor_sys_prio(struct device *d,
681 struct device_attribute *attr,
682 char *buf)
683{
684 struct bonding *bond = to_bond(d);
685
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700686 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
Mahesh Bandewar6791e462015-05-09 00:01:55 -0700687 return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio);
688
689 return 0;
690}
691static DEVICE_ATTR(ad_actor_sys_prio, S_IRUGO | S_IWUSR,
692 bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option);
693
Mahesh Bandewar74514952015-05-09 00:01:56 -0700694static ssize_t bonding_show_ad_actor_system(struct device *d,
695 struct device_attribute *attr,
696 char *buf)
697{
698 struct bonding *bond = to_bond(d);
699
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700700 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
Mahesh Bandewar74514952015-05-09 00:01:56 -0700701 return sprintf(buf, "%pM\n", bond->params.ad_actor_system);
702
703 return 0;
704}
705
706static DEVICE_ATTR(ad_actor_system, S_IRUGO | S_IWUSR,
707 bonding_show_ad_actor_system, bonding_sysfs_store_option);
708
Mahesh Bandeward22a5fc2015-05-09 00:01:57 -0700709static ssize_t bonding_show_ad_user_port_key(struct device *d,
710 struct device_attribute *attr,
711 char *buf)
712{
713 struct bonding *bond = to_bond(d);
714
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700715 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
Mahesh Bandeward22a5fc2015-05-09 00:01:57 -0700716 return sprintf(buf, "%hu\n", bond->params.ad_user_port_key);
717
718 return 0;
719}
720static DEVICE_ATTR(ad_user_port_key, S_IRUGO | S_IWUSR,
721 bonding_show_ad_user_port_key, bonding_sysfs_store_option);
722
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800723static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700724 &dev_attr_slaves.attr,
725 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -0700726 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700727 &dev_attr_arp_validate.attr,
Veaceslav Falico8599b522013-06-24 11:49:34 +0200728 &dev_attr_arp_all_targets.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700729 &dev_attr_arp_interval.attr,
730 &dev_attr_arp_ip_target.attr,
731 &dev_attr_downdelay.attr,
732 &dev_attr_updelay.attr,
733 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -0800734 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700735 &dev_attr_xmit_hash_policy.attr,
Ben Hutchingsad246c92011-04-26 15:25:52 +0000736 &dev_attr_num_grat_arp.attr,
737 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700738 &dev_attr_miimon.attr,
739 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +0000740 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700741 &dev_attr_use_carrier.attr,
742 &dev_attr_active_slave.attr,
743 &dev_attr_mii_status.attr,
744 &dev_attr_ad_aggregator.attr,
745 &dev_attr_ad_num_ports.attr,
746 &dev_attr_ad_actor_key.attr,
747 &dev_attr_ad_partner_key.attr,
748 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000749 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000750 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000751 &dev_attr_resend_igmp.attr,
stephen hemminger655f8912011-06-22 09:54:39 +0000752 &dev_attr_min_links.attr,
Neil Horman7eacd032013-09-13 11:05:33 -0400753 &dev_attr_lp_interval.attr,
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100754 &dev_attr_packets_per_slave.attr,
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700755 &dev_attr_tlb_dynamic_lb.attr,
Mahesh Bandewar6791e462015-05-09 00:01:55 -0700756 &dev_attr_ad_actor_sys_prio.attr,
Mahesh Bandewar74514952015-05-09 00:01:56 -0700757 &dev_attr_ad_actor_system.attr,
Mahesh Bandeward22a5fc2015-05-09 00:01:57 -0700758 &dev_attr_ad_user_port_key.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800759 NULL,
760};
761
762static struct attribute_group bonding_group = {
763 .name = "bonding",
764 .attrs = per_bond_attrs,
765};
766
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200767/* Initialize sysfs. This sets up the bonding_masters file in
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800768 * /sys/class/net.
769 */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000770int bond_create_sysfs(struct bond_net *bn)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800771{
Jay Vosburghb8a97872008-06-13 18:12:04 -0700772 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800773
Eric W. Biederman4c224002011-10-12 21:56:25 +0000774 bn->class_attr_bonding_masters = class_attr_bonding_masters;
Eric W. Biederman01718e32011-10-21 22:43:07 +0000775 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
Eric W. Biederman4c224002011-10-12 21:56:25 +0000776
Tejun Heo58292cbe2013-09-11 22:29:04 -0400777 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
778 bn->net);
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200779 /* Permit multiple loads of the module by ignoring failures to
Jay Vosburgh877cbd32007-01-19 18:15:47 -0800780 * create the bonding_masters sysfs file. Bonding devices
781 * created by second or subsequent loads of the module will
782 * not be listed in, or controllable by, bonding_masters, but
783 * will have the usual "bonding" sysfs directory.
784 *
785 * This is done to preserve backwards compatibility for
786 * initscripts/sysconfig, which load bonding multiple times to
787 * configure multiple bonding devices.
788 */
789 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700790 /* Is someone being kinky and naming a device bonding_master? */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000791 if (__dev_get_by_name(bn->net,
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700792 class_attr_bonding_masters.attr.name))
Joe Perches90194262014-02-15 16:01:45 -0800793 pr_err("network device named %s already exists in sysfs\n",
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700794 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -0700795 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -0800796 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800797
798 return ret;
799
800}
801
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200802/* Remove /sys/class/net/bonding_masters. */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000803void bond_destroy_sysfs(struct bond_net *bn)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800804{
Tejun Heo58292cbe2013-09-11 22:29:04 -0400805 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800806}
807
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200808/* Initialize sysfs for each bond. This sets up and registers
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800809 * the 'bondctl' directory for each individual bond under /sys/class/net.
810 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +0000811void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800812{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +0000813 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800814}
815