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