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