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