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);
392 * bond_dev_queue_xmit - Prepare skb for xmit.
394 * @bond: bond device that got this skb for tx.
395 * @skb: hw accel VLAN tagged skb to transmit
396 * @slave_dev: slave that is supposed to xmit this skbuff
398 int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
399 struct net_device *slave_dev)
401 skb->dev = slave_dev;
403 if (unlikely(netpoll_tx_running(slave_dev)))
404 bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
412 * In the following 3 functions, bond_vlan_rx_register(), bond_vlan_rx_add_vid
413 * and bond_vlan_rx_kill_vid, We don't protect the slave list iteration with a
415 * a. This operation is performed in IOCTL context,
416 * b. The operation is protected by the RTNL semaphore in the 8021q code,
417 * c. Holding a lock with BH disabled while directly calling a base driver
418 * entry point is generally a BAD idea.
420 * The design of synchronization/protection for this operation in the 8021q
421 * module is good for one or more VLAN devices over a single physical device
422 * and cannot be extended for a teaming solution like bonding, so there is a
423 * potential race condition here where a net device from the vlan group might
424 * be referenced (either by a base driver or the 8021q code) while it is being
425 * removed from the system. However, it turns out we're not making matters
426 * worse, and if it works for regular VLAN usage it will work here too.
430 * bond_vlan_rx_register - Propagates registration to slaves
431 * @bond_dev: bonding net device that got called
432 * @grp: vlan group being registered
434 static void bond_vlan_rx_register(struct net_device *bond_dev,
435 struct vlan_group *grp)
437 struct bonding *bond = netdev_priv(bond_dev);
441 write_lock_bh(&bond->lock);
443 write_unlock_bh(&bond->lock);
445 bond_for_each_slave(bond, slave, i) {
446 struct net_device *slave_dev = slave->dev;
447 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
449 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
450 slave_ops->ndo_vlan_rx_register) {
451 slave_ops->ndo_vlan_rx_register(slave_dev, grp);
457 * bond_vlan_rx_add_vid - Propagates adding an id to slaves
458 * @bond_dev: bonding net device that got called
459 * @vid: vlan id being added
461 static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid)
463 struct bonding *bond = netdev_priv(bond_dev);
467 bond_for_each_slave(bond, slave, i) {
468 struct net_device *slave_dev = slave->dev;
469 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
471 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) &&
472 slave_ops->ndo_vlan_rx_add_vid) {
473 slave_ops->ndo_vlan_rx_add_vid(slave_dev, vid);
477 res = bond_add_vlan(bond, vid);
479 pr_err("%s: Error: Failed to add vlan id %d\n",
480 bond_dev->name, vid);
485 * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves
486 * @bond_dev: bonding net device that got called
487 * @vid: vlan id being removed
489 static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
491 struct bonding *bond = netdev_priv(bond_dev);
493 struct net_device *vlan_dev;
496 bond_for_each_slave(bond, slave, i) {
497 struct net_device *slave_dev = slave->dev;
498 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
500 if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) &&
501 slave_ops->ndo_vlan_rx_kill_vid) {
502 /* Save and then restore vlan_dev in the grp array,
503 * since the slave's driver might clear it.
505 vlan_dev = vlan_group_get_device(bond->vlgrp, vid);
506 slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vid);
507 vlan_group_set_device(bond->vlgrp, vid, vlan_dev);
511 res = bond_del_vlan(bond, vid);
513 pr_err("%s: Error: Failed to remove vlan id %d\n",
514 bond_dev->name, vid);
518 static void bond_add_vlans_on_slave(struct bonding *bond, struct net_device *slave_dev)
520 struct vlan_entry *vlan;
521 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
526 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
527 slave_ops->ndo_vlan_rx_register)
528 slave_ops->ndo_vlan_rx_register(slave_dev, bond->vlgrp);
530 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) ||
531 !(slave_ops->ndo_vlan_rx_add_vid))
534 list_for_each_entry(vlan, &bond->vlan_list, vlan_list)
535 slave_ops->ndo_vlan_rx_add_vid(slave_dev, vlan->vlan_id);
538 static void bond_del_vlans_from_slave(struct bonding *bond,
539 struct net_device *slave_dev)
541 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
542 struct vlan_entry *vlan;
543 struct net_device *vlan_dev;
548 if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) ||
549 !(slave_ops->ndo_vlan_rx_kill_vid))
552 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
555 /* Save and then restore vlan_dev in the grp array,
556 * since the slave's driver might clear it.
558 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
559 slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vlan->vlan_id);
560 vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev);
564 if ((slave_dev->features & NETIF_F_HW_VLAN_RX) &&
565 slave_ops->ndo_vlan_rx_register)
566 slave_ops->ndo_vlan_rx_register(slave_dev, NULL);
569 /*------------------------------- Link status -------------------------------*/
572 * Set the carrier state for the master according to the state of its
573 * slaves. If any slaves are up, the master is up. In 802.3ad mode,
574 * do special 802.3ad magic.
576 * Returns zero if carrier state does not change, nonzero if it does.
578 static int bond_set_carrier(struct bonding *bond)
583 if (bond->slave_cnt == 0)
586 if (bond->params.mode == BOND_MODE_8023AD)
587 return bond_3ad_set_carrier(bond);
589 bond_for_each_slave(bond, slave, i) {
590 if (slave->link == BOND_LINK_UP) {
591 if (!netif_carrier_ok(bond->dev)) {
592 netif_carrier_on(bond->dev);
600 if (netif_carrier_ok(bond->dev)) {
601 netif_carrier_off(bond->dev);
608 * Get link speed and duplex from the slave's base driver
609 * using ethtool. If for some reason the call fails or the
610 * values are invalid, fake speed and duplex to 100/Full
613 static int bond_update_speed_duplex(struct slave *slave)
615 struct net_device *slave_dev = slave->dev;
616 struct ethtool_cmd etool = { .cmd = ETHTOOL_GSET };
620 /* Fake speed and duplex */
621 slave->speed = SPEED_100;
622 slave->duplex = DUPLEX_FULL;
624 if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings)
627 res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
631 slave_speed = ethtool_cmd_speed(&etool);
632 switch (slave_speed) {
642 switch (etool.duplex) {
650 slave->speed = slave_speed;
651 slave->duplex = etool.duplex;
657 * if <dev> supports MII link status reporting, check its link status.
659 * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(),
660 * depending upon the setting of the use_carrier parameter.
662 * Return either BMSR_LSTATUS, meaning that the link is up (or we
663 * can't tell and just pretend it is), or 0, meaning that the link is
666 * If reporting is non-zero, instead of faking link up, return -1 if
667 * both ETHTOOL and MII ioctls fail (meaning the device does not
668 * support them). If use_carrier is set, return whatever it says.
669 * It'd be nice if there was a good way to tell if a driver supports
670 * netif_carrier, but there really isn't.
672 static int bond_check_dev_link(struct bonding *bond,
673 struct net_device *slave_dev, int reporting)
675 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
676 int (*ioctl)(struct net_device *, struct ifreq *, int);
678 struct mii_ioctl_data *mii;
680 if (!reporting && !netif_running(slave_dev))
683 if (bond->params.use_carrier)
684 return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
686 /* Try to get link status using Ethtool first. */
687 if (slave_dev->ethtool_ops) {
688 if (slave_dev->ethtool_ops->get_link) {
691 link = slave_dev->ethtool_ops->get_link(slave_dev);
693 return link ? BMSR_LSTATUS : 0;
697 /* Ethtool can't be used, fallback to MII ioctls. */
698 ioctl = slave_ops->ndo_do_ioctl;
700 /* TODO: set pointer to correct ioctl on a per team member */
701 /* bases to make this more efficient. that is, once */
702 /* we determine the correct ioctl, we will always */
703 /* call it and not the others for that team */
707 * We cannot assume that SIOCGMIIPHY will also read a
708 * register; not all network drivers (e.g., e100)
712 /* Yes, the mii is overlaid on the ifreq.ifr_ifru */
713 strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
715 if (IOCTL(slave_dev, &ifr, SIOCGMIIPHY) == 0) {
716 mii->reg_num = MII_BMSR;
717 if (IOCTL(slave_dev, &ifr, SIOCGMIIREG) == 0)
718 return mii->val_out & BMSR_LSTATUS;
723 * If reporting, report that either there's no dev->do_ioctl,
724 * or both SIOCGMIIREG and get_link failed (meaning that we
725 * cannot report link status). If not reporting, pretend
728 return reporting ? -1 : BMSR_LSTATUS;
731 /*----------------------------- Multicast list ------------------------------*/
734 * Push the promiscuity flag down to appropriate slaves
736 static int bond_set_promiscuity(struct bonding *bond, int inc)
739 if (USES_PRIMARY(bond->params.mode)) {
740 /* write lock already acquired */
741 if (bond->curr_active_slave) {
742 err = dev_set_promiscuity(bond->curr_active_slave->dev,
748 bond_for_each_slave(bond, slave, i) {
749 err = dev_set_promiscuity(slave->dev, inc);
758 * Push the allmulti flag down to all slaves
760 static int bond_set_allmulti(struct bonding *bond, int inc)
763 if (USES_PRIMARY(bond->params.mode)) {
764 /* write lock already acquired */
765 if (bond->curr_active_slave) {
766 err = dev_set_allmulti(bond->curr_active_slave->dev,
772 bond_for_each_slave(bond, slave, i) {
773 err = dev_set_allmulti(slave->dev, inc);
782 * Add a Multicast address to slaves
785 static void bond_mc_add(struct bonding *bond, void *addr)
787 if (USES_PRIMARY(bond->params.mode)) {
788 /* write lock already acquired */
789 if (bond->curr_active_slave)
790 dev_mc_add(bond->curr_active_slave->dev, addr);
795 bond_for_each_slave(bond, slave, i)
796 dev_mc_add(slave->dev, addr);
801 * Remove a multicast address from slave
804 static void bond_mc_del(struct bonding *bond, void *addr)
806 if (USES_PRIMARY(bond->params.mode)) {
807 /* write lock already acquired */
808 if (bond->curr_active_slave)
809 dev_mc_del(bond->curr_active_slave->dev, addr);
813 bond_for_each_slave(bond, slave, i) {
814 dev_mc_del(slave->dev, addr);
820 static void __bond_resend_igmp_join_requests(struct net_device *dev)
822 struct in_device *in_dev;
825 in_dev = __in_dev_get_rcu(dev);
827 ip_mc_rejoin_groups(in_dev);
832 * Retrieve the list of registered multicast addresses for the bonding
833 * device and retransmit an IGMP JOIN request to the current active
836 static void bond_resend_igmp_join_requests(struct bonding *bond)
838 struct net_device *vlan_dev;
839 struct vlan_entry *vlan;
841 read_lock(&bond->lock);
843 /* rejoin all groups on bond device */
844 __bond_resend_igmp_join_requests(bond->dev);
846 /* rejoin all groups on vlan devices */
848 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
849 vlan_dev = vlan_group_get_device(bond->vlgrp,
852 __bond_resend_igmp_join_requests(vlan_dev);
856 if (--bond->igmp_retrans > 0)
857 queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
859 read_unlock(&bond->lock);
862 static void bond_resend_igmp_join_requests_delayed(struct work_struct *work)
864 struct bonding *bond = container_of(work, struct bonding,
866 bond_resend_igmp_join_requests(bond);
870 * flush all members of flush->mc_list from device dev->mc_list
872 static void bond_mc_list_flush(struct net_device *bond_dev,
873 struct net_device *slave_dev)
875 struct bonding *bond = netdev_priv(bond_dev);
876 struct netdev_hw_addr *ha;
878 netdev_for_each_mc_addr(ha, bond_dev)
879 dev_mc_del(slave_dev, ha->addr);
881 if (bond->params.mode == BOND_MODE_8023AD) {
882 /* del lacpdu mc addr from mc list */
883 u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
885 dev_mc_del(slave_dev, lacpdu_multicast);
889 /*--------------------------- Active slave change ---------------------------*/
892 * Update the mc list and multicast-related flags for the new and
893 * old active slaves (if any) according to the multicast mode, and
894 * promiscuous flags unconditionally.
896 static void bond_mc_swap(struct bonding *bond, struct slave *new_active,
897 struct slave *old_active)
899 struct netdev_hw_addr *ha;
901 if (!USES_PRIMARY(bond->params.mode))
902 /* nothing to do - mc list is already up-to-date on
908 if (bond->dev->flags & IFF_PROMISC)
909 dev_set_promiscuity(old_active->dev, -1);
911 if (bond->dev->flags & IFF_ALLMULTI)
912 dev_set_allmulti(old_active->dev, -1);
914 netdev_for_each_mc_addr(ha, bond->dev)
915 dev_mc_del(old_active->dev, ha->addr);
919 /* FIXME: Signal errors upstream. */
920 if (bond->dev->flags & IFF_PROMISC)
921 dev_set_promiscuity(new_active->dev, 1);
923 if (bond->dev->flags & IFF_ALLMULTI)
924 dev_set_allmulti(new_active->dev, 1);
926 netdev_for_each_mc_addr(ha, bond->dev)
927 dev_mc_add(new_active->dev, ha->addr);
932 * bond_do_fail_over_mac
934 * Perform special MAC address swapping for fail_over_mac settings
936 * Called with RTNL, bond->lock for read, curr_slave_lock for write_bh.
938 static void bond_do_fail_over_mac(struct bonding *bond,
939 struct slave *new_active,
940 struct slave *old_active)
941 __releases(&bond->curr_slave_lock)
942 __releases(&bond->lock)
943 __acquires(&bond->lock)
944 __acquires(&bond->curr_slave_lock)
946 u8 tmp_mac[ETH_ALEN];
947 struct sockaddr saddr;
950 switch (bond->params.fail_over_mac) {
951 case BOND_FOM_ACTIVE:
953 memcpy(bond->dev->dev_addr, new_active->dev->dev_addr,
954 new_active->dev->addr_len);
956 case BOND_FOM_FOLLOW:
958 * if new_active && old_active, swap them
959 * if just old_active, do nothing (going to no active slave)
960 * if just new_active, set new_active to bond's MAC
965 write_unlock_bh(&bond->curr_slave_lock);
966 read_unlock(&bond->lock);
969 memcpy(tmp_mac, new_active->dev->dev_addr, ETH_ALEN);
970 memcpy(saddr.sa_data, old_active->dev->dev_addr,
972 saddr.sa_family = new_active->dev->type;
974 memcpy(saddr.sa_data, bond->dev->dev_addr, ETH_ALEN);
975 saddr.sa_family = bond->dev->type;
978 rv = dev_set_mac_address(new_active->dev, &saddr);
980 pr_err("%s: Error %d setting MAC of slave %s\n",
981 bond->dev->name, -rv, new_active->dev->name);
988 memcpy(saddr.sa_data, tmp_mac, ETH_ALEN);
989 saddr.sa_family = old_active->dev->type;
991 rv = dev_set_mac_address(old_active->dev, &saddr);
993 pr_err("%s: Error %d setting MAC of slave %s\n",
994 bond->dev->name, -rv, new_active->dev->name);
996 read_lock(&bond->lock);
997 write_lock_bh(&bond->curr_slave_lock);
1000 pr_err("%s: bond_do_fail_over_mac impossible: bad policy %d\n",
1001 bond->dev->name, bond->params.fail_over_mac);
1007 static bool bond_should_change_active(struct bonding *bond)
1009 struct slave *prim = bond->primary_slave;
1010 struct slave *curr = bond->curr_active_slave;
1012 if (!prim || !curr || curr->link != BOND_LINK_UP)
1014 if (bond->force_primary) {
1015 bond->force_primary = false;
1018 if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER &&
1019 (prim->speed < curr->speed ||
1020 (prim->speed == curr->speed && prim->duplex <= curr->duplex)))
1022 if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE)
1028 * find_best_interface - select the best available slave to be the active one
1029 * @bond: our bonding struct
1031 * Warning: Caller must hold curr_slave_lock for writing.
1033 static struct slave *bond_find_best_slave(struct bonding *bond)
1035 struct slave *new_active, *old_active;
1036 struct slave *bestslave = NULL;
1037 int mintime = bond->params.updelay;
1040 new_active = bond->curr_active_slave;
1042 if (!new_active) { /* there were no active slaves left */
1043 if (bond->slave_cnt > 0) /* found one slave */
1044 new_active = bond->first_slave;
1046 return NULL; /* still no slave, return NULL */
1049 if ((bond->primary_slave) &&
1050 bond->primary_slave->link == BOND_LINK_UP &&
1051 bond_should_change_active(bond)) {
1052 new_active = bond->primary_slave;
1055 /* remember where to stop iterating over the slaves */
1056 old_active = new_active;
1058 bond_for_each_slave_from(bond, new_active, i, old_active) {
1059 if (new_active->link == BOND_LINK_UP) {
1061 } else if (new_active->link == BOND_LINK_BACK &&
1062 IS_UP(new_active->dev)) {
1063 /* link up, but waiting for stabilization */
1064 if (new_active->delay < mintime) {
1065 mintime = new_active->delay;
1066 bestslave = new_active;
1074 static bool bond_should_notify_peers(struct bonding *bond)
1076 struct slave *slave = bond->curr_active_slave;
1078 pr_debug("bond_should_notify_peers: bond %s slave %s\n",
1079 bond->dev->name, slave ? slave->dev->name : "NULL");
1081 if (!slave || !bond->send_peer_notif ||
1082 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
1085 bond->send_peer_notif--;
1090 * change_active_interface - change the active slave into the specified one
1091 * @bond: our bonding struct
1092 * @new: the new slave to make the active one
1094 * Set the new slave to the bond's settings and unset them on the old
1095 * curr_active_slave.
1096 * Setting include flags, mc-list, promiscuity, allmulti, etc.
1098 * If @new's link state is %BOND_LINK_BACK we'll set it to %BOND_LINK_UP,
1099 * because it is apparently the best available slave we have, even though its
1100 * updelay hasn't timed out yet.
1102 * If new_active is not NULL, caller must hold bond->lock for read and
1103 * curr_slave_lock for write_bh.
1105 void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1107 struct slave *old_active = bond->curr_active_slave;
1109 if (old_active == new_active)
1113 new_active->jiffies = jiffies;
1115 if (new_active->link == BOND_LINK_BACK) {
1116 if (USES_PRIMARY(bond->params.mode)) {
1117 pr_info("%s: making interface %s the new active one %d ms earlier.\n",
1118 bond->dev->name, new_active->dev->name,
1119 (bond->params.updelay - new_active->delay) * bond->params.miimon);
1122 new_active->delay = 0;
1123 new_active->link = BOND_LINK_UP;
1125 if (bond->params.mode == BOND_MODE_8023AD)
1126 bond_3ad_handle_link_change(new_active, BOND_LINK_UP);
1128 if (bond_is_lb(bond))
1129 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
1131 if (USES_PRIMARY(bond->params.mode)) {
1132 pr_info("%s: making interface %s the new active one.\n",
1133 bond->dev->name, new_active->dev->name);
1138 if (USES_PRIMARY(bond->params.mode))
1139 bond_mc_swap(bond, new_active, old_active);
1141 if (bond_is_lb(bond)) {
1142 bond_alb_handle_active_change(bond, new_active);
1144 bond_set_slave_inactive_flags(old_active);
1146 bond_set_slave_active_flags(new_active);
1148 bond->curr_active_slave = new_active;
1151 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
1153 bond_set_slave_inactive_flags(old_active);
1156 bool should_notify_peers = false;
1158 bond_set_slave_active_flags(new_active);
1160 if (bond->params.fail_over_mac)
1161 bond_do_fail_over_mac(bond, new_active,
1164 if (netif_running(bond->dev)) {
1165 bond->send_peer_notif =
1166 bond->params.num_peer_notif;
1167 should_notify_peers =
1168 bond_should_notify_peers(bond);
1171 write_unlock_bh(&bond->curr_slave_lock);
1172 read_unlock(&bond->lock);
1174 netdev_bonding_change(bond->dev, NETDEV_BONDING_FAILOVER);
1175 if (should_notify_peers)
1176 netdev_bonding_change(bond->dev,
1177 NETDEV_NOTIFY_PEERS);
1179 read_lock(&bond->lock);
1180 write_lock_bh(&bond->curr_slave_lock);
1184 /* resend IGMP joins since active slave has changed or
1185 * all were sent on curr_active_slave.
1186 * resend only if bond is brought up with the affected
1187 * bonding modes and the retransmission is enabled */
1188 if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
1189 ((USES_PRIMARY(bond->params.mode) && new_active) ||
1190 bond->params.mode == BOND_MODE_ROUNDROBIN)) {
1191 bond->igmp_retrans = bond->params.resend_igmp;
1192 queue_delayed_work(bond->wq, &bond->mcast_work, 0);
1197 * bond_select_active_slave - select a new active slave, if needed
1198 * @bond: our bonding struct
1200 * This functions should be called when one of the following occurs:
1201 * - The old curr_active_slave has been released or lost its link.
1202 * - The primary_slave has got its link back.
1203 * - A slave has got its link back and there's no old curr_active_slave.
1205 * Caller must hold bond->lock for read and curr_slave_lock for write_bh.
1207 void bond_select_active_slave(struct bonding *bond)
1209 struct slave *best_slave;
1212 best_slave = bond_find_best_slave(bond);
1213 if (best_slave != bond->curr_active_slave) {
1214 bond_change_active_slave(bond, best_slave);
1215 rv = bond_set_carrier(bond);
1219 if (netif_carrier_ok(bond->dev)) {
1220 pr_info("%s: first active interface up!\n",
1223 pr_info("%s: now running without any active interface !\n",
1229 /*--------------------------- slave list handling ---------------------------*/
1232 * This function attaches the slave to the end of list.
1234 * bond->lock held for writing by caller.
1236 static void bond_attach_slave(struct bonding *bond, struct slave *new_slave)
1238 if (bond->first_slave == NULL) { /* attaching the first slave */
1239 new_slave->next = new_slave;
1240 new_slave->prev = new_slave;
1241 bond->first_slave = new_slave;
1243 new_slave->next = bond->first_slave;
1244 new_slave->prev = bond->first_slave->prev;
1245 new_slave->next->prev = new_slave;
1246 new_slave->prev->next = new_slave;
1253 * This function detaches the slave from the list.
1254 * WARNING: no check is made to verify if the slave effectively
1255 * belongs to <bond>.
1256 * Nothing is freed on return, structures are just unchained.
1257 * If any slave pointer in bond was pointing to <slave>,
1258 * it should be changed by the calling function.
1260 * bond->lock held for writing by caller.
1262 static void bond_detach_slave(struct bonding *bond, struct slave *slave)
1265 slave->next->prev = slave->prev;
1268 slave->prev->next = slave->next;
1270 if (bond->first_slave == slave) { /* slave is the first slave */
1271 if (bond->slave_cnt > 1) { /* there are more slave */
1272 bond->first_slave = slave->next;
1274 bond->first_slave = NULL; /* slave was the last one */
1283 #ifdef CONFIG_NET_POLL_CONTROLLER
1284 static inline int slave_enable_netpoll(struct slave *slave)
1289 np = kzalloc(sizeof(*np), GFP_KERNEL);
1294 np->dev = slave->dev;
1295 err = __netpoll_setup(np);
1304 static inline void slave_disable_netpoll(struct slave *slave)
1306 struct netpoll *np = slave->np;
1312 synchronize_rcu_bh();
1313 __netpoll_cleanup(np);
1316 static inline bool slave_dev_support_netpoll(struct net_device *slave_dev)
1318 if (slave_dev->priv_flags & IFF_DISABLE_NETPOLL)
1320 if (!slave_dev->netdev_ops->ndo_poll_controller)
1325 static void bond_poll_controller(struct net_device *bond_dev)
1329 static void __bond_netpoll_cleanup(struct bonding *bond)
1331 struct slave *slave;
1334 bond_for_each_slave(bond, slave, i)
1335 if (IS_UP(slave->dev))
1336 slave_disable_netpoll(slave);
1338 static void bond_netpoll_cleanup(struct net_device *bond_dev)
1340 struct bonding *bond = netdev_priv(bond_dev);
1342 read_lock(&bond->lock);
1343 __bond_netpoll_cleanup(bond);
1344 read_unlock(&bond->lock);
1347 static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni)
1349 struct bonding *bond = netdev_priv(dev);
1350 struct slave *slave;
1353 read_lock(&bond->lock);
1354 bond_for_each_slave(bond, slave, i) {
1355 err = slave_enable_netpoll(slave);
1357 __bond_netpoll_cleanup(bond);
1361 read_unlock(&bond->lock);
1365 static struct netpoll_info *bond_netpoll_info(struct bonding *bond)
1367 return bond->dev->npinfo;
1371 static inline int slave_enable_netpoll(struct slave *slave)
1375 static inline void slave_disable_netpoll(struct slave *slave)
1378 static void bond_netpoll_cleanup(struct net_device *bond_dev)
1383 /*---------------------------------- IOCTL ----------------------------------*/
1385 static int bond_sethwaddr(struct net_device *bond_dev,
1386 struct net_device *slave_dev)
1388 pr_debug("bond_dev=%p\n", bond_dev);
1389 pr_debug("slave_dev=%p\n", slave_dev);
1390 pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len);
1391 memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
1395 static u32 bond_fix_features(struct net_device *dev, u32 features)
1397 struct slave *slave;
1398 struct bonding *bond = netdev_priv(dev);
1402 read_lock(&bond->lock);
1404 if (!bond->first_slave) {
1405 /* Disable adding VLANs to empty bond. But why? --mq */
1406 features |= NETIF_F_VLAN_CHALLENGED;
1411 features &= ~NETIF_F_ONE_FOR_ALL;
1412 features |= NETIF_F_ALL_FOR_ALL;
1414 bond_for_each_slave(bond, slave, i) {
1415 features = netdev_increment_features(features,
1416 slave->dev->features,
1421 read_unlock(&bond->lock);
1425 #define BOND_VLAN_FEATURES (NETIF_F_ALL_TX_OFFLOADS | \
1426 NETIF_F_SOFT_FEATURES | \
1429 static void bond_compute_features(struct bonding *bond)
1431 struct slave *slave;
1432 struct net_device *bond_dev = bond->dev;
1433 u32 vlan_features = BOND_VLAN_FEATURES;
1434 unsigned short max_hard_header_len = ETH_HLEN;
1437 read_lock(&bond->lock);
1439 if (!bond->first_slave)
1442 bond_for_each_slave(bond, slave, i) {
1443 vlan_features = netdev_increment_features(vlan_features,
1444 slave->dev->vlan_features, BOND_VLAN_FEATURES);
1446 if (slave->dev->hard_header_len > max_hard_header_len)
1447 max_hard_header_len = slave->dev->hard_header_len;
1451 bond_dev->vlan_features = vlan_features;
1452 bond_dev->hard_header_len = max_hard_header_len;
1454 read_unlock(&bond->lock);
1456 netdev_change_features(bond_dev);
1459 static void bond_setup_by_slave(struct net_device *bond_dev,
1460 struct net_device *slave_dev)
1462 struct bonding *bond = netdev_priv(bond_dev);
1464 bond_dev->header_ops = slave_dev->header_ops;
1466 bond_dev->type = slave_dev->type;
1467 bond_dev->hard_header_len = slave_dev->hard_header_len;
1468 bond_dev->addr_len = slave_dev->addr_len;
1470 memcpy(bond_dev->broadcast, slave_dev->broadcast,
1471 slave_dev->addr_len);
1472 bond->setup_by_slave = 1;
1475 /* On bonding slaves other than the currently active slave, suppress
1476 * duplicates except for alb non-mcast/bcast.
1478 static bool bond_should_deliver_exact_match(struct sk_buff *skb,
1479 struct slave *slave,
1480 struct bonding *bond)
1482 if (bond_is_slave_inactive(slave)) {
1483 if (bond->params.mode == BOND_MODE_ALB &&
1484 skb->pkt_type != PACKET_BROADCAST &&
1485 skb->pkt_type != PACKET_MULTICAST)
1492 static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
1494 struct sk_buff *skb = *pskb;
1495 struct slave *slave;
1496 struct bonding *bond;
1498 skb = skb_share_check(skb, GFP_ATOMIC);
1500 return RX_HANDLER_CONSUMED;
1504 slave = bond_slave_get_rcu(skb->dev);
1507 if (bond->params.arp_interval)
1508 slave->dev->last_rx = jiffies;
1510 if (bond->recv_probe) {
1511 struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC);
1514 bond->recv_probe(nskb, bond, slave);
1515 dev_kfree_skb(nskb);
1519 if (bond_should_deliver_exact_match(skb, slave, bond)) {
1520 return RX_HANDLER_EXACT;
1523 skb->dev = bond->dev;
1525 if (bond->params.mode == BOND_MODE_ALB &&
1526 bond->dev->priv_flags & IFF_BRIDGE_PORT &&
1527 skb->pkt_type == PACKET_HOST) {
1529 if (unlikely(skb_cow_head(skb,
1530 skb->data - skb_mac_header(skb)))) {
1532 return RX_HANDLER_CONSUMED;
1534 memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN);
1537 return RX_HANDLER_ANOTHER;
1540 /* enslave device <slave> to bond device <master> */
1541 int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1543 struct bonding *bond = netdev_priv(bond_dev);
1544 const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
1545 struct slave *new_slave = NULL;
1546 struct netdev_hw_addr *ha;
1547 struct sockaddr addr;
1551 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
1552 slave_ops->ndo_do_ioctl == NULL) {
1553 pr_warning("%s: Warning: no link monitoring support for %s\n",
1554 bond_dev->name, slave_dev->name);
1557 /* already enslaved */
1558 if (slave_dev->flags & IFF_SLAVE) {
1559 pr_debug("Error, Device was already enslaved\n");
1563 /* vlan challenged mutual exclusion */
1564 /* no need to lock since we're protected by rtnl_lock */
1565 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
1566 pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
1568 pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n",
1569 bond_dev->name, slave_dev->name, bond_dev->name);
1572 pr_warning("%s: Warning: enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n",
1573 bond_dev->name, slave_dev->name,
1574 slave_dev->name, bond_dev->name);
1577 pr_debug("%s: ! NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
1581 * Old ifenslave binaries are no longer supported. These can
1582 * be identified with moderate accuracy by the state of the slave:
1583 * the current ifenslave will set the interface down prior to
1584 * enslaving it; the old ifenslave will not.
1586 if ((slave_dev->flags & IFF_UP)) {
1587 pr_err("%s is up. This may be due to an out of date ifenslave.\n",
1590 goto err_undo_flags;
1593 /* set bonding device ether type by slave - bonding netdevices are
1594 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
1595 * there is a need to override some of the type dependent attribs/funcs.
1597 * bond ether type mutual exclusion - don't allow slaves of dissimilar
1598 * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
1600 if (bond->slave_cnt == 0) {
1601 if (bond_dev->type != slave_dev->type) {
1602 pr_debug("%s: change device type from %d to %d\n",
1604 bond_dev->type, slave_dev->type);
1606 res = netdev_bonding_change(bond_dev,
1607 NETDEV_PRE_TYPE_CHANGE);
1608 res = notifier_to_errno(res);
1610 pr_err("%s: refused to change device type\n",
1613 goto err_undo_flags;
1616 /* Flush unicast and multicast addresses */
1617 dev_uc_flush(bond_dev);
1618 dev_mc_flush(bond_dev);
1620 if (slave_dev->type != ARPHRD_ETHER)
1621 bond_setup_by_slave(bond_dev, slave_dev);
1623 ether_setup(bond_dev);
1625 netdev_bonding_change(bond_dev,
1626 NETDEV_POST_TYPE_CHANGE);
1628 } else if (bond_dev->type != slave_dev->type) {
1629 pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n",
1631 slave_dev->type, bond_dev->type);
1633 goto err_undo_flags;
1636 if (slave_ops->ndo_set_mac_address == NULL) {
1637 if (bond->slave_cnt == 0) {
1638 pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.",
1640 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1641 } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
1642 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",
1645 goto err_undo_flags;
1649 call_netdevice_notifiers(NETDEV_JOIN, slave_dev);
1651 /* If this is the first slave, then we need to set the master's hardware
1652 * address to be the same as the slave's. */
1653 if (is_zero_ether_addr(bond->dev->dev_addr))
1654 memcpy(bond->dev->dev_addr, slave_dev->dev_addr,
1655 slave_dev->addr_len);
1658 new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL);
1661 goto err_undo_flags;
1665 * Set the new_slave's queue_id to be zero. Queue ID mapping
1666 * is set via sysfs or module option if desired.
1668 new_slave->queue_id = 0;
1670 /* Save slave's original mtu and then set it to match the bond */
1671 new_slave->original_mtu = slave_dev->mtu;
1672 res = dev_set_mtu(slave_dev, bond->dev->mtu);
1674 pr_debug("Error %d calling dev_set_mtu\n", res);
1679 * Save slave's original ("permanent") mac address for modes
1680 * that need it, and for restoring it upon release, and then
1681 * set it to the master's address
1683 memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN);
1685 if (!bond->params.fail_over_mac) {
1687 * Set slave to master's mac address. The application already
1688 * set the master's mac address to that of the first slave
1690 memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
1691 addr.sa_family = slave_dev->type;
1692 res = dev_set_mac_address(slave_dev, &addr);
1694 pr_debug("Error %d calling set_mac_address\n", res);
1695 goto err_restore_mtu;
1699 res = netdev_set_bond_master(slave_dev, bond_dev);
1701 pr_debug("Error %d calling netdev_set_bond_master\n", res);
1702 goto err_restore_mac;
1705 /* open the slave since the application closed it */
1706 res = dev_open(slave_dev);
1708 pr_debug("Opening slave %s failed\n", slave_dev->name);
1709 goto err_unset_master;
1712 new_slave->bond = bond;
1713 new_slave->dev = slave_dev;
1714 slave_dev->priv_flags |= IFF_BONDING;
1716 if (bond_is_lb(bond)) {
1717 /* bond_alb_init_slave() must be called before all other stages since
1718 * it might fail and we do not want to have to undo everything
1720 res = bond_alb_init_slave(bond, new_slave);
1725 /* If the mode USES_PRIMARY, then the new slave gets the
1726 * master's promisc (and mc) settings only if it becomes the
1727 * curr_active_slave, and that is taken care of later when calling
1728 * bond_change_active()
1730 if (!USES_PRIMARY(bond->params.mode)) {
1731 /* set promiscuity level to new slave */
1732 if (bond_dev->flags & IFF_PROMISC) {
1733 res = dev_set_promiscuity(slave_dev, 1);
1738 /* set allmulti level to new slave */
1739 if (bond_dev->flags & IFF_ALLMULTI) {
1740 res = dev_set_allmulti(slave_dev, 1);
1745 netif_addr_lock_bh(bond_dev);
1746 /* upload master's mc_list to new slave */
1747 netdev_for_each_mc_addr(ha, bond_dev)
1748 dev_mc_add(slave_dev, ha->addr);
1749 netif_addr_unlock_bh(bond_dev);
1752 if (bond->params.mode == BOND_MODE_8023AD) {
1753 /* add lacpdu mc addr to mc list */
1754 u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
1756 dev_mc_add(slave_dev, lacpdu_multicast);
1759 bond_add_vlans_on_slave(bond, slave_dev);
1761 write_lock_bh(&bond->lock);
1763 bond_attach_slave(bond, new_slave);
1765 new_slave->delay = 0;
1766 new_slave->link_failure_count = 0;
1768 write_unlock_bh(&bond->lock);
1770 bond_compute_features(bond);
1772 read_lock(&bond->lock);
1774 new_slave->last_arp_rx = jiffies;
1776 if (bond->params.miimon && !bond->params.use_carrier) {
1777 link_reporting = bond_check_dev_link(bond, slave_dev, 1);
1779 if ((link_reporting == -1) && !bond->params.arp_interval) {
1781 * miimon is set but a bonded network driver
1782 * does not support ETHTOOL/MII and
1783 * arp_interval is not set. Note: if
1784 * use_carrier is enabled, we will never go
1785 * here (because netif_carrier is always
1786 * supported); thus, we don't need to change
1787 * the messages for netif_carrier.
1789 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",
1790 bond_dev->name, slave_dev->name);
1791 } else if (link_reporting == -1) {
1792 /* unable get link status using mii/ethtool */
1793 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",
1794 bond_dev->name, slave_dev->name);
1798 /* check for initial state */
1799 if (!bond->params.miimon ||
1800 (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) {
1801 if (bond->params.updelay) {
1802 pr_debug("Initial state of slave_dev is BOND_LINK_BACK\n");
1803 new_slave->link = BOND_LINK_BACK;
1804 new_slave->delay = bond->params.updelay;
1806 pr_debug("Initial state of slave_dev is BOND_LINK_UP\n");
1807 new_slave->link = BOND_LINK_UP;
1809 new_slave->jiffies = jiffies;
1811 pr_debug("Initial state of slave_dev is BOND_LINK_DOWN\n");
1812 new_slave->link = BOND_LINK_DOWN;
1815 if (bond_update_speed_duplex(new_slave) &&
1816 (new_slave->link != BOND_LINK_DOWN)) {
1817 pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n",
1818 bond_dev->name, new_slave->dev->name);
1820 if (bond->params.mode == BOND_MODE_8023AD) {
1821 pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n",
1826 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) {
1827 /* if there is a primary slave, remember it */
1828 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
1829 bond->primary_slave = new_slave;
1830 bond->force_primary = true;
1834 write_lock_bh(&bond->curr_slave_lock);
1836 switch (bond->params.mode) {
1837 case BOND_MODE_ACTIVEBACKUP:
1838 bond_set_slave_inactive_flags(new_slave);
1839 bond_select_active_slave(bond);
1841 case BOND_MODE_8023AD:
1842 /* in 802.3ad mode, the internal mechanism
1843 * will activate the slaves in the selected
1846 bond_set_slave_inactive_flags(new_slave);
1847 /* if this is the first slave */
1848 if (bond->slave_cnt == 1) {
1849 SLAVE_AD_INFO(new_slave).id = 1;
1850 /* Initialize AD with the number of times that the AD timer is called in 1 second
1851 * can be called only after the mac address of the bond is set
1853 bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL,
1854 bond->params.lacp_fast);
1856 SLAVE_AD_INFO(new_slave).id =
1857 SLAVE_AD_INFO(new_slave->prev).id + 1;
1860 bond_3ad_bind_slave(new_slave);
1864 bond_set_active_slave(new_slave);
1865 bond_set_slave_inactive_flags(new_slave);
1866 bond_select_active_slave(bond);
1869 pr_debug("This slave is always active in trunk mode\n");
1871 /* always active in trunk mode */
1872 bond_set_active_slave(new_slave);
1874 /* In trunking mode there is little meaning to curr_active_slave
1875 * anyway (it holds no special properties of the bond device),
1876 * so we can change it without calling change_active_interface()
1878 if (!bond->curr_active_slave)
1879 bond->curr_active_slave = new_slave;
1882 } /* switch(bond_mode) */
1884 write_unlock_bh(&bond->curr_slave_lock);
1886 bond_set_carrier(bond);
1888 #ifdef CONFIG_NET_POLL_CONTROLLER
1889 slave_dev->npinfo = bond_netpoll_info(bond);
1890 if (slave_dev->npinfo) {
1891 if (slave_enable_netpoll(new_slave)) {
1892 read_unlock(&bond->lock);
1893 pr_info("Error, %s: master_dev is using netpoll, "
1894 "but new slave device does not support netpoll.\n",
1902 read_unlock(&bond->lock);
1904 res = bond_create_slave_symlinks(bond_dev, slave_dev);
1908 res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
1911 pr_debug("Error %d calling netdev_rx_handler_register\n", res);
1912 goto err_dest_symlinks;
1915 pr_info("%s: enslaving %s as a%s interface with a%s link.\n",
1916 bond_dev->name, slave_dev->name,
1917 bond_is_active_slave(new_slave) ? "n active" : " backup",
1918 new_slave->link != BOND_LINK_DOWN ? "n up" : " down");
1920 /* enslave is successful */
1923 /* Undo stages on error */
1925 bond_destroy_slave_symlinks(bond_dev, slave_dev);
1928 dev_close(slave_dev);
1931 netdev_set_bond_master(slave_dev, NULL);
1934 if (!bond->params.fail_over_mac) {
1935 /* XXX TODO - fom follow mode needs to change master's
1936 * MAC if this slave's MAC is in use by the bond, or at
1937 * least print a warning.
1939 memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN);
1940 addr.sa_family = slave_dev->type;
1941 dev_set_mac_address(slave_dev, &addr);
1945 dev_set_mtu(slave_dev, new_slave->original_mtu);
1951 bond_compute_features(bond);
1957 * Try to release the slave device <slave> from the bond device <master>
1958 * It is legal to access curr_active_slave without a lock because all the function
1961 * The rules for slave state should be:
1962 * for Active/Backup:
1963 * Active stays on all backups go down
1964 * for Bonded connections:
1965 * The first up interface should be left on and all others downed.
1967 int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1969 struct bonding *bond = netdev_priv(bond_dev);
1970 struct slave *slave, *oldcurrent;
1971 struct sockaddr addr;
1972 u32 old_features = bond_dev->features;
1974 /* slave is not a slave or master is not master of this slave */
1975 if (!(slave_dev->flags & IFF_SLAVE) ||
1976 (slave_dev->master != bond_dev)) {
1977 pr_err("%s: Error: cannot release %s.\n",
1978 bond_dev->name, slave_dev->name);
1983 netdev_bonding_change(bond_dev, NETDEV_RELEASE);
1984 write_lock_bh(&bond->lock);
1986 slave = bond_get_slave_by_dev(bond, slave_dev);
1988 /* not a slave of this bond */
1989 pr_info("%s: %s not enslaved\n",
1990 bond_dev->name, slave_dev->name);
1991 write_unlock_bh(&bond->lock);
1992 unblock_netpoll_tx();
1996 /* unregister rx_handler early so bond_handle_frame wouldn't be called
1997 * for this slave anymore.
1999 netdev_rx_handler_unregister(slave_dev);
2000 write_unlock_bh(&bond->lock);
2002 write_lock_bh(&bond->lock);
2004 if (!bond->params.fail_over_mac) {
2005 if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) &&
2006 bond->slave_cnt > 1)
2007 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",
2008 bond_dev->name, slave_dev->name,
2010 bond_dev->name, slave_dev->name);
2013 /* Inform AD package of unbinding of slave. */
2014 if (bond->params.mode == BOND_MODE_8023AD) {
2015 /* must be called before the slave is
2016 * detached from the list
2018 bond_3ad_unbind_slave(slave);
2021 pr_info("%s: releasing %s interface %s\n",
2023 bond_is_active_slave(slave) ? "active" : "backup",
2026 oldcurrent = bond->curr_active_slave;
2028 bond->current_arp_slave = NULL;
2030 /* release the slave from its bond */
2031 bond_detach_slave(bond, slave);
2033 if (bond->primary_slave == slave)
2034 bond->primary_slave = NULL;
2036 if (oldcurrent == slave)
2037 bond_change_active_slave(bond, NULL);
2039 if (bond_is_lb(bond)) {
2040 /* Must be called only after the slave has been
2041 * detached from the list and the curr_active_slave
2042 * has been cleared (if our_slave == old_current),
2043 * but before a new active slave is selected.
2045 write_unlock_bh(&bond->lock);
2046 bond_alb_deinit_slave(bond, slave);
2047 write_lock_bh(&bond->lock);
2050 if (oldcurrent == slave) {
2052 * Note that we hold RTNL over this sequence, so there
2053 * is no concern that another slave add/remove event
2056 write_unlock_bh(&bond->lock);
2057 read_lock(&bond->lock);
2058 write_lock_bh(&bond->curr_slave_lock);
2060 bond_select_active_slave(bond);
2062 write_unlock_bh(&bond->curr_slave_lock);
2063 read_unlock(&bond->lock);
2064 write_lock_bh(&bond->lock);
2067 if (bond->slave_cnt == 0) {
2068 bond_set_carrier(bond);
2070 /* if the last slave was removed, zero the mac address
2071 * of the master so it will be set by the application
2072 * to the mac address of the first slave
2074 memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
2077 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
2078 bond_dev->name, bond_dev->name);
2079 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
2084 write_unlock_bh(&bond->lock);
2085 unblock_netpoll_tx();
2087 bond_compute_features(bond);
2088 if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
2089 (old_features & NETIF_F_VLAN_CHALLENGED))
2090 pr_info("%s: last VLAN challenged slave %s left bond %s. VLAN blocking is removed\n",
2091 bond_dev->name, slave_dev->name, bond_dev->name);
2093 /* must do this from outside any spinlocks */
2094 bond_destroy_slave_symlinks(bond_dev, slave_dev);
2096 bond_del_vlans_from_slave(bond, slave_dev);
2098 /* If the mode USES_PRIMARY, then we should only remove its
2099 * promisc and mc settings if it was the curr_active_slave, but that was
2100 * already taken care of above when we detached the slave
2102 if (!USES_PRIMARY(bond->params.mode)) {
2103 /* unset promiscuity level from slave */
2104 if (bond_dev->flags & IFF_PROMISC)
2105 dev_set_promiscuity(slave_dev, -1);
2107 /* unset allmulti level from slave */
2108 if (bond_dev->flags & IFF_ALLMULTI)
2109 dev_set_allmulti(slave_dev, -1);
2111 /* flush master's mc_list from slave */
2112 netif_addr_lock_bh(bond_dev);
2113 bond_mc_list_flush(bond_dev, slave_dev);
2114 netif_addr_unlock_bh(bond_dev);
2117 netdev_set_bond_master(slave_dev, NULL);
2119 slave_disable_netpoll(slave);
2121 /* close slave before restoring its mac address */
2122 dev_close(slave_dev);
2124 if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
2125 /* restore original ("permanent") mac address */
2126 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
2127 addr.sa_family = slave_dev->type;
2128 dev_set_mac_address(slave_dev, &addr);
2131 dev_set_mtu(slave_dev, slave->original_mtu);
2133 slave_dev->priv_flags &= ~IFF_BONDING;
2137 return 0; /* deletion OK */
2141 * First release a slave and then destroy the bond if no more slaves are left.
2142 * Must be under rtnl_lock when this function is called.
2144 static int bond_release_and_destroy(struct net_device *bond_dev,
2145 struct net_device *slave_dev)
2147 struct bonding *bond = netdev_priv(bond_dev);
2150 ret = bond_release(bond_dev, slave_dev);
2151 if ((ret == 0) && (bond->slave_cnt == 0)) {
2152 bond_dev->priv_flags |= IFF_DISABLE_NETPOLL;
2153 pr_info("%s: destroying bond %s.\n",
2154 bond_dev->name, bond_dev->name);
2155 unregister_netdevice(bond_dev);
2161 * This function releases all slaves.
2163 static int bond_release_all(struct net_device *bond_dev)
2165 struct bonding *bond = netdev_priv(bond_dev);
2166 struct slave *slave;
2167 struct net_device *slave_dev;
2168 struct sockaddr addr;
2170 write_lock_bh(&bond->lock);
2172 netif_carrier_off(bond_dev);
2174 if (bond->slave_cnt == 0)
2177 bond->current_arp_slave = NULL;
2178 bond->primary_slave = NULL;
2179 bond_change_active_slave(bond, NULL);
2181 while ((slave = bond->first_slave) != NULL) {
2182 /* Inform AD package of unbinding of slave
2183 * before slave is detached from the list.
2185 if (bond->params.mode == BOND_MODE_8023AD)
2186 bond_3ad_unbind_slave(slave);
2188 slave_dev = slave->dev;
2189 bond_detach_slave(bond, slave);
2191 /* now that the slave is detached, unlock and perform
2192 * all the undo steps that should not be called from
2195 write_unlock_bh(&bond->lock);
2197 /* unregister rx_handler early so bond_handle_frame wouldn't
2198 * be called for this slave anymore.
2200 netdev_rx_handler_unregister(slave_dev);
2203 if (bond_is_lb(bond)) {
2204 /* must be called only after the slave
2205 * has been detached from the list
2207 bond_alb_deinit_slave(bond, slave);
2210 bond_destroy_slave_symlinks(bond_dev, slave_dev);
2211 bond_del_vlans_from_slave(bond, slave_dev);
2213 /* If the mode USES_PRIMARY, then we should only remove its
2214 * promisc and mc settings if it was the curr_active_slave, but that was
2215 * already taken care of above when we detached the slave
2217 if (!USES_PRIMARY(bond->params.mode)) {
2218 /* unset promiscuity level from slave */
2219 if (bond_dev->flags & IFF_PROMISC)
2220 dev_set_promiscuity(slave_dev, -1);
2222 /* unset allmulti level from slave */
2223 if (bond_dev->flags & IFF_ALLMULTI)
2224 dev_set_allmulti(slave_dev, -1);
2226 /* flush master's mc_list from slave */
2227 netif_addr_lock_bh(bond_dev);
2228 bond_mc_list_flush(bond_dev, slave_dev);
2229 netif_addr_unlock_bh(bond_dev);
2232 netdev_set_bond_master(slave_dev, NULL);
2234 slave_disable_netpoll(slave);
2236 /* close slave before restoring its mac address */
2237 dev_close(slave_dev);
2239 if (!bond->params.fail_over_mac) {
2240 /* restore original ("permanent") mac address*/
2241 memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN);
2242 addr.sa_family = slave_dev->type;
2243 dev_set_mac_address(slave_dev, &addr);
2248 /* re-acquire the lock before getting the next slave */
2249 write_lock_bh(&bond->lock);
2252 /* zero the mac address of the master so it will be
2253 * set by the application to the mac address of the
2256 memset(bond_dev->dev_addr, 0, bond_dev->addr_len);
2259 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
2260 bond_dev->name, bond_dev->name);
2261 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
2265 pr_info("%s: released all slaves\n", bond_dev->name);
2268 write_unlock_bh(&bond->lock);
2270 bond_compute_features(bond);
2276 * This function changes the active slave to slave <slave_dev>.
2277 * It returns -EINVAL in the following cases.
2278 * - <slave_dev> is not found in the list.
2279 * - There is not active slave now.
2280 * - <slave_dev> is already active.
2281 * - The link state of <slave_dev> is not BOND_LINK_UP.
2282 * - <slave_dev> is not running.
2283 * In these cases, this function does nothing.
2284 * In the other cases, current_slave pointer is changed and 0 is returned.
2286 static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev)
2288 struct bonding *bond = netdev_priv(bond_dev);
2289 struct slave *old_active = NULL;
2290 struct slave *new_active = NULL;
2293 if (!USES_PRIMARY(bond->params.mode))
2296 /* Verify that master_dev is indeed the master of slave_dev */
2297 if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != bond_dev))
2300 read_lock(&bond->lock);
2302 read_lock(&bond->curr_slave_lock);
2303 old_active = bond->curr_active_slave;
2304 read_unlock(&bond->curr_slave_lock);
2306 new_active = bond_get_slave_by_dev(bond, slave_dev);
2309 * Changing to the current active: do nothing; return success.
2311 if (new_active && (new_active == old_active)) {
2312 read_unlock(&bond->lock);
2318 (new_active->link == BOND_LINK_UP) &&
2319 IS_UP(new_active->dev)) {
2321 write_lock_bh(&bond->curr_slave_lock);
2322 bond_change_active_slave(bond, new_active);
2323 write_unlock_bh(&bond->curr_slave_lock);
2324 unblock_netpoll_tx();
2328 read_unlock(&bond->lock);
2333 static int bond_info_query(struct net_device *bond_dev, struct ifbond *info)
2335 struct bonding *bond = netdev_priv(bond_dev);
2337 info->bond_mode = bond->params.mode;
2338 info->miimon = bond->params.miimon;
2340 read_lock(&bond->lock);
2341 info->num_slaves = bond->slave_cnt;
2342 read_unlock(&bond->lock);
2347 static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info)
2349 struct bonding *bond = netdev_priv(bond_dev);
2350 struct slave *slave;
2351 int i, res = -ENODEV;
2353 read_lock(&bond->lock);
2355 bond_for_each_slave(bond, slave, i) {
2356 if (i == (int)info->slave_id) {
2358 strcpy(info->slave_name, slave->dev->name);
2359 info->link = slave->link;
2360 info->state = bond_slave_state(slave);
2361 info->link_failure_count = slave->link_failure_count;
2366 read_unlock(&bond->lock);
2371 /*-------------------------------- Monitoring -------------------------------*/
2374 static int bond_miimon_inspect(struct bonding *bond)
2376 struct slave *slave;
2377 int i, link_state, commit = 0;
2378 bool ignore_updelay;
2380 ignore_updelay = !bond->curr_active_slave ? true : false;
2382 bond_for_each_slave(bond, slave, i) {
2383 slave->new_link = BOND_LINK_NOCHANGE;
2385 link_state = bond_check_dev_link(bond, slave->dev, 0);
2387 switch (slave->link) {
2392 slave->link = BOND_LINK_FAIL;
2393 slave->delay = bond->params.downdelay;
2395 pr_info("%s: link status down for %sinterface %s, disabling it in %d ms.\n",
2397 (bond->params.mode ==
2398 BOND_MODE_ACTIVEBACKUP) ?
2399 (bond_is_active_slave(slave) ?
2400 "active " : "backup ") : "",
2402 bond->params.downdelay * bond->params.miimon);
2405 case BOND_LINK_FAIL:
2408 * recovered before downdelay expired
2410 slave->link = BOND_LINK_UP;
2411 slave->jiffies = jiffies;
2412 pr_info("%s: link status up again after %d ms for interface %s.\n",
2414 (bond->params.downdelay - slave->delay) *
2415 bond->params.miimon,
2420 if (slave->delay <= 0) {
2421 slave->new_link = BOND_LINK_DOWN;
2429 case BOND_LINK_DOWN:
2433 slave->link = BOND_LINK_BACK;
2434 slave->delay = bond->params.updelay;
2437 pr_info("%s: link status up for interface %s, enabling it in %d ms.\n",
2438 bond->dev->name, slave->dev->name,
2439 ignore_updelay ? 0 :
2440 bond->params.updelay *
2441 bond->params.miimon);
2444 case BOND_LINK_BACK:
2446 slave->link = BOND_LINK_DOWN;
2447 pr_info("%s: link status down again after %d ms for interface %s.\n",
2449 (bond->params.updelay - slave->delay) *
2450 bond->params.miimon,
2459 if (slave->delay <= 0) {
2460 slave->new_link = BOND_LINK_UP;
2462 ignore_updelay = false;
2474 static void bond_miimon_commit(struct bonding *bond)
2476 struct slave *slave;
2479 bond_for_each_slave(bond, slave, i) {
2480 switch (slave->new_link) {
2481 case BOND_LINK_NOCHANGE:
2485 slave->link = BOND_LINK_UP;
2486 slave->jiffies = jiffies;
2488 if (bond->params.mode == BOND_MODE_8023AD) {
2489 /* prevent it from being the active one */
2490 bond_set_backup_slave(slave);
2491 } else if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) {
2492 /* make it immediately active */
2493 bond_set_active_slave(slave);
2494 } else if (slave != bond->primary_slave) {
2495 /* prevent it from being the active one */
2496 bond_set_backup_slave(slave);
2499 bond_update_speed_duplex(slave);
2501 pr_info("%s: link status definitely up for interface %s, %u Mbps %s duplex.\n",
2502 bond->dev->name, slave->dev->name,
2503 slave->speed, slave->duplex ? "full" : "half");
2505 /* notify ad that the link status has changed */
2506 if (bond->params.mode == BOND_MODE_8023AD)
2507 bond_3ad_handle_link_change(slave, BOND_LINK_UP);
2509 if (bond_is_lb(bond))
2510 bond_alb_handle_link_change(bond, slave,
2513 if (!bond->curr_active_slave ||
2514 (slave == bond->primary_slave))
2519 case BOND_LINK_DOWN:
2520 if (slave->link_failure_count < UINT_MAX)
2521 slave->link_failure_count++;
2523 slave->link = BOND_LINK_DOWN;
2525 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP ||
2526 bond->params.mode == BOND_MODE_8023AD)
2527 bond_set_slave_inactive_flags(slave);
2529 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2530 bond->dev->name, slave->dev->name);
2532 if (bond->params.mode == BOND_MODE_8023AD)
2533 bond_3ad_handle_link_change(slave,
2536 if (bond_is_lb(bond))
2537 bond_alb_handle_link_change(bond, slave,
2540 if (slave == bond->curr_active_slave)
2546 pr_err("%s: invalid new link %d on slave %s\n",
2547 bond->dev->name, slave->new_link,
2549 slave->new_link = BOND_LINK_NOCHANGE;
2557 write_lock_bh(&bond->curr_slave_lock);
2558 bond_select_active_slave(bond);
2559 write_unlock_bh(&bond->curr_slave_lock);
2560 unblock_netpoll_tx();
2563 bond_set_carrier(bond);
2569 * Really a wrapper that splits the mii monitor into two phases: an
2570 * inspection, then (if inspection indicates something needs to be done)
2571 * an acquisition of appropriate locks followed by a commit phase to
2572 * implement whatever link state changes are indicated.
2574 void bond_mii_monitor(struct work_struct *work)
2576 struct bonding *bond = container_of(work, struct bonding,
2578 bool should_notify_peers = false;
2580 read_lock(&bond->lock);
2581 if (bond->kill_timers)
2584 if (bond->slave_cnt == 0)
2587 should_notify_peers = bond_should_notify_peers(bond);
2589 if (bond_miimon_inspect(bond)) {
2590 read_unlock(&bond->lock);
2592 read_lock(&bond->lock);
2594 bond_miimon_commit(bond);
2596 read_unlock(&bond->lock);
2597 rtnl_unlock(); /* might sleep, hold no other locks */
2598 read_lock(&bond->lock);
2602 if (bond->params.miimon)
2603 queue_delayed_work(bond->wq, &bond->mii_work,
2604 msecs_to_jiffies(bond->params.miimon));
2606 read_unlock(&bond->lock);
2608 if (should_notify_peers) {
2610 netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS);
2615 static __be32 bond_glean_dev_ip(struct net_device *dev)
2617 struct in_device *idev;
2618 struct in_ifaddr *ifa;
2625 idev = __in_dev_get_rcu(dev);
2629 ifa = idev->ifa_list;
2633 addr = ifa->ifa_local;
2639 static int bond_has_this_ip(struct bonding *bond, __be32 ip)
2641 struct vlan_entry *vlan;
2643 if (ip == bond->master_ip)
2646 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2647 if (ip == vlan->vlan_ip)
2655 * We go to the (large) trouble of VLAN tagging ARP frames because
2656 * switches in VLAN mode (especially if ports are configured as
2657 * "native" to a VLAN) might not pass non-tagged frames.
2659 static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_ip, __be32 src_ip, unsigned short vlan_id)
2661 struct sk_buff *skb;
2663 pr_debug("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
2664 slave_dev->name, dest_ip, src_ip, vlan_id);
2666 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
2667 NULL, slave_dev->dev_addr, NULL);
2670 pr_err("ARP packet allocation failed\n");
2674 skb = vlan_put_tag(skb, vlan_id);
2676 pr_err("failed to insert VLAN tag\n");
2684 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2687 __be32 *targets = bond->params.arp_targets;
2688 struct vlan_entry *vlan;
2689 struct net_device *vlan_dev;
2692 for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
2695 pr_debug("basa: target %x\n", targets[i]);
2697 pr_debug("basa: empty vlan: arp_send\n");
2698 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2699 bond->master_ip, 0);
2704 * If VLANs are configured, we do a route lookup to
2705 * determine which VLAN interface would be used, so we
2706 * can tag the ARP with the proper VLAN tag.
2708 rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
2711 if (net_ratelimit()) {
2712 pr_warning("%s: no route to arp_ip_target %pI4\n",
2713 bond->dev->name, &targets[i]);
2719 * This target is not on a VLAN
2721 if (rt->dst.dev == bond->dev) {
2723 pr_debug("basa: rtdev == bond->dev: arp_send\n");
2724 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2725 bond->master_ip, 0);
2730 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
2731 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
2732 if (vlan_dev == rt->dst.dev) {
2733 vlan_id = vlan->vlan_id;
2734 pr_debug("basa: vlan match on %s %d\n",
2735 vlan_dev->name, vlan_id);
2742 bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
2743 vlan->vlan_ip, vlan_id);
2747 if (net_ratelimit()) {
2748 pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
2749 bond->dev->name, &targets[i],
2750 rt->dst.dev ? rt->dst.dev->name : "NULL");
2756 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
2759 __be32 *targets = bond->params.arp_targets;
2761 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
2762 pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n",
2763 &sip, &tip, i, &targets[i],
2764 bond_has_this_ip(bond, tip));
2765 if (sip == targets[i]) {
2766 if (bond_has_this_ip(bond, tip))
2767 slave->last_arp_rx = jiffies;
2773 static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond,
2774 struct slave *slave)
2777 unsigned char *arp_ptr;
2780 if (skb->protocol != __cpu_to_be16(ETH_P_ARP))
2783 read_lock(&bond->lock);
2785 pr_debug("bond_arp_rcv: bond %s skb->dev %s\n",
2786 bond->dev->name, skb->dev->name);
2788 if (!pskb_may_pull(skb, arp_hdr_len(bond->dev)))
2792 if (arp->ar_hln != bond->dev->addr_len ||
2793 skb->pkt_type == PACKET_OTHERHOST ||
2794 skb->pkt_type == PACKET_LOOPBACK ||
2795 arp->ar_hrd != htons(ARPHRD_ETHER) ||
2796 arp->ar_pro != htons(ETH_P_IP) ||
2800 arp_ptr = (unsigned char *)(arp + 1);
2801 arp_ptr += bond->dev->addr_len;
2802 memcpy(&sip, arp_ptr, 4);
2803 arp_ptr += 4 + bond->dev->addr_len;
2804 memcpy(&tip, arp_ptr, 4);
2806 pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2807 bond->dev->name, slave->dev->name, bond_slave_state(slave),
2808 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2812 * Backup slaves won't see the ARP reply, but do come through
2813 * here for each ARP probe (so we swap the sip/tip to validate
2814 * the probe). In a "redundant switch, common router" type of
2815 * configuration, the ARP probe will (hopefully) travel from
2816 * the active, through one switch, the router, then the other
2817 * switch before reaching the backup.
2819 if (bond_is_active_slave(slave))
2820 bond_validate_arp(bond, slave, sip, tip);
2822 bond_validate_arp(bond, slave, tip, sip);
2825 read_unlock(&bond->lock);
2829 * this function is called regularly to monitor each slave's link
2830 * ensuring that traffic is being sent and received when arp monitoring
2831 * is used in load-balancing mode. if the adapter has been dormant, then an
2832 * arp is transmitted to generate traffic. see activebackup_arp_monitor for
2833 * arp monitoring in active backup mode.
2835 void bond_loadbalance_arp_mon(struct work_struct *work)
2837 struct bonding *bond = container_of(work, struct bonding,
2839 struct slave *slave, *oldcurrent;
2840 int do_failover = 0;
2844 read_lock(&bond->lock);
2846 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
2848 if (bond->kill_timers)
2851 if (bond->slave_cnt == 0)
2854 read_lock(&bond->curr_slave_lock);
2855 oldcurrent = bond->curr_active_slave;
2856 read_unlock(&bond->curr_slave_lock);
2858 /* see if any of the previous devices are up now (i.e. they have
2859 * xmt and rcv traffic). the curr_active_slave does not come into
2860 * the picture unless it is null. also, slave->jiffies is not needed
2861 * here because we send an arp on each slave and give a slave as
2862 * long as it needs to get the tx/rx within the delta.
2863 * TODO: what about up/down delay in arp mode? it wasn't here before
2866 bond_for_each_slave(bond, slave, i) {
2867 unsigned long trans_start = dev_trans_start(slave->dev);
2869 if (slave->link != BOND_LINK_UP) {
2870 if (time_in_range(jiffies,
2871 trans_start - delta_in_ticks,
2872 trans_start + delta_in_ticks) &&
2873 time_in_range(jiffies,
2874 slave->dev->last_rx - delta_in_ticks,
2875 slave->dev->last_rx + delta_in_ticks)) {
2877 slave->link = BOND_LINK_UP;
2878 bond_set_active_slave(slave);
2880 /* primary_slave has no meaning in round-robin
2881 * mode. the window of a slave being up and
2882 * curr_active_slave being null after enslaving
2886 pr_info("%s: link status definitely up for interface %s, ",
2891 pr_info("%s: interface %s is now up\n",
2897 /* slave->link == BOND_LINK_UP */
2899 /* not all switches will respond to an arp request
2900 * when the source ip is 0, so don't take the link down
2901 * if we don't know our ip yet
2903 if (!time_in_range(jiffies,
2904 trans_start - delta_in_ticks,
2905 trans_start + 2 * delta_in_ticks) ||
2906 !time_in_range(jiffies,
2907 slave->dev->last_rx - delta_in_ticks,
2908 slave->dev->last_rx + 2 * delta_in_ticks)) {
2910 slave->link = BOND_LINK_DOWN;
2911 bond_set_backup_slave(slave);
2913 if (slave->link_failure_count < UINT_MAX)
2914 slave->link_failure_count++;
2916 pr_info("%s: interface %s is now down.\n",
2920 if (slave == oldcurrent)
2925 /* note: if switch is in round-robin mode, all links
2926 * must tx arp to ensure all links rx an arp - otherwise
2927 * links may oscillate or not come up at all; if switch is
2928 * in something like xor mode, there is nothing we can
2929 * do - all replies will be rx'ed on same link causing slaves
2930 * to be unstable during low/no traffic periods
2932 if (IS_UP(slave->dev))
2933 bond_arp_send_all(bond, slave);
2938 write_lock_bh(&bond->curr_slave_lock);
2940 bond_select_active_slave(bond);
2942 write_unlock_bh(&bond->curr_slave_lock);
2943 unblock_netpoll_tx();
2947 if (bond->params.arp_interval)
2948 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
2950 read_unlock(&bond->lock);
2954 * Called to inspect slaves for active-backup mode ARP monitor link state
2955 * changes. Sets new_link in slaves to specify what action should take
2956 * place for the slave. Returns 0 if no changes are found, >0 if changes
2957 * to link states must be committed.
2959 * Called with bond->lock held for read.
2961 static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks)
2963 struct slave *slave;
2965 unsigned long trans_start;
2967 bond_for_each_slave(bond, slave, i) {
2968 slave->new_link = BOND_LINK_NOCHANGE;
2970 if (slave->link != BOND_LINK_UP) {
2971 if (time_in_range(jiffies,
2972 slave_last_rx(bond, slave) - delta_in_ticks,
2973 slave_last_rx(bond, slave) + delta_in_ticks)) {
2975 slave->new_link = BOND_LINK_UP;
2983 * Give slaves 2*delta after being enslaved or made
2984 * active. This avoids bouncing, as the last receive
2985 * times need a full ARP monitor cycle to be updated.
2987 if (time_in_range(jiffies,
2988 slave->jiffies - delta_in_ticks,
2989 slave->jiffies + 2 * delta_in_ticks))
2993 * Backup slave is down if:
2994 * - No current_arp_slave AND
2995 * - more than 3*delta since last receive AND
2996 * - the bond has an IP address
2998 * Note: a non-null current_arp_slave indicates
2999 * the curr_active_slave went down and we are
3000 * searching for a new one; under this condition
3001 * we only take the curr_active_slave down - this
3002 * gives each slave a chance to tx/rx traffic
3003 * before being taken out
3005 if (!bond_is_active_slave(slave) &&
3006 !bond->current_arp_slave &&
3007 !time_in_range(jiffies,
3008 slave_last_rx(bond, slave) - delta_in_ticks,
3009 slave_last_rx(bond, slave) + 3 * delta_in_ticks)) {
3011 slave->new_link = BOND_LINK_DOWN;
3016 * Active slave is down if:
3017 * - more than 2*delta since transmitting OR
3018 * - (more than 2*delta since receive AND
3019 * the bond has an IP address)
3021 trans_start = dev_trans_start(slave->dev);
3022 if (bond_is_active_slave(slave) &&
3023 (!time_in_range(jiffies,
3024 trans_start - delta_in_ticks,
3025 trans_start + 2 * delta_in_ticks) ||
3026 !time_in_range(jiffies,
3027 slave_last_rx(bond, slave) - delta_in_ticks,
3028 slave_last_rx(bond, slave) + 2 * delta_in_ticks))) {
3030 slave->new_link = BOND_LINK_DOWN;
3039 * Called to commit link state changes noted by inspection step of
3040 * active-backup mode ARP monitor.
3042 * Called with RTNL and bond->lock for read.
3044 static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
3046 struct slave *slave;
3048 unsigned long trans_start;
3050 bond_for_each_slave(bond, slave, i) {
3051 switch (slave->new_link) {
3052 case BOND_LINK_NOCHANGE:
3056 trans_start = dev_trans_start(slave->dev);
3057 if ((!bond->curr_active_slave &&
3058 time_in_range(jiffies,
3059 trans_start - delta_in_ticks,
3060 trans_start + delta_in_ticks)) ||
3061 bond->curr_active_slave != slave) {
3062 slave->link = BOND_LINK_UP;
3063 bond->current_arp_slave = NULL;
3065 pr_info("%s: link status definitely up for interface %s.\n",
3066 bond->dev->name, slave->dev->name);
3068 if (!bond->curr_active_slave ||
3069 (slave == bond->primary_slave))
3076 case BOND_LINK_DOWN:
3077 if (slave->link_failure_count < UINT_MAX)
3078 slave->link_failure_count++;
3080 slave->link = BOND_LINK_DOWN;
3081 bond_set_slave_inactive_flags(slave);
3083 pr_info("%s: link status definitely down for interface %s, disabling it\n",
3084 bond->dev->name, slave->dev->name);
3086 if (slave == bond->curr_active_slave) {
3087 bond->current_arp_slave = NULL;
3094 pr_err("%s: impossible: new_link %d on slave %s\n",
3095 bond->dev->name, slave->new_link,
3103 write_lock_bh(&bond->curr_slave_lock);
3104 bond_select_active_slave(bond);
3105 write_unlock_bh(&bond->curr_slave_lock);
3106 unblock_netpoll_tx();
3109 bond_set_carrier(bond);
3113 * Send ARP probes for active-backup mode ARP monitor.
3115 * Called with bond->lock held for read.
3117 static void bond_ab_arp_probe(struct bonding *bond)
3119 struct slave *slave;
3122 read_lock(&bond->curr_slave_lock);
3124 if (bond->current_arp_slave && bond->curr_active_slave)
3125 pr_info("PROBE: c_arp %s && cas %s BAD\n",
3126 bond->current_arp_slave->dev->name,
3127 bond->curr_active_slave->dev->name);
3129 if (bond->curr_active_slave) {
3130 bond_arp_send_all(bond, bond->curr_active_slave);
3131 read_unlock(&bond->curr_slave_lock);
3135 read_unlock(&bond->curr_slave_lock);
3137 /* if we don't have a curr_active_slave, search for the next available
3138 * backup slave from the current_arp_slave and make it the candidate
3139 * for becoming the curr_active_slave
3142 if (!bond->current_arp_slave) {
3143 bond->current_arp_slave = bond->first_slave;
3144 if (!bond->current_arp_slave)
3148 bond_set_slave_inactive_flags(bond->current_arp_slave);
3150 /* search for next candidate */
3151 bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave->next) {
3152 if (IS_UP(slave->dev)) {
3153 slave->link = BOND_LINK_BACK;
3154 bond_set_slave_active_flags(slave);
3155 bond_arp_send_all(bond, slave);
3156 slave->jiffies = jiffies;
3157 bond->current_arp_slave = slave;
3161 /* if the link state is up at this point, we
3162 * mark it down - this can happen if we have
3163 * simultaneous link failures and
3164 * reselect_active_interface doesn't make this
3165 * one the current slave so it is still marked
3166 * up when it is actually down
3168 if (slave->link == BOND_LINK_UP) {
3169 slave->link = BOND_LINK_DOWN;
3170 if (slave->link_failure_count < UINT_MAX)
3171 slave->link_failure_count++;
3173 bond_set_slave_inactive_flags(slave);
3175 pr_info("%s: backup interface %s is now down.\n",
3176 bond->dev->name, slave->dev->name);
3181 void bond_activebackup_arp_mon(struct work_struct *work)
3183 struct bonding *bond = container_of(work, struct bonding,
3185 bool should_notify_peers = false;
3188 read_lock(&bond->lock);
3190 if (bond->kill_timers)
3193 delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
3195 if (bond->slave_cnt == 0)
3198 should_notify_peers = bond_should_notify_peers(bond);
3200 if (bond_ab_arp_inspect(bond, delta_in_ticks)) {
3201 read_unlock(&bond->lock);
3203 read_lock(&bond->lock);
3205 bond_ab_arp_commit(bond, delta_in_ticks);
3207 read_unlock(&bond->lock);
3209 read_lock(&bond->lock);
3212 bond_ab_arp_probe(bond);
3215 if (bond->params.arp_interval)
3216 queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
3218 read_unlock(&bond->lock);
3220 if (should_notify_peers) {
3222 netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS);
3227 /*-------------------------- netdev event handling --------------------------*/
3230 * Change device name
3232 static int bond_event_changename(struct bonding *bond)
3234 bond_remove_proc_entry(bond);
3235 bond_create_proc_entry(bond);
3237 bond_debug_reregister(bond);
3242 static int bond_master_netdev_event(unsigned long event,
3243 struct net_device *bond_dev)
3245 struct bonding *event_bond = netdev_priv(bond_dev);
3248 case NETDEV_CHANGENAME:
3249 return bond_event_changename(event_bond);
3257 static int bond_slave_netdev_event(unsigned long event,
3258 struct net_device *slave_dev)
3260 struct net_device *bond_dev = slave_dev->master;
3261 struct bonding *bond = netdev_priv(bond_dev);
3264 case NETDEV_UNREGISTER:
3266 if (bond->setup_by_slave)
3267 bond_release_and_destroy(bond_dev, slave_dev);
3269 bond_release(bond_dev, slave_dev);
3273 if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) {
3274 struct slave *slave;
3276 slave = bond_get_slave_by_dev(bond, slave_dev);
3278 u32 old_speed = slave->speed;
3279 u8 old_duplex = slave->duplex;
3281 bond_update_speed_duplex(slave);
3283 if (bond_is_lb(bond))
3286 if (old_speed != slave->speed)
3287 bond_3ad_adapter_speed_changed(slave);
3288 if (old_duplex != slave->duplex)
3289 bond_3ad_adapter_duplex_changed(slave);
3296 * ... Or is it this?
3299 case NETDEV_CHANGEMTU:
3301 * TODO: Should slaves be allowed to
3302 * independently alter their MTU? For
3303 * an active-backup bond, slaves need
3304 * not be the same type of device, so
3305 * MTUs may vary. For other modes,
3306 * slaves arguably should have the
3307 * same MTUs. To do this, we'd need to
3308 * take over the slave's change_mtu
3309 * function for the duration of their
3313 case NETDEV_CHANGENAME:
3315 * TODO: handle changing the primary's name
3318 case NETDEV_FEAT_CHANGE:
3319 bond_compute_features(bond);
3329 * bond_netdev_event: handle netdev notifier chain events.
3331 * This function receives events for the netdev chain. The caller (an
3332 * ioctl handler calling blocking_notifier_call_chain) holds the necessary
3333 * locks for us to safely manipulate the slave devices (RTNL lock,
3336 static int bond_netdev_event(struct notifier_block *this,
3337 unsigned long event, void *ptr)
3339 struct net_device *event_dev = (struct net_device *)ptr;
3341 pr_debug("event_dev: %s, event: %lx\n",
3342 event_dev ? event_dev->name : "None",
3345 if (!(event_dev->priv_flags & IFF_BONDING))
3348 if (event_dev->flags & IFF_MASTER) {
3349 pr_debug("IFF_MASTER\n");
3350 return bond_master_netdev_event(event, event_dev);
3353 if (event_dev->flags & IFF_SLAVE) {
3354 pr_debug("IFF_SLAVE\n");
3355 return bond_slave_netdev_event(event, event_dev);
3362 * bond_inetaddr_event: handle inetaddr notifier chain events.
3364 * We keep track of device IPs primarily to use as source addresses in
3365 * ARP monitor probes (rather than spewing out broadcasts all the time).
3367 * We track one IP for the main device (if it has one), plus one per VLAN.
3369 static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr)
3371 struct in_ifaddr *ifa = ptr;
3372 struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
3373 struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id);
3374 struct bonding *bond;
3375 struct vlan_entry *vlan;
3377 list_for_each_entry(bond, &bn->dev_list, bond_list) {
3378 if (bond->dev == event_dev) {
3381 bond->master_ip = ifa->ifa_local;
3384 bond->master_ip = bond_glean_dev_ip(bond->dev);
3391 list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
3394 vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id);
3395 if (vlan_dev == event_dev) {
3398 vlan->vlan_ip = ifa->ifa_local;
3402 bond_glean_dev_ip(vlan_dev);
3413 static struct notifier_block bond_netdev_notifier = {
3414 .notifier_call = bond_netdev_event,
3417 static struct notifier_block bond_inetaddr_notifier = {
3418 .notifier_call = bond_inetaddr_event,
3421 /*---------------------------- Hashing Policies -----------------------------*/
3424 * Hash for the output device based upon layer 2 and layer 3 data. If
3425 * the packet is not IP mimic bond_xmit_hash_policy_l2()
3427 static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count)
3429 struct ethhdr *data = (struct ethhdr *)skb->data;
3430 struct iphdr *iph = ip_hdr(skb);
3432 if (skb->protocol == htons(ETH_P_IP)) {
3433 return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^
3434 (data->h_dest[5] ^ data->h_source[5])) % count;
3437 return (data->h_dest[5] ^ data->h_source[5]) % count;
3441 * Hash for the output device based upon layer 3 and layer 4 data. If
3442 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3443 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3445 static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count)
3447 struct ethhdr *data = (struct ethhdr *)skb->data;
3448 struct iphdr *iph = ip_hdr(skb);
3449 __be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl);
3452 if (skb->protocol == htons(ETH_P_IP)) {
3453 if (!(iph->frag_off & htons(IP_MF|IP_OFFSET)) &&
3454 (iph->protocol == IPPROTO_TCP ||
3455 iph->protocol == IPPROTO_UDP)) {
3456 layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1)));
3458 return (layer4_xor ^
3459 ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count;
3463 return (data->h_dest[5] ^ data->h_source[5]) % count;
3467 * Hash for the output device based upon layer 2 data
3469 static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count)
3471 struct ethhdr *data = (struct ethhdr *)skb->data;
3473 return (data->h_dest[5] ^ data->h_source[5]) % count;
3476 /*-------------------------- Device entry points ----------------------------*/
3478 static int bond_open(struct net_device *bond_dev)
3480 struct bonding *bond = netdev_priv(bond_dev);
3482 bond->kill_timers = 0;
3484 INIT_DELAYED_WORK(&bond->mcast_work, bond_resend_igmp_join_requests_delayed);
3486 if (bond_is_lb(bond)) {
3487 /* bond_alb_initialize must be called before the timer
3490 if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) {
3491 /* something went wrong - fail the open operation */
3495 INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
3496 queue_delayed_work(bond->wq, &bond->alb_work, 0);
3499 if (bond->params.miimon) { /* link check interval, in milliseconds. */
3500 INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
3501 queue_delayed_work(bond->wq, &bond->mii_work, 0);
3504 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
3505 if (bond->params.mode == BOND_MODE_ACTIVEBACKUP)
3506 INIT_DELAYED_WORK(&bond->arp_work,
3507 bond_activebackup_arp_mon);
3509 INIT_DELAYED_WORK(&bond->arp_work,
3510 bond_loadbalance_arp_mon);
3512 queue_delayed_work(bond->wq, &bond->arp_work, 0);
3513 if (bond->params.arp_validate)
3514 bond->recv_probe = bond_arp_rcv;
3517 if (bond->params.mode == BOND_MODE_8023AD) {
3518 INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
3519 queue_delayed_work(bond->wq, &bond->ad_work, 0);
3520 /* register to receive LACPDUs */
3521 bond->recv_probe = bond_3ad_lacpdu_recv;
3522 bond_3ad_initiate_agg_selection(bond, 1);
3528 static int bond_close(struct net_device *bond_dev)
3530 struct bonding *bond = netdev_priv(bond_dev);
3532 write_lock_bh(&bond->lock);
3534 bond->send_peer_notif = 0;
3536 /* signal timers not to re-arm */
3537 bond->kill_timers = 1;
3539 write_unlock_bh(&bond->lock);
3541 if (bond->params.miimon) { /* link check interval, in milliseconds. */
3542 cancel_delayed_work(&bond->mii_work);
3545 if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
3546 cancel_delayed_work(&bond->arp_work);
3549 switch (bond->params.mode) {
3550 case BOND_MODE_8023AD:
3551 cancel_delayed_work(&bond->ad_work);
3555 cancel_delayed_work(&bond->alb_work);
3561 if (delayed_work_pending(&bond->mcast_work))
3562 cancel_delayed_work(&bond->mcast_work);
3564 if (bond_is_lb(bond)) {
3565 /* Must be called only after all
3566 * slaves have been released
3568 bond_alb_deinitialize(bond);
3570 bond->recv_probe = NULL;
3575 static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev,
3576 struct rtnl_link_stats64 *stats)
3578 struct bonding *bond = netdev_priv(bond_dev);
3579 struct rtnl_link_stats64 temp;
3580 struct slave *slave;
3583 memset(stats, 0, sizeof(*stats));
3585 read_lock_bh(&bond->lock);
3587 bond_for_each_slave(bond, slave, i) {
3588 const struct rtnl_link_stats64 *sstats =
3589 dev_get_stats(slave->dev, &temp);
3591 stats->rx_packets += sstats->rx_packets;
3592 stats->rx_bytes += sstats->rx_bytes;
3593 stats->rx_errors += sstats->rx_errors;
3594 stats->rx_dropped += sstats->rx_dropped;
3596 stats->tx_packets += sstats->tx_packets;
3597 stats->tx_bytes += sstats->tx_bytes;
3598 stats->tx_errors += sstats->tx_errors;
3599 stats->tx_dropped += sstats->tx_dropped;
3601 stats->multicast += sstats->multicast;
3602 stats->collisions += sstats->collisions;
3604 stats->rx_length_errors += sstats->rx_length_errors;
3605 stats->rx_over_errors += sstats->rx_over_errors;
3606 stats->rx_crc_errors += sstats->rx_crc_errors;
3607 stats->rx_frame_errors += sstats->rx_frame_errors;
3608 stats->rx_fifo_errors += sstats->rx_fifo_errors;
3609 stats->rx_missed_errors += sstats->rx_missed_errors;
3611 stats->tx_aborted_errors += sstats->tx_aborted_errors;
3612 stats->tx_carrier_errors += sstats->tx_carrier_errors;
3613 stats->tx_fifo_errors += sstats->tx_fifo_errors;
3614 stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors;
3615 stats->tx_window_errors += sstats->tx_window_errors;
3618 read_unlock_bh(&bond->lock);
3623 static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
3625 struct net_device *slave_dev = NULL;
3626 struct ifbond k_binfo;
3627 struct ifbond __user *u_binfo = NULL;
3628 struct ifslave k_sinfo;
3629 struct ifslave __user *u_sinfo = NULL;
3630 struct mii_ioctl_data *mii = NULL;
3633 pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd);
3645 * We do this again just in case we were called by SIOCGMIIREG
3646 * instead of SIOCGMIIPHY.
3653 if (mii->reg_num == 1) {
3654 struct bonding *bond = netdev_priv(bond_dev);
3656 read_lock(&bond->lock);
3657 read_lock(&bond->curr_slave_lock);
3658 if (netif_carrier_ok(bond->dev))
3659 mii->val_out = BMSR_LSTATUS;
3661 read_unlock(&bond->curr_slave_lock);
3662 read_unlock(&bond->lock);
3666 case BOND_INFO_QUERY_OLD:
3667 case SIOCBONDINFOQUERY:
3668 u_binfo = (struct ifbond __user *)ifr->ifr_data;
3670 if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond)))
3673 res = bond_info_query(bond_dev, &k_binfo);
3675 copy_to_user(u_binfo, &k_binfo, sizeof(ifbond)))
3679 case BOND_SLAVE_INFO_QUERY_OLD:
3680 case SIOCBONDSLAVEINFOQUERY:
3681 u_sinfo = (struct ifslave __user *)ifr->ifr_data;
3683 if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave)))
3686 res = bond_slave_info_query(bond_dev, &k_sinfo);
3688 copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave)))
3697 if (!capable(CAP_NET_ADMIN))
3700 slave_dev = dev_get_by_name(dev_net(bond_dev), ifr->ifr_slave);
3702 pr_debug("slave_dev=%p:\n", slave_dev);
3707 pr_debug("slave_dev->name=%s:\n", slave_dev->name);
3709 case BOND_ENSLAVE_OLD:
3710 case SIOCBONDENSLAVE:
3711 res = bond_enslave(bond_dev, slave_dev);
3713 case BOND_RELEASE_OLD:
3714 case SIOCBONDRELEASE:
3715 res = bond_release(bond_dev, slave_dev);
3717 case BOND_SETHWADDR_OLD:
3718 case SIOCBONDSETHWADDR:
3719 res = bond_sethwaddr(bond_dev, slave_dev);
3721 case BOND_CHANGE_ACTIVE_OLD:
3722 case SIOCBONDCHANGEACTIVE:
3723 res = bond_ioctl_change_active(bond_dev, slave_dev);
3735 static bool bond_addr_in_mc_list(unsigned char *addr,
3736 struct netdev_hw_addr_list *list,
3739 struct netdev_hw_addr *ha;
3741 netdev_hw_addr_list_for_each(ha, list)
3742 if (!memcmp(ha->addr, addr, addrlen))
3748 static void bond_set_multicast_list(struct net_device *bond_dev)
3750 struct bonding *bond = netdev_priv(bond_dev);
3751 struct netdev_hw_addr *ha;
3755 * Do promisc before checking multicast_mode
3757 if ((bond_dev->flags & IFF_PROMISC) && !(bond->flags & IFF_PROMISC))
3759 * FIXME: Need to handle the error when one of the multi-slaves
3762 bond_set_promiscuity(bond, 1);
3765 if (!(bond_dev->flags & IFF_PROMISC) && (bond->flags & IFF_PROMISC))
3766 bond_set_promiscuity(bond, -1);
3769 /* set allmulti flag to slaves */
3770 if ((bond_dev->flags & IFF_ALLMULTI) && !(bond->flags & IFF_ALLMULTI))
3772 * FIXME: Need to handle the error when one of the multi-slaves
3775 bond_set_allmulti(bond, 1);
3778 if (!(bond_dev->flags & IFF_ALLMULTI) && (bond->flags & IFF_ALLMULTI))
3779 bond_set_allmulti(bond, -1);
3782 read_lock(&bond->lock);
3784 bond->flags = bond_dev->flags;
3786 /* looking for addresses to add to slaves' mc list */
3787 netdev_for_each_mc_addr(ha, bond_dev) {
3788 found = bond_addr_in_mc_list(ha->addr, &bond->mc_list,
3789 bond_dev->addr_len);
3791 bond_mc_add(bond, ha->addr);
3794 /* looking for addresses to delete from slaves' list */
3795 netdev_hw_addr_list_for_each(ha, &bond->mc_list) {
3796 found = bond_addr_in_mc_list(ha->addr, &bond_dev->mc,
3797 bond_dev->addr_len);
3799 bond_mc_del(bond, ha->addr);
3802 /* save master's multicast list */
3803 __hw_addr_flush(&bond->mc_list);
3804 __hw_addr_add_multiple(&bond->mc_list, &bond_dev->mc,
3805 bond_dev->addr_len, NETDEV_HW_ADDR_T_MULTICAST);
3807 read_unlock(&bond->lock);
3810 static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms)
3812 struct bonding *bond = netdev_priv(dev);
3813 struct slave *slave = bond->first_slave;
3816 const struct net_device_ops *slave_ops
3817 = slave->dev->netdev_ops;
3818 if (slave_ops->ndo_neigh_setup)
3819 return slave_ops->ndo_neigh_setup(slave->dev, parms);
3825 * Change the MTU of all of a master's slaves to match the master
3827 static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
3829 struct bonding *bond = netdev_priv(bond_dev);
3830 struct slave *slave, *stop_at;
3834 pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond,
3835 (bond_dev ? bond_dev->name : "None"), new_mtu);
3837 /* Can't hold bond->lock with bh disabled here since
3838 * some base drivers panic. On the other hand we can't
3839 * hold bond->lock without bh disabled because we'll
3840 * deadlock. The only solution is to rely on the fact
3841 * that we're under rtnl_lock here, and the slaves
3842 * list won't change. This doesn't solve the problem
3843 * of setting the slave's MTU while it is
3844 * transmitting, but the assumption is that the base
3845 * driver can handle that.
3847 * TODO: figure out a way to safely iterate the slaves
3848 * list, but without holding a lock around the actual
3849 * call to the base driver.
3852 bond_for_each_slave(bond, slave, i) {
3853 pr_debug("s %p s->p %p c_m %p\n",
3856 slave->dev->netdev_ops->ndo_change_mtu);
3858 res = dev_set_mtu(slave->dev, new_mtu);
3861 /* If we failed to set the slave's mtu to the new value
3862 * we must abort the operation even in ACTIVE_BACKUP
3863 * mode, because if we allow the backup slaves to have
3864 * different mtu values than the active slave we'll
3865 * need to change their mtu when doing a failover. That
3866 * means changing their mtu from timer context, which
3867 * is probably not a good idea.
3869 pr_debug("err %d %s\n", res, slave->dev->name);
3874 bond_dev->mtu = new_mtu;
3879 /* unwind from head to the slave that failed */
3881 bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
3884 tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu);
3886 pr_debug("unwind err %d dev %s\n",
3887 tmp_res, slave->dev->name);
3897 * Note that many devices must be down to change the HW address, and
3898 * downing the master releases all slaves. We can make bonds full of
3899 * bonding devices to test this, however.
3901 static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
3903 struct bonding *bond = netdev_priv(bond_dev);
3904 struct sockaddr *sa = addr, tmp_sa;
3905 struct slave *slave, *stop_at;
3909 if (bond->params.mode == BOND_MODE_ALB)
3910 return bond_alb_set_mac_address(bond_dev, addr);
3913 pr_debug("bond=%p, name=%s\n",
3914 bond, bond_dev ? bond_dev->name : "None");
3917 * If fail_over_mac is set to active, do nothing and return
3918 * success. Returning an error causes ifenslave to fail.
3920 if (bond->params.fail_over_mac == BOND_FOM_ACTIVE)
3923 if (!is_valid_ether_addr(sa->sa_data))
3924 return -EADDRNOTAVAIL;
3926 /* Can't hold bond->lock with bh disabled here since
3927 * some base drivers panic. On the other hand we can't
3928 * hold bond->lock without bh disabled because we'll
3929 * deadlock. The only solution is to rely on the fact
3930 * that we're under rtnl_lock here, and the slaves
3931 * list won't change. This doesn't solve the problem
3932 * of setting the slave's hw address while it is
3933 * transmitting, but the assumption is that the base
3934 * driver can handle that.
3936 * TODO: figure out a way to safely iterate the slaves
3937 * list, but without holding a lock around the actual
3938 * call to the base driver.
3941 bond_for_each_slave(bond, slave, i) {
3942 const struct net_device_ops *slave_ops = slave->dev->netdev_ops;
3943 pr_debug("slave %p %s\n", slave, slave->dev->name);
3945 if (slave_ops->ndo_set_mac_address == NULL) {
3947 pr_debug("EOPNOTSUPP %s\n", slave->dev->name);
3951 res = dev_set_mac_address(slave->dev, addr);
3953 /* TODO: consider downing the slave
3955 * User should expect communications
3956 * breakage anyway until ARP finish
3959 pr_debug("err %d %s\n", res, slave->dev->name);
3965 memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len);
3969 memcpy(tmp_sa.sa_data, bond_dev->dev_addr, bond_dev->addr_len);
3970 tmp_sa.sa_family = bond_dev->type;
3972 /* unwind from head to the slave that failed */
3974 bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) {
3977 tmp_res = dev_set_mac_address(slave->dev, &tmp_sa);
3979 pr_debug("unwind err %d dev %s\n",
3980 tmp_res, slave->dev->name);
3987 static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev)
3989 struct bonding *bond = netdev_priv(bond_dev);
3990 struct slave *slave, *start_at;
3991 int i, slave_no, res = 1;
3992 struct iphdr *iph = ip_hdr(skb);
3995 * Start with the curr_active_slave that joined the bond as the
3996 * default for sending IGMP traffic. For failover purposes one
3997 * needs to maintain some consistency for the interface that will
3998 * send the join/membership reports. The curr_active_slave found
3999 * will send all of this type of traffic.
4001 if ((iph->protocol == IPPROTO_IGMP) &&
4002 (skb->protocol == htons(ETH_P_IP))) {
4004 read_lock(&bond->curr_slave_lock);
4005 slave = bond->curr_active_slave;
4006 read_unlock(&bond->curr_slave_lock);
4012 * Concurrent TX may collide on rr_tx_counter; we accept
4013 * that as being rare enough not to justify using an
4016 slave_no = bond->rr_tx_counter++ % bond->slave_cnt;
4018 bond_for_each_slave(bond, slave, i) {
4026 bond_for_each_slave_from(bond, slave, i, start_at) {
4027 if (IS_UP(slave->dev) &&
4028 (slave->link == BOND_LINK_UP) &&
4029 bond_is_active_slave(slave)) {
4030 res = bond_dev_queue_xmit(bond, skb, slave->dev);
4037 /* no suitable interface, frame not sent */
4041 return NETDEV_TX_OK;
4046 * in active-backup mode, we know that bond->curr_active_slave is always valid if
4047 * the bond has a usable interface.
4049 static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_dev)
4051 struct bonding *bond = netdev_priv(bond_dev);
4054 read_lock(&bond->curr_slave_lock);
4056 if (bond->curr_active_slave)
4057 res = bond_dev_queue_xmit(bond, skb,
4058 bond->curr_active_slave->dev);
4061 /* no suitable interface, frame not sent */
4064 read_unlock(&bond->curr_slave_lock);
4066 return NETDEV_TX_OK;
4070 * In bond_xmit_xor() , we determine the output device by using a pre-
4071 * determined xmit_hash_policy(), If the selected device is not enabled,
4072 * find the next active slave.
4074 static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4076 struct bonding *bond = netdev_priv(bond_dev);
4077 struct slave *slave, *start_at;
4082 slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt);
4084 bond_for_each_slave(bond, slave, i) {
4092 bond_for_each_slave_from(bond, slave, i, start_at) {
4093 if (IS_UP(slave->dev) &&
4094 (slave->link == BOND_LINK_UP) &&
4095 bond_is_active_slave(slave)) {
4096 res = bond_dev_queue_xmit(bond, skb, slave->dev);
4102 /* no suitable interface, frame not sent */
4106 return NETDEV_TX_OK;
4110 * in broadcast mode, we send everything to all usable interfaces.
4112 static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
4114 struct bonding *bond = netdev_priv(bond_dev);
4115 struct slave *slave, *start_at;
4116 struct net_device *tx_dev = NULL;
4120 read_lock(&bond->curr_slave_lock);
4121 start_at = bond->curr_active_slave;
4122 read_unlock(&bond->curr_slave_lock);
4127 bond_for_each_slave_from(bond, slave, i, start_at) {
4128 if (IS_UP(slave->dev) &&
4129 (slave->link == BOND_LINK_UP) &&
4130 bond_is_active_slave(slave)) {
4132 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
4134 pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n",
4139 res = bond_dev_queue_xmit(bond, skb2, tx_dev);
4141 dev_kfree_skb(skb2);
4145 tx_dev = slave->dev;
4150 res = bond_dev_queue_xmit(bond, skb, tx_dev);
4154 /* no suitable interface, frame not sent */
4157 /* frame sent to all suitable interfaces */
4158 return NETDEV_TX_OK;
4161 /*------------------------- Device initialization ---------------------------*/
4163 static void bond_set_xmit_hash_policy(struct bonding *bond)
4165 switch (bond->params.xmit_policy) {
4166 case BOND_XMIT_POLICY_LAYER23:
4167 bond->xmit_hash_policy = bond_xmit_hash_policy_l23;
4169 case BOND_XMIT_POLICY_LAYER34:
4170 bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
4172 case BOND_XMIT_POLICY_LAYER2:
4174 bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
4180 * Lookup the slave that corresponds to a qid
4182 static inline int bond_slave_override(struct bonding *bond,
4183 struct sk_buff *skb)
4186 struct slave *slave = NULL;
4187 struct slave *check_slave;
4189 if (!skb->queue_mapping)
4192 /* Find out if any slaves have the same mapping as this skb. */
4193 bond_for_each_slave(bond, check_slave, i) {
4194 if (check_slave->queue_id == skb->queue_mapping) {
4195 slave = check_slave;
4200 /* If the slave isn't UP, use default transmit policy. */
4201 if (slave && slave->queue_id && IS_UP(slave->dev) &&
4202 (slave->link == BOND_LINK_UP)) {
4203 res = bond_dev_queue_xmit(bond, skb, slave->dev);
4209 static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb)
4212 * This helper function exists to help dev_pick_tx get the correct
4213 * destination queue. Using a helper function skips a call to
4214 * skb_tx_hash and will put the skbs in the queue we expect on their
4215 * way down to the bonding driver.
4217 u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0;
4219 if (unlikely(txq >= dev->real_num_tx_queues)) {
4221 txq -= dev->real_num_tx_queues;
4222 } while (txq >= dev->real_num_tx_queues);
4227 static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
4229 struct bonding *bond = netdev_priv(dev);
4231 if (TX_QUEUE_OVERRIDE(bond->params.mode)) {
4232 if (!bond_slave_override(bond, skb))
4233 return NETDEV_TX_OK;
4236 switch (bond->params.mode) {
4237 case BOND_MODE_ROUNDROBIN:
4238 return bond_xmit_roundrobin(skb, dev);
4239 case BOND_MODE_ACTIVEBACKUP:
4240 return bond_xmit_activebackup(skb, dev);
4242 return bond_xmit_xor(skb, dev);
4243 case BOND_MODE_BROADCAST:
4244 return bond_xmit_broadcast(skb, dev);
4245 case BOND_MODE_8023AD:
4246 return bond_3ad_xmit_xor(skb, dev);
4249 return bond_alb_xmit(skb, dev);
4251 /* Should never happen, mode already checked */
4252 pr_err("%s: Error: Unknown bonding mode %d\n",
4253 dev->name, bond->params.mode);
4256 return NETDEV_TX_OK;
4260 static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
4262 struct bonding *bond = netdev_priv(dev);
4263 netdev_tx_t ret = NETDEV_TX_OK;
4266 * If we risk deadlock from transmitting this in the
4267 * netpoll path, tell netpoll to queue the frame for later tx
4269 if (is_netpoll_tx_blocked(dev))
4270 return NETDEV_TX_BUSY;
4272 read_lock(&bond->lock);
4274 if (bond->slave_cnt)
4275 ret = __bond_start_xmit(skb, dev);
4279 read_unlock(&bond->lock);
4285 * set bond mode specific net device operations
4287 void bond_set_mode_ops(struct bonding *bond, int mode)
4289 struct net_device *bond_dev = bond->dev;
4292 case BOND_MODE_ROUNDROBIN:
4294 case BOND_MODE_ACTIVEBACKUP:
4297 bond_set_xmit_hash_policy(bond);
4299 case BOND_MODE_BROADCAST:
4301 case BOND_MODE_8023AD:
4302 bond_set_xmit_hash_policy(bond);
4309 /* Should never happen, mode already checked */
4310 pr_err("%s: Error: Unknown bonding mode %d\n",
4311 bond_dev->name, mode);
4316 static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
4317 struct ethtool_drvinfo *drvinfo)
4319 strncpy(drvinfo->driver, DRV_NAME, 32);
4320 strncpy(drvinfo->version, DRV_VERSION, 32);
4321 snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION);
4324 static const struct ethtool_ops bond_ethtool_ops = {
4325 .get_drvinfo = bond_ethtool_get_drvinfo,
4326 .get_link = ethtool_op_get_link,
4329 static const struct net_device_ops bond_netdev_ops = {
4330 .ndo_init = bond_init,
4331 .ndo_uninit = bond_uninit,
4332 .ndo_open = bond_open,
4333 .ndo_stop = bond_close,
4334 .ndo_start_xmit = bond_start_xmit,
4335 .ndo_select_queue = bond_select_queue,
4336 .ndo_get_stats64 = bond_get_stats,
4337 .ndo_do_ioctl = bond_do_ioctl,
4338 .ndo_set_multicast_list = bond_set_multicast_list,
4339 .ndo_change_mtu = bond_change_mtu,
4340 .ndo_set_mac_address = bond_set_mac_address,
4341 .ndo_neigh_setup = bond_neigh_setup,
4342 .ndo_vlan_rx_register = bond_vlan_rx_register,
4343 .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
4344 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4345 #ifdef CONFIG_NET_POLL_CONTROLLER
4346 .ndo_netpoll_setup = bond_netpoll_setup,
4347 .ndo_netpoll_cleanup = bond_netpoll_cleanup,
4348 .ndo_poll_controller = bond_poll_controller,
4350 .ndo_add_slave = bond_enslave,
4351 .ndo_del_slave = bond_release,
4352 .ndo_fix_features = bond_fix_features,
4355 static void bond_destructor(struct net_device *bond_dev)
4357 struct bonding *bond = netdev_priv(bond_dev);
4359 destroy_workqueue(bond->wq);
4360 free_netdev(bond_dev);
4363 static void bond_setup(struct net_device *bond_dev)
4365 struct bonding *bond = netdev_priv(bond_dev);
4367 /* initialize rwlocks */
4368 rwlock_init(&bond->lock);
4369 rwlock_init(&bond->curr_slave_lock);
4371 bond->params = bonding_defaults;
4373 /* Initialize pointers */
4374 bond->dev = bond_dev;
4375 INIT_LIST_HEAD(&bond->vlan_list);
4377 /* Initialize the device entry points */
4378 ether_setup(bond_dev);
4379 bond_dev->netdev_ops = &bond_netdev_ops;
4380 bond_dev->ethtool_ops = &bond_ethtool_ops;
4381 bond_set_mode_ops(bond, bond->params.mode);
4383 bond_dev->destructor = bond_destructor;
4385 /* Initialize the device options */
4386 bond_dev->tx_queue_len = 0;
4387 bond_dev->flags |= IFF_MASTER|IFF_MULTICAST;
4388 bond_dev->priv_flags |= IFF_BONDING;
4389 bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
4391 /* At first, we block adding VLANs. That's the only way to
4392 * prevent problems that occur when adding VLANs over an
4393 * empty bond. The block will be removed once non-challenged
4394 * slaves are enslaved.
4396 bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
4398 /* don't acquire bond device's netif_tx_lock when
4400 bond_dev->features |= NETIF_F_LLTX;
4402 /* By default, we declare the bond to be fully
4403 * VLAN hardware accelerated capable. Special
4404 * care is taken in the various xmit functions
4405 * when there are slaves that are not hw accel
4409 bond_dev->hw_features = BOND_VLAN_FEATURES |
4410 NETIF_F_HW_VLAN_TX |
4411 NETIF_F_HW_VLAN_RX |
4412 NETIF_F_HW_VLAN_FILTER;
4414 bond_dev->hw_features &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_NO_CSUM);
4415 bond_dev->features |= bond_dev->hw_features;
4418 static void bond_work_cancel_all(struct bonding *bond)
4420 write_lock_bh(&bond->lock);
4421 bond->kill_timers = 1;
4422 write_unlock_bh(&bond->lock);
4424 if (bond->params.miimon && delayed_work_pending(&bond->mii_work))
4425 cancel_delayed_work(&bond->mii_work);
4427 if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work))
4428 cancel_delayed_work(&bond->arp_work);
4430 if (bond->params.mode == BOND_MODE_ALB &&
4431 delayed_work_pending(&bond->alb_work))
4432 cancel_delayed_work(&bond->alb_work);
4434 if (bond->params.mode == BOND_MODE_8023AD &&
4435 delayed_work_pending(&bond->ad_work))
4436 cancel_delayed_work(&bond->ad_work);
4438 if (delayed_work_pending(&bond->mcast_work))
4439 cancel_delayed_work(&bond->mcast_work);
4443 * Destroy a bonding device.
4444 * Must be under rtnl_lock when this function is called.
4446 static void bond_uninit(struct net_device *bond_dev)
4448 struct bonding *bond = netdev_priv(bond_dev);
4449 struct vlan_entry *vlan, *tmp;
4451 bond_netpoll_cleanup(bond_dev);
4453 /* Release the bonded slaves */
4454 bond_release_all(bond_dev);
4456 list_del(&bond->bond_list);
4458 bond_work_cancel_all(bond);
4460 bond_remove_proc_entry(bond);
4462 bond_debug_unregister(bond);
4464 __hw_addr_flush(&bond->mc_list);
4466 list_for_each_entry_safe(vlan, tmp, &bond->vlan_list, vlan_list) {
4467 list_del(&vlan->vlan_list);
4472 /*------------------------- Module initialization ---------------------------*/
4475 * Convert string input module parms. Accept either the
4476 * number of the mode or its string name. A bit complicated because
4477 * some mode names are substrings of other names, and calls from sysfs
4478 * may have whitespace in the name (trailing newlines, for example).
4480 int bond_parse_parm(const char *buf, const struct bond_parm_tbl *tbl)
4482 int modeint = -1, i, rv;
4483 char *p, modestr[BOND_MAX_MODENAME_LEN + 1] = { 0, };
4485 for (p = (char *)buf; *p; p++)
4486 if (!(isdigit(*p) || isspace(*p)))
4490 rv = sscanf(buf, "%20s", modestr);
4492 rv = sscanf(buf, "%d", &modeint);
4497 for (i = 0; tbl[i].modename; i++) {
4498 if (modeint == tbl[i].mode)
4500 if (strcmp(modestr, tbl[i].modename) == 0)
4507 static int bond_check_params(struct bond_params *params)
4509 int arp_validate_value, fail_over_mac_value, primary_reselect_value;
4512 * Convert string parameters.
4515 bond_mode = bond_parse_parm(mode, bond_mode_tbl);
4516 if (bond_mode == -1) {
4517 pr_err("Error: Invalid bonding mode \"%s\"\n",
4518 mode == NULL ? "NULL" : mode);
4523 if (xmit_hash_policy) {
4524 if ((bond_mode != BOND_MODE_XOR) &&
4525 (bond_mode != BOND_MODE_8023AD)) {
4526 pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
4527 bond_mode_name(bond_mode));
4529 xmit_hashtype = bond_parse_parm(xmit_hash_policy,
4531 if (xmit_hashtype == -1) {
4532 pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
4533 xmit_hash_policy == NULL ? "NULL" :
4541 if (bond_mode != BOND_MODE_8023AD) {
4542 pr_info("lacp_rate param is irrelevant in mode %s\n",
4543 bond_mode_name(bond_mode));
4545 lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl);
4546 if (lacp_fast == -1) {
4547 pr_err("Error: Invalid lacp rate \"%s\"\n",
4548 lacp_rate == NULL ? "NULL" : lacp_rate);
4555 params->ad_select = bond_parse_parm(ad_select, ad_select_tbl);
4556 if (params->ad_select == -1) {
4557 pr_err("Error: Invalid ad_select \"%s\"\n",
4558 ad_select == NULL ? "NULL" : ad_select);
4562 if (bond_mode != BOND_MODE_8023AD) {
4563 pr_warning("ad_select param only affects 802.3ad mode\n");
4566 params->ad_select = BOND_AD_STABLE;
4569 if (max_bonds < 0) {
4570 pr_warning("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
4571 max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
4572 max_bonds = BOND_DEFAULT_MAX_BONDS;
4576 pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n",
4577 miimon, INT_MAX, BOND_LINK_MON_INTERV);
4578 miimon = BOND_LINK_MON_INTERV;
4582 pr_warning("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4587 if (downdelay < 0) {
4588 pr_warning("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4589 downdelay, INT_MAX);
4593 if ((use_carrier != 0) && (use_carrier != 1)) {
4594 pr_warning("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n",
4599 if (num_peer_notif < 0 || num_peer_notif > 255) {
4600 pr_warning("Warning: num_grat_arp/num_unsol_na (%d) not in range 0-255 so it was reset to 1\n",
4605 /* reset values for 802.3ad */
4606 if (bond_mode == BOND_MODE_8023AD) {
4608 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");
4609 pr_warning("Forcing miimon to 100msec\n");
4614 if (tx_queues < 1 || tx_queues > 255) {
4615 pr_warning("Warning: tx_queues (%d) should be between "
4616 "1 and 255, resetting to %d\n",
4617 tx_queues, BOND_DEFAULT_TX_QUEUES);
4618 tx_queues = BOND_DEFAULT_TX_QUEUES;
4621 if ((all_slaves_active != 0) && (all_slaves_active != 1)) {
4622 pr_warning("Warning: all_slaves_active module parameter (%d), "
4623 "not of valid value (0/1), so it was set to "
4624 "0\n", all_slaves_active);
4625 all_slaves_active = 0;
4628 if (resend_igmp < 0 || resend_igmp > 255) {
4629 pr_warning("Warning: resend_igmp (%d) should be between "
4630 "0 and 255, resetting to %d\n",
4631 resend_igmp, BOND_DEFAULT_RESEND_IGMP);
4632 resend_igmp = BOND_DEFAULT_RESEND_IGMP;
4635 /* reset values for TLB/ALB */
4636 if ((bond_mode == BOND_MODE_TLB) ||
4637 (bond_mode == BOND_MODE_ALB)) {
4639 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");
4640 pr_warning("Forcing miimon to 100msec\n");
4645 if (bond_mode == BOND_MODE_ALB) {
4646 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",
4651 if (updelay || downdelay) {
4652 /* just warn the user the up/down delay will have
4653 * no effect since miimon is zero...
4655 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",
4656 updelay, downdelay);
4659 /* don't allow arp monitoring */
4661 pr_warning("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n",
4662 miimon, arp_interval);
4666 if ((updelay % miimon) != 0) {
4667 pr_warning("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
4669 (updelay / miimon) * miimon);
4674 if ((downdelay % miimon) != 0) {
4675 pr_warning("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n",
4677 (downdelay / miimon) * miimon);
4680 downdelay /= miimon;
4683 if (arp_interval < 0) {
4684 pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n",
4685 arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
4686 arp_interval = BOND_LINK_ARP_INTERV;
4689 for (arp_ip_count = 0;
4690 (arp_ip_count < BOND_MAX_ARP_TARGETS) && arp_ip_target[arp_ip_count];
4692 /* not complete check, but should be good enough to
4694 if (!isdigit(arp_ip_target[arp_ip_count][0])) {
4695 pr_warning("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n",
4696 arp_ip_target[arp_ip_count]);
4699 __be32 ip = in_aton(arp_ip_target[arp_ip_count]);
4700 arp_target[arp_ip_count] = ip;
4704 if (arp_interval && !arp_ip_count) {
4705 /* don't allow arping if no arp_ip_target given... */
4706 pr_warning("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n",
4712 if (bond_mode != BOND_MODE_ACTIVEBACKUP) {
4713 pr_err("arp_validate only supported in active-backup mode\n");
4716 if (!arp_interval) {
4717 pr_err("arp_validate requires arp_interval\n");
4721 arp_validate_value = bond_parse_parm(arp_validate,
4723 if (arp_validate_value == -1) {
4724 pr_err("Error: invalid arp_validate \"%s\"\n",
4725 arp_validate == NULL ? "NULL" : arp_validate);
4729 arp_validate_value = 0;
4732 pr_info("MII link monitoring set to %d ms\n", miimon);
4733 } else if (arp_interval) {
4736 pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
4738 arp_validate_tbl[arp_validate_value].modename,
4741 for (i = 0; i < arp_ip_count; i++)
4742 pr_info(" %s", arp_ip_target[i]);
4746 } else if (max_bonds) {
4747 /* miimon and arp_interval not set, we need one so things
4748 * work as expected, see bonding.txt for details
4750 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");
4753 if (primary && !USES_PRIMARY(bond_mode)) {
4754 /* currently, using a primary only makes sense
4755 * in active backup, TLB or ALB modes
4757 pr_warning("Warning: %s primary device specified but has no effect in %s mode\n",
4758 primary, bond_mode_name(bond_mode));
4762 if (primary && primary_reselect) {
4763 primary_reselect_value = bond_parse_parm(primary_reselect,
4765 if (primary_reselect_value == -1) {
4766 pr_err("Error: Invalid primary_reselect \"%s\"\n",
4768 NULL ? "NULL" : primary_reselect);
4772 primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
4775 if (fail_over_mac) {
4776 fail_over_mac_value = bond_parse_parm(fail_over_mac,
4778 if (fail_over_mac_value == -1) {
4779 pr_err("Error: invalid fail_over_mac \"%s\"\n",
4780 arp_validate == NULL ? "NULL" : arp_validate);
4784 if (bond_mode != BOND_MODE_ACTIVEBACKUP)
4785 pr_warning("Warning: fail_over_mac only affects active-backup mode.\n");
4787 fail_over_mac_value = BOND_FOM_NONE;
4790 /* fill params struct with the proper values */
4791 params->mode = bond_mode;
4792 params->xmit_policy = xmit_hashtype;
4793 params->miimon = miimon;
4794 params->num_peer_notif = num_peer_notif;
4795 params->arp_interval = arp_interval;
4796 params->arp_validate = arp_validate_value;
4797 params->updelay = updelay;
4798 params->downdelay = downdelay;
4799 params->use_carrier = use_carrier;
4800 params->lacp_fast = lacp_fast;
4801 params->primary[0] = 0;
4802 params->primary_reselect = primary_reselect_value;
4803 params->fail_over_mac = fail_over_mac_value;
4804 params->tx_queues = tx_queues;
4805 params->all_slaves_active = all_slaves_active;
4806 params->resend_igmp = resend_igmp;
4809 strncpy(params->primary, primary, IFNAMSIZ);
4810 params->primary[IFNAMSIZ - 1] = 0;
4813 memcpy(params->arp_targets, arp_target, sizeof(arp_target));
4818 static struct lock_class_key bonding_netdev_xmit_lock_key;
4819 static struct lock_class_key bonding_netdev_addr_lock_key;
4821 static void bond_set_lockdep_class_one(struct net_device *dev,
4822 struct netdev_queue *txq,
4825 lockdep_set_class(&txq->_xmit_lock,
4826 &bonding_netdev_xmit_lock_key);
4829 static void bond_set_lockdep_class(struct net_device *dev)
4831 lockdep_set_class(&dev->addr_list_lock,
4832 &bonding_netdev_addr_lock_key);
4833 netdev_for_each_tx_queue(dev, bond_set_lockdep_class_one, NULL);
4837 * Called from registration process
4839 static int bond_init(struct net_device *bond_dev)
4841 struct bonding *bond = netdev_priv(bond_dev);
4842 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
4843 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
4845 pr_debug("Begin bond_init for %s\n", bond_dev->name);
4848 * Initialize locks that may be required during
4849 * en/deslave operations. All of the bond_open work
4850 * (of which this is part) should really be moved to
4851 * a phase prior to dev_open
4853 spin_lock_init(&(bond_info->tx_hashtbl_lock));
4854 spin_lock_init(&(bond_info->rx_hashtbl_lock));
4856 bond->wq = create_singlethread_workqueue(bond_dev->name);
4860 bond_set_lockdep_class(bond_dev);
4862 bond_create_proc_entry(bond);
4863 list_add_tail(&bond->bond_list, &bn->dev_list);
4865 bond_prepare_sysfs_group(bond);
4867 bond_debug_register(bond);
4869 __hw_addr_init(&bond->mc_list);
4873 static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
4875 if (tb[IFLA_ADDRESS]) {
4876 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
4878 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
4879 return -EADDRNOTAVAIL;
4884 static struct rtnl_link_ops bond_link_ops __read_mostly = {
4886 .priv_size = sizeof(struct bonding),
4887 .setup = bond_setup,
4888 .validate = bond_validate,
4891 /* Create a new bond based on the specified name and bonding parameters.
4892 * If name is NULL, obtain a suitable "bond%d" name for us.
4893 * Caller must NOT hold rtnl_lock; we need to release it here before we
4894 * set up our sysfs entries.
4896 int bond_create(struct net *net, const char *name)
4898 struct net_device *bond_dev;
4903 bond_dev = alloc_netdev_mq(sizeof(struct bonding),
4904 name ? name : "bond%d",
4905 bond_setup, tx_queues);
4907 pr_err("%s: eek! can't alloc netdev!\n", name);
4912 dev_net_set(bond_dev, net);
4913 bond_dev->rtnl_link_ops = &bond_link_ops;
4915 res = register_netdevice(bond_dev);
4917 netif_carrier_off(bond_dev);
4921 bond_destructor(bond_dev);
4925 static int __net_init bond_net_init(struct net *net)
4927 struct bond_net *bn = net_generic(net, bond_net_id);
4930 INIT_LIST_HEAD(&bn->dev_list);
4932 bond_create_proc_dir(bn);
4937 static void __net_exit bond_net_exit(struct net *net)
4939 struct bond_net *bn = net_generic(net, bond_net_id);
4941 bond_destroy_proc_dir(bn);
4944 static struct pernet_operations bond_net_ops = {
4945 .init = bond_net_init,
4946 .exit = bond_net_exit,
4948 .size = sizeof(struct bond_net),
4951 static int __init bonding_init(void)
4956 pr_info("%s", bond_version);
4958 res = bond_check_params(&bonding_defaults);
4962 res = register_pernet_subsys(&bond_net_ops);
4966 res = rtnl_link_register(&bond_link_ops);
4970 bond_create_debugfs();
4972 for (i = 0; i < max_bonds; i++) {
4973 res = bond_create(&init_net, NULL);
4978 res = bond_create_sysfs();
4982 register_netdevice_notifier(&bond_netdev_notifier);
4983 register_inetaddr_notifier(&bond_inetaddr_notifier);
4987 rtnl_link_unregister(&bond_link_ops);
4989 unregister_pernet_subsys(&bond_net_ops);
4994 static void __exit bonding_exit(void)
4996 unregister_netdevice_notifier(&bond_netdev_notifier);
4997 unregister_inetaddr_notifier(&bond_inetaddr_notifier);
4999 bond_destroy_sysfs();
5000 bond_destroy_debugfs();
5002 rtnl_link_unregister(&bond_link_ops);
5003 unregister_pernet_subsys(&bond_net_ops);
5005 #ifdef CONFIG_NET_POLL_CONTROLLER
5007 * Make sure we don't have an imbalance on our netpoll blocking
5009 WARN_ON(atomic_read(&netpoll_block_tx));
5013 module_init(bonding_init);
5014 module_exit(bonding_exit);
5015 MODULE_LICENSE("GPL");
5016 MODULE_VERSION(DRV_VERSION);
5017 MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
5018 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
5019 MODULE_ALIAS_RTNL_LINK("bond");