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