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