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