Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/bond/bond_options.c - bonding options |
| 3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 5 | * |
| 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 Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 16 | #include <linux/netdevice.h> |
Mike Galbraith | eb2d4c6 | 2014-02-14 08:21:04 +0100 | [diff] [blame] | 17 | #include <linux/spinlock.h> |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 18 | #include <linux/rcupdate.h> |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 19 | #include <linux/ctype.h> |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 20 | #include <linux/inet.h> |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 21 | #include "bonding.h" |
| 22 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 23 | static int bond_option_active_slave_set(struct bonding *bond, |
| 24 | struct bond_opt_value *newval); |
| 25 | static int bond_option_miimon_set(struct bonding *bond, |
| 26 | struct bond_opt_value *newval); |
| 27 | static int bond_option_updelay_set(struct bonding *bond, |
| 28 | struct bond_opt_value *newval); |
| 29 | static int bond_option_downdelay_set(struct bonding *bond, |
| 30 | struct bond_opt_value *newval); |
| 31 | static int bond_option_use_carrier_set(struct bonding *bond, |
| 32 | struct bond_opt_value *newval); |
| 33 | static int bond_option_arp_interval_set(struct bonding *bond, |
| 34 | struct bond_opt_value *newval); |
| 35 | static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); |
| 36 | static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target); |
| 37 | static int bond_option_arp_ip_targets_set(struct bonding *bond, |
| 38 | struct bond_opt_value *newval); |
| 39 | static int bond_option_arp_validate_set(struct bonding *bond, |
| 40 | struct bond_opt_value *newval); |
| 41 | static int bond_option_arp_all_targets_set(struct bonding *bond, |
| 42 | struct bond_opt_value *newval); |
| 43 | static int bond_option_primary_set(struct bonding *bond, |
| 44 | struct bond_opt_value *newval); |
| 45 | static int bond_option_primary_reselect_set(struct bonding *bond, |
| 46 | struct bond_opt_value *newval); |
| 47 | static int bond_option_fail_over_mac_set(struct bonding *bond, |
| 48 | struct bond_opt_value *newval); |
| 49 | static int bond_option_xmit_hash_policy_set(struct bonding *bond, |
| 50 | struct bond_opt_value *newval); |
| 51 | static int bond_option_resend_igmp_set(struct bonding *bond, |
| 52 | struct bond_opt_value *newval); |
| 53 | static int bond_option_num_peer_notif_set(struct bonding *bond, |
| 54 | struct bond_opt_value *newval); |
| 55 | static int bond_option_all_slaves_active_set(struct bonding *bond, |
| 56 | struct bond_opt_value *newval); |
| 57 | static int bond_option_min_links_set(struct bonding *bond, |
| 58 | struct bond_opt_value *newval); |
| 59 | static int bond_option_lp_interval_set(struct bonding *bond, |
| 60 | struct bond_opt_value *newval); |
| 61 | static int bond_option_pps_set(struct bonding *bond, |
| 62 | struct bond_opt_value *newval); |
| 63 | static int bond_option_lacp_rate_set(struct bonding *bond, |
| 64 | struct bond_opt_value *newval); |
| 65 | static int bond_option_ad_select_set(struct bonding *bond, |
| 66 | struct bond_opt_value *newval); |
| 67 | static int bond_option_queue_id_set(struct bonding *bond, |
| 68 | struct bond_opt_value *newval); |
| 69 | static int bond_option_mode_set(struct bonding *bond, |
| 70 | struct bond_opt_value *newval); |
| 71 | static int bond_option_slaves_set(struct bonding *bond, |
| 72 | struct bond_opt_value *newval); |
| 73 | |
| 74 | |
| 75 | static const struct bond_opt_value bond_mode_tbl[] = { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 76 | { "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 hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 86 | static const struct bond_opt_value bond_pps_tbl[] = { |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 87 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 88 | { "maxval", USHRT_MAX, BOND_VALFLAG_MAX}, |
| 89 | { NULL, -1, 0}, |
| 90 | }; |
| 91 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 92 | static const struct bond_opt_value bond_xmit_hashtype_tbl[] = { |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 93 | { "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 hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 101 | static const struct bond_opt_value bond_arp_validate_tbl[] = { |
Veaceslav Falico | 896149f | 2014-02-18 07:48:40 +0100 | [diff] [blame] | 102 | { "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 Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 112 | static const struct bond_opt_value bond_arp_all_targets_tbl[] = { |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 113 | { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT}, |
| 114 | { "all", BOND_ARP_TARGETS_ALL, 0}, |
| 115 | { NULL, -1, 0}, |
| 116 | }; |
| 117 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 118 | static const struct bond_opt_value bond_fail_over_mac_tbl[] = { |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 119 | { "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 hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 125 | static const struct bond_opt_value bond_intmax_tbl[] = { |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 126 | { "off", 0, BOND_VALFLAG_DEFAULT}, |
| 127 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, |
| 128 | }; |
| 129 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 130 | static const struct bond_opt_value bond_lacp_rate_tbl[] = { |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 131 | { "slow", AD_LACP_SLOW, 0}, |
| 132 | { "fast", AD_LACP_FAST, 0}, |
| 133 | { NULL, -1, 0}, |
| 134 | }; |
| 135 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 136 | static const struct bond_opt_value bond_ad_select_tbl[] = { |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 137 | { "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 hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 143 | static const struct bond_opt_value bond_num_peer_notif_tbl[] = { |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 144 | { "off", 0, 0}, |
| 145 | { "maxval", 255, BOND_VALFLAG_MAX}, |
| 146 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 147 | { NULL, -1, 0} |
| 148 | }; |
| 149 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 150 | static const struct bond_opt_value bond_primary_reselect_tbl[] = { |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 151 | { "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 hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 157 | static const struct bond_opt_value bond_use_carrier_tbl[] = { |
Nikolay Aleksandrov | 0fff060 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 158 | { "off", 0, 0}, |
| 159 | { "on", 1, BOND_VALFLAG_DEFAULT}, |
| 160 | { NULL, -1, 0} |
| 161 | }; |
| 162 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 163 | static const struct bond_opt_value bond_all_slaves_active_tbl[] = { |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 164 | { "off", 0, BOND_VALFLAG_DEFAULT}, |
| 165 | { "on", 1, 0}, |
| 166 | { NULL, -1, 0} |
| 167 | }; |
| 168 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 169 | static const struct bond_opt_value bond_resend_igmp_tbl[] = { |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 170 | { "off", 0, 0}, |
| 171 | { "maxval", 255, BOND_VALFLAG_MAX}, |
| 172 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 173 | { NULL, -1, 0} |
| 174 | }; |
| 175 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 176 | static const struct bond_opt_value bond_lp_interval_tbl[] = { |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 177 | { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, |
| 178 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, |
| 179 | }; |
| 180 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 181 | static const struct bond_option bond_opts[] = { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 182 | [BOND_OPT_MODE] = { |
| 183 | .id = BOND_OPT_MODE, |
| 184 | .name = "mode", |
| 185 | .desc = "bond device mode", |
| 186 | .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN, |
| 187 | .values = bond_mode_tbl, |
| 188 | .set = bond_option_mode_set |
| 189 | }, |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 190 | [BOND_OPT_PACKETS_PER_SLAVE] = { |
| 191 | .id = BOND_OPT_PACKETS_PER_SLAVE, |
| 192 | .name = "packets_per_slave", |
| 193 | .desc = "Packets to send per slave in RR mode", |
| 194 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)), |
| 195 | .values = bond_pps_tbl, |
| 196 | .set = bond_option_pps_set |
| 197 | }, |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 198 | [BOND_OPT_XMIT_HASH] = { |
| 199 | .id = BOND_OPT_XMIT_HASH, |
| 200 | .name = "xmit_hash_policy", |
| 201 | .desc = "balance-xor and 802.3ad hashing method", |
| 202 | .values = bond_xmit_hashtype_tbl, |
| 203 | .set = bond_option_xmit_hash_policy_set |
| 204 | }, |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 205 | [BOND_OPT_ARP_VALIDATE] = { |
| 206 | .id = BOND_OPT_ARP_VALIDATE, |
| 207 | .name = "arp_validate", |
| 208 | .desc = "validate src/dst of ARP probes", |
Veaceslav Falico | 13ac34a | 2014-02-18 07:48:37 +0100 | [diff] [blame] | 209 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | |
| 210 | BIT(BOND_MODE_ALB), |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 211 | .values = bond_arp_validate_tbl, |
| 212 | .set = bond_option_arp_validate_set |
| 213 | }, |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 214 | [BOND_OPT_ARP_ALL_TARGETS] = { |
| 215 | .id = BOND_OPT_ARP_ALL_TARGETS, |
| 216 | .name = "arp_all_targets", |
| 217 | .desc = "fail on any/all arp targets timeout", |
| 218 | .values = bond_arp_all_targets_tbl, |
| 219 | .set = bond_option_arp_all_targets_set |
| 220 | }, |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 221 | [BOND_OPT_FAIL_OVER_MAC] = { |
| 222 | .id = BOND_OPT_FAIL_OVER_MAC, |
| 223 | .name = "fail_over_mac", |
| 224 | .desc = "For active-backup, do not set all slaves to the same MAC", |
| 225 | .flags = BOND_OPTFLAG_NOSLAVES, |
| 226 | .values = bond_fail_over_mac_tbl, |
| 227 | .set = bond_option_fail_over_mac_set |
| 228 | }, |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 229 | [BOND_OPT_ARP_INTERVAL] = { |
| 230 | .id = BOND_OPT_ARP_INTERVAL, |
| 231 | .name = "arp_interval", |
| 232 | .desc = "arp interval in milliseconds", |
| 233 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | |
| 234 | BIT(BOND_MODE_ALB), |
| 235 | .values = bond_intmax_tbl, |
| 236 | .set = bond_option_arp_interval_set |
| 237 | }, |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 238 | [BOND_OPT_ARP_TARGETS] = { |
| 239 | .id = BOND_OPT_ARP_TARGETS, |
| 240 | .name = "arp_ip_target", |
| 241 | .desc = "arp targets in n.n.n.n form", |
| 242 | .flags = BOND_OPTFLAG_RAWVAL, |
| 243 | .set = bond_option_arp_ip_targets_set |
| 244 | }, |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 245 | [BOND_OPT_DOWNDELAY] = { |
| 246 | .id = BOND_OPT_DOWNDELAY, |
| 247 | .name = "downdelay", |
| 248 | .desc = "Delay before considering link down, in milliseconds", |
| 249 | .values = bond_intmax_tbl, |
| 250 | .set = bond_option_downdelay_set |
| 251 | }, |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 252 | [BOND_OPT_UPDELAY] = { |
| 253 | .id = BOND_OPT_UPDELAY, |
| 254 | .name = "updelay", |
| 255 | .desc = "Delay before considering link up, in milliseconds", |
| 256 | .values = bond_intmax_tbl, |
| 257 | .set = bond_option_updelay_set |
| 258 | }, |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 259 | [BOND_OPT_LACP_RATE] = { |
| 260 | .id = BOND_OPT_LACP_RATE, |
| 261 | .name = "lacp_rate", |
| 262 | .desc = "LACPDU tx rate to request from 802.3ad partner", |
| 263 | .flags = BOND_OPTFLAG_IFDOWN, |
| 264 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), |
| 265 | .values = bond_lacp_rate_tbl, |
| 266 | .set = bond_option_lacp_rate_set |
| 267 | }, |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 268 | [BOND_OPT_MINLINKS] = { |
| 269 | .id = BOND_OPT_MINLINKS, |
| 270 | .name = "min_links", |
| 271 | .desc = "Minimum number of available links before turning on carrier", |
| 272 | .values = bond_intmax_tbl, |
| 273 | .set = bond_option_min_links_set |
| 274 | }, |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 275 | [BOND_OPT_AD_SELECT] = { |
| 276 | .id = BOND_OPT_AD_SELECT, |
| 277 | .name = "ad_select", |
| 278 | .desc = "803.ad aggregation selection logic", |
| 279 | .flags = BOND_OPTFLAG_IFDOWN, |
| 280 | .values = bond_ad_select_tbl, |
| 281 | .set = bond_option_ad_select_set |
| 282 | }, |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 283 | [BOND_OPT_NUM_PEER_NOTIF] = { |
| 284 | .id = BOND_OPT_NUM_PEER_NOTIF, |
| 285 | .name = "num_unsol_na", |
| 286 | .desc = "Number of peer notifications to send on failover event", |
| 287 | .values = bond_num_peer_notif_tbl, |
| 288 | .set = bond_option_num_peer_notif_set |
| 289 | }, |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 290 | [BOND_OPT_MIIMON] = { |
| 291 | .id = BOND_OPT_MIIMON, |
| 292 | .name = "miimon", |
| 293 | .desc = "Link check interval in milliseconds", |
| 294 | .values = bond_intmax_tbl, |
| 295 | .set = bond_option_miimon_set |
| 296 | }, |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 297 | [BOND_OPT_PRIMARY] = { |
| 298 | .id = BOND_OPT_PRIMARY, |
| 299 | .name = "primary", |
| 300 | .desc = "Primary network device to use", |
| 301 | .flags = BOND_OPTFLAG_RAWVAL, |
| 302 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | |
| 303 | BIT(BOND_MODE_TLB) | |
| 304 | BIT(BOND_MODE_ALB)), |
| 305 | .set = bond_option_primary_set |
| 306 | }, |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 307 | [BOND_OPT_PRIMARY_RESELECT] = { |
| 308 | .id = BOND_OPT_PRIMARY_RESELECT, |
| 309 | .name = "primary_reselect", |
| 310 | .desc = "Reselect primary slave once it comes up", |
| 311 | .values = bond_primary_reselect_tbl, |
| 312 | .set = bond_option_primary_reselect_set |
| 313 | }, |
Nikolay Aleksandrov | 0fff060 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 314 | [BOND_OPT_USE_CARRIER] = { |
| 315 | .id = BOND_OPT_USE_CARRIER, |
| 316 | .name = "use_carrier", |
| 317 | .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon", |
| 318 | .values = bond_use_carrier_tbl, |
| 319 | .set = bond_option_use_carrier_set |
| 320 | }, |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 321 | [BOND_OPT_ACTIVE_SLAVE] = { |
| 322 | .id = BOND_OPT_ACTIVE_SLAVE, |
| 323 | .name = "active_slave", |
| 324 | .desc = "Currently active slave", |
| 325 | .flags = BOND_OPTFLAG_RAWVAL, |
| 326 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | |
| 327 | BIT(BOND_MODE_TLB) | |
| 328 | BIT(BOND_MODE_ALB)), |
| 329 | .set = bond_option_active_slave_set |
| 330 | }, |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 331 | [BOND_OPT_QUEUE_ID] = { |
| 332 | .id = BOND_OPT_QUEUE_ID, |
| 333 | .name = "queue_id", |
| 334 | .desc = "Set queue id of a slave", |
| 335 | .flags = BOND_OPTFLAG_RAWVAL, |
| 336 | .set = bond_option_queue_id_set |
| 337 | }, |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 338 | [BOND_OPT_ALL_SLAVES_ACTIVE] = { |
| 339 | .id = BOND_OPT_ALL_SLAVES_ACTIVE, |
| 340 | .name = "all_slaves_active", |
| 341 | .desc = "Keep all frames received on an interface by setting active flag for all slaves", |
| 342 | .values = bond_all_slaves_active_tbl, |
| 343 | .set = bond_option_all_slaves_active_set |
| 344 | }, |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 345 | [BOND_OPT_RESEND_IGMP] = { |
| 346 | .id = BOND_OPT_RESEND_IGMP, |
| 347 | .name = "resend_igmp", |
| 348 | .desc = "Number of IGMP membership reports to send on link failure", |
| 349 | .values = bond_resend_igmp_tbl, |
| 350 | .set = bond_option_resend_igmp_set |
| 351 | }, |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 352 | [BOND_OPT_LP_INTERVAL] = { |
| 353 | .id = BOND_OPT_LP_INTERVAL, |
| 354 | .name = "lp_interval", |
| 355 | .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch", |
| 356 | .values = bond_lp_interval_tbl, |
| 357 | .set = bond_option_lp_interval_set |
| 358 | }, |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 359 | [BOND_OPT_SLAVES] = { |
| 360 | .id = BOND_OPT_SLAVES, |
| 361 | .name = "slaves", |
| 362 | .desc = "Slave membership management", |
| 363 | .flags = BOND_OPTFLAG_RAWVAL, |
| 364 | .set = bond_option_slaves_set |
| 365 | }, |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 366 | { } |
| 367 | }; |
| 368 | |
| 369 | /* Searches for a value in opt's values[] table */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 370 | const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 371 | { |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 372 | const struct bond_option *opt; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 373 | int i; |
| 374 | |
| 375 | opt = bond_opt_get(option); |
| 376 | if (WARN_ON(!opt)) |
| 377 | return NULL; |
| 378 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 379 | if (opt->values[i].value == val) |
| 380 | return &opt->values[i]; |
| 381 | |
| 382 | return NULL; |
| 383 | } |
| 384 | |
| 385 | /* Searches for a value in opt's values[] table which matches the flagmask */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 386 | static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt, |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 387 | u32 flagmask) |
| 388 | { |
| 389 | int i; |
| 390 | |
| 391 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 392 | if (opt->values[i].flags & flagmask) |
| 393 | return &opt->values[i]; |
| 394 | |
| 395 | return NULL; |
| 396 | } |
| 397 | |
| 398 | /* If maxval is missing then there's no range to check. In case minval is |
| 399 | * missing then it's considered to be 0. |
| 400 | */ |
| 401 | static bool bond_opt_check_range(const struct bond_option *opt, u64 val) |
| 402 | { |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 403 | const struct bond_opt_value *minval, *maxval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 404 | |
| 405 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 406 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 407 | if (!maxval || (minval && val < minval->value) || val > maxval->value) |
| 408 | return false; |
| 409 | |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * bond_opt_parse - parse option value |
| 415 | * @opt: the option to parse against |
| 416 | * @val: value to parse |
| 417 | * |
| 418 | * This function tries to extract the value from @val and check if it's |
| 419 | * a possible match for the option and returns NULL if a match isn't found, |
| 420 | * or the struct_opt_value that matched. It also strips the new line from |
| 421 | * @val->string if it's present. |
| 422 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 423 | const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, |
| 424 | struct bond_opt_value *val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 425 | { |
| 426 | char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 427 | const struct bond_opt_value *tbl; |
| 428 | const struct bond_opt_value *ret = NULL; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 429 | bool checkval; |
| 430 | int i, rv; |
| 431 | |
| 432 | /* No parsing if the option wants a raw val */ |
| 433 | if (opt->flags & BOND_OPTFLAG_RAWVAL) |
| 434 | return val; |
| 435 | |
| 436 | tbl = opt->values; |
| 437 | if (!tbl) |
| 438 | goto out; |
| 439 | |
| 440 | /* ULLONG_MAX is used to bypass string processing */ |
| 441 | checkval = val->value != ULLONG_MAX; |
| 442 | if (!checkval) { |
| 443 | if (!val->string) |
| 444 | goto out; |
| 445 | p = strchr(val->string, '\n'); |
| 446 | if (p) |
| 447 | *p = '\0'; |
| 448 | for (p = val->string; *p; p++) |
| 449 | if (!(isdigit(*p) || isspace(*p))) |
| 450 | break; |
| 451 | /* The following code extracts the string to match or the value |
| 452 | * and sets checkval appropriately |
| 453 | */ |
| 454 | if (*p) { |
| 455 | rv = sscanf(val->string, "%32s", valstr); |
| 456 | } else { |
| 457 | rv = sscanf(val->string, "%llu", &val->value); |
| 458 | checkval = true; |
| 459 | } |
| 460 | if (!rv) |
| 461 | goto out; |
| 462 | } |
| 463 | |
| 464 | for (i = 0; tbl[i].string; i++) { |
| 465 | /* Check for exact match */ |
| 466 | if (checkval) { |
| 467 | if (val->value == tbl[i].value) |
| 468 | ret = &tbl[i]; |
| 469 | } else { |
| 470 | if (!strcmp(valstr, "default") && |
| 471 | (tbl[i].flags & BOND_VALFLAG_DEFAULT)) |
| 472 | ret = &tbl[i]; |
| 473 | |
| 474 | if (!strcmp(valstr, tbl[i].string)) |
| 475 | ret = &tbl[i]; |
| 476 | } |
| 477 | /* Found an exact match */ |
| 478 | if (ret) |
| 479 | goto out; |
| 480 | } |
| 481 | /* Possible range match */ |
| 482 | if (checkval && bond_opt_check_range(opt, val->value)) |
| 483 | ret = val; |
| 484 | out: |
| 485 | return ret; |
| 486 | } |
| 487 | |
| 488 | /* Check opt's dependencies against bond mode and currently set options */ |
| 489 | static int bond_opt_check_deps(struct bonding *bond, |
| 490 | const struct bond_option *opt) |
| 491 | { |
| 492 | struct bond_params *params = &bond->params; |
| 493 | |
| 494 | if (test_bit(params->mode, &opt->unsuppmodes)) |
| 495 | return -EACCES; |
| 496 | if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) |
| 497 | return -ENOTEMPTY; |
| 498 | if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) |
| 499 | return -EBUSY; |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static void bond_opt_dep_print(struct bonding *bond, |
| 505 | const struct bond_option *opt) |
| 506 | { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 507 | struct bond_opt_value *modeval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 508 | struct bond_params *params; |
| 509 | |
| 510 | params = &bond->params; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 511 | modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 512 | if (test_bit(params->mode, &opt->unsuppmodes)) |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 513 | pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n", |
| 514 | bond->dev->name, opt->name, |
| 515 | modeval->string, modeval->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | static void bond_opt_error_interpret(struct bonding *bond, |
| 519 | const struct bond_option *opt, |
| 520 | int error, struct bond_opt_value *val) |
| 521 | { |
| 522 | struct bond_opt_value *minval, *maxval; |
| 523 | char *p; |
| 524 | |
| 525 | switch (error) { |
| 526 | case -EINVAL: |
| 527 | if (val) { |
| 528 | if (val->string) { |
| 529 | /* sometimes RAWVAL opts may have new lines */ |
| 530 | p = strchr(val->string, '\n'); |
| 531 | if (p) |
| 532 | *p = '\0'; |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 533 | pr_err("%s: option %s: invalid value (%s)\n", |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 534 | bond->dev->name, opt->name, val->string); |
| 535 | } else { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 536 | pr_err("%s: option %s: invalid value (%llu)\n", |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 537 | bond->dev->name, opt->name, val->value); |
| 538 | } |
| 539 | } |
| 540 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 541 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 542 | if (!maxval) |
| 543 | break; |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 544 | pr_err("%s: option %s: allowed values %llu - %llu\n", |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 545 | bond->dev->name, opt->name, minval ? minval->value : 0, |
| 546 | maxval->value); |
| 547 | break; |
| 548 | case -EACCES: |
| 549 | bond_opt_dep_print(bond, opt); |
| 550 | break; |
| 551 | case -ENOTEMPTY: |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 552 | pr_err("%s: option %s: unable to set because the bond device has slaves\n", |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 553 | bond->dev->name, opt->name); |
| 554 | break; |
| 555 | case -EBUSY: |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 556 | pr_err("%s: option %s: unable to set because the bond device is up\n", |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 557 | bond->dev->name, opt->name); |
| 558 | break; |
| 559 | default: |
| 560 | break; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * __bond_opt_set - set a bonding option |
| 566 | * @bond: target bond device |
| 567 | * @option: option to set |
| 568 | * @val: value to set it to |
| 569 | * |
| 570 | * This function is used to change the bond's option value, it can be |
| 571 | * used for both enabling/changing an option and for disabling it. RTNL lock |
| 572 | * must be obtained before calling this function. |
| 573 | */ |
| 574 | int __bond_opt_set(struct bonding *bond, |
| 575 | unsigned int option, struct bond_opt_value *val) |
| 576 | { |
| 577 | struct bond_opt_value *retval = NULL; |
| 578 | const struct bond_option *opt; |
| 579 | int ret = -ENOENT; |
| 580 | |
| 581 | ASSERT_RTNL(); |
| 582 | |
| 583 | opt = bond_opt_get(option); |
| 584 | if (WARN_ON(!val) || WARN_ON(!opt)) |
| 585 | goto out; |
| 586 | ret = bond_opt_check_deps(bond, opt); |
| 587 | if (ret) |
| 588 | goto out; |
| 589 | retval = bond_opt_parse(opt, val); |
| 590 | if (!retval) { |
| 591 | ret = -EINVAL; |
| 592 | goto out; |
| 593 | } |
| 594 | ret = opt->set(bond, retval); |
| 595 | out: |
| 596 | if (ret) |
| 597 | bond_opt_error_interpret(bond, opt, ret, val); |
| 598 | |
| 599 | return ret; |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set |
| 604 | * @bond: target bond device |
| 605 | * @option: option to set |
| 606 | * @buf: value to set it to |
| 607 | * |
| 608 | * This function tries to acquire RTNL without blocking and if successful |
| 609 | * calls __bond_opt_set. It is mainly used for sysfs option manipulation. |
| 610 | */ |
| 611 | int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) |
| 612 | { |
| 613 | struct bond_opt_value optval; |
| 614 | int ret; |
| 615 | |
| 616 | if (!rtnl_trylock()) |
| 617 | return restart_syscall(); |
| 618 | bond_opt_initstr(&optval, buf); |
| 619 | ret = __bond_opt_set(bond, option, &optval); |
| 620 | rtnl_unlock(); |
| 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * bond_opt_get - get a pointer to an option |
| 627 | * @option: option for which to return a pointer |
| 628 | * |
| 629 | * This function checks if option is valid and if so returns a pointer |
| 630 | * to its entry in the bond_opts[] option array. |
| 631 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 632 | const struct bond_option *bond_opt_get(unsigned int option) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 633 | { |
| 634 | if (!BOND_OPT_VALID(option)) |
| 635 | return NULL; |
| 636 | |
| 637 | return &bond_opts[option]; |
| 638 | } |
| 639 | |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 640 | int bond_option_mode_set(struct bonding *bond, struct bond_opt_value *newval) |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 641 | { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 642 | if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) { |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 643 | pr_info("%s: %s mode is incompatible with arp monitoring, start mii monitoring\n", |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 644 | bond->dev->name, newval->string); |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 645 | /* disable arp monitoring */ |
| 646 | bond->params.arp_interval = 0; |
| 647 | /* set miimon to default value */ |
| 648 | bond->params.miimon = BOND_DEFAULT_MIIMON; |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 649 | pr_info("%s: Setting MII monitoring interval to %d\n", |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 650 | bond->dev->name, bond->params.miimon); |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* don't cache arp_validate between modes */ |
| 654 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 655 | bond->params.mode = newval->value; |
| 656 | |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 657 | return 0; |
| 658 | } |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 659 | |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 660 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
| 661 | struct slave *slave) |
| 662 | { |
| 663 | return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL; |
| 664 | } |
| 665 | |
| 666 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) |
| 667 | { |
| 668 | struct slave *slave = rcu_dereference(bond->curr_active_slave); |
| 669 | |
| 670 | return __bond_option_active_slave_get(bond, slave); |
| 671 | } |
| 672 | |
| 673 | struct net_device *bond_option_active_slave_get(struct bonding *bond) |
| 674 | { |
| 675 | return __bond_option_active_slave_get(bond, bond->curr_active_slave); |
| 676 | } |
| 677 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 678 | static int bond_option_active_slave_set(struct bonding *bond, |
| 679 | struct bond_opt_value *newval) |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 680 | { |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 681 | char ifname[IFNAMSIZ] = { 0, }; |
| 682 | struct net_device *slave_dev; |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 683 | int ret = 0; |
| 684 | |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 685 | sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */ |
| 686 | if (!strlen(ifname) || newval->string[0] == '\n') { |
| 687 | slave_dev = NULL; |
| 688 | } else { |
| 689 | slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 690 | if (!slave_dev) |
| 691 | return -ENODEV; |
| 692 | } |
| 693 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 694 | if (slave_dev) { |
| 695 | if (!netif_is_bond_slave(slave_dev)) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 696 | pr_err("Device %s is not bonding slave\n", |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 697 | slave_dev->name); |
| 698 | return -EINVAL; |
| 699 | } |
| 700 | |
| 701 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 702 | pr_err("%s: Device %s is not our slave\n", |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 703 | bond->dev->name, slave_dev->name); |
| 704 | return -EINVAL; |
| 705 | } |
| 706 | } |
| 707 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 708 | block_netpoll_tx(); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 709 | write_lock_bh(&bond->curr_slave_lock); |
| 710 | |
| 711 | /* check to see if we are clearing active */ |
| 712 | if (!slave_dev) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 713 | pr_info("%s: Clearing current active slave\n", bond->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 714 | rcu_assign_pointer(bond->curr_active_slave, NULL); |
| 715 | bond_select_active_slave(bond); |
| 716 | } else { |
| 717 | struct slave *old_active = bond->curr_active_slave; |
| 718 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); |
| 719 | |
| 720 | BUG_ON(!new_active); |
| 721 | |
| 722 | if (new_active == old_active) { |
| 723 | /* do nothing */ |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 724 | pr_info("%s: %s is already the current active slave\n", |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 725 | bond->dev->name, new_active->dev->name); |
| 726 | } else { |
| 727 | if (old_active && (new_active->link == BOND_LINK_UP) && |
| 728 | IS_UP(new_active->dev)) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 729 | pr_info("%s: Setting %s as active slave\n", |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 730 | bond->dev->name, new_active->dev->name); |
| 731 | bond_change_active_slave(bond, new_active); |
| 732 | } else { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 733 | pr_err("%s: Could not set %s as active slave; either %s is down or the link is down\n", |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 734 | bond->dev->name, new_active->dev->name, |
| 735 | new_active->dev->name); |
| 736 | ret = -EINVAL; |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | write_unlock_bh(&bond->curr_slave_lock); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 742 | unblock_netpoll_tx(); |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 743 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 744 | return ret; |
| 745 | } |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 746 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 747 | static int bond_option_miimon_set(struct bonding *bond, |
| 748 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 749 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 750 | pr_info("%s: Setting MII monitoring interval to %llu\n", |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 751 | bond->dev->name, newval->value); |
| 752 | bond->params.miimon = newval->value; |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 753 | if (bond->params.updelay) |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 754 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value\n", |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 755 | bond->dev->name, |
| 756 | bond->params.updelay * bond->params.miimon); |
| 757 | if (bond->params.downdelay) |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 758 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n", |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 759 | bond->dev->name, |
| 760 | bond->params.downdelay * bond->params.miimon); |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 761 | if (newval->value && bond->params.arp_interval) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 762 | pr_info("%s: MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n", |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 763 | bond->dev->name); |
| 764 | bond->params.arp_interval = 0; |
| 765 | if (bond->params.arp_validate) |
| 766 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 767 | } |
| 768 | if (bond->dev->flags & IFF_UP) { |
| 769 | /* If the interface is up, we may need to fire off |
| 770 | * the MII timer. If the interface is down, the |
| 771 | * timer will get fired off when the open function |
| 772 | * is called. |
| 773 | */ |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 774 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 775 | cancel_delayed_work_sync(&bond->mii_work); |
| 776 | } else { |
| 777 | cancel_delayed_work_sync(&bond->arp_work); |
| 778 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
| 779 | } |
| 780 | } |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 781 | |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 782 | return 0; |
| 783 | } |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 784 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 785 | static int bond_option_updelay_set(struct bonding *bond, |
| 786 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 787 | { |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 788 | int value = newval->value; |
| 789 | |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 790 | if (!bond->params.miimon) { |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 791 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
| 792 | bond->dev->name); |
| 793 | return -EPERM; |
| 794 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 795 | if ((value % bond->params.miimon) != 0) { |
| 796 | pr_warn("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
| 797 | bond->dev->name, value, |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 798 | bond->params.miimon, |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 799 | (value / bond->params.miimon) * |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 800 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 801 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 802 | bond->params.updelay = value / bond->params.miimon; |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 803 | pr_info("%s: Setting up delay to %d\n", |
| 804 | bond->dev->name, bond->params.updelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 805 | |
| 806 | return 0; |
| 807 | } |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 808 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 809 | static int bond_option_downdelay_set(struct bonding *bond, |
| 810 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 811 | { |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 812 | int value = newval->value; |
| 813 | |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 814 | if (!bond->params.miimon) { |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 815 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
| 816 | bond->dev->name); |
| 817 | return -EPERM; |
| 818 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 819 | if ((value % bond->params.miimon) != 0) { |
| 820 | pr_warn("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
| 821 | bond->dev->name, value, |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 822 | bond->params.miimon, |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 823 | (value / bond->params.miimon) * |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 824 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 825 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 826 | bond->params.downdelay = value / bond->params.miimon; |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 827 | pr_info("%s: Setting down delay to %d\n", |
| 828 | bond->dev->name, bond->params.downdelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 829 | |
| 830 | return 0; |
| 831 | } |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 832 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 833 | static int bond_option_use_carrier_set(struct bonding *bond, |
| 834 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 835 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 836 | pr_info("%s: Setting use_carrier to %llu\n", |
Nikolay Aleksandrov | 0fff060 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 837 | bond->dev->name, newval->value); |
| 838 | bond->params.use_carrier = newval->value; |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 839 | |
| 840 | return 0; |
| 841 | } |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 842 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 843 | static int bond_option_arp_interval_set(struct bonding *bond, |
| 844 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 845 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 846 | pr_info("%s: Setting ARP monitoring interval to %llu\n", |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 847 | bond->dev->name, newval->value); |
| 848 | bond->params.arp_interval = newval->value; |
| 849 | if (newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 850 | if (bond->params.miimon) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 851 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring\n", |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 852 | bond->dev->name, bond->dev->name); |
| 853 | bond->params.miimon = 0; |
| 854 | } |
| 855 | if (!bond->params.arp_targets[0]) |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 856 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified\n", |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 857 | bond->dev->name); |
| 858 | } |
| 859 | if (bond->dev->flags & IFF_UP) { |
| 860 | /* If the interface is up, we may need to fire off |
| 861 | * the ARP timer. If the interface is down, the |
| 862 | * timer will get fired off when the open function |
| 863 | * is called. |
| 864 | */ |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 865 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 866 | if (bond->params.arp_validate) |
| 867 | bond->recv_probe = NULL; |
| 868 | cancel_delayed_work_sync(&bond->arp_work); |
| 869 | } else { |
| 870 | /* arp_validate can be set only in active-backup mode */ |
Veaceslav Falico | 3fe68df | 2014-02-18 07:48:39 +0100 | [diff] [blame] | 871 | bond->recv_probe = bond_arp_rcv; |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 872 | cancel_delayed_work_sync(&bond->mii_work); |
| 873 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | return 0; |
| 878 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 879 | |
| 880 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, |
| 881 | __be32 target, |
| 882 | unsigned long last_rx) |
| 883 | { |
| 884 | __be32 *targets = bond->params.arp_targets; |
| 885 | struct list_head *iter; |
| 886 | struct slave *slave; |
| 887 | |
| 888 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { |
| 889 | bond_for_each_slave(bond, slave, iter) |
| 890 | slave->target_last_arp_rx[slot] = last_rx; |
| 891 | targets[slot] = target; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
| 896 | { |
| 897 | __be32 *targets = bond->params.arp_targets; |
| 898 | int ind; |
| 899 | |
| 900 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { |
| 901 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
| 902 | bond->dev->name, &target); |
| 903 | return -EINVAL; |
| 904 | } |
| 905 | |
| 906 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ |
| 907 | pr_err("%s: ARP target %pI4 is already present\n", |
| 908 | bond->dev->name, &target); |
| 909 | return -EINVAL; |
| 910 | } |
| 911 | |
| 912 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 913 | if (ind == -1) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 914 | pr_err("%s: ARP target table is full!\n", bond->dev->name); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 915 | return -EINVAL; |
| 916 | } |
| 917 | |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 918 | pr_info("%s: Adding ARP target %pI4\n", bond->dev->name, &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 919 | |
| 920 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); |
| 921 | |
| 922 | return 0; |
| 923 | } |
| 924 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 925 | static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 926 | { |
| 927 | int ret; |
| 928 | |
| 929 | /* not to race with bond_arp_rcv */ |
| 930 | write_lock_bh(&bond->lock); |
| 931 | ret = _bond_option_arp_ip_target_add(bond, target); |
| 932 | write_unlock_bh(&bond->lock); |
| 933 | |
| 934 | return ret; |
| 935 | } |
| 936 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 937 | static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 938 | { |
| 939 | __be32 *targets = bond->params.arp_targets; |
| 940 | struct list_head *iter; |
| 941 | struct slave *slave; |
| 942 | unsigned long *targets_rx; |
| 943 | int ind, i; |
| 944 | |
| 945 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { |
| 946 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
| 947 | bond->dev->name, &target); |
| 948 | return -EINVAL; |
| 949 | } |
| 950 | |
| 951 | ind = bond_get_targets_ip(targets, target); |
| 952 | if (ind == -1) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 953 | pr_err("%s: unable to remove nonexistent ARP target %pI4\n", |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 954 | bond->dev->name, &target); |
| 955 | return -EINVAL; |
| 956 | } |
| 957 | |
| 958 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 959 | pr_warn("%s: Removing last arp target with arp_interval on\n", |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 960 | bond->dev->name); |
| 961 | |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 962 | pr_info("%s: Removing ARP target %pI4\n", bond->dev->name, &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 963 | |
| 964 | /* not to race with bond_arp_rcv */ |
| 965 | write_lock_bh(&bond->lock); |
| 966 | |
| 967 | bond_for_each_slave(bond, slave, iter) { |
| 968 | targets_rx = slave->target_last_arp_rx; |
| 969 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 970 | targets_rx[i] = targets_rx[i+1]; |
| 971 | targets_rx[i] = 0; |
| 972 | } |
| 973 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 974 | targets[i] = targets[i+1]; |
| 975 | targets[i] = 0; |
| 976 | |
| 977 | write_unlock_bh(&bond->lock); |
| 978 | |
| 979 | return 0; |
| 980 | } |
| 981 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 982 | void bond_option_arp_ip_targets_clear(struct bonding *bond) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 983 | { |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 984 | int i; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 985 | |
| 986 | /* not to race with bond_arp_rcv */ |
| 987 | write_lock_bh(&bond->lock); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 988 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) |
| 989 | _bond_options_arp_ip_target_set(bond, i, 0, 0); |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 990 | write_unlock_bh(&bond->lock); |
| 991 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 992 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 993 | static int bond_option_arp_ip_targets_set(struct bonding *bond, |
| 994 | struct bond_opt_value *newval) |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 995 | { |
| 996 | int ret = -EPERM; |
| 997 | __be32 target; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 998 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 999 | if (newval->string) { |
| 1000 | if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) { |
| 1001 | pr_err("%s: invalid ARP target %pI4 specified\n", |
| 1002 | bond->dev->name, &target); |
| 1003 | return ret; |
| 1004 | } |
| 1005 | if (newval->string[0] == '+') |
| 1006 | ret = bond_option_arp_ip_target_add(bond, target); |
| 1007 | else if (newval->string[0] == '-') |
| 1008 | ret = bond_option_arp_ip_target_rem(bond, target); |
| 1009 | else |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1010 | pr_err("no command found in arp_ip_targets file for bond %s - use +<addr> or -<addr>\n", |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1011 | bond->dev->name); |
| 1012 | } else { |
| 1013 | target = newval->value; |
| 1014 | ret = bond_option_arp_ip_target_add(bond, target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1015 | } |
| 1016 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1017 | return ret; |
| 1018 | } |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1019 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1020 | static int bond_option_arp_validate_set(struct bonding *bond, |
| 1021 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1022 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1023 | pr_info("%s: Setting arp_validate to %s (%llu)\n", |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1024 | bond->dev->name, newval->string, newval->value); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1025 | |
| 1026 | if (bond->dev->flags & IFF_UP) { |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1027 | if (!newval->value) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1028 | bond->recv_probe = NULL; |
| 1029 | else if (bond->params.arp_interval) |
| 1030 | bond->recv_probe = bond_arp_rcv; |
| 1031 | } |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1032 | bond->params.arp_validate = newval->value; |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1033 | |
| 1034 | return 0; |
| 1035 | } |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1036 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1037 | static int bond_option_arp_all_targets_set(struct bonding *bond, |
| 1038 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1039 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1040 | pr_info("%s: Setting arp_all_targets to %s (%llu)\n", |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 1041 | bond->dev->name, newval->string, newval->value); |
| 1042 | bond->params.arp_all_targets = newval->value; |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1043 | |
| 1044 | return 0; |
| 1045 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1046 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1047 | static int bond_option_primary_set(struct bonding *bond, |
| 1048 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1049 | { |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1050 | char *p, *primary = newval->string; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1051 | struct list_head *iter; |
| 1052 | struct slave *slave; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1053 | |
| 1054 | block_netpoll_tx(); |
| 1055 | read_lock(&bond->lock); |
| 1056 | write_lock_bh(&bond->curr_slave_lock); |
| 1057 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1058 | p = strchr(primary, '\n'); |
| 1059 | if (p) |
| 1060 | *p = '\0'; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1061 | /* check to see if we are clearing primary */ |
| 1062 | if (!strlen(primary)) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1063 | pr_info("%s: Setting primary slave to None\n", bond->dev->name); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1064 | bond->primary_slave = NULL; |
| 1065 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
| 1066 | bond_select_active_slave(bond); |
| 1067 | goto out; |
| 1068 | } |
| 1069 | |
| 1070 | bond_for_each_slave(bond, slave, iter) { |
| 1071 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1072 | pr_info("%s: Setting %s as primary slave\n", |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1073 | bond->dev->name, slave->dev->name); |
| 1074 | bond->primary_slave = slave; |
| 1075 | strcpy(bond->params.primary, slave->dev->name); |
| 1076 | bond_select_active_slave(bond); |
| 1077 | goto out; |
| 1078 | } |
| 1079 | } |
| 1080 | |
dingtianhong | c59ab67 | 2014-01-18 16:28:52 +0800 | [diff] [blame] | 1081 | if (bond->primary_slave) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1082 | pr_info("%s: Setting primary slave to None\n", bond->dev->name); |
dingtianhong | c59ab67 | 2014-01-18 16:28:52 +0800 | [diff] [blame] | 1083 | bond->primary_slave = NULL; |
| 1084 | bond_select_active_slave(bond); |
| 1085 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1086 | strncpy(bond->params.primary, primary, IFNAMSIZ); |
| 1087 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 1088 | |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1089 | pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet\n", |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1090 | bond->dev->name, primary, bond->dev->name); |
| 1091 | |
| 1092 | out: |
| 1093 | write_unlock_bh(&bond->curr_slave_lock); |
| 1094 | read_unlock(&bond->lock); |
| 1095 | unblock_netpoll_tx(); |
| 1096 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1097 | return 0; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1098 | } |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1099 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1100 | static int bond_option_primary_reselect_set(struct bonding *bond, |
| 1101 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1102 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1103 | pr_info("%s: Setting primary_reselect to %s (%llu)\n", |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 1104 | bond->dev->name, newval->string, newval->value); |
| 1105 | bond->params.primary_reselect = newval->value; |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1106 | |
| 1107 | block_netpoll_tx(); |
| 1108 | write_lock_bh(&bond->curr_slave_lock); |
| 1109 | bond_select_active_slave(bond); |
| 1110 | write_unlock_bh(&bond->curr_slave_lock); |
| 1111 | unblock_netpoll_tx(); |
| 1112 | |
| 1113 | return 0; |
| 1114 | } |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1115 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1116 | static int bond_option_fail_over_mac_set(struct bonding *bond, |
| 1117 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1118 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1119 | pr_info("%s: Setting fail_over_mac to %s (%llu)\n", |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 1120 | bond->dev->name, newval->string, newval->value); |
| 1121 | bond->params.fail_over_mac = newval->value; |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1122 | |
| 1123 | return 0; |
| 1124 | } |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1125 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1126 | static int bond_option_xmit_hash_policy_set(struct bonding *bond, |
| 1127 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1128 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1129 | pr_info("%s: Setting xmit hash policy to %s (%llu)\n", |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 1130 | bond->dev->name, newval->string, newval->value); |
| 1131 | bond->params.xmit_policy = newval->value; |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1132 | |
| 1133 | return 0; |
| 1134 | } |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1135 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1136 | static int bond_option_resend_igmp_set(struct bonding *bond, |
| 1137 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1138 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1139 | pr_info("%s: Setting resend_igmp to %llu\n", |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 1140 | bond->dev->name, newval->value); |
| 1141 | bond->params.resend_igmp = newval->value; |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1142 | |
| 1143 | return 0; |
| 1144 | } |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1145 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1146 | static int bond_option_num_peer_notif_set(struct bonding *bond, |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 1147 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1148 | { |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 1149 | bond->params.num_peer_notif = newval->value; |
| 1150 | |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1151 | return 0; |
| 1152 | } |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1153 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1154 | static int bond_option_all_slaves_active_set(struct bonding *bond, |
| 1155 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1156 | { |
| 1157 | struct list_head *iter; |
| 1158 | struct slave *slave; |
| 1159 | |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1160 | if (newval->value == bond->params.all_slaves_active) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1161 | return 0; |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1162 | bond->params.all_slaves_active = newval->value; |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1163 | bond_for_each_slave(bond, slave, iter) { |
| 1164 | if (!bond_is_active_slave(slave)) { |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1165 | if (newval->value) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1166 | slave->inactive = 0; |
| 1167 | else |
| 1168 | slave->inactive = 1; |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | return 0; |
| 1173 | } |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1174 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1175 | static int bond_option_min_links_set(struct bonding *bond, |
| 1176 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1177 | { |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 1178 | pr_info("%s: Setting min links value to %llu\n", |
| 1179 | bond->dev->name, newval->value); |
| 1180 | bond->params.min_links = newval->value; |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1181 | |
| 1182 | return 0; |
| 1183 | } |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1184 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1185 | static int bond_option_lp_interval_set(struct bonding *bond, |
| 1186 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1187 | { |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 1188 | bond->params.lp_interval = newval->value; |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1189 | |
| 1190 | return 0; |
| 1191 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1192 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1193 | static int bond_option_pps_set(struct bonding *bond, |
| 1194 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1195 | { |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1196 | bond->params.packets_per_slave = newval->value; |
| 1197 | if (newval->value > 0) { |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1198 | bond->params.reciprocal_packets_per_slave = |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1199 | reciprocal_value(newval->value); |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1200 | } else { |
| 1201 | /* reciprocal_packets_per_slave is unused if |
| 1202 | * packets_per_slave is 0 or 1, just initialize it |
| 1203 | */ |
| 1204 | bond->params.reciprocal_packets_per_slave = |
| 1205 | (struct reciprocal_value) { 0 }; |
| 1206 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1207 | |
| 1208 | return 0; |
| 1209 | } |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1210 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1211 | static int bond_option_lacp_rate_set(struct bonding *bond, |
| 1212 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1213 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1214 | pr_info("%s: Setting LACP rate to %s (%llu)\n", |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 1215 | bond->dev->name, newval->string, newval->value); |
| 1216 | bond->params.lacp_fast = newval->value; |
sfeldma@cumulusnetworks.com | 3243c47 | 2014-01-03 14:28:18 -0800 | [diff] [blame] | 1217 | bond_3ad_update_lacp_rate(bond); |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1218 | |
| 1219 | return 0; |
| 1220 | } |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1221 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1222 | static int bond_option_ad_select_set(struct bonding *bond, |
| 1223 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1224 | { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1225 | pr_info("%s: Setting ad_select to %s (%llu)\n", |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 1226 | bond->dev->name, newval->string, newval->value); |
| 1227 | bond->params.ad_select = newval->value; |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1228 | |
| 1229 | return 0; |
| 1230 | } |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1231 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1232 | static int bond_option_queue_id_set(struct bonding *bond, |
| 1233 | struct bond_opt_value *newval) |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1234 | { |
| 1235 | struct slave *slave, *update_slave; |
| 1236 | struct net_device *sdev; |
| 1237 | struct list_head *iter; |
| 1238 | char *delim; |
| 1239 | int ret = 0; |
| 1240 | u16 qid; |
| 1241 | |
| 1242 | /* delim will point to queue id if successful */ |
| 1243 | delim = strchr(newval->string, ':'); |
| 1244 | if (!delim) |
| 1245 | goto err_no_cmd; |
| 1246 | |
| 1247 | /* Terminate string that points to device name and bump it |
| 1248 | * up one, so we can read the queue id there. |
| 1249 | */ |
| 1250 | *delim = '\0'; |
| 1251 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1252 | goto err_no_cmd; |
| 1253 | |
| 1254 | /* Check buffer length, valid ifname and queue id */ |
dingtianhong | c313c89 | 2014-02-12 14:58:50 +0800 | [diff] [blame] | 1255 | if (!dev_valid_name(newval->string) || |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1256 | qid > bond->dev->real_num_tx_queues) |
| 1257 | goto err_no_cmd; |
| 1258 | |
| 1259 | /* Get the pointer to that interface if it exists */ |
| 1260 | sdev = __dev_get_by_name(dev_net(bond->dev), newval->string); |
| 1261 | if (!sdev) |
| 1262 | goto err_no_cmd; |
| 1263 | |
| 1264 | /* Search for thes slave and check for duplicate qids */ |
| 1265 | update_slave = NULL; |
| 1266 | bond_for_each_slave(bond, slave, iter) { |
| 1267 | if (sdev == slave->dev) |
| 1268 | /* We don't need to check the matching |
| 1269 | * slave for dups, since we're overwriting it |
| 1270 | */ |
| 1271 | update_slave = slave; |
| 1272 | else if (qid && qid == slave->queue_id) { |
| 1273 | goto err_no_cmd; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | if (!update_slave) |
| 1278 | goto err_no_cmd; |
| 1279 | |
| 1280 | /* Actually set the qids for the slave */ |
| 1281 | update_slave->queue_id = qid; |
| 1282 | |
| 1283 | out: |
| 1284 | return ret; |
| 1285 | |
| 1286 | err_no_cmd: |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1287 | pr_info("invalid input for queue_id set for %s\n", bond->dev->name); |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1288 | ret = -EPERM; |
| 1289 | goto out; |
| 1290 | |
| 1291 | } |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1292 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame^] | 1293 | static int bond_option_slaves_set(struct bonding *bond, |
| 1294 | struct bond_opt_value *newval) |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1295 | { |
| 1296 | char command[IFNAMSIZ + 1] = { 0, }; |
| 1297 | struct net_device *dev; |
| 1298 | char *ifname; |
| 1299 | int ret; |
| 1300 | |
| 1301 | sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/ |
| 1302 | ifname = command + 1; |
| 1303 | if ((strlen(command) <= 1) || |
| 1304 | !dev_valid_name(ifname)) |
| 1305 | goto err_no_cmd; |
| 1306 | |
| 1307 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 1308 | if (!dev) { |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1309 | pr_info("%s: interface %s does not exist!\n", |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1310 | bond->dev->name, ifname); |
| 1311 | ret = -ENODEV; |
| 1312 | goto out; |
| 1313 | } |
| 1314 | |
| 1315 | switch (command[0]) { |
| 1316 | case '+': |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1317 | pr_info("%s: Adding slave %s\n", bond->dev->name, dev->name); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1318 | ret = bond_enslave(bond->dev, dev); |
| 1319 | break; |
| 1320 | |
| 1321 | case '-': |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1322 | pr_info("%s: Removing slave %s\n", bond->dev->name, dev->name); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1323 | ret = bond_release(bond->dev, dev); |
| 1324 | break; |
| 1325 | |
| 1326 | default: |
| 1327 | goto err_no_cmd; |
| 1328 | } |
| 1329 | |
| 1330 | out: |
| 1331 | return ret; |
| 1332 | |
| 1333 | err_no_cmd: |
Joe Perches | 9019426 | 2014-02-15 16:01:45 -0800 | [diff] [blame] | 1334 | pr_err("no command found in slaves file for bond %s - use +ifname or -ifname\n", |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1335 | bond->dev->name); |
| 1336 | ret = -EPERM; |
| 1337 | goto out; |
| 1338 | } |