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