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