1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * drivers/net/bond/bond_options.c - bonding options 4 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> 5 * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> 6 */ 7 8 #include <linux/errno.h> 9 #include <linux/if.h> 10 #include <linux/netdevice.h> 11 #include <linux/spinlock.h> 12 #include <linux/rcupdate.h> 13 #include <linux/ctype.h> 14 #include <linux/inet.h> 15 #include <linux/sched/signal.h> 16 17 #include <net/bonding.h> 18 #include <net/ndisc.h> 19 20 static int bond_option_active_slave_set(struct bonding *bond, 21 const struct bond_opt_value *newval); 22 static int bond_option_miimon_set(struct bonding *bond, 23 const struct bond_opt_value *newval); 24 static int bond_option_updelay_set(struct bonding *bond, 25 const struct bond_opt_value *newval); 26 static int bond_option_downdelay_set(struct bonding *bond, 27 const struct bond_opt_value *newval); 28 static int bond_option_peer_notif_delay_set(struct bonding *bond, 29 const struct bond_opt_value *newval); 30 static int bond_option_use_carrier_set(struct bonding *bond, 31 const struct bond_opt_value *newval); 32 static int bond_option_arp_interval_set(struct bonding *bond, 33 const struct bond_opt_value *newval); 34 static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); 35 static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target); 36 static int bond_option_arp_ip_targets_set(struct bonding *bond, 37 const struct bond_opt_value *newval); 38 static int bond_option_ns_ip6_targets_set(struct bonding *bond, 39 const struct bond_opt_value *newval); 40 static int bond_option_arp_validate_set(struct bonding *bond, 41 const struct bond_opt_value *newval); 42 static int bond_option_arp_all_targets_set(struct bonding *bond, 43 const struct bond_opt_value *newval); 44 static int bond_option_prio_set(struct bonding *bond, 45 const struct bond_opt_value *newval); 46 static int bond_option_primary_set(struct bonding *bond, 47 const struct bond_opt_value *newval); 48 static int bond_option_primary_reselect_set(struct bonding *bond, 49 const struct bond_opt_value *newval); 50 static int bond_option_fail_over_mac_set(struct bonding *bond, 51 const struct bond_opt_value *newval); 52 static int bond_option_xmit_hash_policy_set(struct bonding *bond, 53 const struct bond_opt_value *newval); 54 static int bond_option_resend_igmp_set(struct bonding *bond, 55 const struct bond_opt_value *newval); 56 static int bond_option_num_peer_notif_set(struct bonding *bond, 57 const struct bond_opt_value *newval); 58 static int bond_option_all_slaves_active_set(struct bonding *bond, 59 const struct bond_opt_value *newval); 60 static int bond_option_min_links_set(struct bonding *bond, 61 const struct bond_opt_value *newval); 62 static int bond_option_lp_interval_set(struct bonding *bond, 63 const struct bond_opt_value *newval); 64 static int bond_option_pps_set(struct bonding *bond, 65 const struct bond_opt_value *newval); 66 static int bond_option_lacp_active_set(struct bonding *bond, 67 const struct bond_opt_value *newval); 68 static int bond_option_lacp_rate_set(struct bonding *bond, 69 const struct bond_opt_value *newval); 70 static int bond_option_ad_select_set(struct bonding *bond, 71 const struct bond_opt_value *newval); 72 static int bond_option_queue_id_set(struct bonding *bond, 73 const struct bond_opt_value *newval); 74 static int bond_option_mode_set(struct bonding *bond, 75 const struct bond_opt_value *newval); 76 static int bond_option_slaves_set(struct bonding *bond, 77 const struct bond_opt_value *newval); 78 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, 79 const struct bond_opt_value *newval); 80 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond, 81 const struct bond_opt_value *newval); 82 static int bond_option_actor_port_prio_set(struct bonding *bond, 83 const struct bond_opt_value *newval); 84 static int bond_option_ad_actor_system_set(struct bonding *bond, 85 const struct bond_opt_value *newval); 86 static int bond_option_ad_user_port_key_set(struct bonding *bond, 87 const struct bond_opt_value *newval); 88 static int bond_option_missed_max_set(struct bonding *bond, 89 const struct bond_opt_value *newval); 90 static int bond_option_coupled_control_set(struct bonding *bond, 91 const struct bond_opt_value *newval); 92 static int bond_option_broadcast_neigh_set(struct bonding *bond, 93 const struct bond_opt_value *newval); 94 95 static const struct bond_opt_value bond_mode_tbl[] = { 96 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT}, 97 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0}, 98 { "balance-xor", BOND_MODE_XOR, 0}, 99 { "broadcast", BOND_MODE_BROADCAST, 0}, 100 { "802.3ad", BOND_MODE_8023AD, 0}, 101 { "balance-tlb", BOND_MODE_TLB, 0}, 102 { "balance-alb", BOND_MODE_ALB, 0}, 103 { NULL, -1, 0}, 104 }; 105 106 static const struct bond_opt_value bond_pps_tbl[] = { 107 { "default", 1, BOND_VALFLAG_DEFAULT}, 108 { "maxval", USHRT_MAX, BOND_VALFLAG_MAX}, 109 { NULL, -1, 0}, 110 }; 111 112 static const struct bond_opt_value bond_xmit_hashtype_tbl[] = { 113 { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT}, 114 { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0}, 115 { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0}, 116 { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0}, 117 { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0}, 118 { "vlan+srcmac", BOND_XMIT_POLICY_VLAN_SRCMAC, 0}, 119 { NULL, -1, 0}, 120 }; 121 122 static const struct bond_opt_value bond_arp_validate_tbl[] = { 123 { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT}, 124 { "active", BOND_ARP_VALIDATE_ACTIVE, 0}, 125 { "backup", BOND_ARP_VALIDATE_BACKUP, 0}, 126 { "all", BOND_ARP_VALIDATE_ALL, 0}, 127 { "filter", BOND_ARP_FILTER, 0}, 128 { "filter_active", BOND_ARP_FILTER_ACTIVE, 0}, 129 { "filter_backup", BOND_ARP_FILTER_BACKUP, 0}, 130 { NULL, -1, 0}, 131 }; 132 133 static const struct bond_opt_value bond_arp_all_targets_tbl[] = { 134 { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT}, 135 { "all", BOND_ARP_TARGETS_ALL, 0}, 136 { NULL, -1, 0}, 137 }; 138 139 static const struct bond_opt_value bond_fail_over_mac_tbl[] = { 140 { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT}, 141 { "active", BOND_FOM_ACTIVE, 0}, 142 { "follow", BOND_FOM_FOLLOW, 0}, 143 { NULL, -1, 0}, 144 }; 145 146 static const struct bond_opt_value bond_intmax_tbl[] = { 147 { "off", 0, BOND_VALFLAG_DEFAULT}, 148 { "maxval", INT_MAX, BOND_VALFLAG_MAX}, 149 { NULL, -1, 0} 150 }; 151 152 static const struct bond_opt_value bond_lacp_active[] = { 153 { "off", 0, 0}, 154 { "on", 1, BOND_VALFLAG_DEFAULT}, 155 { NULL, -1, 0} 156 }; 157 158 static const struct bond_opt_value bond_lacp_rate_tbl[] = { 159 { "slow", AD_LACP_SLOW, 0}, 160 { "fast", AD_LACP_FAST, 0}, 161 { NULL, -1, 0}, 162 }; 163 164 static const struct bond_opt_value bond_ad_select_tbl[] = { 165 { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT}, 166 { "bandwidth", BOND_AD_BANDWIDTH, 0}, 167 { "count", BOND_AD_COUNT, 0}, 168 { "actor_port_prio", BOND_AD_PRIO, 0}, 169 { NULL, -1, 0}, 170 }; 171 172 static const struct bond_opt_value bond_num_peer_notif_tbl[] = { 173 { "off", 0, 0}, 174 { "maxval", 255, BOND_VALFLAG_MAX}, 175 { "default", 1, BOND_VALFLAG_DEFAULT}, 176 { NULL, -1, 0} 177 }; 178 179 static const struct bond_opt_value bond_peer_notif_delay_tbl[] = { 180 { "off", 0, 0}, 181 { "maxval", 300000, BOND_VALFLAG_MAX}, 182 { NULL, -1, 0} 183 }; 184 185 static const struct bond_opt_value bond_primary_reselect_tbl[] = { 186 { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT}, 187 { "better", BOND_PRI_RESELECT_BETTER, 0}, 188 { "failure", BOND_PRI_RESELECT_FAILURE, 0}, 189 { NULL, -1}, 190 }; 191 192 static const struct bond_opt_value bond_use_carrier_tbl[] = { 193 { "on", 1, BOND_VALFLAG_DEFAULT}, 194 { NULL, -1, 0} 195 }; 196 197 static const struct bond_opt_value bond_all_slaves_active_tbl[] = { 198 { "off", 0, BOND_VALFLAG_DEFAULT}, 199 { "on", 1, 0}, 200 { NULL, -1, 0} 201 }; 202 203 static const struct bond_opt_value bond_resend_igmp_tbl[] = { 204 { "off", 0, 0}, 205 { "maxval", 255, BOND_VALFLAG_MAX}, 206 { "default", 1, BOND_VALFLAG_DEFAULT}, 207 { NULL, -1, 0} 208 }; 209 210 static const struct bond_opt_value bond_lp_interval_tbl[] = { 211 { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, 212 { "maxval", INT_MAX, BOND_VALFLAG_MAX}, 213 { NULL, -1, 0}, 214 }; 215 216 static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = { 217 { "off", 0, 0}, 218 { "on", 1, BOND_VALFLAG_DEFAULT}, 219 { NULL, -1, 0} 220 }; 221 222 static const struct bond_opt_value bond_ad_actor_sys_prio_tbl[] = { 223 { "minval", 1, BOND_VALFLAG_MIN}, 224 { "maxval", 65535, BOND_VALFLAG_MAX | BOND_VALFLAG_DEFAULT}, 225 { NULL, -1, 0}, 226 }; 227 228 static const struct bond_opt_value bond_actor_port_prio_tbl[] = { 229 { "minval", 0, BOND_VALFLAG_MIN}, 230 { "maxval", 65535, BOND_VALFLAG_MAX}, 231 { "default", 255, BOND_VALFLAG_DEFAULT}, 232 { NULL, -1, 0}, 233 }; 234 235 static const struct bond_opt_value bond_ad_user_port_key_tbl[] = { 236 { "minval", 0, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, 237 { "maxval", 1023, BOND_VALFLAG_MAX}, 238 { NULL, -1, 0}, 239 }; 240 241 static const struct bond_opt_value bond_missed_max_tbl[] = { 242 { "minval", 1, BOND_VALFLAG_MIN}, 243 { "maxval", 255, BOND_VALFLAG_MAX}, 244 { "default", 2, BOND_VALFLAG_DEFAULT}, 245 { NULL, -1, 0}, 246 }; 247 248 static const struct bond_opt_value bond_coupled_control_tbl[] = { 249 { "on", 1, BOND_VALFLAG_DEFAULT}, 250 { "off", 0, 0}, 251 { NULL, -1, 0}, 252 }; 253 254 static const struct bond_opt_value bond_broadcast_neigh_tbl[] = { 255 { "off", 0, BOND_VALFLAG_DEFAULT}, 256 { "on", 1, 0}, 257 { NULL, -1, 0} 258 }; 259 260 static const struct bond_option bond_opts[BOND_OPT_LAST] = { 261 [BOND_OPT_MODE] = { 262 .id = BOND_OPT_MODE, 263 .name = "mode", 264 .desc = "bond device mode", 265 .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN, 266 .values = bond_mode_tbl, 267 .set = bond_option_mode_set 268 }, 269 [BOND_OPT_PACKETS_PER_SLAVE] = { 270 .id = BOND_OPT_PACKETS_PER_SLAVE, 271 .name = "packets_per_slave", 272 .desc = "Packets to send per slave in RR mode", 273 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)), 274 .values = bond_pps_tbl, 275 .set = bond_option_pps_set 276 }, 277 [BOND_OPT_XMIT_HASH] = { 278 .id = BOND_OPT_XMIT_HASH, 279 .name = "xmit_hash_policy", 280 .desc = "balance-xor, 802.3ad, and tlb hashing method", 281 .values = bond_xmit_hashtype_tbl, 282 .set = bond_option_xmit_hash_policy_set 283 }, 284 [BOND_OPT_ARP_VALIDATE] = { 285 .id = BOND_OPT_ARP_VALIDATE, 286 .name = "arp_validate", 287 .desc = "validate src/dst of ARP probes", 288 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | 289 BIT(BOND_MODE_ALB), 290 .values = bond_arp_validate_tbl, 291 .set = bond_option_arp_validate_set 292 }, 293 [BOND_OPT_ARP_ALL_TARGETS] = { 294 .id = BOND_OPT_ARP_ALL_TARGETS, 295 .name = "arp_all_targets", 296 .desc = "fail on any/all arp targets timeout", 297 .values = bond_arp_all_targets_tbl, 298 .set = bond_option_arp_all_targets_set 299 }, 300 [BOND_OPT_FAIL_OVER_MAC] = { 301 .id = BOND_OPT_FAIL_OVER_MAC, 302 .name = "fail_over_mac", 303 .desc = "For active-backup, do not set all slaves to the same MAC", 304 .flags = BOND_OPTFLAG_NOSLAVES, 305 .values = bond_fail_over_mac_tbl, 306 .set = bond_option_fail_over_mac_set 307 }, 308 [BOND_OPT_ARP_INTERVAL] = { 309 .id = BOND_OPT_ARP_INTERVAL, 310 .name = "arp_interval", 311 .desc = "arp interval in milliseconds", 312 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | 313 BIT(BOND_MODE_ALB), 314 .values = bond_intmax_tbl, 315 .set = bond_option_arp_interval_set 316 }, 317 [BOND_OPT_MISSED_MAX] = { 318 .id = BOND_OPT_MISSED_MAX, 319 .name = "arp_missed_max", 320 .desc = "Maximum number of missed ARP interval", 321 .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | 322 BIT(BOND_MODE_ALB), 323 .values = bond_missed_max_tbl, 324 .set = bond_option_missed_max_set 325 }, 326 [BOND_OPT_ARP_TARGETS] = { 327 .id = BOND_OPT_ARP_TARGETS, 328 .name = "arp_ip_target", 329 .desc = "arp targets in n.n.n.n form", 330 .flags = BOND_OPTFLAG_RAWVAL, 331 .set = bond_option_arp_ip_targets_set 332 }, 333 [BOND_OPT_NS_TARGETS] = { 334 .id = BOND_OPT_NS_TARGETS, 335 .name = "ns_ip6_target", 336 .desc = "NS targets in ffff:ffff::ffff:ffff form", 337 .flags = BOND_OPTFLAG_RAWVAL, 338 .set = bond_option_ns_ip6_targets_set 339 }, 340 [BOND_OPT_DOWNDELAY] = { 341 .id = BOND_OPT_DOWNDELAY, 342 .name = "downdelay", 343 .desc = "Delay before considering link down, in milliseconds", 344 .values = bond_intmax_tbl, 345 .set = bond_option_downdelay_set 346 }, 347 [BOND_OPT_UPDELAY] = { 348 .id = BOND_OPT_UPDELAY, 349 .name = "updelay", 350 .desc = "Delay before considering link up, in milliseconds", 351 .values = bond_intmax_tbl, 352 .set = bond_option_updelay_set 353 }, 354 [BOND_OPT_LACP_ACTIVE] = { 355 .id = BOND_OPT_LACP_ACTIVE, 356 .name = "lacp_active", 357 .desc = "Send LACPDU frames with configured lacp rate or acts as speak when spoken to", 358 .flags = BOND_OPTFLAG_IFDOWN, 359 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 360 .values = bond_lacp_active, 361 .set = bond_option_lacp_active_set 362 }, 363 [BOND_OPT_LACP_RATE] = { 364 .id = BOND_OPT_LACP_RATE, 365 .name = "lacp_rate", 366 .desc = "LACPDU tx rate to request from 802.3ad partner", 367 .flags = BOND_OPTFLAG_IFDOWN, 368 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 369 .values = bond_lacp_rate_tbl, 370 .set = bond_option_lacp_rate_set 371 }, 372 [BOND_OPT_MINLINKS] = { 373 .id = BOND_OPT_MINLINKS, 374 .name = "min_links", 375 .desc = "Minimum number of available links before turning on carrier", 376 .values = bond_intmax_tbl, 377 .set = bond_option_min_links_set 378 }, 379 [BOND_OPT_AD_SELECT] = { 380 .id = BOND_OPT_AD_SELECT, 381 .name = "ad_select", 382 .desc = "802.3ad aggregation selection logic", 383 .flags = BOND_OPTFLAG_IFDOWN, 384 .values = bond_ad_select_tbl, 385 .set = bond_option_ad_select_set 386 }, 387 [BOND_OPT_NUM_PEER_NOTIF] = { 388 .id = BOND_OPT_NUM_PEER_NOTIF, 389 .name = "num_unsol_na", 390 .desc = "Number of peer notifications to send on failover event", 391 .values = bond_num_peer_notif_tbl, 392 .set = bond_option_num_peer_notif_set 393 }, 394 [BOND_OPT_MIIMON] = { 395 .id = BOND_OPT_MIIMON, 396 .name = "miimon", 397 .desc = "Link check interval in milliseconds", 398 .values = bond_intmax_tbl, 399 .set = bond_option_miimon_set 400 }, 401 [BOND_OPT_PRIO] = { 402 .id = BOND_OPT_PRIO, 403 .name = "prio", 404 .desc = "Link priority for failover re-selection", 405 .flags = BOND_OPTFLAG_RAWVAL, 406 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | 407 BIT(BOND_MODE_TLB) | 408 BIT(BOND_MODE_ALB)), 409 .set = bond_option_prio_set 410 }, 411 [BOND_OPT_PRIMARY] = { 412 .id = BOND_OPT_PRIMARY, 413 .name = "primary", 414 .desc = "Primary network device to use", 415 .flags = BOND_OPTFLAG_RAWVAL, 416 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | 417 BIT(BOND_MODE_TLB) | 418 BIT(BOND_MODE_ALB)), 419 .set = bond_option_primary_set 420 }, 421 [BOND_OPT_PRIMARY_RESELECT] = { 422 .id = BOND_OPT_PRIMARY_RESELECT, 423 .name = "primary_reselect", 424 .desc = "Reselect primary slave once it comes up", 425 .values = bond_primary_reselect_tbl, 426 .set = bond_option_primary_reselect_set 427 }, 428 [BOND_OPT_USE_CARRIER] = { 429 .id = BOND_OPT_USE_CARRIER, 430 .name = "use_carrier", 431 .desc = "option obsolete, use_carrier cannot be disabled", 432 .values = bond_use_carrier_tbl, 433 .set = bond_option_use_carrier_set 434 }, 435 [BOND_OPT_ACTIVE_SLAVE] = { 436 .id = BOND_OPT_ACTIVE_SLAVE, 437 .name = "active_slave", 438 .desc = "Currently active slave", 439 .flags = BOND_OPTFLAG_RAWVAL, 440 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | 441 BIT(BOND_MODE_TLB) | 442 BIT(BOND_MODE_ALB)), 443 .set = bond_option_active_slave_set 444 }, 445 [BOND_OPT_QUEUE_ID] = { 446 .id = BOND_OPT_QUEUE_ID, 447 .name = "queue_id", 448 .desc = "Set queue id of a slave", 449 .flags = BOND_OPTFLAG_RAWVAL, 450 .set = bond_option_queue_id_set 451 }, 452 [BOND_OPT_ALL_SLAVES_ACTIVE] = { 453 .id = BOND_OPT_ALL_SLAVES_ACTIVE, 454 .name = "all_slaves_active", 455 .desc = "Keep all frames received on an interface by setting active flag for all slaves", 456 .values = bond_all_slaves_active_tbl, 457 .set = bond_option_all_slaves_active_set 458 }, 459 [BOND_OPT_RESEND_IGMP] = { 460 .id = BOND_OPT_RESEND_IGMP, 461 .name = "resend_igmp", 462 .desc = "Number of IGMP membership reports to send on link failure", 463 .values = bond_resend_igmp_tbl, 464 .set = bond_option_resend_igmp_set 465 }, 466 [BOND_OPT_LP_INTERVAL] = { 467 .id = BOND_OPT_LP_INTERVAL, 468 .name = "lp_interval", 469 .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch", 470 .values = bond_lp_interval_tbl, 471 .set = bond_option_lp_interval_set 472 }, 473 [BOND_OPT_SLAVES] = { 474 .id = BOND_OPT_SLAVES, 475 .name = "slaves", 476 .desc = "Slave membership management", 477 .flags = BOND_OPTFLAG_RAWVAL, 478 .set = bond_option_slaves_set 479 }, 480 [BOND_OPT_TLB_DYNAMIC_LB] = { 481 .id = BOND_OPT_TLB_DYNAMIC_LB, 482 .name = "tlb_dynamic_lb", 483 .desc = "Enable dynamic flow shuffling", 484 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB) | BIT(BOND_MODE_ALB)), 485 .values = bond_tlb_dynamic_lb_tbl, 486 .flags = BOND_OPTFLAG_IFDOWN, 487 .set = bond_option_tlb_dynamic_lb_set, 488 }, 489 [BOND_OPT_AD_ACTOR_SYS_PRIO] = { 490 .id = BOND_OPT_AD_ACTOR_SYS_PRIO, 491 .name = "ad_actor_sys_prio", 492 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 493 .values = bond_ad_actor_sys_prio_tbl, 494 .set = bond_option_ad_actor_sys_prio_set, 495 }, 496 [BOND_OPT_ACTOR_PORT_PRIO] = { 497 .id = BOND_OPT_ACTOR_PORT_PRIO, 498 .name = "actor_port_prio", 499 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 500 .values = bond_actor_port_prio_tbl, 501 .set = bond_option_actor_port_prio_set, 502 }, 503 [BOND_OPT_AD_ACTOR_SYSTEM] = { 504 .id = BOND_OPT_AD_ACTOR_SYSTEM, 505 .name = "ad_actor_system", 506 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 507 .flags = BOND_OPTFLAG_RAWVAL, 508 .set = bond_option_ad_actor_system_set, 509 }, 510 [BOND_OPT_AD_USER_PORT_KEY] = { 511 .id = BOND_OPT_AD_USER_PORT_KEY, 512 .name = "ad_user_port_key", 513 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 514 .flags = BOND_OPTFLAG_IFDOWN, 515 .values = bond_ad_user_port_key_tbl, 516 .set = bond_option_ad_user_port_key_set, 517 }, 518 [BOND_OPT_NUM_PEER_NOTIF_ALIAS] = { 519 .id = BOND_OPT_NUM_PEER_NOTIF_ALIAS, 520 .name = "num_grat_arp", 521 .desc = "Number of peer notifications to send on failover event", 522 .values = bond_num_peer_notif_tbl, 523 .set = bond_option_num_peer_notif_set 524 }, 525 [BOND_OPT_PEER_NOTIF_DELAY] = { 526 .id = BOND_OPT_PEER_NOTIF_DELAY, 527 .name = "peer_notif_delay", 528 .desc = "Delay between each peer notification on failover event, in milliseconds", 529 .values = bond_peer_notif_delay_tbl, 530 .set = bond_option_peer_notif_delay_set 531 }, 532 [BOND_OPT_COUPLED_CONTROL] = { 533 .id = BOND_OPT_COUPLED_CONTROL, 534 .name = "coupled_control", 535 .desc = "Opt into using coupled control MUX for LACP states", 536 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 537 .flags = BOND_OPTFLAG_IFDOWN, 538 .values = bond_coupled_control_tbl, 539 .set = bond_option_coupled_control_set, 540 }, 541 [BOND_OPT_BROADCAST_NEIGH] = { 542 .id = BOND_OPT_BROADCAST_NEIGH, 543 .name = "broadcast_neighbor", 544 .desc = "Broadcast neighbor packets to all active slaves", 545 .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), 546 .values = bond_broadcast_neigh_tbl, 547 .set = bond_option_broadcast_neigh_set, 548 } 549 }; 550 551 /* Searches for an option by name */ 552 const struct bond_option *bond_opt_get_by_name(const char *name) 553 { 554 const struct bond_option *opt; 555 int option; 556 557 for (option = 0; option < BOND_OPT_LAST; option++) { 558 opt = bond_opt_get(option); 559 if (opt && !strcmp(opt->name, name)) 560 return opt; 561 } 562 563 return NULL; 564 } 565 566 /* Searches for a value in opt's values[] table */ 567 const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) 568 { 569 const struct bond_option *opt; 570 int i; 571 572 opt = bond_opt_get(option); 573 if (WARN_ON(!opt)) 574 return NULL; 575 for (i = 0; opt->values && opt->values[i].string; i++) 576 if (opt->values[i].value == val) 577 return &opt->values[i]; 578 579 return NULL; 580 } 581 582 /* Searches for a value in opt's values[] table which matches the flagmask */ 583 static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt, 584 u32 flagmask) 585 { 586 int i; 587 588 for (i = 0; opt->values && opt->values[i].string; i++) 589 if (opt->values[i].flags & flagmask) 590 return &opt->values[i]; 591 592 return NULL; 593 } 594 595 /* If maxval is missing then there's no range to check. In case minval is 596 * missing then it's considered to be 0. 597 */ 598 static bool bond_opt_check_range(const struct bond_option *opt, u64 val) 599 { 600 const struct bond_opt_value *minval, *maxval; 601 602 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); 603 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); 604 if (!maxval || (minval && val < minval->value) || val > maxval->value) 605 return false; 606 607 return true; 608 } 609 610 /** 611 * bond_opt_parse - parse option value 612 * @opt: the option to parse against 613 * @val: value to parse 614 * 615 * This function tries to extract the value from @val and check if it's 616 * a possible match for the option and returns NULL if a match isn't found, 617 * or the struct_opt_value that matched. It also strips the new line from 618 * @val->string if it's present. 619 */ 620 const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, 621 struct bond_opt_value *val) 622 { 623 char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; 624 const struct bond_opt_value *tbl; 625 const struct bond_opt_value *ret = NULL; 626 bool checkval; 627 int i, rv; 628 629 /* No parsing if the option wants a raw val */ 630 if (opt->flags & BOND_OPTFLAG_RAWVAL) 631 return val; 632 633 tbl = opt->values; 634 if (!tbl) 635 goto out; 636 637 /* ULLONG_MAX is used to bypass string processing */ 638 checkval = val->value != ULLONG_MAX; 639 if (!checkval) { 640 if (!val->string) 641 goto out; 642 p = strchr(val->string, '\n'); 643 if (p) 644 *p = '\0'; 645 for (p = val->string; *p; p++) 646 if (!(isdigit(*p) || isspace(*p))) 647 break; 648 /* The following code extracts the string to match or the value 649 * and sets checkval appropriately 650 */ 651 if (*p) { 652 rv = sscanf(val->string, "%32s", valstr); 653 } else { 654 rv = sscanf(val->string, "%llu", &val->value); 655 checkval = true; 656 } 657 if (!rv) 658 goto out; 659 } 660 661 for (i = 0; tbl[i].string; i++) { 662 /* Check for exact match */ 663 if (checkval) { 664 if (val->value == tbl[i].value) 665 ret = &tbl[i]; 666 } else { 667 if (!strcmp(valstr, "default") && 668 (tbl[i].flags & BOND_VALFLAG_DEFAULT)) 669 ret = &tbl[i]; 670 671 if (!strcmp(valstr, tbl[i].string)) 672 ret = &tbl[i]; 673 } 674 /* Found an exact match */ 675 if (ret) 676 goto out; 677 } 678 /* Possible range match */ 679 if (checkval && bond_opt_check_range(opt, val->value)) 680 ret = val; 681 out: 682 return ret; 683 } 684 685 /* Check opt's dependencies against bond mode and currently set options */ 686 static int bond_opt_check_deps(struct bonding *bond, 687 const struct bond_option *opt) 688 { 689 struct bond_params *params = &bond->params; 690 691 if (test_bit(params->mode, &opt->unsuppmodes)) 692 return -EACCES; 693 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) 694 return -ENOTEMPTY; 695 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) 696 return -EBUSY; 697 698 return 0; 699 } 700 701 static void bond_opt_dep_print(struct bonding *bond, 702 const struct bond_option *opt, 703 struct nlattr *bad_attr, 704 struct netlink_ext_ack *extack) 705 { 706 const struct bond_opt_value *modeval; 707 struct bond_params *params; 708 709 params = &bond->params; 710 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); 711 if (test_bit(params->mode, &opt->unsuppmodes)) { 712 netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n", 713 opt->name, modeval->string, modeval->value); 714 NL_SET_ERR_MSG_ATTR(extack, bad_attr, 715 "option not supported in mode"); 716 } 717 } 718 719 static void bond_opt_error_interpret(struct bonding *bond, 720 const struct bond_option *opt, 721 int error, const struct bond_opt_value *val, 722 struct nlattr *bad_attr, 723 struct netlink_ext_ack *extack) 724 { 725 const struct bond_opt_value *minval, *maxval; 726 char *p; 727 728 switch (error) { 729 case -EINVAL: 730 NL_SET_ERR_MSG_ATTR(extack, bad_attr, "invalid option value"); 731 if (val) { 732 if (val->string) { 733 /* sometimes RAWVAL opts may have new lines */ 734 p = strchr(val->string, '\n'); 735 if (p) 736 *p = '\0'; 737 netdev_err(bond->dev, "option %s: invalid value (%s)\n", 738 opt->name, val->string); 739 } else { 740 netdev_err(bond->dev, "option %s: invalid value (%llu)\n", 741 opt->name, val->value); 742 } 743 } 744 minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); 745 maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); 746 if (!maxval) 747 break; 748 netdev_err(bond->dev, "option %s: allowed values %llu - %llu\n", 749 opt->name, minval ? minval->value : 0, maxval->value); 750 break; 751 case -EACCES: 752 bond_opt_dep_print(bond, opt, bad_attr, extack); 753 break; 754 case -ENOTEMPTY: 755 NL_SET_ERR_MSG_ATTR(extack, bad_attr, 756 "unable to set option because the bond device has slaves"); 757 netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n", 758 opt->name); 759 break; 760 case -EBUSY: 761 NL_SET_ERR_MSG_ATTR(extack, bad_attr, 762 "unable to set option because the bond is up"); 763 netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n", 764 opt->name); 765 break; 766 case -ENODEV: 767 if (val && val->string) { 768 p = strchr(val->string, '\n'); 769 if (p) 770 *p = '\0'; 771 netdev_err(bond->dev, "option %s: interface %s does not exist!\n", 772 opt->name, val->string); 773 NL_SET_ERR_MSG_ATTR(extack, bad_attr, 774 "interface does not exist"); 775 } 776 break; 777 default: 778 break; 779 } 780 } 781 782 /** 783 * __bond_opt_set - set a bonding option 784 * @bond: target bond device 785 * @option: option to set 786 * @val: value to set it to 787 * @bad_attr: netlink attribue that caused the error 788 * @extack: extended netlink error structure, used when an error message 789 * needs to be returned to the caller via netlink 790 * 791 * This function is used to change the bond's option value, it can be 792 * used for both enabling/changing an option and for disabling it. RTNL lock 793 * must be obtained before calling this function. 794 */ 795 int __bond_opt_set(struct bonding *bond, 796 unsigned int option, struct bond_opt_value *val, 797 struct nlattr *bad_attr, struct netlink_ext_ack *extack) 798 { 799 const struct bond_opt_value *retval = NULL; 800 const struct bond_option *opt; 801 int ret = -ENOENT; 802 803 ASSERT_RTNL(); 804 805 opt = bond_opt_get(option); 806 if (WARN_ON(!val) || WARN_ON(!opt)) 807 goto out; 808 ret = bond_opt_check_deps(bond, opt); 809 if (ret) 810 goto out; 811 retval = bond_opt_parse(opt, val); 812 if (!retval) { 813 ret = -EINVAL; 814 goto out; 815 } 816 ret = opt->set(bond, retval); 817 out: 818 if (ret) 819 bond_opt_error_interpret(bond, opt, ret, val, bad_attr, extack); 820 821 return ret; 822 } 823 /** 824 * __bond_opt_set_notify - set a bonding option 825 * @bond: target bond device 826 * @option: option to set 827 * @val: value to set it to 828 * 829 * This function is used to change the bond's option value and trigger 830 * a notification to user sapce. It can be used for both enabling/changing 831 * an option and for disabling it. RTNL lock must be obtained before calling 832 * this function. 833 */ 834 int __bond_opt_set_notify(struct bonding *bond, 835 unsigned int option, struct bond_opt_value *val) 836 { 837 int ret; 838 839 ASSERT_RTNL(); 840 841 ret = __bond_opt_set(bond, option, val, NULL, NULL); 842 843 if (!ret && (bond->dev->reg_state == NETREG_REGISTERED)) 844 call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev); 845 846 return ret; 847 } 848 849 /** 850 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set 851 * @bond: target bond device 852 * @option: option to set 853 * @buf: value to set it to 854 * 855 * This function tries to acquire RTNL without blocking and if successful 856 * calls __bond_opt_set. It is mainly used for sysfs option manipulation. 857 */ 858 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) 859 { 860 struct bond_opt_value optval; 861 int ret; 862 863 if (!rtnl_trylock()) 864 return restart_syscall(); 865 bond_opt_initstr(&optval, buf); 866 ret = __bond_opt_set_notify(bond, option, &optval); 867 rtnl_unlock(); 868 869 return ret; 870 } 871 872 /** 873 * bond_opt_get - get a pointer to an option 874 * @option: option for which to return a pointer 875 * 876 * This function checks if option is valid and if so returns a pointer 877 * to its entry in the bond_opts[] option array. 878 */ 879 const struct bond_option *bond_opt_get(unsigned int option) 880 { 881 if (!BOND_OPT_VALID(option)) 882 return NULL; 883 884 return &bond_opts[option]; 885 } 886 887 static bool bond_set_xfrm_features(struct bonding *bond) 888 { 889 if (!IS_ENABLED(CONFIG_XFRM_OFFLOAD)) 890 return false; 891 892 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) 893 bond->dev->wanted_features |= BOND_XFRM_FEATURES; 894 else 895 bond->dev->wanted_features &= ~BOND_XFRM_FEATURES; 896 897 return true; 898 } 899 900 static int bond_option_mode_set(struct bonding *bond, 901 const struct bond_opt_value *newval) 902 { 903 if (bond->xdp_prog && !bond_xdp_check(bond, newval->value)) 904 return -EOPNOTSUPP; 905 906 if (!bond_mode_uses_arp(newval->value)) { 907 if (bond->params.arp_interval) { 908 netdev_dbg(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n", 909 newval->string); 910 /* disable arp monitoring */ 911 bond->params.arp_interval = 0; 912 } 913 914 if (!bond->params.miimon) { 915 /* set miimon to default value */ 916 bond->params.miimon = BOND_DEFAULT_MIIMON; 917 netdev_dbg(bond->dev, "Setting MII monitoring interval to %d\n", 918 bond->params.miimon); 919 } 920 } 921 922 if (newval->value == BOND_MODE_ALB) 923 bond->params.tlb_dynamic_lb = 1; 924 925 /* don't cache arp_validate between modes */ 926 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; 927 bond->params.mode = newval->value; 928 929 /* When changing mode, the bond device is down, we may reduce 930 * the bond_bcast_neigh_enabled in bond_close() if broadcast_neighbor 931 * enabled in 8023ad mode. Therefore, only clear broadcast_neighbor 932 * to 0. 933 */ 934 bond->params.broadcast_neighbor = 0; 935 936 if (bond->dev->reg_state == NETREG_REGISTERED) { 937 bool update = false; 938 939 update |= bond_set_xfrm_features(bond); 940 941 if (update) 942 netdev_update_features(bond->dev); 943 } 944 945 bond_xdp_set_features(bond->dev); 946 947 return 0; 948 } 949 950 static int bond_option_active_slave_set(struct bonding *bond, 951 const struct bond_opt_value *newval) 952 { 953 char ifname[IFNAMSIZ] = { 0, }; 954 struct net_device *slave_dev; 955 int ret = 0; 956 957 sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */ 958 if (!strlen(ifname) || newval->string[0] == '\n') { 959 slave_dev = NULL; 960 } else { 961 slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname); 962 if (!slave_dev) 963 return -ENODEV; 964 } 965 966 if (slave_dev) { 967 if (!netif_is_bond_slave(slave_dev)) { 968 slave_err(bond->dev, slave_dev, "Device is not bonding slave\n"); 969 return -EINVAL; 970 } 971 972 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { 973 slave_err(bond->dev, slave_dev, "Device is not our slave\n"); 974 return -EINVAL; 975 } 976 } 977 978 block_netpoll_tx(); 979 /* check to see if we are clearing active */ 980 if (!slave_dev) { 981 netdev_dbg(bond->dev, "Clearing current active slave\n"); 982 bond_change_active_slave(bond, NULL); 983 bond_select_active_slave(bond); 984 } else { 985 struct slave *old_active = rtnl_dereference(bond->curr_active_slave); 986 struct slave *new_active = bond_slave_get_rtnl(slave_dev); 987 988 BUG_ON(!new_active); 989 990 if (new_active == old_active) { 991 /* do nothing */ 992 slave_dbg(bond->dev, new_active->dev, "is already the current active slave\n"); 993 } else { 994 if (old_active && (new_active->link == BOND_LINK_UP) && 995 bond_slave_is_up(new_active)) { 996 slave_dbg(bond->dev, new_active->dev, "Setting as active slave\n"); 997 bond_change_active_slave(bond, new_active); 998 } else { 999 slave_err(bond->dev, new_active->dev, "Could not set as active slave; either %s is down or the link is down\n", 1000 new_active->dev->name); 1001 ret = -EINVAL; 1002 } 1003 } 1004 } 1005 unblock_netpoll_tx(); 1006 1007 return ret; 1008 } 1009 1010 /* There are two tricky bits here. First, if MII monitoring is activated, then 1011 * we must disable ARP monitoring. Second, if the timer isn't running, we must 1012 * start it. 1013 */ 1014 static int bond_option_miimon_set(struct bonding *bond, 1015 const struct bond_opt_value *newval) 1016 { 1017 netdev_dbg(bond->dev, "Setting MII monitoring interval to %llu\n", 1018 newval->value); 1019 bond->params.miimon = newval->value; 1020 if (bond->params.updelay) 1021 netdev_dbg(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n", 1022 bond->params.updelay * bond->params.miimon); 1023 if (bond->params.downdelay) 1024 netdev_dbg(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n", 1025 bond->params.downdelay * bond->params.miimon); 1026 if (bond->params.peer_notif_delay) 1027 netdev_dbg(bond->dev, "Note: Updating peer_notif_delay (to %d) since it is a multiple of the miimon value\n", 1028 bond->params.peer_notif_delay * bond->params.miimon); 1029 if (newval->value && bond->params.arp_interval) { 1030 netdev_dbg(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n"); 1031 bond->params.arp_interval = 0; 1032 if (bond->params.arp_validate) 1033 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; 1034 } 1035 if (bond->dev->flags & IFF_UP) { 1036 /* If the interface is up, we may need to fire off 1037 * the MII timer. If the interface is down, the 1038 * timer will get fired off when the open function 1039 * is called. 1040 */ 1041 if (!newval->value) { 1042 cancel_delayed_work_sync(&bond->mii_work); 1043 } else { 1044 cancel_delayed_work_sync(&bond->arp_work); 1045 queue_delayed_work(bond->wq, &bond->mii_work, 0); 1046 } 1047 } 1048 1049 return 0; 1050 } 1051 1052 /* Set up, down and peer notification delays. These must be multiples 1053 * of the MII monitoring value, and are stored internally as the 1054 * multiplier. Thus, we must translate to MS for the real world. 1055 */ 1056 static int _bond_option_delay_set(struct bonding *bond, 1057 const struct bond_opt_value *newval, 1058 const char *name, 1059 int *target) 1060 { 1061 int value = newval->value; 1062 1063 if (!bond->params.miimon) { 1064 netdev_err(bond->dev, "Unable to set %s as MII monitoring is disabled\n", 1065 name); 1066 return -EPERM; 1067 } 1068 if ((value % bond->params.miimon) != 0) { 1069 netdev_warn(bond->dev, 1070 "%s (%d) is not a multiple of miimon (%d), value rounded to %d ms\n", 1071 name, 1072 value, bond->params.miimon, 1073 (value / bond->params.miimon) * 1074 bond->params.miimon); 1075 } 1076 *target = value / bond->params.miimon; 1077 netdev_dbg(bond->dev, "Setting %s to %d\n", 1078 name, 1079 *target * bond->params.miimon); 1080 1081 return 0; 1082 } 1083 1084 static int bond_option_updelay_set(struct bonding *bond, 1085 const struct bond_opt_value *newval) 1086 { 1087 return _bond_option_delay_set(bond, newval, "up delay", 1088 &bond->params.updelay); 1089 } 1090 1091 static int bond_option_downdelay_set(struct bonding *bond, 1092 const struct bond_opt_value *newval) 1093 { 1094 return _bond_option_delay_set(bond, newval, "down delay", 1095 &bond->params.downdelay); 1096 } 1097 1098 static int bond_option_peer_notif_delay_set(struct bonding *bond, 1099 const struct bond_opt_value *newval) 1100 { 1101 int ret = _bond_option_delay_set(bond, newval, 1102 "peer notification delay", 1103 &bond->params.peer_notif_delay); 1104 return ret; 1105 } 1106 1107 static int bond_option_use_carrier_set(struct bonding *bond, 1108 const struct bond_opt_value *newval) 1109 { 1110 return 0; 1111 } 1112 1113 /* There are two tricky bits here. First, if ARP monitoring is activated, then 1114 * we must disable MII monitoring. Second, if the ARP timer isn't running, 1115 * we must start it. 1116 */ 1117 static int bond_option_arp_interval_set(struct bonding *bond, 1118 const struct bond_opt_value *newval) 1119 { 1120 netdev_dbg(bond->dev, "Setting ARP monitoring interval to %llu\n", 1121 newval->value); 1122 bond->params.arp_interval = newval->value; 1123 if (newval->value) { 1124 if (bond->params.miimon) { 1125 netdev_dbg(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring\n"); 1126 bond->params.miimon = 0; 1127 } 1128 if (!bond->params.arp_targets[0]) 1129 netdev_dbg(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n"); 1130 } 1131 if (bond->dev->flags & IFF_UP) { 1132 /* If the interface is up, we may need to fire off 1133 * the ARP timer. If the interface is down, the 1134 * timer will get fired off when the open function 1135 * is called. 1136 */ 1137 if (!newval->value) { 1138 if (bond->params.arp_validate) 1139 bond->recv_probe = NULL; 1140 cancel_delayed_work_sync(&bond->arp_work); 1141 } else { 1142 /* arp_validate can be set only in active-backup mode */ 1143 bond->recv_probe = bond_rcv_validate; 1144 cancel_delayed_work_sync(&bond->mii_work); 1145 queue_delayed_work(bond->wq, &bond->arp_work, 0); 1146 } 1147 } 1148 1149 return 0; 1150 } 1151 1152 static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, 1153 __be32 target, 1154 unsigned long last_rx) 1155 { 1156 __be32 *targets = bond->params.arp_targets; 1157 struct list_head *iter; 1158 struct slave *slave; 1159 1160 if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { 1161 bond_for_each_slave(bond, slave, iter) 1162 slave->target_last_arp_rx[slot] = last_rx; 1163 targets[slot] = target; 1164 } 1165 } 1166 1167 static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) 1168 { 1169 __be32 *targets = bond->params.arp_targets; 1170 int ind; 1171 1172 if (!bond_is_ip_target_ok(target)) { 1173 netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n", 1174 &target); 1175 return -EINVAL; 1176 } 1177 1178 if (bond_get_targets_ip(targets, target) != -1) { /* dup */ 1179 netdev_err(bond->dev, "ARP target %pI4 is already present\n", 1180 &target); 1181 return -EINVAL; 1182 } 1183 1184 ind = bond_get_targets_ip(targets, 0); /* first free slot */ 1185 if (ind == -1) { 1186 netdev_err(bond->dev, "ARP target table is full!\n"); 1187 return -EINVAL; 1188 } 1189 1190 netdev_dbg(bond->dev, "Adding ARP target %pI4\n", &target); 1191 1192 _bond_options_arp_ip_target_set(bond, ind, target, jiffies); 1193 1194 return 0; 1195 } 1196 1197 static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) 1198 { 1199 return _bond_option_arp_ip_target_add(bond, target); 1200 } 1201 1202 static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) 1203 { 1204 __be32 *targets = bond->params.arp_targets; 1205 struct list_head *iter; 1206 struct slave *slave; 1207 unsigned long *targets_rx; 1208 int ind, i; 1209 1210 if (!bond_is_ip_target_ok(target)) { 1211 netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n", 1212 &target); 1213 return -EINVAL; 1214 } 1215 1216 ind = bond_get_targets_ip(targets, target); 1217 if (ind == -1) { 1218 netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n", 1219 &target); 1220 return -EINVAL; 1221 } 1222 1223 if (ind == 0 && !targets[1] && bond->params.arp_interval) 1224 netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n"); 1225 1226 netdev_dbg(bond->dev, "Removing ARP target %pI4\n", &target); 1227 1228 bond_for_each_slave(bond, slave, iter) { 1229 targets_rx = slave->target_last_arp_rx; 1230 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) 1231 targets_rx[i] = targets_rx[i+1]; 1232 targets_rx[i] = 0; 1233 } 1234 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) 1235 targets[i] = targets[i+1]; 1236 targets[i] = 0; 1237 1238 return 0; 1239 } 1240 1241 void bond_option_arp_ip_targets_clear(struct bonding *bond) 1242 { 1243 int i; 1244 1245 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) 1246 _bond_options_arp_ip_target_set(bond, i, 0, 0); 1247 } 1248 1249 static int bond_option_arp_ip_targets_set(struct bonding *bond, 1250 const struct bond_opt_value *newval) 1251 { 1252 int ret = -EPERM; 1253 __be32 target; 1254 1255 if (newval->string) { 1256 if (strlen(newval->string) < 1 || 1257 !in4_pton(newval->string + 1, -1, (u8 *)&target, -1, NULL)) { 1258 netdev_err(bond->dev, "invalid ARP target specified\n"); 1259 return ret; 1260 } 1261 if (newval->string[0] == '+') 1262 ret = bond_option_arp_ip_target_add(bond, target); 1263 else if (newval->string[0] == '-') 1264 ret = bond_option_arp_ip_target_rem(bond, target); 1265 else 1266 netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n"); 1267 } else { 1268 target = newval->value; 1269 ret = bond_option_arp_ip_target_add(bond, target); 1270 } 1271 1272 return ret; 1273 } 1274 1275 #if IS_ENABLED(CONFIG_IPV6) 1276 static bool slave_can_set_ns_maddr(const struct bonding *bond, struct slave *slave) 1277 { 1278 return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP && 1279 !bond_is_active_slave(slave) && 1280 slave->dev->flags & IFF_MULTICAST; 1281 } 1282 1283 /** 1284 * slave_set_ns_maddrs - add/del all NS mac addresses for slave 1285 * @bond: bond device 1286 * @slave: slave device 1287 * @add: add or remove all the NS mac addresses 1288 * 1289 * This function tries to add or delete all the NS mac addresses on the slave 1290 * 1291 * Note, the IPv6 NS target address is the unicast address in Neighbor 1292 * Solicitation (NS) message. The dest address of NS message should be 1293 * solicited-node multicast address of the target. The dest mac of NS message 1294 * is converted from the solicited-node multicast address. 1295 * 1296 * This function is called when 1297 * * arp_validate changes 1298 * * enslaving, releasing new slaves 1299 */ 1300 static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add) 1301 { 1302 struct in6_addr *targets = bond->params.ns_targets; 1303 char slot_maddr[MAX_ADDR_LEN]; 1304 struct in6_addr mcaddr; 1305 int i; 1306 1307 if (!slave_can_set_ns_maddr(bond, slave)) 1308 return; 1309 1310 for (i = 0; i < BOND_MAX_NS_TARGETS; i++) { 1311 if (ipv6_addr_any(&targets[i])) 1312 break; 1313 1314 addrconf_addr_solict_mult(&targets[i], &mcaddr); 1315 if (!ndisc_mc_map(&mcaddr, slot_maddr, slave->dev, 0)) { 1316 if (add) 1317 dev_mc_add(slave->dev, slot_maddr); 1318 else 1319 dev_mc_del(slave->dev, slot_maddr); 1320 } 1321 } 1322 } 1323 1324 void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave) 1325 { 1326 if (!bond->params.arp_validate) 1327 return; 1328 slave_set_ns_maddrs(bond, slave, true); 1329 } 1330 1331 void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave) 1332 { 1333 if (!bond->params.arp_validate) 1334 return; 1335 slave_set_ns_maddrs(bond, slave, false); 1336 } 1337 1338 /** 1339 * slave_set_ns_maddr - set new NS mac address for slave 1340 * @bond: bond device 1341 * @slave: slave device 1342 * @target: the new IPv6 target 1343 * @slot: the old IPv6 target in the slot 1344 * 1345 * This function tries to replace the old mac address to new one on the slave. 1346 * 1347 * Note, the target/slot IPv6 address is the unicast address in Neighbor 1348 * Solicitation (NS) message. The dest address of NS message should be 1349 * solicited-node multicast address of the target. The dest mac of NS message 1350 * is converted from the solicited-node multicast address. 1351 * 1352 * This function is called when 1353 * * An IPv6 NS target is added or removed. 1354 */ 1355 static void slave_set_ns_maddr(struct bonding *bond, struct slave *slave, 1356 struct in6_addr *target, struct in6_addr *slot) 1357 { 1358 char mac_addr[MAX_ADDR_LEN]; 1359 struct in6_addr mcast_addr; 1360 1361 if (!bond->params.arp_validate || !slave_can_set_ns_maddr(bond, slave)) 1362 return; 1363 1364 /* remove the previous mac addr from slave */ 1365 addrconf_addr_solict_mult(slot, &mcast_addr); 1366 if (!ipv6_addr_any(slot) && 1367 !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0)) 1368 dev_mc_del(slave->dev, mac_addr); 1369 1370 /* add new mac addr on slave if target is set */ 1371 addrconf_addr_solict_mult(target, &mcast_addr); 1372 if (!ipv6_addr_any(target) && 1373 !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0)) 1374 dev_mc_add(slave->dev, mac_addr); 1375 } 1376 1377 static void _bond_options_ns_ip6_target_set(struct bonding *bond, int slot, 1378 struct in6_addr *target, 1379 unsigned long last_rx) 1380 { 1381 struct in6_addr *targets = bond->params.ns_targets; 1382 struct list_head *iter; 1383 struct slave *slave; 1384 1385 if (slot >= 0 && slot < BOND_MAX_NS_TARGETS) { 1386 bond_for_each_slave(bond, slave, iter) { 1387 slave->target_last_arp_rx[slot] = last_rx; 1388 slave_set_ns_maddr(bond, slave, target, &targets[slot]); 1389 } 1390 targets[slot] = *target; 1391 } 1392 } 1393 1394 void bond_option_ns_ip6_targets_clear(struct bonding *bond) 1395 { 1396 struct in6_addr addr_any = in6addr_any; 1397 int i; 1398 1399 for (i = 0; i < BOND_MAX_NS_TARGETS; i++) 1400 _bond_options_ns_ip6_target_set(bond, i, &addr_any, 0); 1401 } 1402 1403 static int bond_option_ns_ip6_targets_set(struct bonding *bond, 1404 const struct bond_opt_value *newval) 1405 { 1406 struct in6_addr *target = (struct in6_addr *)newval->extra; 1407 struct in6_addr *targets = bond->params.ns_targets; 1408 struct in6_addr addr_any = in6addr_any; 1409 int index; 1410 1411 if (!bond_is_ip6_target_ok(target)) { 1412 netdev_err(bond->dev, "invalid NS target %pI6c specified for addition\n", 1413 target); 1414 return -EINVAL; 1415 } 1416 1417 if (bond_get_targets_ip6(targets, target) != -1) { /* dup */ 1418 netdev_err(bond->dev, "NS target %pI6c is already present\n", 1419 target); 1420 return -EINVAL; 1421 } 1422 1423 index = bond_get_targets_ip6(targets, &addr_any); /* first free slot */ 1424 if (index == -1) { 1425 netdev_err(bond->dev, "NS target table is full!\n"); 1426 return -EINVAL; 1427 } 1428 1429 netdev_dbg(bond->dev, "Adding NS target %pI6c\n", target); 1430 1431 _bond_options_ns_ip6_target_set(bond, index, target, jiffies); 1432 1433 return 0; 1434 } 1435 #else 1436 static int bond_option_ns_ip6_targets_set(struct bonding *bond, 1437 const struct bond_opt_value *newval) 1438 { 1439 return -EPERM; 1440 } 1441 1442 static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add) {} 1443 1444 void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave) {} 1445 1446 void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave) {} 1447 #endif 1448 1449 static int bond_option_arp_validate_set(struct bonding *bond, 1450 const struct bond_opt_value *newval) 1451 { 1452 bool changed = !!bond->params.arp_validate != !!newval->value; 1453 struct list_head *iter; 1454 struct slave *slave; 1455 1456 netdev_dbg(bond->dev, "Setting arp_validate to %s (%llu)\n", 1457 newval->string, newval->value); 1458 bond->params.arp_validate = newval->value; 1459 1460 if (changed) { 1461 bond_for_each_slave(bond, slave, iter) 1462 slave_set_ns_maddrs(bond, slave, !!bond->params.arp_validate); 1463 } 1464 1465 return 0; 1466 } 1467 1468 static int bond_option_arp_all_targets_set(struct bonding *bond, 1469 const struct bond_opt_value *newval) 1470 { 1471 netdev_dbg(bond->dev, "Setting arp_all_targets to %s (%llu)\n", 1472 newval->string, newval->value); 1473 bond->params.arp_all_targets = newval->value; 1474 1475 return 0; 1476 } 1477 1478 static int bond_option_missed_max_set(struct bonding *bond, 1479 const struct bond_opt_value *newval) 1480 { 1481 netdev_dbg(bond->dev, "Setting missed max to %s (%llu)\n", 1482 newval->string, newval->value); 1483 bond->params.missed_max = newval->value; 1484 1485 return 0; 1486 } 1487 1488 static int bond_option_prio_set(struct bonding *bond, 1489 const struct bond_opt_value *newval) 1490 { 1491 struct slave *slave; 1492 1493 slave = bond_slave_get_rtnl(newval->slave_dev); 1494 if (!slave) { 1495 netdev_dbg(newval->slave_dev, "%s called on NULL slave\n", __func__); 1496 return -ENODEV; 1497 } 1498 slave->prio = newval->value; 1499 1500 if (rtnl_dereference(bond->primary_slave)) 1501 slave_warn(bond->dev, slave->dev, 1502 "prio updated, but will not affect failover re-selection as primary slave have been set\n"); 1503 else 1504 bond_select_active_slave(bond); 1505 1506 return 0; 1507 } 1508 1509 static int bond_option_primary_set(struct bonding *bond, 1510 const struct bond_opt_value *newval) 1511 { 1512 char *p, *primary = newval->string; 1513 struct list_head *iter; 1514 struct slave *slave; 1515 1516 block_netpoll_tx(); 1517 1518 p = strchr(primary, '\n'); 1519 if (p) 1520 *p = '\0'; 1521 /* check to see if we are clearing primary */ 1522 if (!strlen(primary)) { 1523 netdev_dbg(bond->dev, "Setting primary slave to None\n"); 1524 RCU_INIT_POINTER(bond->primary_slave, NULL); 1525 memset(bond->params.primary, 0, sizeof(bond->params.primary)); 1526 bond_select_active_slave(bond); 1527 goto out; 1528 } 1529 1530 bond_for_each_slave(bond, slave, iter) { 1531 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { 1532 slave_dbg(bond->dev, slave->dev, "Setting as primary slave\n"); 1533 rcu_assign_pointer(bond->primary_slave, slave); 1534 strcpy(bond->params.primary, slave->dev->name); 1535 bond->force_primary = true; 1536 bond_select_active_slave(bond); 1537 goto out; 1538 } 1539 } 1540 1541 if (rtnl_dereference(bond->primary_slave)) { 1542 netdev_dbg(bond->dev, "Setting primary slave to None\n"); 1543 RCU_INIT_POINTER(bond->primary_slave, NULL); 1544 bond_select_active_slave(bond); 1545 } 1546 strscpy_pad(bond->params.primary, primary, IFNAMSIZ); 1547 1548 netdev_dbg(bond->dev, "Recording %s as primary, but it has not been enslaved yet\n", 1549 primary); 1550 1551 out: 1552 unblock_netpoll_tx(); 1553 1554 return 0; 1555 } 1556 1557 static int bond_option_primary_reselect_set(struct bonding *bond, 1558 const struct bond_opt_value *newval) 1559 { 1560 netdev_dbg(bond->dev, "Setting primary_reselect to %s (%llu)\n", 1561 newval->string, newval->value); 1562 bond->params.primary_reselect = newval->value; 1563 1564 block_netpoll_tx(); 1565 bond_select_active_slave(bond); 1566 unblock_netpoll_tx(); 1567 1568 return 0; 1569 } 1570 1571 static int bond_option_fail_over_mac_set(struct bonding *bond, 1572 const struct bond_opt_value *newval) 1573 { 1574 netdev_dbg(bond->dev, "Setting fail_over_mac to %s (%llu)\n", 1575 newval->string, newval->value); 1576 bond->params.fail_over_mac = newval->value; 1577 1578 return 0; 1579 } 1580 1581 static int bond_option_xmit_hash_policy_set(struct bonding *bond, 1582 const struct bond_opt_value *newval) 1583 { 1584 netdev_dbg(bond->dev, "Setting xmit hash policy to %s (%llu)\n", 1585 newval->string, newval->value); 1586 bond->params.xmit_policy = newval->value; 1587 1588 return 0; 1589 } 1590 1591 static int bond_option_resend_igmp_set(struct bonding *bond, 1592 const struct bond_opt_value *newval) 1593 { 1594 netdev_dbg(bond->dev, "Setting resend_igmp to %llu\n", 1595 newval->value); 1596 bond->params.resend_igmp = newval->value; 1597 1598 return 0; 1599 } 1600 1601 static int bond_option_num_peer_notif_set(struct bonding *bond, 1602 const struct bond_opt_value *newval) 1603 { 1604 bond->params.num_peer_notif = newval->value; 1605 1606 return 0; 1607 } 1608 1609 static int bond_option_all_slaves_active_set(struct bonding *bond, 1610 const struct bond_opt_value *newval) 1611 { 1612 struct list_head *iter; 1613 struct slave *slave; 1614 1615 if (newval->value == bond->params.all_slaves_active) 1616 return 0; 1617 bond->params.all_slaves_active = newval->value; 1618 bond_for_each_slave(bond, slave, iter) { 1619 if (!bond_is_active_slave(slave)) { 1620 if (newval->value) 1621 slave->inactive = 0; 1622 else 1623 slave->inactive = 1; 1624 } 1625 } 1626 1627 return 0; 1628 } 1629 1630 static int bond_option_min_links_set(struct bonding *bond, 1631 const struct bond_opt_value *newval) 1632 { 1633 netdev_dbg(bond->dev, "Setting min links value to %llu\n", 1634 newval->value); 1635 bond->params.min_links = newval->value; 1636 bond_set_carrier(bond); 1637 1638 return 0; 1639 } 1640 1641 static int bond_option_lp_interval_set(struct bonding *bond, 1642 const struct bond_opt_value *newval) 1643 { 1644 bond->params.lp_interval = newval->value; 1645 1646 return 0; 1647 } 1648 1649 static int bond_option_pps_set(struct bonding *bond, 1650 const struct bond_opt_value *newval) 1651 { 1652 netdev_dbg(bond->dev, "Setting packets per slave to %llu\n", 1653 newval->value); 1654 bond->params.packets_per_slave = newval->value; 1655 if (newval->value > 0) { 1656 bond->params.reciprocal_packets_per_slave = 1657 reciprocal_value(newval->value); 1658 } else { 1659 /* reciprocal_packets_per_slave is unused if 1660 * packets_per_slave is 0 or 1, just initialize it 1661 */ 1662 bond->params.reciprocal_packets_per_slave = 1663 (struct reciprocal_value) { 0 }; 1664 } 1665 1666 return 0; 1667 } 1668 1669 static int bond_option_lacp_active_set(struct bonding *bond, 1670 const struct bond_opt_value *newval) 1671 { 1672 netdev_dbg(bond->dev, "Setting LACP active to %s (%llu)\n", 1673 newval->string, newval->value); 1674 bond->params.lacp_active = newval->value; 1675 bond_3ad_update_lacp_active(bond); 1676 1677 return 0; 1678 } 1679 1680 static int bond_option_lacp_rate_set(struct bonding *bond, 1681 const struct bond_opt_value *newval) 1682 { 1683 netdev_dbg(bond->dev, "Setting LACP rate to %s (%llu)\n", 1684 newval->string, newval->value); 1685 bond->params.lacp_fast = newval->value; 1686 bond_3ad_update_lacp_rate(bond); 1687 1688 return 0; 1689 } 1690 1691 static int bond_option_ad_select_set(struct bonding *bond, 1692 const struct bond_opt_value *newval) 1693 { 1694 netdev_dbg(bond->dev, "Setting ad_select to %s (%llu)\n", 1695 newval->string, newval->value); 1696 bond->params.ad_select = newval->value; 1697 1698 return 0; 1699 } 1700 1701 static int bond_option_queue_id_set(struct bonding *bond, 1702 const struct bond_opt_value *newval) 1703 { 1704 struct slave *slave, *update_slave; 1705 struct net_device *sdev; 1706 struct list_head *iter; 1707 char *delim; 1708 int ret = 0; 1709 u16 qid; 1710 1711 /* delim will point to queue id if successful */ 1712 delim = strchr(newval->string, ':'); 1713 if (!delim) 1714 goto err_no_cmd; 1715 1716 /* Terminate string that points to device name and bump it 1717 * up one, so we can read the queue id there. 1718 */ 1719 *delim = '\0'; 1720 if (sscanf(++delim, "%hd\n", &qid) != 1) 1721 goto err_no_cmd; 1722 1723 /* Check buffer length, valid ifname and queue id */ 1724 if (!dev_valid_name(newval->string) || 1725 qid > bond->dev->real_num_tx_queues) 1726 goto err_no_cmd; 1727 1728 /* Get the pointer to that interface if it exists */ 1729 sdev = __dev_get_by_name(dev_net(bond->dev), newval->string); 1730 if (!sdev) 1731 goto err_no_cmd; 1732 1733 /* Search for thes slave and check for duplicate qids */ 1734 update_slave = NULL; 1735 bond_for_each_slave(bond, slave, iter) { 1736 if (sdev == slave->dev) 1737 /* We don't need to check the matching 1738 * slave for dups, since we're overwriting it 1739 */ 1740 update_slave = slave; 1741 else if (qid && qid == slave->queue_id) { 1742 goto err_no_cmd; 1743 } 1744 } 1745 1746 if (!update_slave) 1747 goto err_no_cmd; 1748 1749 /* Actually set the qids for the slave */ 1750 WRITE_ONCE(update_slave->queue_id, qid); 1751 1752 out: 1753 return ret; 1754 1755 err_no_cmd: 1756 netdev_dbg(bond->dev, "invalid input for queue_id set\n"); 1757 ret = -EPERM; 1758 goto out; 1759 1760 } 1761 1762 static int bond_option_slaves_set(struct bonding *bond, 1763 const struct bond_opt_value *newval) 1764 { 1765 char command[IFNAMSIZ + 1] = { 0, }; 1766 struct net_device *dev; 1767 char *ifname; 1768 int ret; 1769 1770 sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/ 1771 ifname = command + 1; 1772 if ((strlen(command) <= 1) || 1773 (command[0] != '+' && command[0] != '-') || 1774 !dev_valid_name(ifname)) 1775 goto err_no_cmd; 1776 1777 dev = __dev_get_by_name(dev_net(bond->dev), ifname); 1778 if (!dev) { 1779 netdev_dbg(bond->dev, "interface %s does not exist!\n", 1780 ifname); 1781 ret = -ENODEV; 1782 goto out; 1783 } 1784 1785 switch (command[0]) { 1786 case '+': 1787 slave_dbg(bond->dev, dev, "Enslaving interface\n"); 1788 ret = bond_enslave(bond->dev, dev, NULL); 1789 break; 1790 1791 case '-': 1792 slave_dbg(bond->dev, dev, "Releasing interface\n"); 1793 ret = bond_release(bond->dev, dev); 1794 break; 1795 1796 default: 1797 /* should not run here. */ 1798 goto err_no_cmd; 1799 } 1800 1801 out: 1802 return ret; 1803 1804 err_no_cmd: 1805 netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n"); 1806 ret = -EPERM; 1807 goto out; 1808 } 1809 1810 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, 1811 const struct bond_opt_value *newval) 1812 { 1813 netdev_dbg(bond->dev, "Setting dynamic-lb to %s (%llu)\n", 1814 newval->string, newval->value); 1815 bond->params.tlb_dynamic_lb = newval->value; 1816 1817 return 0; 1818 } 1819 1820 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond, 1821 const struct bond_opt_value *newval) 1822 { 1823 netdev_dbg(bond->dev, "Setting ad_actor_sys_prio to %llu\n", 1824 newval->value); 1825 1826 bond->params.ad_actor_sys_prio = newval->value; 1827 bond_3ad_update_ad_actor_settings(bond); 1828 1829 return 0; 1830 } 1831 1832 static int bond_option_actor_port_prio_set(struct bonding *bond, 1833 const struct bond_opt_value *newval) 1834 { 1835 struct slave *slave; 1836 1837 slave = bond_slave_get_rtnl(newval->slave_dev); 1838 if (!slave) { 1839 netdev_dbg(bond->dev, "%s called on NULL slave\n", __func__); 1840 return -ENODEV; 1841 } 1842 1843 netdev_dbg(newval->slave_dev, "Setting actor_port_prio to %llu\n", 1844 newval->value); 1845 1846 SLAVE_AD_INFO(slave)->port_priority = newval->value; 1847 bond_3ad_update_ad_actor_settings(bond); 1848 1849 return 0; 1850 } 1851 1852 static int bond_option_ad_actor_system_set(struct bonding *bond, 1853 const struct bond_opt_value *newval) 1854 { 1855 u8 macaddr[ETH_ALEN]; 1856 u8 *mac; 1857 1858 if (newval->string) { 1859 if (!mac_pton(newval->string, macaddr)) 1860 goto err; 1861 mac = macaddr; 1862 } else { 1863 mac = (u8 *)&newval->value; 1864 } 1865 1866 if (is_multicast_ether_addr(mac)) 1867 goto err; 1868 1869 netdev_dbg(bond->dev, "Setting ad_actor_system to %pM\n", mac); 1870 ether_addr_copy(bond->params.ad_actor_system, mac); 1871 bond_3ad_update_ad_actor_settings(bond); 1872 1873 return 0; 1874 1875 err: 1876 netdev_err(bond->dev, "Invalid ad_actor_system MAC address.\n"); 1877 return -EINVAL; 1878 } 1879 1880 static int bond_option_ad_user_port_key_set(struct bonding *bond, 1881 const struct bond_opt_value *newval) 1882 { 1883 netdev_dbg(bond->dev, "Setting ad_user_port_key to %llu\n", 1884 newval->value); 1885 1886 bond->params.ad_user_port_key = newval->value; 1887 return 0; 1888 } 1889 1890 static int bond_option_coupled_control_set(struct bonding *bond, 1891 const struct bond_opt_value *newval) 1892 { 1893 netdev_info(bond->dev, "Setting coupled_control to %s (%llu)\n", 1894 newval->string, newval->value); 1895 1896 bond->params.coupled_control = newval->value; 1897 return 0; 1898 } 1899 1900 static int bond_option_broadcast_neigh_set(struct bonding *bond, 1901 const struct bond_opt_value *newval) 1902 { 1903 if (bond->params.broadcast_neighbor == newval->value) 1904 return 0; 1905 1906 bond->params.broadcast_neighbor = newval->value; 1907 if (bond->dev->flags & IFF_UP) { 1908 if (bond->params.broadcast_neighbor) 1909 static_branch_inc(&bond_bcast_neigh_enabled); 1910 else 1911 static_branch_dec(&bond_bcast_neigh_enabled); 1912 } 1913 1914 netdev_dbg(bond->dev, "Setting broadcast_neighbor to %s (%llu)\n", 1915 newval->string, newval->value); 1916 return 0; 1917 } 1918