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