blob: f4ae720862158354d028169de77cafe782f539fa [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 Aleksandrov205845a2015-07-24 15:50:31 +0200383/* Show 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}
Ben Hutchingsad246c92011-04-26 15:25:52 +0000391static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR,
Nikolay Aleksandrov205845a2015-07-24 15:50:31 +0200392 bonding_show_num_peer_notif, bonding_sysfs_store_option);
Ben Hutchingsad246c92011-04-26 15:25:52 +0000393static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR,
Nikolay Aleksandrov205845a2015-07-24 15:50:31 +0200394 bonding_show_num_peer_notif, bonding_sysfs_store_option);
Ben Hutchingsad246c92011-04-26 15:25:52 +0000395
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200396/* Show the MII monitor interval. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700397static ssize_t bonding_show_miimon(struct device *d,
398 struct device_attribute *attr,
399 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800400{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700401 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800402
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800403 return sprintf(buf, "%d\n", bond->params.miimon);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800404}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000405static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200406 bonding_show_miimon, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800407
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200408/* Show the primary slave. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700409static ssize_t bonding_show_primary(struct device *d,
410 struct device_attribute *attr,
411 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800412{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700413 struct bonding *bond = to_bond(d);
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +0200414 struct slave *primary;
415 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800416
Nikolay Aleksandrov059b47e2014-09-09 23:17:00 +0200417 rcu_read_lock();
418 primary = rcu_dereference(bond->primary_slave);
419 if (primary)
420 count = sprintf(buf, "%s\n", primary->dev->name);
421 rcu_read_unlock();
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800422
423 return count;
424}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000425static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200426 bonding_show_primary, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800427
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200428/* Show the primary_reselect flag. */
Jiri Pirkoa5499522009-09-25 03:28:09 +0000429static ssize_t bonding_show_primary_reselect(struct device *d,
430 struct device_attribute *attr,
431 char *buf)
432{
433 struct bonding *bond = to_bond(d);
stephen hemmingerf3253332014-03-04 16:36:44 -0800434 const struct bond_opt_value *val;
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100435
436 val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT,
437 bond->params.primary_reselect);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000438
439 return sprintf(buf, "%s %d\n",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100440 val->string, bond->params.primary_reselect);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000441}
Jiri Pirkoa5499522009-09-25 03:28:09 +0000442static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200443 bonding_show_primary_reselect, bonding_sysfs_store_option);
Jiri Pirkoa5499522009-09-25 03:28:09 +0000444
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200445/* Show the use_carrier flag. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700446static ssize_t bonding_show_carrier(struct device *d,
447 struct device_attribute *attr,
448 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800449{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700450 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800451
Wagner Ferenc7bd46502007-12-06 23:40:28 -0800452 return sprintf(buf, "%d\n", bond->params.use_carrier);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800453}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000454static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200455 bonding_show_carrier, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800456
457
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200458/* Show currently active_slave. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700459static ssize_t bonding_show_active_slave(struct device *d,
460 struct device_attribute *attr,
461 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800462{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700463 struct bonding *bond = to_bond(d);
Jiri Pirko752d48b2013-10-18 17:43:37 +0200464 struct net_device *slave_dev;
Wagner Ferenc16cd0162007-12-06 23:40:29 -0800465 int count = 0;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800466
nikolay@redhat.com278b2082013-08-01 16:54:51 +0200467 rcu_read_lock();
Jiri Pirko752d48b2013-10-18 17:43:37 +0200468 slave_dev = bond_option_active_slave_get_rcu(bond);
469 if (slave_dev)
470 count = sprintf(buf, "%s\n", slave_dev->name);
nikolay@redhat.com278b2082013-08-01 16:54:51 +0200471 rcu_read_unlock();
472
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800473 return count;
474}
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000475static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200476 bonding_show_active_slave, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800477
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200478/* Show link status of the bond interface. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700479static ssize_t bonding_show_mii_status(struct device *d,
480 struct device_attribute *attr,
481 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800482{
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700483 struct bonding *bond = to_bond(d);
Eric Dumazetc2646b52014-07-15 06:56:54 -0700484 bool active = !!rcu_access_pointer(bond->curr_active_slave);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800485
Eric Dumazetc2646b52014-07-15 06:56:54 -0700486 return sprintf(buf, "%s\n", active ? "up" : "down");
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800487}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700488static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800489
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200490/* Show current 802.3ad aggregator ID. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700491static ssize_t bonding_show_ad_aggregator(struct device *d,
492 struct device_attribute *attr,
493 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800494{
495 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700496 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800497
Veaceslav Falico01844092014-05-15 21:39:55 +0200498 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800499 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000500 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000501 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000502 ? 0 : ad_info.aggregator_id);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800503 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800504
505 return count;
506}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700507static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800508
509
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200510/* Show number of active 802.3ad ports. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700511static ssize_t bonding_show_ad_num_ports(struct device *d,
512 struct device_attribute *attr,
513 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800514{
515 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700516 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800517
Veaceslav Falico01844092014-05-15 21:39:55 +0200518 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800519 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000520 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000521 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000522 ? 0 : ad_info.ports);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800523 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800524
525 return count;
526}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700527static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800528
529
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200530/* Show current 802.3ad actor key. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700531static ssize_t bonding_show_ad_actor_key(struct device *d,
532 struct device_attribute *attr,
533 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800534{
535 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700536 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800537
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700538 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800539 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000540 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000541 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000542 ? 0 : ad_info.actor_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800543 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800544
545 return count;
546}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700547static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800548
549
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200550/* Show current 802.3ad partner key. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700551static ssize_t bonding_show_ad_partner_key(struct device *d,
552 struct device_attribute *attr,
553 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800554{
555 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700556 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800557
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700558 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800559 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000560 count = sprintf(buf, "%d\n",
nikolay@redhat.com318debd2013-05-18 01:18:31 +0000561 bond_3ad_get_active_agg_info(bond, &ad_info)
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000562 ? 0 : ad_info.partner_key);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800563 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800564
565 return count;
566}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700567static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800568
569
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200570/* Show current 802.3ad partner mac. */
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700571static ssize_t bonding_show_ad_partner_mac(struct device *d,
572 struct device_attribute *attr,
573 char *buf)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800574{
575 int count = 0;
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700576 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800577
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700578 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) {
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800579 struct ad_info ad_info;
Stephen Hemminger3d632c32009-06-12 19:02:48 +0000580 if (!bond_3ad_get_active_agg_info(bond, &ad_info))
Johannes Berge1749612008-10-27 15:59:26 -0700581 count = sprintf(buf, "%pM\n", ad_info.partner_system);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800582 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800583
584 return count;
585}
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700586static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800587
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200588/* Show the queue_ids of the slaves in the current bond. */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000589static ssize_t bonding_show_queue_id(struct device *d,
590 struct device_attribute *attr,
591 char *buf)
592{
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000593 struct bonding *bond = to_bond(d);
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200594 struct list_head *iter;
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200595 struct slave *slave;
596 int res = 0;
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000597
598 if (!rtnl_trylock())
599 return restart_syscall();
600
Veaceslav Falico9caff1e2013-09-25 09:20:14 +0200601 bond_for_each_slave(bond, slave, iter) {
Nicolas de Pesloüan79236682010-07-14 18:24:54 -0700602 if (res > (PAGE_SIZE - IFNAMSIZ - 6)) {
603 /* not enough space for another interface_name:queue_id pair */
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000604 if ((PAGE_SIZE - res) > 10)
605 res = PAGE_SIZE - 10;
606 res += sprintf(buf + res, "++more++ ");
607 break;
608 }
609 res += sprintf(buf + res, "%s:%d ",
610 slave->dev->name, slave->queue_id);
611 }
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000612 if (res)
613 buf[res-1] = '\n'; /* eat the leftover space */
dingtianhong4d1ae5f2013-10-15 16:28:42 +0800614
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000615 rtnl_unlock();
nikolay@redhat.comdec1e902013-08-01 16:54:47 +0200616
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000617 return res;
618}
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000619static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200620 bonding_sysfs_store_option);
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000621
622
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200623/* Show the all_slaves_active flag. */
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000624static ssize_t bonding_show_slaves_active(struct device *d,
625 struct device_attribute *attr,
626 char *buf)
627{
628 struct bonding *bond = to_bond(d);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800629
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000630 return sprintf(buf, "%d\n", bond->params.all_slaves_active);
631}
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000632static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200633 bonding_show_slaves_active, bonding_sysfs_store_option);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800634
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200635/* Show the number of IGMP membership reports to send on link failure */
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000636static ssize_t bonding_show_resend_igmp(struct device *d,
Flavio Leitner94265cf2011-05-25 08:38:58 +0000637 struct device_attribute *attr,
638 char *buf)
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000639{
640 struct bonding *bond = to_bond(d);
641
642 return sprintf(buf, "%d\n", bond->params.resend_igmp);
643}
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000644static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200645 bonding_show_resend_igmp, bonding_sysfs_store_option);
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000646
Neil Horman7eacd032013-09-13 11:05:33 -0400647
648static ssize_t bonding_show_lp_interval(struct device *d,
649 struct device_attribute *attr,
650 char *buf)
651{
652 struct bonding *bond = to_bond(d);
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200653
Neil Horman7eacd032013-09-13 11:05:33 -0400654 return sprintf(buf, "%d\n", bond->params.lp_interval);
655}
Neil Horman7eacd032013-09-13 11:05:33 -0400656static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200657 bonding_show_lp_interval, bonding_sysfs_store_option);
Neil Horman7eacd032013-09-13 11:05:33 -0400658
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700659static ssize_t bonding_show_tlb_dynamic_lb(struct device *d,
660 struct device_attribute *attr,
661 char *buf)
662{
663 struct bonding *bond = to_bond(d);
664 return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb);
665}
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700666static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200667 bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option);
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700668
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100669static ssize_t bonding_show_packets_per_slave(struct device *d,
670 struct device_attribute *attr,
671 char *buf)
672{
673 struct bonding *bond = to_bond(d);
Nikolay Aleksandrova752a8b2013-12-05 11:36:58 +0100674 unsigned int packets_per_slave = bond->params.packets_per_slave;
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200675
Nikolay Aleksandrova752a8b2013-12-05 11:36:58 +0100676 return sprintf(buf, "%u\n", packets_per_slave);
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100677}
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100678static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200679 bonding_show_packets_per_slave, bonding_sysfs_store_option);
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100680
Mahesh Bandewar6791e462015-05-09 00:01:55 -0700681static ssize_t bonding_show_ad_actor_sys_prio(struct device *d,
682 struct device_attribute *attr,
683 char *buf)
684{
685 struct bonding *bond = to_bond(d);
686
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700687 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
Mahesh Bandewar6791e462015-05-09 00:01:55 -0700688 return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio);
689
690 return 0;
691}
692static DEVICE_ATTR(ad_actor_sys_prio, S_IRUGO | S_IWUSR,
693 bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option);
694
Mahesh Bandewar74514952015-05-09 00:01:56 -0700695static ssize_t bonding_show_ad_actor_system(struct device *d,
696 struct device_attribute *attr,
697 char *buf)
698{
699 struct bonding *bond = to_bond(d);
700
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700701 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
Mahesh Bandewar74514952015-05-09 00:01:56 -0700702 return sprintf(buf, "%pM\n", bond->params.ad_actor_system);
703
704 return 0;
705}
706
707static DEVICE_ATTR(ad_actor_system, S_IRUGO | S_IWUSR,
708 bonding_show_ad_actor_system, bonding_sysfs_store_option);
709
Mahesh Bandeward22a5fc2015-05-09 00:01:57 -0700710static ssize_t bonding_show_ad_user_port_key(struct device *d,
711 struct device_attribute *attr,
712 char *buf)
713{
714 struct bonding *bond = to_bond(d);
715
Mahesh Bandewar4cd6b472015-06-18 11:30:54 -0700716 if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN))
Mahesh Bandeward22a5fc2015-05-09 00:01:57 -0700717 return sprintf(buf, "%hu\n", bond->params.ad_user_port_key);
718
719 return 0;
720}
721static DEVICE_ATTR(ad_user_port_key, S_IRUGO | S_IWUSR,
722 bonding_show_ad_user_port_key, bonding_sysfs_store_option);
723
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800724static struct attribute *per_bond_attrs[] = {
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700725 &dev_attr_slaves.attr,
726 &dev_attr_mode.attr,
Jay Vosburghdd957c52007-10-09 19:57:24 -0700727 &dev_attr_fail_over_mac.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700728 &dev_attr_arp_validate.attr,
Veaceslav Falico8599b522013-06-24 11:49:34 +0200729 &dev_attr_arp_all_targets.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700730 &dev_attr_arp_interval.attr,
731 &dev_attr_arp_ip_target.attr,
732 &dev_attr_downdelay.attr,
733 &dev_attr_updelay.attr,
734 &dev_attr_lacp_rate.attr,
Jay Vosburghfd989c82008-11-04 17:51:16 -0800735 &dev_attr_ad_select.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700736 &dev_attr_xmit_hash_policy.attr,
Ben Hutchingsad246c92011-04-26 15:25:52 +0000737 &dev_attr_num_grat_arp.attr,
738 &dev_attr_num_unsol_na.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700739 &dev_attr_miimon.attr,
740 &dev_attr_primary.attr,
Jiri Pirkoa5499522009-09-25 03:28:09 +0000741 &dev_attr_primary_reselect.attr,
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -0700742 &dev_attr_use_carrier.attr,
743 &dev_attr_active_slave.attr,
744 &dev_attr_mii_status.attr,
745 &dev_attr_ad_aggregator.attr,
746 &dev_attr_ad_num_ports.attr,
747 &dev_attr_ad_actor_key.attr,
748 &dev_attr_ad_partner_key.attr,
749 &dev_attr_ad_partner_mac.attr,
Andy Gospodarekbb1d9122010-06-02 08:40:18 +0000750 &dev_attr_queue_id.attr,
Andy Gospodarekebd8e492010-06-02 08:39:21 +0000751 &dev_attr_all_slaves_active.attr,
Flavio Leitnerc2952c32010-10-05 14:23:59 +0000752 &dev_attr_resend_igmp.attr,
stephen hemminger655f8912011-06-22 09:54:39 +0000753 &dev_attr_min_links.attr,
Neil Horman7eacd032013-09-13 11:05:33 -0400754 &dev_attr_lp_interval.attr,
Nikolay Aleksandrov73958322013-11-05 13:51:41 +0100755 &dev_attr_packets_per_slave.attr,
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700756 &dev_attr_tlb_dynamic_lb.attr,
Mahesh Bandewar6791e462015-05-09 00:01:55 -0700757 &dev_attr_ad_actor_sys_prio.attr,
Mahesh Bandewar74514952015-05-09 00:01:56 -0700758 &dev_attr_ad_actor_system.attr,
Mahesh Bandeward22a5fc2015-05-09 00:01:57 -0700759 &dev_attr_ad_user_port_key.attr,
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800760 NULL,
761};
762
763static struct attribute_group bonding_group = {
764 .name = "bonding",
765 .attrs = per_bond_attrs,
766};
767
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200768/* Initialize sysfs. This sets up the bonding_masters file in
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800769 * /sys/class/net.
770 */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000771int bond_create_sysfs(struct bond_net *bn)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800772{
Jay Vosburghb8a97872008-06-13 18:12:04 -0700773 int ret;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800774
Eric W. Biederman4c224002011-10-12 21:56:25 +0000775 bn->class_attr_bonding_masters = class_attr_bonding_masters;
Eric W. Biederman01718e32011-10-21 22:43:07 +0000776 sysfs_attr_init(&bn->class_attr_bonding_masters.attr);
Eric W. Biederman4c224002011-10-12 21:56:25 +0000777
Tejun Heo58292cbe2013-09-11 22:29:04 -0400778 ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters,
779 bn->net);
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200780 /* Permit multiple loads of the module by ignoring failures to
Jay Vosburgh877cbd32007-01-19 18:15:47 -0800781 * create the bonding_masters sysfs file. Bonding devices
782 * created by second or subsequent loads of the module will
783 * not be listed in, or controllable by, bonding_masters, but
784 * will have the usual "bonding" sysfs directory.
785 *
786 * This is done to preserve backwards compatibility for
787 * initscripts/sysconfig, which load bonding multiple times to
788 * configure multiple bonding devices.
789 */
790 if (ret == -EEXIST) {
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700791 /* Is someone being kinky and naming a device bonding_master? */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000792 if (__dev_get_by_name(bn->net,
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700793 class_attr_bonding_masters.attr.name))
Joe Perches90194262014-02-15 16:01:45 -0800794 pr_err("network device named %s already exists in sysfs\n",
Stephen Hemminger38d2f382008-05-14 22:35:04 -0700795 class_attr_bonding_masters.attr.name);
Stephen Hemminger130aa612009-06-11 05:46:04 -0700796 ret = 0;
Jay Vosburgh877cbd32007-01-19 18:15:47 -0800797 }
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800798
799 return ret;
800
801}
802
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200803/* Remove /sys/class/net/bonding_masters. */
Eric W. Biederman4c224002011-10-12 21:56:25 +0000804void bond_destroy_sysfs(struct bond_net *bn)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800805{
Tejun Heo58292cbe2013-09-11 22:29:04 -0400806 netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net);
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800807}
808
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200809/* Initialize sysfs for each bond. This sets up and registers
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800810 * the 'bondctl' directory for each individual bond under /sys/class/net.
811 */
Eric W. Biederman6151b3d2009-10-29 14:18:22 +0000812void bond_prepare_sysfs_group(struct bonding *bond)
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800813{
Eric W. Biederman6151b3d2009-10-29 14:18:22 +0000814 bond->dev->sysfs_groups[0] = &bonding_group;
Mitch Williamsb76cdba2005-11-09 10:36:41 -0800815}
816