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