| .. | .. |
|---|
| 41 | 41 | #include <linux/in.h> |
|---|
| 42 | 42 | #include <net/ip.h> |
|---|
| 43 | 43 | #include <linux/ip.h> |
|---|
| 44 | +#include <linux/icmp.h> |
|---|
| 45 | +#include <linux/icmpv6.h> |
|---|
| 44 | 46 | #include <linux/tcp.h> |
|---|
| 45 | 47 | #include <linux/udp.h> |
|---|
| 46 | 48 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 77 | 79 | #include <net/pkt_sched.h> |
|---|
| 78 | 80 | #include <linux/rculist.h> |
|---|
| 79 | 81 | #include <net/flow_dissector.h> |
|---|
| 80 | | -#include <net/switchdev.h> |
|---|
| 82 | +#include <net/xfrm.h> |
|---|
| 81 | 83 | #include <net/bonding.h> |
|---|
| 82 | 84 | #include <net/bond_3ad.h> |
|---|
| 83 | 85 | #include <net/bond_alb.h> |
|---|
| .. | .. |
|---|
| 201 | 203 | |
|---|
| 202 | 204 | unsigned int bond_net_id __read_mostly; |
|---|
| 203 | 205 | |
|---|
| 206 | +static const struct flow_dissector_key flow_keys_bonding_keys[] = { |
|---|
| 207 | + { |
|---|
| 208 | + .key_id = FLOW_DISSECTOR_KEY_CONTROL, |
|---|
| 209 | + .offset = offsetof(struct flow_keys, control), |
|---|
| 210 | + }, |
|---|
| 211 | + { |
|---|
| 212 | + .key_id = FLOW_DISSECTOR_KEY_BASIC, |
|---|
| 213 | + .offset = offsetof(struct flow_keys, basic), |
|---|
| 214 | + }, |
|---|
| 215 | + { |
|---|
| 216 | + .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS, |
|---|
| 217 | + .offset = offsetof(struct flow_keys, addrs.v4addrs), |
|---|
| 218 | + }, |
|---|
| 219 | + { |
|---|
| 220 | + .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS, |
|---|
| 221 | + .offset = offsetof(struct flow_keys, addrs.v6addrs), |
|---|
| 222 | + }, |
|---|
| 223 | + { |
|---|
| 224 | + .key_id = FLOW_DISSECTOR_KEY_TIPC, |
|---|
| 225 | + .offset = offsetof(struct flow_keys, addrs.tipckey), |
|---|
| 226 | + }, |
|---|
| 227 | + { |
|---|
| 228 | + .key_id = FLOW_DISSECTOR_KEY_PORTS, |
|---|
| 229 | + .offset = offsetof(struct flow_keys, ports), |
|---|
| 230 | + }, |
|---|
| 231 | + { |
|---|
| 232 | + .key_id = FLOW_DISSECTOR_KEY_ICMP, |
|---|
| 233 | + .offset = offsetof(struct flow_keys, icmp), |
|---|
| 234 | + }, |
|---|
| 235 | + { |
|---|
| 236 | + .key_id = FLOW_DISSECTOR_KEY_VLAN, |
|---|
| 237 | + .offset = offsetof(struct flow_keys, vlan), |
|---|
| 238 | + }, |
|---|
| 239 | + { |
|---|
| 240 | + .key_id = FLOW_DISSECTOR_KEY_FLOW_LABEL, |
|---|
| 241 | + .offset = offsetof(struct flow_keys, tags), |
|---|
| 242 | + }, |
|---|
| 243 | + { |
|---|
| 244 | + .key_id = FLOW_DISSECTOR_KEY_GRE_KEYID, |
|---|
| 245 | + .offset = offsetof(struct flow_keys, keyid), |
|---|
| 246 | + }, |
|---|
| 247 | +}; |
|---|
| 248 | + |
|---|
| 249 | +static struct flow_dissector flow_keys_bonding __read_mostly; |
|---|
| 250 | + |
|---|
| 204 | 251 | /*-------------------------- Forward declarations ---------------------------*/ |
|---|
| 205 | 252 | |
|---|
| 206 | 253 | static int bond_init(struct net_device *bond_dev); |
|---|
| .. | .. |
|---|
| 232 | 279 | return names[mode]; |
|---|
| 233 | 280 | } |
|---|
| 234 | 281 | |
|---|
| 235 | | -/*---------------------------------- VLAN -----------------------------------*/ |
|---|
| 236 | | - |
|---|
| 237 | 282 | /** |
|---|
| 238 | 283 | * bond_dev_queue_xmit - Prepare skb for xmit. |
|---|
| 239 | 284 | * |
|---|
| .. | .. |
|---|
| 241 | 286 | * @skb: hw accel VLAN tagged skb to transmit |
|---|
| 242 | 287 | * @slave_dev: slave that is supposed to xmit this skbuff |
|---|
| 243 | 288 | */ |
|---|
| 244 | | -void bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, |
|---|
| 289 | +netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, |
|---|
| 245 | 290 | struct net_device *slave_dev) |
|---|
| 246 | 291 | { |
|---|
| 247 | 292 | skb->dev = slave_dev; |
|---|
| .. | .. |
|---|
| 251 | 296 | skb_set_queue_mapping(skb, qdisc_skb_cb(skb)->slave_dev_queue_mapping); |
|---|
| 252 | 297 | |
|---|
| 253 | 298 | if (unlikely(netpoll_tx_running(bond->dev))) |
|---|
| 254 | | - bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb); |
|---|
| 255 | | - else |
|---|
| 256 | | - dev_queue_xmit(skb); |
|---|
| 299 | + return bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb); |
|---|
| 300 | + |
|---|
| 301 | + return dev_queue_xmit(skb); |
|---|
| 257 | 302 | } |
|---|
| 303 | + |
|---|
| 304 | +/*---------------------------------- VLAN -----------------------------------*/ |
|---|
| 258 | 305 | |
|---|
| 259 | 306 | /* In the following 2 functions, bond_vlan_rx_add_vid and bond_vlan_rx_kill_vid, |
|---|
| 260 | 307 | * We don't protect the slave list iteration with a lock because: |
|---|
| .. | .. |
|---|
| 275 | 322 | /** |
|---|
| 276 | 323 | * bond_vlan_rx_add_vid - Propagates adding an id to slaves |
|---|
| 277 | 324 | * @bond_dev: bonding net device that got called |
|---|
| 325 | + * @proto: network protocol ID |
|---|
| 278 | 326 | * @vid: vlan id being added |
|---|
| 279 | 327 | */ |
|---|
| 280 | 328 | static int bond_vlan_rx_add_vid(struct net_device *bond_dev, |
|---|
| .. | .. |
|---|
| 308 | 356 | /** |
|---|
| 309 | 357 | * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves |
|---|
| 310 | 358 | * @bond_dev: bonding net device that got called |
|---|
| 359 | + * @proto: network protocol ID |
|---|
| 311 | 360 | * @vid: vlan id being removed |
|---|
| 312 | 361 | */ |
|---|
| 313 | 362 | static int bond_vlan_rx_kill_vid(struct net_device *bond_dev, |
|---|
| .. | .. |
|---|
| 325 | 374 | |
|---|
| 326 | 375 | return 0; |
|---|
| 327 | 376 | } |
|---|
| 377 | + |
|---|
| 378 | +/*---------------------------------- XFRM -----------------------------------*/ |
|---|
| 379 | + |
|---|
| 380 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 381 | +/** |
|---|
| 382 | + * bond_ipsec_add_sa - program device with a security association |
|---|
| 383 | + * @xs: pointer to transformer state struct |
|---|
| 384 | + **/ |
|---|
| 385 | +static int bond_ipsec_add_sa(struct xfrm_state *xs) |
|---|
| 386 | +{ |
|---|
| 387 | + struct net_device *bond_dev = xs->xso.dev; |
|---|
| 388 | + struct bond_ipsec *ipsec; |
|---|
| 389 | + struct bonding *bond; |
|---|
| 390 | + struct slave *slave; |
|---|
| 391 | + int err; |
|---|
| 392 | + |
|---|
| 393 | + if (!bond_dev) |
|---|
| 394 | + return -EINVAL; |
|---|
| 395 | + |
|---|
| 396 | + rcu_read_lock(); |
|---|
| 397 | + bond = netdev_priv(bond_dev); |
|---|
| 398 | + slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 399 | + if (!slave) { |
|---|
| 400 | + rcu_read_unlock(); |
|---|
| 401 | + return -ENODEV; |
|---|
| 402 | + } |
|---|
| 403 | + |
|---|
| 404 | + if (!slave->dev->xfrmdev_ops || |
|---|
| 405 | + !slave->dev->xfrmdev_ops->xdo_dev_state_add || |
|---|
| 406 | + netif_is_bond_master(slave->dev)) { |
|---|
| 407 | + slave_warn(bond_dev, slave->dev, "Slave does not support ipsec offload\n"); |
|---|
| 408 | + rcu_read_unlock(); |
|---|
| 409 | + return -EINVAL; |
|---|
| 410 | + } |
|---|
| 411 | + |
|---|
| 412 | + ipsec = kmalloc(sizeof(*ipsec), GFP_ATOMIC); |
|---|
| 413 | + if (!ipsec) { |
|---|
| 414 | + rcu_read_unlock(); |
|---|
| 415 | + return -ENOMEM; |
|---|
| 416 | + } |
|---|
| 417 | + xs->xso.real_dev = slave->dev; |
|---|
| 418 | + |
|---|
| 419 | + err = slave->dev->xfrmdev_ops->xdo_dev_state_add(xs); |
|---|
| 420 | + if (!err) { |
|---|
| 421 | + ipsec->xs = xs; |
|---|
| 422 | + INIT_LIST_HEAD(&ipsec->list); |
|---|
| 423 | + spin_lock_bh(&bond->ipsec_lock); |
|---|
| 424 | + list_add(&ipsec->list, &bond->ipsec_list); |
|---|
| 425 | + spin_unlock_bh(&bond->ipsec_lock); |
|---|
| 426 | + } else { |
|---|
| 427 | + kfree(ipsec); |
|---|
| 428 | + } |
|---|
| 429 | + rcu_read_unlock(); |
|---|
| 430 | + return err; |
|---|
| 431 | +} |
|---|
| 432 | + |
|---|
| 433 | +static void bond_ipsec_add_sa_all(struct bonding *bond) |
|---|
| 434 | +{ |
|---|
| 435 | + struct net_device *bond_dev = bond->dev; |
|---|
| 436 | + struct bond_ipsec *ipsec; |
|---|
| 437 | + struct slave *slave; |
|---|
| 438 | + |
|---|
| 439 | + rcu_read_lock(); |
|---|
| 440 | + slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 441 | + if (!slave) |
|---|
| 442 | + goto out; |
|---|
| 443 | + |
|---|
| 444 | + if (!slave->dev->xfrmdev_ops || |
|---|
| 445 | + !slave->dev->xfrmdev_ops->xdo_dev_state_add || |
|---|
| 446 | + netif_is_bond_master(slave->dev)) { |
|---|
| 447 | + spin_lock_bh(&bond->ipsec_lock); |
|---|
| 448 | + if (!list_empty(&bond->ipsec_list)) |
|---|
| 449 | + slave_warn(bond_dev, slave->dev, |
|---|
| 450 | + "%s: no slave xdo_dev_state_add\n", |
|---|
| 451 | + __func__); |
|---|
| 452 | + spin_unlock_bh(&bond->ipsec_lock); |
|---|
| 453 | + goto out; |
|---|
| 454 | + } |
|---|
| 455 | + |
|---|
| 456 | + spin_lock_bh(&bond->ipsec_lock); |
|---|
| 457 | + list_for_each_entry(ipsec, &bond->ipsec_list, list) { |
|---|
| 458 | + ipsec->xs->xso.real_dev = slave->dev; |
|---|
| 459 | + if (slave->dev->xfrmdev_ops->xdo_dev_state_add(ipsec->xs)) { |
|---|
| 460 | + slave_warn(bond_dev, slave->dev, "%s: failed to add SA\n", __func__); |
|---|
| 461 | + ipsec->xs->xso.real_dev = NULL; |
|---|
| 462 | + } |
|---|
| 463 | + } |
|---|
| 464 | + spin_unlock_bh(&bond->ipsec_lock); |
|---|
| 465 | +out: |
|---|
| 466 | + rcu_read_unlock(); |
|---|
| 467 | +} |
|---|
| 468 | + |
|---|
| 469 | +/** |
|---|
| 470 | + * bond_ipsec_del_sa - clear out this specific SA |
|---|
| 471 | + * @xs: pointer to transformer state struct |
|---|
| 472 | + **/ |
|---|
| 473 | +static void bond_ipsec_del_sa(struct xfrm_state *xs) |
|---|
| 474 | +{ |
|---|
| 475 | + struct net_device *bond_dev = xs->xso.dev; |
|---|
| 476 | + struct bond_ipsec *ipsec; |
|---|
| 477 | + struct bonding *bond; |
|---|
| 478 | + struct slave *slave; |
|---|
| 479 | + |
|---|
| 480 | + if (!bond_dev) |
|---|
| 481 | + return; |
|---|
| 482 | + |
|---|
| 483 | + rcu_read_lock(); |
|---|
| 484 | + bond = netdev_priv(bond_dev); |
|---|
| 485 | + slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 486 | + |
|---|
| 487 | + if (!slave) |
|---|
| 488 | + goto out; |
|---|
| 489 | + |
|---|
| 490 | + if (!xs->xso.real_dev) |
|---|
| 491 | + goto out; |
|---|
| 492 | + |
|---|
| 493 | + WARN_ON(xs->xso.real_dev != slave->dev); |
|---|
| 494 | + |
|---|
| 495 | + if (!slave->dev->xfrmdev_ops || |
|---|
| 496 | + !slave->dev->xfrmdev_ops->xdo_dev_state_delete || |
|---|
| 497 | + netif_is_bond_master(slave->dev)) { |
|---|
| 498 | + slave_warn(bond_dev, slave->dev, "%s: no slave xdo_dev_state_delete\n", __func__); |
|---|
| 499 | + goto out; |
|---|
| 500 | + } |
|---|
| 501 | + |
|---|
| 502 | + slave->dev->xfrmdev_ops->xdo_dev_state_delete(xs); |
|---|
| 503 | +out: |
|---|
| 504 | + spin_lock_bh(&bond->ipsec_lock); |
|---|
| 505 | + list_for_each_entry(ipsec, &bond->ipsec_list, list) { |
|---|
| 506 | + if (ipsec->xs == xs) { |
|---|
| 507 | + list_del(&ipsec->list); |
|---|
| 508 | + kfree(ipsec); |
|---|
| 509 | + break; |
|---|
| 510 | + } |
|---|
| 511 | + } |
|---|
| 512 | + spin_unlock_bh(&bond->ipsec_lock); |
|---|
| 513 | + rcu_read_unlock(); |
|---|
| 514 | +} |
|---|
| 515 | + |
|---|
| 516 | +static void bond_ipsec_del_sa_all(struct bonding *bond) |
|---|
| 517 | +{ |
|---|
| 518 | + struct net_device *bond_dev = bond->dev; |
|---|
| 519 | + struct bond_ipsec *ipsec; |
|---|
| 520 | + struct slave *slave; |
|---|
| 521 | + |
|---|
| 522 | + rcu_read_lock(); |
|---|
| 523 | + slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 524 | + if (!slave) { |
|---|
| 525 | + rcu_read_unlock(); |
|---|
| 526 | + return; |
|---|
| 527 | + } |
|---|
| 528 | + |
|---|
| 529 | + spin_lock_bh(&bond->ipsec_lock); |
|---|
| 530 | + list_for_each_entry(ipsec, &bond->ipsec_list, list) { |
|---|
| 531 | + if (!ipsec->xs->xso.real_dev) |
|---|
| 532 | + continue; |
|---|
| 533 | + |
|---|
| 534 | + if (!slave->dev->xfrmdev_ops || |
|---|
| 535 | + !slave->dev->xfrmdev_ops->xdo_dev_state_delete || |
|---|
| 536 | + netif_is_bond_master(slave->dev)) { |
|---|
| 537 | + slave_warn(bond_dev, slave->dev, |
|---|
| 538 | + "%s: no slave xdo_dev_state_delete\n", |
|---|
| 539 | + __func__); |
|---|
| 540 | + } else { |
|---|
| 541 | + slave->dev->xfrmdev_ops->xdo_dev_state_delete(ipsec->xs); |
|---|
| 542 | + } |
|---|
| 543 | + ipsec->xs->xso.real_dev = NULL; |
|---|
| 544 | + } |
|---|
| 545 | + spin_unlock_bh(&bond->ipsec_lock); |
|---|
| 546 | + rcu_read_unlock(); |
|---|
| 547 | +} |
|---|
| 548 | + |
|---|
| 549 | +/** |
|---|
| 550 | + * bond_ipsec_offload_ok - can this packet use the xfrm hw offload |
|---|
| 551 | + * @skb: current data packet |
|---|
| 552 | + * @xs: pointer to transformer state struct |
|---|
| 553 | + **/ |
|---|
| 554 | +static bool bond_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs) |
|---|
| 555 | +{ |
|---|
| 556 | + struct net_device *bond_dev = xs->xso.dev; |
|---|
| 557 | + struct net_device *real_dev; |
|---|
| 558 | + struct slave *curr_active; |
|---|
| 559 | + struct bonding *bond; |
|---|
| 560 | + int err; |
|---|
| 561 | + |
|---|
| 562 | + bond = netdev_priv(bond_dev); |
|---|
| 563 | + rcu_read_lock(); |
|---|
| 564 | + curr_active = rcu_dereference(bond->curr_active_slave); |
|---|
| 565 | + real_dev = curr_active->dev; |
|---|
| 566 | + |
|---|
| 567 | + if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) { |
|---|
| 568 | + err = false; |
|---|
| 569 | + goto out; |
|---|
| 570 | + } |
|---|
| 571 | + |
|---|
| 572 | + if (!xs->xso.real_dev) { |
|---|
| 573 | + err = false; |
|---|
| 574 | + goto out; |
|---|
| 575 | + } |
|---|
| 576 | + |
|---|
| 577 | + if (!real_dev->xfrmdev_ops || |
|---|
| 578 | + !real_dev->xfrmdev_ops->xdo_dev_offload_ok || |
|---|
| 579 | + netif_is_bond_master(real_dev)) { |
|---|
| 580 | + err = false; |
|---|
| 581 | + goto out; |
|---|
| 582 | + } |
|---|
| 583 | + |
|---|
| 584 | + err = real_dev->xfrmdev_ops->xdo_dev_offload_ok(skb, xs); |
|---|
| 585 | +out: |
|---|
| 586 | + rcu_read_unlock(); |
|---|
| 587 | + return err; |
|---|
| 588 | +} |
|---|
| 589 | + |
|---|
| 590 | +static const struct xfrmdev_ops bond_xfrmdev_ops = { |
|---|
| 591 | + .xdo_dev_state_add = bond_ipsec_add_sa, |
|---|
| 592 | + .xdo_dev_state_delete = bond_ipsec_del_sa, |
|---|
| 593 | + .xdo_dev_offload_ok = bond_ipsec_offload_ok, |
|---|
| 594 | +}; |
|---|
| 595 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 328 | 596 | |
|---|
| 329 | 597 | /*------------------------------- Link status -------------------------------*/ |
|---|
| 330 | 598 | |
|---|
| .. | .. |
|---|
| 559 | 827 | dev_uc_unsync(slave_dev, bond_dev); |
|---|
| 560 | 828 | dev_mc_unsync(slave_dev, bond_dev); |
|---|
| 561 | 829 | |
|---|
| 562 | | - if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
|---|
| 563 | | - /* del lacpdu mc addr from mc list */ |
|---|
| 564 | | - u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
|---|
| 565 | | - |
|---|
| 566 | | - dev_mc_del(slave_dev, lacpdu_multicast); |
|---|
| 567 | | - } |
|---|
| 830 | + if (BOND_MODE(bond) == BOND_MODE_8023AD) |
|---|
| 831 | + dev_mc_del(slave_dev, lacpdu_mcast_addr); |
|---|
| 568 | 832 | } |
|---|
| 569 | 833 | |
|---|
| 570 | 834 | /*--------------------------- Active slave change ---------------------------*/ |
|---|
| .. | .. |
|---|
| 584 | 848 | if (bond->dev->flags & IFF_ALLMULTI) |
|---|
| 585 | 849 | dev_set_allmulti(old_active->dev, -1); |
|---|
| 586 | 850 | |
|---|
| 587 | | - bond_hw_addr_flush(bond->dev, old_active->dev); |
|---|
| 851 | + if (bond->dev->flags & IFF_UP) |
|---|
| 852 | + bond_hw_addr_flush(bond->dev, old_active->dev); |
|---|
| 588 | 853 | } |
|---|
| 589 | 854 | |
|---|
| 590 | 855 | if (new_active) { |
|---|
| .. | .. |
|---|
| 595 | 860 | if (bond->dev->flags & IFF_ALLMULTI) |
|---|
| 596 | 861 | dev_set_allmulti(new_active->dev, 1); |
|---|
| 597 | 862 | |
|---|
| 598 | | - netif_addr_lock_bh(bond->dev); |
|---|
| 599 | | - dev_uc_sync(new_active->dev, bond->dev); |
|---|
| 600 | | - dev_mc_sync(new_active->dev, bond->dev); |
|---|
| 601 | | - netif_addr_unlock_bh(bond->dev); |
|---|
| 863 | + if (bond->dev->flags & IFF_UP) { |
|---|
| 864 | + netif_addr_lock_bh(bond->dev); |
|---|
| 865 | + dev_uc_sync(new_active->dev, bond->dev); |
|---|
| 866 | + dev_mc_sync(new_active->dev, bond->dev); |
|---|
| 867 | + netif_addr_unlock_bh(bond->dev); |
|---|
| 868 | + } |
|---|
| 602 | 869 | } |
|---|
| 603 | 870 | } |
|---|
| 604 | 871 | |
|---|
| .. | .. |
|---|
| 609 | 876 | * |
|---|
| 610 | 877 | * Should be called with RTNL held. |
|---|
| 611 | 878 | */ |
|---|
| 612 | | -static void bond_set_dev_addr(struct net_device *bond_dev, |
|---|
| 613 | | - struct net_device *slave_dev) |
|---|
| 879 | +static int bond_set_dev_addr(struct net_device *bond_dev, |
|---|
| 880 | + struct net_device *slave_dev) |
|---|
| 614 | 881 | { |
|---|
| 615 | | - netdev_dbg(bond_dev, "bond_dev=%p slave_dev=%p slave_dev->name=%s slave_dev->addr_len=%d\n", |
|---|
| 616 | | - bond_dev, slave_dev, slave_dev->name, slave_dev->addr_len); |
|---|
| 882 | + int err; |
|---|
| 883 | + |
|---|
| 884 | + slave_dbg(bond_dev, slave_dev, "bond_dev=%p slave_dev=%p slave_dev->addr_len=%d\n", |
|---|
| 885 | + bond_dev, slave_dev, slave_dev->addr_len); |
|---|
| 886 | + err = dev_pre_changeaddr_notify(bond_dev, slave_dev->dev_addr, NULL); |
|---|
| 887 | + if (err) |
|---|
| 888 | + return err; |
|---|
| 889 | + |
|---|
| 617 | 890 | memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len); |
|---|
| 618 | 891 | bond_dev->addr_assign_type = NET_ADDR_STOLEN; |
|---|
| 619 | 892 | call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev); |
|---|
| 893 | + return 0; |
|---|
| 620 | 894 | } |
|---|
| 621 | 895 | |
|---|
| 622 | 896 | static struct slave *bond_get_old_active(struct bonding *bond, |
|---|
| .. | .. |
|---|
| 652 | 926 | |
|---|
| 653 | 927 | switch (bond->params.fail_over_mac) { |
|---|
| 654 | 928 | case BOND_FOM_ACTIVE: |
|---|
| 655 | | - if (new_active) |
|---|
| 656 | | - bond_set_dev_addr(bond->dev, new_active->dev); |
|---|
| 929 | + if (new_active) { |
|---|
| 930 | + rv = bond_set_dev_addr(bond->dev, new_active->dev); |
|---|
| 931 | + if (rv) |
|---|
| 932 | + slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n", |
|---|
| 933 | + -rv); |
|---|
| 934 | + } |
|---|
| 657 | 935 | break; |
|---|
| 658 | 936 | case BOND_FOM_FOLLOW: |
|---|
| 659 | 937 | /* if new_active && old_active, swap them |
|---|
| .. | .. |
|---|
| 680 | 958 | } |
|---|
| 681 | 959 | |
|---|
| 682 | 960 | rv = dev_set_mac_address(new_active->dev, |
|---|
| 683 | | - (struct sockaddr *)&ss); |
|---|
| 961 | + (struct sockaddr *)&ss, NULL); |
|---|
| 684 | 962 | if (rv) { |
|---|
| 685 | | - netdev_err(bond->dev, "Error %d setting MAC of slave %s\n", |
|---|
| 686 | | - -rv, new_active->dev->name); |
|---|
| 963 | + slave_err(bond->dev, new_active->dev, "Error %d setting MAC of new active slave\n", |
|---|
| 964 | + -rv); |
|---|
| 687 | 965 | goto out; |
|---|
| 688 | 966 | } |
|---|
| 689 | 967 | |
|---|
| .. | .. |
|---|
| 695 | 973 | ss.ss_family = old_active->dev->type; |
|---|
| 696 | 974 | |
|---|
| 697 | 975 | rv = dev_set_mac_address(old_active->dev, |
|---|
| 698 | | - (struct sockaddr *)&ss); |
|---|
| 976 | + (struct sockaddr *)&ss, NULL); |
|---|
| 699 | 977 | if (rv) |
|---|
| 700 | | - netdev_err(bond->dev, "Error %d setting MAC of slave %s\n", |
|---|
| 701 | | - -rv, new_active->dev->name); |
|---|
| 978 | + slave_err(bond->dev, old_active->dev, "Error %d setting MAC of old active slave\n", |
|---|
| 979 | + -rv); |
|---|
| 702 | 980 | out: |
|---|
| 703 | 981 | break; |
|---|
| 704 | 982 | default: |
|---|
| .. | .. |
|---|
| 783 | 1061 | rcu_read_unlock(); |
|---|
| 784 | 1062 | |
|---|
| 785 | 1063 | if (!slave || !bond->send_peer_notif || |
|---|
| 1064 | + bond->send_peer_notif % |
|---|
| 1065 | + max(1, bond->params.peer_notif_delay) != 0 || |
|---|
| 786 | 1066 | !netif_carrier_ok(bond->dev) || |
|---|
| 787 | 1067 | test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state)) |
|---|
| 788 | 1068 | return false; |
|---|
| .. | .. |
|---|
| 796 | 1076 | /** |
|---|
| 797 | 1077 | * change_active_interface - change the active slave into the specified one |
|---|
| 798 | 1078 | * @bond: our bonding struct |
|---|
| 799 | | - * @new: the new slave to make the active one |
|---|
| 1079 | + * @new_active: the new slave to make the active one |
|---|
| 800 | 1080 | * |
|---|
| 801 | 1081 | * Set the new slave to the bond's settings and unset them on the old |
|---|
| 802 | 1082 | * curr_active_slave. |
|---|
| .. | .. |
|---|
| 819 | 1099 | if (old_active == new_active) |
|---|
| 820 | 1100 | return; |
|---|
| 821 | 1101 | |
|---|
| 1102 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 1103 | + bond_ipsec_del_sa_all(bond); |
|---|
| 1104 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 1105 | + |
|---|
| 822 | 1106 | if (new_active) { |
|---|
| 823 | 1107 | new_active->last_link_up = jiffies; |
|---|
| 824 | 1108 | |
|---|
| 825 | 1109 | if (new_active->link == BOND_LINK_BACK) { |
|---|
| 826 | 1110 | if (bond_uses_primary(bond)) { |
|---|
| 827 | | - netdev_info(bond->dev, "making interface %s the new active one %d ms earlier\n", |
|---|
| 828 | | - new_active->dev->name, |
|---|
| 829 | | - (bond->params.updelay - new_active->delay) * bond->params.miimon); |
|---|
| 1111 | + slave_info(bond->dev, new_active->dev, "making interface the new active one %d ms earlier\n", |
|---|
| 1112 | + (bond->params.updelay - new_active->delay) * bond->params.miimon); |
|---|
| 830 | 1113 | } |
|---|
| 831 | 1114 | |
|---|
| 832 | 1115 | new_active->delay = 0; |
|---|
| .. | .. |
|---|
| 840 | 1123 | bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP); |
|---|
| 841 | 1124 | } else { |
|---|
| 842 | 1125 | if (bond_uses_primary(bond)) { |
|---|
| 843 | | - netdev_info(bond->dev, "making interface %s the new active one\n", |
|---|
| 844 | | - new_active->dev->name); |
|---|
| 1126 | + slave_info(bond->dev, new_active->dev, "making interface the new active one\n"); |
|---|
| 845 | 1127 | } |
|---|
| 846 | 1128 | } |
|---|
| 847 | 1129 | } |
|---|
| .. | .. |
|---|
| 878 | 1160 | |
|---|
| 879 | 1161 | if (netif_running(bond->dev)) { |
|---|
| 880 | 1162 | bond->send_peer_notif = |
|---|
| 881 | | - bond->params.num_peer_notif; |
|---|
| 1163 | + bond->params.num_peer_notif * |
|---|
| 1164 | + max(1, bond->params.peer_notif_delay); |
|---|
| 882 | 1165 | should_notify_peers = |
|---|
| 883 | 1166 | bond_should_notify_peers(bond); |
|---|
| 884 | 1167 | } |
|---|
| 885 | 1168 | |
|---|
| 886 | 1169 | call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev); |
|---|
| 887 | | - if (should_notify_peers) |
|---|
| 1170 | + if (should_notify_peers) { |
|---|
| 1171 | + bond->send_peer_notif--; |
|---|
| 888 | 1172 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, |
|---|
| 889 | 1173 | bond->dev); |
|---|
| 1174 | + } |
|---|
| 890 | 1175 | } |
|---|
| 891 | 1176 | } |
|---|
| 1177 | + |
|---|
| 1178 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 1179 | + bond_ipsec_add_sa_all(bond); |
|---|
| 1180 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 892 | 1181 | |
|---|
| 893 | 1182 | /* resend IGMP joins since active slave has changed or |
|---|
| 894 | 1183 | * all were sent on curr_active_slave. |
|---|
| .. | .. |
|---|
| 929 | 1218 | return; |
|---|
| 930 | 1219 | |
|---|
| 931 | 1220 | if (netif_carrier_ok(bond->dev)) |
|---|
| 932 | | - netdev_info(bond->dev, "first active interface up!\n"); |
|---|
| 1221 | + netdev_info(bond->dev, "active interface up!\n"); |
|---|
| 933 | 1222 | else |
|---|
| 934 | 1223 | netdev_info(bond->dev, "now running without any active interface!\n"); |
|---|
| 935 | 1224 | } |
|---|
| .. | .. |
|---|
| 963 | 1252 | return; |
|---|
| 964 | 1253 | |
|---|
| 965 | 1254 | slave->np = NULL; |
|---|
| 966 | | - __netpoll_free_async(np); |
|---|
| 1255 | + |
|---|
| 1256 | + __netpoll_free(np); |
|---|
| 967 | 1257 | } |
|---|
| 968 | 1258 | |
|---|
| 969 | 1259 | static void bond_poll_controller(struct net_device *bond_dev) |
|---|
| .. | .. |
|---|
| 1066 | 1356 | #define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \ |
|---|
| 1067 | 1357 | NETIF_F_RXCSUM | NETIF_F_ALL_TSO) |
|---|
| 1068 | 1358 | |
|---|
| 1359 | +#define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \ |
|---|
| 1360 | + NETIF_F_ALL_TSO) |
|---|
| 1361 | + |
|---|
| 1362 | + |
|---|
| 1069 | 1363 | static void bond_compute_features(struct bonding *bond) |
|---|
| 1070 | 1364 | { |
|---|
| 1071 | 1365 | unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE | |
|---|
| 1072 | 1366 | IFF_XMIT_DST_RELEASE_PERM; |
|---|
| 1073 | 1367 | netdev_features_t vlan_features = BOND_VLAN_FEATURES; |
|---|
| 1074 | 1368 | netdev_features_t enc_features = BOND_ENC_FEATURES; |
|---|
| 1369 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 1370 | + netdev_features_t xfrm_features = BOND_XFRM_FEATURES; |
|---|
| 1371 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 1372 | + netdev_features_t mpls_features = BOND_MPLS_FEATURES; |
|---|
| 1075 | 1373 | struct net_device *bond_dev = bond->dev; |
|---|
| 1076 | 1374 | struct list_head *iter; |
|---|
| 1077 | 1375 | struct slave *slave; |
|---|
| .. | .. |
|---|
| 1082 | 1380 | if (!bond_has_slaves(bond)) |
|---|
| 1083 | 1381 | goto done; |
|---|
| 1084 | 1382 | vlan_features &= NETIF_F_ALL_FOR_ALL; |
|---|
| 1383 | + mpls_features &= NETIF_F_ALL_FOR_ALL; |
|---|
| 1085 | 1384 | |
|---|
| 1086 | 1385 | bond_for_each_slave(bond, slave, iter) { |
|---|
| 1087 | 1386 | vlan_features = netdev_increment_features(vlan_features, |
|---|
| .. | .. |
|---|
| 1090 | 1389 | enc_features = netdev_increment_features(enc_features, |
|---|
| 1091 | 1390 | slave->dev->hw_enc_features, |
|---|
| 1092 | 1391 | BOND_ENC_FEATURES); |
|---|
| 1392 | + |
|---|
| 1393 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 1394 | + xfrm_features = netdev_increment_features(xfrm_features, |
|---|
| 1395 | + slave->dev->hw_enc_features, |
|---|
| 1396 | + BOND_XFRM_FEATURES); |
|---|
| 1397 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 1398 | + |
|---|
| 1399 | + mpls_features = netdev_increment_features(mpls_features, |
|---|
| 1400 | + slave->dev->mpls_features, |
|---|
| 1401 | + BOND_MPLS_FEATURES); |
|---|
| 1402 | + |
|---|
| 1093 | 1403 | dst_release_flag &= slave->dev->priv_flags; |
|---|
| 1094 | 1404 | if (slave->dev->hard_header_len > max_hard_header_len) |
|---|
| 1095 | 1405 | max_hard_header_len = slave->dev->hard_header_len; |
|---|
| .. | .. |
|---|
| 1105 | 1415 | NETIF_F_HW_VLAN_CTAG_TX | |
|---|
| 1106 | 1416 | NETIF_F_HW_VLAN_STAG_TX | |
|---|
| 1107 | 1417 | NETIF_F_GSO_UDP_L4; |
|---|
| 1418 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 1419 | + bond_dev->hw_enc_features |= xfrm_features; |
|---|
| 1420 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 1421 | + bond_dev->mpls_features = mpls_features; |
|---|
| 1108 | 1422 | bond_dev->gso_max_segs = gso_max_segs; |
|---|
| 1109 | 1423 | netif_set_gso_max_size(bond_dev, gso_max_size); |
|---|
| 1110 | 1424 | |
|---|
| .. | .. |
|---|
| 1194 | 1508 | skb->dev = bond->dev; |
|---|
| 1195 | 1509 | |
|---|
| 1196 | 1510 | if (BOND_MODE(bond) == BOND_MODE_ALB && |
|---|
| 1197 | | - bond->dev->priv_flags & IFF_BRIDGE_PORT && |
|---|
| 1511 | + netif_is_bridge_port(bond->dev) && |
|---|
| 1198 | 1512 | skb->pkt_type == PACKET_HOST) { |
|---|
| 1199 | 1513 | |
|---|
| 1200 | 1514 | if (unlikely(skb_cow_head(skb, |
|---|
| .. | .. |
|---|
| 1388 | 1702 | if (!bond->params.use_carrier && |
|---|
| 1389 | 1703 | slave_dev->ethtool_ops->get_link == NULL && |
|---|
| 1390 | 1704 | slave_ops->ndo_do_ioctl == NULL) { |
|---|
| 1391 | | - netdev_warn(bond_dev, "no link monitoring support for %s\n", |
|---|
| 1392 | | - slave_dev->name); |
|---|
| 1705 | + slave_warn(bond_dev, slave_dev, "no link monitoring support\n"); |
|---|
| 1393 | 1706 | } |
|---|
| 1394 | 1707 | |
|---|
| 1395 | 1708 | /* already in-use? */ |
|---|
| 1396 | 1709 | if (netdev_is_rx_handler_busy(slave_dev)) { |
|---|
| 1397 | 1710 | NL_SET_ERR_MSG(extack, "Device is in use and cannot be enslaved"); |
|---|
| 1398 | | - netdev_err(bond_dev, |
|---|
| 1399 | | - "Error: Device is in use and cannot be enslaved\n"); |
|---|
| 1711 | + slave_err(bond_dev, slave_dev, |
|---|
| 1712 | + "Error: Device is in use and cannot be enslaved\n"); |
|---|
| 1400 | 1713 | return -EBUSY; |
|---|
| 1401 | 1714 | } |
|---|
| 1402 | 1715 | |
|---|
| .. | .. |
|---|
| 1409 | 1722 | /* vlan challenged mutual exclusion */ |
|---|
| 1410 | 1723 | /* no need to lock since we're protected by rtnl_lock */ |
|---|
| 1411 | 1724 | if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { |
|---|
| 1412 | | - netdev_dbg(bond_dev, "%s is NETIF_F_VLAN_CHALLENGED\n", |
|---|
| 1413 | | - slave_dev->name); |
|---|
| 1725 | + slave_dbg(bond_dev, slave_dev, "is NETIF_F_VLAN_CHALLENGED\n"); |
|---|
| 1414 | 1726 | if (vlan_uses_dev(bond_dev)) { |
|---|
| 1415 | 1727 | NL_SET_ERR_MSG(extack, "Can not enslave VLAN challenged device to VLAN enabled bond"); |
|---|
| 1416 | | - netdev_err(bond_dev, "Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n", |
|---|
| 1417 | | - slave_dev->name, bond_dev->name); |
|---|
| 1728 | + slave_err(bond_dev, slave_dev, "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n"); |
|---|
| 1418 | 1729 | return -EPERM; |
|---|
| 1419 | 1730 | } else { |
|---|
| 1420 | | - netdev_warn(bond_dev, "enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n", |
|---|
| 1421 | | - slave_dev->name, slave_dev->name, |
|---|
| 1422 | | - bond_dev->name); |
|---|
| 1731 | + slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n"); |
|---|
| 1423 | 1732 | } |
|---|
| 1424 | 1733 | } else { |
|---|
| 1425 | | - netdev_dbg(bond_dev, "%s is !NETIF_F_VLAN_CHALLENGED\n", |
|---|
| 1426 | | - slave_dev->name); |
|---|
| 1734 | + slave_dbg(bond_dev, slave_dev, "is !NETIF_F_VLAN_CHALLENGED\n"); |
|---|
| 1427 | 1735 | } |
|---|
| 1736 | + |
|---|
| 1737 | + if (slave_dev->features & NETIF_F_HW_ESP) |
|---|
| 1738 | + slave_dbg(bond_dev, slave_dev, "is esp-hw-offload capable\n"); |
|---|
| 1428 | 1739 | |
|---|
| 1429 | 1740 | /* Old ifenslave binaries are no longer supported. These can |
|---|
| 1430 | 1741 | * be identified with moderate accuracy by the state of the slave: |
|---|
| .. | .. |
|---|
| 1433 | 1744 | */ |
|---|
| 1434 | 1745 | if (slave_dev->flags & IFF_UP) { |
|---|
| 1435 | 1746 | NL_SET_ERR_MSG(extack, "Device can not be enslaved while up"); |
|---|
| 1436 | | - netdev_err(bond_dev, "%s is up - this may be due to an out of date ifenslave\n", |
|---|
| 1437 | | - slave_dev->name); |
|---|
| 1747 | + slave_err(bond_dev, slave_dev, "slave is up - this may be due to an out of date ifenslave\n"); |
|---|
| 1438 | 1748 | return -EPERM; |
|---|
| 1439 | 1749 | } |
|---|
| 1440 | 1750 | |
|---|
| .. | .. |
|---|
| 1447 | 1757 | */ |
|---|
| 1448 | 1758 | if (!bond_has_slaves(bond)) { |
|---|
| 1449 | 1759 | if (bond_dev->type != slave_dev->type) { |
|---|
| 1450 | | - netdev_dbg(bond_dev, "change device type from %d to %d\n", |
|---|
| 1451 | | - bond_dev->type, slave_dev->type); |
|---|
| 1760 | + slave_dbg(bond_dev, slave_dev, "change device type from %d to %d\n", |
|---|
| 1761 | + bond_dev->type, slave_dev->type); |
|---|
| 1452 | 1762 | |
|---|
| 1453 | 1763 | res = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE, |
|---|
| 1454 | 1764 | bond_dev); |
|---|
| 1455 | 1765 | res = notifier_to_errno(res); |
|---|
| 1456 | 1766 | if (res) { |
|---|
| 1457 | | - netdev_err(bond_dev, "refused to change device type\n"); |
|---|
| 1767 | + slave_err(bond_dev, slave_dev, "refused to change device type\n"); |
|---|
| 1458 | 1768 | return -EBUSY; |
|---|
| 1459 | 1769 | } |
|---|
| 1460 | 1770 | |
|---|
| .. | .. |
|---|
| 1474 | 1784 | } |
|---|
| 1475 | 1785 | } else if (bond_dev->type != slave_dev->type) { |
|---|
| 1476 | 1786 | NL_SET_ERR_MSG(extack, "Device type is different from other slaves"); |
|---|
| 1477 | | - netdev_err(bond_dev, "%s ether type (%d) is different from other slaves (%d), can not enslave it\n", |
|---|
| 1478 | | - slave_dev->name, slave_dev->type, bond_dev->type); |
|---|
| 1787 | + slave_err(bond_dev, slave_dev, "ether type (%d) is different from other slaves (%d), can not enslave it\n", |
|---|
| 1788 | + slave_dev->type, bond_dev->type); |
|---|
| 1479 | 1789 | return -EINVAL; |
|---|
| 1480 | 1790 | } |
|---|
| 1481 | 1791 | |
|---|
| 1482 | 1792 | if (slave_dev->type == ARPHRD_INFINIBAND && |
|---|
| 1483 | 1793 | BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) { |
|---|
| 1484 | 1794 | NL_SET_ERR_MSG(extack, "Only active-backup mode is supported for infiniband slaves"); |
|---|
| 1485 | | - netdev_warn(bond_dev, "Type (%d) supports only active-backup mode\n", |
|---|
| 1486 | | - slave_dev->type); |
|---|
| 1795 | + slave_warn(bond_dev, slave_dev, "Type (%d) supports only active-backup mode\n", |
|---|
| 1796 | + slave_dev->type); |
|---|
| 1487 | 1797 | res = -EOPNOTSUPP; |
|---|
| 1488 | 1798 | goto err_undo_flags; |
|---|
| 1489 | 1799 | } |
|---|
| 1490 | 1800 | |
|---|
| 1491 | 1801 | if (!slave_ops->ndo_set_mac_address || |
|---|
| 1492 | 1802 | slave_dev->type == ARPHRD_INFINIBAND) { |
|---|
| 1493 | | - netdev_warn(bond_dev, "The slave device specified does not support setting the MAC address\n"); |
|---|
| 1803 | + slave_warn(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address\n"); |
|---|
| 1494 | 1804 | if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP && |
|---|
| 1495 | 1805 | bond->params.fail_over_mac != BOND_FOM_ACTIVE) { |
|---|
| 1496 | 1806 | if (!bond_has_slaves(bond)) { |
|---|
| 1497 | 1807 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; |
|---|
| 1498 | | - netdev_warn(bond_dev, "Setting fail_over_mac to active for active-backup mode\n"); |
|---|
| 1808 | + slave_warn(bond_dev, slave_dev, "Setting fail_over_mac to active for active-backup mode\n"); |
|---|
| 1499 | 1809 | } else { |
|---|
| 1500 | 1810 | NL_SET_ERR_MSG(extack, "Slave device does not support setting the MAC address, but fail_over_mac is not set to active"); |
|---|
| 1501 | | - netdev_err(bond_dev, "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n"); |
|---|
| 1811 | + slave_err(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n"); |
|---|
| 1502 | 1812 | res = -EOPNOTSUPP; |
|---|
| 1503 | 1813 | goto err_undo_flags; |
|---|
| 1504 | 1814 | } |
|---|
| .. | .. |
|---|
| 1511 | 1821 | * address to be the same as the slave's. |
|---|
| 1512 | 1822 | */ |
|---|
| 1513 | 1823 | if (!bond_has_slaves(bond) && |
|---|
| 1514 | | - bond->dev->addr_assign_type == NET_ADDR_RANDOM) |
|---|
| 1515 | | - bond_set_dev_addr(bond->dev, slave_dev); |
|---|
| 1824 | + bond->dev->addr_assign_type == NET_ADDR_RANDOM) { |
|---|
| 1825 | + res = bond_set_dev_addr(bond->dev, slave_dev); |
|---|
| 1826 | + if (res) |
|---|
| 1827 | + goto err_undo_flags; |
|---|
| 1828 | + } |
|---|
| 1516 | 1829 | |
|---|
| 1517 | 1830 | new_slave = bond_alloc_slave(bond, slave_dev); |
|---|
| 1518 | 1831 | if (!new_slave) { |
|---|
| .. | .. |
|---|
| 1529 | 1842 | new_slave->original_mtu = slave_dev->mtu; |
|---|
| 1530 | 1843 | res = dev_set_mtu(slave_dev, bond->dev->mtu); |
|---|
| 1531 | 1844 | if (res) { |
|---|
| 1532 | | - netdev_dbg(bond_dev, "Error %d calling dev_set_mtu\n", res); |
|---|
| 1845 | + slave_err(bond_dev, slave_dev, "Error %d calling dev_set_mtu\n", res); |
|---|
| 1533 | 1846 | goto err_free; |
|---|
| 1534 | 1847 | } |
|---|
| 1535 | 1848 | |
|---|
| .. | .. |
|---|
| 1547 | 1860 | */ |
|---|
| 1548 | 1861 | memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len); |
|---|
| 1549 | 1862 | ss.ss_family = slave_dev->type; |
|---|
| 1550 | | - res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss); |
|---|
| 1863 | + res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, |
|---|
| 1864 | + extack); |
|---|
| 1551 | 1865 | if (res) { |
|---|
| 1552 | | - netdev_dbg(bond_dev, "Error %d calling set_mac_address\n", res); |
|---|
| 1866 | + slave_err(bond_dev, slave_dev, "Error %d calling set_mac_address\n", res); |
|---|
| 1553 | 1867 | goto err_restore_mtu; |
|---|
| 1554 | 1868 | } |
|---|
| 1555 | 1869 | } |
|---|
| .. | .. |
|---|
| 1558 | 1872 | slave_dev->flags |= IFF_SLAVE; |
|---|
| 1559 | 1873 | |
|---|
| 1560 | 1874 | /* open the slave since the application closed it */ |
|---|
| 1561 | | - res = dev_open(slave_dev); |
|---|
| 1875 | + res = dev_open(slave_dev, extack); |
|---|
| 1562 | 1876 | if (res) { |
|---|
| 1563 | | - netdev_dbg(bond_dev, "Opening slave %s failed\n", slave_dev->name); |
|---|
| 1877 | + slave_err(bond_dev, slave_dev, "Opening slave failed\n"); |
|---|
| 1564 | 1878 | goto err_restore_mac; |
|---|
| 1565 | 1879 | } |
|---|
| 1566 | 1880 | |
|---|
| .. | .. |
|---|
| 1579 | 1893 | |
|---|
| 1580 | 1894 | res = vlan_vids_add_by_dev(slave_dev, bond_dev); |
|---|
| 1581 | 1895 | if (res) { |
|---|
| 1582 | | - netdev_err(bond_dev, "Couldn't add bond vlan ids to %s\n", |
|---|
| 1583 | | - slave_dev->name); |
|---|
| 1896 | + slave_err(bond_dev, slave_dev, "Couldn't add bond vlan ids\n"); |
|---|
| 1584 | 1897 | goto err_close; |
|---|
| 1585 | 1898 | } |
|---|
| 1586 | 1899 | |
|---|
| .. | .. |
|---|
| 1610 | 1923 | * supported); thus, we don't need to change |
|---|
| 1611 | 1924 | * the messages for netif_carrier. |
|---|
| 1612 | 1925 | */ |
|---|
| 1613 | | - netdev_warn(bond_dev, "MII and ETHTOOL support not available for interface %s, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n", |
|---|
| 1614 | | - slave_dev->name); |
|---|
| 1926 | + slave_warn(bond_dev, slave_dev, "MII and ETHTOOL support not available for slave, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n"); |
|---|
| 1615 | 1927 | } else if (link_reporting == -1) { |
|---|
| 1616 | 1928 | /* unable get link status using mii/ethtool */ |
|---|
| 1617 | | - netdev_warn(bond_dev, "can't get link status from interface %s; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n", |
|---|
| 1618 | | - slave_dev->name); |
|---|
| 1929 | + slave_warn(bond_dev, slave_dev, "can't get link status from slave; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n"); |
|---|
| 1619 | 1930 | } |
|---|
| 1620 | 1931 | } |
|---|
| 1621 | 1932 | |
|---|
| .. | .. |
|---|
| 1649 | 1960 | |
|---|
| 1650 | 1961 | if (new_slave->link != BOND_LINK_DOWN) |
|---|
| 1651 | 1962 | new_slave->last_link_up = jiffies; |
|---|
| 1652 | | - netdev_dbg(bond_dev, "Initial state of slave_dev is BOND_LINK_%s\n", |
|---|
| 1653 | | - new_slave->link == BOND_LINK_DOWN ? "DOWN" : |
|---|
| 1654 | | - (new_slave->link == BOND_LINK_UP ? "UP" : "BACK")); |
|---|
| 1963 | + slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n", |
|---|
| 1964 | + new_slave->link == BOND_LINK_DOWN ? "DOWN" : |
|---|
| 1965 | + (new_slave->link == BOND_LINK_UP ? "UP" : "BACK")); |
|---|
| 1655 | 1966 | |
|---|
| 1656 | 1967 | if (bond_uses_primary(bond) && bond->params.primary[0]) { |
|---|
| 1657 | 1968 | /* if there is a primary slave, remember it */ |
|---|
| .. | .. |
|---|
| 1692 | 2003 | bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW); |
|---|
| 1693 | 2004 | break; |
|---|
| 1694 | 2005 | default: |
|---|
| 1695 | | - netdev_dbg(bond_dev, "This slave is always active in trunk mode\n"); |
|---|
| 2006 | + slave_dbg(bond_dev, slave_dev, "This slave is always active in trunk mode\n"); |
|---|
| 1696 | 2007 | |
|---|
| 1697 | 2008 | /* always active in trunk mode */ |
|---|
| 1698 | 2009 | bond_set_active_slave(new_slave); |
|---|
| .. | .. |
|---|
| 1711 | 2022 | #ifdef CONFIG_NET_POLL_CONTROLLER |
|---|
| 1712 | 2023 | if (bond->dev->npinfo) { |
|---|
| 1713 | 2024 | if (slave_enable_netpoll(new_slave)) { |
|---|
| 1714 | | - netdev_info(bond_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n"); |
|---|
| 2025 | + slave_info(bond_dev, slave_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n"); |
|---|
| 1715 | 2026 | res = -EBUSY; |
|---|
| 1716 | 2027 | goto err_detach; |
|---|
| 1717 | 2028 | } |
|---|
| .. | .. |
|---|
| 1724 | 2035 | res = netdev_rx_handler_register(slave_dev, bond_handle_frame, |
|---|
| 1725 | 2036 | new_slave); |
|---|
| 1726 | 2037 | if (res) { |
|---|
| 1727 | | - netdev_dbg(bond_dev, "Error %d calling netdev_rx_handler_register\n", res); |
|---|
| 2038 | + slave_dbg(bond_dev, slave_dev, "Error %d calling netdev_rx_handler_register\n", res); |
|---|
| 1728 | 2039 | goto err_detach; |
|---|
| 1729 | 2040 | } |
|---|
| 1730 | 2041 | |
|---|
| 1731 | 2042 | res = bond_master_upper_dev_link(bond, new_slave, extack); |
|---|
| 1732 | 2043 | if (res) { |
|---|
| 1733 | | - netdev_dbg(bond_dev, "Error %d calling bond_master_upper_dev_link\n", res); |
|---|
| 2044 | + slave_dbg(bond_dev, slave_dev, "Error %d calling bond_master_upper_dev_link\n", res); |
|---|
| 1734 | 2045 | goto err_unregister; |
|---|
| 1735 | 2046 | } |
|---|
| 1736 | 2047 | |
|---|
| 1737 | 2048 | res = bond_sysfs_slave_add(new_slave); |
|---|
| 1738 | 2049 | if (res) { |
|---|
| 1739 | | - netdev_dbg(bond_dev, "Error %d calling bond_sysfs_slave_add\n", res); |
|---|
| 2050 | + slave_dbg(bond_dev, slave_dev, "Error %d calling bond_sysfs_slave_add\n", res); |
|---|
| 1740 | 2051 | goto err_upper_unlink; |
|---|
| 1741 | 2052 | } |
|---|
| 1742 | | - |
|---|
| 1743 | | - bond->nest_level = dev_get_nest_level(bond_dev) + 1; |
|---|
| 1744 | 2053 | |
|---|
| 1745 | 2054 | /* If the mode uses primary, then the following is handled by |
|---|
| 1746 | 2055 | * bond_change_active_slave(). |
|---|
| .. | .. |
|---|
| 1763 | 2072 | } |
|---|
| 1764 | 2073 | } |
|---|
| 1765 | 2074 | |
|---|
| 1766 | | - netif_addr_lock_bh(bond_dev); |
|---|
| 1767 | | - dev_mc_sync_multiple(slave_dev, bond_dev); |
|---|
| 1768 | | - dev_uc_sync_multiple(slave_dev, bond_dev); |
|---|
| 1769 | | - netif_addr_unlock_bh(bond_dev); |
|---|
| 2075 | + if (bond_dev->flags & IFF_UP) { |
|---|
| 2076 | + netif_addr_lock_bh(bond_dev); |
|---|
| 2077 | + dev_mc_sync_multiple(slave_dev, bond_dev); |
|---|
| 2078 | + dev_uc_sync_multiple(slave_dev, bond_dev); |
|---|
| 2079 | + netif_addr_unlock_bh(bond_dev); |
|---|
| 1770 | 2080 | |
|---|
| 1771 | | - if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
|---|
| 1772 | | - /* add lacpdu mc addr to mc list */ |
|---|
| 1773 | | - u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
|---|
| 1774 | | - |
|---|
| 1775 | | - dev_mc_add(slave_dev, lacpdu_multicast); |
|---|
| 2081 | + if (BOND_MODE(bond) == BOND_MODE_8023AD) |
|---|
| 2082 | + dev_mc_add(slave_dev, lacpdu_mcast_addr); |
|---|
| 1776 | 2083 | } |
|---|
| 1777 | 2084 | } |
|---|
| 1778 | 2085 | |
|---|
| .. | .. |
|---|
| 1790 | 2097 | bond_update_slave_arr(bond, NULL); |
|---|
| 1791 | 2098 | |
|---|
| 1792 | 2099 | |
|---|
| 1793 | | - netdev_info(bond_dev, "Enslaving %s as %s interface with %s link\n", |
|---|
| 1794 | | - slave_dev->name, |
|---|
| 1795 | | - bond_is_active_slave(new_slave) ? "an active" : "a backup", |
|---|
| 1796 | | - new_slave->link != BOND_LINK_DOWN ? "an up" : "a down"); |
|---|
| 2100 | + slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n", |
|---|
| 2101 | + bond_is_active_slave(new_slave) ? "an active" : "a backup", |
|---|
| 2102 | + new_slave->link != BOND_LINK_DOWN ? "an up" : "a down"); |
|---|
| 1797 | 2103 | |
|---|
| 1798 | 2104 | /* enslave is successful */ |
|---|
| 1799 | 2105 | bond_queue_slave_event(new_slave); |
|---|
| .. | .. |
|---|
| 1839 | 2145 | bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr, |
|---|
| 1840 | 2146 | new_slave->dev->addr_len); |
|---|
| 1841 | 2147 | ss.ss_family = slave_dev->type; |
|---|
| 1842 | | - dev_set_mac_address(slave_dev, (struct sockaddr *)&ss); |
|---|
| 2148 | + dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL); |
|---|
| 1843 | 2149 | } |
|---|
| 1844 | 2150 | |
|---|
| 1845 | 2151 | err_restore_mtu: |
|---|
| .. | .. |
|---|
| 1889 | 2195 | /* slave is not a slave or master is not master of this slave */ |
|---|
| 1890 | 2196 | if (!(slave_dev->flags & IFF_SLAVE) || |
|---|
| 1891 | 2197 | !netdev_has_upper_dev(slave_dev, bond_dev)) { |
|---|
| 1892 | | - netdev_dbg(bond_dev, "cannot release %s\n", |
|---|
| 1893 | | - slave_dev->name); |
|---|
| 2198 | + slave_dbg(bond_dev, slave_dev, "cannot release slave\n"); |
|---|
| 1894 | 2199 | return -EINVAL; |
|---|
| 1895 | 2200 | } |
|---|
| 1896 | 2201 | |
|---|
| .. | .. |
|---|
| 1899 | 2204 | slave = bond_get_slave_by_dev(bond, slave_dev); |
|---|
| 1900 | 2205 | if (!slave) { |
|---|
| 1901 | 2206 | /* not a slave of this bond */ |
|---|
| 1902 | | - netdev_info(bond_dev, "%s not enslaved\n", |
|---|
| 1903 | | - slave_dev->name); |
|---|
| 2207 | + slave_info(bond_dev, slave_dev, "interface not enslaved\n"); |
|---|
| 1904 | 2208 | unblock_netpoll_tx(); |
|---|
| 1905 | 2209 | return -EINVAL; |
|---|
| 1906 | 2210 | } |
|---|
| .. | .. |
|---|
| 1925 | 2229 | if (bond_mode_can_use_xmit_hash(bond)) |
|---|
| 1926 | 2230 | bond_update_slave_arr(bond, slave); |
|---|
| 1927 | 2231 | |
|---|
| 1928 | | - netdev_info(bond_dev, "Releasing %s interface %s\n", |
|---|
| 1929 | | - bond_is_active_slave(slave) ? "active" : "backup", |
|---|
| 1930 | | - slave_dev->name); |
|---|
| 2232 | + slave_info(bond_dev, slave_dev, "Releasing %s interface\n", |
|---|
| 2233 | + bond_is_active_slave(slave) ? "active" : "backup"); |
|---|
| 1931 | 2234 | |
|---|
| 1932 | 2235 | oldcurrent = rcu_access_pointer(bond->curr_active_slave); |
|---|
| 1933 | 2236 | |
|---|
| .. | .. |
|---|
| 1937 | 2240 | BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)) { |
|---|
| 1938 | 2241 | if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) && |
|---|
| 1939 | 2242 | bond_has_slaves(bond)) |
|---|
| 1940 | | - netdev_warn(bond_dev, "the permanent HWaddr of %s - %pM - is still in use by %s - set the HWaddr of %s to a different address to avoid conflicts\n", |
|---|
| 1941 | | - slave_dev->name, slave->perm_hwaddr, |
|---|
| 1942 | | - bond_dev->name, slave_dev->name); |
|---|
| 2243 | + slave_warn(bond_dev, slave_dev, "the permanent HWaddr of slave - %pM - is still in use by bond - set the HWaddr of slave to a different address to avoid conflicts\n", |
|---|
| 2244 | + slave->perm_hwaddr); |
|---|
| 1943 | 2245 | } |
|---|
| 1944 | 2246 | |
|---|
| 1945 | 2247 | if (rtnl_dereference(bond->primary_slave) == slave) |
|---|
| .. | .. |
|---|
| 1967 | 2269 | bond_select_active_slave(bond); |
|---|
| 1968 | 2270 | } |
|---|
| 1969 | 2271 | |
|---|
| 1970 | | - if (!bond_has_slaves(bond)) { |
|---|
| 1971 | | - bond_set_carrier(bond); |
|---|
| 2272 | + bond_set_carrier(bond); |
|---|
| 2273 | + if (!bond_has_slaves(bond)) |
|---|
| 1972 | 2274 | eth_hw_addr_random(bond_dev); |
|---|
| 1973 | | - bond->nest_level = SINGLE_DEPTH_NESTING; |
|---|
| 1974 | | - } else { |
|---|
| 1975 | | - bond->nest_level = dev_get_nest_level(bond_dev) + 1; |
|---|
| 1976 | | - } |
|---|
| 1977 | 2275 | |
|---|
| 1978 | 2276 | unblock_netpoll_tx(); |
|---|
| 1979 | 2277 | synchronize_rcu(); |
|---|
| .. | .. |
|---|
| 1987 | 2285 | bond_compute_features(bond); |
|---|
| 1988 | 2286 | if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) && |
|---|
| 1989 | 2287 | (old_features & NETIF_F_VLAN_CHALLENGED)) |
|---|
| 1990 | | - netdev_info(bond_dev, "last VLAN challenged slave %s left bond %s - VLAN blocking is removed\n", |
|---|
| 1991 | | - slave_dev->name, bond_dev->name); |
|---|
| 2288 | + slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n"); |
|---|
| 1992 | 2289 | |
|---|
| 1993 | 2290 | vlan_vids_del_by_dev(slave_dev, bond_dev); |
|---|
| 1994 | 2291 | |
|---|
| .. | .. |
|---|
| 2010 | 2307 | if (old_flags & IFF_ALLMULTI) |
|---|
| 2011 | 2308 | dev_set_allmulti(slave_dev, -1); |
|---|
| 2012 | 2309 | |
|---|
| 2013 | | - bond_hw_addr_flush(bond_dev, slave_dev); |
|---|
| 2310 | + if (old_flags & IFF_UP) |
|---|
| 2311 | + bond_hw_addr_flush(bond_dev, slave_dev); |
|---|
| 2014 | 2312 | } |
|---|
| 2015 | 2313 | |
|---|
| 2016 | 2314 | slave_disable_netpoll(slave); |
|---|
| .. | .. |
|---|
| 2024 | 2322 | bond_hw_addr_copy(ss.__data, slave->perm_hwaddr, |
|---|
| 2025 | 2323 | slave->dev->addr_len); |
|---|
| 2026 | 2324 | ss.ss_family = slave_dev->type; |
|---|
| 2027 | | - dev_set_mac_address(slave_dev, (struct sockaddr *)&ss); |
|---|
| 2325 | + dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL); |
|---|
| 2028 | 2326 | } |
|---|
| 2029 | 2327 | |
|---|
| 2030 | 2328 | if (unregister) |
|---|
| .. | .. |
|---|
| 2049 | 2347 | /* First release a slave and then destroy the bond if no more slaves are left. |
|---|
| 2050 | 2348 | * Must be under rtnl_lock when this function is called. |
|---|
| 2051 | 2349 | */ |
|---|
| 2052 | | -static int bond_release_and_destroy(struct net_device *bond_dev, |
|---|
| 2053 | | - struct net_device *slave_dev) |
|---|
| 2350 | +static int bond_release_and_destroy(struct net_device *bond_dev, |
|---|
| 2351 | + struct net_device *slave_dev) |
|---|
| 2054 | 2352 | { |
|---|
| 2055 | 2353 | struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 2056 | 2354 | int ret; |
|---|
| .. | .. |
|---|
| 2059 | 2357 | if (ret == 0 && !bond_has_slaves(bond) && |
|---|
| 2060 | 2358 | bond_dev->reg_state != NETREG_UNREGISTERING) { |
|---|
| 2061 | 2359 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; |
|---|
| 2062 | | - netdev_info(bond_dev, "Destroying bond %s\n", |
|---|
| 2063 | | - bond_dev->name); |
|---|
| 2360 | + netdev_info(bond_dev, "Destroying bond\n"); |
|---|
| 2064 | 2361 | bond_remove_proc_entry(bond); |
|---|
| 2065 | 2362 | unregister_netdevice(bond_dev); |
|---|
| 2066 | 2363 | } |
|---|
| .. | .. |
|---|
| 2117 | 2414 | commit++; |
|---|
| 2118 | 2415 | slave->delay = bond->params.downdelay; |
|---|
| 2119 | 2416 | if (slave->delay) { |
|---|
| 2120 | | - netdev_info(bond->dev, "link status down for %sinterface %s, disabling it in %d ms\n", |
|---|
| 2121 | | - (BOND_MODE(bond) == |
|---|
| 2122 | | - BOND_MODE_ACTIVEBACKUP) ? |
|---|
| 2123 | | - (bond_is_active_slave(slave) ? |
|---|
| 2124 | | - "active " : "backup ") : "", |
|---|
| 2125 | | - slave->dev->name, |
|---|
| 2126 | | - bond->params.downdelay * bond->params.miimon); |
|---|
| 2417 | + slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n", |
|---|
| 2418 | + (BOND_MODE(bond) == |
|---|
| 2419 | + BOND_MODE_ACTIVEBACKUP) ? |
|---|
| 2420 | + (bond_is_active_slave(slave) ? |
|---|
| 2421 | + "active " : "backup ") : "", |
|---|
| 2422 | + bond->params.downdelay * bond->params.miimon); |
|---|
| 2127 | 2423 | } |
|---|
| 2128 | | - /*FALLTHRU*/ |
|---|
| 2424 | + fallthrough; |
|---|
| 2129 | 2425 | case BOND_LINK_FAIL: |
|---|
| 2130 | 2426 | if (link_state) { |
|---|
| 2131 | 2427 | /* recovered before downdelay expired */ |
|---|
| 2132 | 2428 | bond_propose_link_state(slave, BOND_LINK_UP); |
|---|
| 2133 | 2429 | slave->last_link_up = jiffies; |
|---|
| 2134 | | - netdev_info(bond->dev, "link status up again after %d ms for interface %s\n", |
|---|
| 2135 | | - (bond->params.downdelay - slave->delay) * |
|---|
| 2136 | | - bond->params.miimon, |
|---|
| 2137 | | - slave->dev->name); |
|---|
| 2430 | + slave_info(bond->dev, slave->dev, "link status up again after %d ms\n", |
|---|
| 2431 | + (bond->params.downdelay - slave->delay) * |
|---|
| 2432 | + bond->params.miimon); |
|---|
| 2138 | 2433 | commit++; |
|---|
| 2139 | 2434 | continue; |
|---|
| 2140 | 2435 | } |
|---|
| .. | .. |
|---|
| 2157 | 2452 | slave->delay = bond->params.updelay; |
|---|
| 2158 | 2453 | |
|---|
| 2159 | 2454 | if (slave->delay) { |
|---|
| 2160 | | - netdev_info(bond->dev, "link status up for interface %s, enabling it in %d ms\n", |
|---|
| 2161 | | - slave->dev->name, |
|---|
| 2162 | | - ignore_updelay ? 0 : |
|---|
| 2163 | | - bond->params.updelay * |
|---|
| 2164 | | - bond->params.miimon); |
|---|
| 2455 | + slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n", |
|---|
| 2456 | + ignore_updelay ? 0 : |
|---|
| 2457 | + bond->params.updelay * |
|---|
| 2458 | + bond->params.miimon); |
|---|
| 2165 | 2459 | } |
|---|
| 2166 | | - /*FALLTHRU*/ |
|---|
| 2460 | + fallthrough; |
|---|
| 2167 | 2461 | case BOND_LINK_BACK: |
|---|
| 2168 | 2462 | if (!link_state) { |
|---|
| 2169 | 2463 | bond_propose_link_state(slave, BOND_LINK_DOWN); |
|---|
| 2170 | | - netdev_info(bond->dev, "link status down again after %d ms for interface %s\n", |
|---|
| 2171 | | - (bond->params.updelay - slave->delay) * |
|---|
| 2172 | | - bond->params.miimon, |
|---|
| 2173 | | - slave->dev->name); |
|---|
| 2464 | + slave_info(bond->dev, slave->dev, "link status down again after %d ms\n", |
|---|
| 2465 | + (bond->params.updelay - slave->delay) * |
|---|
| 2466 | + bond->params.miimon); |
|---|
| 2174 | 2467 | commit++; |
|---|
| 2175 | 2468 | continue; |
|---|
| 2176 | 2469 | } |
|---|
| .. | .. |
|---|
| 2235 | 2528 | bond_needs_speed_duplex(bond)) { |
|---|
| 2236 | 2529 | slave->link = BOND_LINK_DOWN; |
|---|
| 2237 | 2530 | if (net_ratelimit()) |
|---|
| 2238 | | - netdev_warn(bond->dev, |
|---|
| 2239 | | - "failed to get link speed/duplex for %s\n", |
|---|
| 2240 | | - slave->dev->name); |
|---|
| 2531 | + slave_warn(bond->dev, slave->dev, |
|---|
| 2532 | + "failed to get link speed/duplex\n"); |
|---|
| 2241 | 2533 | continue; |
|---|
| 2242 | 2534 | } |
|---|
| 2243 | 2535 | bond_set_slave_link_state(slave, BOND_LINK_UP, |
|---|
| .. | .. |
|---|
| 2253 | 2545 | bond_set_active_slave(slave); |
|---|
| 2254 | 2546 | } |
|---|
| 2255 | 2547 | |
|---|
| 2256 | | - netdev_info(bond->dev, "link status definitely up for interface %s, %u Mbps %s duplex\n", |
|---|
| 2257 | | - slave->dev->name, |
|---|
| 2258 | | - slave->speed == SPEED_UNKNOWN ? 0 : slave->speed, |
|---|
| 2259 | | - slave->duplex ? "full" : "half"); |
|---|
| 2548 | + slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n", |
|---|
| 2549 | + slave->speed == SPEED_UNKNOWN ? 0 : slave->speed, |
|---|
| 2550 | + slave->duplex ? "full" : "half"); |
|---|
| 2260 | 2551 | |
|---|
| 2261 | 2552 | bond_miimon_link_change(bond, slave, BOND_LINK_UP); |
|---|
| 2262 | 2553 | |
|---|
| .. | .. |
|---|
| 2277 | 2568 | bond_set_slave_inactive_flags(slave, |
|---|
| 2278 | 2569 | BOND_SLAVE_NOTIFY_NOW); |
|---|
| 2279 | 2570 | |
|---|
| 2280 | | - netdev_info(bond->dev, "link status definitely down for interface %s, disabling it\n", |
|---|
| 2281 | | - slave->dev->name); |
|---|
| 2571 | + slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n"); |
|---|
| 2282 | 2572 | |
|---|
| 2283 | 2573 | bond_miimon_link_change(bond, slave, BOND_LINK_DOWN); |
|---|
| 2284 | 2574 | |
|---|
| .. | .. |
|---|
| 2288 | 2578 | continue; |
|---|
| 2289 | 2579 | |
|---|
| 2290 | 2580 | default: |
|---|
| 2291 | | - netdev_err(bond->dev, "invalid new link %d on slave %s\n", |
|---|
| 2292 | | - slave->link_new_state, slave->dev->name); |
|---|
| 2581 | + slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n", |
|---|
| 2582 | + slave->link_new_state); |
|---|
| 2293 | 2583 | bond_propose_link_state(slave, BOND_LINK_NOCHANGE); |
|---|
| 2294 | 2584 | |
|---|
| 2295 | 2585 | continue; |
|---|
| .. | .. |
|---|
| 2316 | 2606 | struct bonding *bond = container_of(work, struct bonding, |
|---|
| 2317 | 2607 | mii_work.work); |
|---|
| 2318 | 2608 | bool should_notify_peers = false; |
|---|
| 2609 | + bool commit; |
|---|
| 2319 | 2610 | unsigned long delay; |
|---|
| 2320 | 2611 | struct slave *slave; |
|---|
| 2321 | 2612 | struct list_head *iter; |
|---|
| .. | .. |
|---|
| 2326 | 2617 | goto re_arm; |
|---|
| 2327 | 2618 | |
|---|
| 2328 | 2619 | rcu_read_lock(); |
|---|
| 2329 | | - |
|---|
| 2330 | 2620 | should_notify_peers = bond_should_notify_peers(bond); |
|---|
| 2331 | | - |
|---|
| 2332 | | - if (bond_miimon_inspect(bond)) { |
|---|
| 2621 | + commit = !!bond_miimon_inspect(bond); |
|---|
| 2622 | + if (bond->send_peer_notif) { |
|---|
| 2333 | 2623 | rcu_read_unlock(); |
|---|
| 2624 | + if (rtnl_trylock()) { |
|---|
| 2625 | + bond->send_peer_notif--; |
|---|
| 2626 | + rtnl_unlock(); |
|---|
| 2627 | + } |
|---|
| 2628 | + } else { |
|---|
| 2629 | + rcu_read_unlock(); |
|---|
| 2630 | + } |
|---|
| 2334 | 2631 | |
|---|
| 2632 | + if (commit) { |
|---|
| 2335 | 2633 | /* Race avoidance with bond_close cancel of workqueue */ |
|---|
| 2336 | 2634 | if (!rtnl_trylock()) { |
|---|
| 2337 | 2635 | delay = 1; |
|---|
| .. | .. |
|---|
| 2345 | 2643 | bond_miimon_commit(bond); |
|---|
| 2346 | 2644 | |
|---|
| 2347 | 2645 | rtnl_unlock(); /* might sleep, hold no other locks */ |
|---|
| 2348 | | - } else |
|---|
| 2349 | | - rcu_read_unlock(); |
|---|
| 2646 | + } |
|---|
| 2350 | 2647 | |
|---|
| 2351 | 2648 | re_arm: |
|---|
| 2352 | 2649 | if (bond->params.miimon) |
|---|
| .. | .. |
|---|
| 2360 | 2657 | } |
|---|
| 2361 | 2658 | } |
|---|
| 2362 | 2659 | |
|---|
| 2363 | | -static int bond_upper_dev_walk(struct net_device *upper, void *data) |
|---|
| 2660 | +static int bond_upper_dev_walk(struct net_device *upper, |
|---|
| 2661 | + struct netdev_nested_priv *priv) |
|---|
| 2364 | 2662 | { |
|---|
| 2365 | | - __be32 ip = *((__be32 *)data); |
|---|
| 2663 | + __be32 ip = *(__be32 *)priv->data; |
|---|
| 2366 | 2664 | |
|---|
| 2367 | 2665 | return ip == bond_confirm_addr(upper, 0, ip); |
|---|
| 2368 | 2666 | } |
|---|
| 2369 | 2667 | |
|---|
| 2370 | 2668 | static bool bond_has_this_ip(struct bonding *bond, __be32 ip) |
|---|
| 2371 | 2669 | { |
|---|
| 2670 | + struct netdev_nested_priv priv = { |
|---|
| 2671 | + .data = (void *)&ip, |
|---|
| 2672 | + }; |
|---|
| 2372 | 2673 | bool ret = false; |
|---|
| 2373 | 2674 | |
|---|
| 2374 | 2675 | if (ip == bond_confirm_addr(bond->dev, 0, ip)) |
|---|
| 2375 | 2676 | return true; |
|---|
| 2376 | 2677 | |
|---|
| 2377 | 2678 | rcu_read_lock(); |
|---|
| 2378 | | - if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &ip)) |
|---|
| 2679 | + if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv)) |
|---|
| 2379 | 2680 | ret = true; |
|---|
| 2380 | 2681 | rcu_read_unlock(); |
|---|
| 2381 | 2682 | |
|---|
| .. | .. |
|---|
| 2386 | 2687 | * switches in VLAN mode (especially if ports are configured as |
|---|
| 2387 | 2688 | * "native" to a VLAN) might not pass non-tagged frames. |
|---|
| 2388 | 2689 | */ |
|---|
| 2389 | | -static void bond_arp_send(struct net_device *slave_dev, int arp_op, |
|---|
| 2390 | | - __be32 dest_ip, __be32 src_ip, |
|---|
| 2391 | | - struct bond_vlan_tag *tags) |
|---|
| 2690 | +static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip, |
|---|
| 2691 | + __be32 src_ip, struct bond_vlan_tag *tags) |
|---|
| 2392 | 2692 | { |
|---|
| 2393 | 2693 | struct sk_buff *skb; |
|---|
| 2394 | 2694 | struct bond_vlan_tag *outer_tag = tags; |
|---|
| 2695 | + struct net_device *slave_dev = slave->dev; |
|---|
| 2696 | + struct net_device *bond_dev = slave->bond->dev; |
|---|
| 2395 | 2697 | |
|---|
| 2396 | | - netdev_dbg(slave_dev, "arp %d on slave %s: dst %pI4 src %pI4\n", |
|---|
| 2397 | | - arp_op, slave_dev->name, &dest_ip, &src_ip); |
|---|
| 2698 | + slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n", |
|---|
| 2699 | + arp_op, &dest_ip, &src_ip); |
|---|
| 2398 | 2700 | |
|---|
| 2399 | 2701 | skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip, |
|---|
| 2400 | 2702 | NULL, slave_dev->dev_addr, NULL); |
|---|
| .. | .. |
|---|
| 2416 | 2718 | continue; |
|---|
| 2417 | 2719 | } |
|---|
| 2418 | 2720 | |
|---|
| 2419 | | - netdev_dbg(slave_dev, "inner tag: proto %X vid %X\n", |
|---|
| 2420 | | - ntohs(outer_tag->vlan_proto), tags->vlan_id); |
|---|
| 2721 | + slave_dbg(bond_dev, slave_dev, "inner tag: proto %X vid %X\n", |
|---|
| 2722 | + ntohs(outer_tag->vlan_proto), tags->vlan_id); |
|---|
| 2421 | 2723 | skb = vlan_insert_tag_set_proto(skb, tags->vlan_proto, |
|---|
| 2422 | 2724 | tags->vlan_id); |
|---|
| 2423 | 2725 | if (!skb) { |
|---|
| .. | .. |
|---|
| 2429 | 2731 | } |
|---|
| 2430 | 2732 | /* Set the outer tag */ |
|---|
| 2431 | 2733 | if (outer_tag->vlan_id) { |
|---|
| 2432 | | - netdev_dbg(slave_dev, "outer tag: proto %X vid %X\n", |
|---|
| 2433 | | - ntohs(outer_tag->vlan_proto), outer_tag->vlan_id); |
|---|
| 2734 | + slave_dbg(bond_dev, slave_dev, "outer tag: proto %X vid %X\n", |
|---|
| 2735 | + ntohs(outer_tag->vlan_proto), outer_tag->vlan_id); |
|---|
| 2434 | 2736 | __vlan_hwaccel_put_tag(skb, outer_tag->vlan_proto, |
|---|
| 2435 | 2737 | outer_tag->vlan_id); |
|---|
| 2436 | 2738 | } |
|---|
| .. | .. |
|---|
| 2487 | 2789 | int i; |
|---|
| 2488 | 2790 | |
|---|
| 2489 | 2791 | for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) { |
|---|
| 2490 | | - netdev_dbg(bond->dev, "basa: target %pI4\n", &targets[i]); |
|---|
| 2792 | + slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n", |
|---|
| 2793 | + __func__, &targets[i]); |
|---|
| 2491 | 2794 | tags = NULL; |
|---|
| 2492 | 2795 | |
|---|
| 2493 | 2796 | /* Find out through which dev should the packet go */ |
|---|
| .. | .. |
|---|
| 2501 | 2804 | net_warn_ratelimited("%s: no route to arp_ip_target %pI4 and arp_validate is set\n", |
|---|
| 2502 | 2805 | bond->dev->name, |
|---|
| 2503 | 2806 | &targets[i]); |
|---|
| 2504 | | - bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
|---|
| 2807 | + bond_arp_send(slave, ARPOP_REQUEST, targets[i], |
|---|
| 2505 | 2808 | 0, tags); |
|---|
| 2506 | 2809 | continue; |
|---|
| 2507 | 2810 | } |
|---|
| .. | .. |
|---|
| 2518 | 2821 | goto found; |
|---|
| 2519 | 2822 | |
|---|
| 2520 | 2823 | /* Not our device - skip */ |
|---|
| 2521 | | - netdev_dbg(bond->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n", |
|---|
| 2824 | + slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n", |
|---|
| 2522 | 2825 | &targets[i], rt->dst.dev ? rt->dst.dev->name : "NULL"); |
|---|
| 2523 | 2826 | |
|---|
| 2524 | 2827 | ip_rt_put(rt); |
|---|
| .. | .. |
|---|
| 2527 | 2830 | found: |
|---|
| 2528 | 2831 | addr = bond_confirm_addr(rt->dst.dev, targets[i], 0); |
|---|
| 2529 | 2832 | ip_rt_put(rt); |
|---|
| 2530 | | - bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
|---|
| 2531 | | - addr, tags); |
|---|
| 2833 | + bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags); |
|---|
| 2532 | 2834 | kfree(tags); |
|---|
| 2533 | 2835 | } |
|---|
| 2534 | 2836 | } |
|---|
| .. | .. |
|---|
| 2538 | 2840 | int i; |
|---|
| 2539 | 2841 | |
|---|
| 2540 | 2842 | if (!sip || !bond_has_this_ip(bond, tip)) { |
|---|
| 2541 | | - netdev_dbg(bond->dev, "bva: sip %pI4 tip %pI4 not found\n", |
|---|
| 2542 | | - &sip, &tip); |
|---|
| 2843 | + slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n", |
|---|
| 2844 | + __func__, &sip, &tip); |
|---|
| 2543 | 2845 | return; |
|---|
| 2544 | 2846 | } |
|---|
| 2545 | 2847 | |
|---|
| 2546 | 2848 | i = bond_get_targets_ip(bond->params.arp_targets, sip); |
|---|
| 2547 | 2849 | if (i == -1) { |
|---|
| 2548 | | - netdev_dbg(bond->dev, "bva: sip %pI4 not found in targets\n", |
|---|
| 2549 | | - &sip); |
|---|
| 2850 | + slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n", |
|---|
| 2851 | + __func__, &sip); |
|---|
| 2550 | 2852 | return; |
|---|
| 2551 | 2853 | } |
|---|
| 2552 | 2854 | slave->last_rx = jiffies; |
|---|
| .. | .. |
|---|
| 2574 | 2876 | |
|---|
| 2575 | 2877 | alen = arp_hdr_len(bond->dev); |
|---|
| 2576 | 2878 | |
|---|
| 2577 | | - netdev_dbg(bond->dev, "bond_arp_rcv: skb->dev %s\n", |
|---|
| 2578 | | - skb->dev->name); |
|---|
| 2879 | + slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n", |
|---|
| 2880 | + __func__, skb->dev->name); |
|---|
| 2579 | 2881 | |
|---|
| 2580 | 2882 | if (alen > skb_headlen(skb)) { |
|---|
| 2581 | 2883 | arp = kmalloc(alen, GFP_ATOMIC); |
|---|
| .. | .. |
|---|
| 2599 | 2901 | arp_ptr += 4 + bond->dev->addr_len; |
|---|
| 2600 | 2902 | memcpy(&tip, arp_ptr, 4); |
|---|
| 2601 | 2903 | |
|---|
| 2602 | | - netdev_dbg(bond->dev, "bond_arp_rcv: %s/%d av %d sv %d sip %pI4 tip %pI4\n", |
|---|
| 2603 | | - slave->dev->name, bond_slave_state(slave), |
|---|
| 2604 | | - bond->params.arp_validate, slave_do_arp_validate(bond, slave), |
|---|
| 2605 | | - &sip, &tip); |
|---|
| 2904 | + slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n", |
|---|
| 2905 | + __func__, slave->dev->name, bond_slave_state(slave), |
|---|
| 2906 | + bond->params.arp_validate, slave_do_arp_validate(bond, slave), |
|---|
| 2907 | + &sip, &tip); |
|---|
| 2606 | 2908 | |
|---|
| 2607 | 2909 | curr_active_slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 2608 | 2910 | curr_arp_slave = rcu_dereference(bond->current_arp_slave); |
|---|
| .. | .. |
|---|
| 2705 | 3007 | * is closed. |
|---|
| 2706 | 3008 | */ |
|---|
| 2707 | 3009 | if (!oldcurrent) { |
|---|
| 2708 | | - netdev_info(bond->dev, "link status definitely up for interface %s\n", |
|---|
| 2709 | | - slave->dev->name); |
|---|
| 3010 | + slave_info(bond->dev, slave->dev, "link status definitely up\n"); |
|---|
| 2710 | 3011 | do_failover = 1; |
|---|
| 2711 | 3012 | } else { |
|---|
| 2712 | | - netdev_info(bond->dev, "interface %s is now up\n", |
|---|
| 2713 | | - slave->dev->name); |
|---|
| 3013 | + slave_info(bond->dev, slave->dev, "interface is now up\n"); |
|---|
| 2714 | 3014 | } |
|---|
| 2715 | 3015 | } |
|---|
| 2716 | 3016 | } else { |
|---|
| .. | .. |
|---|
| 2729 | 3029 | if (slave->link_failure_count < UINT_MAX) |
|---|
| 2730 | 3030 | slave->link_failure_count++; |
|---|
| 2731 | 3031 | |
|---|
| 2732 | | - netdev_info(bond->dev, "interface %s is now down\n", |
|---|
| 2733 | | - slave->dev->name); |
|---|
| 3032 | + slave_info(bond->dev, slave->dev, "interface is now down\n"); |
|---|
| 2734 | 3033 | |
|---|
| 2735 | 3034 | if (slave == oldcurrent) |
|---|
| 2736 | 3035 | do_failover = 1; |
|---|
| .. | .. |
|---|
| 2883 | 3182 | RCU_INIT_POINTER(bond->current_arp_slave, NULL); |
|---|
| 2884 | 3183 | } |
|---|
| 2885 | 3184 | |
|---|
| 2886 | | - netdev_info(bond->dev, "link status definitely up for interface %s\n", |
|---|
| 2887 | | - slave->dev->name); |
|---|
| 3185 | + slave_info(bond->dev, slave->dev, "link status definitely up\n"); |
|---|
| 2888 | 3186 | |
|---|
| 2889 | 3187 | if (!rtnl_dereference(bond->curr_active_slave) || |
|---|
| 2890 | 3188 | slave == rtnl_dereference(bond->primary_slave)) |
|---|
| .. | .. |
|---|
| 2903 | 3201 | bond_set_slave_inactive_flags(slave, |
|---|
| 2904 | 3202 | BOND_SLAVE_NOTIFY_NOW); |
|---|
| 2905 | 3203 | |
|---|
| 2906 | | - netdev_info(bond->dev, "link status definitely down for interface %s, disabling it\n", |
|---|
| 2907 | | - slave->dev->name); |
|---|
| 3204 | + slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n"); |
|---|
| 2908 | 3205 | |
|---|
| 2909 | 3206 | if (slave == rtnl_dereference(bond->curr_active_slave)) { |
|---|
| 2910 | 3207 | RCU_INIT_POINTER(bond->current_arp_slave, NULL); |
|---|
| .. | .. |
|---|
| 2927 | 3224 | continue; |
|---|
| 2928 | 3225 | |
|---|
| 2929 | 3226 | default: |
|---|
| 2930 | | - netdev_err(bond->dev, "impossible: new_link %d on slave %s\n", |
|---|
| 2931 | | - slave->link_new_state, slave->dev->name); |
|---|
| 3227 | + slave_err(bond->dev, slave->dev, |
|---|
| 3228 | + "impossible: link_new_state %d on slave\n", |
|---|
| 3229 | + slave->link_new_state); |
|---|
| 2932 | 3230 | continue; |
|---|
| 2933 | 3231 | } |
|---|
| 2934 | 3232 | |
|---|
| .. | .. |
|---|
| 2997 | 3295 | bond_set_slave_inactive_flags(slave, |
|---|
| 2998 | 3296 | BOND_SLAVE_NOTIFY_LATER); |
|---|
| 2999 | 3297 | |
|---|
| 3000 | | - netdev_info(bond->dev, "backup interface %s is now down\n", |
|---|
| 3001 | | - slave->dev->name); |
|---|
| 3298 | + slave_info(bond->dev, slave->dev, "backup interface is now down\n"); |
|---|
| 3002 | 3299 | } |
|---|
| 3003 | 3300 | if (slave == curr_arp_slave) |
|---|
| 3004 | 3301 | found = true; |
|---|
| .. | .. |
|---|
| 3069 | 3366 | if (!rtnl_trylock()) |
|---|
| 3070 | 3367 | return; |
|---|
| 3071 | 3368 | |
|---|
| 3072 | | - if (should_notify_peers) |
|---|
| 3369 | + if (should_notify_peers) { |
|---|
| 3370 | + bond->send_peer_notif--; |
|---|
| 3073 | 3371 | call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, |
|---|
| 3074 | 3372 | bond->dev); |
|---|
| 3373 | + } |
|---|
| 3075 | 3374 | if (should_notify_rtnl) { |
|---|
| 3076 | 3375 | bond_slave_state_notify(bond); |
|---|
| 3077 | 3376 | bond_slave_link_notify(bond); |
|---|
| .. | .. |
|---|
| 3110 | 3409 | { |
|---|
| 3111 | 3410 | struct bonding *event_bond = netdev_priv(bond_dev); |
|---|
| 3112 | 3411 | |
|---|
| 3412 | + netdev_dbg(bond_dev, "%s called\n", __func__); |
|---|
| 3413 | + |
|---|
| 3113 | 3414 | switch (event) { |
|---|
| 3114 | 3415 | case NETDEV_CHANGENAME: |
|---|
| 3115 | 3416 | return bond_event_changename(event_bond); |
|---|
| 3116 | 3417 | case NETDEV_UNREGISTER: |
|---|
| 3117 | 3418 | bond_remove_proc_entry(event_bond); |
|---|
| 3419 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 3420 | + xfrm_dev_state_flush(dev_net(bond_dev), bond_dev, true); |
|---|
| 3421 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 3118 | 3422 | break; |
|---|
| 3119 | 3423 | case NETDEV_REGISTER: |
|---|
| 3120 | 3424 | bond_create_proc_entry(event_bond); |
|---|
| 3121 | | - break; |
|---|
| 3122 | | - case NETDEV_NOTIFY_PEERS: |
|---|
| 3123 | | - if (event_bond->send_peer_notif) |
|---|
| 3124 | | - event_bond->send_peer_notif--; |
|---|
| 3125 | 3425 | break; |
|---|
| 3126 | 3426 | default: |
|---|
| 3127 | 3427 | break; |
|---|
| .. | .. |
|---|
| 3141 | 3441 | * before netdev_rx_handler_register is called in which case |
|---|
| 3142 | 3442 | * slave will be NULL |
|---|
| 3143 | 3443 | */ |
|---|
| 3144 | | - if (!slave) |
|---|
| 3444 | + if (!slave) { |
|---|
| 3445 | + netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__); |
|---|
| 3145 | 3446 | return NOTIFY_DONE; |
|---|
| 3447 | + } |
|---|
| 3448 | + |
|---|
| 3146 | 3449 | bond_dev = slave->bond->dev; |
|---|
| 3147 | 3450 | bond = slave->bond; |
|---|
| 3148 | 3451 | primary = rtnl_dereference(bond->primary_slave); |
|---|
| 3452 | + |
|---|
| 3453 | + slave_dbg(bond_dev, slave_dev, "%s called\n", __func__); |
|---|
| 3149 | 3454 | |
|---|
| 3150 | 3455 | switch (event) { |
|---|
| 3151 | 3456 | case NETDEV_UNREGISTER: |
|---|
| .. | .. |
|---|
| 3173 | 3478 | |
|---|
| 3174 | 3479 | if (BOND_MODE(bond) == BOND_MODE_8023AD) |
|---|
| 3175 | 3480 | bond_3ad_adapter_speed_duplex_changed(slave); |
|---|
| 3176 | | - /* Fallthrough */ |
|---|
| 3481 | + fallthrough; |
|---|
| 3177 | 3482 | case NETDEV_DOWN: |
|---|
| 3178 | 3483 | /* Refresh slave-array if applicable! |
|---|
| 3179 | 3484 | * If the setup does not use miimon or arpmon (mode-specific!), |
|---|
| .. | .. |
|---|
| 3248 | 3553 | { |
|---|
| 3249 | 3554 | struct net_device *event_dev = netdev_notifier_info_to_dev(ptr); |
|---|
| 3250 | 3555 | |
|---|
| 3251 | | - netdev_dbg(event_dev, "event: %lx\n", event); |
|---|
| 3556 | + netdev_dbg(event_dev, "%s received %s\n", |
|---|
| 3557 | + __func__, netdev_cmd_to_name(event)); |
|---|
| 3252 | 3558 | |
|---|
| 3253 | 3559 | if (!(event_dev->priv_flags & IFF_BONDING)) |
|---|
| 3254 | 3560 | return NOTIFY_DONE; |
|---|
| .. | .. |
|---|
| 3256 | 3562 | if (event_dev->flags & IFF_MASTER) { |
|---|
| 3257 | 3563 | int ret; |
|---|
| 3258 | 3564 | |
|---|
| 3259 | | - netdev_dbg(event_dev, "IFF_MASTER\n"); |
|---|
| 3260 | 3565 | ret = bond_master_netdev_event(event, event_dev); |
|---|
| 3261 | 3566 | if (ret != NOTIFY_DONE) |
|---|
| 3262 | 3567 | return ret; |
|---|
| 3263 | 3568 | } |
|---|
| 3264 | 3569 | |
|---|
| 3265 | | - if (event_dev->flags & IFF_SLAVE) { |
|---|
| 3266 | | - netdev_dbg(event_dev, "IFF_SLAVE\n"); |
|---|
| 3570 | + if (event_dev->flags & IFF_SLAVE) |
|---|
| 3267 | 3571 | return bond_slave_netdev_event(event, event_dev); |
|---|
| 3268 | | - } |
|---|
| 3269 | 3572 | |
|---|
| 3270 | 3573 | return NOTIFY_DONE; |
|---|
| 3271 | 3574 | } |
|---|
| .. | .. |
|---|
| 3287 | 3590 | return 0; |
|---|
| 3288 | 3591 | } |
|---|
| 3289 | 3592 | |
|---|
| 3593 | +static bool bond_flow_ip(struct sk_buff *skb, struct flow_keys *fk, |
|---|
| 3594 | + int *noff, int *proto, bool l34) |
|---|
| 3595 | +{ |
|---|
| 3596 | + const struct ipv6hdr *iph6; |
|---|
| 3597 | + const struct iphdr *iph; |
|---|
| 3598 | + |
|---|
| 3599 | + if (skb->protocol == htons(ETH_P_IP)) { |
|---|
| 3600 | + if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph)))) |
|---|
| 3601 | + return false; |
|---|
| 3602 | + iph = (const struct iphdr *)(skb->data + *noff); |
|---|
| 3603 | + iph_to_flow_copy_v4addrs(fk, iph); |
|---|
| 3604 | + *noff += iph->ihl << 2; |
|---|
| 3605 | + if (!ip_is_fragment(iph)) |
|---|
| 3606 | + *proto = iph->protocol; |
|---|
| 3607 | + } else if (skb->protocol == htons(ETH_P_IPV6)) { |
|---|
| 3608 | + if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph6)))) |
|---|
| 3609 | + return false; |
|---|
| 3610 | + iph6 = (const struct ipv6hdr *)(skb->data + *noff); |
|---|
| 3611 | + iph_to_flow_copy_v6addrs(fk, iph6); |
|---|
| 3612 | + *noff += sizeof(*iph6); |
|---|
| 3613 | + *proto = iph6->nexthdr; |
|---|
| 3614 | + } else { |
|---|
| 3615 | + return false; |
|---|
| 3616 | + } |
|---|
| 3617 | + |
|---|
| 3618 | + if (l34 && *proto >= 0) |
|---|
| 3619 | + fk->ports.ports = skb_flow_get_ports(skb, *noff, *proto); |
|---|
| 3620 | + |
|---|
| 3621 | + return true; |
|---|
| 3622 | +} |
|---|
| 3623 | + |
|---|
| 3290 | 3624 | /* Extract the appropriate headers based on bond's xmit policy */ |
|---|
| 3291 | 3625 | static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb, |
|---|
| 3292 | 3626 | struct flow_keys *fk) |
|---|
| 3293 | 3627 | { |
|---|
| 3294 | | - const struct ipv6hdr *iph6; |
|---|
| 3295 | | - const struct iphdr *iph; |
|---|
| 3628 | + bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34; |
|---|
| 3296 | 3629 | int noff, proto = -1; |
|---|
| 3297 | 3630 | |
|---|
| 3298 | | - if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) |
|---|
| 3299 | | - return skb_flow_dissect_flow_keys(skb, fk, 0); |
|---|
| 3631 | + if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) { |
|---|
| 3632 | + memset(fk, 0, sizeof(*fk)); |
|---|
| 3633 | + return __skb_flow_dissect(NULL, skb, &flow_keys_bonding, |
|---|
| 3634 | + fk, NULL, 0, 0, 0, 0); |
|---|
| 3635 | + } |
|---|
| 3300 | 3636 | |
|---|
| 3301 | 3637 | fk->ports.ports = 0; |
|---|
| 3638 | + memset(&fk->icmp, 0, sizeof(fk->icmp)); |
|---|
| 3302 | 3639 | noff = skb_network_offset(skb); |
|---|
| 3303 | | - if (skb->protocol == htons(ETH_P_IP)) { |
|---|
| 3304 | | - if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph)))) |
|---|
| 3305 | | - return false; |
|---|
| 3306 | | - iph = ip_hdr(skb); |
|---|
| 3307 | | - iph_to_flow_copy_v4addrs(fk, iph); |
|---|
| 3308 | | - noff += iph->ihl << 2; |
|---|
| 3309 | | - if (!ip_is_fragment(iph)) |
|---|
| 3310 | | - proto = iph->protocol; |
|---|
| 3311 | | - } else if (skb->protocol == htons(ETH_P_IPV6)) { |
|---|
| 3312 | | - if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph6)))) |
|---|
| 3313 | | - return false; |
|---|
| 3314 | | - iph6 = ipv6_hdr(skb); |
|---|
| 3315 | | - iph_to_flow_copy_v6addrs(fk, iph6); |
|---|
| 3316 | | - noff += sizeof(*iph6); |
|---|
| 3317 | | - proto = iph6->nexthdr; |
|---|
| 3318 | | - } else { |
|---|
| 3640 | + if (!bond_flow_ip(skb, fk, &noff, &proto, l34)) |
|---|
| 3319 | 3641 | return false; |
|---|
| 3642 | + |
|---|
| 3643 | + /* ICMP error packets contains at least 8 bytes of the header |
|---|
| 3644 | + * of the packet which generated the error. Use this information |
|---|
| 3645 | + * to correlate ICMP error packets within the same flow which |
|---|
| 3646 | + * generated the error. |
|---|
| 3647 | + */ |
|---|
| 3648 | + if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) { |
|---|
| 3649 | + skb_flow_get_icmp_tci(skb, &fk->icmp, skb->data, |
|---|
| 3650 | + skb_transport_offset(skb), |
|---|
| 3651 | + skb_headlen(skb)); |
|---|
| 3652 | + if (proto == IPPROTO_ICMP) { |
|---|
| 3653 | + if (!icmp_is_err(fk->icmp.type)) |
|---|
| 3654 | + return true; |
|---|
| 3655 | + |
|---|
| 3656 | + noff += sizeof(struct icmphdr); |
|---|
| 3657 | + } else if (proto == IPPROTO_ICMPV6) { |
|---|
| 3658 | + if (!icmpv6_is_err(fk->icmp.type)) |
|---|
| 3659 | + return true; |
|---|
| 3660 | + |
|---|
| 3661 | + noff += sizeof(struct icmp6hdr); |
|---|
| 3662 | + } |
|---|
| 3663 | + return bond_flow_ip(skb, fk, &noff, &proto, l34); |
|---|
| 3320 | 3664 | } |
|---|
| 3321 | | - if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34 && proto >= 0) |
|---|
| 3322 | | - fk->ports.ports = skb_flow_get_ports(skb, noff, proto); |
|---|
| 3323 | 3665 | |
|---|
| 3324 | 3666 | return true; |
|---|
| 3325 | 3667 | } |
|---|
| .. | .. |
|---|
| 3346 | 3688 | return bond_eth_hash(skb); |
|---|
| 3347 | 3689 | |
|---|
| 3348 | 3690 | if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 || |
|---|
| 3349 | | - bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) |
|---|
| 3691 | + bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) { |
|---|
| 3350 | 3692 | hash = bond_eth_hash(skb); |
|---|
| 3351 | | - else |
|---|
| 3352 | | - hash = (__force u32)flow.ports.ports; |
|---|
| 3693 | + } else { |
|---|
| 3694 | + if (flow.icmp.id) |
|---|
| 3695 | + memcpy(&hash, &flow.icmp, sizeof(hash)); |
|---|
| 3696 | + else |
|---|
| 3697 | + memcpy(&hash, &flow.ports.ports, sizeof(hash)); |
|---|
| 3698 | + } |
|---|
| 3353 | 3699 | hash ^= (__force u32)flow_get_u32_dst(&flow) ^ |
|---|
| 3354 | 3700 | (__force u32)flow_get_u32_src(&flow); |
|---|
| 3355 | 3701 | hash ^= (hash >> 16); |
|---|
| .. | .. |
|---|
| 3424 | 3770 | /* register to receive LACPDUs */ |
|---|
| 3425 | 3771 | bond->recv_probe = bond_3ad_lacpdu_recv; |
|---|
| 3426 | 3772 | bond_3ad_initiate_agg_selection(bond, 1); |
|---|
| 3773 | + |
|---|
| 3774 | + bond_for_each_slave(bond, slave, iter) |
|---|
| 3775 | + dev_mc_add(slave->dev, lacpdu_mcast_addr); |
|---|
| 3427 | 3776 | } |
|---|
| 3428 | 3777 | |
|---|
| 3429 | 3778 | if (bond_mode_can_use_xmit_hash(bond)) |
|---|
| .. | .. |
|---|
| 3435 | 3784 | static int bond_close(struct net_device *bond_dev) |
|---|
| 3436 | 3785 | { |
|---|
| 3437 | 3786 | struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 3787 | + struct slave *slave; |
|---|
| 3438 | 3788 | |
|---|
| 3439 | 3789 | bond_work_cancel_all(bond); |
|---|
| 3440 | 3790 | bond->send_peer_notif = 0; |
|---|
| 3441 | 3791 | if (bond_is_lb(bond)) |
|---|
| 3442 | 3792 | bond_alb_deinitialize(bond); |
|---|
| 3443 | 3793 | bond->recv_probe = NULL; |
|---|
| 3794 | + |
|---|
| 3795 | + if (bond_uses_primary(bond)) { |
|---|
| 3796 | + rcu_read_lock(); |
|---|
| 3797 | + slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 3798 | + if (slave) |
|---|
| 3799 | + bond_hw_addr_flush(bond_dev, slave->dev); |
|---|
| 3800 | + rcu_read_unlock(); |
|---|
| 3801 | + } else { |
|---|
| 3802 | + struct list_head *iter; |
|---|
| 3803 | + |
|---|
| 3804 | + bond_for_each_slave(bond, slave, iter) |
|---|
| 3805 | + bond_hw_addr_flush(bond_dev, slave->dev); |
|---|
| 3806 | + } |
|---|
| 3444 | 3807 | |
|---|
| 3445 | 3808 | return 0; |
|---|
| 3446 | 3809 | } |
|---|
| .. | .. |
|---|
| 3474 | 3837 | } |
|---|
| 3475 | 3838 | } |
|---|
| 3476 | 3839 | |
|---|
| 3477 | | -static int bond_get_nest_level(struct net_device *bond_dev) |
|---|
| 3840 | +#ifdef CONFIG_LOCKDEP |
|---|
| 3841 | +static int bond_get_lowest_level_rcu(struct net_device *dev) |
|---|
| 3478 | 3842 | { |
|---|
| 3479 | | - struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 3843 | + struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1]; |
|---|
| 3844 | + struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1]; |
|---|
| 3845 | + int cur = 0, max = 0; |
|---|
| 3480 | 3846 | |
|---|
| 3481 | | - return bond->nest_level; |
|---|
| 3847 | + now = dev; |
|---|
| 3848 | + iter = &dev->adj_list.lower; |
|---|
| 3849 | + |
|---|
| 3850 | + while (1) { |
|---|
| 3851 | + next = NULL; |
|---|
| 3852 | + while (1) { |
|---|
| 3853 | + ldev = netdev_next_lower_dev_rcu(now, &iter); |
|---|
| 3854 | + if (!ldev) |
|---|
| 3855 | + break; |
|---|
| 3856 | + |
|---|
| 3857 | + next = ldev; |
|---|
| 3858 | + niter = &ldev->adj_list.lower; |
|---|
| 3859 | + dev_stack[cur] = now; |
|---|
| 3860 | + iter_stack[cur++] = iter; |
|---|
| 3861 | + if (max <= cur) |
|---|
| 3862 | + max = cur; |
|---|
| 3863 | + break; |
|---|
| 3864 | + } |
|---|
| 3865 | + |
|---|
| 3866 | + if (!next) { |
|---|
| 3867 | + if (!cur) |
|---|
| 3868 | + return max; |
|---|
| 3869 | + next = dev_stack[--cur]; |
|---|
| 3870 | + niter = iter_stack[cur]; |
|---|
| 3871 | + } |
|---|
| 3872 | + |
|---|
| 3873 | + now = next; |
|---|
| 3874 | + iter = niter; |
|---|
| 3875 | + } |
|---|
| 3876 | + |
|---|
| 3877 | + return max; |
|---|
| 3482 | 3878 | } |
|---|
| 3879 | +#endif |
|---|
| 3483 | 3880 | |
|---|
| 3484 | 3881 | static void bond_get_stats(struct net_device *bond_dev, |
|---|
| 3485 | 3882 | struct rtnl_link_stats64 *stats) |
|---|
| .. | .. |
|---|
| 3488 | 3885 | struct rtnl_link_stats64 temp; |
|---|
| 3489 | 3886 | struct list_head *iter; |
|---|
| 3490 | 3887 | struct slave *slave; |
|---|
| 3888 | + int nest_level = 0; |
|---|
| 3491 | 3889 | |
|---|
| 3492 | | - spin_lock_nested(&bond->stats_lock, bond_get_nest_level(bond_dev)); |
|---|
| 3493 | | - memcpy(stats, &bond->bond_stats, sizeof(*stats)); |
|---|
| 3494 | 3890 | |
|---|
| 3495 | 3891 | rcu_read_lock(); |
|---|
| 3892 | +#ifdef CONFIG_LOCKDEP |
|---|
| 3893 | + nest_level = bond_get_lowest_level_rcu(bond_dev); |
|---|
| 3894 | +#endif |
|---|
| 3895 | + |
|---|
| 3896 | + spin_lock_nested(&bond->stats_lock, nest_level); |
|---|
| 3897 | + memcpy(stats, &bond->bond_stats, sizeof(*stats)); |
|---|
| 3898 | + |
|---|
| 3496 | 3899 | bond_for_each_slave_rcu(bond, slave, iter) { |
|---|
| 3497 | 3900 | const struct rtnl_link_stats64 *new = |
|---|
| 3498 | 3901 | dev_get_stats(slave->dev, &temp); |
|---|
| .. | .. |
|---|
| 3502 | 3905 | /* save off the slave stats for the next run */ |
|---|
| 3503 | 3906 | memcpy(&slave->slave_stats, new, sizeof(*new)); |
|---|
| 3504 | 3907 | } |
|---|
| 3505 | | - rcu_read_unlock(); |
|---|
| 3506 | 3908 | |
|---|
| 3507 | 3909 | memcpy(&bond->bond_stats, stats, sizeof(*stats)); |
|---|
| 3508 | 3910 | spin_unlock(&bond->stats_lock); |
|---|
| 3911 | + rcu_read_unlock(); |
|---|
| 3509 | 3912 | } |
|---|
| 3510 | 3913 | |
|---|
| 3511 | 3914 | static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd) |
|---|
| .. | .. |
|---|
| 3530 | 3933 | return -EINVAL; |
|---|
| 3531 | 3934 | |
|---|
| 3532 | 3935 | mii->phy_id = 0; |
|---|
| 3533 | | - /* Fall Through */ |
|---|
| 3936 | + fallthrough; |
|---|
| 3534 | 3937 | case SIOCGMIIREG: |
|---|
| 3535 | 3938 | /* We do this again just in case we were called by SIOCGMIIREG |
|---|
| 3536 | 3939 | * instead of SIOCGMIIPHY. |
|---|
| .. | .. |
|---|
| 3582 | 3985 | |
|---|
| 3583 | 3986 | slave_dev = __dev_get_by_name(net, ifr->ifr_slave); |
|---|
| 3584 | 3987 | |
|---|
| 3585 | | - netdev_dbg(bond_dev, "slave_dev=%p:\n", slave_dev); |
|---|
| 3988 | + slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev); |
|---|
| 3586 | 3989 | |
|---|
| 3587 | 3990 | if (!slave_dev) |
|---|
| 3588 | 3991 | return -ENODEV; |
|---|
| 3589 | 3992 | |
|---|
| 3590 | | - netdev_dbg(bond_dev, "slave_dev->name=%s:\n", slave_dev->name); |
|---|
| 3591 | 3993 | switch (cmd) { |
|---|
| 3592 | 3994 | case BOND_ENSLAVE_OLD: |
|---|
| 3593 | 3995 | case SIOCBONDENSLAVE: |
|---|
| .. | .. |
|---|
| 3599 | 4001 | break; |
|---|
| 3600 | 4002 | case BOND_SETHWADDR_OLD: |
|---|
| 3601 | 4003 | case SIOCBONDSETHWADDR: |
|---|
| 3602 | | - bond_set_dev_addr(bond_dev, slave_dev); |
|---|
| 3603 | | - res = 0; |
|---|
| 4004 | + res = bond_set_dev_addr(bond_dev, slave_dev); |
|---|
| 3604 | 4005 | break; |
|---|
| 3605 | 4006 | case BOND_CHANGE_ACTIVE_OLD: |
|---|
| 3606 | 4007 | case SIOCBONDCHANGEACTIVE: |
|---|
| .. | .. |
|---|
| 3656 | 4057 | const struct net_device_ops *slave_ops; |
|---|
| 3657 | 4058 | struct neigh_parms parms; |
|---|
| 3658 | 4059 | struct slave *slave; |
|---|
| 3659 | | - int ret; |
|---|
| 4060 | + int ret = 0; |
|---|
| 3660 | 4061 | |
|---|
| 3661 | | - slave = bond_first_slave(bond); |
|---|
| 4062 | + rcu_read_lock(); |
|---|
| 4063 | + slave = bond_first_slave_rcu(bond); |
|---|
| 3662 | 4064 | if (!slave) |
|---|
| 3663 | | - return 0; |
|---|
| 4065 | + goto out; |
|---|
| 3664 | 4066 | slave_ops = slave->dev->netdev_ops; |
|---|
| 3665 | 4067 | if (!slave_ops->ndo_neigh_setup) |
|---|
| 3666 | | - return 0; |
|---|
| 4068 | + goto out; |
|---|
| 3667 | 4069 | |
|---|
| 3668 | | - parms.neigh_setup = NULL; |
|---|
| 3669 | | - parms.neigh_cleanup = NULL; |
|---|
| 3670 | | - ret = slave_ops->ndo_neigh_setup(slave->dev, &parms); |
|---|
| 3671 | | - if (ret) |
|---|
| 3672 | | - return ret; |
|---|
| 3673 | | - |
|---|
| 3674 | | - /* Assign slave's neigh_cleanup to neighbour in case cleanup is called |
|---|
| 3675 | | - * after the last slave has been detached. Assumes that all slaves |
|---|
| 3676 | | - * utilize the same neigh_cleanup (true at this writing as only user |
|---|
| 3677 | | - * is ipoib). |
|---|
| 4070 | + /* TODO: find another way [1] to implement this. |
|---|
| 4071 | + * Passing a zeroed structure is fragile, |
|---|
| 4072 | + * but at least we do not pass garbage. |
|---|
| 4073 | + * |
|---|
| 4074 | + * [1] One way would be that ndo_neigh_setup() never touch |
|---|
| 4075 | + * struct neigh_parms, but propagate the new neigh_setup() |
|---|
| 4076 | + * back to ___neigh_create() / neigh_parms_alloc() |
|---|
| 3678 | 4077 | */ |
|---|
| 3679 | | - n->parms->neigh_cleanup = parms.neigh_cleanup; |
|---|
| 4078 | + memset(&parms, 0, sizeof(parms)); |
|---|
| 4079 | + ret = slave_ops->ndo_neigh_setup(slave->dev, &parms); |
|---|
| 3680 | 4080 | |
|---|
| 3681 | | - if (!parms.neigh_setup) |
|---|
| 3682 | | - return 0; |
|---|
| 4081 | + if (ret) |
|---|
| 4082 | + goto out; |
|---|
| 3683 | 4083 | |
|---|
| 3684 | | - return parms.neigh_setup(n); |
|---|
| 4084 | + if (parms.neigh_setup) |
|---|
| 4085 | + ret = parms.neigh_setup(n); |
|---|
| 4086 | +out: |
|---|
| 4087 | + rcu_read_unlock(); |
|---|
| 4088 | + return ret; |
|---|
| 3685 | 4089 | } |
|---|
| 3686 | 4090 | |
|---|
| 3687 | 4091 | /* The bonding ndo_neigh_setup is called at init time beofre any |
|---|
| .. | .. |
|---|
| 3713 | 4117 | netdev_dbg(bond_dev, "bond=%p, new_mtu=%d\n", bond, new_mtu); |
|---|
| 3714 | 4118 | |
|---|
| 3715 | 4119 | bond_for_each_slave(bond, slave, iter) { |
|---|
| 3716 | | - netdev_dbg(bond_dev, "s %p c_m %p\n", |
|---|
| 4120 | + slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n", |
|---|
| 3717 | 4121 | slave, slave->dev->netdev_ops->ndo_change_mtu); |
|---|
| 3718 | 4122 | |
|---|
| 3719 | 4123 | res = dev_set_mtu(slave->dev, new_mtu); |
|---|
| .. | .. |
|---|
| 3727 | 4131 | * means changing their mtu from timer context, which |
|---|
| 3728 | 4132 | * is probably not a good idea. |
|---|
| 3729 | 4133 | */ |
|---|
| 3730 | | - netdev_dbg(bond_dev, "err %d %s\n", res, |
|---|
| 3731 | | - slave->dev->name); |
|---|
| 4134 | + slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n", |
|---|
| 4135 | + res, new_mtu); |
|---|
| 3732 | 4136 | goto unwind; |
|---|
| 3733 | 4137 | } |
|---|
| 3734 | 4138 | } |
|---|
| .. | .. |
|---|
| 3746 | 4150 | break; |
|---|
| 3747 | 4151 | |
|---|
| 3748 | 4152 | tmp_res = dev_set_mtu(rollback_slave->dev, bond_dev->mtu); |
|---|
| 3749 | | - if (tmp_res) { |
|---|
| 3750 | | - netdev_dbg(bond_dev, "unwind err %d dev %s\n", |
|---|
| 3751 | | - tmp_res, rollback_slave->dev->name); |
|---|
| 3752 | | - } |
|---|
| 4153 | + if (tmp_res) |
|---|
| 4154 | + slave_dbg(bond_dev, rollback_slave->dev, "unwind err %d\n", |
|---|
| 4155 | + tmp_res); |
|---|
| 3753 | 4156 | } |
|---|
| 3754 | 4157 | |
|---|
| 3755 | 4158 | return res; |
|---|
| .. | .. |
|---|
| 3773 | 4176 | return bond_alb_set_mac_address(bond_dev, addr); |
|---|
| 3774 | 4177 | |
|---|
| 3775 | 4178 | |
|---|
| 3776 | | - netdev_dbg(bond_dev, "bond=%p\n", bond); |
|---|
| 4179 | + netdev_dbg(bond_dev, "%s: bond=%p\n", __func__, bond); |
|---|
| 3777 | 4180 | |
|---|
| 3778 | 4181 | /* If fail_over_mac is enabled, do nothing and return success. |
|---|
| 3779 | 4182 | * Returning an error causes ifenslave to fail. |
|---|
| .. | .. |
|---|
| 3786 | 4189 | return -EADDRNOTAVAIL; |
|---|
| 3787 | 4190 | |
|---|
| 3788 | 4191 | bond_for_each_slave(bond, slave, iter) { |
|---|
| 3789 | | - netdev_dbg(bond_dev, "slave %p %s\n", slave, slave->dev->name); |
|---|
| 3790 | | - res = dev_set_mac_address(slave->dev, addr); |
|---|
| 4192 | + slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n", |
|---|
| 4193 | + __func__, slave); |
|---|
| 4194 | + res = dev_set_mac_address(slave->dev, addr, NULL); |
|---|
| 3791 | 4195 | if (res) { |
|---|
| 3792 | 4196 | /* TODO: consider downing the slave |
|---|
| 3793 | 4197 | * and retry ? |
|---|
| .. | .. |
|---|
| 3795 | 4199 | * breakage anyway until ARP finish |
|---|
| 3796 | 4200 | * updating, so... |
|---|
| 3797 | 4201 | */ |
|---|
| 3798 | | - netdev_dbg(bond_dev, "err %d %s\n", res, slave->dev->name); |
|---|
| 4202 | + slave_dbg(bond_dev, slave->dev, "%s: err %d\n", |
|---|
| 4203 | + __func__, res); |
|---|
| 3799 | 4204 | goto unwind; |
|---|
| 3800 | 4205 | } |
|---|
| 3801 | 4206 | } |
|---|
| .. | .. |
|---|
| 3816 | 4221 | break; |
|---|
| 3817 | 4222 | |
|---|
| 3818 | 4223 | tmp_res = dev_set_mac_address(rollback_slave->dev, |
|---|
| 3819 | | - (struct sockaddr *)&tmp_ss); |
|---|
| 4224 | + (struct sockaddr *)&tmp_ss, NULL); |
|---|
| 3820 | 4225 | if (tmp_res) { |
|---|
| 3821 | | - netdev_dbg(bond_dev, "unwind err %d dev %s\n", |
|---|
| 3822 | | - tmp_res, rollback_slave->dev->name); |
|---|
| 4226 | + slave_dbg(bond_dev, rollback_slave->dev, "%s: unwind err %d\n", |
|---|
| 4227 | + __func__, tmp_res); |
|---|
| 3823 | 4228 | } |
|---|
| 3824 | 4229 | } |
|---|
| 3825 | 4230 | |
|---|
| .. | .. |
|---|
| 3827 | 4232 | } |
|---|
| 3828 | 4233 | |
|---|
| 3829 | 4234 | /** |
|---|
| 3830 | | - * bond_xmit_slave_id - transmit skb through slave with slave_id |
|---|
| 4235 | + * bond_get_slave_by_id - get xmit slave with slave_id |
|---|
| 3831 | 4236 | * @bond: bonding device that is transmitting |
|---|
| 3832 | | - * @skb: buffer to transmit |
|---|
| 3833 | 4237 | * @slave_id: slave id up to slave_cnt-1 through which to transmit |
|---|
| 3834 | 4238 | * |
|---|
| 3835 | | - * This function tries to transmit through slave with slave_id but in case |
|---|
| 4239 | + * This function tries to get slave with slave_id but in case |
|---|
| 3836 | 4240 | * it fails, it tries to find the first available slave for transmission. |
|---|
| 3837 | | - * The skb is consumed in all cases, thus the function is void. |
|---|
| 3838 | 4241 | */ |
|---|
| 3839 | | -static void bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id) |
|---|
| 4242 | +static struct slave *bond_get_slave_by_id(struct bonding *bond, |
|---|
| 4243 | + int slave_id) |
|---|
| 3840 | 4244 | { |
|---|
| 3841 | 4245 | struct list_head *iter; |
|---|
| 3842 | 4246 | struct slave *slave; |
|---|
| .. | .. |
|---|
| 3845 | 4249 | /* Here we start from the slave with slave_id */ |
|---|
| 3846 | 4250 | bond_for_each_slave_rcu(bond, slave, iter) { |
|---|
| 3847 | 4251 | if (--i < 0) { |
|---|
| 3848 | | - if (bond_slave_can_tx(slave)) { |
|---|
| 3849 | | - bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 3850 | | - return; |
|---|
| 3851 | | - } |
|---|
| 4252 | + if (bond_slave_can_tx(slave)) |
|---|
| 4253 | + return slave; |
|---|
| 3852 | 4254 | } |
|---|
| 3853 | 4255 | } |
|---|
| 3854 | 4256 | |
|---|
| .. | .. |
|---|
| 3857 | 4259 | bond_for_each_slave_rcu(bond, slave, iter) { |
|---|
| 3858 | 4260 | if (--i < 0) |
|---|
| 3859 | 4261 | break; |
|---|
| 3860 | | - if (bond_slave_can_tx(slave)) { |
|---|
| 3861 | | - bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 3862 | | - return; |
|---|
| 3863 | | - } |
|---|
| 4262 | + if (bond_slave_can_tx(slave)) |
|---|
| 4263 | + return slave; |
|---|
| 3864 | 4264 | } |
|---|
| 3865 | 4265 | /* no slave that can tx has been found */ |
|---|
| 3866 | | - bond_tx_drop(bond->dev, skb); |
|---|
| 4266 | + return NULL; |
|---|
| 3867 | 4267 | } |
|---|
| 3868 | 4268 | |
|---|
| 3869 | 4269 | /** |
|---|
| .. | .. |
|---|
| 3899 | 4299 | return slave_id; |
|---|
| 3900 | 4300 | } |
|---|
| 3901 | 4301 | |
|---|
| 3902 | | -static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb, |
|---|
| 3903 | | - struct net_device *bond_dev) |
|---|
| 4302 | +static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond, |
|---|
| 4303 | + struct sk_buff *skb) |
|---|
| 3904 | 4304 | { |
|---|
| 3905 | | - struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 3906 | 4305 | struct slave *slave; |
|---|
| 3907 | 4306 | int slave_cnt; |
|---|
| 3908 | 4307 | u32 slave_id; |
|---|
| .. | .. |
|---|
| 3924 | 4323 | if (iph->protocol == IPPROTO_IGMP) { |
|---|
| 3925 | 4324 | slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 3926 | 4325 | if (slave) |
|---|
| 3927 | | - bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 3928 | | - else |
|---|
| 3929 | | - bond_xmit_slave_id(bond, skb, 0); |
|---|
| 3930 | | - return NETDEV_TX_OK; |
|---|
| 4326 | + return slave; |
|---|
| 4327 | + return bond_get_slave_by_id(bond, 0); |
|---|
| 3931 | 4328 | } |
|---|
| 3932 | 4329 | } |
|---|
| 3933 | 4330 | |
|---|
| 3934 | 4331 | non_igmp: |
|---|
| 3935 | 4332 | slave_cnt = READ_ONCE(bond->slave_cnt); |
|---|
| 3936 | 4333 | if (likely(slave_cnt)) { |
|---|
| 3937 | | - slave_id = bond_rr_gen_slave_id(bond); |
|---|
| 3938 | | - bond_xmit_slave_id(bond, skb, slave_id % slave_cnt); |
|---|
| 3939 | | - } else { |
|---|
| 3940 | | - bond_tx_drop(bond_dev, skb); |
|---|
| 4334 | + slave_id = bond_rr_gen_slave_id(bond) % slave_cnt; |
|---|
| 4335 | + return bond_get_slave_by_id(bond, slave_id); |
|---|
| 3941 | 4336 | } |
|---|
| 3942 | | - return NETDEV_TX_OK; |
|---|
| 4337 | + return NULL; |
|---|
| 4338 | +} |
|---|
| 4339 | + |
|---|
| 4340 | +static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb, |
|---|
| 4341 | + struct net_device *bond_dev) |
|---|
| 4342 | +{ |
|---|
| 4343 | + struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 4344 | + struct slave *slave; |
|---|
| 4345 | + |
|---|
| 4346 | + slave = bond_xmit_roundrobin_slave_get(bond, skb); |
|---|
| 4347 | + if (likely(slave)) |
|---|
| 4348 | + return bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 4349 | + |
|---|
| 4350 | + return bond_tx_drop(bond_dev, skb); |
|---|
| 4351 | +} |
|---|
| 4352 | + |
|---|
| 4353 | +static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond, |
|---|
| 4354 | + struct sk_buff *skb) |
|---|
| 4355 | +{ |
|---|
| 4356 | + return rcu_dereference(bond->curr_active_slave); |
|---|
| 3943 | 4357 | } |
|---|
| 3944 | 4358 | |
|---|
| 3945 | 4359 | /* In active-backup mode, we know that bond->curr_active_slave is always valid if |
|---|
| .. | .. |
|---|
| 3951 | 4365 | struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 3952 | 4366 | struct slave *slave; |
|---|
| 3953 | 4367 | |
|---|
| 3954 | | - slave = rcu_dereference(bond->curr_active_slave); |
|---|
| 4368 | + slave = bond_xmit_activebackup_slave_get(bond, skb); |
|---|
| 3955 | 4369 | if (slave) |
|---|
| 3956 | | - bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 3957 | | - else |
|---|
| 3958 | | - bond_tx_drop(bond_dev, skb); |
|---|
| 4370 | + return bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 3959 | 4371 | |
|---|
| 3960 | | - return NETDEV_TX_OK; |
|---|
| 4372 | + return bond_tx_drop(bond_dev, skb); |
|---|
| 3961 | 4373 | } |
|---|
| 3962 | 4374 | |
|---|
| 3963 | 4375 | /* Use this to update slave_array when (a) it's not appropriate to update |
|---|
| .. | .. |
|---|
| 3991 | 4403 | bond_slave_arr_work_rearm(bond, 1); |
|---|
| 3992 | 4404 | } |
|---|
| 3993 | 4405 | |
|---|
| 4406 | +static void bond_skip_slave(struct bond_up_slave *slaves, |
|---|
| 4407 | + struct slave *skipslave) |
|---|
| 4408 | +{ |
|---|
| 4409 | + int idx; |
|---|
| 4410 | + |
|---|
| 4411 | + /* Rare situation where caller has asked to skip a specific |
|---|
| 4412 | + * slave but allocation failed (most likely!). BTW this is |
|---|
| 4413 | + * only possible when the call is initiated from |
|---|
| 4414 | + * __bond_release_one(). In this situation; overwrite the |
|---|
| 4415 | + * skipslave entry in the array with the last entry from the |
|---|
| 4416 | + * array to avoid a situation where the xmit path may choose |
|---|
| 4417 | + * this to-be-skipped slave to send a packet out. |
|---|
| 4418 | + */ |
|---|
| 4419 | + for (idx = 0; slaves && idx < slaves->count; idx++) { |
|---|
| 4420 | + if (skipslave == slaves->arr[idx]) { |
|---|
| 4421 | + slaves->arr[idx] = |
|---|
| 4422 | + slaves->arr[slaves->count - 1]; |
|---|
| 4423 | + slaves->count--; |
|---|
| 4424 | + break; |
|---|
| 4425 | + } |
|---|
| 4426 | + } |
|---|
| 4427 | +} |
|---|
| 4428 | + |
|---|
| 4429 | +static void bond_set_slave_arr(struct bonding *bond, |
|---|
| 4430 | + struct bond_up_slave *usable_slaves, |
|---|
| 4431 | + struct bond_up_slave *all_slaves) |
|---|
| 4432 | +{ |
|---|
| 4433 | + struct bond_up_slave *usable, *all; |
|---|
| 4434 | + |
|---|
| 4435 | + usable = rtnl_dereference(bond->usable_slaves); |
|---|
| 4436 | + rcu_assign_pointer(bond->usable_slaves, usable_slaves); |
|---|
| 4437 | + kfree_rcu(usable, rcu); |
|---|
| 4438 | + |
|---|
| 4439 | + all = rtnl_dereference(bond->all_slaves); |
|---|
| 4440 | + rcu_assign_pointer(bond->all_slaves, all_slaves); |
|---|
| 4441 | + kfree_rcu(all, rcu); |
|---|
| 4442 | +} |
|---|
| 4443 | + |
|---|
| 4444 | +static void bond_reset_slave_arr(struct bonding *bond) |
|---|
| 4445 | +{ |
|---|
| 4446 | + struct bond_up_slave *usable, *all; |
|---|
| 4447 | + |
|---|
| 4448 | + usable = rtnl_dereference(bond->usable_slaves); |
|---|
| 4449 | + if (usable) { |
|---|
| 4450 | + RCU_INIT_POINTER(bond->usable_slaves, NULL); |
|---|
| 4451 | + kfree_rcu(usable, rcu); |
|---|
| 4452 | + } |
|---|
| 4453 | + |
|---|
| 4454 | + all = rtnl_dereference(bond->all_slaves); |
|---|
| 4455 | + if (all) { |
|---|
| 4456 | + RCU_INIT_POINTER(bond->all_slaves, NULL); |
|---|
| 4457 | + kfree_rcu(all, rcu); |
|---|
| 4458 | + } |
|---|
| 4459 | +} |
|---|
| 4460 | + |
|---|
| 3994 | 4461 | /* Build the usable slaves array in control path for modes that use xmit-hash |
|---|
| 3995 | 4462 | * to determine the slave interface - |
|---|
| 3996 | 4463 | * (a) BOND_MODE_8023AD |
|---|
| .. | .. |
|---|
| 4001 | 4468 | */ |
|---|
| 4002 | 4469 | int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) |
|---|
| 4003 | 4470 | { |
|---|
| 4471 | + struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL; |
|---|
| 4004 | 4472 | struct slave *slave; |
|---|
| 4005 | 4473 | struct list_head *iter; |
|---|
| 4006 | | - struct bond_up_slave *new_arr, *old_arr; |
|---|
| 4007 | 4474 | int agg_id = 0; |
|---|
| 4008 | 4475 | int ret = 0; |
|---|
| 4009 | 4476 | |
|---|
| .. | .. |
|---|
| 4011 | 4478 | WARN_ON(lockdep_is_held(&bond->mode_lock)); |
|---|
| 4012 | 4479 | #endif |
|---|
| 4013 | 4480 | |
|---|
| 4014 | | - new_arr = kzalloc(offsetof(struct bond_up_slave, arr[bond->slave_cnt]), |
|---|
| 4015 | | - GFP_KERNEL); |
|---|
| 4016 | | - if (!new_arr) { |
|---|
| 4481 | + usable_slaves = kzalloc(struct_size(usable_slaves, arr, |
|---|
| 4482 | + bond->slave_cnt), GFP_KERNEL); |
|---|
| 4483 | + all_slaves = kzalloc(struct_size(all_slaves, arr, |
|---|
| 4484 | + bond->slave_cnt), GFP_KERNEL); |
|---|
| 4485 | + if (!usable_slaves || !all_slaves) { |
|---|
| 4017 | 4486 | ret = -ENOMEM; |
|---|
| 4018 | | - pr_err("Failed to build slave-array.\n"); |
|---|
| 4019 | 4487 | goto out; |
|---|
| 4020 | 4488 | } |
|---|
| 4021 | 4489 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
|---|
| .. | .. |
|---|
| 4023 | 4491 | |
|---|
| 4024 | 4492 | if (bond_3ad_get_active_agg_info(bond, &ad_info)) { |
|---|
| 4025 | 4493 | pr_debug("bond_3ad_get_active_agg_info failed\n"); |
|---|
| 4026 | | - kfree_rcu(new_arr, rcu); |
|---|
| 4027 | 4494 | /* No active aggragator means it's not safe to use |
|---|
| 4028 | 4495 | * the previous array. |
|---|
| 4029 | 4496 | */ |
|---|
| 4030 | | - old_arr = rtnl_dereference(bond->slave_arr); |
|---|
| 4031 | | - if (old_arr) { |
|---|
| 4032 | | - RCU_INIT_POINTER(bond->slave_arr, NULL); |
|---|
| 4033 | | - kfree_rcu(old_arr, rcu); |
|---|
| 4034 | | - } |
|---|
| 4497 | + bond_reset_slave_arr(bond); |
|---|
| 4035 | 4498 | goto out; |
|---|
| 4036 | 4499 | } |
|---|
| 4037 | 4500 | agg_id = ad_info.aggregator_id; |
|---|
| 4038 | 4501 | } |
|---|
| 4039 | 4502 | bond_for_each_slave(bond, slave, iter) { |
|---|
| 4503 | + if (skipslave == slave) |
|---|
| 4504 | + continue; |
|---|
| 4505 | + |
|---|
| 4506 | + all_slaves->arr[all_slaves->count++] = slave; |
|---|
| 4040 | 4507 | if (BOND_MODE(bond) == BOND_MODE_8023AD) { |
|---|
| 4041 | 4508 | struct aggregator *agg; |
|---|
| 4042 | 4509 | |
|---|
| .. | .. |
|---|
| 4046 | 4513 | } |
|---|
| 4047 | 4514 | if (!bond_slave_can_tx(slave)) |
|---|
| 4048 | 4515 | continue; |
|---|
| 4049 | | - if (skipslave == slave) |
|---|
| 4050 | | - continue; |
|---|
| 4051 | 4516 | |
|---|
| 4052 | | - netdev_dbg(bond->dev, |
|---|
| 4053 | | - "Adding slave dev %s to tx hash array[%d]\n", |
|---|
| 4054 | | - slave->dev->name, new_arr->count); |
|---|
| 4517 | + slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n", |
|---|
| 4518 | + usable_slaves->count); |
|---|
| 4055 | 4519 | |
|---|
| 4056 | | - new_arr->arr[new_arr->count++] = slave; |
|---|
| 4520 | + usable_slaves->arr[usable_slaves->count++] = slave; |
|---|
| 4057 | 4521 | } |
|---|
| 4058 | 4522 | |
|---|
| 4059 | | - old_arr = rtnl_dereference(bond->slave_arr); |
|---|
| 4060 | | - rcu_assign_pointer(bond->slave_arr, new_arr); |
|---|
| 4061 | | - if (old_arr) |
|---|
| 4062 | | - kfree_rcu(old_arr, rcu); |
|---|
| 4523 | + bond_set_slave_arr(bond, usable_slaves, all_slaves); |
|---|
| 4524 | + return ret; |
|---|
| 4063 | 4525 | out: |
|---|
| 4064 | 4526 | if (ret != 0 && skipslave) { |
|---|
| 4065 | | - int idx; |
|---|
| 4066 | | - |
|---|
| 4067 | | - /* Rare situation where caller has asked to skip a specific |
|---|
| 4068 | | - * slave but allocation failed (most likely!). BTW this is |
|---|
| 4069 | | - * only possible when the call is initiated from |
|---|
| 4070 | | - * __bond_release_one(). In this situation; overwrite the |
|---|
| 4071 | | - * skipslave entry in the array with the last entry from the |
|---|
| 4072 | | - * array to avoid a situation where the xmit path may choose |
|---|
| 4073 | | - * this to-be-skipped slave to send a packet out. |
|---|
| 4074 | | - */ |
|---|
| 4075 | | - old_arr = rtnl_dereference(bond->slave_arr); |
|---|
| 4076 | | - for (idx = 0; old_arr != NULL && idx < old_arr->count; idx++) { |
|---|
| 4077 | | - if (skipslave == old_arr->arr[idx]) { |
|---|
| 4078 | | - old_arr->arr[idx] = |
|---|
| 4079 | | - old_arr->arr[old_arr->count-1]; |
|---|
| 4080 | | - old_arr->count--; |
|---|
| 4081 | | - break; |
|---|
| 4082 | | - } |
|---|
| 4083 | | - } |
|---|
| 4527 | + bond_skip_slave(rtnl_dereference(bond->all_slaves), |
|---|
| 4528 | + skipslave); |
|---|
| 4529 | + bond_skip_slave(rtnl_dereference(bond->usable_slaves), |
|---|
| 4530 | + skipslave); |
|---|
| 4084 | 4531 | } |
|---|
| 4532 | + kfree_rcu(all_slaves, rcu); |
|---|
| 4533 | + kfree_rcu(usable_slaves, rcu); |
|---|
| 4534 | + |
|---|
| 4085 | 4535 | return ret; |
|---|
| 4536 | +} |
|---|
| 4537 | + |
|---|
| 4538 | +static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond, |
|---|
| 4539 | + struct sk_buff *skb, |
|---|
| 4540 | + struct bond_up_slave *slaves) |
|---|
| 4541 | +{ |
|---|
| 4542 | + struct slave *slave; |
|---|
| 4543 | + unsigned int count; |
|---|
| 4544 | + u32 hash; |
|---|
| 4545 | + |
|---|
| 4546 | + hash = bond_xmit_hash(bond, skb); |
|---|
| 4547 | + count = slaves ? READ_ONCE(slaves->count) : 0; |
|---|
| 4548 | + if (unlikely(!count)) |
|---|
| 4549 | + return NULL; |
|---|
| 4550 | + |
|---|
| 4551 | + slave = slaves->arr[hash % count]; |
|---|
| 4552 | + return slave; |
|---|
| 4086 | 4553 | } |
|---|
| 4087 | 4554 | |
|---|
| 4088 | 4555 | /* Use this Xmit function for 3AD as well as XOR modes. The current |
|---|
| .. | .. |
|---|
| 4093 | 4560 | struct net_device *dev) |
|---|
| 4094 | 4561 | { |
|---|
| 4095 | 4562 | struct bonding *bond = netdev_priv(dev); |
|---|
| 4096 | | - struct slave *slave; |
|---|
| 4097 | 4563 | struct bond_up_slave *slaves; |
|---|
| 4098 | | - unsigned int count; |
|---|
| 4564 | + struct slave *slave; |
|---|
| 4099 | 4565 | |
|---|
| 4100 | | - slaves = rcu_dereference(bond->slave_arr); |
|---|
| 4101 | | - count = slaves ? READ_ONCE(slaves->count) : 0; |
|---|
| 4102 | | - if (likely(count)) { |
|---|
| 4103 | | - slave = slaves->arr[bond_xmit_hash(bond, skb) % count]; |
|---|
| 4104 | | - bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 4105 | | - } else { |
|---|
| 4106 | | - bond_tx_drop(dev, skb); |
|---|
| 4107 | | - } |
|---|
| 4566 | + slaves = rcu_dereference(bond->usable_slaves); |
|---|
| 4567 | + slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves); |
|---|
| 4568 | + if (likely(slave)) |
|---|
| 4569 | + return bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 4108 | 4570 | |
|---|
| 4109 | | - return NETDEV_TX_OK; |
|---|
| 4571 | + return bond_tx_drop(dev, skb); |
|---|
| 4110 | 4572 | } |
|---|
| 4111 | 4573 | |
|---|
| 4112 | 4574 | /* in broadcast mode, we send everything to all usable interfaces. */ |
|---|
| .. | .. |
|---|
| 4116 | 4578 | struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 4117 | 4579 | struct slave *slave = NULL; |
|---|
| 4118 | 4580 | struct list_head *iter; |
|---|
| 4581 | + bool xmit_suc = false; |
|---|
| 4582 | + bool skb_used = false; |
|---|
| 4119 | 4583 | |
|---|
| 4120 | 4584 | bond_for_each_slave_rcu(bond, slave, iter) { |
|---|
| 4121 | | - if (bond_is_last_slave(bond, slave)) |
|---|
| 4122 | | - break; |
|---|
| 4123 | | - if (bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) { |
|---|
| 4124 | | - struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
|---|
| 4585 | + struct sk_buff *skb2; |
|---|
| 4125 | 4586 | |
|---|
| 4587 | + if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP)) |
|---|
| 4588 | + continue; |
|---|
| 4589 | + |
|---|
| 4590 | + if (bond_is_last_slave(bond, slave)) { |
|---|
| 4591 | + skb2 = skb; |
|---|
| 4592 | + skb_used = true; |
|---|
| 4593 | + } else { |
|---|
| 4594 | + skb2 = skb_clone(skb, GFP_ATOMIC); |
|---|
| 4126 | 4595 | if (!skb2) { |
|---|
| 4127 | 4596 | net_err_ratelimited("%s: Error: %s: skb_clone() failed\n", |
|---|
| 4128 | 4597 | bond_dev->name, __func__); |
|---|
| 4129 | 4598 | continue; |
|---|
| 4130 | 4599 | } |
|---|
| 4131 | | - bond_dev_queue_xmit(bond, skb2, slave->dev); |
|---|
| 4132 | 4600 | } |
|---|
| 4133 | | - } |
|---|
| 4134 | | - if (slave && bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) |
|---|
| 4135 | | - bond_dev_queue_xmit(bond, skb, slave->dev); |
|---|
| 4136 | | - else |
|---|
| 4137 | | - bond_tx_drop(bond_dev, skb); |
|---|
| 4138 | 4601 | |
|---|
| 4139 | | - return NETDEV_TX_OK; |
|---|
| 4602 | + if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK) |
|---|
| 4603 | + xmit_suc = true; |
|---|
| 4604 | + } |
|---|
| 4605 | + |
|---|
| 4606 | + if (!skb_used) |
|---|
| 4607 | + dev_kfree_skb_any(skb); |
|---|
| 4608 | + |
|---|
| 4609 | + if (xmit_suc) |
|---|
| 4610 | + return NETDEV_TX_OK; |
|---|
| 4611 | + |
|---|
| 4612 | + atomic_long_inc(&bond_dev->tx_dropped); |
|---|
| 4613 | + return NET_XMIT_DROP; |
|---|
| 4140 | 4614 | } |
|---|
| 4141 | 4615 | |
|---|
| 4142 | 4616 | /*------------------------- Device initialization ---------------------------*/ |
|---|
| .. | .. |
|---|
| 4169 | 4643 | |
|---|
| 4170 | 4644 | |
|---|
| 4171 | 4645 | static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb, |
|---|
| 4172 | | - struct net_device *sb_dev, |
|---|
| 4173 | | - select_queue_fallback_t fallback) |
|---|
| 4646 | + struct net_device *sb_dev) |
|---|
| 4174 | 4647 | { |
|---|
| 4175 | 4648 | /* This helper function exists to help dev_pick_tx get the correct |
|---|
| 4176 | 4649 | * destination queue. Using a helper function skips a call to |
|---|
| .. | .. |
|---|
| 4188 | 4661 | } while (txq >= dev->real_num_tx_queues); |
|---|
| 4189 | 4662 | } |
|---|
| 4190 | 4663 | return txq; |
|---|
| 4664 | +} |
|---|
| 4665 | + |
|---|
| 4666 | +static struct net_device *bond_xmit_get_slave(struct net_device *master_dev, |
|---|
| 4667 | + struct sk_buff *skb, |
|---|
| 4668 | + bool all_slaves) |
|---|
| 4669 | +{ |
|---|
| 4670 | + struct bonding *bond = netdev_priv(master_dev); |
|---|
| 4671 | + struct bond_up_slave *slaves; |
|---|
| 4672 | + struct slave *slave = NULL; |
|---|
| 4673 | + |
|---|
| 4674 | + switch (BOND_MODE(bond)) { |
|---|
| 4675 | + case BOND_MODE_ROUNDROBIN: |
|---|
| 4676 | + slave = bond_xmit_roundrobin_slave_get(bond, skb); |
|---|
| 4677 | + break; |
|---|
| 4678 | + case BOND_MODE_ACTIVEBACKUP: |
|---|
| 4679 | + slave = bond_xmit_activebackup_slave_get(bond, skb); |
|---|
| 4680 | + break; |
|---|
| 4681 | + case BOND_MODE_8023AD: |
|---|
| 4682 | + case BOND_MODE_XOR: |
|---|
| 4683 | + if (all_slaves) |
|---|
| 4684 | + slaves = rcu_dereference(bond->all_slaves); |
|---|
| 4685 | + else |
|---|
| 4686 | + slaves = rcu_dereference(bond->usable_slaves); |
|---|
| 4687 | + slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves); |
|---|
| 4688 | + break; |
|---|
| 4689 | + case BOND_MODE_BROADCAST: |
|---|
| 4690 | + break; |
|---|
| 4691 | + case BOND_MODE_ALB: |
|---|
| 4692 | + slave = bond_xmit_alb_slave_get(bond, skb); |
|---|
| 4693 | + break; |
|---|
| 4694 | + case BOND_MODE_TLB: |
|---|
| 4695 | + slave = bond_xmit_tlb_slave_get(bond, skb); |
|---|
| 4696 | + break; |
|---|
| 4697 | + default: |
|---|
| 4698 | + /* Should never happen, mode already checked */ |
|---|
| 4699 | + WARN_ONCE(true, "Unknown bonding mode"); |
|---|
| 4700 | + break; |
|---|
| 4701 | + } |
|---|
| 4702 | + |
|---|
| 4703 | + if (slave) |
|---|
| 4704 | + return slave->dev; |
|---|
| 4705 | + return NULL; |
|---|
| 4191 | 4706 | } |
|---|
| 4192 | 4707 | |
|---|
| 4193 | 4708 | static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev) |
|---|
| .. | .. |
|---|
| 4216 | 4731 | /* Should never happen, mode already checked */ |
|---|
| 4217 | 4732 | netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond)); |
|---|
| 4218 | 4733 | WARN_ON_ONCE(1); |
|---|
| 4219 | | - bond_tx_drop(dev, skb); |
|---|
| 4220 | | - return NETDEV_TX_OK; |
|---|
| 4734 | + return bond_tx_drop(dev, skb); |
|---|
| 4221 | 4735 | } |
|---|
| 4222 | 4736 | } |
|---|
| 4223 | 4737 | |
|---|
| .. | .. |
|---|
| 4236 | 4750 | if (bond_has_slaves(bond)) |
|---|
| 4237 | 4751 | ret = __bond_start_xmit(skb, dev); |
|---|
| 4238 | 4752 | else |
|---|
| 4239 | | - bond_tx_drop(dev, skb); |
|---|
| 4753 | + ret = bond_tx_drop(dev, skb); |
|---|
| 4240 | 4754 | rcu_read_unlock(); |
|---|
| 4241 | 4755 | |
|---|
| 4242 | 4756 | return ret; |
|---|
| .. | .. |
|---|
| 4291 | 4805 | struct ethtool_drvinfo *drvinfo) |
|---|
| 4292 | 4806 | { |
|---|
| 4293 | 4807 | strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
|---|
| 4294 | | - strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version)); |
|---|
| 4295 | 4808 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d", |
|---|
| 4296 | 4809 | BOND_ABI_VERSION); |
|---|
| 4297 | 4810 | } |
|---|
| .. | .. |
|---|
| 4318 | 4831 | .ndo_neigh_setup = bond_neigh_setup, |
|---|
| 4319 | 4832 | .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid, |
|---|
| 4320 | 4833 | .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, |
|---|
| 4321 | | - .ndo_get_lock_subclass = bond_get_nest_level, |
|---|
| 4322 | 4834 | #ifdef CONFIG_NET_POLL_CONTROLLER |
|---|
| 4323 | 4835 | .ndo_netpoll_setup = bond_netpoll_setup, |
|---|
| 4324 | 4836 | .ndo_netpoll_cleanup = bond_netpoll_cleanup, |
|---|
| .. | .. |
|---|
| 4328 | 4840 | .ndo_del_slave = bond_release, |
|---|
| 4329 | 4841 | .ndo_fix_features = bond_fix_features, |
|---|
| 4330 | 4842 | .ndo_features_check = passthru_features_check, |
|---|
| 4843 | + .ndo_get_xmit_slave = bond_xmit_get_slave, |
|---|
| 4331 | 4844 | }; |
|---|
| 4332 | 4845 | |
|---|
| 4333 | 4846 | static const struct device_type bond_type = { |
|---|
| .. | .. |
|---|
| 4346 | 4859 | struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 4347 | 4860 | |
|---|
| 4348 | 4861 | spin_lock_init(&bond->mode_lock); |
|---|
| 4349 | | - spin_lock_init(&bond->stats_lock); |
|---|
| 4350 | 4862 | bond->params = bonding_defaults; |
|---|
| 4351 | 4863 | |
|---|
| 4352 | 4864 | /* Initialize pointers */ |
|---|
| .. | .. |
|---|
| 4368 | 4880 | bond_dev->priv_flags |= IFF_BONDING | IFF_UNICAST_FLT | IFF_NO_QUEUE; |
|---|
| 4369 | 4881 | bond_dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING); |
|---|
| 4370 | 4882 | |
|---|
| 4883 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 4884 | + /* set up xfrm device ops (only supported in active-backup right now) */ |
|---|
| 4885 | + bond_dev->xfrmdev_ops = &bond_xfrmdev_ops; |
|---|
| 4886 | + INIT_LIST_HEAD(&bond->ipsec_list); |
|---|
| 4887 | + spin_lock_init(&bond->ipsec_lock); |
|---|
| 4888 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 4889 | + |
|---|
| 4371 | 4890 | /* don't acquire bond device's netif_tx_lock when transmitting */ |
|---|
| 4372 | 4891 | bond_dev->features |= NETIF_F_LLTX; |
|---|
| 4373 | 4892 | |
|---|
| .. | .. |
|---|
| 4386 | 4905 | NETIF_F_HW_VLAN_CTAG_FILTER; |
|---|
| 4387 | 4906 | |
|---|
| 4388 | 4907 | bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4; |
|---|
| 4908 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 4909 | + bond_dev->hw_features |= BOND_XFRM_FEATURES; |
|---|
| 4910 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 4389 | 4911 | bond_dev->features |= bond_dev->hw_features; |
|---|
| 4390 | 4912 | bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX; |
|---|
| 4913 | +#ifdef CONFIG_XFRM_OFFLOAD |
|---|
| 4914 | + /* Disable XFRM features if this isn't an active-backup config */ |
|---|
| 4915 | + if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) |
|---|
| 4916 | + bond_dev->features &= ~BOND_XFRM_FEATURES; |
|---|
| 4917 | +#endif /* CONFIG_XFRM_OFFLOAD */ |
|---|
| 4391 | 4918 | } |
|---|
| 4392 | 4919 | |
|---|
| 4393 | 4920 | /* Destroy a bonding device. |
|---|
| .. | .. |
|---|
| 4396 | 4923 | static void bond_uninit(struct net_device *bond_dev) |
|---|
| 4397 | 4924 | { |
|---|
| 4398 | 4925 | struct bonding *bond = netdev_priv(bond_dev); |
|---|
| 4926 | + struct bond_up_slave *usable, *all; |
|---|
| 4399 | 4927 | struct list_head *iter; |
|---|
| 4400 | 4928 | struct slave *slave; |
|---|
| 4401 | | - struct bond_up_slave *arr; |
|---|
| 4402 | 4929 | |
|---|
| 4403 | 4930 | bond_netpoll_cleanup(bond_dev); |
|---|
| 4404 | 4931 | |
|---|
| .. | .. |
|---|
| 4407 | 4934 | __bond_release_one(bond_dev, slave->dev, true, true); |
|---|
| 4408 | 4935 | netdev_info(bond_dev, "Released all slaves\n"); |
|---|
| 4409 | 4936 | |
|---|
| 4410 | | - arr = rtnl_dereference(bond->slave_arr); |
|---|
| 4411 | | - if (arr) { |
|---|
| 4412 | | - RCU_INIT_POINTER(bond->slave_arr, NULL); |
|---|
| 4413 | | - kfree_rcu(arr, rcu); |
|---|
| 4937 | + usable = rtnl_dereference(bond->usable_slaves); |
|---|
| 4938 | + if (usable) { |
|---|
| 4939 | + RCU_INIT_POINTER(bond->usable_slaves, NULL); |
|---|
| 4940 | + kfree_rcu(usable, rcu); |
|---|
| 4941 | + } |
|---|
| 4942 | + |
|---|
| 4943 | + all = rtnl_dereference(bond->all_slaves); |
|---|
| 4944 | + if (all) { |
|---|
| 4945 | + RCU_INIT_POINTER(bond->all_slaves, NULL); |
|---|
| 4946 | + kfree_rcu(all, rcu); |
|---|
| 4414 | 4947 | } |
|---|
| 4415 | 4948 | |
|---|
| 4416 | 4949 | list_del(&bond->bond_list); |
|---|
| .. | .. |
|---|
| 4769 | 5302 | params->arp_all_targets = arp_all_targets_value; |
|---|
| 4770 | 5303 | params->updelay = updelay; |
|---|
| 4771 | 5304 | params->downdelay = downdelay; |
|---|
| 5305 | + params->peer_notif_delay = 0; |
|---|
| 4772 | 5306 | params->use_carrier = use_carrier; |
|---|
| 4773 | 5307 | params->lacp_fast = lacp_fast; |
|---|
| 4774 | 5308 | params->primary[0] = 0; |
|---|
| .. | .. |
|---|
| 4817 | 5351 | if (!bond->wq) |
|---|
| 4818 | 5352 | return -ENOMEM; |
|---|
| 4819 | 5353 | |
|---|
| 4820 | | - bond->nest_level = SINGLE_DEPTH_NESTING; |
|---|
| 5354 | + spin_lock_init(&bond->stats_lock); |
|---|
| 4821 | 5355 | netdev_lockdep_set_classes(bond_dev); |
|---|
| 4822 | 5356 | |
|---|
| 4823 | 5357 | list_add_tail(&bond->bond_list, &bn->dev_list); |
|---|
| .. | .. |
|---|
| 4932 | 5466 | int i; |
|---|
| 4933 | 5467 | int res; |
|---|
| 4934 | 5468 | |
|---|
| 4935 | | - pr_info("%s", bond_version); |
|---|
| 4936 | | - |
|---|
| 4937 | 5469 | res = bond_check_params(&bonding_defaults); |
|---|
| 4938 | 5470 | if (res) |
|---|
| 4939 | 5471 | goto out; |
|---|
| .. | .. |
|---|
| 4953 | 5485 | if (res) |
|---|
| 4954 | 5486 | goto err; |
|---|
| 4955 | 5487 | } |
|---|
| 5488 | + |
|---|
| 5489 | + skb_flow_dissector_init(&flow_keys_bonding, |
|---|
| 5490 | + flow_keys_bonding_keys, |
|---|
| 5491 | + ARRAY_SIZE(flow_keys_bonding_keys)); |
|---|
| 4956 | 5492 | |
|---|
| 4957 | 5493 | register_netdevice_notifier(&bond_netdev_notifier); |
|---|
| 4958 | 5494 | out: |
|---|
| .. | .. |
|---|
| 4984 | 5520 | module_init(bonding_init); |
|---|
| 4985 | 5521 | module_exit(bonding_exit); |
|---|
| 4986 | 5522 | MODULE_LICENSE("GPL"); |
|---|
| 4987 | | -MODULE_VERSION(DRV_VERSION); |
|---|
| 4988 | | -MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION); |
|---|
| 5523 | +MODULE_DESCRIPTION(DRV_DESCRIPTION); |
|---|
| 4989 | 5524 | MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others"); |
|---|