blob: cf720ce1b69e070d4df4e02111e0bc34a34956ed [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);
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -070073static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
74 const struct bond_opt_value *newval);
stephen hemmingerf3253332014-03-04 16:36:44 -080075
76
77static const struct bond_opt_value bond_mode_tbl[] = {
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +010078 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
79 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
80 { "balance-xor", BOND_MODE_XOR, 0},
81 { "broadcast", BOND_MODE_BROADCAST, 0},
82 { "802.3ad", BOND_MODE_8023AD, 0},
83 { "balance-tlb", BOND_MODE_TLB, 0},
84 { "balance-alb", BOND_MODE_ALB, 0},
85 { NULL, -1, 0},
86};
87
stephen hemmingerf3253332014-03-04 16:36:44 -080088static const struct bond_opt_value bond_pps_tbl[] = {
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +010089 { "default", 1, BOND_VALFLAG_DEFAULT},
90 { "maxval", USHRT_MAX, BOND_VALFLAG_MAX},
91 { NULL, -1, 0},
92};
93
stephen hemmingerf3253332014-03-04 16:36:44 -080094static const struct bond_opt_value bond_xmit_hashtype_tbl[] = {
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +010095 { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT},
96 { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0},
97 { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0},
98 { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0},
99 { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0},
100 { NULL, -1, 0},
101};
102
stephen hemmingerf3253332014-03-04 16:36:44 -0800103static const struct bond_opt_value bond_arp_validate_tbl[] = {
Veaceslav Falico896149f2014-02-18 07:48:40 +0100104 { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT},
105 { "active", BOND_ARP_VALIDATE_ACTIVE, 0},
106 { "backup", BOND_ARP_VALIDATE_BACKUP, 0},
107 { "all", BOND_ARP_VALIDATE_ALL, 0},
108 { "filter", BOND_ARP_FILTER, 0},
109 { "filter_active", BOND_ARP_FILTER_ACTIVE, 0},
110 { "filter_backup", BOND_ARP_FILTER_BACKUP, 0},
111 { NULL, -1, 0},
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100112};
113
stephen hemmingerf3253332014-03-04 16:36:44 -0800114static const struct bond_opt_value bond_arp_all_targets_tbl[] = {
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100115 { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT},
116 { "all", BOND_ARP_TARGETS_ALL, 0},
117 { NULL, -1, 0},
118};
119
stephen hemmingerf3253332014-03-04 16:36:44 -0800120static const struct bond_opt_value bond_fail_over_mac_tbl[] = {
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100121 { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT},
122 { "active", BOND_FOM_ACTIVE, 0},
123 { "follow", BOND_FOM_FOLLOW, 0},
124 { NULL, -1, 0},
125};
126
stephen hemmingerf3253332014-03-04 16:36:44 -0800127static const struct bond_opt_value bond_intmax_tbl[] = {
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100128 { "off", 0, BOND_VALFLAG_DEFAULT},
129 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
Nikolay Aleksandrov81c70802014-05-15 13:35:23 +0200130 { NULL, -1, 0}
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100131};
132
stephen hemmingerf3253332014-03-04 16:36:44 -0800133static const struct bond_opt_value bond_lacp_rate_tbl[] = {
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100134 { "slow", AD_LACP_SLOW, 0},
135 { "fast", AD_LACP_FAST, 0},
136 { NULL, -1, 0},
137};
138
stephen hemmingerf3253332014-03-04 16:36:44 -0800139static const struct bond_opt_value bond_ad_select_tbl[] = {
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100140 { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT},
141 { "bandwidth", BOND_AD_BANDWIDTH, 0},
142 { "count", BOND_AD_COUNT, 0},
143 { NULL, -1, 0},
144};
145
stephen hemmingerf3253332014-03-04 16:36:44 -0800146static const struct bond_opt_value bond_num_peer_notif_tbl[] = {
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100147 { "off", 0, 0},
148 { "maxval", 255, BOND_VALFLAG_MAX},
149 { "default", 1, BOND_VALFLAG_DEFAULT},
150 { NULL, -1, 0}
151};
152
stephen hemmingerf3253332014-03-04 16:36:44 -0800153static const struct bond_opt_value bond_primary_reselect_tbl[] = {
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100154 { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT},
155 { "better", BOND_PRI_RESELECT_BETTER, 0},
156 { "failure", BOND_PRI_RESELECT_FAILURE, 0},
157 { NULL, -1},
158};
159
stephen hemmingerf3253332014-03-04 16:36:44 -0800160static const struct bond_opt_value bond_use_carrier_tbl[] = {
Nikolay Aleksandrov0fff0602014-01-22 14:53:34 +0100161 { "off", 0, 0},
162 { "on", 1, BOND_VALFLAG_DEFAULT},
163 { NULL, -1, 0}
164};
165
stephen hemmingerf3253332014-03-04 16:36:44 -0800166static const struct bond_opt_value bond_all_slaves_active_tbl[] = {
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +0100167 { "off", 0, BOND_VALFLAG_DEFAULT},
168 { "on", 1, 0},
169 { NULL, -1, 0}
170};
171
stephen hemmingerf3253332014-03-04 16:36:44 -0800172static const struct bond_opt_value bond_resend_igmp_tbl[] = {
Nikolay Aleksandrov105c8fb2014-01-22 14:53:38 +0100173 { "off", 0, 0},
174 { "maxval", 255, BOND_VALFLAG_MAX},
175 { "default", 1, BOND_VALFLAG_DEFAULT},
176 { NULL, -1, 0}
177};
178
stephen hemmingerf3253332014-03-04 16:36:44 -0800179static const struct bond_opt_value bond_lp_interval_tbl[] = {
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +0100180 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT},
181 { "maxval", INT_MAX, BOND_VALFLAG_MAX},
Sasha Levin5bd4e4c2014-03-06 16:53:11 -0500182 { NULL, -1, 0},
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +0100183};
184
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700185static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = {
186 { "off", 0, 0},
187 { "on", 1, BOND_VALFLAG_DEFAULT},
188 { NULL, -1, 0}
189};
190
stephen hemmingerf3253332014-03-04 16:36:44 -0800191static const struct bond_option bond_opts[] = {
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100192 [BOND_OPT_MODE] = {
193 .id = BOND_OPT_MODE,
194 .name = "mode",
195 .desc = "bond device mode",
196 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN,
197 .values = bond_mode_tbl,
198 .set = bond_option_mode_set
199 },
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +0100200 [BOND_OPT_PACKETS_PER_SLAVE] = {
201 .id = BOND_OPT_PACKETS_PER_SLAVE,
202 .name = "packets_per_slave",
203 .desc = "Packets to send per slave in RR mode",
204 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)),
205 .values = bond_pps_tbl,
206 .set = bond_option_pps_set
207 },
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100208 [BOND_OPT_XMIT_HASH] = {
209 .id = BOND_OPT_XMIT_HASH,
210 .name = "xmit_hash_policy",
Mahesh Bandewarf05b42e2014-04-22 16:30:20 -0700211 .desc = "balance-xor, 802.3ad, and tlb hashing method",
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100212 .values = bond_xmit_hashtype_tbl,
213 .set = bond_option_xmit_hash_policy_set
214 },
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100215 [BOND_OPT_ARP_VALIDATE] = {
216 .id = BOND_OPT_ARP_VALIDATE,
217 .name = "arp_validate",
218 .desc = "validate src/dst of ARP probes",
Veaceslav Falico13ac34a2014-02-18 07:48:37 +0100219 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
220 BIT(BOND_MODE_ALB),
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100221 .values = bond_arp_validate_tbl,
222 .set = bond_option_arp_validate_set
223 },
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100224 [BOND_OPT_ARP_ALL_TARGETS] = {
225 .id = BOND_OPT_ARP_ALL_TARGETS,
226 .name = "arp_all_targets",
227 .desc = "fail on any/all arp targets timeout",
228 .values = bond_arp_all_targets_tbl,
229 .set = bond_option_arp_all_targets_set
230 },
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100231 [BOND_OPT_FAIL_OVER_MAC] = {
232 .id = BOND_OPT_FAIL_OVER_MAC,
233 .name = "fail_over_mac",
234 .desc = "For active-backup, do not set all slaves to the same MAC",
235 .flags = BOND_OPTFLAG_NOSLAVES,
236 .values = bond_fail_over_mac_tbl,
237 .set = bond_option_fail_over_mac_set
238 },
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100239 [BOND_OPT_ARP_INTERVAL] = {
240 .id = BOND_OPT_ARP_INTERVAL,
241 .name = "arp_interval",
242 .desc = "arp interval in milliseconds",
243 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) |
244 BIT(BOND_MODE_ALB),
245 .values = bond_intmax_tbl,
246 .set = bond_option_arp_interval_set
247 },
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100248 [BOND_OPT_ARP_TARGETS] = {
249 .id = BOND_OPT_ARP_TARGETS,
250 .name = "arp_ip_target",
251 .desc = "arp targets in n.n.n.n form",
252 .flags = BOND_OPTFLAG_RAWVAL,
253 .set = bond_option_arp_ip_targets_set
254 },
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100255 [BOND_OPT_DOWNDELAY] = {
256 .id = BOND_OPT_DOWNDELAY,
257 .name = "downdelay",
258 .desc = "Delay before considering link down, in milliseconds",
259 .values = bond_intmax_tbl,
260 .set = bond_option_downdelay_set
261 },
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100262 [BOND_OPT_UPDELAY] = {
263 .id = BOND_OPT_UPDELAY,
264 .name = "updelay",
265 .desc = "Delay before considering link up, in milliseconds",
266 .values = bond_intmax_tbl,
267 .set = bond_option_updelay_set
268 },
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100269 [BOND_OPT_LACP_RATE] = {
270 .id = BOND_OPT_LACP_RATE,
271 .name = "lacp_rate",
272 .desc = "LACPDU tx rate to request from 802.3ad partner",
273 .flags = BOND_OPTFLAG_IFDOWN,
274 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)),
275 .values = bond_lacp_rate_tbl,
276 .set = bond_option_lacp_rate_set
277 },
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +0100278 [BOND_OPT_MINLINKS] = {
279 .id = BOND_OPT_MINLINKS,
280 .name = "min_links",
281 .desc = "Minimum number of available links before turning on carrier",
282 .values = bond_intmax_tbl,
283 .set = bond_option_min_links_set
284 },
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100285 [BOND_OPT_AD_SELECT] = {
286 .id = BOND_OPT_AD_SELECT,
287 .name = "ad_select",
288 .desc = "803.ad aggregation selection logic",
289 .flags = BOND_OPTFLAG_IFDOWN,
290 .values = bond_ad_select_tbl,
291 .set = bond_option_ad_select_set
292 },
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100293 [BOND_OPT_NUM_PEER_NOTIF] = {
294 .id = BOND_OPT_NUM_PEER_NOTIF,
295 .name = "num_unsol_na",
296 .desc = "Number of peer notifications to send on failover event",
297 .values = bond_num_peer_notif_tbl,
298 .set = bond_option_num_peer_notif_set
299 },
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100300 [BOND_OPT_MIIMON] = {
301 .id = BOND_OPT_MIIMON,
302 .name = "miimon",
303 .desc = "Link check interval in milliseconds",
304 .values = bond_intmax_tbl,
305 .set = bond_option_miimon_set
306 },
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +0100307 [BOND_OPT_PRIMARY] = {
308 .id = BOND_OPT_PRIMARY,
309 .name = "primary",
310 .desc = "Primary network device to use",
311 .flags = BOND_OPTFLAG_RAWVAL,
312 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
313 BIT(BOND_MODE_TLB) |
314 BIT(BOND_MODE_ALB)),
315 .set = bond_option_primary_set
316 },
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +0100317 [BOND_OPT_PRIMARY_RESELECT] = {
318 .id = BOND_OPT_PRIMARY_RESELECT,
319 .name = "primary_reselect",
320 .desc = "Reselect primary slave once it comes up",
321 .values = bond_primary_reselect_tbl,
322 .set = bond_option_primary_reselect_set
323 },
Nikolay Aleksandrov0fff0602014-01-22 14:53:34 +0100324 [BOND_OPT_USE_CARRIER] = {
325 .id = BOND_OPT_USE_CARRIER,
326 .name = "use_carrier",
327 .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon",
328 .values = bond_use_carrier_tbl,
329 .set = bond_option_use_carrier_set
330 },
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100331 [BOND_OPT_ACTIVE_SLAVE] = {
332 .id = BOND_OPT_ACTIVE_SLAVE,
333 .name = "active_slave",
334 .desc = "Currently active slave",
335 .flags = BOND_OPTFLAG_RAWVAL,
336 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) |
337 BIT(BOND_MODE_TLB) |
338 BIT(BOND_MODE_ALB)),
339 .set = bond_option_active_slave_set
340 },
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +0100341 [BOND_OPT_QUEUE_ID] = {
342 .id = BOND_OPT_QUEUE_ID,
343 .name = "queue_id",
344 .desc = "Set queue id of a slave",
345 .flags = BOND_OPTFLAG_RAWVAL,
346 .set = bond_option_queue_id_set
347 },
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +0100348 [BOND_OPT_ALL_SLAVES_ACTIVE] = {
349 .id = BOND_OPT_ALL_SLAVES_ACTIVE,
350 .name = "all_slaves_active",
351 .desc = "Keep all frames received on an interface by setting active flag for all slaves",
352 .values = bond_all_slaves_active_tbl,
353 .set = bond_option_all_slaves_active_set
354 },
Nikolay Aleksandrov105c8fb2014-01-22 14:53:38 +0100355 [BOND_OPT_RESEND_IGMP] = {
356 .id = BOND_OPT_RESEND_IGMP,
357 .name = "resend_igmp",
358 .desc = "Number of IGMP membership reports to send on link failure",
359 .values = bond_resend_igmp_tbl,
360 .set = bond_option_resend_igmp_set
361 },
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +0100362 [BOND_OPT_LP_INTERVAL] = {
363 .id = BOND_OPT_LP_INTERVAL,
364 .name = "lp_interval",
365 .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch",
366 .values = bond_lp_interval_tbl,
367 .set = bond_option_lp_interval_set
368 },
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +0100369 [BOND_OPT_SLAVES] = {
370 .id = BOND_OPT_SLAVES,
371 .name = "slaves",
372 .desc = "Slave membership management",
373 .flags = BOND_OPTFLAG_RAWVAL,
374 .set = bond_option_slaves_set
375 },
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700376 [BOND_OPT_TLB_DYNAMIC_LB] = {
377 .id = BOND_OPT_TLB_DYNAMIC_LB,
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200378 .name = "tlb_dynamic_lb",
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -0700379 .desc = "Enable dynamic flow shuffling",
380 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB)),
381 .values = bond_tlb_dynamic_lb_tbl,
382 .flags = BOND_OPTFLAG_IFDOWN,
383 .set = bond_option_tlb_dynamic_lb_set,
384 },
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100385 { }
386};
387
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200388/* Searches for an option by name */
389const struct bond_option *bond_opt_get_by_name(const char *name)
390{
391 const struct bond_option *opt;
392 int option;
393
394 for (option = 0; option < BOND_OPT_LAST; option++) {
395 opt = bond_opt_get(option);
396 if (opt && !strcmp(opt->name, name))
397 return opt;
398 }
399
400 return NULL;
401}
402
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100403/* Searches for a value in opt's values[] table */
stephen hemmingerf3253332014-03-04 16:36:44 -0800404const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100405{
stephen hemmingerf3253332014-03-04 16:36:44 -0800406 const struct bond_option *opt;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100407 int i;
408
409 opt = bond_opt_get(option);
410 if (WARN_ON(!opt))
411 return NULL;
412 for (i = 0; opt->values && opt->values[i].string; i++)
413 if (opt->values[i].value == val)
414 return &opt->values[i];
415
416 return NULL;
417}
418
419/* Searches for a value in opt's values[] table which matches the flagmask */
stephen hemmingerf3253332014-03-04 16:36:44 -0800420static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt,
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100421 u32 flagmask)
422{
423 int i;
424
425 for (i = 0; opt->values && opt->values[i].string; i++)
426 if (opt->values[i].flags & flagmask)
427 return &opt->values[i];
428
429 return NULL;
430}
431
432/* If maxval is missing then there's no range to check. In case minval is
433 * missing then it's considered to be 0.
434 */
435static bool bond_opt_check_range(const struct bond_option *opt, u64 val)
436{
stephen hemmingerf3253332014-03-04 16:36:44 -0800437 const struct bond_opt_value *minval, *maxval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100438
439 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
440 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
441 if (!maxval || (minval && val < minval->value) || val > maxval->value)
442 return false;
443
444 return true;
445}
446
447/**
448 * bond_opt_parse - parse option value
449 * @opt: the option to parse against
450 * @val: value to parse
451 *
452 * This function tries to extract the value from @val and check if it's
453 * a possible match for the option and returns NULL if a match isn't found,
454 * or the struct_opt_value that matched. It also strips the new line from
455 * @val->string if it's present.
456 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800457const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt,
458 struct bond_opt_value *val)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100459{
460 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, };
stephen hemmingerf3253332014-03-04 16:36:44 -0800461 const struct bond_opt_value *tbl;
462 const struct bond_opt_value *ret = NULL;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100463 bool checkval;
464 int i, rv;
465
466 /* No parsing if the option wants a raw val */
467 if (opt->flags & BOND_OPTFLAG_RAWVAL)
468 return val;
469
470 tbl = opt->values;
471 if (!tbl)
472 goto out;
473
474 /* ULLONG_MAX is used to bypass string processing */
475 checkval = val->value != ULLONG_MAX;
476 if (!checkval) {
477 if (!val->string)
478 goto out;
479 p = strchr(val->string, '\n');
480 if (p)
481 *p = '\0';
482 for (p = val->string; *p; p++)
483 if (!(isdigit(*p) || isspace(*p)))
484 break;
485 /* The following code extracts the string to match or the value
486 * and sets checkval appropriately
487 */
488 if (*p) {
489 rv = sscanf(val->string, "%32s", valstr);
490 } else {
491 rv = sscanf(val->string, "%llu", &val->value);
492 checkval = true;
493 }
494 if (!rv)
495 goto out;
496 }
497
498 for (i = 0; tbl[i].string; i++) {
499 /* Check for exact match */
500 if (checkval) {
501 if (val->value == tbl[i].value)
502 ret = &tbl[i];
503 } else {
504 if (!strcmp(valstr, "default") &&
505 (tbl[i].flags & BOND_VALFLAG_DEFAULT))
506 ret = &tbl[i];
507
508 if (!strcmp(valstr, tbl[i].string))
509 ret = &tbl[i];
510 }
511 /* Found an exact match */
512 if (ret)
513 goto out;
514 }
515 /* Possible range match */
516 if (checkval && bond_opt_check_range(opt, val->value))
517 ret = val;
518out:
519 return ret;
520}
521
522/* Check opt's dependencies against bond mode and currently set options */
523static int bond_opt_check_deps(struct bonding *bond,
524 const struct bond_option *opt)
525{
526 struct bond_params *params = &bond->params;
527
528 if (test_bit(params->mode, &opt->unsuppmodes))
529 return -EACCES;
530 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond))
531 return -ENOTEMPTY;
532 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP))
533 return -EBUSY;
534
535 return 0;
536}
537
538static void bond_opt_dep_print(struct bonding *bond,
539 const struct bond_option *opt)
540{
stephen hemminger28f084c2014-03-06 14:20:17 -0800541 const struct bond_opt_value *modeval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100542 struct bond_params *params;
543
544 params = &bond->params;
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100545 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode);
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100546 if (test_bit(params->mode, &opt->unsuppmodes))
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100547 pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n",
548 bond->dev->name, opt->name,
549 modeval->string, modeval->value);
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100550}
551
552static void bond_opt_error_interpret(struct bonding *bond,
553 const struct bond_option *opt,
stephen hemminger28f084c2014-03-06 14:20:17 -0800554 int error, const struct bond_opt_value *val)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100555{
stephen hemminger28f084c2014-03-06 14:20:17 -0800556 const struct bond_opt_value *minval, *maxval;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100557 char *p;
558
559 switch (error) {
560 case -EINVAL:
561 if (val) {
562 if (val->string) {
563 /* sometimes RAWVAL opts may have new lines */
564 p = strchr(val->string, '\n');
565 if (p)
566 *p = '\0';
Joe Perches90194262014-02-15 16:01:45 -0800567 pr_err("%s: option %s: invalid value (%s)\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100568 bond->dev->name, opt->name, val->string);
569 } else {
Joe Perches90194262014-02-15 16:01:45 -0800570 pr_err("%s: option %s: invalid value (%llu)\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100571 bond->dev->name, opt->name, val->value);
572 }
573 }
574 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN);
575 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX);
576 if (!maxval)
577 break;
Joe Perches90194262014-02-15 16:01:45 -0800578 pr_err("%s: option %s: allowed values %llu - %llu\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100579 bond->dev->name, opt->name, minval ? minval->value : 0,
580 maxval->value);
581 break;
582 case -EACCES:
583 bond_opt_dep_print(bond, opt);
584 break;
585 case -ENOTEMPTY:
Joe Perches90194262014-02-15 16:01:45 -0800586 pr_err("%s: option %s: unable to set because the bond device has slaves\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100587 bond->dev->name, opt->name);
588 break;
589 case -EBUSY:
Joe Perches90194262014-02-15 16:01:45 -0800590 pr_err("%s: option %s: unable to set because the bond device is up\n",
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100591 bond->dev->name, opt->name);
592 break;
593 default:
594 break;
595 }
596}
597
598/**
599 * __bond_opt_set - set a bonding option
600 * @bond: target bond device
601 * @option: option to set
602 * @val: value to set it to
603 *
604 * This function is used to change the bond's option value, it can be
605 * used for both enabling/changing an option and for disabling it. RTNL lock
606 * must be obtained before calling this function.
607 */
608int __bond_opt_set(struct bonding *bond,
609 unsigned int option, struct bond_opt_value *val)
610{
stephen hemminger28f084c2014-03-06 14:20:17 -0800611 const struct bond_opt_value *retval = NULL;
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100612 const struct bond_option *opt;
613 int ret = -ENOENT;
614
615 ASSERT_RTNL();
616
617 opt = bond_opt_get(option);
618 if (WARN_ON(!val) || WARN_ON(!opt))
619 goto out;
620 ret = bond_opt_check_deps(bond, opt);
621 if (ret)
622 goto out;
623 retval = bond_opt_parse(opt, val);
624 if (!retval) {
625 ret = -EINVAL;
626 goto out;
627 }
628 ret = opt->set(bond, retval);
629out:
630 if (ret)
631 bond_opt_error_interpret(bond, opt, ret, val);
632
633 return ret;
634}
635
636/**
637 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
638 * @bond: target bond device
639 * @option: option to set
640 * @buf: value to set it to
641 *
642 * This function tries to acquire RTNL without blocking and if successful
643 * calls __bond_opt_set. It is mainly used for sysfs option manipulation.
644 */
645int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf)
646{
647 struct bond_opt_value optval;
648 int ret;
649
650 if (!rtnl_trylock())
651 return restart_syscall();
652 bond_opt_initstr(&optval, buf);
653 ret = __bond_opt_set(bond, option, &optval);
654 rtnl_unlock();
655
656 return ret;
657}
658
659/**
660 * bond_opt_get - get a pointer to an option
661 * @option: option for which to return a pointer
662 *
663 * This function checks if option is valid and if so returns a pointer
664 * to its entry in the bond_opts[] option array.
665 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800666const struct bond_option *bond_opt_get(unsigned int option)
Nikolay Aleksandrov09117362014-01-22 14:53:16 +0100667{
668 if (!BOND_OPT_VALID(option))
669 return NULL;
670
671 return &bond_opts[option];
672}
673
Nikolay Aleksandrovff11d8b2014-07-15 16:08:57 +0200674static int bond_option_mode_set(struct bonding *bond,
675 const struct bond_opt_value *newval)
Jiri Pirko72be35f2013-10-18 17:43:34 +0200676{
Veaceslav Falico267bed72014-05-15 21:39:53 +0200677 if (!bond_mode_uses_arp(newval->value) && bond->params.arp_interval) {
dingtianhongfe9d04a2013-11-22 22:28:43 +0800678 pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n",
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100679 bond->dev->name, newval->string);
dingtianhongfe9d04a2013-11-22 22:28:43 +0800680 /* disable arp monitoring */
681 bond->params.arp_interval = 0;
682 /* set miimon to default value */
683 bond->params.miimon = BOND_DEFAULT_MIIMON;
Joe Perches90194262014-02-15 16:01:45 -0800684 pr_info("%s: Setting MII monitoring interval to %d\n",
dingtianhongfe9d04a2013-11-22 22:28:43 +0800685 bond->dev->name, bond->params.miimon);
Jiri Pirko72be35f2013-10-18 17:43:34 +0200686 }
687
688 /* don't cache arp_validate between modes */
689 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100690 bond->params.mode = newval->value;
691
Jiri Pirko72be35f2013-10-18 17:43:34 +0200692 return 0;
693}
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200694
Jiri Pirko752d48b2013-10-18 17:43:37 +0200695static struct net_device *__bond_option_active_slave_get(struct bonding *bond,
696 struct slave *slave)
697{
Veaceslav Falicoec0865a2014-05-15 21:39:54 +0200698 return bond_uses_primary(bond) && slave ? slave->dev : NULL;
Jiri Pirko752d48b2013-10-18 17:43:37 +0200699}
700
701struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
702{
703 struct slave *slave = rcu_dereference(bond->curr_active_slave);
704
705 return __bond_option_active_slave_get(bond, slave);
706}
707
stephen hemmingerf3253332014-03-04 16:36:44 -0800708static int bond_option_active_slave_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800709 const struct bond_opt_value *newval)
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200710{
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100711 char ifname[IFNAMSIZ] = { 0, };
712 struct net_device *slave_dev;
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200713 int ret = 0;
714
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100715 sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */
716 if (!strlen(ifname) || newval->string[0] == '\n') {
717 slave_dev = NULL;
718 } else {
719 slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname);
720 if (!slave_dev)
721 return -ENODEV;
722 }
723
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200724 if (slave_dev) {
725 if (!netif_is_bond_slave(slave_dev)) {
Joe Perches90194262014-02-15 16:01:45 -0800726 pr_err("Device %s is not bonding slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200727 slave_dev->name);
728 return -EINVAL;
729 }
730
731 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) {
Joe Perches90194262014-02-15 16:01:45 -0800732 pr_err("%s: Device %s is not our slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200733 bond->dev->name, slave_dev->name);
734 return -EINVAL;
735 }
736 }
737
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200738 block_netpoll_tx();
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200739 write_lock_bh(&bond->curr_slave_lock);
740
741 /* check to see if we are clearing active */
742 if (!slave_dev) {
Joe Perches90194262014-02-15 16:01:45 -0800743 pr_info("%s: Clearing current active slave\n", bond->dev->name);
Monam Agarwal8800a242014-03-24 00:00:17 +0530744 RCU_INIT_POINTER(bond->curr_active_slave, NULL);
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200745 bond_select_active_slave(bond);
746 } else {
Eric Dumazet4740d632014-07-15 06:56:55 -0700747 struct slave *old_active = bond_deref_active_protected(bond);
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200748 struct slave *new_active = bond_slave_get_rtnl(slave_dev);
749
750 BUG_ON(!new_active);
751
752 if (new_active == old_active) {
753 /* do nothing */
Joe Perches90194262014-02-15 16:01:45 -0800754 pr_info("%s: %s is already the current active slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200755 bond->dev->name, new_active->dev->name);
756 } else {
757 if (old_active && (new_active->link == BOND_LINK_UP) &&
Veaceslav Falicob6adc612014-05-15 21:39:57 +0200758 bond_slave_is_up(new_active)) {
Joe Perches90194262014-02-15 16:01:45 -0800759 pr_info("%s: Setting %s as active slave\n",
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200760 bond->dev->name, new_active->dev->name);
761 bond_change_active_slave(bond, new_active);
762 } else {
Joe Perches90194262014-02-15 16:01:45 -0800763 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 +0200764 bond->dev->name, new_active->dev->name,
765 new_active->dev->name);
766 ret = -EINVAL;
767 }
768 }
769 }
770
771 write_unlock_bh(&bond->curr_slave_lock);
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200772 unblock_netpoll_tx();
Nikolay Aleksandrovd1fbd3e2014-01-22 14:53:35 +0100773
Jiri Pirkod9e32b22013-10-18 17:43:35 +0200774 return ret;
775}
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800776
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200777/* There are two tricky bits here. First, if MII monitoring is activated, then
778 * we must disable ARP monitoring. Second, if the timer isn't running, we must
779 * start it.
780 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800781static int bond_option_miimon_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800782 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800783{
Joe Perches90194262014-02-15 16:01:45 -0800784 pr_info("%s: Setting MII monitoring interval to %llu\n",
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100785 bond->dev->name, newval->value);
786 bond->params.miimon = newval->value;
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800787 if (bond->params.updelay)
Joe Perches90194262014-02-15 16:01:45 -0800788 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 -0800789 bond->dev->name,
790 bond->params.updelay * bond->params.miimon);
791 if (bond->params.downdelay)
Joe Perches90194262014-02-15 16:01:45 -0800792 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 -0800793 bond->dev->name,
794 bond->params.downdelay * bond->params.miimon);
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100795 if (newval->value && bond->params.arp_interval) {
Joe Perches90194262014-02-15 16:01:45 -0800796 pr_info("%s: MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n",
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800797 bond->dev->name);
798 bond->params.arp_interval = 0;
799 if (bond->params.arp_validate)
800 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
801 }
802 if (bond->dev->flags & IFF_UP) {
803 /* If the interface is up, we may need to fire off
804 * the MII timer. If the interface is down, the
805 * timer will get fired off when the open function
806 * is called.
807 */
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100808 if (!newval->value) {
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800809 cancel_delayed_work_sync(&bond->mii_work);
810 } else {
811 cancel_delayed_work_sync(&bond->arp_work);
812 queue_delayed_work(bond->wq, &bond->mii_work, 0);
813 }
814 }
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100815
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800816 return 0;
817}
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800818
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200819/* Set up and down delays. These must be multiples of the
820 * MII monitoring value, and are stored internally as the multiplier.
821 * Thus, we must translate to MS for the real world.
822 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800823static int bond_option_updelay_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800824 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800825{
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100826 int value = newval->value;
827
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100828 if (!bond->params.miimon) {
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800829 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
830 bond->dev->name);
831 return -EPERM;
832 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100833 if ((value % bond->params.miimon) != 0) {
834 pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
835 bond->dev->name, value,
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100836 bond->params.miimon,
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100837 (value / bond->params.miimon) *
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100838 bond->params.miimon);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800839 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100840 bond->params.updelay = value / bond->params.miimon;
Joe Perches90194262014-02-15 16:01:45 -0800841 pr_info("%s: Setting up delay to %d\n",
842 bond->dev->name, bond->params.updelay * bond->params.miimon);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800843
844 return 0;
845}
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800846
stephen hemmingerf3253332014-03-04 16:36:44 -0800847static int bond_option_downdelay_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800848 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800849{
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100850 int value = newval->value;
851
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100852 if (!bond->params.miimon) {
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800853 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
854 bond->dev->name);
855 return -EPERM;
856 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100857 if ((value % bond->params.miimon) != 0) {
858 pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
859 bond->dev->name, value,
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100860 bond->params.miimon,
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100861 (value / bond->params.miimon) *
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100862 bond->params.miimon);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800863 }
Nikolay Aleksandrov0681a282014-01-23 23:43:43 +0100864 bond->params.downdelay = value / bond->params.miimon;
Joe Perches90194262014-02-15 16:01:45 -0800865 pr_info("%s: Setting down delay to %d\n",
866 bond->dev->name, bond->params.downdelay * bond->params.miimon);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800867
868 return 0;
869}
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800870
stephen hemmingerf3253332014-03-04 16:36:44 -0800871static int bond_option_use_carrier_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800872 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800873{
Joe Perches90194262014-02-15 16:01:45 -0800874 pr_info("%s: Setting use_carrier to %llu\n",
Nikolay Aleksandrov0fff0602014-01-22 14:53:34 +0100875 bond->dev->name, newval->value);
876 bond->params.use_carrier = newval->value;
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800877
878 return 0;
879}
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800880
Nikolay Aleksandrovdc3e5d12014-05-08 14:23:54 +0200881/* There are two tricky bits here. First, if ARP monitoring is activated, then
882 * we must disable MII monitoring. Second, if the ARP timer isn't running,
883 * we must start it.
884 */
stephen hemmingerf3253332014-03-04 16:36:44 -0800885static int bond_option_arp_interval_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -0800886 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800887{
Joe Perches90194262014-02-15 16:01:45 -0800888 pr_info("%s: Setting ARP monitoring interval to %llu\n",
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100889 bond->dev->name, newval->value);
890 bond->params.arp_interval = newval->value;
891 if (newval->value) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800892 if (bond->params.miimon) {
Joe Perches90194262014-02-15 16:01:45 -0800893 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring\n",
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800894 bond->dev->name, bond->dev->name);
895 bond->params.miimon = 0;
896 }
897 if (!bond->params.arp_targets[0])
Joe Perches90194262014-02-15 16:01:45 -0800898 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 -0800899 bond->dev->name);
900 }
901 if (bond->dev->flags & IFF_UP) {
902 /* If the interface is up, we may need to fire off
903 * the ARP timer. If the interface is down, the
904 * timer will get fired off when the open function
905 * is called.
906 */
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100907 if (!newval->value) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800908 if (bond->params.arp_validate)
909 bond->recv_probe = NULL;
910 cancel_delayed_work_sync(&bond->arp_work);
911 } else {
912 /* arp_validate can be set only in active-backup mode */
Veaceslav Falico3fe68df2014-02-18 07:48:39 +0100913 bond->recv_probe = bond_arp_rcv;
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800914 cancel_delayed_work_sync(&bond->mii_work);
915 queue_delayed_work(bond->wq, &bond->arp_work, 0);
916 }
917 }
918
919 return 0;
920}
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800921
922static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
923 __be32 target,
924 unsigned long last_rx)
925{
926 __be32 *targets = bond->params.arp_targets;
927 struct list_head *iter;
928 struct slave *slave;
929
930 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
931 bond_for_each_slave(bond, slave, iter)
932 slave->target_last_arp_rx[slot] = last_rx;
933 targets[slot] = target;
934 }
935}
936
937static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
938{
939 __be32 *targets = bond->params.arp_targets;
940 int ind;
941
Veaceslav Falico2807a9f2014-05-15 21:39:56 +0200942 if (!bond_is_ip_target_ok(target)) {
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800943 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
944 bond->dev->name, &target);
945 return -EINVAL;
946 }
947
948 if (bond_get_targets_ip(targets, target) != -1) { /* dup */
949 pr_err("%s: ARP target %pI4 is already present\n",
950 bond->dev->name, &target);
951 return -EINVAL;
952 }
953
954 ind = bond_get_targets_ip(targets, 0); /* first free slot */
955 if (ind == -1) {
Joe Perches90194262014-02-15 16:01:45 -0800956 pr_err("%s: ARP target table is full!\n", bond->dev->name);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800957 return -EINVAL;
958 }
959
Joe Perches90194262014-02-15 16:01:45 -0800960 pr_info("%s: Adding ARP target %pI4\n", bond->dev->name, &target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800961
962 _bond_options_arp_ip_target_set(bond, ind, target, jiffies);
963
964 return 0;
965}
966
stephen hemmingerf3253332014-03-04 16:36:44 -0800967static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800968{
969 int ret;
970
971 /* not to race with bond_arp_rcv */
972 write_lock_bh(&bond->lock);
973 ret = _bond_option_arp_ip_target_add(bond, target);
974 write_unlock_bh(&bond->lock);
975
976 return ret;
977}
978
stephen hemmingerf3253332014-03-04 16:36:44 -0800979static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800980{
981 __be32 *targets = bond->params.arp_targets;
982 struct list_head *iter;
983 struct slave *slave;
984 unsigned long *targets_rx;
985 int ind, i;
986
Veaceslav Falico2807a9f2014-05-15 21:39:56 +0200987 if (!bond_is_ip_target_ok(target)) {
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800988 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
989 bond->dev->name, &target);
990 return -EINVAL;
991 }
992
993 ind = bond_get_targets_ip(targets, target);
994 if (ind == -1) {
Joe Perches90194262014-02-15 16:01:45 -0800995 pr_err("%s: unable to remove nonexistent ARP target %pI4\n",
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800996 bond->dev->name, &target);
997 return -EINVAL;
998 }
999
1000 if (ind == 0 && !targets[1] && bond->params.arp_interval)
Joe Perches90194262014-02-15 16:01:45 -08001001 pr_warn("%s: Removing last arp target with arp_interval on\n",
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001002 bond->dev->name);
1003
Joe Perches90194262014-02-15 16:01:45 -08001004 pr_info("%s: Removing ARP target %pI4\n", bond->dev->name, &target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001005
1006 /* not to race with bond_arp_rcv */
1007 write_lock_bh(&bond->lock);
1008
1009 bond_for_each_slave(bond, slave, iter) {
1010 targets_rx = slave->target_last_arp_rx;
1011 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
1012 targets_rx[i] = targets_rx[i+1];
1013 targets_rx[i] = 0;
1014 }
1015 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
1016 targets[i] = targets[i+1];
1017 targets[i] = 0;
1018
1019 write_unlock_bh(&bond->lock);
1020
1021 return 0;
1022}
1023
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001024void bond_option_arp_ip_targets_clear(struct bonding *bond)
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001025{
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001026 int i;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001027
1028 /* not to race with bond_arp_rcv */
1029 write_lock_bh(&bond->lock);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001030 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
1031 _bond_options_arp_ip_target_set(bond, i, 0, 0);
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001032 write_unlock_bh(&bond->lock);
1033}
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001034
stephen hemmingerf3253332014-03-04 16:36:44 -08001035static int bond_option_arp_ip_targets_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001036 const struct bond_opt_value *newval)
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001037{
1038 int ret = -EPERM;
1039 __be32 target;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001040
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +01001041 if (newval->string) {
1042 if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) {
1043 pr_err("%s: invalid ARP target %pI4 specified\n",
1044 bond->dev->name, &target);
1045 return ret;
1046 }
1047 if (newval->string[0] == '+')
1048 ret = bond_option_arp_ip_target_add(bond, target);
1049 else if (newval->string[0] == '-')
1050 ret = bond_option_arp_ip_target_rem(bond, target);
1051 else
Joe Perches90194262014-02-15 16:01:45 -08001052 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 +01001053 bond->dev->name);
1054 } else {
1055 target = newval->value;
1056 ret = bond_option_arp_ip_target_add(bond, target);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001057 }
1058
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -08001059 return ret;
1060}
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001061
stephen hemmingerf3253332014-03-04 16:36:44 -08001062static int bond_option_arp_validate_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001063 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001064{
Joe Perches90194262014-02-15 16:01:45 -08001065 pr_info("%s: Setting arp_validate to %s (%llu)\n",
Nikolay Aleksandrov16228882014-01-22 14:53:20 +01001066 bond->dev->name, newval->string, newval->value);
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001067
1068 if (bond->dev->flags & IFF_UP) {
Nikolay Aleksandrov16228882014-01-22 14:53:20 +01001069 if (!newval->value)
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001070 bond->recv_probe = NULL;
1071 else if (bond->params.arp_interval)
1072 bond->recv_probe = bond_arp_rcv;
1073 }
Nikolay Aleksandrov16228882014-01-22 14:53:20 +01001074 bond->params.arp_validate = newval->value;
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -08001075
1076 return 0;
1077}
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -08001078
stephen hemmingerf3253332014-03-04 16:36:44 -08001079static int bond_option_arp_all_targets_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001080 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -08001081{
Joe Perches90194262014-02-15 16:01:45 -08001082 pr_info("%s: Setting arp_all_targets to %s (%llu)\n",
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +01001083 bond->dev->name, newval->string, newval->value);
1084 bond->params.arp_all_targets = newval->value;
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -08001085
1086 return 0;
1087}
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001088
stephen hemmingerf3253332014-03-04 16:36:44 -08001089static int bond_option_primary_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001090 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001091{
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +01001092 char *p, *primary = newval->string;
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001093 struct list_head *iter;
1094 struct slave *slave;
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001095
1096 block_netpoll_tx();
1097 read_lock(&bond->lock);
1098 write_lock_bh(&bond->curr_slave_lock);
1099
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +01001100 p = strchr(primary, '\n');
1101 if (p)
1102 *p = '\0';
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001103 /* check to see if we are clearing primary */
1104 if (!strlen(primary)) {
Joe Perches90194262014-02-15 16:01:45 -08001105 pr_info("%s: Setting primary slave to None\n", bond->dev->name);
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001106 bond->primary_slave = NULL;
1107 memset(bond->params.primary, 0, sizeof(bond->params.primary));
1108 bond_select_active_slave(bond);
1109 goto out;
1110 }
1111
1112 bond_for_each_slave(bond, slave, iter) {
1113 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) {
Joe Perches90194262014-02-15 16:01:45 -08001114 pr_info("%s: Setting %s as primary slave\n",
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001115 bond->dev->name, slave->dev->name);
1116 bond->primary_slave = slave;
1117 strcpy(bond->params.primary, slave->dev->name);
1118 bond_select_active_slave(bond);
1119 goto out;
1120 }
1121 }
1122
dingtianhongc59ab672014-01-18 16:28:52 +08001123 if (bond->primary_slave) {
Joe Perches90194262014-02-15 16:01:45 -08001124 pr_info("%s: Setting primary slave to None\n", bond->dev->name);
dingtianhongc59ab672014-01-18 16:28:52 +08001125 bond->primary_slave = NULL;
1126 bond_select_active_slave(bond);
1127 }
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001128 strncpy(bond->params.primary, primary, IFNAMSIZ);
1129 bond->params.primary[IFNAMSIZ - 1] = 0;
1130
Joe Perches90194262014-02-15 16:01:45 -08001131 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 -08001132 bond->dev->name, primary, bond->dev->name);
1133
1134out:
1135 write_unlock_bh(&bond->curr_slave_lock);
1136 read_unlock(&bond->lock);
1137 unblock_netpoll_tx();
1138
Nikolay Aleksandrov180222f2014-01-22 14:53:32 +01001139 return 0;
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -08001140}
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -08001141
stephen hemmingerf3253332014-03-04 16:36:44 -08001142static int bond_option_primary_reselect_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001143 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -08001144{
Joe Perches90194262014-02-15 16:01:45 -08001145 pr_info("%s: Setting primary_reselect to %s (%llu)\n",
Nikolay Aleksandrov388d3a62014-01-22 14:53:33 +01001146 bond->dev->name, newval->string, newval->value);
1147 bond->params.primary_reselect = newval->value;
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -08001148
1149 block_netpoll_tx();
1150 write_lock_bh(&bond->curr_slave_lock);
1151 bond_select_active_slave(bond);
1152 write_unlock_bh(&bond->curr_slave_lock);
1153 unblock_netpoll_tx();
1154
1155 return 0;
1156}
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -08001157
stephen hemmingerf3253332014-03-04 16:36:44 -08001158static int bond_option_fail_over_mac_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001159 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -08001160{
Joe Perches90194262014-02-15 16:01:45 -08001161 pr_info("%s: Setting fail_over_mac to %s (%llu)\n",
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +01001162 bond->dev->name, newval->string, newval->value);
1163 bond->params.fail_over_mac = newval->value;
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -08001164
1165 return 0;
1166}
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -08001167
stephen hemmingerf3253332014-03-04 16:36:44 -08001168static int bond_option_xmit_hash_policy_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001169 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -08001170{
Joe Perches90194262014-02-15 16:01:45 -08001171 pr_info("%s: Setting xmit hash policy to %s (%llu)\n",
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +01001172 bond->dev->name, newval->string, newval->value);
1173 bond->params.xmit_policy = newval->value;
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -08001174
1175 return 0;
1176}
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -08001177
stephen hemmingerf3253332014-03-04 16:36:44 -08001178static int bond_option_resend_igmp_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001179 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -08001180{
Joe Perches90194262014-02-15 16:01:45 -08001181 pr_info("%s: Setting resend_igmp to %llu\n",
Nikolay Aleksandrov105c8fb2014-01-22 14:53:38 +01001182 bond->dev->name, newval->value);
1183 bond->params.resend_igmp = newval->value;
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -08001184
1185 return 0;
1186}
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -08001187
stephen hemmingerf3253332014-03-04 16:36:44 -08001188static int bond_option_num_peer_notif_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001189 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -08001190{
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +01001191 bond->params.num_peer_notif = newval->value;
1192
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -08001193 return 0;
1194}
sfeldma@cumulusnetworks.com1cc0b1e32013-12-17 21:30:16 -08001195
stephen hemmingerf3253332014-03-04 16:36:44 -08001196static int bond_option_all_slaves_active_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001197 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com1cc0b1e32013-12-17 21:30:16 -08001198{
1199 struct list_head *iter;
1200 struct slave *slave;
1201
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +01001202 if (newval->value == bond->params.all_slaves_active)
sfeldma@cumulusnetworks.com1cc0b1e32013-12-17 21:30:16 -08001203 return 0;
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +01001204 bond->params.all_slaves_active = newval->value;
sfeldma@cumulusnetworks.com1cc0b1e32013-12-17 21:30:16 -08001205 bond_for_each_slave(bond, slave, iter) {
1206 if (!bond_is_active_slave(slave)) {
Nikolay Aleksandrov3df01162014-01-22 14:53:37 +01001207 if (newval->value)
sfeldma@cumulusnetworks.com1cc0b1e32013-12-17 21:30:16 -08001208 slave->inactive = 0;
1209 else
1210 slave->inactive = 1;
1211 }
1212 }
1213
1214 return 0;
1215}
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001216
stephen hemmingerf3253332014-03-04 16:36:44 -08001217static int bond_option_min_links_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001218 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001219{
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +01001220 pr_info("%s: Setting min links value to %llu\n",
1221 bond->dev->name, newval->value);
1222 bond->params.min_links = newval->value;
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -08001223
1224 return 0;
1225}
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001226
stephen hemmingerf3253332014-03-04 16:36:44 -08001227static int bond_option_lp_interval_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001228 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001229{
Nikolay Aleksandrov4325b372014-01-22 14:53:39 +01001230 bond->params.lp_interval = newval->value;
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -08001231
1232 return 0;
1233}
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001234
stephen hemmingerf3253332014-03-04 16:36:44 -08001235static int bond_option_pps_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001236 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001237{
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001238 bond->params.packets_per_slave = newval->value;
1239 if (newval->value > 0) {
Hannes Frederic Sowa809fa972014-01-22 02:29:41 +01001240 bond->params.reciprocal_packets_per_slave =
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +01001241 reciprocal_value(newval->value);
Hannes Frederic Sowa809fa972014-01-22 02:29:41 +01001242 } else {
1243 /* reciprocal_packets_per_slave is unused if
1244 * packets_per_slave is 0 or 1, just initialize it
1245 */
1246 bond->params.reciprocal_packets_per_slave =
1247 (struct reciprocal_value) { 0 };
1248 }
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -08001249
1250 return 0;
1251}
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001252
stephen hemmingerf3253332014-03-04 16:36:44 -08001253static int bond_option_lacp_rate_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001254 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001255{
Joe Perches90194262014-02-15 16:01:45 -08001256 pr_info("%s: Setting LACP rate to %s (%llu)\n",
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +01001257 bond->dev->name, newval->string, newval->value);
1258 bond->params.lacp_fast = newval->value;
sfeldma@cumulusnetworks.com3243c472014-01-03 14:28:18 -08001259 bond_3ad_update_lacp_rate(bond);
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -08001260
1261 return 0;
1262}
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001263
stephen hemmingerf3253332014-03-04 16:36:44 -08001264static int bond_option_ad_select_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001265 const struct bond_opt_value *newval)
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001266{
Joe Perches90194262014-02-15 16:01:45 -08001267 pr_info("%s: Setting ad_select to %s (%llu)\n",
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +01001268 bond->dev->name, newval->string, newval->value);
1269 bond->params.ad_select = newval->value;
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -08001270
1271 return 0;
1272}
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001273
stephen hemmingerf3253332014-03-04 16:36:44 -08001274static int bond_option_queue_id_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001275 const struct bond_opt_value *newval)
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001276{
1277 struct slave *slave, *update_slave;
1278 struct net_device *sdev;
1279 struct list_head *iter;
1280 char *delim;
1281 int ret = 0;
1282 u16 qid;
1283
1284 /* delim will point to queue id if successful */
1285 delim = strchr(newval->string, ':');
1286 if (!delim)
1287 goto err_no_cmd;
1288
1289 /* Terminate string that points to device name and bump it
1290 * up one, so we can read the queue id there.
1291 */
1292 *delim = '\0';
1293 if (sscanf(++delim, "%hd\n", &qid) != 1)
1294 goto err_no_cmd;
1295
1296 /* Check buffer length, valid ifname and queue id */
dingtianhongc313c892014-02-12 14:58:50 +08001297 if (!dev_valid_name(newval->string) ||
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001298 qid > bond->dev->real_num_tx_queues)
1299 goto err_no_cmd;
1300
1301 /* Get the pointer to that interface if it exists */
1302 sdev = __dev_get_by_name(dev_net(bond->dev), newval->string);
1303 if (!sdev)
1304 goto err_no_cmd;
1305
1306 /* Search for thes slave and check for duplicate qids */
1307 update_slave = NULL;
1308 bond_for_each_slave(bond, slave, iter) {
1309 if (sdev == slave->dev)
1310 /* We don't need to check the matching
1311 * slave for dups, since we're overwriting it
1312 */
1313 update_slave = slave;
1314 else if (qid && qid == slave->queue_id) {
1315 goto err_no_cmd;
1316 }
1317 }
1318
1319 if (!update_slave)
1320 goto err_no_cmd;
1321
1322 /* Actually set the qids for the slave */
1323 update_slave->queue_id = qid;
1324
1325out:
1326 return ret;
1327
1328err_no_cmd:
Joe Perches90194262014-02-15 16:01:45 -08001329 pr_info("invalid input for queue_id set for %s\n", bond->dev->name);
Nikolay Aleksandrov24089ba2014-01-22 14:53:36 +01001330 ret = -EPERM;
1331 goto out;
1332
1333}
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001334
stephen hemmingerf3253332014-03-04 16:36:44 -08001335static int bond_option_slaves_set(struct bonding *bond,
stephen hemminger28f084c2014-03-06 14:20:17 -08001336 const struct bond_opt_value *newval)
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001337{
1338 char command[IFNAMSIZ + 1] = { 0, };
1339 struct net_device *dev;
1340 char *ifname;
1341 int ret;
1342
1343 sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/
1344 ifname = command + 1;
1345 if ((strlen(command) <= 1) ||
1346 !dev_valid_name(ifname))
1347 goto err_no_cmd;
1348
1349 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
1350 if (!dev) {
Joe Perches90194262014-02-15 16:01:45 -08001351 pr_info("%s: interface %s does not exist!\n",
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001352 bond->dev->name, ifname);
1353 ret = -ENODEV;
1354 goto out;
1355 }
1356
1357 switch (command[0]) {
1358 case '+':
Joe Perches90194262014-02-15 16:01:45 -08001359 pr_info("%s: Adding slave %s\n", bond->dev->name, dev->name);
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001360 ret = bond_enslave(bond->dev, dev);
1361 break;
1362
1363 case '-':
Joe Perches90194262014-02-15 16:01:45 -08001364 pr_info("%s: Removing slave %s\n", bond->dev->name, dev->name);
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001365 ret = bond_release(bond->dev, dev);
1366 break;
1367
1368 default:
1369 goto err_no_cmd;
1370 }
1371
1372out:
1373 return ret;
1374
1375err_no_cmd:
Joe Perches90194262014-02-15 16:01:45 -08001376 pr_err("no command found in slaves file for bond %s - use +ifname or -ifname\n",
Nikolay Aleksandrov0e2e5b62014-01-22 14:53:40 +01001377 bond->dev->name);
1378 ret = -EPERM;
1379 goto out;
1380}
Mahesh Bandeware9f0fb82014-04-22 16:30:22 -07001381
1382static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
1383 const struct bond_opt_value *newval)
1384{
1385 pr_info("%s: Setting dynamic-lb to %s (%llu)\n",
1386 bond->dev->name, newval->string, newval->value);
1387 bond->params.tlb_dynamic_lb = newval->value;
1388
1389 return 0;
1390}