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