Commit | Line | Data |
---|---|---|
72be35fe JP |
1 | /* |
2 | * drivers/net/bond/bond_options.c - bonding options | |
3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> | |
eecdaa6e | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
72be35fe JP |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
13 | ||
14 | #include <linux/errno.h> | |
15 | #include <linux/if.h> | |
d9e32b21 JP |
16 | #include <linux/netdevice.h> |
17 | #include <linux/rwlock.h> | |
18 | #include <linux/rcupdate.h> | |
09117362 | 19 | #include <linux/ctype.h> |
4fb0ef58 | 20 | #include <linux/inet.h> |
72be35fe JP |
21 | #include "bonding.h" |
22 | ||
2b3798d5 NA |
23 | static struct bond_opt_value bond_mode_tbl[] = { |
24 | { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT}, | |
25 | { "active-backup", BOND_MODE_ACTIVEBACKUP, 0}, | |
26 | { "balance-xor", BOND_MODE_XOR, 0}, | |
27 | { "broadcast", BOND_MODE_BROADCAST, 0}, | |
28 | { "802.3ad", BOND_MODE_8023AD, 0}, | |
29 | { "balance-tlb", BOND_MODE_TLB, 0}, | |
30 | { "balance-alb", BOND_MODE_ALB, 0}, | |
31 | { NULL, -1, 0}, | |
32 | }; | |
33 | ||
aa59d851 NA |
34 | static struct bond_opt_value bond_pps_tbl[] = { |
35 | { "default", 1, BOND_VALFLAG_DEFAULT}, | |
36 | { "maxval", USHRT_MAX, BOND_VALFLAG_MAX}, | |
37 | { NULL, -1, 0}, | |
38 | }; | |
39 | ||
a4b32ce7 NA |
40 | static struct bond_opt_value bond_xmit_hashtype_tbl[] = { |
41 | { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT}, | |
42 | { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0}, | |
43 | { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0}, | |
44 | { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0}, | |
45 | { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0}, | |
46 | { NULL, -1, 0}, | |
47 | }; | |
48 | ||
16228881 NA |
49 | static struct bond_opt_value bond_arp_validate_tbl[] = { |
50 | { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT}, | |
51 | { "active", BOND_ARP_VALIDATE_ACTIVE, 0}, | |
52 | { "backup", BOND_ARP_VALIDATE_BACKUP, 0}, | |
53 | { "all", BOND_ARP_VALIDATE_ALL, 0}, | |
54 | { NULL, -1, 0}, | |
55 | }; | |
56 | ||
edf36b24 NA |
57 | static struct bond_opt_value bond_arp_all_targets_tbl[] = { |
58 | { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT}, | |
59 | { "all", BOND_ARP_TARGETS_ALL, 0}, | |
60 | { NULL, -1, 0}, | |
61 | }; | |
62 | ||
1df6b6aa NA |
63 | static struct bond_opt_value bond_fail_over_mac_tbl[] = { |
64 | { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT}, | |
65 | { "active", BOND_FOM_ACTIVE, 0}, | |
66 | { "follow", BOND_FOM_FOLLOW, 0}, | |
67 | { NULL, -1, 0}, | |
68 | }; | |
69 | ||
7bdb04ed NA |
70 | static struct bond_opt_value bond_intmax_tbl[] = { |
71 | { "off", 0, BOND_VALFLAG_DEFAULT}, | |
72 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, | |
73 | }; | |
74 | ||
d3131de7 NA |
75 | static struct bond_opt_value bond_lacp_rate_tbl[] = { |
76 | { "slow", AD_LACP_SLOW, 0}, | |
77 | { "fast", AD_LACP_FAST, 0}, | |
78 | { NULL, -1, 0}, | |
79 | }; | |
80 | ||
9e5f5eeb NA |
81 | static struct bond_opt_value bond_ad_select_tbl[] = { |
82 | { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT}, | |
83 | { "bandwidth", BOND_AD_BANDWIDTH, 0}, | |
84 | { "count", BOND_AD_COUNT, 0}, | |
85 | { NULL, -1, 0}, | |
86 | }; | |
87 | ||
ef56becb NA |
88 | static struct bond_opt_value bond_num_peer_notif_tbl[] = { |
89 | { "off", 0, 0}, | |
90 | { "maxval", 255, BOND_VALFLAG_MAX}, | |
91 | { "default", 1, BOND_VALFLAG_DEFAULT}, | |
92 | { NULL, -1, 0} | |
93 | }; | |
94 | ||
388d3a6d NA |
95 | static struct bond_opt_value bond_primary_reselect_tbl[] = { |
96 | { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT}, | |
97 | { "better", BOND_PRI_RESELECT_BETTER, 0}, | |
98 | { "failure", BOND_PRI_RESELECT_FAILURE, 0}, | |
99 | { NULL, -1}, | |
100 | }; | |
101 | ||
0fff0608 NA |
102 | static struct bond_opt_value bond_use_carrier_tbl[] = { |
103 | { "off", 0, 0}, | |
104 | { "on", 1, BOND_VALFLAG_DEFAULT}, | |
105 | { NULL, -1, 0} | |
106 | }; | |
107 | ||
3df01162 NA |
108 | static struct bond_opt_value bond_all_slaves_active_tbl[] = { |
109 | { "off", 0, BOND_VALFLAG_DEFAULT}, | |
110 | { "on", 1, 0}, | |
111 | { NULL, -1, 0} | |
112 | }; | |
113 | ||
09117362 | 114 | static struct bond_option bond_opts[] = { |
2b3798d5 NA |
115 | [BOND_OPT_MODE] = { |
116 | .id = BOND_OPT_MODE, | |
117 | .name = "mode", | |
118 | .desc = "bond device mode", | |
119 | .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN, | |
120 | .values = bond_mode_tbl, | |
121 | .set = bond_option_mode_set | |
122 | }, | |
aa59d851 NA |
123 | [BOND_OPT_PACKETS_PER_SLAVE] = { |
124 | .id = BOND_OPT_PACKETS_PER_SLAVE, | |
125 | .name = "packets_per_slave", | |
126 | .desc = "Packets to send per slave in RR mode", | |
127 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)), | |
128 | .values = bond_pps_tbl, | |
129 | .set = bond_option_pps_set | |
130 | }, | |
a4b32ce7 NA |
131 | [BOND_OPT_XMIT_HASH] = { |
132 | .id = BOND_OPT_XMIT_HASH, | |
133 | .name = "xmit_hash_policy", | |
134 | .desc = "balance-xor and 802.3ad hashing method", | |
135 | .values = bond_xmit_hashtype_tbl, | |
136 | .set = bond_option_xmit_hash_policy_set | |
137 | }, | |
16228881 NA |
138 | [BOND_OPT_ARP_VALIDATE] = { |
139 | .id = BOND_OPT_ARP_VALIDATE, | |
140 | .name = "arp_validate", | |
141 | .desc = "validate src/dst of ARP probes", | |
142 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)), | |
143 | .values = bond_arp_validate_tbl, | |
144 | .set = bond_option_arp_validate_set | |
145 | }, | |
edf36b24 NA |
146 | [BOND_OPT_ARP_ALL_TARGETS] = { |
147 | .id = BOND_OPT_ARP_ALL_TARGETS, | |
148 | .name = "arp_all_targets", | |
149 | .desc = "fail on any/all arp targets timeout", | |
150 | .values = bond_arp_all_targets_tbl, | |
151 | .set = bond_option_arp_all_targets_set | |
152 | }, | |
1df6b6aa NA |
153 | [BOND_OPT_FAIL_OVER_MAC] = { |
154 | .id = BOND_OPT_FAIL_OVER_MAC, | |
155 | .name = "fail_over_mac", | |
156 | .desc = "For active-backup, do not set all slaves to the same MAC", | |
157 | .flags = BOND_OPTFLAG_NOSLAVES, | |
158 | .values = bond_fail_over_mac_tbl, | |
159 | .set = bond_option_fail_over_mac_set | |
160 | }, | |
7bdb04ed NA |
161 | [BOND_OPT_ARP_INTERVAL] = { |
162 | .id = BOND_OPT_ARP_INTERVAL, | |
163 | .name = "arp_interval", | |
164 | .desc = "arp interval in milliseconds", | |
165 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | | |
166 | BIT(BOND_MODE_ALB), | |
167 | .values = bond_intmax_tbl, | |
168 | .set = bond_option_arp_interval_set | |
169 | }, | |
4fb0ef58 NA |
170 | [BOND_OPT_ARP_TARGETS] = { |
171 | .id = BOND_OPT_ARP_TARGETS, | |
172 | .name = "arp_ip_target", | |
173 | .desc = "arp targets in n.n.n.n form", | |
174 | .flags = BOND_OPTFLAG_RAWVAL, | |
175 | .set = bond_option_arp_ip_targets_set | |
176 | }, | |
25a9b54a NA |
177 | [BOND_OPT_DOWNDELAY] = { |
178 | .id = BOND_OPT_DOWNDELAY, | |
179 | .name = "downdelay", | |
180 | .desc = "Delay before considering link down, in milliseconds", | |
181 | .values = bond_intmax_tbl, | |
182 | .set = bond_option_downdelay_set | |
183 | }, | |
e4994612 NA |
184 | [BOND_OPT_UPDELAY] = { |
185 | .id = BOND_OPT_UPDELAY, | |
186 | .name = "updelay", | |
187 | .desc = "Delay before considering link up, in milliseconds", | |
188 | .values = bond_intmax_tbl, | |
189 | .set = bond_option_updelay_set | |
190 | }, | |
d3131de7 NA |
191 | [BOND_OPT_LACP_RATE] = { |
192 | .id = BOND_OPT_LACP_RATE, | |
193 | .name = "lacp_rate", | |
194 | .desc = "LACPDU tx rate to request from 802.3ad partner", | |
195 | .flags = BOND_OPTFLAG_IFDOWN, | |
196 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), | |
197 | .values = bond_lacp_rate_tbl, | |
198 | .set = bond_option_lacp_rate_set | |
199 | }, | |
633ddc9e NA |
200 | [BOND_OPT_MINLINKS] = { |
201 | .id = BOND_OPT_MINLINKS, | |
202 | .name = "min_links", | |
203 | .desc = "Minimum number of available links before turning on carrier", | |
204 | .values = bond_intmax_tbl, | |
205 | .set = bond_option_min_links_set | |
206 | }, | |
9e5f5eeb NA |
207 | [BOND_OPT_AD_SELECT] = { |
208 | .id = BOND_OPT_AD_SELECT, | |
209 | .name = "ad_select", | |
210 | .desc = "803.ad aggregation selection logic", | |
211 | .flags = BOND_OPTFLAG_IFDOWN, | |
212 | .values = bond_ad_select_tbl, | |
213 | .set = bond_option_ad_select_set | |
214 | }, | |
ef56becb NA |
215 | [BOND_OPT_NUM_PEER_NOTIF] = { |
216 | .id = BOND_OPT_NUM_PEER_NOTIF, | |
217 | .name = "num_unsol_na", | |
218 | .desc = "Number of peer notifications to send on failover event", | |
219 | .values = bond_num_peer_notif_tbl, | |
220 | .set = bond_option_num_peer_notif_set | |
221 | }, | |
b98d9c66 NA |
222 | [BOND_OPT_MIIMON] = { |
223 | .id = BOND_OPT_MIIMON, | |
224 | .name = "miimon", | |
225 | .desc = "Link check interval in milliseconds", | |
226 | .values = bond_intmax_tbl, | |
227 | .set = bond_option_miimon_set | |
228 | }, | |
180222f0 NA |
229 | [BOND_OPT_PRIMARY] = { |
230 | .id = BOND_OPT_PRIMARY, | |
231 | .name = "primary", | |
232 | .desc = "Primary network device to use", | |
233 | .flags = BOND_OPTFLAG_RAWVAL, | |
234 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | | |
235 | BIT(BOND_MODE_TLB) | | |
236 | BIT(BOND_MODE_ALB)), | |
237 | .set = bond_option_primary_set | |
238 | }, | |
388d3a6d NA |
239 | [BOND_OPT_PRIMARY_RESELECT] = { |
240 | .id = BOND_OPT_PRIMARY_RESELECT, | |
241 | .name = "primary_reselect", | |
242 | .desc = "Reselect primary slave once it comes up", | |
243 | .values = bond_primary_reselect_tbl, | |
244 | .set = bond_option_primary_reselect_set | |
245 | }, | |
0fff0608 NA |
246 | [BOND_OPT_USE_CARRIER] = { |
247 | .id = BOND_OPT_USE_CARRIER, | |
248 | .name = "use_carrier", | |
249 | .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon", | |
250 | .values = bond_use_carrier_tbl, | |
251 | .set = bond_option_use_carrier_set | |
252 | }, | |
d1fbd3ed NA |
253 | [BOND_OPT_ACTIVE_SLAVE] = { |
254 | .id = BOND_OPT_ACTIVE_SLAVE, | |
255 | .name = "active_slave", | |
256 | .desc = "Currently active slave", | |
257 | .flags = BOND_OPTFLAG_RAWVAL, | |
258 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | | |
259 | BIT(BOND_MODE_TLB) | | |
260 | BIT(BOND_MODE_ALB)), | |
261 | .set = bond_option_active_slave_set | |
262 | }, | |
24089ba1 NA |
263 | [BOND_OPT_QUEUE_ID] = { |
264 | .id = BOND_OPT_QUEUE_ID, | |
265 | .name = "queue_id", | |
266 | .desc = "Set queue id of a slave", | |
267 | .flags = BOND_OPTFLAG_RAWVAL, | |
268 | .set = bond_option_queue_id_set | |
269 | }, | |
3df01162 NA |
270 | [BOND_OPT_ALL_SLAVES_ACTIVE] = { |
271 | .id = BOND_OPT_ALL_SLAVES_ACTIVE, | |
272 | .name = "all_slaves_active", | |
273 | .desc = "Keep all frames received on an interface by setting active flag for all slaves", | |
274 | .values = bond_all_slaves_active_tbl, | |
275 | .set = bond_option_all_slaves_active_set | |
276 | }, | |
09117362 NA |
277 | { } |
278 | }; | |
279 | ||
280 | /* Searches for a value in opt's values[] table */ | |
281 | struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) | |
282 | { | |
283 | struct bond_option *opt; | |
284 | int i; | |
285 | ||
286 | opt = bond_opt_get(option); | |
287 | if (WARN_ON(!opt)) | |
288 | return NULL; | |
289 | for (i = 0; opt->values && opt->values[i].string; i++) | |
290 | if (opt->values[i].value == val) | |
291 | return &opt->values[i]; | |
292 | ||
293 | return NULL; | |
294 | } | |
295 | ||
296 | /* Searches for a value in opt's values[] table which matches the flagmask */ | |
297 | static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt, | |
298 | u32 flagmask) | |
299 | { | |
300 | int i; | |
301 | ||
302 | for (i = 0; opt->values && opt->values[i].string; i++) | |
303 | if (opt->values[i].flags & flagmask) | |
304 | return &opt->values[i]; | |
305 | ||
306 | return NULL; | |
307 | } | |
308 | ||
309 | /* If maxval is missing then there's no range to check. In case minval is | |
310 | * missing then it's considered to be 0. | |
311 | */ | |
312 | static bool bond_opt_check_range(const struct bond_option *opt, u64 val) | |
313 | { | |
314 | struct bond_opt_value *minval, *maxval; | |
315 | ||
316 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); | |
317 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); | |
318 | if (!maxval || (minval && val < minval->value) || val > maxval->value) | |
319 | return false; | |
320 | ||
321 | return true; | |
322 | } | |
323 | ||
324 | /** | |
325 | * bond_opt_parse - parse option value | |
326 | * @opt: the option to parse against | |
327 | * @val: value to parse | |
328 | * | |
329 | * This function tries to extract the value from @val and check if it's | |
330 | * a possible match for the option and returns NULL if a match isn't found, | |
331 | * or the struct_opt_value that matched. It also strips the new line from | |
332 | * @val->string if it's present. | |
333 | */ | |
334 | struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, | |
335 | struct bond_opt_value *val) | |
336 | { | |
337 | char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; | |
338 | struct bond_opt_value *tbl, *ret = NULL; | |
339 | bool checkval; | |
340 | int i, rv; | |
341 | ||
342 | /* No parsing if the option wants a raw val */ | |
343 | if (opt->flags & BOND_OPTFLAG_RAWVAL) | |
344 | return val; | |
345 | ||
346 | tbl = opt->values; | |
347 | if (!tbl) | |
348 | goto out; | |
349 | ||
350 | /* ULLONG_MAX is used to bypass string processing */ | |
351 | checkval = val->value != ULLONG_MAX; | |
352 | if (!checkval) { | |
353 | if (!val->string) | |
354 | goto out; | |
355 | p = strchr(val->string, '\n'); | |
356 | if (p) | |
357 | *p = '\0'; | |
358 | for (p = val->string; *p; p++) | |
359 | if (!(isdigit(*p) || isspace(*p))) | |
360 | break; | |
361 | /* The following code extracts the string to match or the value | |
362 | * and sets checkval appropriately | |
363 | */ | |
364 | if (*p) { | |
365 | rv = sscanf(val->string, "%32s", valstr); | |
366 | } else { | |
367 | rv = sscanf(val->string, "%llu", &val->value); | |
368 | checkval = true; | |
369 | } | |
370 | if (!rv) | |
371 | goto out; | |
372 | } | |
373 | ||
374 | for (i = 0; tbl[i].string; i++) { | |
375 | /* Check for exact match */ | |
376 | if (checkval) { | |
377 | if (val->value == tbl[i].value) | |
378 | ret = &tbl[i]; | |
379 | } else { | |
380 | if (!strcmp(valstr, "default") && | |
381 | (tbl[i].flags & BOND_VALFLAG_DEFAULT)) | |
382 | ret = &tbl[i]; | |
383 | ||
384 | if (!strcmp(valstr, tbl[i].string)) | |
385 | ret = &tbl[i]; | |
386 | } | |
387 | /* Found an exact match */ | |
388 | if (ret) | |
389 | goto out; | |
390 | } | |
391 | /* Possible range match */ | |
392 | if (checkval && bond_opt_check_range(opt, val->value)) | |
393 | ret = val; | |
394 | out: | |
395 | return ret; | |
396 | } | |
397 | ||
398 | /* Check opt's dependencies against bond mode and currently set options */ | |
399 | static int bond_opt_check_deps(struct bonding *bond, | |
400 | const struct bond_option *opt) | |
401 | { | |
402 | struct bond_params *params = &bond->params; | |
403 | ||
404 | if (test_bit(params->mode, &opt->unsuppmodes)) | |
405 | return -EACCES; | |
406 | if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) | |
407 | return -ENOTEMPTY; | |
408 | if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) | |
409 | return -EBUSY; | |
410 | ||
411 | return 0; | |
412 | } | |
413 | ||
414 | static void bond_opt_dep_print(struct bonding *bond, | |
415 | const struct bond_option *opt) | |
416 | { | |
2b3798d5 | 417 | struct bond_opt_value *modeval; |
09117362 NA |
418 | struct bond_params *params; |
419 | ||
420 | params = &bond->params; | |
2b3798d5 | 421 | modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); |
09117362 | 422 | if (test_bit(params->mode, &opt->unsuppmodes)) |
2b3798d5 NA |
423 | pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n", |
424 | bond->dev->name, opt->name, | |
425 | modeval->string, modeval->value); | |
09117362 NA |
426 | } |
427 | ||
428 | static void bond_opt_error_interpret(struct bonding *bond, | |
429 | const struct bond_option *opt, | |
430 | int error, struct bond_opt_value *val) | |
431 | { | |
432 | struct bond_opt_value *minval, *maxval; | |
433 | char *p; | |
434 | ||
435 | switch (error) { | |
436 | case -EINVAL: | |
437 | if (val) { | |
438 | if (val->string) { | |
439 | /* sometimes RAWVAL opts may have new lines */ | |
440 | p = strchr(val->string, '\n'); | |
441 | if (p) | |
442 | *p = '\0'; | |
443 | pr_err("%s: option %s: invalid value (%s).\n", | |
444 | bond->dev->name, opt->name, val->string); | |
445 | } else { | |
446 | pr_err("%s: option %s: invalid value (%llu).\n", | |
447 | bond->dev->name, opt->name, val->value); | |
448 | } | |
449 | } | |
450 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); | |
451 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); | |
452 | if (!maxval) | |
453 | break; | |
454 | pr_err("%s: option %s: allowed values %llu - %llu.\n", | |
455 | bond->dev->name, opt->name, minval ? minval->value : 0, | |
456 | maxval->value); | |
457 | break; | |
458 | case -EACCES: | |
459 | bond_opt_dep_print(bond, opt); | |
460 | break; | |
461 | case -ENOTEMPTY: | |
462 | pr_err("%s: option %s: unable to set because the bond device has slaves.\n", | |
463 | bond->dev->name, opt->name); | |
464 | break; | |
465 | case -EBUSY: | |
466 | pr_err("%s: option %s: unable to set because the bond device is up.\n", | |
467 | bond->dev->name, opt->name); | |
468 | break; | |
469 | default: | |
470 | break; | |
471 | } | |
472 | } | |
473 | ||
474 | /** | |
475 | * __bond_opt_set - set a bonding option | |
476 | * @bond: target bond device | |
477 | * @option: option to set | |
478 | * @val: value to set it to | |
479 | * | |
480 | * This function is used to change the bond's option value, it can be | |
481 | * used for both enabling/changing an option and for disabling it. RTNL lock | |
482 | * must be obtained before calling this function. | |
483 | */ | |
484 | int __bond_opt_set(struct bonding *bond, | |
485 | unsigned int option, struct bond_opt_value *val) | |
486 | { | |
487 | struct bond_opt_value *retval = NULL; | |
488 | const struct bond_option *opt; | |
489 | int ret = -ENOENT; | |
490 | ||
491 | ASSERT_RTNL(); | |
492 | ||
493 | opt = bond_opt_get(option); | |
494 | if (WARN_ON(!val) || WARN_ON(!opt)) | |
495 | goto out; | |
496 | ret = bond_opt_check_deps(bond, opt); | |
497 | if (ret) | |
498 | goto out; | |
499 | retval = bond_opt_parse(opt, val); | |
500 | if (!retval) { | |
501 | ret = -EINVAL; | |
502 | goto out; | |
503 | } | |
504 | ret = opt->set(bond, retval); | |
505 | out: | |
506 | if (ret) | |
507 | bond_opt_error_interpret(bond, opt, ret, val); | |
508 | ||
509 | return ret; | |
510 | } | |
511 | ||
512 | /** | |
513 | * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set | |
514 | * @bond: target bond device | |
515 | * @option: option to set | |
516 | * @buf: value to set it to | |
517 | * | |
518 | * This function tries to acquire RTNL without blocking and if successful | |
519 | * calls __bond_opt_set. It is mainly used for sysfs option manipulation. | |
520 | */ | |
521 | int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) | |
522 | { | |
523 | struct bond_opt_value optval; | |
524 | int ret; | |
525 | ||
526 | if (!rtnl_trylock()) | |
527 | return restart_syscall(); | |
528 | bond_opt_initstr(&optval, buf); | |
529 | ret = __bond_opt_set(bond, option, &optval); | |
530 | rtnl_unlock(); | |
531 | ||
532 | return ret; | |
533 | } | |
534 | ||
535 | /** | |
536 | * bond_opt_get - get a pointer to an option | |
537 | * @option: option for which to return a pointer | |
538 | * | |
539 | * This function checks if option is valid and if so returns a pointer | |
540 | * to its entry in the bond_opts[] option array. | |
541 | */ | |
542 | struct bond_option *bond_opt_get(unsigned int option) | |
543 | { | |
544 | if (!BOND_OPT_VALID(option)) | |
545 | return NULL; | |
546 | ||
547 | return &bond_opts[option]; | |
548 | } | |
549 | ||
2b3798d5 | 550 | int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval) |
72be35fe | 551 | { |
2b3798d5 | 552 | if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) { |
fe9d04af | 553 | pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n", |
2b3798d5 | 554 | bond->dev->name, newval->string); |
fe9d04af | 555 | /* disable arp monitoring */ |
556 | bond->params.arp_interval = 0; | |
557 | /* set miimon to default value */ | |
558 | bond->params.miimon = BOND_DEFAULT_MIIMON; | |
559 | pr_info("%s: Setting MII monitoring interval to %d.\n", | |
560 | bond->dev->name, bond->params.miimon); | |
72be35fe JP |
561 | } |
562 | ||
563 | /* don't cache arp_validate between modes */ | |
564 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
2b3798d5 NA |
565 | bond->params.mode = newval->value; |
566 | ||
72be35fe JP |
567 | return 0; |
568 | } | |
d9e32b21 | 569 | |
752d48b5 JP |
570 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
571 | struct slave *slave) | |
572 | { | |
573 | return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL; | |
574 | } | |
575 | ||
576 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) | |
577 | { | |
578 | struct slave *slave = rcu_dereference(bond->curr_active_slave); | |
579 | ||
580 | return __bond_option_active_slave_get(bond, slave); | |
581 | } | |
582 | ||
583 | struct net_device *bond_option_active_slave_get(struct bonding *bond) | |
584 | { | |
585 | return __bond_option_active_slave_get(bond, bond->curr_active_slave); | |
586 | } | |
587 | ||
d9e32b21 | 588 | int bond_option_active_slave_set(struct bonding *bond, |
d1fbd3ed | 589 | struct bond_opt_value *newval) |
d9e32b21 | 590 | { |
d1fbd3ed NA |
591 | char ifname[IFNAMSIZ] = { 0, }; |
592 | struct net_device *slave_dev; | |
d9e32b21 JP |
593 | int ret = 0; |
594 | ||
d1fbd3ed NA |
595 | sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */ |
596 | if (!strlen(ifname) || newval->string[0] == '\n') { | |
597 | slave_dev = NULL; | |
598 | } else { | |
599 | slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname); | |
600 | if (!slave_dev) | |
601 | return -ENODEV; | |
602 | } | |
603 | ||
d9e32b21 JP |
604 | if (slave_dev) { |
605 | if (!netif_is_bond_slave(slave_dev)) { | |
606 | pr_err("Device %s is not bonding slave.\n", | |
607 | slave_dev->name); | |
608 | return -EINVAL; | |
609 | } | |
610 | ||
611 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { | |
612 | pr_err("%s: Device %s is not our slave.\n", | |
613 | bond->dev->name, slave_dev->name); | |
614 | return -EINVAL; | |
615 | } | |
616 | } | |
617 | ||
d9e32b21 | 618 | block_netpoll_tx(); |
d9e32b21 JP |
619 | write_lock_bh(&bond->curr_slave_lock); |
620 | ||
621 | /* check to see if we are clearing active */ | |
622 | if (!slave_dev) { | |
623 | pr_info("%s: Clearing current active slave.\n", | |
624 | bond->dev->name); | |
625 | rcu_assign_pointer(bond->curr_active_slave, NULL); | |
626 | bond_select_active_slave(bond); | |
627 | } else { | |
628 | struct slave *old_active = bond->curr_active_slave; | |
629 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); | |
630 | ||
631 | BUG_ON(!new_active); | |
632 | ||
633 | if (new_active == old_active) { | |
634 | /* do nothing */ | |
635 | pr_info("%s: %s is already the current active slave.\n", | |
636 | bond->dev->name, new_active->dev->name); | |
637 | } else { | |
638 | if (old_active && (new_active->link == BOND_LINK_UP) && | |
639 | IS_UP(new_active->dev)) { | |
640 | pr_info("%s: Setting %s as active slave.\n", | |
641 | bond->dev->name, new_active->dev->name); | |
642 | bond_change_active_slave(bond, new_active); | |
643 | } else { | |
644 | pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n", | |
645 | bond->dev->name, new_active->dev->name, | |
646 | new_active->dev->name); | |
647 | ret = -EINVAL; | |
648 | } | |
649 | } | |
650 | } | |
651 | ||
652 | write_unlock_bh(&bond->curr_slave_lock); | |
d9e32b21 | 653 | unblock_netpoll_tx(); |
d1fbd3ed | 654 | |
d9e32b21 JP |
655 | return ret; |
656 | } | |
eecdaa6e | 657 | |
b98d9c66 | 658 | int bond_option_miimon_set(struct bonding *bond, struct bond_opt_value *newval) |
eecdaa6e | 659 | { |
b98d9c66 NA |
660 | pr_info("%s: Setting MII monitoring interval to %llu.\n", |
661 | bond->dev->name, newval->value); | |
662 | bond->params.miimon = newval->value; | |
eecdaa6e | 663 | if (bond->params.updelay) |
664 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", | |
665 | bond->dev->name, | |
666 | bond->params.updelay * bond->params.miimon); | |
667 | if (bond->params.downdelay) | |
668 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", | |
669 | bond->dev->name, | |
670 | bond->params.downdelay * bond->params.miimon); | |
b98d9c66 | 671 | if (newval->value && bond->params.arp_interval) { |
eecdaa6e | 672 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
673 | bond->dev->name); | |
674 | bond->params.arp_interval = 0; | |
675 | if (bond->params.arp_validate) | |
676 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; | |
677 | } | |
678 | if (bond->dev->flags & IFF_UP) { | |
679 | /* If the interface is up, we may need to fire off | |
680 | * the MII timer. If the interface is down, the | |
681 | * timer will get fired off when the open function | |
682 | * is called. | |
683 | */ | |
b98d9c66 | 684 | if (!newval->value) { |
eecdaa6e | 685 | cancel_delayed_work_sync(&bond->mii_work); |
686 | } else { | |
687 | cancel_delayed_work_sync(&bond->arp_work); | |
688 | queue_delayed_work(bond->wq, &bond->mii_work, 0); | |
689 | } | |
690 | } | |
b98d9c66 | 691 | |
eecdaa6e | 692 | return 0; |
693 | } | |
25852e29 | 694 | |
e4994612 | 695 | int bond_option_updelay_set(struct bonding *bond, struct bond_opt_value *newval) |
25852e29 | 696 | { |
e4994612 | 697 | if (!bond->params.miimon) { |
25852e29 | 698 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
699 | bond->dev->name); | |
700 | return -EPERM; | |
701 | } | |
e4994612 NA |
702 | if ((newval->value % bond->params.miimon) != 0) { |
703 | pr_warn("%s: Warning: up delay (%llu) is not a multiple of miimon (%d), updelay rounded to %llu ms\n", | |
704 | bond->dev->name, newval->value, | |
705 | bond->params.miimon, | |
706 | (newval->value / bond->params.miimon) * | |
707 | bond->params.miimon); | |
25852e29 | 708 | } |
e4994612 NA |
709 | bond->params.updelay = newval->value / bond->params.miimon; |
710 | pr_info("%s: Setting up delay to %d.\n", | |
711 | bond->dev->name, | |
712 | bond->params.updelay * bond->params.miimon); | |
25852e29 | 713 | |
714 | return 0; | |
715 | } | |
c7461f9b | 716 | |
25a9b54a NA |
717 | int bond_option_downdelay_set(struct bonding *bond, |
718 | struct bond_opt_value *newval) | |
c7461f9b | 719 | { |
25a9b54a | 720 | if (!bond->params.miimon) { |
c7461f9b | 721 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
722 | bond->dev->name); | |
723 | return -EPERM; | |
724 | } | |
25a9b54a NA |
725 | if ((newval->value % bond->params.miimon) != 0) { |
726 | pr_warn("%s: Warning: down delay (%llu) is not a multiple of miimon (%d), delay rounded to %llu ms\n", | |
727 | bond->dev->name, newval->value, | |
728 | bond->params.miimon, | |
729 | (newval->value / bond->params.miimon) * | |
730 | bond->params.miimon); | |
c7461f9b | 731 | } |
25a9b54a NA |
732 | bond->params.downdelay = newval->value / bond->params.miimon; |
733 | pr_info("%s: Setting down delay to %d.\n", | |
734 | bond->dev->name, | |
735 | bond->params.downdelay * bond->params.miimon); | |
c7461f9b | 736 | |
737 | return 0; | |
738 | } | |
9f53e14e | 739 | |
0fff0608 NA |
740 | int bond_option_use_carrier_set(struct bonding *bond, |
741 | struct bond_opt_value *newval) | |
9f53e14e | 742 | { |
0fff0608 NA |
743 | pr_info("%s: Setting use_carrier to %llu.\n", |
744 | bond->dev->name, newval->value); | |
745 | bond->params.use_carrier = newval->value; | |
9f53e14e | 746 | |
747 | return 0; | |
748 | } | |
06151dbc | 749 | |
7bdb04ed NA |
750 | int bond_option_arp_interval_set(struct bonding *bond, |
751 | struct bond_opt_value *newval) | |
06151dbc | 752 | { |
7bdb04ed NA |
753 | pr_info("%s: Setting ARP monitoring interval to %llu.\n", |
754 | bond->dev->name, newval->value); | |
755 | bond->params.arp_interval = newval->value; | |
756 | if (newval->value) { | |
06151dbc | 757 | if (bond->params.miimon) { |
758 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", | |
759 | bond->dev->name, bond->dev->name); | |
760 | bond->params.miimon = 0; | |
761 | } | |
762 | if (!bond->params.arp_targets[0]) | |
763 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", | |
764 | bond->dev->name); | |
765 | } | |
766 | if (bond->dev->flags & IFF_UP) { | |
767 | /* If the interface is up, we may need to fire off | |
768 | * the ARP timer. If the interface is down, the | |
769 | * timer will get fired off when the open function | |
770 | * is called. | |
771 | */ | |
7bdb04ed | 772 | if (!newval->value) { |
06151dbc | 773 | if (bond->params.arp_validate) |
774 | bond->recv_probe = NULL; | |
775 | cancel_delayed_work_sync(&bond->arp_work); | |
776 | } else { | |
777 | /* arp_validate can be set only in active-backup mode */ | |
778 | if (bond->params.arp_validate) | |
779 | bond->recv_probe = bond_arp_rcv; | |
780 | cancel_delayed_work_sync(&bond->mii_work); | |
781 | queue_delayed_work(bond->wq, &bond->arp_work, 0); | |
782 | } | |
783 | } | |
784 | ||
785 | return 0; | |
786 | } | |
7f28fa10 | 787 | |
788 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, | |
789 | __be32 target, | |
790 | unsigned long last_rx) | |
791 | { | |
792 | __be32 *targets = bond->params.arp_targets; | |
793 | struct list_head *iter; | |
794 | struct slave *slave; | |
795 | ||
796 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { | |
797 | bond_for_each_slave(bond, slave, iter) | |
798 | slave->target_last_arp_rx[slot] = last_rx; | |
799 | targets[slot] = target; | |
800 | } | |
801 | } | |
802 | ||
803 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) | |
804 | { | |
805 | __be32 *targets = bond->params.arp_targets; | |
806 | int ind; | |
807 | ||
808 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { | |
809 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", | |
810 | bond->dev->name, &target); | |
811 | return -EINVAL; | |
812 | } | |
813 | ||
814 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ | |
815 | pr_err("%s: ARP target %pI4 is already present\n", | |
816 | bond->dev->name, &target); | |
817 | return -EINVAL; | |
818 | } | |
819 | ||
820 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ | |
821 | if (ind == -1) { | |
822 | pr_err("%s: ARP target table is full!\n", | |
823 | bond->dev->name); | |
824 | return -EINVAL; | |
825 | } | |
826 | ||
827 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target); | |
828 | ||
829 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); | |
830 | ||
831 | return 0; | |
832 | } | |
833 | ||
834 | int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) | |
835 | { | |
836 | int ret; | |
837 | ||
838 | /* not to race with bond_arp_rcv */ | |
839 | write_lock_bh(&bond->lock); | |
840 | ret = _bond_option_arp_ip_target_add(bond, target); | |
841 | write_unlock_bh(&bond->lock); | |
842 | ||
843 | return ret; | |
844 | } | |
845 | ||
846 | int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) | |
847 | { | |
848 | __be32 *targets = bond->params.arp_targets; | |
849 | struct list_head *iter; | |
850 | struct slave *slave; | |
851 | unsigned long *targets_rx; | |
852 | int ind, i; | |
853 | ||
854 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { | |
855 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", | |
856 | bond->dev->name, &target); | |
857 | return -EINVAL; | |
858 | } | |
859 | ||
860 | ind = bond_get_targets_ip(targets, target); | |
861 | if (ind == -1) { | |
862 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", | |
863 | bond->dev->name, &target); | |
864 | return -EINVAL; | |
865 | } | |
866 | ||
867 | if (ind == 0 && !targets[1] && bond->params.arp_interval) | |
868 | pr_warn("%s: removing last arp target with arp_interval on\n", | |
869 | bond->dev->name); | |
870 | ||
871 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, | |
872 | &target); | |
873 | ||
874 | /* not to race with bond_arp_rcv */ | |
875 | write_lock_bh(&bond->lock); | |
876 | ||
877 | bond_for_each_slave(bond, slave, iter) { | |
878 | targets_rx = slave->target_last_arp_rx; | |
879 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
880 | targets_rx[i] = targets_rx[i+1]; | |
881 | targets_rx[i] = 0; | |
882 | } | |
883 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) | |
884 | targets[i] = targets[i+1]; | |
885 | targets[i] = 0; | |
886 | ||
887 | write_unlock_bh(&bond->lock); | |
888 | ||
889 | return 0; | |
890 | } | |
891 | ||
4fb0ef58 | 892 | void bond_option_arp_ip_targets_clear(struct bonding *bond) |
7f28fa10 | 893 | { |
4fb0ef58 | 894 | int i; |
7f28fa10 | 895 | |
896 | /* not to race with bond_arp_rcv */ | |
897 | write_lock_bh(&bond->lock); | |
7f28fa10 | 898 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) |
899 | _bond_options_arp_ip_target_set(bond, i, 0, 0); | |
4fb0ef58 NA |
900 | write_unlock_bh(&bond->lock); |
901 | } | |
7f28fa10 | 902 | |
4fb0ef58 NA |
903 | int bond_option_arp_ip_targets_set(struct bonding *bond, |
904 | struct bond_opt_value *newval) | |
905 | { | |
906 | int ret = -EPERM; | |
907 | __be32 target; | |
908 | ||
909 | if (newval->string) { | |
910 | if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) { | |
911 | pr_err("%s: invalid ARP target %pI4 specified\n", | |
912 | bond->dev->name, &target); | |
913 | return ret; | |
914 | } | |
915 | if (newval->string[0] == '+') | |
916 | ret = bond_option_arp_ip_target_add(bond, target); | |
917 | else if (newval->string[0] == '-') | |
918 | ret = bond_option_arp_ip_target_rem(bond, target); | |
919 | else | |
920 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", | |
921 | bond->dev->name); | |
922 | } else { | |
923 | target = newval->value; | |
924 | ret = bond_option_arp_ip_target_add(bond, target); | |
7f28fa10 | 925 | } |
926 | ||
7f28fa10 | 927 | return ret; |
928 | } | |
29c49482 | 929 | |
16228881 NA |
930 | int bond_option_arp_validate_set(struct bonding *bond, |
931 | struct bond_opt_value *newval) | |
29c49482 | 932 | { |
16228881 NA |
933 | pr_info("%s: setting arp_validate to %s (%llu).\n", |
934 | bond->dev->name, newval->string, newval->value); | |
29c49482 | 935 | |
936 | if (bond->dev->flags & IFF_UP) { | |
16228881 | 937 | if (!newval->value) |
29c49482 | 938 | bond->recv_probe = NULL; |
939 | else if (bond->params.arp_interval) | |
940 | bond->recv_probe = bond_arp_rcv; | |
941 | } | |
16228881 | 942 | bond->params.arp_validate = newval->value; |
29c49482 | 943 | |
944 | return 0; | |
945 | } | |
d5c84254 | 946 | |
edf36b24 NA |
947 | int bond_option_arp_all_targets_set(struct bonding *bond, |
948 | struct bond_opt_value *newval) | |
d5c84254 | 949 | { |
edf36b24 NA |
950 | pr_info("%s: setting arp_all_targets to %s (%llu).\n", |
951 | bond->dev->name, newval->string, newval->value); | |
952 | bond->params.arp_all_targets = newval->value; | |
d5c84254 | 953 | |
954 | return 0; | |
955 | } | |
0a98a0d1 | 956 | |
180222f0 | 957 | int bond_option_primary_set(struct bonding *bond, struct bond_opt_value *newval) |
0a98a0d1 | 958 | { |
180222f0 | 959 | char *p, *primary = newval->string; |
0a98a0d1 | 960 | struct list_head *iter; |
961 | struct slave *slave; | |
0a98a0d1 | 962 | |
963 | block_netpoll_tx(); | |
964 | read_lock(&bond->lock); | |
965 | write_lock_bh(&bond->curr_slave_lock); | |
966 | ||
180222f0 NA |
967 | p = strchr(primary, '\n'); |
968 | if (p) | |
969 | *p = '\0'; | |
0a98a0d1 | 970 | /* check to see if we are clearing primary */ |
971 | if (!strlen(primary)) { | |
972 | pr_info("%s: Setting primary slave to None.\n", | |
973 | bond->dev->name); | |
974 | bond->primary_slave = NULL; | |
975 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); | |
976 | bond_select_active_slave(bond); | |
977 | goto out; | |
978 | } | |
979 | ||
980 | bond_for_each_slave(bond, slave, iter) { | |
981 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { | |
982 | pr_info("%s: Setting %s as primary slave.\n", | |
983 | bond->dev->name, slave->dev->name); | |
984 | bond->primary_slave = slave; | |
985 | strcpy(bond->params.primary, slave->dev->name); | |
986 | bond_select_active_slave(bond); | |
987 | goto out; | |
988 | } | |
989 | } | |
990 | ||
991 | strncpy(bond->params.primary, primary, IFNAMSIZ); | |
992 | bond->params.primary[IFNAMSIZ - 1] = 0; | |
993 | ||
994 | pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n", | |
995 | bond->dev->name, primary, bond->dev->name); | |
996 | ||
997 | out: | |
998 | write_unlock_bh(&bond->curr_slave_lock); | |
999 | read_unlock(&bond->lock); | |
1000 | unblock_netpoll_tx(); | |
1001 | ||
180222f0 | 1002 | return 0; |
0a98a0d1 | 1003 | } |
8a41ae44 | 1004 | |
388d3a6d NA |
1005 | int bond_option_primary_reselect_set(struct bonding *bond, |
1006 | struct bond_opt_value *newval) | |
8a41ae44 | 1007 | { |
388d3a6d NA |
1008 | pr_info("%s: setting primary_reselect to %s (%llu).\n", |
1009 | bond->dev->name, newval->string, newval->value); | |
1010 | bond->params.primary_reselect = newval->value; | |
8a41ae44 | 1011 | |
1012 | block_netpoll_tx(); | |
1013 | write_lock_bh(&bond->curr_slave_lock); | |
1014 | bond_select_active_slave(bond); | |
1015 | write_unlock_bh(&bond->curr_slave_lock); | |
1016 | unblock_netpoll_tx(); | |
1017 | ||
1018 | return 0; | |
1019 | } | |
89901972 | 1020 | |
1df6b6aa NA |
1021 | int bond_option_fail_over_mac_set(struct bonding *bond, |
1022 | struct bond_opt_value *newval) | |
89901972 | 1023 | { |
1df6b6aa NA |
1024 | pr_info("%s: Setting fail_over_mac to %s (%llu).\n", |
1025 | bond->dev->name, newval->string, newval->value); | |
1026 | bond->params.fail_over_mac = newval->value; | |
89901972 | 1027 | |
1028 | return 0; | |
1029 | } | |
f70161c6 | 1030 | |
a4b32ce7 NA |
1031 | int bond_option_xmit_hash_policy_set(struct bonding *bond, |
1032 | struct bond_opt_value *newval) | |
f70161c6 | 1033 | { |
a4b32ce7 NA |
1034 | pr_info("%s: setting xmit hash policy to %s (%llu).\n", |
1035 | bond->dev->name, newval->string, newval->value); | |
1036 | bond->params.xmit_policy = newval->value; | |
f70161c6 | 1037 | |
1038 | return 0; | |
1039 | } | |
d8838de7 | 1040 | |
1041 | int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp) | |
1042 | { | |
1043 | if (resend_igmp < 0 || resend_igmp > 255) { | |
1044 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", | |
1045 | bond->dev->name, resend_igmp); | |
1046 | return -EINVAL; | |
1047 | } | |
1048 | ||
1049 | bond->params.resend_igmp = resend_igmp; | |
1050 | pr_info("%s: Setting resend_igmp to %d.\n", | |
1051 | bond->dev->name, resend_igmp); | |
1052 | ||
1053 | return 0; | |
1054 | } | |
2c9839c1 | 1055 | |
ef56becb NA |
1056 | int bond_option_num_peer_notif_set(struct bonding *bond, |
1057 | struct bond_opt_value *newval) | |
2c9839c1 | 1058 | { |
ef56becb NA |
1059 | bond->params.num_peer_notif = newval->value; |
1060 | ||
2c9839c1 | 1061 | return 0; |
1062 | } | |
1cc0b1e3 | 1063 | |
1064 | int bond_option_all_slaves_active_set(struct bonding *bond, | |
3df01162 | 1065 | struct bond_opt_value *newval) |
1cc0b1e3 | 1066 | { |
1067 | struct list_head *iter; | |
1068 | struct slave *slave; | |
1069 | ||
3df01162 | 1070 | if (newval->value == bond->params.all_slaves_active) |
1cc0b1e3 | 1071 | return 0; |
3df01162 | 1072 | bond->params.all_slaves_active = newval->value; |
1cc0b1e3 | 1073 | bond_for_each_slave(bond, slave, iter) { |
1074 | if (!bond_is_active_slave(slave)) { | |
3df01162 | 1075 | if (newval->value) |
1cc0b1e3 | 1076 | slave->inactive = 0; |
1077 | else | |
1078 | slave->inactive = 1; | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | return 0; | |
1083 | } | |
7d101008 | 1084 | |
633ddc9e NA |
1085 | int bond_option_min_links_set(struct bonding *bond, |
1086 | struct bond_opt_value *newval) | |
7d101008 | 1087 | { |
633ddc9e NA |
1088 | pr_info("%s: Setting min links value to %llu\n", |
1089 | bond->dev->name, newval->value); | |
1090 | bond->params.min_links = newval->value; | |
7d101008 | 1091 | |
1092 | return 0; | |
1093 | } | |
8d836d09 | 1094 | |
1095 | int bond_option_lp_interval_set(struct bonding *bond, int lp_interval) | |
1096 | { | |
1097 | if (lp_interval <= 0) { | |
1098 | pr_err("%s: lp_interval must be between 1 and %d\n", | |
1099 | bond->dev->name, INT_MAX); | |
1100 | return -EINVAL; | |
1101 | } | |
1102 | ||
1103 | bond->params.lp_interval = lp_interval; | |
1104 | ||
1105 | return 0; | |
1106 | } | |
c13ab3ff | 1107 | |
aa59d851 | 1108 | int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval) |
c13ab3ff | 1109 | { |
aa59d851 NA |
1110 | bond->params.packets_per_slave = newval->value; |
1111 | if (newval->value > 0) { | |
809fa972 | 1112 | bond->params.reciprocal_packets_per_slave = |
aa59d851 | 1113 | reciprocal_value(newval->value); |
809fa972 HFS |
1114 | } else { |
1115 | /* reciprocal_packets_per_slave is unused if | |
1116 | * packets_per_slave is 0 or 1, just initialize it | |
1117 | */ | |
1118 | bond->params.reciprocal_packets_per_slave = | |
1119 | (struct reciprocal_value) { 0 }; | |
1120 | } | |
c13ab3ff | 1121 | |
1122 | return 0; | |
1123 | } | |
998e40bb | 1124 | |
d3131de7 NA |
1125 | int bond_option_lacp_rate_set(struct bonding *bond, |
1126 | struct bond_opt_value *newval) | |
998e40bb | 1127 | { |
d3131de7 NA |
1128 | pr_info("%s: Setting LACP rate to %s (%llu).\n", |
1129 | bond->dev->name, newval->string, newval->value); | |
1130 | bond->params.lacp_fast = newval->value; | |
3243c47b | 1131 | bond_3ad_update_lacp_rate(bond); |
998e40bb | 1132 | |
1133 | return 0; | |
1134 | } | |
ec029fac | 1135 | |
9e5f5eeb NA |
1136 | int bond_option_ad_select_set(struct bonding *bond, |
1137 | struct bond_opt_value *newval) | |
ec029fac | 1138 | { |
9e5f5eeb NA |
1139 | pr_info("%s: Setting ad_select to %s (%llu).\n", |
1140 | bond->dev->name, newval->string, newval->value); | |
1141 | bond->params.ad_select = newval->value; | |
ec029fac | 1142 | |
1143 | return 0; | |
1144 | } | |
24089ba1 NA |
1145 | |
1146 | int bond_option_queue_id_set(struct bonding *bond, | |
1147 | struct bond_opt_value *newval) | |
1148 | { | |
1149 | struct slave *slave, *update_slave; | |
1150 | struct net_device *sdev; | |
1151 | struct list_head *iter; | |
1152 | char *delim; | |
1153 | int ret = 0; | |
1154 | u16 qid; | |
1155 | ||
1156 | /* delim will point to queue id if successful */ | |
1157 | delim = strchr(newval->string, ':'); | |
1158 | if (!delim) | |
1159 | goto err_no_cmd; | |
1160 | ||
1161 | /* Terminate string that points to device name and bump it | |
1162 | * up one, so we can read the queue id there. | |
1163 | */ | |
1164 | *delim = '\0'; | |
1165 | if (sscanf(++delim, "%hd\n", &qid) != 1) | |
1166 | goto err_no_cmd; | |
1167 | ||
1168 | /* Check buffer length, valid ifname and queue id */ | |
1169 | if (strlen(newval->string) > IFNAMSIZ || | |
1170 | !dev_valid_name(newval->string) || | |
1171 | qid > bond->dev->real_num_tx_queues) | |
1172 | goto err_no_cmd; | |
1173 | ||
1174 | /* Get the pointer to that interface if it exists */ | |
1175 | sdev = __dev_get_by_name(dev_net(bond->dev), newval->string); | |
1176 | if (!sdev) | |
1177 | goto err_no_cmd; | |
1178 | ||
1179 | /* Search for thes slave and check for duplicate qids */ | |
1180 | update_slave = NULL; | |
1181 | bond_for_each_slave(bond, slave, iter) { | |
1182 | if (sdev == slave->dev) | |
1183 | /* We don't need to check the matching | |
1184 | * slave for dups, since we're overwriting it | |
1185 | */ | |
1186 | update_slave = slave; | |
1187 | else if (qid && qid == slave->queue_id) { | |
1188 | goto err_no_cmd; | |
1189 | } | |
1190 | } | |
1191 | ||
1192 | if (!update_slave) | |
1193 | goto err_no_cmd; | |
1194 | ||
1195 | /* Actually set the qids for the slave */ | |
1196 | update_slave->queue_id = qid; | |
1197 | ||
1198 | out: | |
1199 | return ret; | |
1200 | ||
1201 | err_no_cmd: | |
1202 | pr_info("invalid input for queue_id set for %s.\n", | |
1203 | bond->dev->name); | |
1204 | ret = -EPERM; | |
1205 | goto out; | |
1206 | ||
1207 | } |