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 |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 21 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 22 | |
| 23 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 24 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 27 | #include <linux/device.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 28 | #include <linux/sched.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 29 | #include <linux/fs.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/netdevice.h> |
| 33 | #include <linux/inetdevice.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/sysfs.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 36 | #include <linux/ctype.h> |
| 37 | #include <linux/inet.h> |
| 38 | #include <linux/rtnetlink.h> |
Stephen Hemminger | 5c5129b | 2009-06-12 19:02:51 +0000 | [diff] [blame] | 39 | #include <linux/etherdevice.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 40 | #include <net/net_namespace.h> |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 41 | #include <net/netns/generic.h> |
| 42 | #include <linux/nsproxy.h> |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 43 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 44 | #include "bonding.h" |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 45 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 46 | #define to_dev(obj) container_of(obj, struct device, kobj) |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 47 | #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 48 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 49 | /* |
| 50 | * "show" function for the bond_masters attribute. |
| 51 | * The class parameter is ignored. |
| 52 | */ |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 53 | static ssize_t bonding_show_bonds(struct class *cls, |
| 54 | struct class_attribute *attr, |
| 55 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 56 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 57 | struct bond_net *bn = |
| 58 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 59 | int res = 0; |
| 60 | struct bonding *bond; |
| 61 | |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 62 | rtnl_lock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 63 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 64 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 65 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 66 | /* not enough space for another interface name */ |
| 67 | if ((PAGE_SIZE - res) > 10) |
| 68 | res = PAGE_SIZE - 10; |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 69 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 70 | break; |
| 71 | } |
Wagner Ferenc | b884366 | 2007-12-06 23:40:30 -0800 | [diff] [blame] | 72 | res += sprintf(buf + res, "%s ", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 73 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 74 | if (res) |
| 75 | buf[res-1] = '\n'; /* eat the leftover space */ |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 76 | |
| 77 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 78 | return res; |
| 79 | } |
| 80 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 81 | 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] | 82 | { |
| 83 | struct bonding *bond; |
| 84 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 85 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 86 | if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) |
| 87 | return bond->dev; |
| 88 | } |
| 89 | return NULL; |
| 90 | } |
| 91 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 92 | /* |
| 93 | * "store" function for the bond_masters attribute. This is what |
| 94 | * creates and deletes entire bonds. |
| 95 | * |
| 96 | * The class parameter is ignored. |
| 97 | * |
| 98 | */ |
| 99 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 100 | static ssize_t bonding_store_bonds(struct class *cls, |
Andi Kleen | 28812fe | 2010-01-05 12:48:07 +0100 | [diff] [blame] | 101 | struct class_attribute *attr, |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 102 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 103 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 104 | struct bond_net *bn = |
| 105 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 106 | char command[IFNAMSIZ + 1] = {0, }; |
| 107 | char *ifname; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 108 | int rv, res = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 109 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 110 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 111 | ifname = command + 1; |
| 112 | if ((strlen(command) <= 1) || |
| 113 | !dev_valid_name(ifname)) |
| 114 | goto err_no_cmd; |
| 115 | |
| 116 | if (command[0] == '+') { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 117 | pr_info("%s is being created...\n", ifname); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 118 | rv = bond_create(bn->net, ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 119 | if (rv) { |
Phil Oester | 5f86cad1 | 2011-03-14 06:22:06 +0000 | [diff] [blame] | 120 | if (rv == -EEXIST) |
| 121 | pr_info("%s already exists.\n", ifname); |
| 122 | else |
| 123 | pr_info("%s creation failed.\n", ifname); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 124 | res = rv; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 125 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 126 | } else if (command[0] == '-') { |
| 127 | struct net_device *bond_dev; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 128 | |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 129 | rtnl_lock(); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 130 | bond_dev = bond_get_by_name(bn, ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 131 | if (bond_dev) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 132 | pr_info("%s is being deleted...\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 133 | unregister_netdevice(bond_dev); |
| 134 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 135 | pr_err("unable to delete non-existent %s\n", ifname); |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 136 | res = -ENODEV; |
| 137 | } |
| 138 | rtnl_unlock(); |
| 139 | } else |
| 140 | goto err_no_cmd; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 141 | |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 142 | /* Always return either count or an error. If you return 0, you'll |
| 143 | * get called forever, which is bad. |
| 144 | */ |
| 145 | return res; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 146 | |
| 147 | err_no_cmd: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 148 | 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] | 149 | return -EPERM; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 150 | } |
Stephen Hemminger | 373500d | 2009-06-12 19:02:50 +0000 | [diff] [blame] | 151 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 152 | static const void *bonding_namespace(struct class *cls, |
| 153 | const struct class_attribute *attr) |
| 154 | { |
| 155 | const struct bond_net *bn = |
| 156 | container_of(attr, struct bond_net, class_attr_bonding_masters); |
| 157 | return bn->net; |
| 158 | } |
| 159 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 160 | /* 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] | 161 | static const struct class_attribute class_attr_bonding_masters = { |
| 162 | .attr = { |
| 163 | .name = "bonding_masters", |
| 164 | .mode = S_IWUSR | S_IRUGO, |
| 165 | }, |
| 166 | .show = bonding_show_bonds, |
| 167 | .store = bonding_store_bonds, |
| 168 | .namespace = bonding_namespace, |
| 169 | }; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 170 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 171 | /* |
| 172 | * Show the slaves in the current bond. |
| 173 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 174 | static ssize_t bonding_show_slaves(struct device *d, |
| 175 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 176 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 177 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 178 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 179 | struct slave *slave; |
| 180 | int res = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 181 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 182 | read_lock(&bond->lock); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 183 | bond_for_each_slave(bond, slave, iter) { |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 184 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
| 185 | /* not enough space for another interface name */ |
| 186 | if ((PAGE_SIZE - res) > 10) |
| 187 | res = PAGE_SIZE - 10; |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 188 | res += sprintf(buf + res, "++more++ "); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 189 | break; |
| 190 | } |
| 191 | res += sprintf(buf + res, "%s ", slave->dev->name); |
| 192 | } |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 193 | read_unlock(&bond->lock); |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 194 | if (res) |
| 195 | buf[res-1] = '\n'; /* eat the leftover space */ |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 196 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 197 | return res; |
| 198 | } |
| 199 | |
| 200 | /* |
Veaceslav Falico | d6641cc | 2013-05-28 01:26:13 +0000 | [diff] [blame] | 201 | * Set the slaves in the current bond. |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 202 | * This is supposed to be only thin wrapper for bond_enslave and bond_release. |
| 203 | * All hard work should be done there. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 204 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 205 | static ssize_t bonding_store_slaves(struct device *d, |
| 206 | struct device_attribute *attr, |
| 207 | const char *buffer, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 208 | { |
| 209 | char command[IFNAMSIZ + 1] = { 0, }; |
| 210 | char *ifname; |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 211 | int res, ret = count; |
| 212 | struct net_device *dev; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 213 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 214 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 215 | if (!rtnl_trylock()) |
| 216 | return restart_syscall(); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 217 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 218 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
| 219 | ifname = command + 1; |
| 220 | if ((strlen(command) <= 1) || |
| 221 | !dev_valid_name(ifname)) |
| 222 | goto err_no_cmd; |
| 223 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 224 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 225 | if (!dev) { |
| 226 | pr_info("%s: Interface %s does not exist!\n", |
| 227 | bond->dev->name, ifname); |
| 228 | ret = -ENODEV; |
| 229 | goto out; |
| 230 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 231 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 232 | switch (command[0]) { |
| 233 | case '+': |
| 234 | pr_info("%s: Adding slave %s.\n", bond->dev->name, dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 235 | res = bond_enslave(bond->dev, dev); |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 236 | break; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 237 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 238 | case '-': |
| 239 | pr_info("%s: Removing slave %s.\n", bond->dev->name, dev->name); |
| 240 | res = bond_release(bond->dev, dev); |
| 241 | break; |
| 242 | |
| 243 | default: |
| 244 | goto err_no_cmd; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Jiri Pirko | f9f3545 | 2010-05-18 05:46:39 +0000 | [diff] [blame] | 247 | if (res) |
| 248 | ret = res; |
| 249 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 250 | |
| 251 | err_no_cmd: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 252 | pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n", |
| 253 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 254 | ret = -EPERM; |
| 255 | |
| 256 | out: |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 257 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 258 | return ret; |
| 259 | } |
| 260 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 261 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, |
| 262 | bonding_store_slaves); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * Show and set the bonding mode. The bond interface must be down to |
| 266 | * change the mode. |
| 267 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 268 | static ssize_t bonding_show_mode(struct device *d, |
| 269 | struct device_attribute *attr, char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 270 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 271 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 272 | |
| 273 | return sprintf(buf, "%s %d\n", |
| 274 | bond_mode_tbl[bond->params.mode].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 275 | bond->params.mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 278 | static ssize_t bonding_store_mode(struct device *d, |
| 279 | struct device_attribute *attr, |
| 280 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 281 | { |
| 282 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 283 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 284 | |
nikolay@redhat.com | ea6836d | 2013-05-18 01:18:28 +0000 | [diff] [blame] | 285 | if (!rtnl_trylock()) |
| 286 | return restart_syscall(); |
| 287 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 288 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 289 | pr_err("unable to update mode of %s because interface is up.\n", |
| 290 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 291 | ret = -EPERM; |
| 292 | goto out; |
| 293 | } |
| 294 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 295 | if (bond_has_slaves(bond)) { |
Veaceslav Falico | 4a8bb7e | 2011-11-15 06:44:42 +0000 | [diff] [blame] | 296 | pr_err("unable to update mode of %s because it has slaves.\n", |
| 297 | bond->dev->name); |
| 298 | ret = -EPERM; |
| 299 | goto out; |
| 300 | } |
| 301 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 302 | new_value = bond_parse_parm(buf, bond_mode_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 303 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 304 | pr_err("%s: Ignoring invalid mode value %.*s.\n", |
| 305 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 306 | ret = -EINVAL; |
| 307 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 308 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 309 | if ((new_value == BOND_MODE_ALB || |
| 310 | new_value == BOND_MODE_TLB) && |
| 311 | bond->params.arp_interval) { |
| 312 | pr_err("%s: %s mode is incompatible with arp monitoring.\n", |
| 313 | bond->dev->name, bond_mode_tbl[new_value].modename); |
| 314 | ret = -EINVAL; |
| 315 | goto out; |
| 316 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 317 | |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 318 | /* don't cache arp_validate between modes */ |
| 319 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 320 | bond->params.mode = new_value; |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 321 | pr_info("%s: setting mode to %s (%d).\n", |
| 322 | bond->dev->name, bond_mode_tbl[new_value].modename, |
| 323 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 324 | out: |
nikolay@redhat.com | ea6836d | 2013-05-18 01:18:28 +0000 | [diff] [blame] | 325 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 326 | return ret; |
| 327 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 328 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
| 329 | bonding_show_mode, bonding_store_mode); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 330 | |
| 331 | /* |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 332 | * Show and set the bonding transmit hash method. |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 333 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 334 | static ssize_t bonding_show_xmit_hash(struct device *d, |
| 335 | struct device_attribute *attr, |
| 336 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 337 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 338 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 339 | |
Wagner Ferenc | 8e4b932 | 2007-12-06 23:40:32 -0800 | [diff] [blame] | 340 | return sprintf(buf, "%s %d\n", |
| 341 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, |
| 342 | bond->params.xmit_policy); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 345 | static ssize_t bonding_store_xmit_hash(struct device *d, |
| 346 | struct device_attribute *attr, |
| 347 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 348 | { |
| 349 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 350 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 351 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 352 | new_value = bond_parse_parm(buf, xmit_hashtype_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 353 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 354 | pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 355 | bond->dev->name, |
| 356 | (int)strlen(buf) - 1, buf); |
| 357 | ret = -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 358 | } else { |
| 359 | bond->params.xmit_policy = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 360 | pr_info("%s: setting xmit hash policy to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 361 | bond->dev->name, |
| 362 | xmit_hashtype_tbl[new_value].modename, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 363 | } |
Nikolay Aleksandrov | 53edee2 | 2013-05-24 00:59:47 +0000 | [diff] [blame] | 364 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 365 | return ret; |
| 366 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 367 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
| 368 | bonding_show_xmit_hash, bonding_store_xmit_hash); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 369 | |
| 370 | /* |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 371 | * Show and set arp_validate. |
| 372 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 373 | static ssize_t bonding_show_arp_validate(struct device *d, |
| 374 | struct device_attribute *attr, |
| 375 | char *buf) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 376 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 377 | struct bonding *bond = to_bond(d); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 378 | |
| 379 | return sprintf(buf, "%s %d\n", |
| 380 | arp_validate_tbl[bond->params.arp_validate].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 381 | bond->params.arp_validate); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 384 | static ssize_t bonding_store_arp_validate(struct device *d, |
| 385 | struct device_attribute *attr, |
| 386 | const char *buf, size_t count) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 387 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 388 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 389 | int new_value, ret = count; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 390 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 391 | if (!rtnl_trylock()) |
| 392 | return restart_syscall(); |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 393 | new_value = bond_parse_parm(buf, arp_validate_tbl); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 394 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 395 | pr_err("%s: Ignoring invalid arp_validate value %s\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 396 | bond->dev->name, buf); |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 397 | ret = -EINVAL; |
| 398 | goto out; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 399 | } |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 400 | if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 401 | pr_err("%s: arp_validate only supported in active-backup mode.\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 402 | bond->dev->name); |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 403 | ret = -EINVAL; |
| 404 | goto out; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 405 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 406 | pr_info("%s: setting arp_validate to %s (%d).\n", |
| 407 | bond->dev->name, arp_validate_tbl[new_value].modename, |
| 408 | new_value); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 409 | |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 410 | if (bond->dev->flags & IFF_UP) { |
| 411 | if (!new_value) |
| 412 | bond->recv_probe = NULL; |
| 413 | else if (bond->params.arp_interval) |
| 414 | bond->recv_probe = bond_arp_rcv; |
| 415 | } |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 416 | bond->params.arp_validate = new_value; |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 417 | out: |
| 418 | rtnl_unlock(); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 419 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 420 | return ret; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 423 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
| 424 | bonding_store_arp_validate); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 425 | /* |
| 426 | * Show and set arp_all_targets. |
| 427 | */ |
| 428 | static ssize_t bonding_show_arp_all_targets(struct device *d, |
| 429 | struct device_attribute *attr, |
| 430 | char *buf) |
| 431 | { |
| 432 | struct bonding *bond = to_bond(d); |
| 433 | int value = bond->params.arp_all_targets; |
| 434 | |
| 435 | return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename, |
| 436 | value); |
| 437 | } |
| 438 | |
| 439 | static ssize_t bonding_store_arp_all_targets(struct device *d, |
| 440 | struct device_attribute *attr, |
| 441 | const char *buf, size_t count) |
| 442 | { |
| 443 | struct bonding *bond = to_bond(d); |
| 444 | int new_value; |
| 445 | |
| 446 | new_value = bond_parse_parm(buf, arp_all_targets_tbl); |
| 447 | if (new_value < 0) { |
| 448 | pr_err("%s: Ignoring invalid arp_all_targets value %s\n", |
| 449 | bond->dev->name, buf); |
| 450 | return -EINVAL; |
| 451 | } |
| 452 | pr_info("%s: setting arp_all_targets to %s (%d).\n", |
| 453 | bond->dev->name, arp_all_targets_tbl[new_value].modename, |
| 454 | new_value); |
| 455 | |
| 456 | bond->params.arp_all_targets = new_value; |
| 457 | |
| 458 | return count; |
| 459 | } |
| 460 | |
| 461 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, |
| 462 | bonding_show_arp_all_targets, bonding_store_arp_all_targets); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 463 | |
| 464 | /* |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 465 | * Show and store fail_over_mac. User only allowed to change the |
| 466 | * value when there are no slaves. |
| 467 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 468 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
| 469 | struct device_attribute *attr, |
| 470 | char *buf) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 471 | { |
| 472 | struct bonding *bond = to_bond(d); |
| 473 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 474 | return sprintf(buf, "%s %d\n", |
| 475 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, |
| 476 | bond->params.fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 479 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
| 480 | struct device_attribute *attr, |
| 481 | const char *buf, size_t count) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 482 | { |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 483 | int new_value, ret = count; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 484 | struct bonding *bond = to_bond(d); |
| 485 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 486 | if (!rtnl_trylock()) |
| 487 | return restart_syscall(); |
| 488 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 489 | if (bond_has_slaves(bond)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 490 | pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n", |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 491 | bond->dev->name); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 492 | ret = -EPERM; |
| 493 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 496 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
| 497 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 498 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 499 | bond->dev->name, buf); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 500 | ret = -EINVAL; |
| 501 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 502 | } |
| 503 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 504 | bond->params.fail_over_mac = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 505 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", |
| 506 | bond->dev->name, fail_over_mac_tbl[new_value].modename, |
| 507 | new_value); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 508 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 509 | out: |
| 510 | rtnl_unlock(); |
| 511 | return ret; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 514 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
| 515 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 516 | |
| 517 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 518 | * Show and set the arp timer interval. There are two tricky bits |
| 519 | * here. First, if ARP monitoring is activated, then we must disable |
| 520 | * MII monitoring. Second, if the ARP timer isn't running, we must |
| 521 | * start it. |
| 522 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 523 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 524 | struct device_attribute *attr, |
| 525 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 526 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 527 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 528 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 529 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 530 | } |
| 531 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 532 | static ssize_t bonding_store_arp_interval(struct device *d, |
| 533 | struct device_attribute *attr, |
| 534 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 535 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 536 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 537 | int new_value, ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 538 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 539 | if (!rtnl_trylock()) |
| 540 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 541 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 542 | pr_err("%s: no arp_interval value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 543 | bond->dev->name); |
| 544 | ret = -EINVAL; |
| 545 | goto out; |
| 546 | } |
| 547 | if (new_value < 0) { |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 548 | pr_err("%s: Invalid arp_interval value %d not in range 0-%d; rejected.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 549 | bond->dev->name, new_value, INT_MAX); |
| 550 | ret = -EINVAL; |
| 551 | goto out; |
| 552 | } |
Andy Gospodarek | c5cb002 | 2010-07-28 15:13:56 +0000 | [diff] [blame] | 553 | if (bond->params.mode == BOND_MODE_ALB || |
| 554 | bond->params.mode == BOND_MODE_TLB) { |
| 555 | pr_info("%s: ARP monitoring cannot be used with ALB/TLB. Only MII monitoring is supported on %s.\n", |
| 556 | bond->dev->name, bond->dev->name); |
| 557 | ret = -EINVAL; |
| 558 | goto out; |
| 559 | } |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 560 | pr_info("%s: Setting ARP monitoring interval to %d.\n", |
| 561 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 562 | bond->params.arp_interval = new_value; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 563 | if (new_value) { |
| 564 | if (bond->params.miimon) { |
| 565 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", |
| 566 | bond->dev->name, bond->dev->name); |
| 567 | bond->params.miimon = 0; |
| 568 | } |
| 569 | if (!bond->params.arp_targets[0]) |
| 570 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", |
| 571 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 572 | } |
| 573 | if (bond->dev->flags & IFF_UP) { |
| 574 | /* If the interface is up, we may need to fire off |
| 575 | * the ARP timer. If the interface is down, the |
| 576 | * timer will get fired off when the open function |
| 577 | * is called. |
| 578 | */ |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 579 | if (!new_value) { |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 580 | if (bond->params.arp_validate) |
| 581 | bond->recv_probe = NULL; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 582 | cancel_delayed_work_sync(&bond->arp_work); |
| 583 | } else { |
nikolay@redhat.com | 5bb9e0b | 2013-09-07 00:00:26 +0200 | [diff] [blame] | 584 | /* arp_validate can be set only in active-backup mode */ |
| 585 | if (bond->params.arp_validate) |
| 586 | bond->recv_probe = bond_arp_rcv; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 587 | cancel_delayed_work_sync(&bond->mii_work); |
| 588 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 589 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 590 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 591 | out: |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 592 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 593 | return ret; |
| 594 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 595 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
| 596 | bonding_show_arp_interval, bonding_store_arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 597 | |
| 598 | /* |
| 599 | * Show and set the arp targets. |
| 600 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 601 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 602 | struct device_attribute *attr, |
| 603 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 604 | { |
| 605 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 606 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 607 | |
| 608 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 609 | if (bond->params.arp_targets[i]) |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 610 | res += sprintf(buf + res, "%pI4 ", |
| 611 | &bond->params.arp_targets[i]); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 612 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 613 | if (res) |
| 614 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 615 | return res; |
| 616 | } |
| 617 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 618 | static ssize_t bonding_store_arp_targets(struct device *d, |
| 619 | struct device_attribute *attr, |
| 620 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 621 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 622 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 623 | struct list_head *iter; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 624 | struct slave *slave; |
| 625 | __be32 newtarget, *targets; |
| 626 | unsigned long *targets_rx; |
| 627 | int ind, i, j, ret = -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 628 | |
| 629 | targets = bond->params.arp_targets; |
| 630 | newtarget = in_aton(buf + 1); |
| 631 | /* look for adds */ |
| 632 | if (buf[0] == '+') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 633 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 634 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 635 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 636 | goto out; |
| 637 | } |
| 638 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 639 | if (bond_get_targets_ip(targets, newtarget) != -1) { /* dup */ |
| 640 | pr_err("%s: ARP target %pI4 is already present\n", |
| 641 | bond->dev->name, &newtarget); |
| 642 | goto out; |
| 643 | } |
| 644 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 645 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 646 | if (ind == -1) { |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 647 | pr_err("%s: ARP target table is full!\n", |
| 648 | bond->dev->name); |
| 649 | goto out; |
| 650 | } |
| 651 | |
| 652 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, |
| 653 | &newtarget); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 654 | /* not to race with bond_arp_rcv */ |
| 655 | write_lock_bh(&bond->lock); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 656 | bond_for_each_slave(bond, slave, iter) |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 657 | slave->target_last_arp_rx[ind] = jiffies; |
| 658 | targets[ind] = newtarget; |
| 659 | write_unlock_bh(&bond->lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 660 | } else if (buf[0] == '-') { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 661 | if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 662 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 663 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 664 | goto out; |
| 665 | } |
| 666 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 667 | ind = bond_get_targets_ip(targets, newtarget); |
| 668 | if (ind == -1) { |
| 669 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 670 | bond->dev->name, &newtarget); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 671 | goto out; |
| 672 | } |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 673 | |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 674 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
| 675 | pr_warn("%s: removing last arp target with arp_interval on\n", |
| 676 | bond->dev->name); |
| 677 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 678 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, |
| 679 | &newtarget); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 680 | |
| 681 | write_lock_bh(&bond->lock); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 682 | bond_for_each_slave(bond, slave, iter) { |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 683 | targets_rx = slave->target_last_arp_rx; |
| 684 | j = ind; |
| 685 | for (; (j < BOND_MAX_ARP_TARGETS-1) && targets[j+1]; j++) |
| 686 | targets_rx[j] = targets_rx[j+1]; |
| 687 | targets_rx[j] = 0; |
| 688 | } |
| 689 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 690 | targets[i] = targets[i+1]; |
| 691 | targets[i] = 0; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 692 | write_unlock_bh(&bond->lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 693 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 694 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 695 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 696 | ret = -EPERM; |
| 697 | goto out; |
| 698 | } |
| 699 | |
Veaceslav Falico | 87a7b84 | 2013-06-24 11:49:29 +0200 | [diff] [blame] | 700 | ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 701 | out: |
| 702 | return ret; |
| 703 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 704 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 705 | |
| 706 | /* |
| 707 | * Show and set the up and down delays. These must be multiples of the |
| 708 | * MII monitoring value, and are stored internally as the multiplier. |
| 709 | * Thus, we must translate to MS for the real world. |
| 710 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 711 | static ssize_t bonding_show_downdelay(struct device *d, |
| 712 | struct device_attribute *attr, |
| 713 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 714 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 715 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 716 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 717 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 718 | } |
| 719 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 720 | static ssize_t bonding_store_downdelay(struct device *d, |
| 721 | struct device_attribute *attr, |
| 722 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 723 | { |
| 724 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 725 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 726 | |
| 727 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 728 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 729 | bond->dev->name); |
| 730 | ret = -EPERM; |
| 731 | goto out; |
| 732 | } |
| 733 | |
| 734 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 735 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 736 | ret = -EINVAL; |
| 737 | goto out; |
| 738 | } |
| 739 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 740 | pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n", |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 741 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 742 | ret = -EINVAL; |
| 743 | goto out; |
| 744 | } else { |
| 745 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 746 | pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 747 | bond->dev->name, new_value, |
| 748 | bond->params.miimon, |
| 749 | (new_value / bond->params.miimon) * |
| 750 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 751 | } |
| 752 | bond->params.downdelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 753 | pr_info("%s: Setting down delay to %d.\n", |
| 754 | bond->dev->name, |
| 755 | bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 756 | |
| 757 | } |
| 758 | |
| 759 | out: |
| 760 | return ret; |
| 761 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 762 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
| 763 | bonding_show_downdelay, bonding_store_downdelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 764 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 765 | static ssize_t bonding_show_updelay(struct device *d, |
| 766 | struct device_attribute *attr, |
| 767 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 768 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 769 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 770 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 771 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 772 | |
| 773 | } |
| 774 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 775 | static ssize_t bonding_store_updelay(struct device *d, |
| 776 | struct device_attribute *attr, |
| 777 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 778 | { |
| 779 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 780 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 781 | |
| 782 | if (!(bond->params.miimon)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 783 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 784 | bond->dev->name); |
| 785 | ret = -EPERM; |
| 786 | goto out; |
| 787 | } |
| 788 | |
| 789 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 790 | pr_err("%s: no up delay value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 791 | bond->dev->name); |
| 792 | ret = -EINVAL; |
| 793 | goto out; |
| 794 | } |
| 795 | if (new_value < 0) { |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 796 | pr_err("%s: Invalid up delay value %d not in range %d-%d; rejected.\n", |
| 797 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 798 | ret = -EINVAL; |
| 799 | goto out; |
| 800 | } else { |
| 801 | if ((new_value % bond->params.miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 802 | pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 803 | bond->dev->name, new_value, |
| 804 | bond->params.miimon, |
| 805 | (new_value / bond->params.miimon) * |
| 806 | bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 807 | } |
| 808 | bond->params.updelay = new_value / bond->params.miimon; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 809 | pr_info("%s: Setting up delay to %d.\n", |
| 810 | bond->dev->name, |
| 811 | bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | out: |
| 815 | return ret; |
| 816 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 817 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
| 818 | bonding_show_updelay, bonding_store_updelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 819 | |
| 820 | /* |
| 821 | * Show and set the LACP interval. Interface must be down, and the mode |
| 822 | * must be set to 802.3ad mode. |
| 823 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 824 | static ssize_t bonding_show_lacp(struct device *d, |
| 825 | struct device_attribute *attr, |
| 826 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 827 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 828 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 829 | |
| 830 | return sprintf(buf, "%s %d\n", |
| 831 | bond_lacp_tbl[bond->params.lacp_fast].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 832 | bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 833 | } |
| 834 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 835 | static ssize_t bonding_store_lacp(struct device *d, |
| 836 | struct device_attribute *attr, |
| 837 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 838 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 839 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 840 | int new_value, ret = count; |
| 841 | |
| 842 | if (!rtnl_trylock()) |
| 843 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 844 | |
| 845 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 846 | pr_err("%s: Unable to update LACP rate because interface is up.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 847 | bond->dev->name); |
| 848 | ret = -EPERM; |
| 849 | goto out; |
| 850 | } |
| 851 | |
| 852 | if (bond->params.mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 853 | pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 854 | bond->dev->name); |
| 855 | ret = -EPERM; |
| 856 | goto out; |
| 857 | } |
| 858 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 859 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 860 | |
| 861 | if ((new_value == 1) || (new_value == 0)) { |
| 862 | bond->params.lacp_fast = new_value; |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 863 | bond_3ad_update_lacp_rate(bond); |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 864 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 865 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
| 866 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 867 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 868 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 869 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 870 | ret = -EINVAL; |
| 871 | } |
| 872 | out: |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 873 | rtnl_unlock(); |
| 874 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 875 | return ret; |
| 876 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 877 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
| 878 | bonding_show_lacp, bonding_store_lacp); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 879 | |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 880 | static ssize_t bonding_show_min_links(struct device *d, |
| 881 | struct device_attribute *attr, |
| 882 | char *buf) |
| 883 | { |
| 884 | struct bonding *bond = to_bond(d); |
| 885 | |
| 886 | return sprintf(buf, "%d\n", bond->params.min_links); |
| 887 | } |
| 888 | |
| 889 | static ssize_t bonding_store_min_links(struct device *d, |
| 890 | struct device_attribute *attr, |
| 891 | const char *buf, size_t count) |
| 892 | { |
| 893 | struct bonding *bond = to_bond(d); |
| 894 | int ret; |
| 895 | unsigned int new_value; |
| 896 | |
| 897 | ret = kstrtouint(buf, 0, &new_value); |
| 898 | if (ret < 0) { |
| 899 | pr_err("%s: Ignoring invalid min links value %s.\n", |
| 900 | bond->dev->name, buf); |
| 901 | return ret; |
| 902 | } |
| 903 | |
| 904 | pr_info("%s: Setting min links value to %u\n", |
| 905 | bond->dev->name, new_value); |
| 906 | bond->params.min_links = new_value; |
| 907 | return count; |
| 908 | } |
| 909 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, |
| 910 | bonding_show_min_links, bonding_store_min_links); |
| 911 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 912 | static ssize_t bonding_show_ad_select(struct device *d, |
| 913 | struct device_attribute *attr, |
| 914 | char *buf) |
| 915 | { |
| 916 | struct bonding *bond = to_bond(d); |
| 917 | |
| 918 | return sprintf(buf, "%s %d\n", |
| 919 | ad_select_tbl[bond->params.ad_select].modename, |
| 920 | bond->params.ad_select); |
| 921 | } |
| 922 | |
| 923 | |
| 924 | static ssize_t bonding_store_ad_select(struct device *d, |
| 925 | struct device_attribute *attr, |
| 926 | const char *buf, size_t count) |
| 927 | { |
| 928 | int new_value, ret = count; |
| 929 | struct bonding *bond = to_bond(d); |
| 930 | |
| 931 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 932 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
| 933 | bond->dev->name); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 934 | ret = -EPERM; |
| 935 | goto out; |
| 936 | } |
| 937 | |
| 938 | new_value = bond_parse_parm(buf, ad_select_tbl); |
| 939 | |
| 940 | if (new_value != -1) { |
| 941 | bond->params.ad_select = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 942 | pr_info("%s: Setting ad_select to %s (%d).\n", |
| 943 | bond->dev->name, ad_select_tbl[new_value].modename, |
| 944 | new_value); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 945 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 946 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 947 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 948 | ret = -EINVAL; |
| 949 | } |
| 950 | out: |
| 951 | return ret; |
| 952 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 953 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
| 954 | bonding_show_ad_select, bonding_store_ad_select); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 955 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 956 | /* |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 957 | * Show and set the number of peer notifications to send after a failover event. |
| 958 | */ |
| 959 | static ssize_t bonding_show_num_peer_notif(struct device *d, |
| 960 | struct device_attribute *attr, |
| 961 | char *buf) |
| 962 | { |
| 963 | struct bonding *bond = to_bond(d); |
| 964 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); |
| 965 | } |
| 966 | |
| 967 | static ssize_t bonding_store_num_peer_notif(struct device *d, |
| 968 | struct device_attribute *attr, |
| 969 | const char *buf, size_t count) |
| 970 | { |
| 971 | struct bonding *bond = to_bond(d); |
| 972 | int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); |
| 973 | return err ? err : count; |
| 974 | } |
| 975 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, |
| 976 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 977 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, |
| 978 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 979 | |
| 980 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 981 | * Show and set the MII monitor interval. There are two tricky bits |
| 982 | * here. First, if MII monitoring is activated, then we must disable |
| 983 | * ARP monitoring. Second, if the timer isn't running, we must |
| 984 | * start it. |
| 985 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 986 | static ssize_t bonding_show_miimon(struct device *d, |
| 987 | struct device_attribute *attr, |
| 988 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 989 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 990 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 991 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 992 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 993 | } |
| 994 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 995 | static ssize_t bonding_store_miimon(struct device *d, |
| 996 | struct device_attribute *attr, |
| 997 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 998 | { |
| 999 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1000 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1001 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1002 | if (!rtnl_trylock()) |
| 1003 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1004 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1005 | pr_err("%s: no miimon value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1006 | bond->dev->name); |
| 1007 | ret = -EINVAL; |
| 1008 | goto out; |
| 1009 | } |
| 1010 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1011 | pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n", |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 1012 | bond->dev->name, new_value, 0, INT_MAX); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1013 | ret = -EINVAL; |
| 1014 | goto out; |
nikolay@redhat.com | 1bc7db1 | 2013-03-27 03:32:41 +0000 | [diff] [blame] | 1015 | } |
| 1016 | pr_info("%s: Setting MII monitoring interval to %d.\n", |
| 1017 | bond->dev->name, new_value); |
| 1018 | bond->params.miimon = new_value; |
| 1019 | if (bond->params.updelay) |
| 1020 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", |
| 1021 | bond->dev->name, |
| 1022 | bond->params.updelay * bond->params.miimon); |
| 1023 | if (bond->params.downdelay) |
| 1024 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", |
| 1025 | bond->dev->name, |
| 1026 | bond->params.downdelay * bond->params.miimon); |
| 1027 | if (new_value && bond->params.arp_interval) { |
| 1028 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
| 1029 | bond->dev->name); |
| 1030 | bond->params.arp_interval = 0; |
| 1031 | if (bond->params.arp_validate) |
| 1032 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 1033 | } |
| 1034 | if (bond->dev->flags & IFF_UP) { |
| 1035 | /* If the interface is up, we may need to fire off |
| 1036 | * the MII timer. If the interface is down, the |
| 1037 | * timer will get fired off when the open function |
| 1038 | * is called. |
| 1039 | */ |
| 1040 | if (!new_value) { |
| 1041 | cancel_delayed_work_sync(&bond->mii_work); |
| 1042 | } else { |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1043 | cancel_delayed_work_sync(&bond->arp_work); |
| 1044 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | out: |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 1048 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1049 | return ret; |
| 1050 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1051 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
| 1052 | bonding_show_miimon, bonding_store_miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1053 | |
| 1054 | /* |
| 1055 | * Show and set the primary slave. The store function is much |
| 1056 | * simpler than bonding_store_slaves function because it only needs to |
| 1057 | * handle one interface name. |
| 1058 | * The bond must be a mode that supports a primary for this be |
| 1059 | * set. |
| 1060 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1061 | static ssize_t bonding_show_primary(struct device *d, |
| 1062 | struct device_attribute *attr, |
| 1063 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1064 | { |
| 1065 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1066 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1067 | |
| 1068 | if (bond->primary_slave) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1069 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1070 | |
| 1071 | return count; |
| 1072 | } |
| 1073 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1074 | static ssize_t bonding_store_primary(struct device *d, |
| 1075 | struct device_attribute *attr, |
| 1076 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1077 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1078 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1079 | struct list_head *iter; |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1080 | char ifname[IFNAMSIZ]; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1081 | struct slave *slave; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1082 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1083 | if (!rtnl_trylock()) |
| 1084 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1085 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1086 | read_lock(&bond->lock); |
| 1087 | write_lock_bh(&bond->curr_slave_lock); |
| 1088 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1089 | if (!USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1090 | pr_info("%s: Unable to set primary slave; %s is in mode %d\n", |
| 1091 | bond->dev->name, bond->dev->name, bond->params.mode); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1092 | goto out; |
| 1093 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1094 | |
nikolay@redhat.com | eb6e98a | 2012-10-31 04:42:51 +0000 | [diff] [blame] | 1095 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1096 | |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1097 | /* check to see if we are clearing primary */ |
| 1098 | if (!strlen(ifname) || buf[0] == '\n') { |
| 1099 | pr_info("%s: Setting primary slave to None.\n", |
| 1100 | bond->dev->name); |
| 1101 | bond->primary_slave = NULL; |
Milos Vyletel | eb492f7 | 2013-01-29 09:59:00 +0000 | [diff] [blame] | 1102 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1103 | bond_select_active_slave(bond); |
| 1104 | goto out; |
| 1105 | } |
| 1106 | |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1107 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1108 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1109 | pr_info("%s: Setting %s as primary slave.\n", |
| 1110 | bond->dev->name, slave->dev->name); |
| 1111 | bond->primary_slave = slave; |
| 1112 | strcpy(bond->params.primary, slave->dev->name); |
| 1113 | bond_select_active_slave(bond); |
| 1114 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1115 | } |
| 1116 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1117 | |
Weiping Pan | 8a93664 | 2012-06-10 23:00:20 +0000 | [diff] [blame] | 1118 | strncpy(bond->params.primary, ifname, IFNAMSIZ); |
| 1119 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 1120 | |
| 1121 | pr_info("%s: Recording %s as primary, " |
| 1122 | "but it has not been enslaved to %s yet.\n", |
| 1123 | bond->dev->name, ifname, bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1124 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1125 | write_unlock_bh(&bond->curr_slave_lock); |
| 1126 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1127 | unblock_netpoll_tx(); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1128 | rtnl_unlock(); |
| 1129 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1130 | return count; |
| 1131 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1132 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
| 1133 | bonding_show_primary, bonding_store_primary); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1134 | |
| 1135 | /* |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1136 | * Show and set the primary_reselect flag. |
| 1137 | */ |
| 1138 | static ssize_t bonding_show_primary_reselect(struct device *d, |
| 1139 | struct device_attribute *attr, |
| 1140 | char *buf) |
| 1141 | { |
| 1142 | struct bonding *bond = to_bond(d); |
| 1143 | |
| 1144 | return sprintf(buf, "%s %d\n", |
| 1145 | pri_reselect_tbl[bond->params.primary_reselect].modename, |
| 1146 | bond->params.primary_reselect); |
| 1147 | } |
| 1148 | |
| 1149 | static ssize_t bonding_store_primary_reselect(struct device *d, |
| 1150 | struct device_attribute *attr, |
| 1151 | const char *buf, size_t count) |
| 1152 | { |
| 1153 | int new_value, ret = count; |
| 1154 | struct bonding *bond = to_bond(d); |
| 1155 | |
| 1156 | if (!rtnl_trylock()) |
| 1157 | return restart_syscall(); |
| 1158 | |
| 1159 | new_value = bond_parse_parm(buf, pri_reselect_tbl); |
| 1160 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1161 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1162 | bond->dev->name, |
| 1163 | (int) strlen(buf) - 1, buf); |
| 1164 | ret = -EINVAL; |
| 1165 | goto out; |
| 1166 | } |
| 1167 | |
| 1168 | bond->params.primary_reselect = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1169 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1170 | bond->dev->name, pri_reselect_tbl[new_value].modename, |
| 1171 | new_value); |
| 1172 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1173 | block_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1174 | read_lock(&bond->lock); |
| 1175 | write_lock_bh(&bond->curr_slave_lock); |
| 1176 | bond_select_active_slave(bond); |
| 1177 | write_unlock_bh(&bond->curr_slave_lock); |
| 1178 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1179 | unblock_netpoll_tx(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1180 | out: |
| 1181 | rtnl_unlock(); |
| 1182 | return ret; |
| 1183 | } |
| 1184 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
| 1185 | bonding_show_primary_reselect, |
| 1186 | bonding_store_primary_reselect); |
| 1187 | |
| 1188 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1189 | * Show and set the use_carrier flag. |
| 1190 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1191 | static ssize_t bonding_show_carrier(struct device *d, |
| 1192 | struct device_attribute *attr, |
| 1193 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1194 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1195 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1196 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1197 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1200 | static ssize_t bonding_store_carrier(struct device *d, |
| 1201 | struct device_attribute *attr, |
| 1202 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1203 | { |
| 1204 | int new_value, ret = count; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1205 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1206 | |
| 1207 | |
| 1208 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1209 | pr_err("%s: no use_carrier value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1210 | bond->dev->name); |
| 1211 | ret = -EINVAL; |
| 1212 | goto out; |
| 1213 | } |
| 1214 | if ((new_value == 0) || (new_value == 1)) { |
| 1215 | bond->params.use_carrier = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1216 | pr_info("%s: Setting use_carrier to %d.\n", |
| 1217 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1218 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1219 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
| 1220 | bond->dev->name, new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1221 | } |
| 1222 | out: |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1223 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1224 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1225 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
| 1226 | bonding_show_carrier, bonding_store_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1227 | |
| 1228 | |
| 1229 | /* |
| 1230 | * Show and set currently active_slave. |
| 1231 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1232 | static ssize_t bonding_show_active_slave(struct device *d, |
| 1233 | struct device_attribute *attr, |
| 1234 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1235 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1236 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1237 | struct slave *curr; |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 1238 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1239 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1240 | rcu_read_lock(); |
| 1241 | curr = rcu_dereference(bond->curr_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1242 | if (USES_PRIMARY(bond->params.mode) && curr) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 1243 | count = sprintf(buf, "%s\n", curr->dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1244 | rcu_read_unlock(); |
| 1245 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1246 | return count; |
| 1247 | } |
| 1248 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1249 | static ssize_t bonding_store_active_slave(struct device *d, |
| 1250 | struct device_attribute *attr, |
| 1251 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1252 | { |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1253 | struct slave *slave, *old_active, *new_active; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1254 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1255 | struct list_head *iter; |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1256 | char ifname[IFNAMSIZ]; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1257 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1258 | if (!rtnl_trylock()) |
| 1259 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1260 | |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1261 | old_active = new_active = NULL; |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1262 | block_netpoll_tx(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1263 | read_lock(&bond->lock); |
| 1264 | write_lock_bh(&bond->curr_slave_lock); |
Jay Vosburgh | 1466a21 | 2007-11-06 13:33:28 -0800 | [diff] [blame] | 1265 | |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1266 | if (!USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1267 | pr_info("%s: Unable to change active slave; %s is in mode %d\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1268 | bond->dev->name, bond->dev->name, bond->params.mode); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1269 | goto out; |
| 1270 | } |
| 1271 | |
nikolay@redhat.com | c84e159 | 2012-10-31 06:03:52 +0000 | [diff] [blame] | 1272 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1273 | |
| 1274 | /* check to see if we are clearing active */ |
| 1275 | if (!strlen(ifname) || buf[0] == '\n') { |
| 1276 | pr_info("%s: Clearing current active slave.\n", |
| 1277 | bond->dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1278 | rcu_assign_pointer(bond->curr_active_slave, NULL); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1279 | bond_select_active_slave(bond); |
| 1280 | goto out; |
| 1281 | } |
| 1282 | |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1283 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1284 | if (strncmp(slave->dev->name, ifname, IFNAMSIZ) == 0) { |
| 1285 | old_active = bond->curr_active_slave; |
| 1286 | new_active = slave; |
| 1287 | if (new_active == old_active) { |
| 1288 | /* do nothing */ |
| 1289 | pr_info("%s: %s is already the current" |
| 1290 | " active slave.\n", |
| 1291 | bond->dev->name, |
| 1292 | slave->dev->name); |
| 1293 | goto out; |
dingtianhong | 38c4916 | 2013-07-23 15:25:32 +0800 | [diff] [blame] | 1294 | } else { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1295 | if ((new_active) && |
| 1296 | (old_active) && |
| 1297 | (new_active->link == BOND_LINK_UP) && |
| 1298 | IS_UP(new_active->dev)) { |
| 1299 | pr_info("%s: Setting %s as active" |
| 1300 | " slave.\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1301 | bond->dev->name, |
| 1302 | slave->dev->name); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1303 | bond_change_active_slave(bond, |
| 1304 | new_active); |
dingtianhong | 38c4916 | 2013-07-23 15:25:32 +0800 | [diff] [blame] | 1305 | } else { |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1306 | pr_info("%s: Could not set %s as" |
| 1307 | " active slave; either %s is" |
| 1308 | " down or the link is down.\n", |
| 1309 | bond->dev->name, |
| 1310 | slave->dev->name, |
| 1311 | slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1312 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1313 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1314 | } |
| 1315 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1316 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1317 | |
| 1318 | pr_info("%s: Unable to set %.*s as active slave.\n", |
| 1319 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1320 | out: |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 1321 | write_unlock_bh(&bond->curr_slave_lock); |
| 1322 | read_unlock(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1323 | unblock_netpoll_tx(); |
| 1324 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1325 | rtnl_unlock(); |
| 1326 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1327 | return count; |
| 1328 | |
| 1329 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1330 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
| 1331 | bonding_show_active_slave, bonding_store_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1332 | |
| 1333 | |
| 1334 | /* |
| 1335 | * Show link status of the bond interface. |
| 1336 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1337 | static ssize_t bonding_show_mii_status(struct device *d, |
| 1338 | struct device_attribute *attr, |
| 1339 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1340 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1341 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1342 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1343 | return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1344 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1345 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1346 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1347 | /* |
| 1348 | * Show current 802.3ad aggregator ID. |
| 1349 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1350 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 1351 | struct device_attribute *attr, |
| 1352 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1353 | { |
| 1354 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1355 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1356 | |
| 1357 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1358 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1359 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1360 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1361 | ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1362 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1363 | |
| 1364 | return count; |
| 1365 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1366 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1367 | |
| 1368 | |
| 1369 | /* |
| 1370 | * Show number of active 802.3ad ports. |
| 1371 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1372 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 1373 | struct device_attribute *attr, |
| 1374 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1375 | { |
| 1376 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1377 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1378 | |
| 1379 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1380 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1381 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1382 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1383 | ? 0 : ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1384 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1385 | |
| 1386 | return count; |
| 1387 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1388 | 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] | 1389 | |
| 1390 | |
| 1391 | /* |
| 1392 | * Show current 802.3ad actor key. |
| 1393 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1394 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 1395 | struct device_attribute *attr, |
| 1396 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1397 | { |
| 1398 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1399 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1400 | |
| 1401 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1402 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1403 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1404 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1405 | ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1406 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1407 | |
| 1408 | return count; |
| 1409 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1410 | 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] | 1411 | |
| 1412 | |
| 1413 | /* |
| 1414 | * Show current 802.3ad partner key. |
| 1415 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1416 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 1417 | struct device_attribute *attr, |
| 1418 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1419 | { |
| 1420 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1421 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1422 | |
| 1423 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1424 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1425 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1426 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1427 | ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1428 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1429 | |
| 1430 | return count; |
| 1431 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1432 | 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] | 1433 | |
| 1434 | |
| 1435 | /* |
| 1436 | * Show current 802.3ad partner mac. |
| 1437 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1438 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 1439 | struct device_attribute *attr, |
| 1440 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1441 | { |
| 1442 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1443 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1444 | |
| 1445 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1446 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1447 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1448 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1449 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1450 | |
| 1451 | return count; |
| 1452 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1453 | 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] | 1454 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1455 | /* |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1456 | * Show the queue_ids of the slaves in the current bond. |
| 1457 | */ |
| 1458 | static ssize_t bonding_show_queue_id(struct device *d, |
| 1459 | struct device_attribute *attr, |
| 1460 | char *buf) |
| 1461 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1462 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1463 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1464 | struct slave *slave; |
| 1465 | int res = 0; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1466 | |
| 1467 | if (!rtnl_trylock()) |
| 1468 | return restart_syscall(); |
| 1469 | |
| 1470 | read_lock(&bond->lock); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1471 | bond_for_each_slave(bond, slave, iter) { |
Nicolas de Pesloüan | 7923668 | 2010-07-14 18:24:54 -0700 | [diff] [blame] | 1472 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 1473 | /* not enough space for another interface_name:queue_id pair */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1474 | if ((PAGE_SIZE - res) > 10) |
| 1475 | res = PAGE_SIZE - 10; |
| 1476 | res += sprintf(buf + res, "++more++ "); |
| 1477 | break; |
| 1478 | } |
| 1479 | res += sprintf(buf + res, "%s:%d ", |
| 1480 | slave->dev->name, slave->queue_id); |
| 1481 | } |
| 1482 | read_unlock(&bond->lock); |
| 1483 | if (res) |
| 1484 | buf[res-1] = '\n'; /* eat the leftover space */ |
| 1485 | rtnl_unlock(); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1486 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1487 | return res; |
| 1488 | } |
| 1489 | |
| 1490 | /* |
| 1491 | * Set the queue_ids of the slaves in the current bond. The bond |
| 1492 | * interface must be enslaved for this to work. |
| 1493 | */ |
| 1494 | static ssize_t bonding_store_queue_id(struct device *d, |
| 1495 | struct device_attribute *attr, |
| 1496 | const char *buffer, size_t count) |
| 1497 | { |
| 1498 | struct slave *slave, *update_slave; |
| 1499 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1500 | struct list_head *iter; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1501 | u16 qid; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1502 | int ret = count; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1503 | char *delim; |
| 1504 | struct net_device *sdev = NULL; |
| 1505 | |
| 1506 | if (!rtnl_trylock()) |
| 1507 | return restart_syscall(); |
| 1508 | |
| 1509 | /* delim will point to queue id if successful */ |
| 1510 | delim = strchr(buffer, ':'); |
| 1511 | if (!delim) |
| 1512 | goto err_no_cmd; |
| 1513 | |
| 1514 | /* |
| 1515 | * Terminate string that points to device name and bump it |
| 1516 | * up one, so we can read the queue id there. |
| 1517 | */ |
| 1518 | *delim = '\0'; |
| 1519 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1520 | goto err_no_cmd; |
| 1521 | |
| 1522 | /* Check buffer length, valid ifname and queue id */ |
| 1523 | if (strlen(buffer) > IFNAMSIZ || |
| 1524 | !dev_valid_name(buffer) || |
Jiri Pirko | 8a540ff | 2012-07-20 02:28:50 +0000 | [diff] [blame] | 1525 | qid > bond->dev->real_num_tx_queues) |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1526 | goto err_no_cmd; |
| 1527 | |
| 1528 | /* Get the pointer to that interface if it exists */ |
| 1529 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); |
| 1530 | if (!sdev) |
| 1531 | goto err_no_cmd; |
| 1532 | |
| 1533 | read_lock(&bond->lock); |
| 1534 | |
| 1535 | /* Search for thes slave and check for duplicate qids */ |
| 1536 | update_slave = NULL; |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1537 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1538 | if (sdev == slave->dev) |
| 1539 | /* |
| 1540 | * We don't need to check the matching |
| 1541 | * slave for dups, since we're overwriting it |
| 1542 | */ |
| 1543 | update_slave = slave; |
| 1544 | else if (qid && qid == slave->queue_id) { |
| 1545 | goto err_no_cmd_unlock; |
| 1546 | } |
| 1547 | } |
| 1548 | |
| 1549 | if (!update_slave) |
| 1550 | goto err_no_cmd_unlock; |
| 1551 | |
| 1552 | /* Actually set the qids for the slave */ |
| 1553 | update_slave->queue_id = qid; |
| 1554 | |
| 1555 | read_unlock(&bond->lock); |
| 1556 | out: |
| 1557 | rtnl_unlock(); |
| 1558 | return ret; |
| 1559 | |
| 1560 | err_no_cmd_unlock: |
| 1561 | read_unlock(&bond->lock); |
| 1562 | err_no_cmd: |
| 1563 | pr_info("invalid input for queue_id set for %s.\n", |
| 1564 | bond->dev->name); |
| 1565 | ret = -EPERM; |
| 1566 | goto out; |
| 1567 | } |
| 1568 | |
| 1569 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
| 1570 | bonding_store_queue_id); |
| 1571 | |
| 1572 | |
| 1573 | /* |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1574 | * Show and set the all_slaves_active flag. |
| 1575 | */ |
| 1576 | static ssize_t bonding_show_slaves_active(struct device *d, |
| 1577 | struct device_attribute *attr, |
| 1578 | char *buf) |
| 1579 | { |
| 1580 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1581 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1582 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); |
| 1583 | } |
| 1584 | |
| 1585 | static ssize_t bonding_store_slaves_active(struct device *d, |
| 1586 | struct device_attribute *attr, |
| 1587 | const char *buf, size_t count) |
| 1588 | { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1589 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1590 | int new_value, ret = count; |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1591 | struct list_head *iter; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1592 | struct slave *slave; |
| 1593 | |
| 1594 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1595 | pr_err("%s: no all_slaves_active value specified.\n", |
| 1596 | bond->dev->name); |
| 1597 | ret = -EINVAL; |
| 1598 | goto out; |
| 1599 | } |
| 1600 | |
| 1601 | if (new_value == bond->params.all_slaves_active) |
| 1602 | goto out; |
| 1603 | |
| 1604 | if ((new_value == 0) || (new_value == 1)) { |
| 1605 | bond->params.all_slaves_active = new_value; |
| 1606 | } else { |
| 1607 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", |
| 1608 | bond->dev->name, new_value); |
| 1609 | ret = -EINVAL; |
| 1610 | goto out; |
| 1611 | } |
| 1612 | |
nikolay@redhat.com | e196c0e | 2012-11-29 01:37:59 +0000 | [diff] [blame] | 1613 | read_lock(&bond->lock); |
Veaceslav Falico | 9caff1e | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1614 | bond_for_each_slave(bond, slave, iter) { |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1615 | if (!bond_is_active_slave(slave)) { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1616 | if (new_value) |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1617 | slave->inactive = 0; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1618 | else |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1619 | slave->inactive = 1; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1620 | } |
| 1621 | } |
nikolay@redhat.com | e196c0e | 2012-11-29 01:37:59 +0000 | [diff] [blame] | 1622 | read_unlock(&bond->lock); |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1623 | out: |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1624 | return ret; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1625 | } |
| 1626 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
| 1627 | bonding_show_slaves_active, bonding_store_slaves_active); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1628 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1629 | /* |
| 1630 | * Show and set the number of IGMP membership reports to send on link failure |
| 1631 | */ |
| 1632 | static ssize_t bonding_show_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1633 | struct device_attribute *attr, |
| 1634 | char *buf) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1635 | { |
| 1636 | struct bonding *bond = to_bond(d); |
| 1637 | |
| 1638 | return sprintf(buf, "%d\n", bond->params.resend_igmp); |
| 1639 | } |
| 1640 | |
| 1641 | static ssize_t bonding_store_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1642 | struct device_attribute *attr, |
| 1643 | const char *buf, size_t count) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1644 | { |
| 1645 | int new_value, ret = count; |
| 1646 | struct bonding *bond = to_bond(d); |
| 1647 | |
| 1648 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1649 | pr_err("%s: no resend_igmp value specified.\n", |
| 1650 | bond->dev->name); |
| 1651 | ret = -EINVAL; |
| 1652 | goto out; |
| 1653 | } |
| 1654 | |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1655 | if (new_value < 0 || new_value > 255) { |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1656 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
| 1657 | bond->dev->name, new_value); |
| 1658 | ret = -EINVAL; |
| 1659 | goto out; |
| 1660 | } |
| 1661 | |
| 1662 | pr_info("%s: Setting resend_igmp to %d.\n", |
| 1663 | bond->dev->name, new_value); |
| 1664 | bond->params.resend_igmp = new_value; |
| 1665 | out: |
| 1666 | return ret; |
| 1667 | } |
| 1668 | |
| 1669 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
| 1670 | bonding_show_resend_igmp, bonding_store_resend_igmp); |
| 1671 | |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1672 | |
| 1673 | static ssize_t bonding_show_lp_interval(struct device *d, |
| 1674 | struct device_attribute *attr, |
| 1675 | char *buf) |
| 1676 | { |
| 1677 | struct bonding *bond = to_bond(d); |
| 1678 | return sprintf(buf, "%d\n", bond->params.lp_interval); |
| 1679 | } |
| 1680 | |
| 1681 | static ssize_t bonding_store_lp_interval(struct device *d, |
| 1682 | struct device_attribute *attr, |
| 1683 | const char *buf, size_t count) |
| 1684 | { |
| 1685 | struct bonding *bond = to_bond(d); |
| 1686 | int new_value, ret = count; |
| 1687 | |
| 1688 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1689 | pr_err("%s: no lp interval value specified.\n", |
| 1690 | bond->dev->name); |
| 1691 | ret = -EINVAL; |
| 1692 | goto out; |
| 1693 | } |
| 1694 | |
| 1695 | if (new_value <= 0) { |
| 1696 | pr_err ("%s: lp_interval must be between 1 and %d\n", |
| 1697 | bond->dev->name, INT_MAX); |
| 1698 | ret = -EINVAL; |
| 1699 | goto out; |
| 1700 | } |
| 1701 | |
| 1702 | bond->params.lp_interval = new_value; |
| 1703 | out: |
| 1704 | return ret; |
| 1705 | } |
| 1706 | |
| 1707 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, |
| 1708 | bonding_show_lp_interval, bonding_store_lp_interval); |
| 1709 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1710 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1711 | &dev_attr_slaves.attr, |
| 1712 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1713 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1714 | &dev_attr_arp_validate.attr, |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 1715 | &dev_attr_arp_all_targets.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1716 | &dev_attr_arp_interval.attr, |
| 1717 | &dev_attr_arp_ip_target.attr, |
| 1718 | &dev_attr_downdelay.attr, |
| 1719 | &dev_attr_updelay.attr, |
| 1720 | &dev_attr_lacp_rate.attr, |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1721 | &dev_attr_ad_select.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1722 | &dev_attr_xmit_hash_policy.attr, |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1723 | &dev_attr_num_grat_arp.attr, |
| 1724 | &dev_attr_num_unsol_na.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1725 | &dev_attr_miimon.attr, |
| 1726 | &dev_attr_primary.attr, |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1727 | &dev_attr_primary_reselect.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1728 | &dev_attr_use_carrier.attr, |
| 1729 | &dev_attr_active_slave.attr, |
| 1730 | &dev_attr_mii_status.attr, |
| 1731 | &dev_attr_ad_aggregator.attr, |
| 1732 | &dev_attr_ad_num_ports.attr, |
| 1733 | &dev_attr_ad_actor_key.attr, |
| 1734 | &dev_attr_ad_partner_key.attr, |
| 1735 | &dev_attr_ad_partner_mac.attr, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1736 | &dev_attr_queue_id.attr, |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1737 | &dev_attr_all_slaves_active.attr, |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1738 | &dev_attr_resend_igmp.attr, |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 1739 | &dev_attr_min_links.attr, |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1740 | &dev_attr_lp_interval.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1741 | NULL, |
| 1742 | }; |
| 1743 | |
| 1744 | static struct attribute_group bonding_group = { |
| 1745 | .name = "bonding", |
| 1746 | .attrs = per_bond_attrs, |
| 1747 | }; |
| 1748 | |
| 1749 | /* |
| 1750 | * Initialize sysfs. This sets up the bonding_masters file in |
| 1751 | * /sys/class/net. |
| 1752 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1753 | int bond_create_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1754 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1755 | int ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1756 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1757 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
Eric W. Biederman | 01718e3 | 2011-10-21 22:43:07 +0000 | [diff] [blame] | 1758 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1759 | |
| 1760 | ret = netdev_class_create_file(&bn->class_attr_bonding_masters); |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1761 | /* |
| 1762 | * Permit multiple loads of the module by ignoring failures to |
| 1763 | * create the bonding_masters sysfs file. Bonding devices |
| 1764 | * created by second or subsequent loads of the module will |
| 1765 | * not be listed in, or controllable by, bonding_masters, but |
| 1766 | * will have the usual "bonding" sysfs directory. |
| 1767 | * |
| 1768 | * This is done to preserve backwards compatibility for |
| 1769 | * initscripts/sysconfig, which load bonding multiple times to |
| 1770 | * configure multiple bonding devices. |
| 1771 | */ |
| 1772 | if (ret == -EEXIST) { |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1773 | /* Is someone being kinky and naming a device bonding_master? */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1774 | if (__dev_get_by_name(bn->net, |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1775 | class_attr_bonding_masters.attr.name)) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1776 | pr_err("network device named %s already exists in sysfs", |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1777 | class_attr_bonding_masters.attr.name); |
Stephen Hemminger | 130aa61 | 2009-06-11 05:46:04 -0700 | [diff] [blame] | 1778 | ret = 0; |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1779 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1780 | |
| 1781 | return ret; |
| 1782 | |
| 1783 | } |
| 1784 | |
| 1785 | /* |
| 1786 | * Remove /sys/class/net/bonding_masters. |
| 1787 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1788 | void bond_destroy_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1789 | { |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1790 | netdev_class_remove_file(&bn->class_attr_bonding_masters); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | /* |
| 1794 | * Initialize sysfs for each bond. This sets up and registers |
| 1795 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 1796 | */ |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1797 | void bond_prepare_sysfs_group(struct bonding *bond) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1798 | { |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1799 | bond->dev->sysfs_groups[0] = &bonding_group; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1800 | } |
| 1801 | |