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