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); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 361 | int new_value, ret; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 362 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 363 | new_value = bond_parse_parm(buf, arp_validate_tbl); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 364 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 365 | pr_err("%s: Ignoring invalid arp_validate value %s\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 366 | bond->dev->name, buf); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 367 | return -EINVAL; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 368 | } |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 369 | if (!rtnl_trylock()) |
| 370 | return restart_syscall(); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 371 | |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 372 | ret = bond_option_arp_validate_set(bond, new_value); |
| 373 | if (!ret) |
| 374 | ret = count; |
| 375 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 376 | rtnl_unlock(); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 377 | |
nikolay@redhat.com | 5c5038d | 2013-09-07 00:00:25 +0200 | [diff] [blame] | 378 | return ret; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 381 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
| 382 | bonding_store_arp_validate); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 383 | /* |
| 384 | * Show and set arp_all_targets. |
| 385 | */ |
| 386 | static ssize_t bonding_show_arp_all_targets(struct device *d, |
| 387 | struct device_attribute *attr, |
| 388 | char *buf) |
| 389 | { |
| 390 | struct bonding *bond = to_bond(d); |
| 391 | int value = bond->params.arp_all_targets; |
| 392 | |
| 393 | return sprintf(buf, "%s %d\n", arp_all_targets_tbl[value].modename, |
| 394 | value); |
| 395 | } |
| 396 | |
| 397 | static ssize_t bonding_store_arp_all_targets(struct device *d, |
| 398 | struct device_attribute *attr, |
| 399 | const char *buf, size_t count) |
| 400 | { |
| 401 | struct bonding *bond = to_bond(d); |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 402 | int new_value, ret; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 403 | |
| 404 | new_value = bond_parse_parm(buf, arp_all_targets_tbl); |
| 405 | if (new_value < 0) { |
| 406 | pr_err("%s: Ignoring invalid arp_all_targets value %s\n", |
| 407 | bond->dev->name, buf); |
| 408 | return -EINVAL; |
| 409 | } |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 410 | |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 411 | if (!rtnl_trylock()) |
| 412 | return restart_syscall(); |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 413 | |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 414 | ret = bond_option_arp_all_targets_set(bond, new_value); |
| 415 | if (!ret) |
| 416 | ret = count; |
| 417 | |
| 418 | rtnl_unlock(); |
| 419 | |
| 420 | return ret; |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, |
| 424 | bonding_show_arp_all_targets, bonding_store_arp_all_targets); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 425 | |
| 426 | /* |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 427 | * Show and store fail_over_mac. User only allowed to change the |
| 428 | * value when there are no slaves. |
| 429 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 430 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
| 431 | struct device_attribute *attr, |
| 432 | char *buf) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 433 | { |
| 434 | struct bonding *bond = to_bond(d); |
| 435 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 436 | return sprintf(buf, "%s %d\n", |
| 437 | fail_over_mac_tbl[bond->params.fail_over_mac].modename, |
| 438 | bond->params.fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 441 | static ssize_t bonding_store_fail_over_mac(struct device *d, |
| 442 | struct device_attribute *attr, |
| 443 | const char *buf, size_t count) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 444 | { |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 445 | int new_value, ret = count; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 446 | struct bonding *bond = to_bond(d); |
| 447 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 448 | if (!rtnl_trylock()) |
| 449 | return restart_syscall(); |
| 450 | |
Veaceslav Falico | 0965a1f | 2013-09-25 09:20:21 +0200 | [diff] [blame] | 451 | if (bond_has_slaves(bond)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 452 | 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] | 453 | bond->dev->name); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 454 | ret = -EPERM; |
| 455 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 458 | new_value = bond_parse_parm(buf, fail_over_mac_tbl); |
| 459 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 460 | pr_err("%s: Ignoring invalid fail_over_mac value %s.\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 461 | bond->dev->name, buf); |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 462 | ret = -EINVAL; |
| 463 | goto out; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 466 | bond->params.fail_over_mac = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 467 | pr_info("%s: Setting fail_over_mac to %s (%d).\n", |
| 468 | bond->dev->name, fail_over_mac_tbl[new_value].modename, |
| 469 | new_value); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 470 | |
dingtianhong | 9402b74 | 2013-07-23 15:25:39 +0800 | [diff] [blame] | 471 | out: |
| 472 | rtnl_unlock(); |
| 473 | return ret; |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 476 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
| 477 | bonding_show_fail_over_mac, bonding_store_fail_over_mac); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 478 | |
| 479 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 480 | * Show and set the arp timer interval. There are two tricky bits |
| 481 | * here. First, if ARP monitoring is activated, then we must disable |
| 482 | * MII monitoring. Second, if the ARP timer isn't running, we must |
| 483 | * start it. |
| 484 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 485 | static ssize_t bonding_show_arp_interval(struct device *d, |
| 486 | struct device_attribute *attr, |
| 487 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 488 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 489 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 490 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 491 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 492 | } |
| 493 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 494 | static ssize_t bonding_store_arp_interval(struct device *d, |
| 495 | struct device_attribute *attr, |
| 496 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 497 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 498 | struct bonding *bond = to_bond(d); |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 499 | int new_value, ret; |
| 500 | |
| 501 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 502 | pr_err("%s: no arp_interval value specified.\n", |
| 503 | bond->dev->name); |
| 504 | return -EINVAL; |
| 505 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 506 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 507 | if (!rtnl_trylock()) |
| 508 | return restart_syscall(); |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 509 | |
| 510 | ret = bond_option_arp_interval_set(bond, new_value); |
| 511 | if (!ret) |
| 512 | ret = count; |
| 513 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 514 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 515 | return ret; |
| 516 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 517 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
| 518 | bonding_show_arp_interval, bonding_store_arp_interval); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 519 | |
| 520 | /* |
| 521 | * Show and set the arp targets. |
| 522 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 523 | static ssize_t bonding_show_arp_targets(struct device *d, |
| 524 | struct device_attribute *attr, |
| 525 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 526 | { |
| 527 | int i, res = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 528 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 529 | |
| 530 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 531 | if (bond->params.arp_targets[i]) |
Harvey Harrison | 6377943 | 2008-10-31 00:56:00 -0700 | [diff] [blame] | 532 | res += sprintf(buf + res, "%pI4 ", |
| 533 | &bond->params.arp_targets[i]); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 534 | } |
Wagner Ferenc | 1dcdcd6 | 2007-12-06 23:40:31 -0800 | [diff] [blame] | 535 | if (res) |
| 536 | buf[res-1] = '\n'; /* eat the leftover space */ |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 537 | return res; |
| 538 | } |
| 539 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 540 | static ssize_t bonding_store_arp_targets(struct device *d, |
| 541 | struct device_attribute *attr, |
| 542 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 543 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 544 | struct bonding *bond = to_bond(d); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 545 | __be32 target; |
| 546 | int ret = -EPERM; |
| 547 | |
| 548 | if (!in4_pton(buf + 1, -1, (u8 *)&target, -1, NULL)) { |
| 549 | pr_err("%s: invalid ARP target %pI4 specified\n", |
| 550 | bond->dev->name, &target); |
| 551 | return -EPERM; |
| 552 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 553 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 554 | if (!rtnl_trylock()) |
| 555 | return restart_syscall(); |
| 556 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 557 | if (buf[0] == '+') |
| 558 | ret = bond_option_arp_ip_target_add(bond, target); |
| 559 | else if (buf[0] == '-') |
| 560 | ret = bond_option_arp_ip_target_rem(bond, target); |
| 561 | else |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 562 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 563 | bond->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 564 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 565 | if (!ret) |
| 566 | ret = count; |
| 567 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 568 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 569 | return ret; |
| 570 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 571 | 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] | 572 | |
| 573 | /* |
| 574 | * Show and set the up and down delays. These must be multiples of the |
| 575 | * MII monitoring value, and are stored internally as the multiplier. |
| 576 | * Thus, we must translate to MS for the real world. |
| 577 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 578 | static ssize_t bonding_show_downdelay(struct device *d, |
| 579 | struct device_attribute *attr, |
| 580 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 581 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 582 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 583 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 584 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 587 | static ssize_t bonding_store_downdelay(struct device *d, |
| 588 | struct device_attribute *attr, |
| 589 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 590 | { |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 591 | int new_value, ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 592 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 593 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 594 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 595 | pr_err("%s: no down delay value specified.\n", bond->dev->name); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 596 | return -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 597 | } |
| 598 | |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 599 | if (!rtnl_trylock()) |
| 600 | return restart_syscall(); |
| 601 | |
| 602 | ret = bond_option_downdelay_set(bond, new_value); |
| 603 | if (!ret) |
| 604 | ret = count; |
| 605 | |
Nikolay Aleksandrov | b869ccf | 2013-11-13 17:07:46 +0100 | [diff] [blame] | 606 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 607 | return ret; |
| 608 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 609 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
| 610 | bonding_show_downdelay, bonding_store_downdelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 611 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 612 | static ssize_t bonding_show_updelay(struct device *d, |
| 613 | struct device_attribute *attr, |
| 614 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 615 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 616 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 617 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 618 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 619 | |
| 620 | } |
| 621 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 622 | static ssize_t bonding_store_updelay(struct device *d, |
| 623 | struct device_attribute *attr, |
| 624 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 625 | { |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 626 | int new_value, ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 627 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 628 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 629 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 630 | pr_err("%s: no up delay value specified.\n", |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 631 | bond->dev->name); |
| 632 | return -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 633 | } |
| 634 | |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 635 | if (!rtnl_trylock()) |
| 636 | return restart_syscall(); |
| 637 | |
| 638 | ret = bond_option_updelay_set(bond, new_value); |
| 639 | if (!ret) |
| 640 | ret = count; |
| 641 | |
Nikolay Aleksandrov | b869ccf | 2013-11-13 17:07:46 +0100 | [diff] [blame] | 642 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 643 | return ret; |
| 644 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 645 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
| 646 | bonding_show_updelay, bonding_store_updelay); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 647 | |
| 648 | /* |
| 649 | * Show and set the LACP interval. Interface must be down, and the mode |
| 650 | * must be set to 802.3ad mode. |
| 651 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 652 | static ssize_t bonding_show_lacp(struct device *d, |
| 653 | struct device_attribute *attr, |
| 654 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 655 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 656 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 657 | |
| 658 | return sprintf(buf, "%s %d\n", |
| 659 | bond_lacp_tbl[bond->params.lacp_fast].modename, |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 660 | bond->params.lacp_fast); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 661 | } |
| 662 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 663 | static ssize_t bonding_store_lacp(struct device *d, |
| 664 | struct device_attribute *attr, |
| 665 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 666 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 667 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 668 | int new_value, ret = count; |
| 669 | |
| 670 | if (!rtnl_trylock()) |
| 671 | return restart_syscall(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 672 | |
| 673 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 674 | 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] | 675 | bond->dev->name); |
| 676 | ret = -EPERM; |
| 677 | goto out; |
| 678 | } |
| 679 | |
| 680 | if (bond->params.mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 681 | 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] | 682 | bond->dev->name); |
| 683 | ret = -EPERM; |
| 684 | goto out; |
| 685 | } |
| 686 | |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 687 | new_value = bond_parse_parm(buf, bond_lacp_tbl); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 688 | |
| 689 | if ((new_value == 1) || (new_value == 0)) { |
| 690 | bond->params.lacp_fast = new_value; |
Peter Pan(潘卫平) | ba824a8 | 2011-06-08 21:19:01 +0000 | [diff] [blame] | 691 | bond_3ad_update_lacp_rate(bond); |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 692 | pr_info("%s: Setting LACP rate to %s (%d).\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 693 | bond->dev->name, bond_lacp_tbl[new_value].modename, |
| 694 | new_value); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 695 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 696 | pr_err("%s: Ignoring invalid LACP rate value %.*s.\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 697 | bond->dev->name, (int)strlen(buf) - 1, buf); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 698 | ret = -EINVAL; |
| 699 | } |
| 700 | out: |
nikolay@redhat.com | c509316 | 2013-09-02 13:51:40 +0200 | [diff] [blame] | 701 | rtnl_unlock(); |
| 702 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 703 | return ret; |
| 704 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 705 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
| 706 | bonding_show_lacp, bonding_store_lacp); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 707 | |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 708 | static ssize_t bonding_show_min_links(struct device *d, |
| 709 | struct device_attribute *attr, |
| 710 | char *buf) |
| 711 | { |
| 712 | struct bonding *bond = to_bond(d); |
| 713 | |
| 714 | return sprintf(buf, "%d\n", bond->params.min_links); |
| 715 | } |
| 716 | |
| 717 | static ssize_t bonding_store_min_links(struct device *d, |
| 718 | struct device_attribute *attr, |
| 719 | const char *buf, size_t count) |
| 720 | { |
| 721 | struct bonding *bond = to_bond(d); |
| 722 | int ret; |
| 723 | unsigned int new_value; |
| 724 | |
| 725 | ret = kstrtouint(buf, 0, &new_value); |
| 726 | if (ret < 0) { |
| 727 | pr_err("%s: Ignoring invalid min links value %s.\n", |
| 728 | bond->dev->name, buf); |
| 729 | return ret; |
| 730 | } |
| 731 | |
| 732 | pr_info("%s: Setting min links value to %u\n", |
| 733 | bond->dev->name, new_value); |
| 734 | bond->params.min_links = new_value; |
| 735 | return count; |
| 736 | } |
| 737 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, |
| 738 | bonding_show_min_links, bonding_store_min_links); |
| 739 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 740 | static ssize_t bonding_show_ad_select(struct device *d, |
| 741 | struct device_attribute *attr, |
| 742 | char *buf) |
| 743 | { |
| 744 | struct bonding *bond = to_bond(d); |
| 745 | |
| 746 | return sprintf(buf, "%s %d\n", |
| 747 | ad_select_tbl[bond->params.ad_select].modename, |
| 748 | bond->params.ad_select); |
| 749 | } |
| 750 | |
| 751 | |
| 752 | static ssize_t bonding_store_ad_select(struct device *d, |
| 753 | struct device_attribute *attr, |
| 754 | const char *buf, size_t count) |
| 755 | { |
| 756 | int new_value, ret = count; |
| 757 | struct bonding *bond = to_bond(d); |
| 758 | |
| 759 | if (bond->dev->flags & IFF_UP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 760 | pr_err("%s: Unable to update ad_select because interface is up.\n", |
| 761 | bond->dev->name); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 762 | ret = -EPERM; |
| 763 | goto out; |
| 764 | } |
| 765 | |
| 766 | new_value = bond_parse_parm(buf, ad_select_tbl); |
| 767 | |
| 768 | if (new_value != -1) { |
| 769 | bond->params.ad_select = new_value; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 770 | pr_info("%s: Setting ad_select to %s (%d).\n", |
| 771 | bond->dev->name, ad_select_tbl[new_value].modename, |
| 772 | new_value); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 773 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 774 | pr_err("%s: Ignoring invalid ad_select value %.*s.\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 775 | bond->dev->name, (int)strlen(buf) - 1, buf); |
| 776 | ret = -EINVAL; |
| 777 | } |
| 778 | out: |
| 779 | return ret; |
| 780 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 781 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
| 782 | bonding_show_ad_select, bonding_store_ad_select); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 783 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 784 | /* |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 785 | * Show and set the number of peer notifications to send after a failover event. |
| 786 | */ |
| 787 | static ssize_t bonding_show_num_peer_notif(struct device *d, |
| 788 | struct device_attribute *attr, |
| 789 | char *buf) |
| 790 | { |
| 791 | struct bonding *bond = to_bond(d); |
| 792 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); |
| 793 | } |
| 794 | |
| 795 | static ssize_t bonding_store_num_peer_notif(struct device *d, |
| 796 | struct device_attribute *attr, |
| 797 | const char *buf, size_t count) |
| 798 | { |
| 799 | struct bonding *bond = to_bond(d); |
| 800 | int err = kstrtou8(buf, 10, &bond->params.num_peer_notif); |
| 801 | return err ? err : count; |
| 802 | } |
| 803 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, |
| 804 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 805 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, |
| 806 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); |
| 807 | |
| 808 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 809 | * Show and set the MII monitor interval. There are two tricky bits |
| 810 | * here. First, if MII monitoring is activated, then we must disable |
| 811 | * ARP monitoring. Second, if the timer isn't running, we must |
| 812 | * start it. |
| 813 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 814 | static ssize_t bonding_show_miimon(struct device *d, |
| 815 | struct device_attribute *attr, |
| 816 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 817 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 818 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 819 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 820 | return sprintf(buf, "%d\n", bond->params.miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 821 | } |
| 822 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 823 | static ssize_t bonding_store_miimon(struct device *d, |
| 824 | struct device_attribute *attr, |
| 825 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 826 | { |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 827 | int new_value, ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 828 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 829 | |
| 830 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 831 | pr_err("%s: no miimon value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 832 | bond->dev->name); |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 833 | return -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 834 | } |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 835 | |
| 836 | if (!rtnl_trylock()) |
| 837 | return restart_syscall(); |
| 838 | |
| 839 | ret = bond_option_miimon_set(bond, new_value); |
| 840 | if (!ret) |
| 841 | ret = count; |
| 842 | |
nikolay@redhat.com | fbb0c41 | 2012-11-29 01:31:31 +0000 | [diff] [blame] | 843 | rtnl_unlock(); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 844 | return ret; |
| 845 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 846 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
| 847 | bonding_show_miimon, bonding_store_miimon); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 848 | |
| 849 | /* |
| 850 | * Show and set the primary slave. The store function is much |
| 851 | * simpler than bonding_store_slaves function because it only needs to |
| 852 | * handle one interface name. |
| 853 | * The bond must be a mode that supports a primary for this be |
| 854 | * set. |
| 855 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 856 | static ssize_t bonding_show_primary(struct device *d, |
| 857 | struct device_attribute *attr, |
| 858 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 859 | { |
| 860 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 861 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 862 | |
| 863 | if (bond->primary_slave) |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 864 | count = sprintf(buf, "%s\n", bond->primary_slave->dev->name); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 865 | |
| 866 | return count; |
| 867 | } |
| 868 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 869 | static ssize_t bonding_store_primary(struct device *d, |
| 870 | struct device_attribute *attr, |
| 871 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 872 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 873 | struct bonding *bond = to_bond(d); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 874 | char ifname[IFNAMSIZ]; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 875 | int ret; |
| 876 | |
| 877 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
| 878 | if (ifname[0] == '\n') |
| 879 | ifname[0] = '\0'; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 880 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 881 | if (!rtnl_trylock()) |
| 882 | return restart_syscall(); |
Jay Vosburgh | e934dd7 | 2008-01-17 16:24:57 -0800 | [diff] [blame] | 883 | |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 884 | ret = bond_option_primary_set(bond, ifname); |
| 885 | if (!ret) |
| 886 | ret = count; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 887 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 888 | rtnl_unlock(); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 889 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 890 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 891 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
| 892 | bonding_show_primary, bonding_store_primary); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 893 | |
| 894 | /* |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 895 | * Show and set the primary_reselect flag. |
| 896 | */ |
| 897 | static ssize_t bonding_show_primary_reselect(struct device *d, |
| 898 | struct device_attribute *attr, |
| 899 | char *buf) |
| 900 | { |
| 901 | struct bonding *bond = to_bond(d); |
| 902 | |
| 903 | return sprintf(buf, "%s %d\n", |
| 904 | pri_reselect_tbl[bond->params.primary_reselect].modename, |
| 905 | bond->params.primary_reselect); |
| 906 | } |
| 907 | |
| 908 | static ssize_t bonding_store_primary_reselect(struct device *d, |
| 909 | struct device_attribute *attr, |
| 910 | const char *buf, size_t count) |
| 911 | { |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame^] | 912 | int new_value, ret; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 913 | struct bonding *bond = to_bond(d); |
| 914 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 915 | new_value = bond_parse_parm(buf, pri_reselect_tbl); |
| 916 | if (new_value < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 917 | pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 918 | bond->dev->name, |
| 919 | (int) strlen(buf) - 1, buf); |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame^] | 920 | return -EINVAL; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 921 | } |
| 922 | |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame^] | 923 | if (!rtnl_trylock()) |
| 924 | return restart_syscall(); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 925 | |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame^] | 926 | ret = bond_option_primary_reselect_set(bond, new_value); |
| 927 | if (!ret) |
| 928 | ret = count; |
| 929 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 930 | rtnl_unlock(); |
| 931 | return ret; |
| 932 | } |
| 933 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
| 934 | bonding_show_primary_reselect, |
| 935 | bonding_store_primary_reselect); |
| 936 | |
| 937 | /* |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 938 | * Show and set the use_carrier flag. |
| 939 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 940 | static ssize_t bonding_show_carrier(struct device *d, |
| 941 | struct device_attribute *attr, |
| 942 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 943 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 944 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 945 | |
Wagner Ferenc | 7bd4650 | 2007-12-06 23:40:28 -0800 | [diff] [blame] | 946 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 947 | } |
| 948 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 949 | static ssize_t bonding_store_carrier(struct device *d, |
| 950 | struct device_attribute *attr, |
| 951 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 952 | { |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 953 | int new_value, ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 954 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 955 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 956 | if (sscanf(buf, "%d", &new_value) != 1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 957 | pr_err("%s: no use_carrier value specified.\n", |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 958 | bond->dev->name); |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 959 | return -EINVAL; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 960 | } |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 961 | |
| 962 | if (!rtnl_trylock()) |
| 963 | return restart_syscall(); |
| 964 | |
| 965 | ret = bond_option_use_carrier_set(bond, new_value); |
| 966 | if (!ret) |
| 967 | ret = count; |
| 968 | |
| 969 | rtnl_unlock(); |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 970 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 971 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 972 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
| 973 | bonding_show_carrier, bonding_store_carrier); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 974 | |
| 975 | |
| 976 | /* |
| 977 | * Show and set currently active_slave. |
| 978 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 979 | static ssize_t bonding_show_active_slave(struct device *d, |
| 980 | struct device_attribute *attr, |
| 981 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 982 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 983 | struct bonding *bond = to_bond(d); |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 984 | struct net_device *slave_dev; |
Wagner Ferenc | 16cd016 | 2007-12-06 23:40:29 -0800 | [diff] [blame] | 985 | int count = 0; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 986 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 987 | rcu_read_lock(); |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 988 | slave_dev = bond_option_active_slave_get_rcu(bond); |
| 989 | if (slave_dev) |
| 990 | count = sprintf(buf, "%s\n", slave_dev->name); |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 991 | rcu_read_unlock(); |
| 992 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 993 | return count; |
| 994 | } |
| 995 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 996 | static ssize_t bonding_store_active_slave(struct device *d, |
| 997 | struct device_attribute *attr, |
| 998 | const char *buf, size_t count) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 999 | { |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1000 | int ret; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1001 | struct bonding *bond = to_bond(d); |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1002 | char ifname[IFNAMSIZ]; |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1003 | struct net_device *dev; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1004 | |
Eric W. Biederman | 496a60c | 2009-05-13 17:02:50 +0000 | [diff] [blame] | 1005 | if (!rtnl_trylock()) |
| 1006 | return restart_syscall(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1007 | |
nikolay@redhat.com | c84e159 | 2012-10-31 06:03:52 +0000 | [diff] [blame] | 1008 | sscanf(buf, "%15s", ifname); /* IFNAMSIZ */ |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1009 | if (!strlen(ifname) || buf[0] == '\n') { |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1010 | dev = NULL; |
| 1011 | } else { |
| 1012 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 1013 | if (!dev) { |
| 1014 | ret = -ENODEV; |
| 1015 | goto out; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1016 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1017 | } |
Andy Gospodarek | f4bb2e9 | 2011-07-26 11:12:27 +0000 | [diff] [blame] | 1018 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1019 | ret = bond_option_active_slave_set(bond, dev); |
| 1020 | if (!ret) |
| 1021 | ret = count; |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1022 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1023 | out: |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 1024 | rtnl_unlock(); |
| 1025 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 1026 | return ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1027 | |
| 1028 | } |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1029 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
| 1030 | bonding_show_active_slave, bonding_store_active_slave); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1031 | |
| 1032 | |
| 1033 | /* |
| 1034 | * Show link status of the bond interface. |
| 1035 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1036 | static ssize_t bonding_show_mii_status(struct device *d, |
| 1037 | struct device_attribute *attr, |
| 1038 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1039 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1040 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1041 | |
nikolay@redhat.com | 278b208 | 2013-08-01 16:54:51 +0200 | [diff] [blame] | 1042 | return sprintf(buf, "%s\n", bond->curr_active_slave ? "up" : "down"); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1043 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1044 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1045 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1046 | /* |
| 1047 | * Show current 802.3ad aggregator ID. |
| 1048 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1049 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
| 1050 | struct device_attribute *attr, |
| 1051 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1052 | { |
| 1053 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1054 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1055 | |
| 1056 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1057 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1058 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1059 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1060 | ? 0 : ad_info.aggregator_id); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1061 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1062 | |
| 1063 | return count; |
| 1064 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1065 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1066 | |
| 1067 | |
| 1068 | /* |
| 1069 | * Show number of active 802.3ad ports. |
| 1070 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1071 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
| 1072 | struct device_attribute *attr, |
| 1073 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1074 | { |
| 1075 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1076 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1077 | |
| 1078 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1079 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1080 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1081 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1082 | ? 0 : ad_info.ports); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1083 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1084 | |
| 1085 | return count; |
| 1086 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1087 | 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] | 1088 | |
| 1089 | |
| 1090 | /* |
| 1091 | * Show current 802.3ad actor key. |
| 1092 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1093 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
| 1094 | struct device_attribute *attr, |
| 1095 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1096 | { |
| 1097 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1098 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1099 | |
| 1100 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1101 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1102 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1103 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1104 | ? 0 : ad_info.actor_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1105 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1106 | |
| 1107 | return count; |
| 1108 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1109 | 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] | 1110 | |
| 1111 | |
| 1112 | /* |
| 1113 | * Show current 802.3ad partner key. |
| 1114 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1115 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
| 1116 | struct device_attribute *attr, |
| 1117 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1118 | { |
| 1119 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1120 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1121 | |
| 1122 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1123 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1124 | count = sprintf(buf, "%d\n", |
nikolay@redhat.com | 318debd | 2013-05-18 01:18:31 +0000 | [diff] [blame] | 1125 | bond_3ad_get_active_agg_info(bond, &ad_info) |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1126 | ? 0 : ad_info.partner_key); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1127 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1128 | |
| 1129 | return count; |
| 1130 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1131 | 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] | 1132 | |
| 1133 | |
| 1134 | /* |
| 1135 | * Show current 802.3ad partner mac. |
| 1136 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1137 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
| 1138 | struct device_attribute *attr, |
| 1139 | char *buf) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1140 | { |
| 1141 | int count = 0; |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1142 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1143 | |
| 1144 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1145 | struct ad_info ad_info; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1146 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1147 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1148 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1149 | |
| 1150 | return count; |
| 1151 | } |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1152 | 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] | 1153 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1154 | /* |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1155 | * Show the queue_ids of the slaves in the current bond. |
| 1156 | */ |
| 1157 | static ssize_t bonding_show_queue_id(struct device *d, |
| 1158 | struct device_attribute *attr, |
| 1159 | char *buf) |
| 1160 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1161 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1162 | struct list_head *iter; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1163 | struct slave *slave; |
| 1164 | int res = 0; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1165 | |
| 1166 | if (!rtnl_trylock()) |
| 1167 | return restart_syscall(); |
| 1168 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1169 | bond_for_each_slave(bond, slave, iter) { |
Nicolas de Pesloüan | 7923668 | 2010-07-14 18:24:54 -0700 | [diff] [blame] | 1170 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
| 1171 | /* not enough space for another interface_name:queue_id pair */ |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1172 | if ((PAGE_SIZE - res) > 10) |
| 1173 | res = PAGE_SIZE - 10; |
| 1174 | res += sprintf(buf + res, "++more++ "); |
| 1175 | break; |
| 1176 | } |
| 1177 | res += sprintf(buf + res, "%s:%d ", |
| 1178 | slave->dev->name, slave->queue_id); |
| 1179 | } |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1180 | if (res) |
| 1181 | buf[res-1] = '\n'; /* eat the leftover space */ |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1182 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1183 | rtnl_unlock(); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1184 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1185 | return res; |
| 1186 | } |
| 1187 | |
| 1188 | /* |
| 1189 | * Set the queue_ids of the slaves in the current bond. The bond |
| 1190 | * interface must be enslaved for this to work. |
| 1191 | */ |
| 1192 | static ssize_t bonding_store_queue_id(struct device *d, |
| 1193 | struct device_attribute *attr, |
| 1194 | const char *buffer, size_t count) |
| 1195 | { |
| 1196 | struct slave *slave, *update_slave; |
| 1197 | struct bonding *bond = to_bond(d); |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1198 | struct list_head *iter; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1199 | u16 qid; |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1200 | int ret = count; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1201 | char *delim; |
| 1202 | struct net_device *sdev = NULL; |
| 1203 | |
| 1204 | if (!rtnl_trylock()) |
| 1205 | return restart_syscall(); |
| 1206 | |
| 1207 | /* delim will point to queue id if successful */ |
| 1208 | delim = strchr(buffer, ':'); |
| 1209 | if (!delim) |
| 1210 | goto err_no_cmd; |
| 1211 | |
| 1212 | /* |
| 1213 | * Terminate string that points to device name and bump it |
| 1214 | * up one, so we can read the queue id there. |
| 1215 | */ |
| 1216 | *delim = '\0'; |
| 1217 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1218 | goto err_no_cmd; |
| 1219 | |
| 1220 | /* Check buffer length, valid ifname and queue id */ |
| 1221 | if (strlen(buffer) > IFNAMSIZ || |
| 1222 | !dev_valid_name(buffer) || |
Jiri Pirko | 8a540ff | 2012-07-20 02:28:50 +0000 | [diff] [blame] | 1223 | qid > bond->dev->real_num_tx_queues) |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1224 | goto err_no_cmd; |
| 1225 | |
| 1226 | /* Get the pointer to that interface if it exists */ |
| 1227 | sdev = __dev_get_by_name(dev_net(bond->dev), buffer); |
| 1228 | if (!sdev) |
| 1229 | goto err_no_cmd; |
| 1230 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1231 | /* Search for thes slave and check for duplicate qids */ |
| 1232 | update_slave = NULL; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1233 | bond_for_each_slave(bond, slave, iter) { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1234 | if (sdev == slave->dev) |
| 1235 | /* |
| 1236 | * We don't need to check the matching |
| 1237 | * slave for dups, since we're overwriting it |
| 1238 | */ |
| 1239 | update_slave = slave; |
| 1240 | else if (qid && qid == slave->queue_id) { |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1241 | goto err_no_cmd; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | if (!update_slave) |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1246 | goto err_no_cmd; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1247 | |
| 1248 | /* Actually set the qids for the slave */ |
| 1249 | update_slave->queue_id = qid; |
| 1250 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1251 | out: |
| 1252 | rtnl_unlock(); |
| 1253 | return ret; |
| 1254 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1255 | err_no_cmd: |
| 1256 | pr_info("invalid input for queue_id set for %s.\n", |
| 1257 | bond->dev->name); |
| 1258 | ret = -EPERM; |
| 1259 | goto out; |
| 1260 | } |
| 1261 | |
| 1262 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
| 1263 | bonding_store_queue_id); |
| 1264 | |
| 1265 | |
| 1266 | /* |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1267 | * Show and set the all_slaves_active flag. |
| 1268 | */ |
| 1269 | static ssize_t bonding_show_slaves_active(struct device *d, |
| 1270 | struct device_attribute *attr, |
| 1271 | char *buf) |
| 1272 | { |
| 1273 | struct bonding *bond = to_bond(d); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1274 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1275 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); |
| 1276 | } |
| 1277 | |
| 1278 | static ssize_t bonding_store_slaves_active(struct device *d, |
| 1279 | struct device_attribute *attr, |
| 1280 | const char *buf, size_t count) |
| 1281 | { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1282 | struct bonding *bond = to_bond(d); |
nikolay@redhat.com | dec1e90 | 2013-08-01 16:54:47 +0200 | [diff] [blame] | 1283 | int new_value, ret = count; |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1284 | struct list_head *iter; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1285 | struct slave *slave; |
| 1286 | |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1287 | if (!rtnl_trylock()) |
| 1288 | return restart_syscall(); |
| 1289 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1290 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1291 | pr_err("%s: no all_slaves_active value specified.\n", |
| 1292 | bond->dev->name); |
| 1293 | ret = -EINVAL; |
| 1294 | goto out; |
| 1295 | } |
| 1296 | |
| 1297 | if (new_value == bond->params.all_slaves_active) |
| 1298 | goto out; |
| 1299 | |
| 1300 | if ((new_value == 0) || (new_value == 1)) { |
| 1301 | bond->params.all_slaves_active = new_value; |
| 1302 | } else { |
| 1303 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", |
| 1304 | bond->dev->name, new_value); |
| 1305 | ret = -EINVAL; |
| 1306 | goto out; |
| 1307 | } |
| 1308 | |
Veaceslav Falico | 9caff1e7 | 2013-09-25 09:20:14 +0200 | [diff] [blame] | 1309 | bond_for_each_slave(bond, slave, iter) { |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1310 | if (!bond_is_active_slave(slave)) { |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1311 | if (new_value) |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1312 | slave->inactive = 0; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1313 | else |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1314 | slave->inactive = 1; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | out: |
dingtianhong | 4d1ae5f | 2013-10-15 16:28:42 +0800 | [diff] [blame] | 1318 | rtnl_unlock(); |
Jiri Pirko | 672bda3 | 2011-01-25 11:03:25 +0000 | [diff] [blame] | 1319 | return ret; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1320 | } |
| 1321 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
| 1322 | bonding_show_slaves_active, bonding_store_slaves_active); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1323 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1324 | /* |
| 1325 | * Show and set the number of IGMP membership reports to send on link failure |
| 1326 | */ |
| 1327 | static ssize_t bonding_show_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1328 | struct device_attribute *attr, |
| 1329 | char *buf) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1330 | { |
| 1331 | struct bonding *bond = to_bond(d); |
| 1332 | |
| 1333 | return sprintf(buf, "%d\n", bond->params.resend_igmp); |
| 1334 | } |
| 1335 | |
| 1336 | static ssize_t bonding_store_resend_igmp(struct device *d, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1337 | struct device_attribute *attr, |
| 1338 | const char *buf, size_t count) |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1339 | { |
| 1340 | int new_value, ret = count; |
| 1341 | struct bonding *bond = to_bond(d); |
| 1342 | |
| 1343 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1344 | pr_err("%s: no resend_igmp value specified.\n", |
| 1345 | bond->dev->name); |
| 1346 | ret = -EINVAL; |
| 1347 | goto out; |
| 1348 | } |
| 1349 | |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1350 | if (new_value < 0 || new_value > 255) { |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1351 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
| 1352 | bond->dev->name, new_value); |
| 1353 | ret = -EINVAL; |
| 1354 | goto out; |
| 1355 | } |
| 1356 | |
| 1357 | pr_info("%s: Setting resend_igmp to %d.\n", |
| 1358 | bond->dev->name, new_value); |
| 1359 | bond->params.resend_igmp = new_value; |
| 1360 | out: |
| 1361 | return ret; |
| 1362 | } |
| 1363 | |
| 1364 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
| 1365 | bonding_show_resend_igmp, bonding_store_resend_igmp); |
| 1366 | |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1367 | |
| 1368 | static ssize_t bonding_show_lp_interval(struct device *d, |
| 1369 | struct device_attribute *attr, |
| 1370 | char *buf) |
| 1371 | { |
| 1372 | struct bonding *bond = to_bond(d); |
| 1373 | return sprintf(buf, "%d\n", bond->params.lp_interval); |
| 1374 | } |
| 1375 | |
| 1376 | static ssize_t bonding_store_lp_interval(struct device *d, |
| 1377 | struct device_attribute *attr, |
| 1378 | const char *buf, size_t count) |
| 1379 | { |
| 1380 | struct bonding *bond = to_bond(d); |
| 1381 | int new_value, ret = count; |
| 1382 | |
| 1383 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1384 | pr_err("%s: no lp interval value specified.\n", |
| 1385 | bond->dev->name); |
| 1386 | ret = -EINVAL; |
| 1387 | goto out; |
| 1388 | } |
| 1389 | |
| 1390 | if (new_value <= 0) { |
| 1391 | pr_err ("%s: lp_interval must be between 1 and %d\n", |
| 1392 | bond->dev->name, INT_MAX); |
| 1393 | ret = -EINVAL; |
| 1394 | goto out; |
| 1395 | } |
| 1396 | |
| 1397 | bond->params.lp_interval = new_value; |
| 1398 | out: |
| 1399 | return ret; |
| 1400 | } |
| 1401 | |
| 1402 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, |
| 1403 | bonding_show_lp_interval, bonding_store_lp_interval); |
| 1404 | |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1405 | static ssize_t bonding_show_packets_per_slave(struct device *d, |
| 1406 | struct device_attribute *attr, |
| 1407 | char *buf) |
| 1408 | { |
| 1409 | struct bonding *bond = to_bond(d); |
Nikolay Aleksandrov | a752a8b | 2013-12-05 11:36:58 +0100 | [diff] [blame] | 1410 | unsigned int packets_per_slave = bond->params.packets_per_slave; |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1411 | |
| 1412 | if (packets_per_slave > 1) |
| 1413 | packets_per_slave = reciprocal_value(packets_per_slave); |
| 1414 | |
Nikolay Aleksandrov | a752a8b | 2013-12-05 11:36:58 +0100 | [diff] [blame] | 1415 | return sprintf(buf, "%u\n", packets_per_slave); |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static ssize_t bonding_store_packets_per_slave(struct device *d, |
| 1419 | struct device_attribute *attr, |
| 1420 | const char *buf, size_t count) |
| 1421 | { |
| 1422 | struct bonding *bond = to_bond(d); |
| 1423 | int new_value, ret = count; |
| 1424 | |
| 1425 | if (sscanf(buf, "%d", &new_value) != 1) { |
| 1426 | pr_err("%s: no packets_per_slave value specified.\n", |
| 1427 | bond->dev->name); |
| 1428 | ret = -EINVAL; |
| 1429 | goto out; |
| 1430 | } |
| 1431 | if (new_value < 0 || new_value > USHRT_MAX) { |
| 1432 | pr_err("%s: packets_per_slave must be between 0 and %u\n", |
| 1433 | bond->dev->name, USHRT_MAX); |
| 1434 | ret = -EINVAL; |
| 1435 | goto out; |
| 1436 | } |
| 1437 | if (bond->params.mode != BOND_MODE_ROUNDROBIN) |
| 1438 | pr_warn("%s: Warning: packets_per_slave has effect only in balance-rr mode\n", |
| 1439 | bond->dev->name); |
| 1440 | if (new_value > 1) |
| 1441 | bond->params.packets_per_slave = reciprocal_value(new_value); |
| 1442 | else |
| 1443 | bond->params.packets_per_slave = new_value; |
| 1444 | out: |
| 1445 | return ret; |
| 1446 | } |
| 1447 | |
| 1448 | static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR, |
| 1449 | bonding_show_packets_per_slave, |
| 1450 | bonding_store_packets_per_slave); |
| 1451 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1452 | static struct attribute *per_bond_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1453 | &dev_attr_slaves.attr, |
| 1454 | &dev_attr_mode.attr, |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1455 | &dev_attr_fail_over_mac.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1456 | &dev_attr_arp_validate.attr, |
Veaceslav Falico | 8599b52 | 2013-06-24 11:49:34 +0200 | [diff] [blame] | 1457 | &dev_attr_arp_all_targets.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1458 | &dev_attr_arp_interval.attr, |
| 1459 | &dev_attr_arp_ip_target.attr, |
| 1460 | &dev_attr_downdelay.attr, |
| 1461 | &dev_attr_updelay.attr, |
| 1462 | &dev_attr_lacp_rate.attr, |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 1463 | &dev_attr_ad_select.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1464 | &dev_attr_xmit_hash_policy.attr, |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1465 | &dev_attr_num_grat_arp.attr, |
| 1466 | &dev_attr_num_unsol_na.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1467 | &dev_attr_miimon.attr, |
| 1468 | &dev_attr_primary.attr, |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1469 | &dev_attr_primary_reselect.attr, |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1470 | &dev_attr_use_carrier.attr, |
| 1471 | &dev_attr_active_slave.attr, |
| 1472 | &dev_attr_mii_status.attr, |
| 1473 | &dev_attr_ad_aggregator.attr, |
| 1474 | &dev_attr_ad_num_ports.attr, |
| 1475 | &dev_attr_ad_actor_key.attr, |
| 1476 | &dev_attr_ad_partner_key.attr, |
| 1477 | &dev_attr_ad_partner_mac.attr, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1478 | &dev_attr_queue_id.attr, |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 1479 | &dev_attr_all_slaves_active.attr, |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1480 | &dev_attr_resend_igmp.attr, |
stephen hemminger | 655f891 | 2011-06-22 09:54:39 +0000 | [diff] [blame] | 1481 | &dev_attr_min_links.attr, |
Neil Horman | 7eacd03 | 2013-09-13 11:05:33 -0400 | [diff] [blame] | 1482 | &dev_attr_lp_interval.attr, |
Nikolay Aleksandrov | 7395832 | 2013-11-05 13:51:41 +0100 | [diff] [blame] | 1483 | &dev_attr_packets_per_slave.attr, |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1484 | NULL, |
| 1485 | }; |
| 1486 | |
| 1487 | static struct attribute_group bonding_group = { |
| 1488 | .name = "bonding", |
| 1489 | .attrs = per_bond_attrs, |
| 1490 | }; |
| 1491 | |
| 1492 | /* |
| 1493 | * Initialize sysfs. This sets up the bonding_masters file in |
| 1494 | * /sys/class/net. |
| 1495 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1496 | int bond_create_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1497 | { |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1498 | int ret; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1499 | |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1500 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
Eric W. Biederman | 01718e3 | 2011-10-21 22:43:07 +0000 | [diff] [blame] | 1501 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1502 | |
Tejun Heo | 58292cbe | 2013-09-11 22:29:04 -0400 | [diff] [blame] | 1503 | ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, |
| 1504 | bn->net); |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1505 | /* |
| 1506 | * Permit multiple loads of the module by ignoring failures to |
| 1507 | * create the bonding_masters sysfs file. Bonding devices |
| 1508 | * created by second or subsequent loads of the module will |
| 1509 | * not be listed in, or controllable by, bonding_masters, but |
| 1510 | * will have the usual "bonding" sysfs directory. |
| 1511 | * |
| 1512 | * This is done to preserve backwards compatibility for |
| 1513 | * initscripts/sysconfig, which load bonding multiple times to |
| 1514 | * configure multiple bonding devices. |
| 1515 | */ |
| 1516 | if (ret == -EEXIST) { |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1517 | /* Is someone being kinky and naming a device bonding_master? */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1518 | if (__dev_get_by_name(bn->net, |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1519 | class_attr_bonding_masters.attr.name)) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1520 | pr_err("network device named %s already exists in sysfs", |
Stephen Hemminger | 38d2f38 | 2008-05-14 22:35:04 -0700 | [diff] [blame] | 1521 | class_attr_bonding_masters.attr.name); |
Stephen Hemminger | 130aa61 | 2009-06-11 05:46:04 -0700 | [diff] [blame] | 1522 | ret = 0; |
Jay Vosburgh | 877cbd3 | 2007-01-19 18:15:47 -0800 | [diff] [blame] | 1523 | } |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1524 | |
| 1525 | return ret; |
| 1526 | |
| 1527 | } |
| 1528 | |
| 1529 | /* |
| 1530 | * Remove /sys/class/net/bonding_masters. |
| 1531 | */ |
Eric W. Biederman | 4c22400 | 2011-10-12 21:56:25 +0000 | [diff] [blame] | 1532 | void bond_destroy_sysfs(struct bond_net *bn) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1533 | { |
Tejun Heo | 58292cbe | 2013-09-11 22:29:04 -0400 | [diff] [blame] | 1534 | netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /* |
| 1538 | * Initialize sysfs for each bond. This sets up and registers |
| 1539 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
| 1540 | */ |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1541 | void bond_prepare_sysfs_group(struct bonding *bond) |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1542 | { |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 1543 | bond->dev->sysfs_groups[0] = &bonding_group; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1544 | } |
| 1545 | |