Commit | Line | Data |
---|---|---|
b76cdba9 MW |
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 | |
adf8d3ff | 15 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
b76cdba9 MW |
16 | * |
17 | * The full GNU General Public License is included in this distribution in the | |
18 | * file called LICENSE. | |
19 | * | |
b76cdba9 | 20 | */ |
a4aee5c8 JP |
21 | |
22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
23 | ||
b76cdba9 MW |
24 | #include <linux/kernel.h> |
25 | #include <linux/module.h> | |
b76cdba9 | 26 | #include <linux/device.h> |
d43c36dc | 27 | #include <linux/sched.h> |
b76cdba9 MW |
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> | |
b76cdba9 MW |
35 | #include <linux/ctype.h> |
36 | #include <linux/inet.h> | |
37 | #include <linux/rtnetlink.h> | |
5c5129b5 | 38 | #include <linux/etherdevice.h> |
881d966b | 39 | #include <net/net_namespace.h> |
ec87fd3b EB |
40 | #include <net/netns/generic.h> |
41 | #include <linux/nsproxy.h> | |
b76cdba9 | 42 | |
1ef8019b | 43 | #include <net/bonding.h> |
5a03cdb7 | 44 | |
3d632c3f | 45 | #define to_dev(obj) container_of(obj, struct device, kobj) |
454d7c9b | 46 | #define to_bond(cd) ((struct bonding *)(netdev_priv(to_net_dev(cd)))) |
b76cdba9 | 47 | |
dc3e5d18 | 48 | /* "show" function for the bond_masters attribute. |
b76cdba9 MW |
49 | * The class parameter is ignored. |
50 | */ | |
28812fe1 AK |
51 | static ssize_t bonding_show_bonds(struct class *cls, |
52 | struct class_attribute *attr, | |
53 | char *buf) | |
b76cdba9 | 54 | { |
4c22400a EB |
55 | struct bond_net *bn = |
56 | container_of(attr, struct bond_net, class_attr_bonding_masters); | |
b76cdba9 MW |
57 | int res = 0; |
58 | struct bonding *bond; | |
59 | ||
7e083840 | 60 | rtnl_lock(); |
b76cdba9 | 61 | |
ec87fd3b | 62 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
b76cdba9 MW |
63 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
64 | /* not enough space for another interface name */ | |
65 | if ((PAGE_SIZE - res) > 10) | |
66 | res = PAGE_SIZE - 10; | |
b8843665 | 67 | res += sprintf(buf + res, "++more++ "); |
b76cdba9 MW |
68 | break; |
69 | } | |
b8843665 | 70 | res += sprintf(buf + res, "%s ", bond->dev->name); |
b76cdba9 | 71 | } |
1dcdcd69 WF |
72 | if (res) |
73 | buf[res-1] = '\n'; /* eat the leftover space */ | |
7e083840 SH |
74 | |
75 | rtnl_unlock(); | |
b76cdba9 MW |
76 | return res; |
77 | } | |
78 | ||
4c22400a | 79 | static struct net_device *bond_get_by_name(struct bond_net *bn, const char *ifname) |
373500db SH |
80 | { |
81 | struct bonding *bond; | |
82 | ||
ec87fd3b | 83 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
373500db SH |
84 | if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) |
85 | return bond->dev; | |
86 | } | |
87 | return NULL; | |
88 | } | |
89 | ||
dc3e5d18 | 90 | /* "store" function for the bond_masters attribute. This is what |
b76cdba9 MW |
91 | * creates and deletes entire bonds. |
92 | * | |
93 | * The class parameter is ignored. | |
b76cdba9 | 94 | */ |
3d632c3f | 95 | static ssize_t bonding_store_bonds(struct class *cls, |
28812fe1 | 96 | struct class_attribute *attr, |
3d632c3f | 97 | const char *buffer, size_t count) |
b76cdba9 | 98 | { |
4c22400a EB |
99 | struct bond_net *bn = |
100 | container_of(attr, struct bond_net, class_attr_bonding_masters); | |
b76cdba9 MW |
101 | char command[IFNAMSIZ + 1] = {0, }; |
102 | char *ifname; | |
027ea041 | 103 | int rv, res = count; |
b76cdba9 | 104 | |
b76cdba9 MW |
105 | sscanf(buffer, "%16s", command); /* IFNAMSIZ*/ |
106 | ifname = command + 1; | |
107 | if ((strlen(command) <= 1) || | |
108 | !dev_valid_name(ifname)) | |
109 | goto err_no_cmd; | |
110 | ||
111 | if (command[0] == '+') { | |
a4aee5c8 | 112 | pr_info("%s is being created...\n", ifname); |
4c22400a | 113 | rv = bond_create(bn->net, ifname); |
027ea041 | 114 | if (rv) { |
5f86cad1 | 115 | if (rv == -EEXIST) |
90194264 | 116 | pr_info("%s already exists\n", ifname); |
5f86cad1 | 117 | else |
90194264 | 118 | pr_info("%s creation failed\n", ifname); |
027ea041 | 119 | res = rv; |
b76cdba9 | 120 | } |
373500db SH |
121 | } else if (command[0] == '-') { |
122 | struct net_device *bond_dev; | |
b76cdba9 | 123 | |
027ea041 | 124 | rtnl_lock(); |
4c22400a | 125 | bond_dev = bond_get_by_name(bn, ifname); |
373500db | 126 | if (bond_dev) { |
a4aee5c8 | 127 | pr_info("%s is being deleted...\n", ifname); |
373500db SH |
128 | unregister_netdevice(bond_dev); |
129 | } else { | |
a4aee5c8 | 130 | pr_err("unable to delete non-existent %s\n", ifname); |
373500db SH |
131 | res = -ENODEV; |
132 | } | |
133 | rtnl_unlock(); | |
134 | } else | |
135 | goto err_no_cmd; | |
027ea041 | 136 | |
373500db SH |
137 | /* Always return either count or an error. If you return 0, you'll |
138 | * get called forever, which is bad. | |
139 | */ | |
140 | return res; | |
b76cdba9 MW |
141 | |
142 | err_no_cmd: | |
90194264 | 143 | pr_err("no command found in bonding_masters - use +ifname or -ifname\n"); |
c4ebc66a | 144 | return -EPERM; |
b76cdba9 | 145 | } |
373500db | 146 | |
b76cdba9 | 147 | /* class attribute for bond_masters file. This ends up in /sys/class/net */ |
4c22400a EB |
148 | static const struct class_attribute class_attr_bonding_masters = { |
149 | .attr = { | |
150 | .name = "bonding_masters", | |
151 | .mode = S_IWUSR | S_IRUGO, | |
152 | }, | |
153 | .show = bonding_show_bonds, | |
154 | .store = bonding_store_bonds, | |
4c22400a | 155 | }; |
b76cdba9 | 156 | |
dc3e5d18 NA |
157 | /* Generic "store" method for bonding sysfs option setting */ |
158 | static ssize_t bonding_sysfs_store_option(struct device *d, | |
159 | struct device_attribute *attr, | |
160 | const char *buffer, size_t count) | |
161 | { | |
162 | struct bonding *bond = to_bond(d); | |
163 | const struct bond_option *opt; | |
164 | int ret; | |
165 | ||
166 | opt = bond_opt_get_by_name(attr->attr.name); | |
167 | if (WARN_ON(!opt)) | |
168 | return -ENOENT; | |
169 | ret = bond_opt_tryset_rtnl(bond, opt->id, (char *)buffer); | |
170 | if (!ret) | |
171 | ret = count; | |
172 | ||
173 | return ret; | |
174 | } | |
175 | ||
176 | /* Show the slaves in the current bond. */ | |
43cb76d9 GKH |
177 | static ssize_t bonding_show_slaves(struct device *d, |
178 | struct device_attribute *attr, char *buf) | |
b76cdba9 | 179 | { |
43cb76d9 | 180 | struct bonding *bond = to_bond(d); |
9caff1e7 | 181 | struct list_head *iter; |
dec1e90e | 182 | struct slave *slave; |
183 | int res = 0; | |
b76cdba9 | 184 | |
4d1ae5fb | 185 | if (!rtnl_trylock()) |
186 | return restart_syscall(); | |
187 | ||
9caff1e7 | 188 | bond_for_each_slave(bond, slave, iter) { |
b76cdba9 MW |
189 | if (res > (PAGE_SIZE - IFNAMSIZ)) { |
190 | /* not enough space for another interface name */ | |
191 | if ((PAGE_SIZE - res) > 10) | |
192 | res = PAGE_SIZE - 10; | |
7bd46508 | 193 | res += sprintf(buf + res, "++more++ "); |
b76cdba9 MW |
194 | break; |
195 | } | |
196 | res += sprintf(buf + res, "%s ", slave->dev->name); | |
197 | } | |
4d1ae5fb | 198 | |
199 | rtnl_unlock(); | |
200 | ||
1dcdcd69 WF |
201 | if (res) |
202 | buf[res-1] = '\n'; /* eat the leftover space */ | |
dec1e90e | 203 | |
b76cdba9 MW |
204 | return res; |
205 | } | |
3d632c3f | 206 | static DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, |
dc3e5d18 | 207 | bonding_sysfs_store_option); |
b76cdba9 | 208 | |
dc3e5d18 | 209 | /* Show the bonding mode. */ |
43cb76d9 GKH |
210 | static ssize_t bonding_show_mode(struct device *d, |
211 | struct device_attribute *attr, char *buf) | |
b76cdba9 | 212 | { |
43cb76d9 | 213 | struct bonding *bond = to_bond(d); |
f3253339 | 214 | const struct bond_opt_value *val; |
b76cdba9 | 215 | |
01844098 | 216 | val = bond_opt_get_val(BOND_OPT_MODE, BOND_MODE(bond)); |
2b3798d5 | 217 | |
01844098 | 218 | return sprintf(buf, "%s %d\n", val->string, BOND_MODE(bond)); |
b76cdba9 | 219 | } |
3d632c3f | 220 | static DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, |
dc3e5d18 | 221 | bonding_show_mode, bonding_sysfs_store_option); |
b76cdba9 | 222 | |
dc3e5d18 | 223 | /* Show the bonding transmit hash method. */ |
43cb76d9 GKH |
224 | static ssize_t bonding_show_xmit_hash(struct device *d, |
225 | struct device_attribute *attr, | |
226 | char *buf) | |
b76cdba9 | 227 | { |
43cb76d9 | 228 | struct bonding *bond = to_bond(d); |
f3253339 | 229 | const struct bond_opt_value *val; |
a4b32ce7 NA |
230 | |
231 | val = bond_opt_get_val(BOND_OPT_XMIT_HASH, bond->params.xmit_policy); | |
b76cdba9 | 232 | |
a4b32ce7 | 233 | return sprintf(buf, "%s %d\n", val->string, bond->params.xmit_policy); |
b76cdba9 | 234 | } |
3d632c3f | 235 | static DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, |
dc3e5d18 | 236 | bonding_show_xmit_hash, bonding_sysfs_store_option); |
b76cdba9 | 237 | |
dc3e5d18 | 238 | /* Show arp_validate. */ |
43cb76d9 GKH |
239 | static ssize_t bonding_show_arp_validate(struct device *d, |
240 | struct device_attribute *attr, | |
241 | char *buf) | |
f5b2b966 | 242 | { |
43cb76d9 | 243 | struct bonding *bond = to_bond(d); |
f3253339 | 244 | const struct bond_opt_value *val; |
16228881 NA |
245 | |
246 | val = bond_opt_get_val(BOND_OPT_ARP_VALIDATE, | |
247 | bond->params.arp_validate); | |
f5b2b966 | 248 | |
16228881 | 249 | return sprintf(buf, "%s %d\n", val->string, bond->params.arp_validate); |
f5b2b966 | 250 | } |
3d632c3f | 251 | static DEVICE_ATTR(arp_validate, S_IRUGO | S_IWUSR, bonding_show_arp_validate, |
dc3e5d18 NA |
252 | bonding_sysfs_store_option); |
253 | ||
254 | /* Show arp_all_targets. */ | |
8599b52e VF |
255 | static ssize_t bonding_show_arp_all_targets(struct device *d, |
256 | struct device_attribute *attr, | |
257 | char *buf) | |
258 | { | |
259 | struct bonding *bond = to_bond(d); | |
f3253339 | 260 | const struct bond_opt_value *val; |
8599b52e | 261 | |
edf36b24 NA |
262 | val = bond_opt_get_val(BOND_OPT_ARP_ALL_TARGETS, |
263 | bond->params.arp_all_targets); | |
264 | return sprintf(buf, "%s %d\n", | |
265 | val->string, bond->params.arp_all_targets); | |
8599b52e | 266 | } |
8599b52e | 267 | static DEVICE_ATTR(arp_all_targets, S_IRUGO | S_IWUSR, |
dc3e5d18 | 268 | bonding_show_arp_all_targets, bonding_sysfs_store_option); |
f5b2b966 | 269 | |
dc3e5d18 | 270 | /* Show fail_over_mac. */ |
3d632c3f SH |
271 | static ssize_t bonding_show_fail_over_mac(struct device *d, |
272 | struct device_attribute *attr, | |
273 | char *buf) | |
dd957c57 JV |
274 | { |
275 | struct bonding *bond = to_bond(d); | |
f3253339 | 276 | const struct bond_opt_value *val; |
dd957c57 | 277 | |
1df6b6aa NA |
278 | val = bond_opt_get_val(BOND_OPT_FAIL_OVER_MAC, |
279 | bond->params.fail_over_mac); | |
280 | ||
281 | return sprintf(buf, "%s %d\n", val->string, bond->params.fail_over_mac); | |
dd957c57 | 282 | } |
3d632c3f | 283 | static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR, |
dc3e5d18 | 284 | bonding_show_fail_over_mac, bonding_sysfs_store_option); |
dd957c57 | 285 | |
dc3e5d18 | 286 | /* Show the arp timer interval. */ |
43cb76d9 GKH |
287 | static ssize_t bonding_show_arp_interval(struct device *d, |
288 | struct device_attribute *attr, | |
289 | char *buf) | |
b76cdba9 | 290 | { |
43cb76d9 | 291 | struct bonding *bond = to_bond(d); |
b76cdba9 | 292 | |
7bd46508 | 293 | return sprintf(buf, "%d\n", bond->params.arp_interval); |
b76cdba9 | 294 | } |
3d632c3f | 295 | static DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR, |
dc3e5d18 | 296 | bonding_show_arp_interval, bonding_sysfs_store_option); |
b76cdba9 | 297 | |
dc3e5d18 | 298 | /* Show the arp targets. */ |
43cb76d9 GKH |
299 | static ssize_t bonding_show_arp_targets(struct device *d, |
300 | struct device_attribute *attr, | |
301 | char *buf) | |
b76cdba9 | 302 | { |
43cb76d9 | 303 | struct bonding *bond = to_bond(d); |
4fb0ef58 | 304 | int i, res = 0; |
b76cdba9 MW |
305 | |
306 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { | |
307 | if (bond->params.arp_targets[i]) | |
63779436 HH |
308 | res += sprintf(buf + res, "%pI4 ", |
309 | &bond->params.arp_targets[i]); | |
b76cdba9 | 310 | } |
1dcdcd69 WF |
311 | if (res) |
312 | buf[res-1] = '\n'; /* eat the leftover space */ | |
4fb0ef58 | 313 | |
b76cdba9 MW |
314 | return res; |
315 | } | |
dc3e5d18 NA |
316 | static DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR, |
317 | bonding_show_arp_targets, bonding_sysfs_store_option); | |
b76cdba9 | 318 | |
dc3e5d18 | 319 | /* Show the up and down delays. */ |
43cb76d9 GKH |
320 | static ssize_t bonding_show_downdelay(struct device *d, |
321 | struct device_attribute *attr, | |
322 | char *buf) | |
b76cdba9 | 323 | { |
43cb76d9 | 324 | struct bonding *bond = to_bond(d); |
b76cdba9 | 325 | |
7bd46508 | 326 | return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon); |
b76cdba9 | 327 | } |
3d632c3f | 328 | static DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR, |
dc3e5d18 | 329 | bonding_show_downdelay, bonding_sysfs_store_option); |
b76cdba9 | 330 | |
43cb76d9 GKH |
331 | static ssize_t bonding_show_updelay(struct device *d, |
332 | struct device_attribute *attr, | |
333 | char *buf) | |
b76cdba9 | 334 | { |
43cb76d9 | 335 | struct bonding *bond = to_bond(d); |
b76cdba9 | 336 | |
7bd46508 | 337 | return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon); |
b76cdba9 MW |
338 | |
339 | } | |
3d632c3f | 340 | static DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR, |
dc3e5d18 | 341 | bonding_show_updelay, bonding_sysfs_store_option); |
b76cdba9 | 342 | |
dc3e5d18 | 343 | /* Show the LACP interval. */ |
43cb76d9 GKH |
344 | static ssize_t bonding_show_lacp(struct device *d, |
345 | struct device_attribute *attr, | |
346 | char *buf) | |
b76cdba9 | 347 | { |
43cb76d9 | 348 | struct bonding *bond = to_bond(d); |
f3253339 | 349 | const struct bond_opt_value *val; |
b76cdba9 | 350 | |
d3131de7 NA |
351 | val = bond_opt_get_val(BOND_OPT_LACP_RATE, bond->params.lacp_fast); |
352 | ||
353 | return sprintf(buf, "%s %d\n", val->string, bond->params.lacp_fast); | |
b76cdba9 | 354 | } |
3d632c3f | 355 | static DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, |
dc3e5d18 | 356 | bonding_show_lacp, bonding_sysfs_store_option); |
b76cdba9 | 357 | |
655f8919 | 358 | static ssize_t bonding_show_min_links(struct device *d, |
359 | struct device_attribute *attr, | |
360 | char *buf) | |
361 | { | |
362 | struct bonding *bond = to_bond(d); | |
363 | ||
014f1b20 | 364 | return sprintf(buf, "%u\n", bond->params.min_links); |
655f8919 | 365 | } |
655f8919 | 366 | static DEVICE_ATTR(min_links, S_IRUGO | S_IWUSR, |
dc3e5d18 | 367 | bonding_show_min_links, bonding_sysfs_store_option); |
655f8919 | 368 | |
fd989c83 JV |
369 | static ssize_t bonding_show_ad_select(struct device *d, |
370 | struct device_attribute *attr, | |
371 | char *buf) | |
372 | { | |
373 | struct bonding *bond = to_bond(d); | |
f3253339 | 374 | const struct bond_opt_value *val; |
fd989c83 | 375 | |
9e5f5eeb NA |
376 | val = bond_opt_get_val(BOND_OPT_AD_SELECT, bond->params.ad_select); |
377 | ||
378 | return sprintf(buf, "%s %d\n", val->string, bond->params.ad_select); | |
fd989c83 | 379 | } |
3d632c3f | 380 | static DEVICE_ATTR(ad_select, S_IRUGO | S_IWUSR, |
dc3e5d18 | 381 | bonding_show_ad_select, bonding_sysfs_store_option); |
fd989c83 | 382 | |
dc3e5d18 | 383 | /* Show and set the number of peer notifications to send after a failover event. */ |
ad246c99 BH |
384 | static ssize_t bonding_show_num_peer_notif(struct device *d, |
385 | struct device_attribute *attr, | |
386 | char *buf) | |
387 | { | |
388 | struct bonding *bond = to_bond(d); | |
389 | return sprintf(buf, "%d\n", bond->params.num_peer_notif); | |
390 | } | |
391 | ||
392 | static ssize_t bonding_store_num_peer_notif(struct device *d, | |
393 | struct device_attribute *attr, | |
394 | const char *buf, size_t count) | |
395 | { | |
396 | struct bonding *bond = to_bond(d); | |
2c9839c1 | 397 | int ret; |
398 | ||
ef56becb | 399 | ret = bond_opt_tryset_rtnl(bond, BOND_OPT_NUM_PEER_NOTIF, (char *)buf); |
2c9839c1 | 400 | if (!ret) |
401 | ret = count; | |
402 | ||
2c9839c1 | 403 | return ret; |
ad246c99 BH |
404 | } |
405 | static DEVICE_ATTR(num_grat_arp, S_IRUGO | S_IWUSR, | |
406 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
407 | static DEVICE_ATTR(num_unsol_na, S_IRUGO | S_IWUSR, | |
408 | bonding_show_num_peer_notif, bonding_store_num_peer_notif); | |
409 | ||
dc3e5d18 | 410 | /* Show the MII monitor interval. */ |
43cb76d9 GKH |
411 | static ssize_t bonding_show_miimon(struct device *d, |
412 | struct device_attribute *attr, | |
413 | char *buf) | |
b76cdba9 | 414 | { |
43cb76d9 | 415 | struct bonding *bond = to_bond(d); |
b76cdba9 | 416 | |
7bd46508 | 417 | return sprintf(buf, "%d\n", bond->params.miimon); |
b76cdba9 | 418 | } |
3d632c3f | 419 | static DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, |
dc3e5d18 | 420 | bonding_show_miimon, bonding_sysfs_store_option); |
b76cdba9 | 421 | |
dc3e5d18 | 422 | /* Show the primary slave. */ |
43cb76d9 GKH |
423 | static ssize_t bonding_show_primary(struct device *d, |
424 | struct device_attribute *attr, | |
425 | char *buf) | |
b76cdba9 | 426 | { |
43cb76d9 | 427 | struct bonding *bond = to_bond(d); |
059b47e8 NA |
428 | struct slave *primary; |
429 | int count = 0; | |
b76cdba9 | 430 | |
059b47e8 NA |
431 | rcu_read_lock(); |
432 | primary = rcu_dereference(bond->primary_slave); | |
433 | if (primary) | |
434 | count = sprintf(buf, "%s\n", primary->dev->name); | |
435 | rcu_read_unlock(); | |
b76cdba9 MW |
436 | |
437 | return count; | |
438 | } | |
3d632c3f | 439 | static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, |
dc3e5d18 | 440 | bonding_show_primary, bonding_sysfs_store_option); |
b76cdba9 | 441 | |
dc3e5d18 | 442 | /* Show the primary_reselect flag. */ |
a549952a JP |
443 | static ssize_t bonding_show_primary_reselect(struct device *d, |
444 | struct device_attribute *attr, | |
445 | char *buf) | |
446 | { | |
447 | struct bonding *bond = to_bond(d); | |
f3253339 | 448 | const struct bond_opt_value *val; |
388d3a6d NA |
449 | |
450 | val = bond_opt_get_val(BOND_OPT_PRIMARY_RESELECT, | |
451 | bond->params.primary_reselect); | |
a549952a JP |
452 | |
453 | return sprintf(buf, "%s %d\n", | |
388d3a6d | 454 | val->string, bond->params.primary_reselect); |
a549952a | 455 | } |
a549952a | 456 | static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR, |
dc3e5d18 | 457 | bonding_show_primary_reselect, bonding_sysfs_store_option); |
a549952a | 458 | |
dc3e5d18 | 459 | /* Show the use_carrier flag. */ |
43cb76d9 GKH |
460 | static ssize_t bonding_show_carrier(struct device *d, |
461 | struct device_attribute *attr, | |
462 | char *buf) | |
b76cdba9 | 463 | { |
43cb76d9 | 464 | struct bonding *bond = to_bond(d); |
b76cdba9 | 465 | |
7bd46508 | 466 | return sprintf(buf, "%d\n", bond->params.use_carrier); |
b76cdba9 | 467 | } |
3d632c3f | 468 | static DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, |
dc3e5d18 | 469 | bonding_show_carrier, bonding_sysfs_store_option); |
b76cdba9 MW |
470 | |
471 | ||
dc3e5d18 | 472 | /* Show currently active_slave. */ |
43cb76d9 GKH |
473 | static ssize_t bonding_show_active_slave(struct device *d, |
474 | struct device_attribute *attr, | |
475 | char *buf) | |
b76cdba9 | 476 | { |
43cb76d9 | 477 | struct bonding *bond = to_bond(d); |
752d48b5 | 478 | struct net_device *slave_dev; |
16cd0160 | 479 | int count = 0; |
b76cdba9 | 480 | |
278b2083 | 481 | rcu_read_lock(); |
752d48b5 JP |
482 | slave_dev = bond_option_active_slave_get_rcu(bond); |
483 | if (slave_dev) | |
484 | count = sprintf(buf, "%s\n", slave_dev->name); | |
278b2083 | 485 | rcu_read_unlock(); |
486 | ||
b76cdba9 MW |
487 | return count; |
488 | } | |
3d632c3f | 489 | static DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, |
dc3e5d18 | 490 | bonding_show_active_slave, bonding_sysfs_store_option); |
b76cdba9 | 491 | |
dc3e5d18 | 492 | /* Show link status of the bond interface. */ |
43cb76d9 GKH |
493 | static ssize_t bonding_show_mii_status(struct device *d, |
494 | struct device_attribute *attr, | |
495 | char *buf) | |
b76cdba9 | 496 | { |
43cb76d9 | 497 | struct bonding *bond = to_bond(d); |
c2646b59 | 498 | bool active = !!rcu_access_pointer(bond->curr_active_slave); |
b76cdba9 | 499 | |
c2646b59 | 500 | return sprintf(buf, "%s\n", active ? "up" : "down"); |
b76cdba9 | 501 | } |
43cb76d9 | 502 | static DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL); |
b76cdba9 | 503 | |
dc3e5d18 | 504 | /* Show current 802.3ad aggregator ID. */ |
43cb76d9 GKH |
505 | static ssize_t bonding_show_ad_aggregator(struct device *d, |
506 | struct device_attribute *attr, | |
507 | char *buf) | |
b76cdba9 MW |
508 | { |
509 | int count = 0; | |
43cb76d9 | 510 | struct bonding *bond = to_bond(d); |
b76cdba9 | 511 | |
01844098 | 512 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
b76cdba9 | 513 | struct ad_info ad_info; |
3d632c3f | 514 | count = sprintf(buf, "%d\n", |
318debd8 | 515 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 516 | ? 0 : ad_info.aggregator_id); |
b76cdba9 | 517 | } |
b76cdba9 MW |
518 | |
519 | return count; | |
520 | } | |
43cb76d9 | 521 | static DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL); |
b76cdba9 MW |
522 | |
523 | ||
dc3e5d18 | 524 | /* Show number of active 802.3ad ports. */ |
43cb76d9 GKH |
525 | static ssize_t bonding_show_ad_num_ports(struct device *d, |
526 | struct device_attribute *attr, | |
527 | char *buf) | |
b76cdba9 MW |
528 | { |
529 | int count = 0; | |
43cb76d9 | 530 | struct bonding *bond = to_bond(d); |
b76cdba9 | 531 | |
01844098 | 532 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
b76cdba9 | 533 | struct ad_info ad_info; |
3d632c3f | 534 | count = sprintf(buf, "%d\n", |
318debd8 | 535 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 536 | ? 0 : ad_info.ports); |
b76cdba9 | 537 | } |
b76cdba9 MW |
538 | |
539 | return count; | |
540 | } | |
43cb76d9 | 541 | static DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL); |
b76cdba9 MW |
542 | |
543 | ||
dc3e5d18 | 544 | /* Show current 802.3ad actor key. */ |
43cb76d9 GKH |
545 | static ssize_t bonding_show_ad_actor_key(struct device *d, |
546 | struct device_attribute *attr, | |
547 | char *buf) | |
b76cdba9 MW |
548 | { |
549 | int count = 0; | |
43cb76d9 | 550 | struct bonding *bond = to_bond(d); |
b76cdba9 | 551 | |
4cd6b475 | 552 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { |
b76cdba9 | 553 | struct ad_info ad_info; |
3d632c3f | 554 | count = sprintf(buf, "%d\n", |
318debd8 | 555 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 556 | ? 0 : ad_info.actor_key); |
b76cdba9 | 557 | } |
b76cdba9 MW |
558 | |
559 | return count; | |
560 | } | |
43cb76d9 | 561 | static DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL); |
b76cdba9 MW |
562 | |
563 | ||
dc3e5d18 | 564 | /* Show current 802.3ad partner key. */ |
43cb76d9 GKH |
565 | static ssize_t bonding_show_ad_partner_key(struct device *d, |
566 | struct device_attribute *attr, | |
567 | char *buf) | |
b76cdba9 MW |
568 | { |
569 | int count = 0; | |
43cb76d9 | 570 | struct bonding *bond = to_bond(d); |
b76cdba9 | 571 | |
4cd6b475 | 572 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { |
b76cdba9 | 573 | struct ad_info ad_info; |
3d632c3f | 574 | count = sprintf(buf, "%d\n", |
318debd8 | 575 | bond_3ad_get_active_agg_info(bond, &ad_info) |
3d632c3f | 576 | ? 0 : ad_info.partner_key); |
b76cdba9 | 577 | } |
b76cdba9 MW |
578 | |
579 | return count; | |
580 | } | |
43cb76d9 | 581 | static DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL); |
b76cdba9 MW |
582 | |
583 | ||
dc3e5d18 | 584 | /* Show current 802.3ad partner mac. */ |
43cb76d9 GKH |
585 | static ssize_t bonding_show_ad_partner_mac(struct device *d, |
586 | struct device_attribute *attr, | |
587 | char *buf) | |
b76cdba9 MW |
588 | { |
589 | int count = 0; | |
43cb76d9 | 590 | struct bonding *bond = to_bond(d); |
b76cdba9 | 591 | |
4cd6b475 | 592 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) { |
b76cdba9 | 593 | struct ad_info ad_info; |
3d632c3f | 594 | if (!bond_3ad_get_active_agg_info(bond, &ad_info)) |
e174961c | 595 | count = sprintf(buf, "%pM\n", ad_info.partner_system); |
b76cdba9 | 596 | } |
b76cdba9 MW |
597 | |
598 | return count; | |
599 | } | |
43cb76d9 | 600 | static DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL); |
b76cdba9 | 601 | |
dc3e5d18 | 602 | /* Show the queue_ids of the slaves in the current bond. */ |
bb1d9123 AG |
603 | static ssize_t bonding_show_queue_id(struct device *d, |
604 | struct device_attribute *attr, | |
605 | char *buf) | |
606 | { | |
bb1d9123 | 607 | struct bonding *bond = to_bond(d); |
9caff1e7 | 608 | struct list_head *iter; |
dec1e90e | 609 | struct slave *slave; |
610 | int res = 0; | |
bb1d9123 AG |
611 | |
612 | if (!rtnl_trylock()) | |
613 | return restart_syscall(); | |
614 | ||
9caff1e7 | 615 | bond_for_each_slave(bond, slave, iter) { |
79236680 NP |
616 | if (res > (PAGE_SIZE - IFNAMSIZ - 6)) { |
617 | /* not enough space for another interface_name:queue_id pair */ | |
bb1d9123 AG |
618 | if ((PAGE_SIZE - res) > 10) |
619 | res = PAGE_SIZE - 10; | |
620 | res += sprintf(buf + res, "++more++ "); | |
621 | break; | |
622 | } | |
623 | res += sprintf(buf + res, "%s:%d ", | |
624 | slave->dev->name, slave->queue_id); | |
625 | } | |
bb1d9123 AG |
626 | if (res) |
627 | buf[res-1] = '\n'; /* eat the leftover space */ | |
4d1ae5fb | 628 | |
bb1d9123 | 629 | rtnl_unlock(); |
dec1e90e | 630 | |
bb1d9123 AG |
631 | return res; |
632 | } | |
bb1d9123 | 633 | static DEVICE_ATTR(queue_id, S_IRUGO | S_IWUSR, bonding_show_queue_id, |
dc3e5d18 | 634 | bonding_sysfs_store_option); |
bb1d9123 AG |
635 | |
636 | ||
dc3e5d18 | 637 | /* Show the all_slaves_active flag. */ |
ebd8e497 AG |
638 | static ssize_t bonding_show_slaves_active(struct device *d, |
639 | struct device_attribute *attr, | |
640 | char *buf) | |
641 | { | |
642 | struct bonding *bond = to_bond(d); | |
643 | ||
644 | return sprintf(buf, "%d\n", bond->params.all_slaves_active); | |
645 | } | |
ebd8e497 | 646 | static DEVICE_ATTR(all_slaves_active, S_IRUGO | S_IWUSR, |
dc3e5d18 | 647 | bonding_show_slaves_active, bonding_sysfs_store_option); |
b76cdba9 | 648 | |
dc3e5d18 | 649 | /* Show the number of IGMP membership reports to send on link failure */ |
c2952c31 | 650 | static ssize_t bonding_show_resend_igmp(struct device *d, |
94265cf5 FL |
651 | struct device_attribute *attr, |
652 | char *buf) | |
c2952c31 FL |
653 | { |
654 | struct bonding *bond = to_bond(d); | |
655 | ||
656 | return sprintf(buf, "%d\n", bond->params.resend_igmp); | |
657 | } | |
c2952c31 | 658 | static DEVICE_ATTR(resend_igmp, S_IRUGO | S_IWUSR, |
dc3e5d18 | 659 | bonding_show_resend_igmp, bonding_sysfs_store_option); |
c2952c31 | 660 | |
7eacd038 NH |
661 | |
662 | static ssize_t bonding_show_lp_interval(struct device *d, | |
663 | struct device_attribute *attr, | |
664 | char *buf) | |
665 | { | |
666 | struct bonding *bond = to_bond(d); | |
8d836d09 | 667 | |
dc3e5d18 | 668 | return sprintf(buf, "%d\n", bond->params.lp_interval); |
7eacd038 | 669 | } |
7eacd038 | 670 | static DEVICE_ATTR(lp_interval, S_IRUGO | S_IWUSR, |
dc3e5d18 | 671 | bonding_show_lp_interval, bonding_sysfs_store_option); |
7eacd038 | 672 | |
e9f0fb88 MB |
673 | static ssize_t bonding_show_tlb_dynamic_lb(struct device *d, |
674 | struct device_attribute *attr, | |
675 | char *buf) | |
676 | { | |
677 | struct bonding *bond = to_bond(d); | |
678 | return sprintf(buf, "%d\n", bond->params.tlb_dynamic_lb); | |
679 | } | |
e9f0fb88 | 680 | static DEVICE_ATTR(tlb_dynamic_lb, S_IRUGO | S_IWUSR, |
dc3e5d18 | 681 | bonding_show_tlb_dynamic_lb, bonding_sysfs_store_option); |
e9f0fb88 | 682 | |
73958329 NA |
683 | static ssize_t bonding_show_packets_per_slave(struct device *d, |
684 | struct device_attribute *attr, | |
685 | char *buf) | |
686 | { | |
687 | struct bonding *bond = to_bond(d); | |
a752a8b9 | 688 | unsigned int packets_per_slave = bond->params.packets_per_slave; |
c13ab3ff | 689 | |
dc3e5d18 | 690 | return sprintf(buf, "%u\n", packets_per_slave); |
73958329 | 691 | } |
73958329 | 692 | static DEVICE_ATTR(packets_per_slave, S_IRUGO | S_IWUSR, |
dc3e5d18 | 693 | bonding_show_packets_per_slave, bonding_sysfs_store_option); |
73958329 | 694 | |
6791e466 MB |
695 | static ssize_t bonding_show_ad_actor_sys_prio(struct device *d, |
696 | struct device_attribute *attr, | |
697 | char *buf) | |
698 | { | |
699 | struct bonding *bond = to_bond(d); | |
700 | ||
4cd6b475 | 701 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) |
6791e466 MB |
702 | return sprintf(buf, "%hu\n", bond->params.ad_actor_sys_prio); |
703 | ||
704 | return 0; | |
705 | } | |
706 | static DEVICE_ATTR(ad_actor_sys_prio, S_IRUGO | S_IWUSR, | |
707 | bonding_show_ad_actor_sys_prio, bonding_sysfs_store_option); | |
708 | ||
74514957 MB |
709 | static ssize_t bonding_show_ad_actor_system(struct device *d, |
710 | struct device_attribute *attr, | |
711 | char *buf) | |
712 | { | |
713 | struct bonding *bond = to_bond(d); | |
714 | ||
4cd6b475 | 715 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) |
74514957 MB |
716 | return sprintf(buf, "%pM\n", bond->params.ad_actor_system); |
717 | ||
718 | return 0; | |
719 | } | |
720 | ||
721 | static DEVICE_ATTR(ad_actor_system, S_IRUGO | S_IWUSR, | |
722 | bonding_show_ad_actor_system, bonding_sysfs_store_option); | |
723 | ||
d22a5fc0 MB |
724 | static ssize_t bonding_show_ad_user_port_key(struct device *d, |
725 | struct device_attribute *attr, | |
726 | char *buf) | |
727 | { | |
728 | struct bonding *bond = to_bond(d); | |
729 | ||
4cd6b475 | 730 | if (BOND_MODE(bond) == BOND_MODE_8023AD && capable(CAP_NET_ADMIN)) |
d22a5fc0 MB |
731 | return sprintf(buf, "%hu\n", bond->params.ad_user_port_key); |
732 | ||
733 | return 0; | |
734 | } | |
735 | static DEVICE_ATTR(ad_user_port_key, S_IRUGO | S_IWUSR, | |
736 | bonding_show_ad_user_port_key, bonding_sysfs_store_option); | |
737 | ||
b76cdba9 | 738 | static struct attribute *per_bond_attrs[] = { |
43cb76d9 GKH |
739 | &dev_attr_slaves.attr, |
740 | &dev_attr_mode.attr, | |
dd957c57 | 741 | &dev_attr_fail_over_mac.attr, |
43cb76d9 | 742 | &dev_attr_arp_validate.attr, |
8599b52e | 743 | &dev_attr_arp_all_targets.attr, |
43cb76d9 GKH |
744 | &dev_attr_arp_interval.attr, |
745 | &dev_attr_arp_ip_target.attr, | |
746 | &dev_attr_downdelay.attr, | |
747 | &dev_attr_updelay.attr, | |
748 | &dev_attr_lacp_rate.attr, | |
fd989c83 | 749 | &dev_attr_ad_select.attr, |
43cb76d9 | 750 | &dev_attr_xmit_hash_policy.attr, |
ad246c99 BH |
751 | &dev_attr_num_grat_arp.attr, |
752 | &dev_attr_num_unsol_na.attr, | |
43cb76d9 GKH |
753 | &dev_attr_miimon.attr, |
754 | &dev_attr_primary.attr, | |
a549952a | 755 | &dev_attr_primary_reselect.attr, |
43cb76d9 GKH |
756 | &dev_attr_use_carrier.attr, |
757 | &dev_attr_active_slave.attr, | |
758 | &dev_attr_mii_status.attr, | |
759 | &dev_attr_ad_aggregator.attr, | |
760 | &dev_attr_ad_num_ports.attr, | |
761 | &dev_attr_ad_actor_key.attr, | |
762 | &dev_attr_ad_partner_key.attr, | |
763 | &dev_attr_ad_partner_mac.attr, | |
bb1d9123 | 764 | &dev_attr_queue_id.attr, |
ebd8e497 | 765 | &dev_attr_all_slaves_active.attr, |
c2952c31 | 766 | &dev_attr_resend_igmp.attr, |
655f8919 | 767 | &dev_attr_min_links.attr, |
7eacd038 | 768 | &dev_attr_lp_interval.attr, |
73958329 | 769 | &dev_attr_packets_per_slave.attr, |
e9f0fb88 | 770 | &dev_attr_tlb_dynamic_lb.attr, |
6791e466 | 771 | &dev_attr_ad_actor_sys_prio.attr, |
74514957 | 772 | &dev_attr_ad_actor_system.attr, |
d22a5fc0 | 773 | &dev_attr_ad_user_port_key.attr, |
b76cdba9 MW |
774 | NULL, |
775 | }; | |
776 | ||
777 | static struct attribute_group bonding_group = { | |
778 | .name = "bonding", | |
779 | .attrs = per_bond_attrs, | |
780 | }; | |
781 | ||
dc3e5d18 | 782 | /* Initialize sysfs. This sets up the bonding_masters file in |
b76cdba9 MW |
783 | * /sys/class/net. |
784 | */ | |
4c22400a | 785 | int bond_create_sysfs(struct bond_net *bn) |
b76cdba9 | 786 | { |
b8a9787e | 787 | int ret; |
b76cdba9 | 788 | |
4c22400a | 789 | bn->class_attr_bonding_masters = class_attr_bonding_masters; |
01718e36 | 790 | sysfs_attr_init(&bn->class_attr_bonding_masters.attr); |
4c22400a | 791 | |
58292cbe TH |
792 | ret = netdev_class_create_file_ns(&bn->class_attr_bonding_masters, |
793 | bn->net); | |
dc3e5d18 | 794 | /* Permit multiple loads of the module by ignoring failures to |
877cbd36 JV |
795 | * create the bonding_masters sysfs file. Bonding devices |
796 | * created by second or subsequent loads of the module will | |
797 | * not be listed in, or controllable by, bonding_masters, but | |
798 | * will have the usual "bonding" sysfs directory. | |
799 | * | |
800 | * This is done to preserve backwards compatibility for | |
801 | * initscripts/sysconfig, which load bonding multiple times to | |
802 | * configure multiple bonding devices. | |
803 | */ | |
804 | if (ret == -EEXIST) { | |
38d2f38b | 805 | /* Is someone being kinky and naming a device bonding_master? */ |
4c22400a | 806 | if (__dev_get_by_name(bn->net, |
38d2f38b | 807 | class_attr_bonding_masters.attr.name)) |
90194264 | 808 | pr_err("network device named %s already exists in sysfs\n", |
38d2f38b | 809 | class_attr_bonding_masters.attr.name); |
130aa61a | 810 | ret = 0; |
877cbd36 | 811 | } |
b76cdba9 MW |
812 | |
813 | return ret; | |
814 | ||
815 | } | |
816 | ||
dc3e5d18 | 817 | /* Remove /sys/class/net/bonding_masters. */ |
4c22400a | 818 | void bond_destroy_sysfs(struct bond_net *bn) |
b76cdba9 | 819 | { |
58292cbe | 820 | netdev_class_remove_file_ns(&bn->class_attr_bonding_masters, bn->net); |
b76cdba9 MW |
821 | } |
822 | ||
dc3e5d18 | 823 | /* Initialize sysfs for each bond. This sets up and registers |
b76cdba9 MW |
824 | * the 'bondctl' directory for each individual bond under /sys/class/net. |
825 | */ | |
6151b3d4 | 826 | void bond_prepare_sysfs_group(struct bonding *bond) |
b76cdba9 | 827 | { |
6151b3d4 | 828 | bond->dev->sysfs_groups[0] = &bonding_group; |
b76cdba9 MW |
829 | } |
830 |