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