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