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