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