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> |
| 17 | #include <linux/rwlock.h> |
| 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 | |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 23 | static struct bond_opt_value bond_mode_tbl[] = { |
| 24 | { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT}, |
| 25 | { "active-backup", BOND_MODE_ACTIVEBACKUP, 0}, |
| 26 | { "balance-xor", BOND_MODE_XOR, 0}, |
| 27 | { "broadcast", BOND_MODE_BROADCAST, 0}, |
| 28 | { "802.3ad", BOND_MODE_8023AD, 0}, |
| 29 | { "balance-tlb", BOND_MODE_TLB, 0}, |
| 30 | { "balance-alb", BOND_MODE_ALB, 0}, |
| 31 | { NULL, -1, 0}, |
| 32 | }; |
| 33 | |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 34 | static struct bond_opt_value bond_pps_tbl[] = { |
| 35 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 36 | { "maxval", USHRT_MAX, BOND_VALFLAG_MAX}, |
| 37 | { NULL, -1, 0}, |
| 38 | }; |
| 39 | |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 40 | static struct bond_opt_value bond_xmit_hashtype_tbl[] = { |
| 41 | { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT}, |
| 42 | { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0}, |
| 43 | { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0}, |
| 44 | { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0}, |
| 45 | { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0}, |
| 46 | { NULL, -1, 0}, |
| 47 | }; |
| 48 | |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 49 | static struct bond_opt_value bond_arp_validate_tbl[] = { |
| 50 | { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT}, |
| 51 | { "active", BOND_ARP_VALIDATE_ACTIVE, 0}, |
| 52 | { "backup", BOND_ARP_VALIDATE_BACKUP, 0}, |
| 53 | { "all", BOND_ARP_VALIDATE_ALL, 0}, |
| 54 | { NULL, -1, 0}, |
| 55 | }; |
| 56 | |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 57 | static struct bond_opt_value bond_arp_all_targets_tbl[] = { |
| 58 | { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT}, |
| 59 | { "all", BOND_ARP_TARGETS_ALL, 0}, |
| 60 | { NULL, -1, 0}, |
| 61 | }; |
| 62 | |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 63 | static struct bond_opt_value bond_fail_over_mac_tbl[] = { |
| 64 | { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT}, |
| 65 | { "active", BOND_FOM_ACTIVE, 0}, |
| 66 | { "follow", BOND_FOM_FOLLOW, 0}, |
| 67 | { NULL, -1, 0}, |
| 68 | }; |
| 69 | |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 70 | static struct bond_opt_value bond_intmax_tbl[] = { |
| 71 | { "off", 0, BOND_VALFLAG_DEFAULT}, |
| 72 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, |
| 73 | }; |
| 74 | |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 75 | static struct bond_opt_value bond_lacp_rate_tbl[] = { |
| 76 | { "slow", AD_LACP_SLOW, 0}, |
| 77 | { "fast", AD_LACP_FAST, 0}, |
| 78 | { NULL, -1, 0}, |
| 79 | }; |
| 80 | |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 81 | static struct bond_opt_value bond_ad_select_tbl[] = { |
| 82 | { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT}, |
| 83 | { "bandwidth", BOND_AD_BANDWIDTH, 0}, |
| 84 | { "count", BOND_AD_COUNT, 0}, |
| 85 | { NULL, -1, 0}, |
| 86 | }; |
| 87 | |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 88 | static struct bond_opt_value bond_num_peer_notif_tbl[] = { |
| 89 | { "off", 0, 0}, |
| 90 | { "maxval", 255, BOND_VALFLAG_MAX}, |
| 91 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 92 | { NULL, -1, 0} |
| 93 | }; |
| 94 | |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 95 | static struct bond_option bond_opts[] = { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 96 | [BOND_OPT_MODE] = { |
| 97 | .id = BOND_OPT_MODE, |
| 98 | .name = "mode", |
| 99 | .desc = "bond device mode", |
| 100 | .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN, |
| 101 | .values = bond_mode_tbl, |
| 102 | .set = bond_option_mode_set |
| 103 | }, |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 104 | [BOND_OPT_PACKETS_PER_SLAVE] = { |
| 105 | .id = BOND_OPT_PACKETS_PER_SLAVE, |
| 106 | .name = "packets_per_slave", |
| 107 | .desc = "Packets to send per slave in RR mode", |
| 108 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)), |
| 109 | .values = bond_pps_tbl, |
| 110 | .set = bond_option_pps_set |
| 111 | }, |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 112 | [BOND_OPT_XMIT_HASH] = { |
| 113 | .id = BOND_OPT_XMIT_HASH, |
| 114 | .name = "xmit_hash_policy", |
| 115 | .desc = "balance-xor and 802.3ad hashing method", |
| 116 | .values = bond_xmit_hashtype_tbl, |
| 117 | .set = bond_option_xmit_hash_policy_set |
| 118 | }, |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 119 | [BOND_OPT_ARP_VALIDATE] = { |
| 120 | .id = BOND_OPT_ARP_VALIDATE, |
| 121 | .name = "arp_validate", |
| 122 | .desc = "validate src/dst of ARP probes", |
| 123 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP)), |
| 124 | .values = bond_arp_validate_tbl, |
| 125 | .set = bond_option_arp_validate_set |
| 126 | }, |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 127 | [BOND_OPT_ARP_ALL_TARGETS] = { |
| 128 | .id = BOND_OPT_ARP_ALL_TARGETS, |
| 129 | .name = "arp_all_targets", |
| 130 | .desc = "fail on any/all arp targets timeout", |
| 131 | .values = bond_arp_all_targets_tbl, |
| 132 | .set = bond_option_arp_all_targets_set |
| 133 | }, |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 134 | [BOND_OPT_FAIL_OVER_MAC] = { |
| 135 | .id = BOND_OPT_FAIL_OVER_MAC, |
| 136 | .name = "fail_over_mac", |
| 137 | .desc = "For active-backup, do not set all slaves to the same MAC", |
| 138 | .flags = BOND_OPTFLAG_NOSLAVES, |
| 139 | .values = bond_fail_over_mac_tbl, |
| 140 | .set = bond_option_fail_over_mac_set |
| 141 | }, |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 142 | [BOND_OPT_ARP_INTERVAL] = { |
| 143 | .id = BOND_OPT_ARP_INTERVAL, |
| 144 | .name = "arp_interval", |
| 145 | .desc = "arp interval in milliseconds", |
| 146 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | |
| 147 | BIT(BOND_MODE_ALB), |
| 148 | .values = bond_intmax_tbl, |
| 149 | .set = bond_option_arp_interval_set |
| 150 | }, |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 151 | [BOND_OPT_ARP_TARGETS] = { |
| 152 | .id = BOND_OPT_ARP_TARGETS, |
| 153 | .name = "arp_ip_target", |
| 154 | .desc = "arp targets in n.n.n.n form", |
| 155 | .flags = BOND_OPTFLAG_RAWVAL, |
| 156 | .set = bond_option_arp_ip_targets_set |
| 157 | }, |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 158 | [BOND_OPT_DOWNDELAY] = { |
| 159 | .id = BOND_OPT_DOWNDELAY, |
| 160 | .name = "downdelay", |
| 161 | .desc = "Delay before considering link down, in milliseconds", |
| 162 | .values = bond_intmax_tbl, |
| 163 | .set = bond_option_downdelay_set |
| 164 | }, |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 165 | [BOND_OPT_UPDELAY] = { |
| 166 | .id = BOND_OPT_UPDELAY, |
| 167 | .name = "updelay", |
| 168 | .desc = "Delay before considering link up, in milliseconds", |
| 169 | .values = bond_intmax_tbl, |
| 170 | .set = bond_option_updelay_set |
| 171 | }, |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 172 | [BOND_OPT_LACP_RATE] = { |
| 173 | .id = BOND_OPT_LACP_RATE, |
| 174 | .name = "lacp_rate", |
| 175 | .desc = "LACPDU tx rate to request from 802.3ad partner", |
| 176 | .flags = BOND_OPTFLAG_IFDOWN, |
| 177 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), |
| 178 | .values = bond_lacp_rate_tbl, |
| 179 | .set = bond_option_lacp_rate_set |
| 180 | }, |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 181 | [BOND_OPT_MINLINKS] = { |
| 182 | .id = BOND_OPT_MINLINKS, |
| 183 | .name = "min_links", |
| 184 | .desc = "Minimum number of available links before turning on carrier", |
| 185 | .values = bond_intmax_tbl, |
| 186 | .set = bond_option_min_links_set |
| 187 | }, |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 188 | [BOND_OPT_AD_SELECT] = { |
| 189 | .id = BOND_OPT_AD_SELECT, |
| 190 | .name = "ad_select", |
| 191 | .desc = "803.ad aggregation selection logic", |
| 192 | .flags = BOND_OPTFLAG_IFDOWN, |
| 193 | .values = bond_ad_select_tbl, |
| 194 | .set = bond_option_ad_select_set |
| 195 | }, |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 196 | [BOND_OPT_NUM_PEER_NOTIF] = { |
| 197 | .id = BOND_OPT_NUM_PEER_NOTIF, |
| 198 | .name = "num_unsol_na", |
| 199 | .desc = "Number of peer notifications to send on failover event", |
| 200 | .values = bond_num_peer_notif_tbl, |
| 201 | .set = bond_option_num_peer_notif_set |
| 202 | }, |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 203 | [BOND_OPT_MIIMON] = { |
| 204 | .id = BOND_OPT_MIIMON, |
| 205 | .name = "miimon", |
| 206 | .desc = "Link check interval in milliseconds", |
| 207 | .values = bond_intmax_tbl, |
| 208 | .set = bond_option_miimon_set |
| 209 | }, |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame^] | 210 | [BOND_OPT_PRIMARY] = { |
| 211 | .id = BOND_OPT_PRIMARY, |
| 212 | .name = "primary", |
| 213 | .desc = "Primary network device to use", |
| 214 | .flags = BOND_OPTFLAG_RAWVAL, |
| 215 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | |
| 216 | BIT(BOND_MODE_TLB) | |
| 217 | BIT(BOND_MODE_ALB)), |
| 218 | .set = bond_option_primary_set |
| 219 | }, |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 220 | { } |
| 221 | }; |
| 222 | |
| 223 | /* Searches for a value in opt's values[] table */ |
| 224 | struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) |
| 225 | { |
| 226 | struct bond_option *opt; |
| 227 | int i; |
| 228 | |
| 229 | opt = bond_opt_get(option); |
| 230 | if (WARN_ON(!opt)) |
| 231 | return NULL; |
| 232 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 233 | if (opt->values[i].value == val) |
| 234 | return &opt->values[i]; |
| 235 | |
| 236 | return NULL; |
| 237 | } |
| 238 | |
| 239 | /* Searches for a value in opt's values[] table which matches the flagmask */ |
| 240 | static struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt, |
| 241 | u32 flagmask) |
| 242 | { |
| 243 | int i; |
| 244 | |
| 245 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 246 | if (opt->values[i].flags & flagmask) |
| 247 | return &opt->values[i]; |
| 248 | |
| 249 | return NULL; |
| 250 | } |
| 251 | |
| 252 | /* If maxval is missing then there's no range to check. In case minval is |
| 253 | * missing then it's considered to be 0. |
| 254 | */ |
| 255 | static bool bond_opt_check_range(const struct bond_option *opt, u64 val) |
| 256 | { |
| 257 | struct bond_opt_value *minval, *maxval; |
| 258 | |
| 259 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 260 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 261 | if (!maxval || (minval && val < minval->value) || val > maxval->value) |
| 262 | return false; |
| 263 | |
| 264 | return true; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * bond_opt_parse - parse option value |
| 269 | * @opt: the option to parse against |
| 270 | * @val: value to parse |
| 271 | * |
| 272 | * This function tries to extract the value from @val and check if it's |
| 273 | * a possible match for the option and returns NULL if a match isn't found, |
| 274 | * or the struct_opt_value that matched. It also strips the new line from |
| 275 | * @val->string if it's present. |
| 276 | */ |
| 277 | struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, |
| 278 | struct bond_opt_value *val) |
| 279 | { |
| 280 | char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; |
| 281 | struct bond_opt_value *tbl, *ret = NULL; |
| 282 | bool checkval; |
| 283 | int i, rv; |
| 284 | |
| 285 | /* No parsing if the option wants a raw val */ |
| 286 | if (opt->flags & BOND_OPTFLAG_RAWVAL) |
| 287 | return val; |
| 288 | |
| 289 | tbl = opt->values; |
| 290 | if (!tbl) |
| 291 | goto out; |
| 292 | |
| 293 | /* ULLONG_MAX is used to bypass string processing */ |
| 294 | checkval = val->value != ULLONG_MAX; |
| 295 | if (!checkval) { |
| 296 | if (!val->string) |
| 297 | goto out; |
| 298 | p = strchr(val->string, '\n'); |
| 299 | if (p) |
| 300 | *p = '\0'; |
| 301 | for (p = val->string; *p; p++) |
| 302 | if (!(isdigit(*p) || isspace(*p))) |
| 303 | break; |
| 304 | /* The following code extracts the string to match or the value |
| 305 | * and sets checkval appropriately |
| 306 | */ |
| 307 | if (*p) { |
| 308 | rv = sscanf(val->string, "%32s", valstr); |
| 309 | } else { |
| 310 | rv = sscanf(val->string, "%llu", &val->value); |
| 311 | checkval = true; |
| 312 | } |
| 313 | if (!rv) |
| 314 | goto out; |
| 315 | } |
| 316 | |
| 317 | for (i = 0; tbl[i].string; i++) { |
| 318 | /* Check for exact match */ |
| 319 | if (checkval) { |
| 320 | if (val->value == tbl[i].value) |
| 321 | ret = &tbl[i]; |
| 322 | } else { |
| 323 | if (!strcmp(valstr, "default") && |
| 324 | (tbl[i].flags & BOND_VALFLAG_DEFAULT)) |
| 325 | ret = &tbl[i]; |
| 326 | |
| 327 | if (!strcmp(valstr, tbl[i].string)) |
| 328 | ret = &tbl[i]; |
| 329 | } |
| 330 | /* Found an exact match */ |
| 331 | if (ret) |
| 332 | goto out; |
| 333 | } |
| 334 | /* Possible range match */ |
| 335 | if (checkval && bond_opt_check_range(opt, val->value)) |
| 336 | ret = val; |
| 337 | out: |
| 338 | return ret; |
| 339 | } |
| 340 | |
| 341 | /* Check opt's dependencies against bond mode and currently set options */ |
| 342 | static int bond_opt_check_deps(struct bonding *bond, |
| 343 | const struct bond_option *opt) |
| 344 | { |
| 345 | struct bond_params *params = &bond->params; |
| 346 | |
| 347 | if (test_bit(params->mode, &opt->unsuppmodes)) |
| 348 | return -EACCES; |
| 349 | if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) |
| 350 | return -ENOTEMPTY; |
| 351 | if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) |
| 352 | return -EBUSY; |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static void bond_opt_dep_print(struct bonding *bond, |
| 358 | const struct bond_option *opt) |
| 359 | { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 360 | struct bond_opt_value *modeval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 361 | struct bond_params *params; |
| 362 | |
| 363 | params = &bond->params; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 364 | modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 365 | if (test_bit(params->mode, &opt->unsuppmodes)) |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 366 | pr_err("%s: option %s: mode dependency failed, not supported in mode %s(%llu)\n", |
| 367 | bond->dev->name, opt->name, |
| 368 | modeval->string, modeval->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static void bond_opt_error_interpret(struct bonding *bond, |
| 372 | const struct bond_option *opt, |
| 373 | int error, struct bond_opt_value *val) |
| 374 | { |
| 375 | struct bond_opt_value *minval, *maxval; |
| 376 | char *p; |
| 377 | |
| 378 | switch (error) { |
| 379 | case -EINVAL: |
| 380 | if (val) { |
| 381 | if (val->string) { |
| 382 | /* sometimes RAWVAL opts may have new lines */ |
| 383 | p = strchr(val->string, '\n'); |
| 384 | if (p) |
| 385 | *p = '\0'; |
| 386 | pr_err("%s: option %s: invalid value (%s).\n", |
| 387 | bond->dev->name, opt->name, val->string); |
| 388 | } else { |
| 389 | pr_err("%s: option %s: invalid value (%llu).\n", |
| 390 | bond->dev->name, opt->name, val->value); |
| 391 | } |
| 392 | } |
| 393 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 394 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 395 | if (!maxval) |
| 396 | break; |
| 397 | pr_err("%s: option %s: allowed values %llu - %llu.\n", |
| 398 | bond->dev->name, opt->name, minval ? minval->value : 0, |
| 399 | maxval->value); |
| 400 | break; |
| 401 | case -EACCES: |
| 402 | bond_opt_dep_print(bond, opt); |
| 403 | break; |
| 404 | case -ENOTEMPTY: |
| 405 | pr_err("%s: option %s: unable to set because the bond device has slaves.\n", |
| 406 | bond->dev->name, opt->name); |
| 407 | break; |
| 408 | case -EBUSY: |
| 409 | pr_err("%s: option %s: unable to set because the bond device is up.\n", |
| 410 | bond->dev->name, opt->name); |
| 411 | break; |
| 412 | default: |
| 413 | break; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * __bond_opt_set - set a bonding option |
| 419 | * @bond: target bond device |
| 420 | * @option: option to set |
| 421 | * @val: value to set it to |
| 422 | * |
| 423 | * This function is used to change the bond's option value, it can be |
| 424 | * used for both enabling/changing an option and for disabling it. RTNL lock |
| 425 | * must be obtained before calling this function. |
| 426 | */ |
| 427 | int __bond_opt_set(struct bonding *bond, |
| 428 | unsigned int option, struct bond_opt_value *val) |
| 429 | { |
| 430 | struct bond_opt_value *retval = NULL; |
| 431 | const struct bond_option *opt; |
| 432 | int ret = -ENOENT; |
| 433 | |
| 434 | ASSERT_RTNL(); |
| 435 | |
| 436 | opt = bond_opt_get(option); |
| 437 | if (WARN_ON(!val) || WARN_ON(!opt)) |
| 438 | goto out; |
| 439 | ret = bond_opt_check_deps(bond, opt); |
| 440 | if (ret) |
| 441 | goto out; |
| 442 | retval = bond_opt_parse(opt, val); |
| 443 | if (!retval) { |
| 444 | ret = -EINVAL; |
| 445 | goto out; |
| 446 | } |
| 447 | ret = opt->set(bond, retval); |
| 448 | out: |
| 449 | if (ret) |
| 450 | bond_opt_error_interpret(bond, opt, ret, val); |
| 451 | |
| 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set |
| 457 | * @bond: target bond device |
| 458 | * @option: option to set |
| 459 | * @buf: value to set it to |
| 460 | * |
| 461 | * This function tries to acquire RTNL without blocking and if successful |
| 462 | * calls __bond_opt_set. It is mainly used for sysfs option manipulation. |
| 463 | */ |
| 464 | int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) |
| 465 | { |
| 466 | struct bond_opt_value optval; |
| 467 | int ret; |
| 468 | |
| 469 | if (!rtnl_trylock()) |
| 470 | return restart_syscall(); |
| 471 | bond_opt_initstr(&optval, buf); |
| 472 | ret = __bond_opt_set(bond, option, &optval); |
| 473 | rtnl_unlock(); |
| 474 | |
| 475 | return ret; |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * bond_opt_get - get a pointer to an option |
| 480 | * @option: option for which to return a pointer |
| 481 | * |
| 482 | * This function checks if option is valid and if so returns a pointer |
| 483 | * to its entry in the bond_opts[] option array. |
| 484 | */ |
| 485 | struct bond_option *bond_opt_get(unsigned int option) |
| 486 | { |
| 487 | if (!BOND_OPT_VALID(option)) |
| 488 | return NULL; |
| 489 | |
| 490 | return &bond_opts[option]; |
| 491 | } |
| 492 | |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 493 | 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] | 494 | { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 495 | if (BOND_NO_USES_ARP(newval->value) && bond->params.arp_interval) { |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 496 | 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] | 497 | bond->dev->name, newval->string); |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 498 | /* disable arp monitoring */ |
| 499 | bond->params.arp_interval = 0; |
| 500 | /* set miimon to default value */ |
| 501 | bond->params.miimon = BOND_DEFAULT_MIIMON; |
| 502 | pr_info("%s: Setting MII monitoring interval to %d.\n", |
| 503 | bond->dev->name, bond->params.miimon); |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* don't cache arp_validate between modes */ |
| 507 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 508 | bond->params.mode = newval->value; |
| 509 | |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 510 | return 0; |
| 511 | } |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 512 | |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 513 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
| 514 | struct slave *slave) |
| 515 | { |
| 516 | return USES_PRIMARY(bond->params.mode) && slave ? slave->dev : NULL; |
| 517 | } |
| 518 | |
| 519 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) |
| 520 | { |
| 521 | struct slave *slave = rcu_dereference(bond->curr_active_slave); |
| 522 | |
| 523 | return __bond_option_active_slave_get(bond, slave); |
| 524 | } |
| 525 | |
| 526 | struct net_device *bond_option_active_slave_get(struct bonding *bond) |
| 527 | { |
| 528 | return __bond_option_active_slave_get(bond, bond->curr_active_slave); |
| 529 | } |
| 530 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 531 | int bond_option_active_slave_set(struct bonding *bond, |
| 532 | struct net_device *slave_dev) |
| 533 | { |
| 534 | int ret = 0; |
| 535 | |
| 536 | if (slave_dev) { |
| 537 | if (!netif_is_bond_slave(slave_dev)) { |
| 538 | pr_err("Device %s is not bonding slave.\n", |
| 539 | slave_dev->name); |
| 540 | return -EINVAL; |
| 541 | } |
| 542 | |
| 543 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { |
| 544 | pr_err("%s: Device %s is not our slave.\n", |
| 545 | bond->dev->name, slave_dev->name); |
| 546 | return -EINVAL; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | if (!USES_PRIMARY(bond->params.mode)) { |
| 551 | pr_err("%s: Unable to change active slave; %s is in mode %d\n", |
| 552 | bond->dev->name, bond->dev->name, bond->params.mode); |
| 553 | return -EINVAL; |
| 554 | } |
| 555 | |
| 556 | block_netpoll_tx(); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 557 | write_lock_bh(&bond->curr_slave_lock); |
| 558 | |
| 559 | /* check to see if we are clearing active */ |
| 560 | if (!slave_dev) { |
| 561 | pr_info("%s: Clearing current active slave.\n", |
| 562 | bond->dev->name); |
| 563 | rcu_assign_pointer(bond->curr_active_slave, NULL); |
| 564 | bond_select_active_slave(bond); |
| 565 | } else { |
| 566 | struct slave *old_active = bond->curr_active_slave; |
| 567 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); |
| 568 | |
| 569 | BUG_ON(!new_active); |
| 570 | |
| 571 | if (new_active == old_active) { |
| 572 | /* do nothing */ |
| 573 | pr_info("%s: %s is already the current active slave.\n", |
| 574 | bond->dev->name, new_active->dev->name); |
| 575 | } else { |
| 576 | if (old_active && (new_active->link == BOND_LINK_UP) && |
| 577 | IS_UP(new_active->dev)) { |
| 578 | pr_info("%s: Setting %s as active slave.\n", |
| 579 | bond->dev->name, new_active->dev->name); |
| 580 | bond_change_active_slave(bond, new_active); |
| 581 | } else { |
| 582 | pr_err("%s: Could not set %s as active slave; either %s is down or the link is down.\n", |
| 583 | bond->dev->name, new_active->dev->name, |
| 584 | new_active->dev->name); |
| 585 | ret = -EINVAL; |
| 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | write_unlock_bh(&bond->curr_slave_lock); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 591 | unblock_netpoll_tx(); |
| 592 | return ret; |
| 593 | } |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 594 | |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 595 | int bond_option_miimon_set(struct bonding *bond, struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 596 | { |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 597 | pr_info("%s: Setting MII monitoring interval to %llu.\n", |
| 598 | bond->dev->name, newval->value); |
| 599 | bond->params.miimon = newval->value; |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 600 | if (bond->params.updelay) |
| 601 | pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n", |
| 602 | bond->dev->name, |
| 603 | bond->params.updelay * bond->params.miimon); |
| 604 | if (bond->params.downdelay) |
| 605 | pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n", |
| 606 | bond->dev->name, |
| 607 | bond->params.downdelay * bond->params.miimon); |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 608 | if (newval->value && bond->params.arp_interval) { |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 609 | pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n", |
| 610 | bond->dev->name); |
| 611 | bond->params.arp_interval = 0; |
| 612 | if (bond->params.arp_validate) |
| 613 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 614 | } |
| 615 | if (bond->dev->flags & IFF_UP) { |
| 616 | /* If the interface is up, we may need to fire off |
| 617 | * the MII timer. If the interface is down, the |
| 618 | * timer will get fired off when the open function |
| 619 | * is called. |
| 620 | */ |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 621 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 622 | cancel_delayed_work_sync(&bond->mii_work); |
| 623 | } else { |
| 624 | cancel_delayed_work_sync(&bond->arp_work); |
| 625 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
| 626 | } |
| 627 | } |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 628 | |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 629 | return 0; |
| 630 | } |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 631 | |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 632 | int bond_option_updelay_set(struct bonding *bond, struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 633 | { |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 634 | if (!bond->params.miimon) { |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 635 | pr_err("%s: Unable to set up delay as MII monitoring is disabled\n", |
| 636 | bond->dev->name); |
| 637 | return -EPERM; |
| 638 | } |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 639 | if ((newval->value % bond->params.miimon) != 0) { |
| 640 | pr_warn("%s: Warning: up delay (%llu) is not a multiple of miimon (%d), updelay rounded to %llu ms\n", |
| 641 | bond->dev->name, newval->value, |
| 642 | bond->params.miimon, |
| 643 | (newval->value / bond->params.miimon) * |
| 644 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 645 | } |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 646 | bond->params.updelay = newval->value / bond->params.miimon; |
| 647 | pr_info("%s: Setting up delay to %d.\n", |
| 648 | bond->dev->name, |
| 649 | bond->params.updelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | } |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 653 | |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 654 | int bond_option_downdelay_set(struct bonding *bond, |
| 655 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 656 | { |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 657 | if (!bond->params.miimon) { |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 658 | pr_err("%s: Unable to set down delay as MII monitoring is disabled\n", |
| 659 | bond->dev->name); |
| 660 | return -EPERM; |
| 661 | } |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 662 | if ((newval->value % bond->params.miimon) != 0) { |
| 663 | pr_warn("%s: Warning: down delay (%llu) is not a multiple of miimon (%d), delay rounded to %llu ms\n", |
| 664 | bond->dev->name, newval->value, |
| 665 | bond->params.miimon, |
| 666 | (newval->value / bond->params.miimon) * |
| 667 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 668 | } |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 669 | bond->params.downdelay = newval->value / bond->params.miimon; |
| 670 | pr_info("%s: Setting down delay to %d.\n", |
| 671 | bond->dev->name, |
| 672 | bond->params.downdelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 673 | |
| 674 | return 0; |
| 675 | } |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 676 | |
| 677 | int bond_option_use_carrier_set(struct bonding *bond, int use_carrier) |
| 678 | { |
| 679 | if ((use_carrier == 0) || (use_carrier == 1)) { |
| 680 | bond->params.use_carrier = use_carrier; |
| 681 | pr_info("%s: Setting use_carrier to %d.\n", |
| 682 | bond->dev->name, use_carrier); |
| 683 | } else { |
| 684 | pr_info("%s: Ignoring invalid use_carrier value %d.\n", |
| 685 | bond->dev->name, use_carrier); |
| 686 | } |
| 687 | |
| 688 | return 0; |
| 689 | } |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 690 | |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 691 | int bond_option_arp_interval_set(struct bonding *bond, |
| 692 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 693 | { |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 694 | pr_info("%s: Setting ARP monitoring interval to %llu.\n", |
| 695 | bond->dev->name, newval->value); |
| 696 | bond->params.arp_interval = newval->value; |
| 697 | if (newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 698 | if (bond->params.miimon) { |
| 699 | pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n", |
| 700 | bond->dev->name, bond->dev->name); |
| 701 | bond->params.miimon = 0; |
| 702 | } |
| 703 | if (!bond->params.arp_targets[0]) |
| 704 | pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n", |
| 705 | bond->dev->name); |
| 706 | } |
| 707 | if (bond->dev->flags & IFF_UP) { |
| 708 | /* If the interface is up, we may need to fire off |
| 709 | * the ARP timer. If the interface is down, the |
| 710 | * timer will get fired off when the open function |
| 711 | * is called. |
| 712 | */ |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 713 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 714 | if (bond->params.arp_validate) |
| 715 | bond->recv_probe = NULL; |
| 716 | cancel_delayed_work_sync(&bond->arp_work); |
| 717 | } else { |
| 718 | /* arp_validate can be set only in active-backup mode */ |
| 719 | if (bond->params.arp_validate) |
| 720 | bond->recv_probe = bond_arp_rcv; |
| 721 | cancel_delayed_work_sync(&bond->mii_work); |
| 722 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | return 0; |
| 727 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 728 | |
| 729 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, |
| 730 | __be32 target, |
| 731 | unsigned long last_rx) |
| 732 | { |
| 733 | __be32 *targets = bond->params.arp_targets; |
| 734 | struct list_head *iter; |
| 735 | struct slave *slave; |
| 736 | |
| 737 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { |
| 738 | bond_for_each_slave(bond, slave, iter) |
| 739 | slave->target_last_arp_rx[slot] = last_rx; |
| 740 | targets[slot] = target; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
| 745 | { |
| 746 | __be32 *targets = bond->params.arp_targets; |
| 747 | int ind; |
| 748 | |
| 749 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { |
| 750 | pr_err("%s: invalid ARP target %pI4 specified for addition\n", |
| 751 | bond->dev->name, &target); |
| 752 | return -EINVAL; |
| 753 | } |
| 754 | |
| 755 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ |
| 756 | pr_err("%s: ARP target %pI4 is already present\n", |
| 757 | bond->dev->name, &target); |
| 758 | return -EINVAL; |
| 759 | } |
| 760 | |
| 761 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 762 | if (ind == -1) { |
| 763 | pr_err("%s: ARP target table is full!\n", |
| 764 | bond->dev->name); |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | |
| 768 | pr_info("%s: adding ARP target %pI4.\n", bond->dev->name, &target); |
| 769 | |
| 770 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
| 776 | { |
| 777 | int ret; |
| 778 | |
| 779 | /* not to race with bond_arp_rcv */ |
| 780 | write_lock_bh(&bond->lock); |
| 781 | ret = _bond_option_arp_ip_target_add(bond, target); |
| 782 | write_unlock_bh(&bond->lock); |
| 783 | |
| 784 | return ret; |
| 785 | } |
| 786 | |
| 787 | int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) |
| 788 | { |
| 789 | __be32 *targets = bond->params.arp_targets; |
| 790 | struct list_head *iter; |
| 791 | struct slave *slave; |
| 792 | unsigned long *targets_rx; |
| 793 | int ind, i; |
| 794 | |
| 795 | if (IS_IP_TARGET_UNUSABLE_ADDRESS(target)) { |
| 796 | pr_err("%s: invalid ARP target %pI4 specified for removal\n", |
| 797 | bond->dev->name, &target); |
| 798 | return -EINVAL; |
| 799 | } |
| 800 | |
| 801 | ind = bond_get_targets_ip(targets, target); |
| 802 | if (ind == -1) { |
| 803 | pr_err("%s: unable to remove nonexistent ARP target %pI4.\n", |
| 804 | bond->dev->name, &target); |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | |
| 808 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
| 809 | pr_warn("%s: removing last arp target with arp_interval on\n", |
| 810 | bond->dev->name); |
| 811 | |
| 812 | pr_info("%s: removing ARP target %pI4.\n", bond->dev->name, |
| 813 | &target); |
| 814 | |
| 815 | /* not to race with bond_arp_rcv */ |
| 816 | write_lock_bh(&bond->lock); |
| 817 | |
| 818 | bond_for_each_slave(bond, slave, iter) { |
| 819 | targets_rx = slave->target_last_arp_rx; |
| 820 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 821 | targets_rx[i] = targets_rx[i+1]; |
| 822 | targets_rx[i] = 0; |
| 823 | } |
| 824 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 825 | targets[i] = targets[i+1]; |
| 826 | targets[i] = 0; |
| 827 | |
| 828 | write_unlock_bh(&bond->lock); |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 833 | void bond_option_arp_ip_targets_clear(struct bonding *bond) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 834 | { |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 835 | int i; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 836 | |
| 837 | /* not to race with bond_arp_rcv */ |
| 838 | write_lock_bh(&bond->lock); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 839 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) |
| 840 | _bond_options_arp_ip_target_set(bond, i, 0, 0); |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 841 | write_unlock_bh(&bond->lock); |
| 842 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 843 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 844 | int bond_option_arp_ip_targets_set(struct bonding *bond, |
| 845 | struct bond_opt_value *newval) |
| 846 | { |
| 847 | int ret = -EPERM; |
| 848 | __be32 target; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 849 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 850 | if (newval->string) { |
| 851 | if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) { |
| 852 | pr_err("%s: invalid ARP target %pI4 specified\n", |
| 853 | bond->dev->name, &target); |
| 854 | return ret; |
| 855 | } |
| 856 | if (newval->string[0] == '+') |
| 857 | ret = bond_option_arp_ip_target_add(bond, target); |
| 858 | else if (newval->string[0] == '-') |
| 859 | ret = bond_option_arp_ip_target_rem(bond, target); |
| 860 | else |
| 861 | pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n", |
| 862 | bond->dev->name); |
| 863 | } else { |
| 864 | target = newval->value; |
| 865 | ret = bond_option_arp_ip_target_add(bond, target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 866 | } |
| 867 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 868 | return ret; |
| 869 | } |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 870 | |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 871 | int bond_option_arp_validate_set(struct bonding *bond, |
| 872 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 873 | { |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 874 | pr_info("%s: setting arp_validate to %s (%llu).\n", |
| 875 | bond->dev->name, newval->string, newval->value); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 876 | |
| 877 | if (bond->dev->flags & IFF_UP) { |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 878 | if (!newval->value) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 879 | bond->recv_probe = NULL; |
| 880 | else if (bond->params.arp_interval) |
| 881 | bond->recv_probe = bond_arp_rcv; |
| 882 | } |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 883 | bond->params.arp_validate = newval->value; |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 884 | |
| 885 | return 0; |
| 886 | } |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 887 | |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 888 | int bond_option_arp_all_targets_set(struct bonding *bond, |
| 889 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 890 | { |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 891 | pr_info("%s: setting arp_all_targets to %s (%llu).\n", |
| 892 | bond->dev->name, newval->string, newval->value); |
| 893 | bond->params.arp_all_targets = newval->value; |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 894 | |
| 895 | return 0; |
| 896 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 897 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame^] | 898 | int bond_option_primary_set(struct bonding *bond, struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 899 | { |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame^] | 900 | char *p, *primary = newval->string; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 901 | struct list_head *iter; |
| 902 | struct slave *slave; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 903 | |
| 904 | block_netpoll_tx(); |
| 905 | read_lock(&bond->lock); |
| 906 | write_lock_bh(&bond->curr_slave_lock); |
| 907 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame^] | 908 | p = strchr(primary, '\n'); |
| 909 | if (p) |
| 910 | *p = '\0'; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 911 | /* check to see if we are clearing primary */ |
| 912 | if (!strlen(primary)) { |
| 913 | pr_info("%s: Setting primary slave to None.\n", |
| 914 | bond->dev->name); |
| 915 | bond->primary_slave = NULL; |
| 916 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
| 917 | bond_select_active_slave(bond); |
| 918 | goto out; |
| 919 | } |
| 920 | |
| 921 | bond_for_each_slave(bond, slave, iter) { |
| 922 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { |
| 923 | pr_info("%s: Setting %s as primary slave.\n", |
| 924 | bond->dev->name, slave->dev->name); |
| 925 | bond->primary_slave = slave; |
| 926 | strcpy(bond->params.primary, slave->dev->name); |
| 927 | bond_select_active_slave(bond); |
| 928 | goto out; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | strncpy(bond->params.primary, primary, IFNAMSIZ); |
| 933 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 934 | |
| 935 | pr_info("%s: Recording %s as primary, but it has not been enslaved to %s yet.\n", |
| 936 | bond->dev->name, primary, bond->dev->name); |
| 937 | |
| 938 | out: |
| 939 | write_unlock_bh(&bond->curr_slave_lock); |
| 940 | read_unlock(&bond->lock); |
| 941 | unblock_netpoll_tx(); |
| 942 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame^] | 943 | return 0; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 944 | } |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 945 | |
| 946 | int bond_option_primary_reselect_set(struct bonding *bond, int primary_reselect) |
| 947 | { |
sfeldma@cumulusnetworks.com | 3243c47 | 2014-01-03 14:28:18 -0800 | [diff] [blame] | 948 | if (bond_parm_tbl_lookup(primary_reselect, pri_reselect_tbl) < 0) { |
| 949 | pr_err("%s: Ignoring invalid primary_reselect value %d.\n", |
| 950 | bond->dev->name, primary_reselect); |
| 951 | return -EINVAL; |
| 952 | } |
| 953 | |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 954 | bond->params.primary_reselect = primary_reselect; |
| 955 | pr_info("%s: setting primary_reselect to %s (%d).\n", |
| 956 | bond->dev->name, pri_reselect_tbl[primary_reselect].modename, |
| 957 | primary_reselect); |
| 958 | |
| 959 | block_netpoll_tx(); |
| 960 | write_lock_bh(&bond->curr_slave_lock); |
| 961 | bond_select_active_slave(bond); |
| 962 | write_unlock_bh(&bond->curr_slave_lock); |
| 963 | unblock_netpoll_tx(); |
| 964 | |
| 965 | return 0; |
| 966 | } |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 967 | |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 968 | int bond_option_fail_over_mac_set(struct bonding *bond, |
| 969 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 970 | { |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 971 | pr_info("%s: Setting fail_over_mac to %s (%llu).\n", |
| 972 | bond->dev->name, newval->string, newval->value); |
| 973 | bond->params.fail_over_mac = newval->value; |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 974 | |
| 975 | return 0; |
| 976 | } |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 977 | |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 978 | int bond_option_xmit_hash_policy_set(struct bonding *bond, |
| 979 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 980 | { |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 981 | pr_info("%s: setting xmit hash policy to %s (%llu).\n", |
| 982 | bond->dev->name, newval->string, newval->value); |
| 983 | bond->params.xmit_policy = newval->value; |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 984 | |
| 985 | return 0; |
| 986 | } |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 987 | |
| 988 | int bond_option_resend_igmp_set(struct bonding *bond, int resend_igmp) |
| 989 | { |
| 990 | if (resend_igmp < 0 || resend_igmp > 255) { |
| 991 | pr_err("%s: Invalid resend_igmp value %d not in range 0-255; rejected.\n", |
| 992 | bond->dev->name, resend_igmp); |
| 993 | return -EINVAL; |
| 994 | } |
| 995 | |
| 996 | bond->params.resend_igmp = resend_igmp; |
| 997 | pr_info("%s: Setting resend_igmp to %d.\n", |
| 998 | bond->dev->name, resend_igmp); |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1002 | |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 1003 | int bond_option_num_peer_notif_set(struct bonding *bond, |
| 1004 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1005 | { |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 1006 | bond->params.num_peer_notif = newval->value; |
| 1007 | |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1008 | return 0; |
| 1009 | } |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1010 | |
| 1011 | int bond_option_all_slaves_active_set(struct bonding *bond, |
| 1012 | int all_slaves_active) |
| 1013 | { |
| 1014 | struct list_head *iter; |
| 1015 | struct slave *slave; |
| 1016 | |
| 1017 | if (all_slaves_active == bond->params.all_slaves_active) |
| 1018 | return 0; |
| 1019 | |
| 1020 | if ((all_slaves_active == 0) || (all_slaves_active == 1)) { |
| 1021 | bond->params.all_slaves_active = all_slaves_active; |
| 1022 | } else { |
| 1023 | pr_info("%s: Ignoring invalid all_slaves_active value %d.\n", |
| 1024 | bond->dev->name, all_slaves_active); |
| 1025 | return -EINVAL; |
| 1026 | } |
| 1027 | |
| 1028 | bond_for_each_slave(bond, slave, iter) { |
| 1029 | if (!bond_is_active_slave(slave)) { |
| 1030 | if (all_slaves_active) |
| 1031 | slave->inactive = 0; |
| 1032 | else |
| 1033 | slave->inactive = 1; |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | return 0; |
| 1038 | } |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1039 | |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 1040 | int bond_option_min_links_set(struct bonding *bond, |
| 1041 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1042 | { |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 1043 | pr_info("%s: Setting min links value to %llu\n", |
| 1044 | bond->dev->name, newval->value); |
| 1045 | bond->params.min_links = newval->value; |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1046 | |
| 1047 | return 0; |
| 1048 | } |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1049 | |
| 1050 | int bond_option_lp_interval_set(struct bonding *bond, int lp_interval) |
| 1051 | { |
| 1052 | if (lp_interval <= 0) { |
| 1053 | pr_err("%s: lp_interval must be between 1 and %d\n", |
| 1054 | bond->dev->name, INT_MAX); |
| 1055 | return -EINVAL; |
| 1056 | } |
| 1057 | |
| 1058 | bond->params.lp_interval = lp_interval; |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1062 | |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1063 | int bond_option_pps_set(struct bonding *bond, struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1064 | { |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1065 | bond->params.packets_per_slave = newval->value; |
| 1066 | if (newval->value > 0) { |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1067 | bond->params.reciprocal_packets_per_slave = |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1068 | reciprocal_value(newval->value); |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1069 | } else { |
| 1070 | /* reciprocal_packets_per_slave is unused if |
| 1071 | * packets_per_slave is 0 or 1, just initialize it |
| 1072 | */ |
| 1073 | bond->params.reciprocal_packets_per_slave = |
| 1074 | (struct reciprocal_value) { 0 }; |
| 1075 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1076 | |
| 1077 | return 0; |
| 1078 | } |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1079 | |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 1080 | int bond_option_lacp_rate_set(struct bonding *bond, |
| 1081 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1082 | { |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 1083 | pr_info("%s: Setting LACP rate to %s (%llu).\n", |
| 1084 | bond->dev->name, newval->string, newval->value); |
| 1085 | bond->params.lacp_fast = newval->value; |
sfeldma@cumulusnetworks.com | 3243c47 | 2014-01-03 14:28:18 -0800 | [diff] [blame] | 1086 | bond_3ad_update_lacp_rate(bond); |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1087 | |
| 1088 | return 0; |
| 1089 | } |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1090 | |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 1091 | int bond_option_ad_select_set(struct bonding *bond, |
| 1092 | struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1093 | { |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 1094 | pr_info("%s: Setting ad_select to %s (%llu).\n", |
| 1095 | bond->dev->name, newval->string, newval->value); |
| 1096 | bond->params.ad_select = newval->value; |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1097 | |
| 1098 | return 0; |
| 1099 | } |