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