blob: 6e6b09359ec35479d604db91e28b5c91c5a95708 [file] [log] [blame]
Jiri Pirko72be35f2013-10-18 17:43:34 +02001/*
2 * drivers/net/bond/bond_options.c - bonding options
3 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -08004 * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
Jiri Pirko72be35f2013-10-18 17:43:34 +02005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/errno.h>
15#include <linux/if.h>
Jiri Pirkod9e32b22013-10-18 17:43:35 +020016#include <linux/netdevice.h>
Mike Galbraitheb2d4c62014-02-14 08:21:04 +010017#include <linux/spinlock.h>
Jiri Pirkod9e32b22013-10-18 17:43:35 +020018#include <linux/rcupdate.h>
Nikolay Aleksandrov09117362014-01-22 14:53:16 +010019#include <linux/ctype.h>
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +010020#include <linux/inet.h>
Jiri Pirko72be35f2013-10-18 17:43:34 +020021#include "bonding.h"
22
stephen hemmingerf3253332014-03-04 16:36:44 -080023static int bond_option_active_slave_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080024 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080025static int bond_option_miimon_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080026 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080027static int bond_option_updelay_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080028 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080029static int bond_option_downdelay_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080030 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080031static int bond_option_use_carrier_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080032 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080033static int bond_option_arp_interval_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080034 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080035static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
36static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
37static int bond_option_arp_ip_targets_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080038 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080039static int bond_option_arp_validate_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080040 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080041static int bond_option_arp_all_targets_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080042 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080043static int bond_option_primary_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080044 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080045static int bond_option_primary_reselect_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080046 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080047static int bond_option_fail_over_mac_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080048 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080049static int bond_option_xmit_hash_policy_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080050 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080051static int bond_option_resend_igmp_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080052 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080053static int bond_option_num_peer_notif_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080054 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080055static int bond_option_all_slaves_active_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080056 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080057static int bond_option_min_links_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080058 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080059static int bond_option_lp_interval_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080060 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080061static int bond_option_pps_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080062 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080063static int bond_option_lacp_rate_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080064 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080065static int bond_option_ad_select_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080066 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080067static int bond_option_queue_id_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080068 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080069static int bond_option_mode_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080070 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080071static int bond_option_slaves_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -080072 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080073
74
75static const struct bond_opt_value bond_mode_tbl[] = {
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +010076 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
77 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
78 { "balance-xor", BOND_MODE_XOR, 0},
79 { "broadcast", BOND_MODE_BROADCAST, 0},
80 { "802.3ad", BOND_MODE_8023AD, 0},
81 { "balance-tlb", BOND_MODE_TLB, 0},
82 { "balance-alb", BOND_MODE_ALB, 0},
83 { NULL, -1, 0},
84};
85
stephen hemmingerf3253332014-03-04 16:36:44 -080086static const struct bond_opt_value bond_pps_tbl[] = {
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +010087 { "default", 1, BOND_VALFLAG_DEFAULT},
88 { "maxval", USHRT_MAX, BOND_VALFLAG_MAX},
89 { NULL, -1, 0},
90};
91
stephen hemmingerf3253332014-03-04 16:36:44 -080092static const struct bond_opt_value bond_xmit_hashtype_tbl[] = {
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010093 { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
94 { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
95 { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
96 { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
97 { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
98 { NULL, -1, 0},
99};
100
stephen hemmingerf3253332014-03-04 16:36:44 -0800101static const struct bond_opt_value bond_arp_validate_tbl[] = {
Veaceslav Falico896149f2014-02-18 07:48:40 +0100102 { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
103 { "active", BOND_ARP_VALIDATE_ACTIVE, 0},
104 { "backup", BOND_ARP_VALIDATE_BACKUP, 0},
105 { "all", BOND_ARP_VALIDATE_ALL, 0},
106 { "filter", BOND_ARP_FILTER, 0},
107 { "filter_active", BOND_ARP_FILTER_ACTIVE, 0},
108 { "filter_backup", BOND_ARP_FILTER_BACKUP, 0},
109 { NULL, -1, 0},
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100110};
111
stephen hemmingerf3253332014-03-04 16:36:44 -0800112static const struct bond_opt_value bond_arp_all_targets_tbl[] = {
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100113 { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT},
114 { "all", BOND_ARP_TARGETS_ALL, 0},
115 { NULL, -1, 0},
116};
117
stephen hemmingerf3253332014-03-04 16:36:44 -0800118static const struct bond_opt_value bond_fail_over_mac_tbl[] = {
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100119 { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT},
120 { "active", BOND_FOM_ACTIVE, 0},
121 { "follow", BOND_FOM_FOLLOW, 0},
122 { NULL, -1, 0},
123};
124
stephen hemmingerf3253332014-03-04 16:36:44 -0800125static const struct bond_opt_value bond_intmax_tbl[] = {
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100126 { "off", 0, BOND_VALFLAG_DEFAULT},
127 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
128};
129
stephen hemmingerf3253332014-03-04 16:36:44 -0800130static const struct bond_opt_value bond_lacp_rate_tbl[] = {
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100131 { "slow", AD_LACP_SLOW, 0},
132 { "fast", AD_LACP_FAST, 0},
133 { NULL, -1, 0},
134};
135
stephen hemmingerf3253332014-03-04 16:36:44 -0800136static const struct bond_opt_value bond_ad_select_tbl[] = {
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100137 { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT},
138 { "bandwidth", BOND_AD_BANDWIDTH, 0},
139 { "count", BOND_AD_COUNT, 0},
140 { NULL, -1, 0},
141};
142
stephen hemmingerf3253332014-03-04 16:36:44 -0800143static const struct bond_opt_value bond_num_peer_notif_tbl[] = {
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100144 { "off", 0, 0},
145 { "maxval", 255, BOND_VALFLAG_MAX},
146 { "default", 1, BOND_VALFLAG_DEFAULT},
147 { NULL, -1, 0}
148};
149
stephen hemmingerf3253332014-03-04 16:36:44 -0800150static const struct bond_opt_value bond_primary_reselect_tbl[] = {
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100151 { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT},
152 { "better", BOND_PRI_RESELECT_BETTER, 0},
153 { "failure", BOND_PRI_RESELECT_FAILURE, 0},
154 { NULL, -1},
155};
156
stephen hemmingerf3253332014-03-04 16:36:44 -0800157static const struct bond_opt_value bond_use_carrier_tbl[] = {
Nikolay Aleksandrov0fff0602014-01-22 14:53:34 +0100158 { "off", 0, 0},
159 { "on", 1, BOND_VALFLAG_DEFAULT},
160 { NULL, -1, 0}
161};
162
stephen hemmingerf3253332014-03-04 16:36:44 -0800163static const struct bond_opt_value bond_all_slaves_active_tbl[] = {
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +0100164 { "off", 0, BOND_VALFLAG_DEFAULT},
165 { "on", 1, 0},
166 { NULL, -1, 0}
167};
168
stephen hemmingerf3253332014-03-04 16:36:44 -0800169static const struct bond_opt_value bond_resend_igmp_tbl[] = {
Nikolay Aleksandrov105c8fb2014-01-22 14:53:38 +0100170 { "off", 0, 0},
171 { "maxval", 255, BOND_VALFLAG_MAX},
172 { "default", 1, BOND_VALFLAG_DEFAULT},
173 { NULL, -1, 0}
174};
175
stephen hemmingerf3253332014-03-04 16:36:44 -0800176static const struct bond_opt_value bond_lp_interval_tbl[] = {
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +0100177 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
178 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
Sasha Levin5bd4e4c2014-03-06 16:53:11 -0500179 { NULL, -1, 0},
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +0100180};
181
stephen hemmingerf3253332014-03-04 16:36:44 -0800182static const struct bond_option bond_opts[] = {
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100183 [BOND_OPT_MODE] = {
184 .id = BOND_OPT_MODE,
185 .name = "mode",
186 .desc = "bond device mode",
187 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
188 .values = bond_mode_tbl,
189 .set = bond_option_mode_set
190 },
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +0100191 [BOND_OPT_PACKETS_PER_SLAVE] = {
192 .id = BOND_OPT_PACKETS_PER_SLAVE,
193 .name = "packets_per_slave",
194 .desc = "Packets to send per slave in RR mode",
195 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
196 .values = bond_pps_tbl,
197 .set = bond_option_pps_set
198 },
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100199 [BOND_OPT_XMIT_HASH] = {
200 .id = BOND_OPT_XMIT_HASH,
201 .name = "xmit_hash_policy",
202 .desc = "balance-xor and 802.3ad hashing method",
203 .values = bond_xmit_hashtype_tbl,
204 .set = bond_option_xmit_hash_policy_set
205 },
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100206 [BOND_OPT_ARP_VALIDATE] = {
207 .id = BOND_OPT_ARP_VALIDATE,
208 .name = "arp_validate",
209 .desc = "validate src/dst of ARP probes",
Veaceslav Falico13ac34a2014-02-18 07:48:37 +0100210 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
211 BIT(BOND_MODE_ALB),
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100212 .values = bond_arp_validate_tbl,
213 .set = bond_option_arp_validate_set
214 },
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100215 [BOND_OPT_ARP_ALL_TARGETS] = {
216 .id = BOND_OPT_ARP_ALL_TARGETS,
217 .name = "arp_all_targets",
218 .desc = "fail on any/all arp targets timeout",
219 .values = bond_arp_all_targets_tbl,
220 .set = bond_option_arp_all_targets_set
221 },
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100222 [BOND_OPT_FAIL_OVER_MAC] = {
223 .id = BOND_OPT_FAIL_OVER_MAC,
224 .name = "fail_over_mac",
225 .desc = "For active-backup, do not set all slaves to the same MAC",
226 .flags = BOND_OPTFLAG_NOSLAVES,
227 .values = bond_fail_over_mac_tbl,
228 .set = bond_option_fail_over_mac_set
229 },
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100230 [BOND_OPT_ARP_INTERVAL] = {
231 .id = BOND_OPT_ARP_INTERVAL,
232 .name = "arp_interval",
233 .desc = "arp interval in milliseconds",
234 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
235 BIT(BOND_MODE_ALB),
236 .values = bond_intmax_tbl,
237 .set = bond_option_arp_interval_set
238 },
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100239 [BOND_OPT_ARP_TARGETS] = {
240 .id = BOND_OPT_ARP_TARGETS,
241 .name = "arp_ip_target",
242 .desc = "arp targets in n.n.n.n form",
243 .flags = BOND_OPTFLAG_RAWVAL,
244 .set = bond_option_arp_ip_targets_set
245 },
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100246 [BOND_OPT_DOWNDELAY] = {
247 .id = BOND_OPT_DOWNDELAY,
248 .name = "downdelay",
249 .desc = "Delay before considering link down, in milliseconds",
250 .values = bond_intmax_tbl,
251 .set = bond_option_downdelay_set
252 },
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100253 [BOND_OPT_UPDELAY] = {
254 .id = BOND_OPT_UPDELAY,
255 .name = "updelay",
256 .desc = "Delay before considering link up, in milliseconds",
257 .values = bond_intmax_tbl,
258 .set = bond_option_updelay_set
259 },
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100260 [BOND_OPT_LACP_RATE] = {
261 .id = BOND_OPT_LACP_RATE,
262 .name = "lacp_rate",
263 .desc = "LACPDU tx rate to request from 802.3ad partner",
264 .flags = BOND_OPTFLAG_IFDOWN,
265 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
266 .values = bond_lacp_rate_tbl,
267 .set = bond_option_lacp_rate_set
268 },
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +0100269 [BOND_OPT_MINLINKS] = {
270 .id = BOND_OPT_MINLINKS,
271 .name = "min_links",
272 .desc = "Minimum number of available links before turning on carrier",
273 .values = bond_intmax_tbl,
274 .set = bond_option_min_links_set
275 },
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100276 [BOND_OPT_AD_SELECT] = {
277 .id = BOND_OPT_AD_SELECT,
278 .name = "ad_select",
279 .desc = "803.ad aggregation selection logic",
280 .flags = BOND_OPTFLAG_IFDOWN,
281 .values = bond_ad_select_tbl,
282 .set = bond_option_ad_select_set
283 },
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100284 [BOND_OPT_NUM_PEER_NOTIF] = {
285 .id = BOND_OPT_NUM_PEER_NOTIF,
286 .name = "num_unsol_na",
287 .desc = "Number of peer notifications to send on failover event",
288 .values = bond_num_peer_notif_tbl,
289 .set = bond_option_num_peer_notif_set
290 },
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100291 [BOND_OPT_MIIMON] = {
292 .id = BOND_OPT_MIIMON,
293 .name = "miimon",
294 .desc = "Link check interval in milliseconds",
295 .values = bond_intmax_tbl,
296 .set = bond_option_miimon_set
297 },
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +0100298 [BOND_OPT_PRIMARY] = {
299 .id = BOND_OPT_PRIMARY,
300 .name = "primary",
301 .desc = "Primary network device to use",
302 .flags = BOND_OPTFLAG_RAWVAL,
303 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
304 BIT(BOND_MODE_TLB) |
305 BIT(BOND_MODE_ALB)),
306 .set = bond_option_primary_set
307 },
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100308 [BOND_OPT_PRIMARY_RESELECT] = {
309 .id = BOND_OPT_PRIMARY_RESELECT,
310 .name = "primary_reselect",
311 .desc = "Reselect primary slave once it comes up",
312 .values = bond_primary_reselect_tbl,
313 .set = bond_option_primary_reselect_set
314 },
Nikolay Aleksandrov0fff0602014-01-22 14:53:34 +0100315 [BOND_OPT_USE_CARRIER] = {
316 .id = BOND_OPT_USE_CARRIER,
317 .name = "use_carrier",
318 .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon",
319 .values = bond_use_carrier_tbl,
320 .set = bond_option_use_carrier_set
321 },
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100322 [BOND_OPT_ACTIVE_SLAVE] = {
323 .id = BOND_OPT_ACTIVE_SLAVE,
324 .name = "active_slave",
325 .desc = "Currently active slave",
326 .flags = BOND_OPTFLAG_RAWVAL,
327 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
328 BIT(BOND_MODE_TLB) |
329 BIT(BOND_MODE_ALB)),
330 .set = bond_option_active_slave_set
331 },
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +0100332 [BOND_OPT_QUEUE_ID] = {
333 .id = BOND_OPT_QUEUE_ID,
334 .name = "queue_id",
335 .desc = "Set queue id of a slave",
336 .flags = BOND_OPTFLAG_RAWVAL,
337 .set = bond_option_queue_id_set
338 },
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +0100339 [BOND_OPT_ALL_SLAVES_ACTIVE] = {
340 .id = BOND_OPT_ALL_SLAVES_ACTIVE,
341 .name = "all_slaves_active",
342 .desc = "Keep all frames received on an interface by setting active flag for all slaves",
343 .values = bond_all_slaves_active_tbl,
344 .set = bond_option_all_slaves_active_set
345 },
Nikolay Aleksandrov105c8fb2014-01-22 14:53:38 +0100346 [BOND_OPT_RESEND_IGMP] = {
347 .id = BOND_OPT_RESEND_IGMP,
348 .name = "resend_igmp",
349 .desc = "Number of IGMP membership reports to send on link failure",
350 .values = bond_resend_igmp_tbl,
351 .set = bond_option_resend_igmp_set
352 },
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +0100353 [BOND_OPT_LP_INTERVAL] = {
354 .id = BOND_OPT_LP_INTERVAL,
355 .name = "lp_interval",
356 .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch",
357 .values = bond_lp_interval_tbl,
358 .set = bond_option_lp_interval_set
359 },
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +0100360 [BOND_OPT_SLAVES] = {
361 .id = BOND_OPT_SLAVES,
362 .name = "slaves",
363 .desc = "Slave membership management",
364 .flags = BOND_OPTFLAG_RAWVAL,
365 .set = bond_option_slaves_set
366 },
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100367 { }
368};
369
370/* Searches for a value in opt's values[] table */
stephen hemmingerf3253332014-03-04 16:36:44 -0800371const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100372{
stephen hemmingerf3253332014-03-04 16:36:44 -0800373 const struct bond_option *opt;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100374 int i;
375
376 opt = bond_opt_get(option);
377 if (WARN_ON(!opt))
378 return NULL;
379 for (i = 0; opt->values && opt->values[i].string; i++)
380 if (opt->values[i].value == val)
381 return &opt->values[i];
382
383 return NULL;
384}
385
386/* Searches for a value in opt's values[] table which matches the flagmask */
stephen hemmingerf3253332014-03-04 16:36:44 -0800387static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100388 u32 flagmask)
389{
390 int i;
391
392 for (i = 0; opt->values && opt->values[i].string; i++)
393 if (opt->values[i].flags & flagmask)
394 return &opt->values[i];
395
396 return NULL;
397}
398
399/* If maxval is missing then there's no range to check. In case minval is
400 * missing then it's considered to be 0.
401 */
402static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
403{
stephen hemmingerf3253332014-03-04 16:36:44 -0800404 const struct bond_opt_value *minval, *maxval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100405
406 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
407 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
408 if (!maxval || (minval && val < minval->value) || val > maxval->value)
409 return false;
410
411 return true;
412}
413
414/**
415 * bond_opt_parse - parse option value
416 * @opt: the option to parse against
417 * @val: value to parse
418 *
419 * This function tries to extract the value from @val and check if it's
420 * a possible match for the option and returns NULL if a match isn't found,
421 * or the struct_opt_value that matched. It also strips the new line from
422 * @val->string if it's present.
423 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800424const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
425 struct bond_opt_value *val)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100426{
427 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
stephen hemmingerf3253332014-03-04 16:36:44 -0800428 const struct bond_opt_value *tbl;
429 const struct bond_opt_value *ret = NULL;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100430 bool checkval;
431 int i, rv;
432
433 /* No parsing if the option wants a raw val */
434 if (opt->flags & BOND_OPTFLAG_RAWVAL)
435 return val;
436
437 tbl = opt->values;
438 if (!tbl)
439 goto out;
440
441 /* ULLONG_MAX is used to bypass string processing */
442 checkval = val->value != ULLONG_MAX;
443 if (!checkval) {
444 if (!val->string)
445 goto out;
446 p = strchr(val->string, '\n');
447 if (p)
448 *p = '\0';
449 for (p = val->string; *p; p++)
450 if (!(isdigit(*p) || isspace(*p)))
451 break;
452 /* The following code extracts the string to match or the value
453 * and sets checkval appropriately
454 */
455 if (*p) {
456 rv = sscanf(val->string, "%32s", valstr);
457 } else {
458 rv = sscanf(val->string, "%llu", &val->value);
459 checkval = true;
460 }
461 if (!rv)
462 goto out;
463 }
464
465 for (i = 0; tbl[i].string; i++) {
466 /* Check for exact match */
467 if (checkval) {
468 if (val->value == tbl[i].value)
469 ret = &tbl[i];
470 } else {
471 if (!strcmp(valstr, "default") &&
472 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
473 ret = &tbl[i];
474
475 if (!strcmp(valstr, tbl[i].string))
476 ret = &tbl[i];
477 }
478 /* Found an exact match */
479 if (ret)
480 goto out;
481 }
482 /* Possible range match */
483 if (checkval && bond_opt_check_range(opt, val->value))
484 ret = val;
485out:
486 return ret;
487}
488
489/* Check opt's dependencies against bond mode and currently set options */
490static int bond_opt_check_deps(struct bonding *bond,
491 const struct bond_option *opt)
492{
493 struct bond_params *params = &bond->params;
494
495 if (test_bit(params->mode, &opt->unsuppmodes))
496 return -EACCES;
497 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
498 return -ENOTEMPTY;
499 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
500 return -EBUSY;
501
502 return 0;
503}
504
505static void bond_opt_dep_print(struct bonding *bond,
506 const struct bond_option *opt)
507{
stephen hemminger28f084c2014-03-06 14:20:17 -0800508 const struct bond_opt_value *modeval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100509 struct bond_params *params;
510
511 params = &bond->params;
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100512 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100513 if (test_bit(params->mode, &opt->unsuppmodes))
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100514 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
515 bond->dev->name, opt->name,
516 modeval->string, modeval->value);
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100517}
518
519static void bond_opt_error_interpret(struct bonding *bond,
520 const struct bond_option *opt,
stephen hemminger28f084c2014-03-06 14:20:17 -0800521 int error, const struct bond_opt_value *val)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100522{
stephen hemminger28f084c2014-03-06 14:20:17 -0800523 const struct bond_opt_value *minval, *maxval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100524 char *p;
525
526 switch (error) {
527 case -EINVAL:
528 if (val) {
529 if (val->string) {
530 /* sometimes RAWVAL opts may have new lines */
531 p = strchr(val->string, '\n');
532 if (p)
533 *p = '\0';
Joe Perches90194262014-02-15 16:01:45 -0800534 pr_err("%s: option %s: invalid value (%s)\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100535 bond->dev->name, opt->name, val->string);
536 } else {
Joe Perches90194262014-02-15 16:01:45 -0800537 pr_err("%s: option %s: invalid value (%llu)\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100538 bond->dev->name, opt->name, val->value);
539 }
540 }
541 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
542 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
543 if (!maxval)
544 break;
Joe Perches90194262014-02-15 16:01:45 -0800545 pr_err("%s: option %s: allowed values %llu - %llu\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100546 bond->dev->name, opt->name, minval ? minval->value : 0,
547 maxval->value);
548 break;
549 case -EACCES:
550 bond_opt_dep_print(bond, opt);
551 break;
552 case -ENOTEMPTY:
Joe Perches90194262014-02-15 16:01:45 -0800553 pr_err("%s: option %s: unable to set because the bond device has slaves\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100554 bond->dev->name, opt->name);
555 break;
556 case -EBUSY:
Joe Perches90194262014-02-15 16:01:45 -0800557 pr_err("%s: option %s: unable to set because the bond device is up\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100558 bond->dev->name, opt->name);
559 break;
560 default:
561 break;
562 }
563}
564
565/**
566 * __bond_opt_set - set a bonding option
567 * @bond: target bond device
568 * @option: option to set
569 * @val: value to set it to
570 *
571 * This function is used to change the bond's option value, it can be
572 * used for both enabling/changing an option and for disabling it. RTNL lock
573 * must be obtained before calling this function.
574 */
575int __bond_opt_set(struct bonding *bond,
576 unsigned int option, struct bond_opt_value *val)
577{
stephen hemminger28f084c2014-03-06 14:20:17 -0800578 const struct bond_opt_value *retval = NULL;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100579 const struct bond_option *opt;
580 int ret = -ENOENT;
581
582 ASSERT_RTNL();
583
584 opt = bond_opt_get(option);
585 if (WARN_ON(!val) || WARN_ON(!opt))
586 goto out;
587 ret = bond_opt_check_deps(bond, opt);
588 if (ret)
589 goto out;
590 retval = bond_opt_parse(opt, val);
591 if (!retval) {
592 ret = -EINVAL;
593 goto out;
594 }
595 ret = opt->set(bond, retval);
596out:
597 if (ret)
598 bond_opt_error_interpret(bond, opt, ret, val);
599
600 return ret;
601}
602
603/**
604 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
605 * @bond: target bond device
606 * @option: option to set
607 * @buf: value to set it to
608 *
609 * This function tries to acquire RTNL without blocking and if successful
610 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
611 */
612int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
613{
614 struct bond_opt_value optval;
615 int ret;
616
617 if (!rtnl_trylock())
618 return restart_syscall();
619 bond_opt_initstr(&optval, buf);
620 ret = __bond_opt_set(bond, option, &optval);
621 rtnl_unlock();
622
623 return ret;
624}
625
626/**
627 * bond_opt_get - get a pointer to an option
628 * @option: option for which to return a pointer
629 *
630 * This function checks if option is valid and if so returns a pointer
631 * to its entry in the bond_opts[] option array.
632 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800633const struct bond_option *bond_opt_get(unsigned int option)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100634{
635 if (!BOND_OPT_VALID(option))
636 return NULL;
637
638 return &bond_opts[option];
639}
640
stephen hemminger28f084c2014-03-06 14:20:17 -0800641int bond_option_mode_set(struct bonding *bond, const struct bond_opt_value *newval)
Jiri Pirko72be35f2013-10-18 17:43:34 +0200642{
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100643 if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) {
dingtianhongfe9d04a2013-11-22 22:28:43 +0800644 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100645 bond->dev->name, newval->string);
dingtianhongfe9d04a2013-11-22 22:28:43 +0800646 /* disable arp monitoring */
647 bond->params.arp_interval = 0;
648 /* set miimon to default value */
649 bond->params.miimon = BOND_DEFAULT_MIIMON;
Joe Perches90194262014-02-15 16:01:45 -0800650 pr_info("%s: Setting MII monitoring interval to %d\n",
dingtianhongfe9d04a2013-11-22 22:28:43 +0800651 bond->dev->name, bond->params.miimon);
Jiri Pirko72be35f2013-10-18 17:43:34 +0200652 }
653
654 /* don't cache arp_validate between modes */
655 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100656 bond->params.mode = newval->value;
657
Jiri Pirko72be35f2013-10-18 17:43:34 +0200658 return 0;
659}
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200660
Jiri Pirko752d48b2013-10-18 17:43:37 +0200661static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
662 struct slave *slave)
663{
664 return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL;
665}
666
667struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
668{
669 struct slave *slave = rcu_dereference(bond->curr_active_slave);
670
671 return __bond_option_active_slave_get(bond, slave);
672}
673
674struct net_device *bond_option_active_slave_get(struct bonding *bond)
675{
676 return __bond_option_active_slave_get(bond, bond->curr_active_slave);
677}
678
stephen hemmingerf3253332014-03-04 16:36:44 -0800679static int bond_option_active_slave_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800680 const struct bond_opt_value *newval)
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200681{
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100682 char ifname[IFNAMSIZ] = { 0, };
683 struct net_device *slave_dev;
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200684 int ret = 0;
685
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100686 sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */
687 if (!strlen(ifname) || newval->string[0] == '\n') {
688 slave_dev = NULL;
689 } else {
690 slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname);
691 if (!slave_dev)
692 return -ENODEV;
693 }
694
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200695 if (slave_dev) {
696 if (!netif_is_bond_slave(slave_dev)) {
Joe Perches90194262014-02-15 16:01:45 -0800697 pr_err("Device %s is not bonding slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200698 slave_dev->name);
699 return -EINVAL;
700 }
701
702 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
Joe Perches90194262014-02-15 16:01:45 -0800703 pr_err("%s: Device %s is not our slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200704 bond->dev->name, slave_dev->name);
705 return -EINVAL;
706 }
707 }
708
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200709 block_netpoll_tx();
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200710 write_lock_bh(&bond->curr_slave_lock);
711
712 /* check to see if we are clearing active */
713 if (!slave_dev) {
Joe Perches90194262014-02-15 16:01:45 -0800714 pr_info("%s: Clearing current active slave\n", bond->dev->name);
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200715 rcu_assign_pointer(bond->curr_active_slave, NULL);
716 bond_select_active_slave(bond);
717 } else {
718 struct slave *old_active = bond->curr_active_slave;
719 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
720
721 BUG_ON(!new_active);
722
723 if (new_active == old_active) {
724 /* do nothing */
Joe Perches90194262014-02-15 16:01:45 -0800725 pr_info("%s: %s is already the current active slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200726 bond->dev->name, new_active->dev->name);
727 } else {
728 if (old_active && (new_active->link == BOND_LINK_UP) &&
729 IS_UP(new_active->dev)) {
Joe Perches90194262014-02-15 16:01:45 -0800730 pr_info("%s: Setting %s as active slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200731 bond->dev->name, new_active->dev->name);
732 bond_change_active_slave(bond, new_active);
733 } else {
Joe Perches90194262014-02-15 16:01:45 -0800734 pr_err("%s: Could not set %s as active slave; either %s is down or the link is down\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200735 bond->dev->name, new_active->dev->name,
736 new_active->dev->name);
737 ret = -EINVAL;
738 }
739 }
740 }
741
742 write_unlock_bh(&bond->curr_slave_lock);
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200743 unblock_netpoll_tx();
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100744
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200745 return ret;
746}
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800747
stephen hemmingerf3253332014-03-04 16:36:44 -0800748static int bond_option_miimon_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800749 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800750{
Joe Perches90194262014-02-15 16:01:45 -0800751 pr_info("%s: Setting MII monitoring interval to %llu\n",
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100752 bond->dev->name, newval->value);
753 bond->params.miimon = newval->value;
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800754 if (bond->params.updelay)
Joe Perches90194262014-02-15 16:01:45 -0800755 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value\n",
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800756 bond->dev->name,
757 bond->params.updelay * bond->params.miimon);
758 if (bond->params.downdelay)
Joe Perches90194262014-02-15 16:01:45 -0800759 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n",
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800760 bond->dev->name,
761 bond->params.downdelay * bond->params.miimon);
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100762 if (newval->value && bond->params.arp_interval) {
Joe Perches90194262014-02-15 16:01:45 -0800763 pr_info("%s: MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n",
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800764 bond->dev->name);
765 bond->params.arp_interval = 0;
766 if (bond->params.arp_validate)
767 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
768 }
769 if (bond->dev->flags & IFF_UP) {
770 /* If the interface is up, we may need to fire off
771 * the MII timer. If the interface is down, the
772 * timer will get fired off when the open function
773 * is called.
774 */
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100775 if (!newval->value) {
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800776 cancel_delayed_work_sync(&bond->mii_work);
777 } else {
778 cancel_delayed_work_sync(&bond->arp_work);
779 queue_delayed_work(bond->wq, &bond->mii_work, 0);
780 }
781 }
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100782
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800783 return 0;
784}
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800785
stephen hemmingerf3253332014-03-04 16:36:44 -0800786static int bond_option_updelay_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800787 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800788{
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100789 int value = newval->value;
790
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100791 if (!bond->params.miimon) {
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800792 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
793 bond->dev->name);
794 return -EPERM;
795 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100796 if ((value % bond->params.miimon) != 0) {
797 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
798 bond->dev->name, value,
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100799 bond->params.miimon,
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100800 (value / bond->params.miimon) *
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100801 bond->params.miimon);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800802 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100803 bond->params.updelay = value / bond->params.miimon;
Joe Perches90194262014-02-15 16:01:45 -0800804 pr_info("%s: Setting up delay to %d\n",
805 bond->dev->name, bond->params.updelay * bond->params.miimon);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800806
807 return 0;
808}
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800809
stephen hemmingerf3253332014-03-04 16:36:44 -0800810static int bond_option_downdelay_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800811 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800812{
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100813 int value = newval->value;
814
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100815 if (!bond->params.miimon) {
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800816 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
817 bond->dev->name);
818 return -EPERM;
819 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100820 if ((value % bond->params.miimon) != 0) {
821 pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
822 bond->dev->name, value,
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100823 bond->params.miimon,
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100824 (value / bond->params.miimon) *
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100825 bond->params.miimon);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800826 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100827 bond->params.downdelay = value / bond->params.miimon;
Joe Perches90194262014-02-15 16:01:45 -0800828 pr_info("%s: Setting down delay to %d\n",
829 bond->dev->name, bond->params.downdelay * bond->params.miimon);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800830
831 return 0;
832}
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800833
stephen hemmingerf3253332014-03-04 16:36:44 -0800834static int bond_option_use_carrier_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800835 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800836{
Joe Perches90194262014-02-15 16:01:45 -0800837 pr_info("%s: Setting use_carrier to %llu\n",
Nikolay Aleksandrov0fff0602014-01-22 14:53:34 +0100838 bond->dev->name, newval->value);
839 bond->params.use_carrier = newval->value;
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800840
841 return 0;
842}
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800843
stephen hemmingerf3253332014-03-04 16:36:44 -0800844static int bond_option_arp_interval_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800845 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800846{
Joe Perches90194262014-02-15 16:01:45 -0800847 pr_info("%s: Setting ARP monitoring interval to %llu\n",
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100848 bond->dev->name, newval->value);
849 bond->params.arp_interval = newval->value;
850 if (newval->value) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800851 if (bond->params.miimon) {
Joe Perches90194262014-02-15 16:01:45 -0800852 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring\n",
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800853 bond->dev->name, bond->dev->name);
854 bond->params.miimon = 0;
855 }
856 if (!bond->params.arp_targets[0])
Joe Perches90194262014-02-15 16:01:45 -0800857 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified\n",
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800858 bond->dev->name);
859 }
860 if (bond->dev->flags & IFF_UP) {
861 /* If the interface is up, we may need to fire off
862 * the ARP timer. If the interface is down, the
863 * timer will get fired off when the open function
864 * is called.
865 */
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100866 if (!newval->value) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800867 if (bond->params.arp_validate)
868 bond->recv_probe = NULL;
869 cancel_delayed_work_sync(&bond->arp_work);
870 } else {
871 /* arp_validate can be set only in active-backup mode */
Veaceslav Falico3fe68df2014-02-18 07:48:39 +0100872 bond->recv_probe = bond_arp_rcv;
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800873 cancel_delayed_work_sync(&bond->mii_work);
874 queue_delayed_work(bond->wq, &bond->arp_work, 0);
875 }
876 }
877
878 return 0;
879}
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800880
881static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
882 __be32 target,
883 unsigned long last_rx)
884{
885 __be32 *targets = bond->params.arp_targets;
886 struct list_head *iter;
887 struct slave *slave;
888
889 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
890 bond_for_each_slave(bond, slave, iter)
891 slave->target_last_arp_rx[slot] = last_rx;
892 targets[slot] = target;
893 }
894}
895
896static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
897{
898 __be32 *targets = bond->params.arp_targets;
899 int ind;
900
901 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
902 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
903 bond->dev->name, &target);
904 return -EINVAL;
905 }
906
907 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
908 pr_err("%s: ARP target %pI4 is already present\n",
909 bond->dev->name, &target);
910 return -EINVAL;
911 }
912
913 ind = bond_get_targets_ip(targets, 0); /* first free slot */
914 if (ind == -1) {
Joe Perches90194262014-02-15 16:01:45 -0800915 pr_err("%s: ARP target table is full!\n", bond->dev->name);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800916 return -EINVAL;
917 }
918
Joe Perches90194262014-02-15 16:01:45 -0800919 pr_info("%s: Adding ARP target %pI4\n", bond->dev->name, &target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800920
921 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
922
923 return 0;
924}
925
stephen hemmingerf3253332014-03-04 16:36:44 -0800926static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800927{
928 int ret;
929
930 /* not to race with bond_arp_rcv */
931 write_lock_bh(&bond->lock);
932 ret = _bond_option_arp_ip_target_add(bond, target);
933 write_unlock_bh(&bond->lock);
934
935 return ret;
936}
937
stephen hemmingerf3253332014-03-04 16:36:44 -0800938static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800939{
940 __be32 *targets = bond->params.arp_targets;
941 struct list_head *iter;
942 struct slave *slave;
943 unsigned long *targets_rx;
944 int ind, i;
945
946 if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) {
947 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
948 bond->dev->name, &target);
949 return -EINVAL;
950 }
951
952 ind = bond_get_targets_ip(targets, target);
953 if (ind == -1) {
Joe Perches90194262014-02-15 16:01:45 -0800954 pr_err("%s: unable to remove nonexistent ARP target %pI4\n",
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800955 bond->dev->name, &target);
956 return -EINVAL;
957 }
958
959 if (ind == 0 && !targets[1] && bond->params.arp_interval)
Joe Perches90194262014-02-15 16:01:45 -0800960 pr_warn("%s: Removing last arp target with arp_interval on\n",
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800961 bond->dev->name);
962
Joe Perches90194262014-02-15 16:01:45 -0800963 pr_info("%s: Removing ARP target %pI4\n", bond->dev->name, &target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800964
965 /* not to race with bond_arp_rcv */
966 write_lock_bh(&bond->lock);
967
968 bond_for_each_slave(bond, slave, iter) {
969 targets_rx = slave->target_last_arp_rx;
970 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
971 targets_rx[i] = targets_rx[i+1];
972 targets_rx[i] = 0;
973 }
974 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
975 targets[i] = targets[i+1];
976 targets[i] = 0;
977
978 write_unlock_bh(&bond->lock);
979
980 return 0;
981}
982
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100983void bond_option_arp_ip_targets_clear(struct bonding *bond)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800984{
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100985 int i;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800986
987 /* not to race with bond_arp_rcv */
988 write_lock_bh(&bond->lock);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800989 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
990 _bond_options_arp_ip_target_set(bond, i, 0, 0);
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100991 write_unlock_bh(&bond->lock);
992}
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800993
stephen hemmingerf3253332014-03-04 16:36:44 -0800994static int bond_option_arp_ip_targets_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800995 const struct bond_opt_value *newval)
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100996{
997 int ret = -EPERM;
998 __be32 target;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800999
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001000 if (newval->string) {
1001 if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) {
1002 pr_err("%s: invalid ARP target %pI4 specified\n",
1003 bond->dev->name, &target);
1004 return ret;
1005 }
1006 if (newval->string[0] == '+')
1007 ret = bond_option_arp_ip_target_add(bond, target);
1008 else if (newval->string[0] == '-')
1009 ret = bond_option_arp_ip_target_rem(bond, target);
1010 else
Joe Perches90194262014-02-15 16:01:45 -08001011 pr_err("no command found in arp_ip_targets file for bond %s - use +<addr> or -<addr>\n",
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001012 bond->dev->name);
1013 } else {
1014 target = newval->value;
1015 ret = bond_option_arp_ip_target_add(bond, target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001016 }
1017
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001018 return ret;
1019}
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001020
stephen hemmingerf3253332014-03-04 16:36:44 -08001021static int bond_option_arp_validate_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001022 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001023{
Joe Perches90194262014-02-15 16:01:45 -08001024 pr_info("%s: Setting arp_validate to %s (%llu)\n",
Nikolay Aleksandrov16228882014-01-22 14:53:20 +01001025 bond->dev->name, newval->string, newval->value);
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001026
1027 if (bond->dev->flags & IFF_UP) {
Nikolay Aleksandrov16228882014-01-22 14:53:20 +01001028 if (!newval->value)
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001029 bond->recv_probe = NULL;
1030 else if (bond->params.arp_interval)
1031 bond->recv_probe = bond_arp_rcv;
1032 }
Nikolay Aleksandrov16228882014-01-22 14:53:20 +01001033 bond->params.arp_validate = newval->value;
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001034
1035 return 0;
1036}
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -08001037
stephen hemmingerf3253332014-03-04 16:36:44 -08001038static int bond_option_arp_all_targets_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001039 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -08001040{
Joe Perches90194262014-02-15 16:01:45 -08001041 pr_info("%s: Setting arp_all_targets to %s (%llu)\n",
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +01001042 bond->dev->name, newval->string, newval->value);
1043 bond->params.arp_all_targets = newval->value;
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -08001044
1045 return 0;
1046}
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001047
stephen hemmingerf3253332014-03-04 16:36:44 -08001048static int bond_option_primary_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001049 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001050{
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +01001051 char *p, *primary = newval->string;
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001052 struct list_head *iter;
1053 struct slave *slave;
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001054
1055 block_netpoll_tx();
1056 read_lock(&bond->lock);
1057 write_lock_bh(&bond->curr_slave_lock);
1058
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +01001059 p = strchr(primary, '\n');
1060 if (p)
1061 *p = '\0';
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001062 /* check to see if we are clearing primary */
1063 if (!strlen(primary)) {
Joe Perches90194262014-02-15 16:01:45 -08001064 pr_info("%s: Setting primary slave to None\n", bond->dev->name);
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001065 bond->primary_slave = NULL;
1066 memset(bond->params.primary, 0, sizeof(bond->params.primary));
1067 bond_select_active_slave(bond);
1068 goto out;
1069 }
1070
1071 bond_for_each_slave(bond, slave, iter) {
1072 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
Joe Perches90194262014-02-15 16:01:45 -08001073 pr_info("%s: Setting %s as primary slave\n",
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001074 bond->dev->name, slave->dev->name);
1075 bond->primary_slave = slave;
1076 strcpy(bond->params.primary, slave->dev->name);
1077 bond_select_active_slave(bond);
1078 goto out;
1079 }
1080 }
1081
dingtianhongc59ab672014-01-18 16:28:52 +08001082 if (bond->primary_slave) {
Joe Perches90194262014-02-15 16:01:45 -08001083 pr_info("%s: Setting primary slave to None\n", bond->dev->name);
dingtianhongc59ab672014-01-18 16:28:52 +08001084 bond->primary_slave = NULL;
1085 bond_select_active_slave(bond);
1086 }
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001087 strncpy(bond->params.primary, primary, IFNAMSIZ);
1088 bond->params.primary[IFNAMSIZ - 1] = 0;
1089
Joe Perches90194262014-02-15 16:01:45 -08001090 pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet\n",
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001091 bond->dev->name, primary, bond->dev->name);
1092
1093out:
1094 write_unlock_bh(&bond->curr_slave_lock);
1095 read_unlock(&bond->lock);
1096 unblock_netpoll_tx();
1097
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +01001098 return 0;
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001099}
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -08001100
stephen hemmingerf3253332014-03-04 16:36:44 -08001101static int bond_option_primary_reselect_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001102 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -08001103{
Joe Perches90194262014-02-15 16:01:45 -08001104 pr_info("%s: Setting primary_reselect to %s (%llu)\n",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +01001105 bond->dev->name, newval->string, newval->value);
1106 bond->params.primary_reselect = newval->value;
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -08001107
1108 block_netpoll_tx();
1109 write_lock_bh(&bond->curr_slave_lock);
1110 bond_select_active_slave(bond);
1111 write_unlock_bh(&bond->curr_slave_lock);
1112 unblock_netpoll_tx();
1113
1114 return 0;
1115}
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -08001116
stephen hemmingerf3253332014-03-04 16:36:44 -08001117static int bond_option_fail_over_mac_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001118 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -08001119{
Joe Perches90194262014-02-15 16:01:45 -08001120 pr_info("%s: Setting fail_over_mac to %s (%llu)\n",
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +01001121 bond->dev->name, newval->string, newval->value);
1122 bond->params.fail_over_mac = newval->value;
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -08001123
1124 return 0;
1125}
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -08001126
stephen hemmingerf3253332014-03-04 16:36:44 -08001127static int bond_option_xmit_hash_policy_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001128 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -08001129{
Joe Perches90194262014-02-15 16:01:45 -08001130 pr_info("%s: Setting xmit hash policy to %s (%llu)\n",
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +01001131 bond->dev->name, newval->string, newval->value);
1132 bond->params.xmit_policy = newval->value;
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -08001133
1134 return 0;
1135}
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -08001136
stephen hemmingerf3253332014-03-04 16:36:44 -08001137static int bond_option_resend_igmp_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001138 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -08001139{
Joe Perches90194262014-02-15 16:01:45 -08001140 pr_info("%s: Setting resend_igmp to %llu\n",
Nikolay Aleksandrov105c8fb2014-01-22 14:53:38 +01001141 bond->dev->name, newval->value);
1142 bond->params.resend_igmp = newval->value;
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -08001143
1144 return 0;
1145}
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -08001146
stephen hemmingerf3253332014-03-04 16:36:44 -08001147static int bond_option_num_peer_notif_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001148 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -08001149{
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +01001150 bond->params.num_peer_notif = newval->value;
1151
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -08001152 return 0;
1153}
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -08001154
stephen hemmingerf3253332014-03-04 16:36:44 -08001155static int bond_option_all_slaves_active_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001156 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -08001157{
1158 struct list_head *iter;
1159 struct slave *slave;
1160
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +01001161 if (newval->value == bond->params.all_slaves_active)
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -08001162 return 0;
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +01001163 bond->params.all_slaves_active = newval->value;
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -08001164 bond_for_each_slave(bond, slave, iter) {
1165 if (!bond_is_active_slave(slave)) {
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +01001166 if (newval->value)
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -08001167 slave->inactive = 0;
1168 else
1169 slave->inactive = 1;
1170 }
1171 }
1172
1173 return 0;
1174}
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001175
stephen hemmingerf3253332014-03-04 16:36:44 -08001176static int bond_option_min_links_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001177 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001178{
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +01001179 pr_info("%s: Setting min links value to %llu\n",
1180 bond->dev->name, newval->value);
1181 bond->params.min_links = newval->value;
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001182
1183 return 0;
1184}
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001185
stephen hemmingerf3253332014-03-04 16:36:44 -08001186static int bond_option_lp_interval_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001187 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001188{
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +01001189 bond->params.lp_interval = newval->value;
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001190
1191 return 0;
1192}
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001193
stephen hemmingerf3253332014-03-04 16:36:44 -08001194static int bond_option_pps_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001195 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001196{
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001197 bond->params.packets_per_slave = newval->value;
1198 if (newval->value > 0) {
Hannes Frederic Sowa809fa972014-01-22 02:29:41 +01001199 bond->params.reciprocal_packets_per_slave =
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001200 reciprocal_value(newval->value);
Hannes Frederic Sowa809fa972014-01-22 02:29:41 +01001201 } else {
1202 /* reciprocal_packets_per_slave is unused if
1203 * packets_per_slave is 0 or 1, just initialize it
1204 */
1205 bond->params.reciprocal_packets_per_slave =
1206 (struct reciprocal_value) { 0 };
1207 }
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001208
1209 return 0;
1210}
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001211
stephen hemmingerf3253332014-03-04 16:36:44 -08001212static int bond_option_lacp_rate_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001213 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001214{
Joe Perches90194262014-02-15 16:01:45 -08001215 pr_info("%s: Setting LACP rate to %s (%llu)\n",
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +01001216 bond->dev->name, newval->string, newval->value);
1217 bond->params.lacp_fast = newval->value;
sfeldma@cumulusnetworks.com3243c472014-01-03 14:28:18 -08001218 bond_3ad_update_lacp_rate(bond);
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001219
1220 return 0;
1221}
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001222
stephen hemmingerf3253332014-03-04 16:36:44 -08001223static int bond_option_ad_select_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001224 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001225{
Joe Perches90194262014-02-15 16:01:45 -08001226 pr_info("%s: Setting ad_select to %s (%llu)\n",
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +01001227 bond->dev->name, newval->string, newval->value);
1228 bond->params.ad_select = newval->value;
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001229
1230 return 0;
1231}
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001232
stephen hemmingerf3253332014-03-04 16:36:44 -08001233static int bond_option_queue_id_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001234 const struct bond_opt_value *newval)
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001235{
1236 struct slave *slave, *update_slave;
1237 struct net_device *sdev;
1238 struct list_head *iter;
1239 char *delim;
1240 int ret = 0;
1241 u16 qid;
1242
1243 /* delim will point to queue id if successful */
1244 delim = strchr(newval->string, ':');
1245 if (!delim)
1246 goto err_no_cmd;
1247
1248 /* Terminate string that points to device name and bump it
1249 * up one, so we can read the queue id there.
1250 */
1251 *delim = '\0';
1252 if (sscanf(++delim, "%hd\n", &qid) != 1)
1253 goto err_no_cmd;
1254
1255 /* Check buffer length, valid ifname and queue id */
dingtianhongc313c892014-02-12 14:58:50 +08001256 if (!dev_valid_name(newval->string) ||
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001257 qid > bond->dev->real_num_tx_queues)
1258 goto err_no_cmd;
1259
1260 /* Get the pointer to that interface if it exists */
1261 sdev = __dev_get_by_name(dev_net(bond->dev), newval->string);
1262 if (!sdev)
1263 goto err_no_cmd;
1264
1265 /* Search for thes slave and check for duplicate qids */
1266 update_slave = NULL;
1267 bond_for_each_slave(bond, slave, iter) {
1268 if (sdev == slave->dev)
1269 /* We don't need to check the matching
1270 * slave for dups, since we're overwriting it
1271 */
1272 update_slave = slave;
1273 else if (qid && qid == slave->queue_id) {
1274 goto err_no_cmd;
1275 }
1276 }
1277
1278 if (!update_slave)
1279 goto err_no_cmd;
1280
1281 /* Actually set the qids for the slave */
1282 update_slave->queue_id = qid;
1283
1284out:
1285 return ret;
1286
1287err_no_cmd:
Joe Perches90194262014-02-15 16:01:45 -08001288 pr_info("invalid input for queue_id set for %s\n", bond->dev->name);
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001289 ret = -EPERM;
1290 goto out;
1291
1292}
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001293
stephen hemmingerf3253332014-03-04 16:36:44 -08001294static int bond_option_slaves_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001295 const struct bond_opt_value *newval)
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001296{
1297 char command[IFNAMSIZ + 1] = { 0, };
1298 struct net_device *dev;
1299 char *ifname;
1300 int ret;
1301
1302 sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
1303 ifname = command + 1;
1304 if ((strlen(command) <= 1) ||
1305 !dev_valid_name(ifname))
1306 goto err_no_cmd;
1307
1308 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
1309 if (!dev) {
Joe Perches90194262014-02-15 16:01:45 -08001310 pr_info("%s: interface %s does not exist!\n",
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001311 bond->dev->name, ifname);
1312 ret = -ENODEV;
1313 goto out;
1314 }
1315
1316 switch (command[0]) {
1317 case '+':
Joe Perches90194262014-02-15 16:01:45 -08001318 pr_info("%s: Adding slave %s\n", bond->dev->name, dev->name);
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001319 ret = bond_enslave(bond->dev, dev);
1320 break;
1321
1322 case '-':
Joe Perches90194262014-02-15 16:01:45 -08001323 pr_info("%s: Removing slave %s\n", bond->dev->name, dev->name);
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001324 ret = bond_release(bond->dev, dev);
1325 break;
1326
1327 default:
1328 goto err_no_cmd;
1329 }
1330
1331out:
1332 return ret;
1333
1334err_no_cmd:
Joe Perches90194262014-02-15 16:01:45 -08001335 pr_err("no command found in slaves file for bond %s - use +ifname or -ifname\n",
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001336 bond->dev->name);
1337 ret = -EPERM;
1338 goto out;
1339}