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