2 * originally based on the dummy device.
4 * Copyright 1999, Thomas Davis, tadavis@lbl.gov.
5 * Licensed under the GPL. Based on dummy.c, and eql.c devices.
7 * bonding.c: an Ethernet Bonding driver
9 * This is useful to talk to a Cisco EtherChannel compatible equipment:
11 * Sun Trunking (Solaris)
12 * Alteon AceDirector Trunks
14 * and probably many L2 switches ...
17 * ifconfig bond0 ipaddress netmask up
18 * will setup a network device, with an ip address. No mac address
19 * will be assigned at this time. The hw mac address will come from
20 * the first slave bonded to the channel. All slaves will then use
21 * this hw mac address.
24 * will release all slaves, marking them as down.
26 * ifenslave bond0 eth0
27 * will attach eth0 to bond0 as a slave. eth0 hw mac address will either
28 * a: be used as initial mac address
29 * b: if a hw mac address already is there, eth0's hw mac address
30 * will then be set from bond0.
34 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <linux/fcntl.h>
40 #include <linux/interrupt.h>
41 #include <linux/ptrace.h>
42 #include <linux/ioport.h>
46 #include <linux/tcp.h>
47 #include <linux/udp.h>
48 #include <linux/slab.h>
49 #include <linux/string.h>
50 #include <linux/init.h>
51 #include <linux/timer.h>
52 #include <linux/socket.h>
53 #include <linux/ctype.h>
54 #include <linux/inet.h>
55 #include <linux/bitops.h>
57 #include <asm/system.h>
59 #include <linux/uaccess.h>
60 #include <linux/errno.h>
61 #include <linux/netdevice.h>
62 #include <linux/inetdevice.h>
63 #include <linux/igmp.h>
64 #include <linux/etherdevice.h>
65 #include <linux/skbuff.h>
67 #include <linux/rtnetlink.h>
68 #include <linux/smp.h>
69 #include <linux/if_ether.h>
71 #include <linux/mii.h>
72 #include <linux/ethtool.h>
73 #include <linux/if_vlan.h>
74 #include <linux/if_bonding.h>
75 #include <linux/jiffies.h>
76 #include <linux/preempt.h>
77 #include <net/route.h>
78 #include <net/net_namespace.h>
79 #include <net/netns/generic.h>
84 /*---------------------------- Module parameters ----------------------------*/
86 /* monitor all links that often (in milliseconds). <=0 disables monitoring */
87 #define BOND_LINK_MON_INTERV 0
88 #define BOND_LINK_ARP_INTERV 0
90 static int max_bonds = BOND_DEFAULT_MAX_BONDS;
91 static int tx_queues = BOND_DEFAULT_TX_QUEUES;
92 static int num_peer_notif = 1;
93 static int miimon = BOND_LINK_MON_INTERV;
96 static int use_carrier = 1;
99 static char *primary_reselect;
100 static char *lacp_rate;
101 static char *ad_select;
102 static char *xmit_hash_policy;
103 static int arp_interval = BOND_LINK_ARP_INTERV;
104 static char *arp_ip_target[BOND_MAX_ARP_TARGETS];
105 static char *arp_validate;
106 static char *fail_over_mac;
107 static int all_slaves_active = 0;
108 static struct bond_params bonding_defaults;
109 static int resend_igmp = BOND_DEFAULT_RESEND_IGMP;
111 module_param(max_bonds, int, 0);
112 MODULE_PARM_DESC(max_bonds, "Max number of bonded devices");
113 module_param(tx_queues, int, 0);
114 MODULE_PARM_DESC(tx_queues, "Max number of transmit queues (default = 16)");
115 module_param_named(num_grat_arp, num_peer_notif, int, 0644);
116 MODULE_PARM_DESC(num_grat_arp, "Number of peer notifications to send on "
117 "failover event (alias of num_unsol_na)");
118 module_param_named(num_unsol_na, num_peer_notif, int, 0644);
119 MODULE_PARM_DESC(num_unsol_na, "Number of peer notifications to send on "
120 "failover event (alias of num_grat_arp)");
121 module_param(miimon, int, 0);
122 MODULE_PARM_DESC(miimon, "Link check interval in milliseconds");
123 module_param(updelay, int, 0);
124 MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds");
125 module_param(downdelay, int, 0);
126 MODULE_PARM_DESC(downdelay, "Delay before considering link down, "
128 module_param(use_carrier, int, 0);
129 MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; "
130 "0 for off, 1 for on (default)");
131 module_param(mode, charp, 0);
132 MODULE_PARM_DESC(mode, "Mode of operation; 0 for balance-rr, "
133 "1 for active-backup, 2 for balance-xor, "
134 "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, "
135 "6 for balance-alb");
136 module_param(primary, charp, 0);
137 MODULE_PARM_DESC(primary, "Primary network device to use");
138 module_param(primary_reselect, charp, 0);
139 MODULE_PARM_DESC(primary_reselect, "Reselect primary slave "
141 "0 for always (default), "
142 "1 for only if speed of primary is "
144 "2 for only on active slave "
146 module_param(lacp_rate, charp, 0);
147 MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner; "
148 "0 for slow, 1 for fast");
149 module_param(ad_select, charp, 0);
150 MODULE_PARM_DESC(ad_select, "803.ad aggregation selection logic; "
151 "0 for stable (default), 1 for bandwidth, "
153 module_param(xmit_hash_policy, charp, 0);
154 MODULE_PARM_DESC(xmit_hash_policy, "balance-xor and 802.3ad hashing method; "
155 "0 for layer 2 (default), 1 for layer 3+4, "
157 module_param(arp_interval, int, 0);
158 MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
159 module_param_array(arp_ip_target, charp, NULL, 0);
160 MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form");
161 module_param(arp_validate, charp, 0);
162 MODULE_PARM_DESC(arp_validate, "validate src/dst of ARP probes; "
163 "0 for none (default), 1 for active, "
164 "2 for backup, 3 for all");
165 module_param(fail_over_mac, charp, 0);
166 MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to "
167 "the same MAC; 0 for none (default), "
168 "1 for active, 2 for follow");
169 module_param(all_slaves_active, int, 0);
170 MODULE_PARM_DESC(all_slaves_active, "Keep all frames received on an interface"
171 "by setting active flag for all slaves; "
172 "0 for never (default), 1 for always.");
173 module_param(resend_igmp, int, 0);
174 MODULE_PARM_DESC(resend_igmp, "Number of IGMP membership reports to send on "
177 /*----------------------------- Global variables ----------------------------*/
179 #ifdef CONFIG_NET_POLL_CONTROLLER
180 atomic_t netpoll_block_tx = ATOMIC_INIT(0);
183 int bond_net_id __read_mostly;
185 static __be32 arp_target[BOND_MAX_ARP_TARGETS];
186 static int arp_ip_count;
187 static int bond_mode = BOND_MODE_ROUNDROBIN;
188 static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2;
189 static int lacp_fast;
191 const struct bond_parm_tbl bond_lacp_tbl[] = {
192 { "slow", AD_LACP_SLOW},
193 { "fast", AD_LACP_FAST},
197 const struct bond_parm_tbl bond_mode_tbl[] = {
198 { "balance-rr", BOND_MODE_ROUNDROBIN},
199 { "active-backup", BOND_MODE_ACTIVEBACKUP},
200 { "balance-xor", BOND_MODE_XOR},
201 { "broadcast", BOND_MODE_BROADCAST},
202 { "802.3ad", BOND_MODE_8023AD},
203 { "balance-tlb", BOND_MODE_TLB},
204 { "balance-alb", BOND_MODE_ALB},
208 const struct bond_parm_tbl xmit_hashtype_tbl[] = {
209 { "layer2", BOND_XMIT_POLICY_LAYER2},
210 { "layer3+4", BOND_XMIT_POLICY_LAYER34},
211 { "layer2+3", BOND_XMIT_POLICY_LAYER23},
215 const struct bond_parm_tbl arp_validate_tbl[] = {
216 { "none", BOND_ARP_VALIDATE_NONE},
217 { "active", BOND_ARP_VALIDATE_ACTIVE},
218 { "backup", BOND_ARP_VALIDATE_BACKUP},
219 { "all", BOND_ARP_VALIDATE_ALL},
223 const struct bond_parm_tbl fail_over_mac_tbl[] = {
224 { "none", BOND_FOM_NONE},
225 { "active", BOND_FOM_ACTIVE},
226 { "follow", BOND_FOM_FOLLOW},
230 const struct bond_parm_tbl pri_reselect_tbl[] = {
231 { "always", BOND_PRI_RESELECT_ALWAYS},
232 { "better", BOND_PRI_RESELECT_BETTER},
233 { "failure", BOND_PRI_RESELECT_FAILURE},
237 struct bond_parm_tbl ad_select_tbl[] = {
238 { "stable", BOND_AD_STABLE},
239 { "bandwidth", BOND_AD_BANDWIDTH},
240 { "count", BOND_AD_COUNT},
244 /*-------------------------- Forward declarations ---------------------------*/
246 static int bond_init(struct net_device *bond_dev);
247 static void bond_uninit(struct net_device *bond_dev);
249 /*---------------------------- General routines -----------------------------*/
251 const char *bond_mode_name(int mode)
253 static const char *names[] = {
254 [BOND_MODE_ROUNDROBIN] = "load balancing (round-robin)",
255 [BOND_MODE_ACTIVEBACKUP] = "fault-tolerance (active-backup)",
256 [BOND_MODE_XOR] = "load balancing (xor)",
257 [BOND_MODE_BROADCAST] = "fault-tolerance (broadcast)",
258 [BOND_MODE_8023AD] = "IEEE 802.3ad Dynamic link aggregation",
259 [BOND_MODE_TLB] = "transmit load balancing",
260 [BOND_MODE_ALB] = "adaptive load balancing",
263 if (mode < 0 || mode > BOND_MODE_ALB)
269 /*---------------------------------- VLAN -----------------------------------*/
272 * bond_add_vlan - add a new vlan id on bond
273 * @bond: bond that got the notification
274 * @vlan_id: the vlan id to add
276 * Returns -ENOMEM if allocation failed.
278 static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
280 struct vlan_entry *vlan;
282 pr_debug("bond: %s, vlan id %d\n",
283 (bond ? bond->dev->name : "None"), vlan_id);
285 vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL);
289 INIT_LIST_HEAD(&vlan->vlan_list);
290 vlan->vlan_id = vlan_id;
292 write_lock_bh(&bond->lock);
294 list_add_tail(&vlan->vlan_list, &bond->vlan_list);
296 write_unlock_bh(&bond->lock);
298 pr_debug("added VLAN ID %d on bond %s\n", vlan_id, bond->dev->name);
304 * bond_del_vlan - delete a vlan id from bond
305 * @bond: bond that got the notification
306 * @vlan_id: the vlan id to delete
308 * returns -ENODEV if @vlan_id was not found in @bond.
310 static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
312 struct vlan_entry *vlan;
315 pr_debug("bond: %s, vlan id %d\n", bond->dev->name, vlan_id);
318 write_lock_bh(&bond->lock);
320 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
321 if (vlan->vlan_id == vlan_id) {
322 list_del(&vlan->vlan_list);
324 if (bond_is_lb(bond))
325 bond_alb_clear_vlan(bond, vlan_id);
327 pr_debug("removed VLAN ID %d from bond %s\n",
328 vlan_id, bond->dev->name);
332 if (list_empty(&bond->vlan_list) &&
333 (bond->slave_cnt == 0)) {
334 /* Last VLAN removed and no slaves, so
335 * restore block on adding VLANs. This will
336 * be removed once new slaves that are not
337 * VLAN challenged will be added.
339 bond->dev->features |= NETIF_F_VLAN_CHALLENGED;
347 pr_debug("couldn't find VLAN ID %d in bond %s\n",
348 vlan_id, bond->dev->name);
351 write_unlock_bh(&bond->lock);
352 unblock_netpoll_tx();
357 * bond_next_vlan - safely skip to the next item in the vlans list.
358 * @bond: the bond we're working on
359 * @curr: item we're advancing from
361 * Returns %NULL if list is empty, bond->next_vlan if @curr is %NULL,
362 * or @curr->next otherwise (even if it is @curr itself again).
364 * Caller must hold bond->lock
366 struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr)
368 struct vlan_entry *next, *last;
370 if (list_empty(&bond->vlan_list))
374 next = list_entry(bond->vlan_list.next,
375 struct vlan_entry, vlan_list);
377 last = list_entry(bond->vlan_list.prev,
378 struct vlan_entry, vlan_list);
380 next = list_entry(bond->vlan_list.next,
381 struct vlan_entry, vlan_list);
383 next = list_entry(curr->vlan_list.next,
384 struct vlan_entry, vlan_list);
391 #define bond_queue_mapping(skb) (*(u16 *)((skb)->cb))
394 * bond_dev_queue_xmit - Prepare skb for xmit.
396 * @bond: bond device that got this skb for tx.
397 * @skb: hw accel VLAN tagged skb to transmit
398 * @slave_dev: slave that is supposed to xmit this skbuff
400 int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
401 struct net_device *slave_dev)
403 skb->dev = slave_dev;
406 skb->queue_mapping = bond_queue_mapping(skb);
408 if (unlikely(netpoll_tx_running(slave_dev)))
409 bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
417 * In the following 3 functions, bond_vlan_rx_register(), bond_vlan_rx_add_vid
418 * and bond_vlan_rx_kill_vid, We don't protect the slave list iteration with a
420 * a. This operation is performed in IOCTL context,
421 * b. The operation is protected by the RTNL semaphore in the 8021q code,
422 * c. Holding a lock with BH disabled while directly calling a base driver
423 * entry point is generally a BAD idea.
425 * The design of synchronization/protection for this operation in the 8021q
426 * module is good for one or more VLAN devices over a single physical device
427 * and cannot be extended for a teaming solution like bonding, so there is a
428 * potential race condition here where a net device from the vlan group might
429 * be referenced (either by a base driver or the 8021q code) while it is being
430 * removed from the system. However, it turns out we're not making matters
431 * worse, and if it works for regular VLAN usage it will work here too.
435 * bond_vlan_rx_register - Propagates registration to slaves
436 * @bond_dev: bonding net device that got called
437 * @grp: vlan group being registered
439 static void bond_vlan_rx_register(struct net_device *bond_dev,
440 struct vlan_group *grp)
442 struct bonding *bond = netdev_priv(bond_dev);
446 write_lock_bh(&bond->lock);
448 write_unlock_bh(&bond->lock);
450 bond_for_each_slave(bond, slave, i) {
451 struct net_device *slave_dev = slave->dev;
452 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
454 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
455 slave_ops->ndo_vlan_rx_register) {
456 slave_ops->ndo_vlan_rx_register(slave_dev, grp);
462 * bond_vlan_rx_add_vid - Propagates adding an id to slaves
463 * @bond_dev: bonding net device that got called
464 * @vid: vlan id being added
466 static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid)
468 struct bonding *bond = netdev_priv(bond_dev);
472 bond_for_each_slave(bond, slave, i) {
473 struct net_device *slave_dev = slave->dev;
474 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
476 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) &&
477 slave_ops->ndo_vlan_rx_add_vid) {
478 slave_ops->ndo_vlan_rx_add_vid(slave_dev, vid);
482 res = bond_add_vlan(bond, vid);
484 pr_err("%s: Error: Failed to add vlan id %d\n",
485 bond_dev->name, vid);
490 * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves
491 * @bond_dev: bonding net device that got called
492 * @vid: vlan id being removed
494 static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
496 struct bonding *bond = netdev_priv(bond_dev);
498 struct net_device *vlan_dev;
501 bond_for_each_slave(bond, slave, i) {
502 struct net_device *slave_dev = slave->dev;
503 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
505 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) &&
506 slave_ops->ndo_vlan_rx_kill_vid) {
507 /* Save and then restore vlan_dev in the grp array,
508 * since the slave's driver might clear it.
510 vlan_dev = vlan_group_get_device(bond->vlgrp, vid);
511 slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vid);
512 vlan_group_set_device(bond->vlgrp, vid, vlan_dev);
516 res = bond_del_vlan(bond, vid);
518 pr_err("%s: Error: Failed to remove vlan id %d\n",
519 bond_dev->name, vid);
523 static void bond_add_vlans_on_slave(struct bonding *bond, struct net_device *slave_dev)
525 struct vlan_entry *vlan;
526 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
531 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
532 slave_ops->ndo_vlan_rx_register)
533 slave_ops->ndo_vlan_rx_register(slave_dev, bond->vlgrp);
535 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) ||
536 !(slave_ops->ndo_vlan_rx_add_vid))
539 list_for_each_entry(vlan, &bond->vlan_list, vlan_list)
540 slave_ops->ndo_vlan_rx_add_vid(slave_dev, vlan->vlan_id);
543 static void bond_del_vlans_from_slave(struct bonding *bond,
544 struct net_device *slave_dev)
546 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
547 struct vlan_entry *vlan;
548 struct net_device *vlan_dev;
553 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) ||
554 !(slave_ops->ndo_vlan_rx_kill_vid))
557 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
560 /* Save and then restore vlan_dev in the grp array,
561 * since the slave's driver might clear it.
563 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
564 slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vlan->vlan_id);
565 vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev);
569 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
570 slave_ops->ndo_vlan_rx_register)
571 slave_ops->ndo_vlan_rx_register(slave_dev, NULL);
574 /*------------------------------- Link status -------------------------------*/
577 * Set the carrier state for the master according to the state of its
578 * slaves. If any slaves are up, the master is up. In 802.3ad mode,
579 * do special 802.3ad magic.
581 * Returns zero if carrier state does not change, nonzero if it does.
583 static int bond_set_carrier(struct bonding *bond)
588 if (bond->slave_cnt == 0)
591 if (bond->params.mode == BOND_MODE_8023AD)
592 return bond_3ad_set_carrier(bond);
594 bond_for_each_slave(bond, slave, i) {
595 if (slave->link == BOND_LINK_UP) {
596 if (!netif_carrier_ok(bond->dev)) {
597 netif_carrier_on(bond->dev);
605 if (netif_carrier_ok(bond->dev)) {
606 netif_carrier_off(bond->dev);
613 * Get link speed and duplex from the slave's base driver
614 * using ethtool. If for some reason the call fails or the
615 * values are invalid, fake speed and duplex to 100/Full
618 static int bond_update_speed_duplex(struct slave *slave)
620 struct net_device *slave_dev = slave->dev;
621 struct ethtool_cmd etool = { .cmd = ETHTOOL_GSET };
625 /* Fake speed and duplex */
626 slave->speed = SPEED_100;
627 slave->duplex = DUPLEX_FULL;
629 if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings)
632 res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
636 slave_speed = ethtool_cmd_speed(&etool);
637 switch (slave_speed) {
647 switch (etool.duplex) {
655 slave->speed = slave_speed;
656 slave->duplex = etool.duplex;
662 * if <dev> supports MII link status reporting, check its link status.
664 * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(),
665 * depending upon the setting of the use_carrier parameter.
667 * Return either BMSR_LSTATUS, meaning that the link is up (or we
668 * can't tell and just pretend it is), or 0, meaning that the link is
671 * If reporting is non-zero, instead of faking link up, return -1 if
672 * both ETHTOOL and MII ioctls fail (meaning the device does not
673 * support them). If use_carrier is set, return whatever it says.
674 * It'd be nice if there was a good way to tell if a driver supports
675 * netif_carrier, but there really isn't.
677 static int bond_check_dev_link(struct bonding *bond,
678 struct net_device *slave_dev, int reporting)
680 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
681 int (*ioctl)(struct net_device *, struct ifreq *, int);
683 struct mii_ioctl_data *mii;
685 if (!reporting && !netif_running(slave_dev))
688 if (bond->params.use_carrier)
689 return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
691 /* Try to get link status using Ethtool first. */
692 if (slave_dev->ethtool_ops) {
693 if (slave_dev->ethtool_ops->get_link) {
696 link = slave_dev->ethtool_ops->get_link(slave_dev);
698 return link ? BMSR_LSTATUS : 0;
702 /* Ethtool can't be used, fallback to MII ioctls. */
703 ioctl = slave_ops->ndo_do_ioctl;
705 /* TODO: set pointer to correct ioctl on a per team member */
706 /* bases to make this more efficient. that is, once */
707 /* we determine the correct ioctl, we will always */
708 /* call it and not the others for that team */
712 * We cannot assume that SIOCGMIIPHY will also read a
713 * register; not all network drivers (e.g., e100)
717 /* Yes, the mii is overlaid on the ifreq.ifr_ifru */
718 strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
720 if (IOCTL(slave_dev, &ifr, SIOCGMIIPHY) == 0) {
721 mii->reg_num = MII_BMSR;
722 if (IOCTL(slave_dev, &ifr, SIOCGMIIREG) == 0)
723 return mii->val_out & BMSR_LSTATUS;
728 * If reporting, report that either there's no dev->do_ioctl,
729 * or both SIOCGMIIREG and get_link failed (meaning that we
730 * cannot report link status). If not reporting, pretend
733 return reporting ? -1 : BMSR_LSTATUS;
736 /*----------------------------- Multicast list ------------------------------*/
739 * Push the promiscuity flag down to appropriate slaves
741 static int bond_set_promiscuity(struct bonding *bond, int inc)
744 if (USES_PRIMARY(bond->params.mode)) {
745 /* write lock already acquired */
746 if (bond->curr_active_slave) {
747 err = dev_set_promiscuity(bond->curr_active_slave->dev,
753 bond_for_each_slave(bond, slave, i) {
754 err = dev_set_promiscuity(slave->dev, inc);
763 * Push the allmulti flag down to all slaves
765 static int bond_set_allmulti(struct bonding *bond, int inc)
768 if (USES_PRIMARY(bond->params.mode)) {
769 /* write lock already acquired */
770 if (bond->curr_active_slave) {
771 err = dev_set_allmulti(bond->curr_active_slave->dev,
777 bond_for_each_slave(bond, slave, i) {
778 err = dev_set_allmulti(slave->dev, inc);
787 * Add a Multicast address to slaves
790 static void bond_mc_add(struct bonding *bond, void *addr)
792 if (USES_PRIMARY(bond->params.mode)) {
793 /* write lock already acquired */
794 if (bond->curr_active_slave)
795 dev_mc_add(bond->curr_active_slave->dev, addr);
800 bond_for_each_slave(bond, slave, i)
801 dev_mc_add(slave->dev, addr);
806 * Remove a multicast address from slave
809 static void bond_mc_del(struct bonding *bond, void *addr)
811 if (USES_PRIMARY(bond->params.mode)) {
812 /* write lock already acquired */
813 if (bond->curr_active_slave)
814 dev_mc_del(bond->curr_active_slave->dev, addr);
818 bond_for_each_slave(bond, slave, i) {
819 dev_mc_del(slave->dev, addr);
825 static void __bond_resend_igmp_join_requests(struct net_device *dev)
827 struct in_device *in_dev;
830 in_dev = __in_dev_get_rcu(dev);
832 ip_mc_rejoin_groups(in_dev);
837 * Retrieve the list of registered multicast addresses for the bonding
838 * device and retransmit an IGMP JOIN request to the current active
841 static void bond_resend_igmp_join_requests(struct bonding *bond)
843 struct net_device *vlan_dev;
844 struct vlan_entry *vlan;
846 read_lock(&bond->lock);
848 /* rejoin all groups on bond device */
849 __bond_resend_igmp_join_requests(bond->dev);
851 /* rejoin all groups on vlan devices */
853 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
854 vlan_dev = vlan_group_get_device(bond->vlgrp,
857 __bond_resend_igmp_join_requests(vlan_dev);
861 if (--bond->igmp_retrans > 0)
862 queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
864 read_unlock(&bond->lock);
867 static void bond_resend_igmp_join_requests_delayed(struct work_struct *work)
869 struct bonding *bond = container_of(work, struct bonding,
871 bond_resend_igmp_join_requests(bond);
875 * flush all members of flush->mc_list from device dev->mc_list
877 static void bond_mc_list_flush(struct net_device *bond_dev,
878 struct net_device *slave_dev)
880 struct bonding *bond = netdev_priv(bond_dev);
881 struct netdev_hw_addr *ha;
883 netdev_for_each_mc_addr(ha, bond_dev)
884 dev_mc_del(slave_dev, ha->addr);
886 if (bond->params.mode == BOND_MODE_8023AD) {
887 /* del lacpdu mc addr from mc list */
888 u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
890 dev_mc_del(slave_dev, lacpdu_multicast);
894 /*--------------------------- Active slave change ---------------------------*/
897 * Update the mc list and multicast-related flags for the new and
898 * old active slaves (if any) according to the multicast mode, and
899 * promiscuous flags unconditionally.
901 static void bond_mc_swap(struct bonding *bond, struct slave *new_active,
902 struct slave *old_active)
904 struct netdev_hw_addr *ha;
906 if (!USES_PRIMARY(bond->params.mode))
907 /* nothing to do - mc list is already up-to-date on
913 if (bond->dev->flags & IFF_PROMISC)
914 dev_set_promiscuity(old_active->dev, -1);
916 if (bond->dev->flags & IFF_ALLMULTI)
917 dev_set_allmulti(old_active->dev, -1);
919 netdev_for_each_mc_addr(ha, bond->dev)
920 dev_mc_del(old_active->dev, ha->addr);
924 /* FIXME: Signal errors upstream. */
925 if (bond->dev->flags & IFF_PROMISC)
926 dev_set_promiscuity(new_active->dev, 1);
928 if (bond->dev->flags & IFF_ALLMULTI)
929 dev_set_allmulti(new_active->dev, 1);
931 netdev_for_each_mc_addr(ha, bond->dev)
932 dev_mc_add(new_active->dev, ha->addr);
937 * bond_do_fail_over_mac
939 * Perform special MAC address swapping for fail_over_mac settings
941 * Called with RTNL, bond->lock for read, curr_slave_lock for write_bh.
943 static void bond_do_fail_over_mac(struct bonding *bond,
944 struct slave *new_active,
945 struct slave *old_active)
946 __releases(&bond->curr_slave_lock)
947 __releases(&bond->lock)
948 __acquires(&bond->lock)
949 __acquires(&bond->curr_slave_lock)
951 u8 tmp_mac[ETH_ALEN];
952 struct sockaddr saddr;
955 switch (bond->params.fail_over_mac) {
956 case BOND_FOM_ACTIVE:
958 memcpy(bond->dev->dev_addr, new_active->dev->dev_addr,
959 new_active->dev->addr_len);
961 case BOND_FOM_FOLLOW:
963 * if new_active && old_active, swap them
964 * if just old_active, do nothing (going to no active slave)
965 * if just new_active, set new_active to bond's MAC
970 write_unlock_bh(&bond->curr_slave_lock);
971 read_unlock(&bond->lock);
974 memcpy(tmp_mac, new_active->dev->dev_addr, ETH_ALEN);
975 memcpy(saddr.sa_data, old_active->dev->dev_addr,
977 saddr.sa_family = new_active->dev->type;
979 memcpy(saddr.sa_data, bond->dev->dev_addr, ETH_ALEN);
980 saddr.sa_family = bond->dev->type;
983 rv = dev_set_mac_address(new_active->dev, &saddr);
985 pr_err("%s: Error %d setting MAC of slave %s\n",
986 bond->dev->name, -rv, new_active->dev->name);
993 memcpy(saddr.sa_data, tmp_mac, ETH_ALEN);
994 saddr.sa_family = old_active->dev->type;
996 rv = dev_set_mac_address(old_active->dev, &saddr);
998 pr_err("%s: Error %d setting MAC of slave %s\n",
999 bond->dev->name, -rv, new_active->dev->name);
1001 read_lock(&bond->lock);
1002 write_lock_bh(&bond->curr_slave_lock);
1005 pr_err("%s: bond_do_fail_over_mac impossible: bad policy %d\n",
1006 bond->dev->name, bond->params.fail_over_mac);
1012 static bool bond_should_change_active(struct bonding *bond)
1014 struct slave *prim = bond->primary_slave;
1015 struct slave *curr = bond->curr_active_slave;
1017 if (!prim || !curr || curr->link != BOND_LINK_UP)
1019 if (bond->force_primary) {
1020 bond->force_primary = false;
1023 if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER &&
1024 (prim->speed < curr->speed ||
1025 (prim->speed == curr->speed && prim->duplex <= curr->duplex)))
1027 if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE)
1033 * find_best_interface - select the best available slave to be the active one
1034 * @bond: our bonding struct
1036 * Warning: Caller must hold curr_slave_lock for writing.
1038 static struct slave *bond_find_best_slave(struct bonding *bond)
1040 struct slave *new_active, *old_active;
1041 struct slave *bestslave = NULL;
1042 int mintime = bond->params.updelay;
1045 new_active = bond->curr_active_slave;
1047 if (!new_active) { /* there were no active slaves left */
1048 if (bond->slave_cnt > 0) /* found one slave */
1049 new_active = bond->first_slave;
1051 return NULL; /* still no slave, return NULL */
1054 if ((bond->primary_slave) &&
1055 bond->primary_slave->link == BOND_LINK_UP &&
1056 bond_should_change_active(bond)) {
1057 new_active = bond->primary_slave;
1060 /* remember where to stop iterating over the slaves */
1061 old_active = new_active;
1063 bond_for_each_slave_from(bond, new_active, i, old_active) {
1064 if (new_active->link == BOND_LINK_UP) {
1066 } else if (new_active->link == BOND_LINK_BACK &&
1067 IS_UP(new_active->dev)) {
1068 /* link up, but waiting for stabilization */
1069 if (new_active->delay < mintime) {
1070 mintime = new_active->delay;
1071 bestslave = new_active;
1079 static bool bond_should_notify_peers(struct bonding *bond)
1081 struct slave *slave = bond->curr_active_slave;
1083 pr_debug("bond_should_notify_peers: bond %s slave %s\n",
1084 bond->dev->name, slave ? slave->dev->name : "NULL");
1086 if (!slave || !bond->send_peer_notif ||
1087 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
1090 bond->send_peer_notif--;
1095 * change_active_interface - change the active slave into the specified one
1096 * @bond: our bonding struct
1097 * @new: the new slave to make the active one
1099 * Set the new slave to the bond's settings and unset them on the old
1100 * curr_active_slave.
1101 * Setting include flags, mc-list, promiscuity, allmulti, etc.
1103 * If @new's link state is %BOND_LINK_BACK we'll set it to %BOND_LINK_UP,
1104 * because it is apparently the best available slave we have, even though its
1105 * updelay hasn't timed out yet.
1107 * If new_active is not NULL, caller must hold bond->lock for read and
1108 * curr_slave_lock for write_bh.
1110 void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1112 struct slave *old_active = bond->curr_active_slave;
1114 if (old_active == new_active)
1118 new_active->jiffies = jiffies;
1120 if (new_active->link == BOND_LINK_BACK) {
1121 if (USES_PRIMARY(bond->params.mode)) {
1122 pr_info("%s: making interface %s the new active one %d ms earlier.\n",
1123 bond->dev->name, new_active->dev->name,
1124 (bond->params.updelay - new_active->delay) * bond->params.miimon);
1127 new_active->delay = 0;
1128 new_active->link = BOND_LINK_UP;
1130 if (bond->params.mode == BOND_MODE_8023AD)
1131 bond_3ad_handle_link_change(new_active, BOND_LINK_UP);
1133 if (bond_is_lb(bond))
1134 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
1136 if (USES_PRIMARY(bond->params.mode)) {
1137 pr_info("%s: making interface %s the new active one.\n",
1138 bond->dev->name, new_active->dev->name);
1143 if (USES_PRIMARY(bond->params.mode))
1144 bond_mc_swap(bond, new_active, old_active);
1146 if (bond_is_lb(bond)) {
1147 bond_alb_handle_active_change(bond, new_active);
1149 bond_set_slave_inactive_flags(old_active);
1151 bond_set_slave_active_flags(new_active);
1153 bond->curr_active_slave = new_active;
1156 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1158 bond_set_slave_inactive_flags(old_active);
1161 bool should_notify_peers = false;
1163 bond_set_slave_active_flags(new_active);
1165 if (bond->params.fail_over_mac)
1166 bond_do_fail_over_mac(bond, new_active,
1169 if (netif_running(bond->dev)) {
1170 bond->send_peer_notif =
1171 bond->params.num_peer_notif;
1172 should_notify_peers =
1173 bond_should_notify_peers(bond);
1176 write_unlock_bh(&bond->curr_slave_lock);
1177 read_unlock(&bond->lock);
1179 netdev_bonding_change(bond->dev, NETDEV_BONDING_FAILOVER);
1180 if (should_notify_peers)
1181 netdev_bonding_change(bond->dev,
1182 NETDEV_NOTIFY_PEERS);
1184 read_lock(&bond->lock);
1185 write_lock_bh(&bond->curr_slave_lock);
1189 /* resend IGMP joins since active slave has changed or
1190 * all were sent on curr_active_slave.
1191 * resend only if bond is brought up with the affected
1192 * bonding modes and the retransmission is enabled */
1193 if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
1194 ((USES_PRIMARY(bond->params.mode) && new_active) ||
1195 bond->params.mode == BOND_MODE_ROUNDROBIN)) {
1196 bond->igmp_retrans = bond->params.resend_igmp;
1197 queue_delayed_work(bond->wq, &bond->mcast_work, 0);
1202 * bond_select_active_slave - select a new active slave, if needed
1203 * @bond: our bonding struct
1205 * This functions should be called when one of the following occurs:
1206 * - The old curr_active_slave has been released or lost its link.
1207 * - The primary_slave has got its link back.
1208 * - A slave has got its link back and there's no old curr_active_slave.
1210 * Caller must hold bond->lock for read and curr_slave_lock for write_bh.
1212 void bond_select_active_slave(struct bonding *bond)
1214 struct slave *best_slave;
1217 best_slave = bond_find_best_slave(bond);
1218 if (best_slave != bond->curr_active_slave) {
1219 bond_change_active_slave(bond, best_slave);
1220 rv = bond_set_carrier(bond);
1224 if (netif_carrier_ok(bond->dev)) {
1225 pr_info("%s: first active interface up!\n",
1228 pr_info("%s: now running without any active interface !\n",
1234 /*--------------------------- slave list handling ---------------------------*/
1237 * This function attaches the slave to the end of list.
1239 * bond->lock held for writing by caller.
1241 static void bond_attach_slave(struct bonding *bond, struct slave *new_slave)
1243 if (bond->first_slave == NULL) { /* attaching the first slave */
1244 new_slave->next = new_slave;
1245 new_slave->prev = new_slave;
1246 bond->first_slave = new_slave;
1248 new_slave->next = bond->first_slave;
1249 new_slave->prev = bond->first_slave->prev;
1250 new_slave->next->prev = new_slave;
1251 new_slave->prev->next = new_slave;
1258 * This function detaches the slave from the list.
1259 * WARNING: no check is made to verify if the slave effectively
1260 * belongs to <bond>.
1261 * Nothing is freed on return, structures are just unchained.
1262 * If any slave pointer in bond was pointing to <slave>,
1263 * it should be changed by the calling function.
1265 * bond->lock held for writing by caller.
1267 static void bond_detach_slave(struct bonding *bond, struct slave *slave)
1270 slave->next->prev = slave->prev;
1273 slave->prev->next = slave->next;
1275 if (bond->first_slave == slave) { /* slave is the first slave */
1276 if (bond->slave_cnt > 1) { /* there are more slave */
1277 bond->first_slave = slave->next;
1279 bond->first_slave = NULL; /* slave was the last one */
1288 #ifdef CONFIG_NET_POLL_CONTROLLER
1289 static inline int slave_enable_netpoll(struct slave *slave)
1294 np = kzalloc(sizeof(*np), GFP_KERNEL);
1299 np->dev = slave->dev;
1300 err = __netpoll_setup(np);
1309 static inline void slave_disable_netpoll(struct slave *slave)
1311 struct netpoll *np = slave->np;
1317 synchronize_rcu_bh();
1318 __netpoll_cleanup(np);
1321 static inline bool slave_dev_support_netpoll(struct net_device *slave_dev)
1323 if (slave_dev->priv_flags & IFF_DISABLE_NETPOLL)
1325 if (!slave_dev->netdev_ops->ndo_poll_controller)
1330 static void bond_poll_controller(struct net_device *bond_dev)
1334 static void __bond_netpoll_cleanup(struct bonding *bond)
1336 struct slave *slave;
1339 bond_for_each_slave(bond, slave, i)
1340 if (IS_UP(slave->dev))
1341 slave_disable_netpoll(slave);
1343 static void bond_netpoll_cleanup(struct net_device *bond_dev)
1345 struct bonding *bond = netdev_priv(bond_dev);
1347 read_lock(&bond->lock);
1348 __bond_netpoll_cleanup(bond);
1349 read_unlock(&bond->lock);
1352 static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni)
1354 struct bonding *bond = netdev_priv(dev);
1355 struct slave *slave;
1358 read_lock(&bond->lock);
1359 bond_for_each_slave(bond, slave, i) {
1360 err = slave_enable_netpoll(slave);
1362 __bond_netpoll_cleanup(bond);
1366 read_unlock(&bond->lock);
1370 static struct netpoll_info *bond_netpoll_info(struct bonding *bond)
1372 return bond->dev->npinfo;
1376 static inline int slave_enable_netpoll(struct slave *slave)
1380 static inline void slave_disable_netpoll(struct slave *slave)
1383 static void bond_netpoll_cleanup(struct net_device *bond_dev)
1388 /*---------------------------------- IOCTL ----------------------------------*/
1390 static int bond_sethwaddr(struct net_device *bond_dev,
1391 struct net_device *slave_dev)
1393 pr_debug("bond_dev=%p\n", bond_dev);
1394 pr_debug("slave_dev=%p\n", slave_dev);
1395 pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
1396 memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
1400 static u32 bond_fix_features(struct net_device *dev, u32 features)
1402 struct slave *slave;
1403 struct bonding *bond = netdev_priv(dev);
1407 read_lock(&bond->lock);
1409 if (!bond->first_slave) {
1410 /* Disable adding VLANs to empty bond. But why? --mq */
1411 features |= NETIF_F_VLAN_CHALLENGED;
1416 features &= ~NETIF_F_ONE_FOR_ALL;
1417 features |= NETIF_F_ALL_FOR_ALL;
1419 bond_for_each_slave(bond, slave, i) {
1420 features = netdev_increment_features(features,
1421 slave->dev->features,
1426 read_unlock(&bond->lock);
1430 #define BOND_VLAN_FEATURES (NETIF_F_ALL_TX_OFFLOADS | \
1431 NETIF_F_SOFT_FEATURES | \
1434 static void bond_compute_features(struct bonding *bond)
1436 struct slave *slave;
1437 struct net_device *bond_dev = bond->dev;
1438 u32 vlan_features = BOND_VLAN_FEATURES;
1439 unsigned short max_hard_header_len = ETH_HLEN;
1442 read_lock(&bond->lock);
1444 if (!bond->first_slave)
1447 bond_for_each_slave(bond, slave, i) {
1448 vlan_features = netdev_increment_features(vlan_features,
1449 slave->dev->vlan_features, BOND_VLAN_FEATURES);
1451 if (slave->dev->hard_header_len > max_hard_header_len)
1452 max_hard_header_len = slave->dev->hard_header_len;
1456 bond_dev->vlan_features = vlan_features;
1457 bond_dev->hard_header_len = max_hard_header_len;
1459 read_unlock(&bond->lock);
1461 netdev_change_features(bond_dev);
1464 static void bond_setup_by_slave(struct net_device *bond_dev,
1465 struct net_device *slave_dev)
1467 struct bonding *bond = netdev_priv(bond_dev);
1469 bond_dev->header_ops = slave_dev->header_ops;
1471 bond_dev->type = slave_dev->type;
1472 bond_dev->hard_header_len = slave_dev->hard_header_len;
1473 bond_dev->addr_len = slave_dev->addr_len;
1475 memcpy(bond_dev->broadcast, slave_dev->broadcast,
1476 slave_dev->addr_len);
1477 bond->setup_by_slave = 1;
1480 /* On bonding slaves other than the currently active slave, suppress
1481 * duplicates except for alb non-mcast/bcast.
1483 static bool bond_should_deliver_exact_match(struct sk_buff *skb,
1484 struct slave *slave,
1485 struct bonding *bond)
1487 if (bond_is_slave_inactive(slave)) {
1488 if (bond->params.mode == BOND_MODE_ALB &&
1489 skb->pkt_type != PACKET_BROADCAST &&
1490 skb->pkt_type != PACKET_MULTICAST)
1497 static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
1499 struct sk_buff *skb = *pskb;
1500 struct slave *slave;
1501 struct bonding *bond;
1503 skb = skb_share_check(skb, GFP_ATOMIC);
1505 return RX_HANDLER_CONSUMED;
1509 slave = bond_slave_get_rcu(skb->dev);
1512 if (bond->params.arp_interval)
1513 slave->dev->last_rx = jiffies;
1515 if (bond->recv_probe) {
1516 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
1519 bond->recv_probe(nskb, bond, slave);
1520 dev_kfree_skb(nskb);
1524 if (bond_should_deliver_exact_match(skb, slave, bond)) {
1525 return RX_HANDLER_EXACT;
1528 skb->dev = bond->dev;
1530 if (bond->params.mode == BOND_MODE_ALB &&
1531 bond->dev->priv_flags & IFF_BRIDGE_PORT &&
1532 skb->pkt_type == PACKET_HOST) {
1534 if (unlikely(skb_cow_head(skb,
1535 skb->data - skb_mac_header(skb)))) {
1537 return RX_HANDLER_CONSUMED;
1539 memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN);
1542 return RX_HANDLER_ANOTHER;
1545 /* enslave device <slave> to bond device <master> */
1546 int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1548 struct bonding *bond = netdev_priv(bond_dev);
1549 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
1550 struct slave *new_slave = NULL;
1551 struct netdev_hw_addr *ha;
1552 struct sockaddr addr;
1556 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
1557 slave_ops->ndo_do_ioctl == NULL) {
1558 pr_warning("%s: Warning: no link monitoring support for %s\n",
1559 bond_dev->name, slave_dev->name);
1562 /* already enslaved */
1563 if (slave_dev->flags & IFF_SLAVE) {
1564 pr_debug("Error, Device was already enslaved\n");
1568 /* vlan challenged mutual exclusion */
1569 /* no need to lock since we're protected by rtnl_lock */
1570 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
1571 pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
1573 pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n",
1574 bond_dev->name, slave_dev->name, bond_dev->name);
1577 pr_warning("%s: Warning: enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n",
1578 bond_dev->name, slave_dev->name,
1579 slave_dev->name, bond_dev->name);
1582 pr_debug("%s: ! NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
1586 * Old ifenslave binaries are no longer supported. These can
1587 * be identified with moderate accuracy by the state of the slave:
1588 * the current ifenslave will set the interface down prior to
1589 * enslaving it; the old ifenslave will not.
1591 if ((slave_dev->flags & IFF_UP)) {
1592 pr_err("%s is up. This may be due to an out of date ifenslave.\n",
1595 goto err_undo_flags;
1598 /* set bonding device ether type by slave - bonding netdevices are
1599 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
1600 * there is a need to override some of the type dependent attribs/funcs.
1602 * bond ether type mutual exclusion - don't allow slaves of dissimilar
1603 * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
1605 if (bond->slave_cnt == 0) {
1606 if (bond_dev->type != slave_dev->type) {
1607 pr_debug("%s: change device type from %d to %d\n",
1609 bond_dev->type, slave_dev->type);
1611 res = netdev_bonding_change(bond_dev,
1612 NETDEV_PRE_TYPE_CHANGE);
1613 res = notifier_to_errno(res);
1615 pr_err("%s: refused to change device type\n",
1618 goto err_undo_flags;
1621 /* Flush unicast and multicast addresses */
1622 dev_uc_flush(bond_dev);
1623 dev_mc_flush(bond_dev);
1625 if (slave_dev->type != ARPHRD_ETHER)
1626 bond_setup_by_slave(bond_dev, slave_dev);
1628 ether_setup(bond_dev);
1630 netdev_bonding_change(bond_dev,
1631 NETDEV_POST_TYPE_CHANGE);
1633 } else if (bond_dev->type != slave_dev->type) {
1634 pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n",
1636 slave_dev->type, bond_dev->type);
1638 goto err_undo_flags;
1641 if (slave_ops->ndo_set_mac_address == NULL) {
1642 if (bond->slave_cnt == 0) {
1643 pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.",
1645 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1646 } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
1647 pr_err("%s: Error: The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active.\n",
1650 goto err_undo_flags;
1654 call_netdevice_notifiers(NETDEV_JOIN, slave_dev);
1656 /* If this is the first slave, then we need to set the master's hardware
1657 * address to be the same as the slave's. */
1658 if (is_zero_ether_addr(bond->dev->dev_addr))
1659 memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
1660 slave_dev->addr_len);
1663 new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
1666 goto err_undo_flags;
1670 * Set the new_slave's queue_id to be zero. Queue ID mapping
1671 * is set via sysfs or module option if desired.
1673 new_slave->queue_id = 0;
1675 /* Save slave's original mtu and then set it to match the bond */
1676 new_slave->original_mtu = slave_dev->mtu;
1677 res = dev_set_mtu(slave_dev, bond->dev->mtu);
1679 pr_debug("Error %d calling dev_set_mtu\n", res);
1684 * Save slave's original ("permanent") mac address for modes
1685 * that need it, and for restoring it upon release, and then
1686 * set it to the master's address
1688 memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN);
1690 if (!bond->params.fail_over_mac) {
1692 * Set slave to master's mac address. The application already
1693 * set the master's mac address to that of the first slave
1695 memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
1696 addr.sa_family = slave_dev->type;
1697 res = dev_set_mac_address(slave_dev, &addr);
1699 pr_debug("Error %d calling set_mac_address\n", res);
1700 goto err_restore_mtu;
1704 res = netdev_set_bond_master(slave_dev, bond_dev);
1706 pr_debug("Error %d calling netdev_set_bond_master\n", res);
1707 goto err_restore_mac;
1710 /* open the slave since the application closed it */
1711 res = dev_open(slave_dev);
1713 pr_debug("Opening slave %s failed\n", slave_dev->name);
1714 goto err_unset_master;
1717 new_slave->bond = bond;
1718 new_slave->dev = slave_dev;
1719 slave_dev->priv_flags |= IFF_BONDING;
1721 if (bond_is_lb(bond)) {
1722 /* bond_alb_init_slave() must be called before all other stages since
1723 * it might fail and we do not want to have to undo everything
1725 res = bond_alb_init_slave(bond, new_slave);
1730 /* If the mode USES_PRIMARY, then the new slave gets the
1731 * master's promisc (and mc) settings only if it becomes the
1732 * curr_active_slave, and that is taken care of later when calling
1733 * bond_change_active()
1735 if (!USES_PRIMARY(bond->params.mode)) {
1736 /* set promiscuity level to new slave */
1737 if (bond_dev->flags & IFF_PROMISC) {
1738 res = dev_set_promiscuity(slave_dev, 1);
1743 /* set allmulti level to new slave */
1744 if (bond_dev->flags & IFF_ALLMULTI) {
1745 res = dev_set_allmulti(slave_dev, 1);
1750 netif_addr_lock_bh(bond_dev);
1751 /* upload master's mc_list to new slave */
1752 netdev_for_each_mc_addr(ha, bond_dev)
1753 dev_mc_add(slave_dev, ha->addr);
1754 netif_addr_unlock_bh(bond_dev);
1757 if (bond->params.mode == BOND_MODE_8023AD) {
1758 /* add lacpdu mc addr to mc list */
1759 u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
1761 dev_mc_add(slave_dev, lacpdu_multicast);
1764 bond_add_vlans_on_slave(bond, slave_dev);
1766 write_lock_bh(&bond->lock);
1768 bond_attach_slave(bond, new_slave);
1770 new_slave->delay = 0;
1771 new_slave->link_failure_count = 0;
1773 write_unlock_bh(&bond->lock);
1775 bond_compute_features(bond);
1777 read_lock(&bond->lock);
1779 new_slave->last_arp_rx = jiffies;
1781 if (bond->params.miimon && !bond->params.use_carrier) {
1782 link_reporting = bond_check_dev_link(bond, slave_dev, 1);
1784 if ((link_reporting == -1) && !bond->params.arp_interval) {
1786 * miimon is set but a bonded network driver
1787 * does not support ETHTOOL/MII and
1788 * arp_interval is not set. Note: if
1789 * use_carrier is enabled, we will never go
1790 * here (because netif_carrier is always
1791 * supported); thus, we don't need to change
1792 * the messages for netif_carrier.
1794 pr_warning("%s: Warning: 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",
1795 bond_dev->name, slave_dev->name);
1796 } else if (link_reporting == -1) {
1797 /* unable get link status using mii/ethtool */
1798 pr_warning("%s: Warning: 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",
1799 bond_dev->name, slave_dev->name);
1803 /* check for initial state */
1804 if (!bond->params.miimon ||
1805 (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) {
1806 if (bond->params.updelay) {
1807 pr_debug("Initial state of slave_dev is BOND_LINK_BACK\n");
1808 new_slave->link = BOND_LINK_BACK;
1809 new_slave->delay = bond->params.updelay;
1811 pr_debug("Initial state of slave_dev is BOND_LINK_UP\n");
1812 new_slave->link = BOND_LINK_UP;
1814 new_slave->jiffies = jiffies;
1816 pr_debug("Initial state of slave_dev is BOND_LINK_DOWN\n");
1817 new_slave->link = BOND_LINK_DOWN;
1820 if (bond_update_speed_duplex(new_slave) &&
1821 (new_slave->link != BOND_LINK_DOWN)) {
1822 pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n",
1823 bond_dev->name, new_slave->dev->name);
1825 if (bond->params.mode == BOND_MODE_8023AD) {
1826 pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n",
1831 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) {
1832 /* if there is a primary slave, remember it */
1833 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
1834 bond->primary_slave = new_slave;
1835 bond->force_primary = true;
1839 write_lock_bh(&bond->curr_slave_lock);
1841 switch (bond->params.mode) {
1842 case BOND_MODE_ACTIVEBACKUP:
1843 bond_set_slave_inactive_flags(new_slave);
1844 bond_select_active_slave(bond);
1846 case BOND_MODE_8023AD:
1847 /* in 802.3ad mode, the internal mechanism
1848 * will activate the slaves in the selected
1851 bond_set_slave_inactive_flags(new_slave);
1852 /* if this is the first slave */
1853 if (bond->slave_cnt == 1) {
1854 SLAVE_AD_INFO(new_slave).id = 1;
1855 /* Initialize AD with the number of times that the AD timer is called in 1 second
1856 * can be called only after the mac address of the bond is set
1858 bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL,
1859 bond->params.lacp_fast);
1861 SLAVE_AD_INFO(new_slave).id =
1862 SLAVE_AD_INFO(new_slave->prev).id + 1;
1865 bond_3ad_bind_slave(new_slave);
1869 bond_set_active_slave(new_slave);
1870 bond_set_slave_inactive_flags(new_slave);
1871 bond_select_active_slave(bond);
1874 pr_debug("This slave is always active in trunk mode\n");
1876 /* always active in trunk mode */
1877 bond_set_active_slave(new_slave);
1879 /* In trunking mode there is little meaning to curr_active_slave
1880 * anyway (it holds no special properties of the bond device),
1881 * so we can change it without calling change_active_interface()
1883 if (!bond->curr_active_slave)
1884 bond->curr_active_slave = new_slave;
1887 } /* switch(bond_mode) */
1889 write_unlock_bh(&bond->curr_slave_lock);
1891 bond_set_carrier(bond);
1893 #ifdef CONFIG_NET_POLL_CONTROLLER
1894 slave_dev->npinfo = bond_netpoll_info(bond);
1895 if (slave_dev->npinfo) {
1896 if (slave_enable_netpoll(new_slave)) {
1897 read_unlock(&bond->lock);
1898 pr_info("Error, %s: master_dev is using netpoll, "
1899 "but new slave device does not support netpoll.\n",
1907 read_unlock(&bond->lock);
1909 res = bond_create_slave_symlinks(bond_dev, slave_dev);
1913 res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
1916 pr_debug("Error %d calling netdev_rx_handler_register\n", res);
1917 goto err_dest_symlinks;
1920 pr_info("%s: enslaving %s as a%s interface with a%s link.\n",
1921 bond_dev->name, slave_dev->name,
1922 bond_is_active_slave(new_slave) ? "n active" : " backup",
1923 new_slave->link != BOND_LINK_DOWN ? "n up" : " down");
1925 /* enslave is successful */
1928 /* Undo stages on error */
1930 bond_destroy_slave_symlinks(bond_dev, slave_dev);
1933 dev_close(slave_dev);
1936 netdev_set_bond_master(slave_dev, NULL);
1939 if (!bond->params.fail_over_mac) {
1940 /* XXX TODO - fom follow mode needs to change master's
1941 * MAC if this slave's MAC is in use by the bond, or at
1942 * least print a warning.
1944 memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN);
1945 addr.sa_family = slave_dev->type;
1946 dev_set_mac_address(slave_dev, &addr);
1950 dev_set_mtu(slave_dev, new_slave->original_mtu);
1956 bond_compute_features(bond);
1962 * Try to release the slave device <slave> from the bond device <master>
1963 * It is legal to access curr_active_slave without a lock because all the function
1966 * The rules for slave state should be:
1967 * for Active/Backup:
1968 * Active stays on all backups go down
1969 * for Bonded connections:
1970 * The first up interface should be left on and all others downed.
1972 int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1974 struct bonding *bond = netdev_priv(bond_dev);
1975 struct slave *slave, *oldcurrent;
1976 struct sockaddr addr;
1977 u32 old_features = bond_dev->features;
1979 /* slave is not a slave or master is not master of this slave */
1980 if (!(slave_dev->flags & IFF_SLAVE) ||
1981 (slave_dev->master != bond_dev)) {
1982 pr_err("%s: Error: cannot release %s.\n",
1983 bond_dev->name, slave_dev->name);
1988 netdev_bonding_change(bond_dev, NETDEV_RELEASE);
1989 write_lock_bh(&bond->lock);
1991 slave = bond_get_slave_by_dev(bond, slave_dev);
1993 /* not a slave of this bond */
1994 pr_info("%s: %s not enslaved\n",
1995 bond_dev->name, slave_dev->name);
1996 write_unlock_bh(&bond->lock);
1997 unblock_netpoll_tx();
2001 /* unregister rx_handler early so bond_handle_frame wouldn't be called
2002 * for this slave anymore.
2004 netdev_rx_handler_unregister(slave_dev);
2005 write_unlock_bh(&bond->lock);
2007 write_lock_bh(&bond->lock);
2009 if (!bond->params.fail_over_mac) {
2010 if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) &&
2011 bond->slave_cnt > 1)
2012 pr_warning("%s: Warning: 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",
2013 bond_dev->name, slave_dev->name,
2015 bond_dev->name, slave_dev->name);
2018 /* Inform AD package of unbinding of slave. */
2019 if (bond->params.mode == BOND_MODE_8023AD) {
2020 /* must be called before the slave is
2021 * detached from the list
2023 bond_3ad_unbind_slave(slave);
2026 pr_info("%s: releasing %s interface %s\n",
2028 bond_is_active_slave(slave) ? "active" : "backup",
2031 oldcurrent = bond->curr_active_slave;
2033 bond->current_arp_slave = NULL;
2035 /* release the slave from its bond */
2036 bond_detach_slave(bond, slave);
2038 if (bond->primary_slave == slave)
2039 bond->primary_slave = NULL;
2041 if (oldcurrent == slave)
2042 bond_change_active_slave(bond, NULL);
2044 if (bond_is_lb(bond)) {
2045 /* Must be called only after the slave has been
2046 * detached from the list and the curr_active_slave
2047 * has been cleared (if our_slave == old_current),
2048 * but before a new active slave is selected.
2050 write_unlock_bh(&bond->lock);
2051 bond_alb_deinit_slave(bond, slave);
2052 write_lock_bh(&bond->lock);
2055 if (oldcurrent == slave) {
2057 * Note that we hold RTNL over this sequence, so there
2058 * is no concern that another slave add/remove event
2061 write_unlock_bh(&bond->lock);
2062 read_lock(&bond->lock);
2063 write_lock_bh(&bond->curr_slave_lock);
2065 bond_select_active_slave(bond);
2067 write_unlock_bh(&bond->curr_slave_lock);
2068 read_unlock(&bond->lock);
2069 write_lock_bh(&bond->lock);
2072 if (bond->slave_cnt == 0) {
2073 bond_set_carrier(bond);
2075 /* if the last slave was removed, zero the mac address
2076 * of the master so it will be set by the application
2077 * to the mac address of the first slave
2079 memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
2082 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
2083 bond_dev->name, bond_dev->name);
2084 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
2089 write_unlock_bh(&bond->lock);
2090 unblock_netpoll_tx();
2092 bond_compute_features(bond);
2093 if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
2094 (old_features & NETIF_F_VLAN_CHALLENGED))
2095 pr_info("%s: last VLAN challenged slave %s left bond %s. VLAN blocking is removed\n",
2096 bond_dev->name, slave_dev->name, bond_dev->name);
2098 /* must do this from outside any spinlocks */
2099 bond_destroy_slave_symlinks(bond_dev, slave_dev);
2101 bond_del_vlans_from_slave(bond, slave_dev);
2103 /* If the mode USES_PRIMARY, then we should only remove its
2104 * promisc and mc settings if it was the curr_active_slave, but that was
2105 * already taken care of above when we detached the slave
2107 if (!USES_PRIMARY(bond->params.mode)) {
2108 /* unset promiscuity level from slave */
2109 if (bond_dev->flags & IFF_PROMISC)
2110 dev_set_promiscuity(slave_dev, -1);
2112 /* unset allmulti level from slave */
2113 if (bond_dev->flags & IFF_ALLMULTI)
2114 dev_set_allmulti(slave_dev, -1);
2116 /* flush master's mc_list from slave */
2117 netif_addr_lock_bh(bond_dev);
2118 bond_mc_list_flush(bond_dev, slave_dev);
2119 netif_addr_unlock_bh(bond_dev);
2122 netdev_set_bond_master(slave_dev, NULL);
2124 slave_disable_netpoll(slave);
2126 /* close slave before restoring its mac address */
2127 dev_close(slave_dev);
2129 if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
2130 /* restore original ("permanent") mac address */
2131 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
2132 addr.sa_family = slave_dev->type;
2133 dev_set_mac_address(slave_dev, &addr);
2136 dev_set_mtu(slave_dev, slave->original_mtu);
2138 slave_dev->priv_flags &= ~IFF_BONDING;
2142 return 0; /* deletion OK */
2146 * First release a slave and then destroy the bond if no more slaves are left.
2147 * Must be under rtnl_lock when this function is called.
2149 static int bond_release_and_destroy(struct net_device *bond_dev,
2150 struct net_device *slave_dev)
2152 struct bonding *bond = netdev_priv(bond_dev);
2155 ret = bond_release(bond_dev, slave_dev);
2156 if ((ret == 0) && (bond->slave_cnt == 0)) {
2157 bond_dev->priv_flags |= IFF_DISABLE_NETPOLL;
2158 pr_info("%s: destroying bond %s.\n",
2159 bond_dev->name, bond_dev->name);
2160 unregister_netdevice(bond_dev);
2166 * This function releases all slaves.
2168 static int bond_release_all(struct net_device *bond_dev)
2170 struct bonding *bond = netdev_priv(bond_dev);
2171 struct slave *slave;
2172 struct net_device *slave_dev;
2173 struct sockaddr addr;
2175 write_lock_bh(&bond->lock);
2177 netif_carrier_off(bond_dev);
2179 if (bond->slave_cnt == 0)
2182 bond->current_arp_slave = NULL;
2183 bond->primary_slave = NULL;
2184 bond_change_active_slave(bond, NULL);
2186 while ((slave = bond->first_slave) != NULL) {
2187 /* Inform AD package of unbinding of slave
2188 * before slave is detached from the list.
2190 if (bond->params.mode == BOND_MODE_8023AD)
2191 bond_3ad_unbind_slave(slave);
2193 slave_dev = slave->dev;
2194 bond_detach_slave(bond, slave);
2196 /* now that the slave is detached, unlock and perform
2197 * all the undo steps that should not be called from
2200 write_unlock_bh(&bond->lock);
2202 /* unregister rx_handler early so bond_handle_frame wouldn't
2203 * be called for this slave anymore.
2205 netdev_rx_handler_unregister(slave_dev);
2208 if (bond_is_lb(bond)) {
2209 /* must be called only after the slave
2210 * has been detached from the list
2212 bond_alb_deinit_slave(bond, slave);
2215 bond_destroy_slave_symlinks(bond_dev, slave_dev);
2216 bond_del_vlans_from_slave(bond, slave_dev);
2218 /* If the mode USES_PRIMARY, then we should only remove its
2219 * promisc and mc settings if it was the curr_active_slave, but that was
2220 * already taken care of above when we detached the slave
2222 if (!USES_PRIMARY(bond->params.mode)) {
2223 /* unset promiscuity level from slave */
2224 if (bond_dev->flags & IFF_PROMISC)
2225 dev_set_promiscuity(slave_dev, -1);
2227 /* unset allmulti level from slave */
2228 if (bond_dev->flags & IFF_ALLMULTI)
2229 dev_set_allmulti(slave_dev, -1);
2231 /* flush master's mc_list from slave */
2232 netif_addr_lock_bh(bond_dev);
2233 bond_mc_list_flush(bond_dev, slave_dev);
2234 netif_addr_unlock_bh(bond_dev);
2237 netdev_set_bond_master(slave_dev, NULL);
2239 slave_disable_netpoll(slave);
2241 /* close slave before restoring its mac address */
2242 dev_close(slave_dev);
2244 if (!bond->params.fail_over_mac) {
2245 /* restore original ("permanent") mac address*/
2246 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
2247 addr.sa_family = slave_dev->type;
2248 dev_set_mac_address(slave_dev, &addr);
2253 /* re-acquire the lock before getting the next slave */
2254 write_lock_bh(&bond->lock);
2257 /* zero the mac address of the master so it will be
2258 * set by the application to the mac address of the
2261 memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
2264 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
2265 bond_dev->name, bond_dev->name);
2266 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
2270 pr_info("%s: released all slaves\n", bond_dev->name);
2273 write_unlock_bh(&bond->lock);
2275 bond_compute_features(bond);
2281 * This function changes the active slave to slave <slave_dev>.
2282 * It returns -EINVAL in the following cases.
2283 * - <slave_dev> is not found in the list.
2284 * - There is not active slave now.
2285 * - <slave_dev> is already active.
2286 * - The link state of <slave_dev> is not BOND_LINK_UP.
2287 * - <slave_dev> is not running.
2288 * In these cases, this function does nothing.
2289 * In the other cases, current_slave pointer is changed and 0 is returned.
2291 static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev)
2293 struct bonding *bond = netdev_priv(bond_dev);
2294 struct slave *old_active = NULL;
2295 struct slave *new_active = NULL;
2298 if (!USES_PRIMARY(bond->params.mode))
2301 /* Verify that master_dev is indeed the master of slave_dev */
2302 if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != bond_dev))
2305 read_lock(&bond->lock);
2307 read_lock(&bond->curr_slave_lock);
2308 old_active = bond->curr_active_slave;
2309 read_unlock(&bond->curr_slave_lock);
2311 new_active = bond_get_slave_by_dev(bond, slave_dev);
2314 * Changing to the current active: do nothing; return success.
2316 if (new_active && (new_active == old_active)) {
2317 read_unlock(&bond->lock);
2323 (new_active->link == BOND_LINK_UP) &&
2324 IS_UP(new_active->dev)) {
2326 write_lock_bh(&bond->curr_slave_lock);
2327 bond_change_active_slave(bond, new_active);
2328 write_unlock_bh(&bond->curr_slave_lock);
2329 unblock_netpoll_tx();
2333 read_unlock(&bond->lock);
2338 static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
2340 struct bonding *bond = netdev_priv(bond_dev);
2342 info->bond_mode = bond->params.mode;
2343 info->miimon = bond->params.miimon;
2345 read_lock(&bond->lock);
2346 info->num_slaves = bond->slave_cnt;
2347 read_unlock(&bond->lock);
2352 static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info)
2354 struct bonding *bond = netdev_priv(bond_dev);
2355 struct slave *slave;
2356 int i, res = -ENODEV;
2358 read_lock(&bond->lock);
2360 bond_for_each_slave(bond, slave, i) {
2361 if (i == (int)info->slave_id) {
2363 strcpy(info->slave_name, slave->dev->name);
2364 info->link = slave->link;
2365 info->state = bond_slave_state(slave);
2366 info->link_failure_count = slave->link_failure_count;
2371 read_unlock(&bond->lock);
2376 /*-------------------------------- Monitoring -------------------------------*/
2379 static int bond_miimon_inspect(struct bonding *bond)
2381 struct slave *slave;
2382 int i, link_state, commit = 0;
2383 bool ignore_updelay;
2385 ignore_updelay = !bond->curr_active_slave ? true : false;
2387 bond_for_each_slave(bond, slave, i) {
2388 slave->new_link = BOND_LINK_NOCHANGE;
2390 link_state = bond_check_dev_link(bond, slave->dev, 0);
2392 switch (slave->link) {
2397 slave->link = BOND_LINK_FAIL;
2398 slave->delay = bond->params.downdelay;
2400 pr_info("%s: link status down for %sinterface %s, disabling it in %d ms.\n",
2402 (bond->params.mode ==
2403 BOND_MODE_ACTIVEBACKUP) ?
2404 (bond_is_active_slave(slave) ?
2405 "active " : "backup ") : "",
2407 bond->params.downdelay * bond->params.miimon);
2410 case BOND_LINK_FAIL:
2413 * recovered before downdelay expired
2415 slave->link = BOND_LINK_UP;
2416 slave->jiffies = jiffies;
2417 pr_info("%s: link status up again after %d ms for interface %s.\n",
2419 (bond->params.downdelay - slave->delay) *
2420 bond->params.miimon,
2425 if (slave->delay <= 0) {
2426 slave->new_link = BOND_LINK_DOWN;
2434 case BOND_LINK_DOWN:
2438 slave->link = BOND_LINK_BACK;
2439 slave->delay = bond->params.updelay;
2442 pr_info("%s: link status up for interface %s, enabling it in %d ms.\n",
2443 bond->dev->name, slave->dev->name,
2444 ignore_updelay ? 0 :
2445 bond->params.updelay *
2446 bond->params.miimon);
2449 case BOND_LINK_BACK:
2451 slave->link = BOND_LINK_DOWN;
2452 pr_info("%s: link status down again after %d ms for interface %s.\n",
2454 (bond->params.updelay - slave->delay) *
2455 bond->params.miimon,
2464 if (slave->delay <= 0) {
2465 slave->new_link = BOND_LINK_UP;
2467 ignore_updelay = false;
2479 static void bond_miimon_commit(struct bonding *bond)
2481 struct slave *slave;
2484 bond_for_each_slave(bond, slave, i) {
2485 switch (slave->new_link) {
2486 case BOND_LINK_NOCHANGE:
2490 slave->link = BOND_LINK_UP;
2491 slave->jiffies = jiffies;
2493 if (bond->params.mode == BOND_MODE_8023AD) {
2494 /* prevent it from being the active one */
2495 bond_set_backup_slave(slave);
2496 } else if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
2497 /* make it immediately active */
2498 bond_set_active_slave(slave);
2499 } else if (slave != bond->primary_slave) {
2500 /* prevent it from being the active one */
2501 bond_set_backup_slave(slave);
2504 bond_update_speed_duplex(slave);
2506 pr_info("%s: link status definitely up for interface %s, %u Mbps %s duplex.\n",
2507 bond->dev->name, slave->dev->name,
2508 slave->speed, slave->duplex ? "full" : "half");
2510 /* notify ad that the link status has changed */
2511 if (bond->params.mode == BOND_MODE_8023AD)
2512 bond_3ad_handle_link_change(slave, BOND_LINK_UP);
2514 if (bond_is_lb(bond))
2515 bond_alb_handle_link_change(bond, slave,
2518 if (!bond->curr_active_slave ||
2519 (slave == bond->primary_slave))
2524 case BOND_LINK_DOWN:
2525 if (slave->link_failure_count < UINT_MAX)
2526 slave->link_failure_count++;
2528 slave->link = BOND_LINK_DOWN;
2530 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP ||
2531 bond->params.mode == BOND_MODE_8023AD)
2532 bond_set_slave_inactive_flags(slave);
2534 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2535 bond->dev->name, slave->dev->name);
2537 if (bond->params.mode == BOND_MODE_8023AD)
2538 bond_3ad_handle_link_change(slave,
2541 if (bond_is_lb(bond))
2542 bond_alb_handle_link_change(bond, slave,
2545 if (slave == bond->curr_active_slave)
2551 pr_err("%s: invalid new link %d on slave %s\n",
2552 bond->dev->name, slave->new_link,
2554 slave->new_link = BOND_LINK_NOCHANGE;
2562 write_lock_bh(&bond->curr_slave_lock);
2563 bond_select_active_slave(bond);
2564 write_unlock_bh(&bond->curr_slave_lock);
2565 unblock_netpoll_tx();
2568 bond_set_carrier(bond);
2574 * Really a wrapper that splits the mii monitor into two phases: an
2575 * inspection, then (if inspection indicates something needs to be done)
2576 * an acquisition of appropriate locks followed by a commit phase to
2577 * implement whatever link state changes are indicated.
2579 void bond_mii_monitor(struct work_struct *work)
2581 struct bonding *bond = container_of(work, struct bonding,
2583 bool should_notify_peers = false;
2585 read_lock(&bond->lock);
2586 if (bond->kill_timers)
2589 if (bond->slave_cnt == 0)
2592 should_notify_peers = bond_should_notify_peers(bond);
2594 if (bond_miimon_inspect(bond)) {
2595 read_unlock(&bond->lock);
2597 read_lock(&bond->lock);
2599 bond_miimon_commit(bond);
2601 read_unlock(&bond->lock);
2602 rtnl_unlock(); /* might sleep, hold no other locks */
2603 read_lock(&bond->lock);
2607 if (bond->params.miimon)
2608 queue_delayed_work(bond->wq, &bond->mii_work,
2609 msecs_to_jiffies(bond->params.miimon));
2611 read_unlock(&bond->lock);
2613 if (should_notify_peers) {
2615 netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS);
2620 static __be32 bond_glean_dev_ip(struct net_device *dev)
2622 struct in_device *idev;
2623 struct in_ifaddr *ifa;
2630 idev = __in_dev_get_rcu(dev);
2634 ifa = idev->ifa_list;
2638 addr = ifa->ifa_local;
2644 static int bond_has_this_ip(struct bonding *bond, __be32 ip)
2646 struct vlan_entry *vlan;
2648 if (ip == bond->master_ip)
2651 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2652 if (ip == vlan->vlan_ip)
2660 * We go to the (large) trouble of VLAN tagging ARP frames because
2661 * switches in VLAN mode (especially if ports are configured as
2662 * "native" to a VLAN) might not pass non-tagged frames.
2664 static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_ip, __be32 src_ip, unsigned short vlan_id)
2666 struct sk_buff *skb;
2668 pr_debug("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
2669 slave_dev->name, dest_ip, src_ip, vlan_id);
2671 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
2672 NULL, slave_dev->dev_addr, NULL);
2675 pr_err("ARP packet allocation failed\n");
2679 skb = vlan_put_tag(skb, vlan_id);
2681 pr_err("failed to insert VLAN tag\n");
2689 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2692 __be32 *targets = bond->params.arp_targets;
2693 struct vlan_entry *vlan;
2694 struct net_device *vlan_dev;
2697 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
2700 pr_debug("basa: target %x\n", targets[i]);
2702 pr_debug("basa: empty vlan: arp_send\n");
2703 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2704 bond->master_ip, 0);
2709 * If VLANs are configured, we do a route lookup to
2710 * determine which VLAN interface would be used, so we
2711 * can tag the ARP with the proper VLAN tag.
2713 rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
2716 if (net_ratelimit()) {
2717 pr_warning("%s: no route to arp_ip_target %pI4\n",
2718 bond->dev->name, &targets[i]);
2724 * This target is not on a VLAN
2726 if (rt->dst.dev == bond->dev) {
2728 pr_debug("basa: rtdev == bond->dev: arp_send\n");
2729 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2730 bond->master_ip, 0);
2735 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2736 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
2737 if (vlan_dev == rt->dst.dev) {
2738 vlan_id = vlan->vlan_id;
2739 pr_debug("basa: vlan match on %s %d\n",
2740 vlan_dev->name, vlan_id);
2747 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2748 vlan->vlan_ip, vlan_id);
2752 if (net_ratelimit()) {
2753 pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
2754 bond->dev->name, &targets[i],
2755 rt->dst.dev ? rt->dst.dev->name : "NULL");
2761 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
2764 __be32 *targets = bond->params.arp_targets;
2766 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
2767 pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n",
2768 &sip, &tip, i, &targets[i],
2769 bond_has_this_ip(bond, tip));
2770 if (sip == targets[i]) {
2771 if (bond_has_this_ip(bond, tip))
2772 slave->last_arp_rx = jiffies;
2778 static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond,
2779 struct slave *slave)
2782 unsigned char *arp_ptr;
2785 if (skb->protocol != __cpu_to_be16(ETH_P_ARP))
2788 read_lock(&bond->lock);
2790 pr_debug("bond_arp_rcv: bond %s skb->dev %s\n",
2791 bond->dev->name, skb->dev->name);
2793 if (!pskb_may_pull(skb, arp_hdr_len(bond->dev)))
2797 if (arp->ar_hln != bond->dev->addr_len ||
2798 skb->pkt_type == PACKET_OTHERHOST ||
2799 skb->pkt_type == PACKET_LOOPBACK ||
2800 arp->ar_hrd != htons(ARPHRD_ETHER) ||
2801 arp->ar_pro != htons(ETH_P_IP) ||
2805 arp_ptr = (unsigned char *)(arp + 1);
2806 arp_ptr += bond->dev->addr_len;
2807 memcpy(&sip, arp_ptr, 4);
2808 arp_ptr += 4 + bond->dev->addr_len;
2809 memcpy(&tip, arp_ptr, 4);
2811 pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2812 bond->dev->name, slave->dev->name, bond_slave_state(slave),
2813 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2817 * Backup slaves won't see the ARP reply, but do come through
2818 * here for each ARP probe (so we swap the sip/tip to validate
2819 * the probe). In a "redundant switch, common router" type of
2820 * configuration, the ARP probe will (hopefully) travel from
2821 * the active, through one switch, the router, then the other
2822 * switch before reaching the backup.
2824 if (bond_is_active_slave(slave))
2825 bond_validate_arp(bond, slave, sip, tip);
2827 bond_validate_arp(bond, slave, tip, sip);
2830 read_unlock(&bond->lock);
2834 * this function is called regularly to monitor each slave's link
2835 * ensuring that traffic is being sent and received when arp monitoring
2836 * is used in load-balancing mode. if the adapter has been dormant, then an
2837 * arp is transmitted to generate traffic. see activebackup_arp_monitor for
2838 * arp monitoring in active backup mode.
2840 void bond_loadbalance_arp_mon(struct work_struct *work)
2842 struct bonding *bond = container_of(work, struct bonding,
2844 struct slave *slave, *oldcurrent;
2845 int do_failover = 0;
2849 read_lock(&bond->lock);
2851 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
2853 if (bond->kill_timers)
2856 if (bond->slave_cnt == 0)
2859 read_lock(&bond->curr_slave_lock);
2860 oldcurrent = bond->curr_active_slave;
2861 read_unlock(&bond->curr_slave_lock);
2863 /* see if any of the previous devices are up now (i.e. they have
2864 * xmt and rcv traffic). the curr_active_slave does not come into
2865 * the picture unless it is null. also, slave->jiffies is not needed
2866 * here because we send an arp on each slave and give a slave as
2867 * long as it needs to get the tx/rx within the delta.
2868 * TODO: what about up/down delay in arp mode? it wasn't here before
2871 bond_for_each_slave(bond, slave, i) {
2872 unsigned long trans_start = dev_trans_start(slave->dev);
2874 if (slave->link != BOND_LINK_UP) {
2875 if (time_in_range(jiffies,
2876 trans_start - delta_in_ticks,
2877 trans_start + delta_in_ticks) &&
2878 time_in_range(jiffies,
2879 slave->dev->last_rx - delta_in_ticks,
2880 slave->dev->last_rx + delta_in_ticks)) {
2882 slave->link = BOND_LINK_UP;
2883 bond_set_active_slave(slave);
2885 /* primary_slave has no meaning in round-robin
2886 * mode. the window of a slave being up and
2887 * curr_active_slave being null after enslaving
2891 pr_info("%s: link status definitely up for interface %s, ",
2896 pr_info("%s: interface %s is now up\n",
2902 /* slave->link == BOND_LINK_UP */
2904 /* not all switches will respond to an arp request
2905 * when the source ip is 0, so don't take the link down
2906 * if we don't know our ip yet
2908 if (!time_in_range(jiffies,
2909 trans_start - delta_in_ticks,
2910 trans_start + 2 * delta_in_ticks) ||
2911 !time_in_range(jiffies,
2912 slave->dev->last_rx - delta_in_ticks,
2913 slave->dev->last_rx + 2 * delta_in_ticks)) {
2915 slave->link = BOND_LINK_DOWN;
2916 bond_set_backup_slave(slave);
2918 if (slave->link_failure_count < UINT_MAX)
2919 slave->link_failure_count++;
2921 pr_info("%s: interface %s is now down.\n",
2925 if (slave == oldcurrent)
2930 /* note: if switch is in round-robin mode, all links
2931 * must tx arp to ensure all links rx an arp - otherwise
2932 * links may oscillate or not come up at all; if switch is
2933 * in something like xor mode, there is nothing we can
2934 * do - all replies will be rx'ed on same link causing slaves
2935 * to be unstable during low/no traffic periods
2937 if (IS_UP(slave->dev))
2938 bond_arp_send_all(bond, slave);
2943 write_lock_bh(&bond->curr_slave_lock);
2945 bond_select_active_slave(bond);
2947 write_unlock_bh(&bond->curr_slave_lock);
2948 unblock_netpoll_tx();
2952 if (bond->params.arp_interval)
2953 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
2955 read_unlock(&bond->lock);
2959 * Called to inspect slaves for active-backup mode ARP monitor link state
2960 * changes. Sets new_link in slaves to specify what action should take
2961 * place for the slave. Returns 0 if no changes are found, >0 if changes
2962 * to link states must be committed.
2964 * Called with bond->lock held for read.
2966 static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks)
2968 struct slave *slave;
2970 unsigned long trans_start;
2972 bond_for_each_slave(bond, slave, i) {
2973 slave->new_link = BOND_LINK_NOCHANGE;
2975 if (slave->link != BOND_LINK_UP) {
2976 if (time_in_range(jiffies,
2977 slave_last_rx(bond, slave) - delta_in_ticks,
2978 slave_last_rx(bond, slave) + delta_in_ticks)) {
2980 slave->new_link = BOND_LINK_UP;
2988 * Give slaves 2*delta after being enslaved or made
2989 * active. This avoids bouncing, as the last receive
2990 * times need a full ARP monitor cycle to be updated.
2992 if (time_in_range(jiffies,
2993 slave->jiffies - delta_in_ticks,
2994 slave->jiffies + 2 * delta_in_ticks))
2998 * Backup slave is down if:
2999 * - No current_arp_slave AND
3000 * - more than 3*delta since last receive AND
3001 * - the bond has an IP address
3003 * Note: a non-null current_arp_slave indicates
3004 * the curr_active_slave went down and we are
3005 * searching for a new one; under this condition
3006 * we only take the curr_active_slave down - this
3007 * gives each slave a chance to tx/rx traffic
3008 * before being taken out
3010 if (!bond_is_active_slave(slave) &&
3011 !bond->current_arp_slave &&
3012 !time_in_range(jiffies,
3013 slave_last_rx(bond, slave) - delta_in_ticks,
3014 slave_last_rx(bond, slave) + 3 * delta_in_ticks)) {
3016 slave->new_link = BOND_LINK_DOWN;
3021 * Active slave is down if:
3022 * - more than 2*delta since transmitting OR
3023 * - (more than 2*delta since receive AND
3024 * the bond has an IP address)
3026 trans_start = dev_trans_start(slave->dev);
3027 if (bond_is_active_slave(slave) &&
3028 (!time_in_range(jiffies,
3029 trans_start - delta_in_ticks,
3030 trans_start + 2 * delta_in_ticks) ||
3031 !time_in_range(jiffies,
3032 slave_last_rx(bond, slave) - delta_in_ticks,
3033 slave_last_rx(bond, slave) + 2 * delta_in_ticks))) {
3035 slave->new_link = BOND_LINK_DOWN;
3044 * Called to commit link state changes noted by inspection step of
3045 * active-backup mode ARP monitor.
3047 * Called with RTNL and bond->lock for read.
3049 static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
3051 struct slave *slave;
3053 unsigned long trans_start;
3055 bond_for_each_slave(bond, slave, i) {
3056 switch (slave->new_link) {
3057 case BOND_LINK_NOCHANGE:
3061 trans_start = dev_trans_start(slave->dev);
3062 if ((!bond->curr_active_slave &&
3063 time_in_range(jiffies,
3064 trans_start - delta_in_ticks,
3065 trans_start + delta_in_ticks)) ||
3066 bond->curr_active_slave != slave) {
3067 slave->link = BOND_LINK_UP;
3068 bond->current_arp_slave = NULL;
3070 pr_info("%s: link status definitely up for interface %s.\n",
3071 bond->dev->name, slave->dev->name);
3073 if (!bond->curr_active_slave ||
3074 (slave == bond->primary_slave))
3081 case BOND_LINK_DOWN:
3082 if (slave->link_failure_count < UINT_MAX)
3083 slave->link_failure_count++;
3085 slave->link = BOND_LINK_DOWN;
3086 bond_set_slave_inactive_flags(slave);
3088 pr_info("%s: link status definitely down for interface %s, disabling it\n",
3089 bond->dev->name, slave->dev->name);
3091 if (slave == bond->curr_active_slave) {
3092 bond->current_arp_slave = NULL;
3099 pr_err("%s: impossible: new_link %d on slave %s\n",
3100 bond->dev->name, slave->new_link,
3108 write_lock_bh(&bond->curr_slave_lock);
3109 bond_select_active_slave(bond);
3110 write_unlock_bh(&bond->curr_slave_lock);
3111 unblock_netpoll_tx();
3114 bond_set_carrier(bond);
3118 * Send ARP probes for active-backup mode ARP monitor.
3120 * Called with bond->lock held for read.
3122 static void bond_ab_arp_probe(struct bonding *bond)
3124 struct slave *slave;
3127 read_lock(&bond->curr_slave_lock);
3129 if (bond->current_arp_slave && bond->curr_active_slave)
3130 pr_info("PROBE: c_arp %s && cas %s BAD\n",
3131 bond->current_arp_slave->dev->name,
3132 bond->curr_active_slave->dev->name);
3134 if (bond->curr_active_slave) {
3135 bond_arp_send_all(bond, bond->curr_active_slave);
3136 read_unlock(&bond->curr_slave_lock);
3140 read_unlock(&bond->curr_slave_lock);
3142 /* if we don't have a curr_active_slave, search for the next available
3143 * backup slave from the current_arp_slave and make it the candidate
3144 * for becoming the curr_active_slave
3147 if (!bond->current_arp_slave) {
3148 bond->current_arp_slave = bond->first_slave;
3149 if (!bond->current_arp_slave)
3153 bond_set_slave_inactive_flags(bond->current_arp_slave);
3155 /* search for next candidate */
3156 bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave->next) {
3157 if (IS_UP(slave->dev)) {
3158 slave->link = BOND_LINK_BACK;
3159 bond_set_slave_active_flags(slave);
3160 bond_arp_send_all(bond, slave);
3161 slave->jiffies = jiffies;
3162 bond->current_arp_slave = slave;
3166 /* if the link state is up at this point, we
3167 * mark it down - this can happen if we have
3168 * simultaneous link failures and
3169 * reselect_active_interface doesn't make this
3170 * one the current slave so it is still marked
3171 * up when it is actually down
3173 if (slave->link == BOND_LINK_UP) {
3174 slave->link = BOND_LINK_DOWN;
3175 if (slave->link_failure_count < UINT_MAX)
3176 slave->link_failure_count++;
3178 bond_set_slave_inactive_flags(slave);
3180 pr_info("%s: backup interface %s is now down.\n",
3181 bond->dev->name, slave->dev->name);
3186 void bond_activebackup_arp_mon(struct work_struct *work)
3188 struct bonding *bond = container_of(work, struct bonding,
3190 bool should_notify_peers = false;
3193 read_lock(&bond->lock);
3195 if (bond->kill_timers)
3198 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
3200 if (bond->slave_cnt == 0)
3203 should_notify_peers = bond_should_notify_peers(bond);
3205 if (bond_ab_arp_inspect(bond, delta_in_ticks)) {
3206 read_unlock(&bond->lock);
3208 read_lock(&bond->lock);
3210 bond_ab_arp_commit(bond, delta_in_ticks);
3212 read_unlock(&bond->lock);
3214 read_lock(&bond->lock);
3217 bond_ab_arp_probe(bond);
3220 if (bond->params.arp_interval)
3221 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
3223 read_unlock(&bond->lock);
3225 if (should_notify_peers) {
3227 netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS);
3232 /*-------------------------- netdev event handling --------------------------*/
3235 * Change device name
3237 static int bond_event_changename(struct bonding *bond)
3239 bond_remove_proc_entry(bond);
3240 bond_create_proc_entry(bond);
3242 bond_debug_reregister(bond);
3247 static int bond_master_netdev_event(unsigned long event,
3248 struct net_device *bond_dev)
3250 struct bonding *event_bond = netdev_priv(bond_dev);
3253 case NETDEV_CHANGENAME:
3254 return bond_event_changename(event_bond);
3262 static int bond_slave_netdev_event(unsigned long event,
3263 struct net_device *slave_dev)
3265 struct net_device *bond_dev = slave_dev->master;
3266 struct bonding *bond = netdev_priv(bond_dev);
3269 case NETDEV_UNREGISTER:
3271 if (bond->setup_by_slave)
3272 bond_release_and_destroy(bond_dev, slave_dev);
3274 bond_release(bond_dev, slave_dev);
3278 if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) {
3279 struct slave *slave;
3281 slave = bond_get_slave_by_dev(bond, slave_dev);
3283 u32 old_speed = slave->speed;
3284 u8 old_duplex = slave->duplex;
3286 bond_update_speed_duplex(slave);
3288 if (bond_is_lb(bond))
3291 if (old_speed != slave->speed)
3292 bond_3ad_adapter_speed_changed(slave);
3293 if (old_duplex != slave->duplex)
3294 bond_3ad_adapter_duplex_changed(slave);
3301 * ... Or is it this?
3304 case NETDEV_CHANGEMTU:
3306 * TODO: Should slaves be allowed to
3307 * independently alter their MTU? For
3308 * an active-backup bond, slaves need
3309 * not be the same type of device, so
3310 * MTUs may vary. For other modes,
3311 * slaves arguably should have the
3312 * same MTUs. To do this, we'd need to
3313 * take over the slave's change_mtu
3314 * function for the duration of their
3318 case NETDEV_CHANGENAME:
3320 * TODO: handle changing the primary's name
3323 case NETDEV_FEAT_CHANGE:
3324 bond_compute_features(bond);
3334 * bond_netdev_event: handle netdev notifier chain events.
3336 * This function receives events for the netdev chain. The caller (an
3337 * ioctl handler calling blocking_notifier_call_chain) holds the necessary
3338 * locks for us to safely manipulate the slave devices (RTNL lock,
3341 static int bond_netdev_event(struct notifier_block *this,
3342 unsigned long event, void *ptr)
3344 struct net_device *event_dev = (struct net_device *)ptr;
3346 pr_debug("event_dev: %s, event: %lx\n",
3347 event_dev ? event_dev->name : "None",
3350 if (!(event_dev->priv_flags & IFF_BONDING))
3353 if (event_dev->flags & IFF_MASTER) {
3354 pr_debug("IFF_MASTER\n");
3355 return bond_master_netdev_event(event, event_dev);
3358 if (event_dev->flags & IFF_SLAVE) {
3359 pr_debug("IFF_SLAVE\n");
3360 return bond_slave_netdev_event(event, event_dev);
3367 * bond_inetaddr_event: handle inetaddr notifier chain events.
3369 * We keep track of device IPs primarily to use as source addresses in
3370 * ARP monitor probes (rather than spewing out broadcasts all the time).
3372 * We track one IP for the main device (if it has one), plus one per VLAN.
3374 static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
3376 struct in_ifaddr *ifa = ptr;
3377 struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
3378 struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id);
3379 struct bonding *bond;
3380 struct vlan_entry *vlan;
3382 list_for_each_entry(bond, &bn->dev_list, bond_list) {
3383 if (bond->dev == event_dev) {
3386 bond->master_ip = ifa->ifa_local;
3389 bond->master_ip = bond_glean_dev_ip(bond->dev);
3396 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
3399 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
3400 if (vlan_dev == event_dev) {
3403 vlan->vlan_ip = ifa->ifa_local;
3407 bond_glean_dev_ip(vlan_dev);
3418 static struct notifier_block bond_netdev_notifier = {
3419 .notifier_call = bond_netdev_event,
3422 static struct notifier_block bond_inetaddr_notifier = {
3423 .notifier_call = bond_inetaddr_event,
3426 /*---------------------------- Hashing Policies -----------------------------*/
3429 * Hash for the output device based upon layer 2 and layer 3 data. If
3430 * the packet is not IP mimic bond_xmit_hash_policy_l2()
3432 static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count)
3434 struct ethhdr *data = (struct ethhdr *)skb->data;
3435 struct iphdr *iph = ip_hdr(skb);
3437 if (skb->protocol == htons(ETH_P_IP)) {
3438 return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
3439 (data->h_dest[5] ^ data->h_source[5])) % count;
3442 return (data->h_dest[5] ^ data->h_source[5]) % count;
3446 * Hash for the output device based upon layer 3 and layer 4 data. If
3447 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3448 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3450 static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count)
3452 struct ethhdr *data = (struct ethhdr *)skb->data;
3453 struct iphdr *iph = ip_hdr(skb);
3454 __be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl);
3457 if (skb->protocol == htons(ETH_P_IP)) {
3458 if (!(iph->frag_off & htons(IP_MF|IP_OFFSET)) &&
3459 (iph->protocol == IPPROTO_TCP ||
3460 iph->protocol == IPPROTO_UDP)) {
3461 layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
3463 return (layer4_xor ^
3464 ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
3468 return (data->h_dest[5] ^ data->h_source[5]) % count;
3472 * Hash for the output device based upon layer 2 data
3474 static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count)
3476 struct ethhdr *data = (struct ethhdr *)skb->data;
3478 return (data->h_dest[5] ^ data->h_source[5]) % count;
3481 /*-------------------------- Device entry points ----------------------------*/
3483 static int bond_open(struct net_device *bond_dev)
3485 struct bonding *bond = netdev_priv(bond_dev);
3487 bond->kill_timers = 0;
3489 INIT_DELAYED_WORK(&bond->mcast_work, bond_resend_igmp_join_requests_delayed);
3491 if (bond_is_lb(bond)) {
3492 /* bond_alb_initialize must be called before the timer
3495 if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) {
3496 /* something went wrong - fail the open operation */
3500 INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
3501 queue_delayed_work(bond->wq, &bond->alb_work, 0);
3504 if (bond->params.miimon) { /* link check interval, in milliseconds. */
3505 INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
3506 queue_delayed_work(bond->wq, &bond->mii_work, 0);
3509 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
3510 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
3511 INIT_DELAYED_WORK(&bond->arp_work,
3512 bond_activebackup_arp_mon);
3514 INIT_DELAYED_WORK(&bond->arp_work,
3515 bond_loadbalance_arp_mon);
3517 queue_delayed_work(bond->wq, &bond->arp_work, 0);
3518 if (bond->params.arp_validate)
3519 bond->recv_probe = bond_arp_rcv;
3522 if (bond->params.mode == BOND_MODE_8023AD) {
3523 INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
3524 queue_delayed_work(bond->wq, &bond->ad_work, 0);
3525 /* register to receive LACPDUs */
3526 bond->recv_probe = bond_3ad_lacpdu_recv;
3527 bond_3ad_initiate_agg_selection(bond, 1);
3533 static int bond_close(struct net_device *bond_dev)
3535 struct bonding *bond = netdev_priv(bond_dev);
3537 write_lock_bh(&bond->lock);
3539 bond->send_peer_notif = 0;
3541 /* signal timers not to re-arm */
3542 bond->kill_timers = 1;
3544 write_unlock_bh(&bond->lock);
3546 if (bond->params.miimon) { /* link check interval, in milliseconds. */
3547 cancel_delayed_work(&bond->mii_work);
3550 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
3551 cancel_delayed_work(&bond->arp_work);
3554 switch (bond->params.mode) {
3555 case BOND_MODE_8023AD:
3556 cancel_delayed_work(&bond->ad_work);
3560 cancel_delayed_work(&bond->alb_work);
3566 if (delayed_work_pending(&bond->mcast_work))
3567 cancel_delayed_work(&bond->mcast_work);
3569 if (bond_is_lb(bond)) {
3570 /* Must be called only after all
3571 * slaves have been released
3573 bond_alb_deinitialize(bond);
3575 bond->recv_probe = NULL;
3580 static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
3581 struct rtnl_link_stats64 *stats)
3583 struct bonding *bond = netdev_priv(bond_dev);
3584 struct rtnl_link_stats64 temp;
3585 struct slave *slave;
3588 memset(stats, 0, sizeof(*stats));
3590 read_lock_bh(&bond->lock);
3592 bond_for_each_slave(bond, slave, i) {
3593 const struct rtnl_link_stats64 *sstats =
3594 dev_get_stats(slave->dev, &temp);
3596 stats->rx_packets += sstats->rx_packets;
3597 stats->rx_bytes += sstats->rx_bytes;
3598 stats->rx_errors += sstats->rx_errors;
3599 stats->rx_dropped += sstats->rx_dropped;
3601 stats->tx_packets += sstats->tx_packets;
3602 stats->tx_bytes += sstats->tx_bytes;
3603 stats->tx_errors += sstats->tx_errors;
3604 stats->tx_dropped += sstats->tx_dropped;
3606 stats->multicast += sstats->multicast;
3607 stats->collisions += sstats->collisions;
3609 stats->rx_length_errors += sstats->rx_length_errors;
3610 stats->rx_over_errors += sstats->rx_over_errors;
3611 stats->rx_crc_errors += sstats->rx_crc_errors;
3612 stats->rx_frame_errors += sstats->rx_frame_errors;
3613 stats->rx_fifo_errors += sstats->rx_fifo_errors;
3614 stats->rx_missed_errors += sstats->rx_missed_errors;
3616 stats->tx_aborted_errors += sstats->tx_aborted_errors;
3617 stats->tx_carrier_errors += sstats->tx_carrier_errors;
3618 stats->tx_fifo_errors += sstats->tx_fifo_errors;
3619 stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
3620 stats->tx_window_errors += sstats->tx_window_errors;
3623 read_unlock_bh(&bond->lock);
3628 static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
3630 struct net_device *slave_dev = NULL;
3631 struct ifbond k_binfo;
3632 struct ifbond __user *u_binfo = NULL;
3633 struct ifslave k_sinfo;
3634 struct ifslave __user *u_sinfo = NULL;
3635 struct mii_ioctl_data *mii = NULL;
3638 pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd);
3650 * We do this again just in case we were called by SIOCGMIIREG
3651 * instead of SIOCGMIIPHY.
3658 if (mii->reg_num == 1) {
3659 struct bonding *bond = netdev_priv(bond_dev);
3661 read_lock(&bond->lock);
3662 read_lock(&bond->curr_slave_lock);
3663 if (netif_carrier_ok(bond->dev))
3664 mii->val_out = BMSR_LSTATUS;
3666 read_unlock(&bond->curr_slave_lock);
3667 read_unlock(&bond->lock);
3671 case BOND_INFO_QUERY_OLD:
3672 case SIOCBONDINFOQUERY:
3673 u_binfo = (struct ifbond __user *)ifr->ifr_data;
3675 if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond)))
3678 res = bond_info_query(bond_dev, &k_binfo);
3680 copy_to_user(u_binfo, &k_binfo, sizeof(ifbond)))
3684 case BOND_SLAVE_INFO_QUERY_OLD:
3685 case SIOCBONDSLAVEINFOQUERY:
3686 u_sinfo = (struct ifslave __user *)ifr->ifr_data;
3688 if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave)))
3691 res = bond_slave_info_query(bond_dev, &k_sinfo);
3693 copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave)))
3702 if (!capable(CAP_NET_ADMIN))
3705 slave_dev = dev_get_by_name(dev_net(bond_dev), ifr->ifr_slave);
3707 pr_debug("slave_dev=%p:\n", slave_dev);
3712 pr_debug("slave_dev->name=%s:\n", slave_dev->name);
3714 case BOND_ENSLAVE_OLD:
3715 case SIOCBONDENSLAVE:
3716 res = bond_enslave(bond_dev, slave_dev);
3718 case BOND_RELEASE_OLD:
3719 case SIOCBONDRELEASE:
3720 res = bond_release(bond_dev, slave_dev);
3722 case BOND_SETHWADDR_OLD:
3723 case SIOCBONDSETHWADDR:
3724 res = bond_sethwaddr(bond_dev, slave_dev);
3726 case BOND_CHANGE_ACTIVE_OLD:
3727 case SIOCBONDCHANGEACTIVE:
3728 res = bond_ioctl_change_active(bond_dev, slave_dev);
3740 static bool bond_addr_in_mc_list(unsigned char *addr,
3741 struct netdev_hw_addr_list *list,
3744 struct netdev_hw_addr *ha;
3746 netdev_hw_addr_list_for_each(ha, list)
3747 if (!memcmp(ha->addr, addr, addrlen))
3753 static void bond_set_multicast_list(struct net_device *bond_dev)
3755 struct bonding *bond = netdev_priv(bond_dev);
3756 struct netdev_hw_addr *ha;
3760 * Do promisc before checking multicast_mode
3762 if ((bond_dev->flags & IFF_PROMISC) && !(bond->flags & IFF_PROMISC))
3764 * FIXME: Need to handle the error when one of the multi-slaves
3767 bond_set_promiscuity(bond, 1);
3770 if (!(bond_dev->flags & IFF_PROMISC) && (bond->flags & IFF_PROMISC))
3771 bond_set_promiscuity(bond, -1);
3774 /* set allmulti flag to slaves */
3775 if ((bond_dev->flags & IFF_ALLMULTI) && !(bond->flags & IFF_ALLMULTI))
3777 * FIXME: Need to handle the error when one of the multi-slaves
3780 bond_set_allmulti(bond, 1);
3783 if (!(bond_dev->flags & IFF_ALLMULTI) && (bond->flags & IFF_ALLMULTI))
3784 bond_set_allmulti(bond, -1);
3787 read_lock(&bond->lock);
3789 bond->flags = bond_dev->flags;
3791 /* looking for addresses to add to slaves' mc list */
3792 netdev_for_each_mc_addr(ha, bond_dev) {
3793 found = bond_addr_in_mc_list(ha->addr, &bond->mc_list,
3794 bond_dev->addr_len);
3796 bond_mc_add(bond, ha->addr);
3799 /* looking for addresses to delete from slaves' list */
3800 netdev_hw_addr_list_for_each(ha, &bond->mc_list) {
3801 found = bond_addr_in_mc_list(ha->addr, &bond_dev->mc,
3802 bond_dev->addr_len);
3804 bond_mc_del(bond, ha->addr);
3807 /* save master's multicast list */
3808 __hw_addr_flush(&bond->mc_list);
3809 __hw_addr_add_multiple(&bond->mc_list, &bond_dev->mc,
3810 bond_dev->addr_len, NETDEV_HW_ADDR_T_MULTICAST);
3812 read_unlock(&bond->lock);
3815 static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms)
3817 struct bonding *bond = netdev_priv(dev);
3818 struct slave *slave = bond->first_slave;
3821 const struct net_device_ops *slave_ops
3822 = slave->dev->netdev_ops;
3823 if (slave_ops->ndo_neigh_setup)
3824 return slave_ops->ndo_neigh_setup(slave->dev, parms);
3830 * Change the MTU of all of a master's slaves to match the master
3832 static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
3834 struct bonding *bond = netdev_priv(bond_dev);
3835 struct slave *slave, *stop_at;
3839 pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond,
3840 (bond_dev ? bond_dev->name : "None"), new_mtu);
3842 /* Can't hold bond->lock with bh disabled here since
3843 * some base drivers panic. On the other hand we can't
3844 * hold bond->lock without bh disabled because we'll
3845 * deadlock. The only solution is to rely on the fact
3846 * that we're under rtnl_lock here, and the slaves
3847 * list won't change. This doesn't solve the problem
3848 * of setting the slave's MTU while it is
3849 * transmitting, but the assumption is that the base
3850 * driver can handle that.
3852 * TODO: figure out a way to safely iterate the slaves
3853 * list, but without holding a lock around the actual
3854 * call to the base driver.
3857 bond_for_each_slave(bond, slave, i) {
3858 pr_debug("s %p s->p %p c_m %p\n",
3861 slave->dev->netdev_ops->ndo_change_mtu);
3863 res = dev_set_mtu(slave->dev, new_mtu);
3866 /* If we failed to set the slave's mtu to the new value
3867 * we must abort the operation even in ACTIVE_BACKUP
3868 * mode, because if we allow the backup slaves to have
3869 * different mtu values than the active slave we'll
3870 * need to change their mtu when doing a failover. That
3871 * means changing their mtu from timer context, which
3872 * is probably not a good idea.
3874 pr_debug("err %d %s\n", res, slave->dev->name);
3879 bond_dev->mtu = new_mtu;
3884 /* unwind from head to the slave that failed */
3886 bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
3889 tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu);
3891 pr_debug("unwind err %d dev %s\n",
3892 tmp_res, slave->dev->name);
3902 * Note that many devices must be down to change the HW address, and
3903 * downing the master releases all slaves. We can make bonds full of
3904 * bonding devices to test this, however.
3906 static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
3908 struct bonding *bond = netdev_priv(bond_dev);
3909 struct sockaddr *sa = addr, tmp_sa;
3910 struct slave *slave, *stop_at;
3914 if (bond->params.mode == BOND_MODE_ALB)
3915 return bond_alb_set_mac_address(bond_dev, addr);
3918 pr_debug("bond=%p, name=%s\n",
3919 bond, bond_dev ? bond_dev->name : "None");
3922 * If fail_over_mac is set to active, do nothing and return
3923 * success. Returning an error causes ifenslave to fail.
3925 if (bond->params.fail_over_mac == BOND_FOM_ACTIVE)
3928 if (!is_valid_ether_addr(sa->sa_data))
3929 return -EADDRNOTAVAIL;
3931 /* Can't hold bond->lock with bh disabled here since
3932 * some base drivers panic. On the other hand we can't
3933 * hold bond->lock without bh disabled because we'll
3934 * deadlock. The only solution is to rely on the fact
3935 * that we're under rtnl_lock here, and the slaves
3936 * list won't change. This doesn't solve the problem
3937 * of setting the slave's hw address while it is
3938 * transmitting, but the assumption is that the base
3939 * driver can handle that.
3941 * TODO: figure out a way to safely iterate the slaves
3942 * list, but without holding a lock around the actual
3943 * call to the base driver.
3946 bond_for_each_slave(bond, slave, i) {
3947 const struct net_device_ops *slave_ops = slave->dev->netdev_ops;
3948 pr_debug("slave %p %s\n", slave, slave->dev->name);
3950 if (slave_ops->ndo_set_mac_address == NULL) {
3952 pr_debug("EOPNOTSUPP %s\n", slave->dev->name);
3956 res = dev_set_mac_address(slave->dev, addr);
3958 /* TODO: consider downing the slave
3960 * User should expect communications
3961 * breakage anyway until ARP finish
3964 pr_debug("err %d %s\n", res, slave->dev->name);
3970 memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len);
3974 memcpy(tmp_sa.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
3975 tmp_sa.sa_family = bond_dev->type;
3977 /* unwind from head to the slave that failed */
3979 bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
3982 tmp_res = dev_set_mac_address(slave->dev, &tmp_sa);
3984 pr_debug("unwind err %d dev %s\n",
3985 tmp_res, slave->dev->name);
3992 static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev)
3994 struct bonding *bond = netdev_priv(bond_dev);
3995 struct slave *slave, *start_at;
3996 int i, slave_no, res = 1;
3997 struct iphdr *iph = ip_hdr(skb);
4000 * Start with the curr_active_slave that joined the bond as the
4001 * default for sending IGMP traffic. For failover purposes one
4002 * needs to maintain some consistency for the interface that will
4003 * send the join/membership reports. The curr_active_slave found
4004 * will send all of this type of traffic.
4006 if ((iph->protocol == IPPROTO_IGMP) &&
4007 (skb->protocol == htons(ETH_P_IP))) {
4009 read_lock(&bond->curr_slave_lock);
4010 slave = bond->curr_active_slave;
4011 read_unlock(&bond->curr_slave_lock);
4017 * Concurrent TX may collide on rr_tx_counter; we accept
4018 * that as being rare enough not to justify using an
4021 slave_no = bond->rr_tx_counter++ % bond->slave_cnt;
4023 bond_for_each_slave(bond, slave, i) {
4031 bond_for_each_slave_from(bond, slave, i, start_at) {
4032 if (IS_UP(slave->dev) &&
4033 (slave->link == BOND_LINK_UP) &&
4034 bond_is_active_slave(slave)) {
4035 res = bond_dev_queue_xmit(bond, skb, slave->dev);
4042 /* no suitable interface, frame not sent */
4046 return NETDEV_TX_OK;
4051 * in active-backup mode, we know that bond->curr_active_slave is always valid if
4052 * the bond has a usable interface.
4054 static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_dev)
4056 struct bonding *bond = netdev_priv(bond_dev);
4059 read_lock(&bond->curr_slave_lock);
4061 if (bond->curr_active_slave)
4062 res = bond_dev_queue_xmit(bond, skb,
4063 bond->curr_active_slave->dev);
4066 /* no suitable interface, frame not sent */
4069 read_unlock(&bond->curr_slave_lock);
4071 return NETDEV_TX_OK;
4075 * In bond_xmit_xor() , we determine the output device by using a pre-
4076 * determined xmit_hash_policy(), If the selected device is not enabled,
4077 * find the next active slave.
4079 static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4081 struct bonding *bond = netdev_priv(bond_dev);
4082 struct slave *slave, *start_at;
4087 slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt);
4089 bond_for_each_slave(bond, slave, i) {
4097 bond_for_each_slave_from(bond, slave, i, start_at) {
4098 if (IS_UP(slave->dev) &&
4099 (slave->link == BOND_LINK_UP) &&
4100 bond_is_active_slave(slave)) {
4101 res = bond_dev_queue_xmit(bond, skb, slave->dev);
4107 /* no suitable interface, frame not sent */
4111 return NETDEV_TX_OK;
4115 * in broadcast mode, we send everything to all usable interfaces.
4117 static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
4119 struct bonding *bond = netdev_priv(bond_dev);
4120 struct slave *slave, *start_at;
4121 struct net_device *tx_dev = NULL;
4125 read_lock(&bond->curr_slave_lock);
4126 start_at = bond->curr_active_slave;
4127 read_unlock(&bond->curr_slave_lock);
4132 bond_for_each_slave_from(bond, slave, i, start_at) {
4133 if (IS_UP(slave->dev) &&
4134 (slave->link == BOND_LINK_UP) &&
4135 bond_is_active_slave(slave)) {
4137 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
4139 pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n",
4144 res = bond_dev_queue_xmit(bond, skb2, tx_dev);
4146 dev_kfree_skb(skb2);
4150 tx_dev = slave->dev;
4155 res = bond_dev_queue_xmit(bond, skb, tx_dev);
4159 /* no suitable interface, frame not sent */
4162 /* frame sent to all suitable interfaces */
4163 return NETDEV_TX_OK;
4166 /*------------------------- Device initialization ---------------------------*/
4168 static void bond_set_xmit_hash_policy(struct bonding *bond)
4170 switch (bond->params.xmit_policy) {
4171 case BOND_XMIT_POLICY_LAYER23:
4172 bond->xmit_hash_policy = bond_xmit_hash_policy_l23;
4174 case BOND_XMIT_POLICY_LAYER34:
4175 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4177 case BOND_XMIT_POLICY_LAYER2:
4179 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4185 * Lookup the slave that corresponds to a qid
4187 static inline int bond_slave_override(struct bonding *bond,
4188 struct sk_buff *skb)
4191 struct slave *slave = NULL;
4192 struct slave *check_slave;
4194 if (!skb->queue_mapping)
4197 /* Find out if any slaves have the same mapping as this skb. */
4198 bond_for_each_slave(bond, check_slave, i) {
4199 if (check_slave->queue_id == skb->queue_mapping) {
4200 slave = check_slave;
4205 /* If the slave isn't UP, use default transmit policy. */
4206 if (slave && slave->queue_id && IS_UP(slave->dev) &&
4207 (slave->link == BOND_LINK_UP)) {
4208 res = bond_dev_queue_xmit(bond, skb, slave->dev);
4215 static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb)
4218 * This helper function exists to help dev_pick_tx get the correct
4219 * destination queue. Using a helper function skips a call to
4220 * skb_tx_hash and will put the skbs in the queue we expect on their
4221 * way down to the bonding driver.
4223 u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0;
4226 * Save the original txq to restore before passing to the driver
4228 bond_queue_mapping(skb) = skb->queue_mapping;
4230 if (unlikely(txq >= dev->real_num_tx_queues)) {
4232 txq -= dev->real_num_tx_queues;
4233 } while (txq >= dev->real_num_tx_queues);
4238 static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
4240 struct bonding *bond = netdev_priv(dev);
4242 if (TX_QUEUE_OVERRIDE(bond->params.mode)) {
4243 if (!bond_slave_override(bond, skb))
4244 return NETDEV_TX_OK;
4247 switch (bond->params.mode) {
4248 case BOND_MODE_ROUNDROBIN:
4249 return bond_xmit_roundrobin(skb, dev);
4250 case BOND_MODE_ACTIVEBACKUP:
4251 return bond_xmit_activebackup(skb, dev);
4253 return bond_xmit_xor(skb, dev);
4254 case BOND_MODE_BROADCAST:
4255 return bond_xmit_broadcast(skb, dev);
4256 case BOND_MODE_8023AD:
4257 return bond_3ad_xmit_xor(skb, dev);
4260 return bond_alb_xmit(skb, dev);
4262 /* Should never happen, mode already checked */
4263 pr_err("%s: Error: Unknown bonding mode %d\n",
4264 dev->name, bond->params.mode);
4267 return NETDEV_TX_OK;
4271 static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
4273 struct bonding *bond = netdev_priv(dev);
4274 netdev_tx_t ret = NETDEV_TX_OK;
4277 * If we risk deadlock from transmitting this in the
4278 * netpoll path, tell netpoll to queue the frame for later tx
4280 if (is_netpoll_tx_blocked(dev))
4281 return NETDEV_TX_BUSY;
4283 read_lock(&bond->lock);
4285 if (bond->slave_cnt)
4286 ret = __bond_start_xmit(skb, dev);
4290 read_unlock(&bond->lock);
4296 * set bond mode specific net device operations
4298 void bond_set_mode_ops(struct bonding *bond, int mode)
4300 struct net_device *bond_dev = bond->dev;
4303 case BOND_MODE_ROUNDROBIN:
4305 case BOND_MODE_ACTIVEBACKUP:
4308 bond_set_xmit_hash_policy(bond);
4310 case BOND_MODE_BROADCAST:
4312 case BOND_MODE_8023AD:
4313 bond_set_xmit_hash_policy(bond);
4320 /* Should never happen, mode already checked */
4321 pr_err("%s: Error: Unknown bonding mode %d\n",
4322 bond_dev->name, mode);
4327 static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
4328 struct ethtool_drvinfo *drvinfo)
4330 strncpy(drvinfo->driver, DRV_NAME, 32);
4331 strncpy(drvinfo->version, DRV_VERSION, 32);
4332 snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION);
4335 static const struct ethtool_ops bond_ethtool_ops = {
4336 .get_drvinfo = bond_ethtool_get_drvinfo,
4337 .get_link = ethtool_op_get_link,
4340 static const struct net_device_ops bond_netdev_ops = {
4341 .ndo_init = bond_init,
4342 .ndo_uninit = bond_uninit,
4343 .ndo_open = bond_open,
4344 .ndo_stop = bond_close,
4345 .ndo_start_xmit = bond_start_xmit,
4346 .ndo_select_queue = bond_select_queue,
4347 .ndo_get_stats64 = bond_get_stats,
4348 .ndo_do_ioctl = bond_do_ioctl,
4349 .ndo_set_multicast_list = bond_set_multicast_list,
4350 .ndo_change_mtu = bond_change_mtu,
4351 .ndo_set_mac_address = bond_set_mac_address,
4352 .ndo_neigh_setup = bond_neigh_setup,
4353 .ndo_vlan_rx_register = bond_vlan_rx_register,
4354 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
4355 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4356 #ifdef CONFIG_NET_POLL_CONTROLLER
4357 .ndo_netpoll_setup = bond_netpoll_setup,
4358 .ndo_netpoll_cleanup = bond_netpoll_cleanup,
4359 .ndo_poll_controller = bond_poll_controller,
4361 .ndo_add_slave = bond_enslave,
4362 .ndo_del_slave = bond_release,
4363 .ndo_fix_features = bond_fix_features,
4366 static void bond_destructor(struct net_device *bond_dev)
4368 struct bonding *bond = netdev_priv(bond_dev);
4370 destroy_workqueue(bond->wq);
4371 free_netdev(bond_dev);
4374 static void bond_setup(struct net_device *bond_dev)
4376 struct bonding *bond = netdev_priv(bond_dev);
4378 /* initialize rwlocks */
4379 rwlock_init(&bond->lock);
4380 rwlock_init(&bond->curr_slave_lock);
4382 bond->params = bonding_defaults;
4384 /* Initialize pointers */
4385 bond->dev = bond_dev;
4386 INIT_LIST_HEAD(&bond->vlan_list);
4388 /* Initialize the device entry points */
4389 ether_setup(bond_dev);
4390 bond_dev->netdev_ops = &bond_netdev_ops;
4391 bond_dev->ethtool_ops = &bond_ethtool_ops;
4392 bond_set_mode_ops(bond, bond->params.mode);
4394 bond_dev->destructor = bond_destructor;
4396 /* Initialize the device options */
4397 bond_dev->tx_queue_len = 0;
4398 bond_dev->flags |= IFF_MASTER|IFF_MULTICAST;
4399 bond_dev->priv_flags |= IFF_BONDING;
4400 bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
4402 /* At first, we block adding VLANs. That's the only way to
4403 * prevent problems that occur when adding VLANs over an
4404 * empty bond. The block will be removed once non-challenged
4405 * slaves are enslaved.
4407 bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
4409 /* don't acquire bond device's netif_tx_lock when
4411 bond_dev->features |= NETIF_F_LLTX;
4413 /* By default, we declare the bond to be fully
4414 * VLAN hardware accelerated capable. Special
4415 * care is taken in the various xmit functions
4416 * when there are slaves that are not hw accel
4420 bond_dev->hw_features = BOND_VLAN_FEATURES |
4421 NETIF_F_HW_VLAN_TX |
4422 NETIF_F_HW_VLAN_RX |
4423 NETIF_F_HW_VLAN_FILTER;
4425 bond_dev->hw_features &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_NO_CSUM);
4426 bond_dev->features |= bond_dev->hw_features;
4429 static void bond_work_cancel_all(struct bonding *bond)
4431 write_lock_bh(&bond->lock);
4432 bond->kill_timers = 1;
4433 write_unlock_bh(&bond->lock);
4435 if (bond->params.miimon && delayed_work_pending(&bond->mii_work))
4436 cancel_delayed_work(&bond->mii_work);
4438 if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work))
4439 cancel_delayed_work(&bond->arp_work);
4441 if (bond->params.mode == BOND_MODE_ALB &&
4442 delayed_work_pending(&bond->alb_work))
4443 cancel_delayed_work(&bond->alb_work);
4445 if (bond->params.mode == BOND_MODE_8023AD &&
4446 delayed_work_pending(&bond->ad_work))
4447 cancel_delayed_work(&bond->ad_work);
4449 if (delayed_work_pending(&bond->mcast_work))
4450 cancel_delayed_work(&bond->mcast_work);
4454 * Destroy a bonding device.
4455 * Must be under rtnl_lock when this function is called.
4457 static void bond_uninit(struct net_device *bond_dev)
4459 struct bonding *bond = netdev_priv(bond_dev);
4460 struct vlan_entry *vlan, *tmp;
4462 bond_netpoll_cleanup(bond_dev);
4464 /* Release the bonded slaves */
4465 bond_release_all(bond_dev);
4467 list_del(&bond->bond_list);
4469 bond_work_cancel_all(bond);
4471 bond_remove_proc_entry(bond);
4473 bond_debug_unregister(bond);
4475 __hw_addr_flush(&bond->mc_list);
4477 list_for_each_entry_safe(vlan, tmp, &bond->vlan_list, vlan_list) {
4478 list_del(&vlan->vlan_list);
4483 /*------------------------- Module initialization ---------------------------*/
4486 * Convert string input module parms. Accept either the
4487 * number of the mode or its string name. A bit complicated because
4488 * some mode names are substrings of other names, and calls from sysfs
4489 * may have whitespace in the name (trailing newlines, for example).
4491 int bond_parse_parm(const char *buf, const struct bond_parm_tbl *tbl)
4493 int modeint = -1, i, rv;
4494 char *p, modestr[BOND_MAX_MODENAME_LEN + 1] = { 0, };
4496 for (p = (char *)buf; *p; p++)
4497 if (!(isdigit(*p) || isspace(*p)))
4501 rv = sscanf(buf, "%20s", modestr);
4503 rv = sscanf(buf, "%d", &modeint);
4508 for (i = 0; tbl[i].modename; i++) {
4509 if (modeint == tbl[i].mode)
4511 if (strcmp(modestr, tbl[i].modename) == 0)
4518 static int bond_check_params(struct bond_params *params)
4520 int arp_validate_value, fail_over_mac_value, primary_reselect_value;
4523 * Convert string parameters.
4526 bond_mode = bond_parse_parm(mode, bond_mode_tbl);
4527 if (bond_mode == -1) {
4528 pr_err("Error: Invalid bonding mode \"%s\"\n",
4529 mode == NULL ? "NULL" : mode);
4534 if (xmit_hash_policy) {
4535 if ((bond_mode != BOND_MODE_XOR) &&
4536 (bond_mode != BOND_MODE_8023AD)) {
4537 pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
4538 bond_mode_name(bond_mode));
4540 xmit_hashtype = bond_parse_parm(xmit_hash_policy,
4542 if (xmit_hashtype == -1) {
4543 pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
4544 xmit_hash_policy == NULL ? "NULL" :
4552 if (bond_mode != BOND_MODE_8023AD) {
4553 pr_info("lacp_rate param is irrelevant in mode %s\n",
4554 bond_mode_name(bond_mode));
4556 lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl);
4557 if (lacp_fast == -1) {
4558 pr_err("Error: Invalid lacp rate \"%s\"\n",
4559 lacp_rate == NULL ? "NULL" : lacp_rate);
4566 params->ad_select = bond_parse_parm(ad_select, ad_select_tbl);
4567 if (params->ad_select == -1) {
4568 pr_err("Error: Invalid ad_select \"%s\"\n",
4569 ad_select == NULL ? "NULL" : ad_select);
4573 if (bond_mode != BOND_MODE_8023AD) {
4574 pr_warning("ad_select param only affects 802.3ad mode\n");
4577 params->ad_select = BOND_AD_STABLE;
4580 if (max_bonds < 0) {
4581 pr_warning("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
4582 max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
4583 max_bonds = BOND_DEFAULT_MAX_BONDS;
4587 pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n",
4588 miimon, INT_MAX, BOND_LINK_MON_INTERV);
4589 miimon = BOND_LINK_MON_INTERV;
4593 pr_warning("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4598 if (downdelay < 0) {
4599 pr_warning("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4600 downdelay, INT_MAX);
4604 if ((use_carrier != 0) && (use_carrier != 1)) {
4605 pr_warning("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n",
4610 if (num_peer_notif < 0 || num_peer_notif > 255) {
4611 pr_warning("Warning: num_grat_arp/num_unsol_na (%d) not in range 0-255 so it was reset to 1\n",
4616 /* reset values for 802.3ad */
4617 if (bond_mode == BOND_MODE_8023AD) {
4619 pr_warning("Warning: miimon must be specified, otherwise bonding will not detect link failure, speed and duplex which are essential for 802.3ad operation\n");
4620 pr_warning("Forcing miimon to 100msec\n");
4625 if (tx_queues < 1 || tx_queues > 255) {
4626 pr_warning("Warning: tx_queues (%d) should be between "
4627 "1 and 255, resetting to %d\n",
4628 tx_queues, BOND_DEFAULT_TX_QUEUES);
4629 tx_queues = BOND_DEFAULT_TX_QUEUES;
4632 if ((all_slaves_active != 0) && (all_slaves_active != 1)) {
4633 pr_warning("Warning: all_slaves_active module parameter (%d), "
4634 "not of valid value (0/1), so it was set to "
4635 "0\n", all_slaves_active);
4636 all_slaves_active = 0;
4639 if (resend_igmp < 0 || resend_igmp > 255) {
4640 pr_warning("Warning: resend_igmp (%d) should be between "
4641 "0 and 255, resetting to %d\n",
4642 resend_igmp, BOND_DEFAULT_RESEND_IGMP);
4643 resend_igmp = BOND_DEFAULT_RESEND_IGMP;
4646 /* reset values for TLB/ALB */
4647 if ((bond_mode == BOND_MODE_TLB) ||
4648 (bond_mode == BOND_MODE_ALB)) {
4650 pr_warning("Warning: miimon must be specified, otherwise bonding will not detect link failure and link speed which are essential for TLB/ALB load balancing\n");
4651 pr_warning("Forcing miimon to 100msec\n");
4656 if (bond_mode == BOND_MODE_ALB) {
4657 pr_notice("In ALB mode you might experience client disconnections upon reconnection of a link if the bonding module updelay parameter (%d msec) is incompatible with the forwarding delay time of the switch\n",
4662 if (updelay || downdelay) {
4663 /* just warn the user the up/down delay will have
4664 * no effect since miimon is zero...
4666 pr_warning("Warning: miimon module parameter not set and updelay (%d) or downdelay (%d) module parameter is set; updelay and downdelay have no effect unless miimon is set\n",
4667 updelay, downdelay);
4670 /* don't allow arp monitoring */
4672 pr_warning("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n",
4673 miimon, arp_interval);
4677 if ((updelay % miimon) != 0) {
4678 pr_warning("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
4680 (updelay / miimon) * miimon);
4685 if ((downdelay % miimon) != 0) {
4686 pr_warning("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n",
4688 (downdelay / miimon) * miimon);
4691 downdelay /= miimon;
4694 if (arp_interval < 0) {
4695 pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n",
4696 arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
4697 arp_interval = BOND_LINK_ARP_INTERV;
4700 for (arp_ip_count = 0;
4701 (arp_ip_count < BOND_MAX_ARP_TARGETS) && arp_ip_target[arp_ip_count];
4703 /* not complete check, but should be good enough to
4705 if (!isdigit(arp_ip_target[arp_ip_count][0])) {
4706 pr_warning("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n",
4707 arp_ip_target[arp_ip_count]);
4710 __be32 ip = in_aton(arp_ip_target[arp_ip_count]);
4711 arp_target[arp_ip_count] = ip;
4715 if (arp_interval && !arp_ip_count) {
4716 /* don't allow arping if no arp_ip_target given... */
4717 pr_warning("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n",
4723 if (bond_mode != BOND_MODE_ACTIVEBACKUP) {
4724 pr_err("arp_validate only supported in active-backup mode\n");
4727 if (!arp_interval) {
4728 pr_err("arp_validate requires arp_interval\n");
4732 arp_validate_value = bond_parse_parm(arp_validate,
4734 if (arp_validate_value == -1) {
4735 pr_err("Error: invalid arp_validate \"%s\"\n",
4736 arp_validate == NULL ? "NULL" : arp_validate);
4740 arp_validate_value = 0;
4743 pr_info("MII link monitoring set to %d ms\n", miimon);
4744 } else if (arp_interval) {
4747 pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
4749 arp_validate_tbl[arp_validate_value].modename,
4752 for (i = 0; i < arp_ip_count; i++)
4753 pr_info(" %s", arp_ip_target[i]);
4757 } else if (max_bonds) {
4758 /* miimon and arp_interval not set, we need one so things
4759 * work as expected, see bonding.txt for details
4761 pr_warning("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details.\n");
4764 if (primary && !USES_PRIMARY(bond_mode)) {
4765 /* currently, using a primary only makes sense
4766 * in active backup, TLB or ALB modes
4768 pr_warning("Warning: %s primary device specified but has no effect in %s mode\n",
4769 primary, bond_mode_name(bond_mode));
4773 if (primary && primary_reselect) {
4774 primary_reselect_value = bond_parse_parm(primary_reselect,
4776 if (primary_reselect_value == -1) {
4777 pr_err("Error: Invalid primary_reselect \"%s\"\n",
4779 NULL ? "NULL" : primary_reselect);
4783 primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
4786 if (fail_over_mac) {
4787 fail_over_mac_value = bond_parse_parm(fail_over_mac,
4789 if (fail_over_mac_value == -1) {
4790 pr_err("Error: invalid fail_over_mac \"%s\"\n",
4791 arp_validate == NULL ? "NULL" : arp_validate);
4795 if (bond_mode != BOND_MODE_ACTIVEBACKUP)
4796 pr_warning("Warning: fail_over_mac only affects active-backup mode.\n");
4798 fail_over_mac_value = BOND_FOM_NONE;
4801 /* fill params struct with the proper values */
4802 params->mode = bond_mode;
4803 params->xmit_policy = xmit_hashtype;
4804 params->miimon = miimon;
4805 params->num_peer_notif = num_peer_notif;
4806 params->arp_interval = arp_interval;
4807 params->arp_validate = arp_validate_value;
4808 params->updelay = updelay;
4809 params->downdelay = downdelay;
4810 params->use_carrier = use_carrier;
4811 params->lacp_fast = lacp_fast;
4812 params->primary[0] = 0;
4813 params->primary_reselect = primary_reselect_value;
4814 params->fail_over_mac = fail_over_mac_value;
4815 params->tx_queues = tx_queues;
4816 params->all_slaves_active = all_slaves_active;
4817 params->resend_igmp = resend_igmp;
4820 strncpy(params->primary, primary, IFNAMSIZ);
4821 params->primary[IFNAMSIZ - 1] = 0;
4824 memcpy(params->arp_targets, arp_target, sizeof(arp_target));
4829 static struct lock_class_key bonding_netdev_xmit_lock_key;
4830 static struct lock_class_key bonding_netdev_addr_lock_key;
4832 static void bond_set_lockdep_class_one(struct net_device *dev,
4833 struct netdev_queue *txq,
4836 lockdep_set_class(&txq->_xmit_lock,
4837 &bonding_netdev_xmit_lock_key);
4840 static void bond_set_lockdep_class(struct net_device *dev)
4842 lockdep_set_class(&dev->addr_list_lock,
4843 &bonding_netdev_addr_lock_key);
4844 netdev_for_each_tx_queue(dev, bond_set_lockdep_class_one, NULL);
4848 * Called from registration process
4850 static int bond_init(struct net_device *bond_dev)
4852 struct bonding *bond = netdev_priv(bond_dev);
4853 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
4854 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
4856 pr_debug("Begin bond_init for %s\n", bond_dev->name);
4859 * Initialize locks that may be required during
4860 * en/deslave operations. All of the bond_open work
4861 * (of which this is part) should really be moved to
4862 * a phase prior to dev_open
4864 spin_lock_init(&(bond_info->tx_hashtbl_lock));
4865 spin_lock_init(&(bond_info->rx_hashtbl_lock));
4867 bond->wq = create_singlethread_workqueue(bond_dev->name);
4871 bond_set_lockdep_class(bond_dev);
4873 bond_create_proc_entry(bond);
4874 list_add_tail(&bond->bond_list, &bn->dev_list);
4876 bond_prepare_sysfs_group(bond);
4878 bond_debug_register(bond);
4880 __hw_addr_init(&bond->mc_list);
4884 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
4886 if (tb[IFLA_ADDRESS]) {
4887 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
4889 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
4890 return -EADDRNOTAVAIL;
4895 static struct rtnl_link_ops bond_link_ops __read_mostly = {
4897 .priv_size = sizeof(struct bonding),
4898 .setup = bond_setup,
4899 .validate = bond_validate,
4902 /* Create a new bond based on the specified name and bonding parameters.
4903 * If name is NULL, obtain a suitable "bond%d" name for us.
4904 * Caller must NOT hold rtnl_lock; we need to release it here before we
4905 * set up our sysfs entries.
4907 int bond_create(struct net *net, const char *name)
4909 struct net_device *bond_dev;
4914 bond_dev = alloc_netdev_mq(sizeof(struct bonding),
4915 name ? name : "bond%d",
4916 bond_setup, tx_queues);
4918 pr_err("%s: eek! can't alloc netdev!\n", name);
4923 dev_net_set(bond_dev, net);
4924 bond_dev->rtnl_link_ops = &bond_link_ops;
4926 res = register_netdevice(bond_dev);
4928 netif_carrier_off(bond_dev);
4932 bond_destructor(bond_dev);
4936 static int __net_init bond_net_init(struct net *net)
4938 struct bond_net *bn = net_generic(net, bond_net_id);
4941 INIT_LIST_HEAD(&bn->dev_list);
4943 bond_create_proc_dir(bn);
4948 static void __net_exit bond_net_exit(struct net *net)
4950 struct bond_net *bn = net_generic(net, bond_net_id);
4952 bond_destroy_proc_dir(bn);
4955 static struct pernet_operations bond_net_ops = {
4956 .init = bond_net_init,
4957 .exit = bond_net_exit,
4959 .size = sizeof(struct bond_net),
4962 static int __init bonding_init(void)
4967 pr_info("%s", bond_version);
4969 res = bond_check_params(&bonding_defaults);
4973 res = register_pernet_subsys(&bond_net_ops);
4977 res = rtnl_link_register(&bond_link_ops);
4981 bond_create_debugfs();
4983 for (i = 0; i < max_bonds; i++) {
4984 res = bond_create(&init_net, NULL);
4989 res = bond_create_sysfs();
4993 register_netdevice_notifier(&bond_netdev_notifier);
4994 register_inetaddr_notifier(&bond_inetaddr_notifier);
4998 rtnl_link_unregister(&bond_link_ops);
5000 unregister_pernet_subsys(&bond_net_ops);
5005 static void __exit bonding_exit(void)
5007 unregister_netdevice_notifier(&bond_netdev_notifier);
5008 unregister_inetaddr_notifier(&bond_inetaddr_notifier);
5010 bond_destroy_sysfs();
5011 bond_destroy_debugfs();
5013 rtnl_link_unregister(&bond_link_ops);
5014 unregister_pernet_subsys(&bond_net_ops);
5016 #ifdef CONFIG_NET_POLL_CONTROLLER
5018 * Make sure we don't have an imbalance on our netpoll blocking
5020 WARN_ON(atomic_read(&netpoll_block_tx));
5024 module_init(bonding_init);
5025 module_exit(bonding_exit);
5026 MODULE_LICENSE("GPL");
5027 MODULE_VERSION(DRV_VERSION);
5028 MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
5029 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
5030 MODULE_ALIAS_RTNL_LINK("bond");