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 BONDING_DEBUG 1
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>
56 #include <asm/system.h>
59 #include <asm/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/proc_fs.h>
69 #include <linux/seq_file.h>
70 #include <linux/smp.h>
71 #include <linux/if_ether.h>
73 #include <linux/mii.h>
74 #include <linux/ethtool.h>
75 #include <linux/if_vlan.h>
76 #include <linux/if_bonding.h>
77 #include <net/route.h>
82 /*---------------------------- Module parameters ----------------------------*/
84 /* monitor all links that often (in milliseconds). <=0 disables monitoring */
85 #define BOND_LINK_MON_INTERV 0
86 #define BOND_LINK_ARP_INTERV 0
88 static int max_bonds
= BOND_DEFAULT_MAX_BONDS
;
89 static int miimon
= BOND_LINK_MON_INTERV
;
90 static int updelay
= 0;
91 static int downdelay
= 0;
92 static int use_carrier
= 1;
93 static char *mode
= NULL
;
94 static char *primary
= NULL
;
95 static char *lacp_rate
= NULL
;
96 static char *xmit_hash_policy
= NULL
;
97 static int arp_interval
= BOND_LINK_ARP_INTERV
;
98 static char *arp_ip_target
[BOND_MAX_ARP_TARGETS
] = { NULL
, };
99 static char *arp_validate
= NULL
;
100 struct bond_params bonding_defaults
;
102 module_param(max_bonds
, int, 0);
103 MODULE_PARM_DESC(max_bonds
, "Max number of bonded devices");
104 module_param(miimon
, int, 0);
105 MODULE_PARM_DESC(miimon
, "Link check interval in milliseconds");
106 module_param(updelay
, int, 0);
107 MODULE_PARM_DESC(updelay
, "Delay before considering link up, in milliseconds");
108 module_param(downdelay
, int, 0);
109 MODULE_PARM_DESC(downdelay
, "Delay before considering link down, "
111 module_param(use_carrier
, int, 0);
112 MODULE_PARM_DESC(use_carrier
, "Use netif_carrier_ok (vs MII ioctls) in miimon; "
113 "0 for off, 1 for on (default)");
114 module_param(mode
, charp
, 0);
115 MODULE_PARM_DESC(mode
, "Mode of operation : 0 for balance-rr, "
116 "1 for active-backup, 2 for balance-xor, "
117 "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, "
118 "6 for balance-alb");
119 module_param(primary
, charp
, 0);
120 MODULE_PARM_DESC(primary
, "Primary network device to use");
121 module_param(lacp_rate
, charp
, 0);
122 MODULE_PARM_DESC(lacp_rate
, "LACPDU tx rate to request from 802.3ad partner "
124 module_param(xmit_hash_policy
, charp
, 0);
125 MODULE_PARM_DESC(xmit_hash_policy
, "XOR hashing method: 0 for layer 2 (default)"
126 ", 1 for layer 3+4");
127 module_param(arp_interval
, int, 0);
128 MODULE_PARM_DESC(arp_interval
, "arp interval in milliseconds");
129 module_param_array(arp_ip_target
, charp
, NULL
, 0);
130 MODULE_PARM_DESC(arp_ip_target
, "arp targets in n.n.n.n form");
131 module_param(arp_validate
, charp
, 0);
132 MODULE_PARM_DESC(arp_validate
, "validate src/dst of ARP probes: none (default), active, backup or all");
134 /*----------------------------- Global variables ----------------------------*/
136 static const char * const version
=
137 DRV_DESCRIPTION
": v" DRV_VERSION
" (" DRV_RELDATE
")\n";
139 LIST_HEAD(bond_dev_list
);
141 #ifdef CONFIG_PROC_FS
142 static struct proc_dir_entry
*bond_proc_dir
= NULL
;
145 extern struct rw_semaphore bonding_rwsem
;
146 static u32 arp_target
[BOND_MAX_ARP_TARGETS
] = { 0, } ;
147 static int arp_ip_count
= 0;
148 static int bond_mode
= BOND_MODE_ROUNDROBIN
;
149 static int xmit_hashtype
= BOND_XMIT_POLICY_LAYER2
;
150 static int lacp_fast
= 0;
153 struct bond_parm_tbl bond_lacp_tbl
[] = {
154 { "slow", AD_LACP_SLOW
},
155 { "fast", AD_LACP_FAST
},
159 struct bond_parm_tbl bond_mode_tbl
[] = {
160 { "balance-rr", BOND_MODE_ROUNDROBIN
},
161 { "active-backup", BOND_MODE_ACTIVEBACKUP
},
162 { "balance-xor", BOND_MODE_XOR
},
163 { "broadcast", BOND_MODE_BROADCAST
},
164 { "802.3ad", BOND_MODE_8023AD
},
165 { "balance-tlb", BOND_MODE_TLB
},
166 { "balance-alb", BOND_MODE_ALB
},
170 struct bond_parm_tbl xmit_hashtype_tbl
[] = {
171 { "layer2", BOND_XMIT_POLICY_LAYER2
},
172 { "layer3+4", BOND_XMIT_POLICY_LAYER34
},
176 struct bond_parm_tbl arp_validate_tbl
[] = {
177 { "none", BOND_ARP_VALIDATE_NONE
},
178 { "active", BOND_ARP_VALIDATE_ACTIVE
},
179 { "backup", BOND_ARP_VALIDATE_BACKUP
},
180 { "all", BOND_ARP_VALIDATE_ALL
},
184 /*-------------------------- Forward declarations ---------------------------*/
186 static void bond_send_gratuitous_arp(struct bonding
*bond
);
188 /*---------------------------- General routines -----------------------------*/
190 const char *bond_mode_name(int mode
)
193 case BOND_MODE_ROUNDROBIN
:
194 return "load balancing (round-robin)";
195 case BOND_MODE_ACTIVEBACKUP
:
196 return "fault-tolerance (active-backup)";
198 return "load balancing (xor)";
199 case BOND_MODE_BROADCAST
:
200 return "fault-tolerance (broadcast)";
201 case BOND_MODE_8023AD
:
202 return "IEEE 802.3ad Dynamic link aggregation";
204 return "transmit load balancing";
206 return "adaptive load balancing";
212 /*---------------------------------- VLAN -----------------------------------*/
215 * bond_add_vlan - add a new vlan id on bond
216 * @bond: bond that got the notification
217 * @vlan_id: the vlan id to add
219 * Returns -ENOMEM if allocation failed.
221 static int bond_add_vlan(struct bonding
*bond
, unsigned short vlan_id
)
223 struct vlan_entry
*vlan
;
225 dprintk("bond: %s, vlan id %d\n",
226 (bond
? bond
->dev
->name
: "None"), vlan_id
);
228 vlan
= kmalloc(sizeof(struct vlan_entry
), GFP_KERNEL
);
233 INIT_LIST_HEAD(&vlan
->vlan_list
);
234 vlan
->vlan_id
= vlan_id
;
237 write_lock_bh(&bond
->lock
);
239 list_add_tail(&vlan
->vlan_list
, &bond
->vlan_list
);
241 write_unlock_bh(&bond
->lock
);
243 dprintk("added VLAN ID %d on bond %s\n", vlan_id
, bond
->dev
->name
);
249 * bond_del_vlan - delete a vlan id from bond
250 * @bond: bond that got the notification
251 * @vlan_id: the vlan id to delete
253 * returns -ENODEV if @vlan_id was not found in @bond.
255 static int bond_del_vlan(struct bonding
*bond
, unsigned short vlan_id
)
257 struct vlan_entry
*vlan
, *next
;
260 dprintk("bond: %s, vlan id %d\n", bond
->dev
->name
, vlan_id
);
262 write_lock_bh(&bond
->lock
);
264 list_for_each_entry_safe(vlan
, next
, &bond
->vlan_list
, vlan_list
) {
265 if (vlan
->vlan_id
== vlan_id
) {
266 list_del(&vlan
->vlan_list
);
268 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
269 (bond
->params
.mode
== BOND_MODE_ALB
)) {
270 bond_alb_clear_vlan(bond
, vlan_id
);
273 dprintk("removed VLAN ID %d from bond %s\n", vlan_id
,
278 if (list_empty(&bond
->vlan_list
) &&
279 (bond
->slave_cnt
== 0)) {
280 /* Last VLAN removed and no slaves, so
281 * restore block on adding VLANs. This will
282 * be removed once new slaves that are not
283 * VLAN challenged will be added.
285 bond
->dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
293 dprintk("couldn't find VLAN ID %d in bond %s\n", vlan_id
,
297 write_unlock_bh(&bond
->lock
);
302 * bond_has_challenged_slaves
303 * @bond: the bond we're working on
305 * Searches the slave list. Returns 1 if a vlan challenged slave
306 * was found, 0 otherwise.
308 * Assumes bond->lock is held.
310 static int bond_has_challenged_slaves(struct bonding
*bond
)
315 bond_for_each_slave(bond
, slave
, i
) {
316 if (slave
->dev
->features
& NETIF_F_VLAN_CHALLENGED
) {
317 dprintk("found VLAN challenged slave - %s\n",
323 dprintk("no VLAN challenged slaves found\n");
328 * bond_next_vlan - safely skip to the next item in the vlans list.
329 * @bond: the bond we're working on
330 * @curr: item we're advancing from
332 * Returns %NULL if list is empty, bond->next_vlan if @curr is %NULL,
333 * or @curr->next otherwise (even if it is @curr itself again).
335 * Caller must hold bond->lock
337 struct vlan_entry
*bond_next_vlan(struct bonding
*bond
, struct vlan_entry
*curr
)
339 struct vlan_entry
*next
, *last
;
341 if (list_empty(&bond
->vlan_list
)) {
346 next
= list_entry(bond
->vlan_list
.next
,
347 struct vlan_entry
, vlan_list
);
349 last
= list_entry(bond
->vlan_list
.prev
,
350 struct vlan_entry
, vlan_list
);
352 next
= list_entry(bond
->vlan_list
.next
,
353 struct vlan_entry
, vlan_list
);
355 next
= list_entry(curr
->vlan_list
.next
,
356 struct vlan_entry
, vlan_list
);
364 * bond_dev_queue_xmit - Prepare skb for xmit.
366 * @bond: bond device that got this skb for tx.
367 * @skb: hw accel VLAN tagged skb to transmit
368 * @slave_dev: slave that is supposed to xmit this skbuff
370 * When the bond gets an skb to transmit that is
371 * already hardware accelerated VLAN tagged, and it
372 * needs to relay this skb to a slave that is not
373 * hw accel capable, the skb needs to be "unaccelerated",
374 * i.e. strip the hwaccel tag and re-insert it as part
377 int bond_dev_queue_xmit(struct bonding
*bond
, struct sk_buff
*skb
, struct net_device
*slave_dev
)
379 unsigned short vlan_id
;
381 if (!list_empty(&bond
->vlan_list
) &&
382 !(slave_dev
->features
& NETIF_F_HW_VLAN_TX
) &&
383 vlan_get_tag(skb
, &vlan_id
) == 0) {
384 skb
->dev
= slave_dev
;
385 skb
= vlan_put_tag(skb
, vlan_id
);
387 /* vlan_put_tag() frees the skb in case of error,
388 * so return success here so the calling functions
389 * won't attempt to free is again.
394 skb
->dev
= slave_dev
;
404 * In the following 3 functions, bond_vlan_rx_register(), bond_vlan_rx_add_vid
405 * and bond_vlan_rx_kill_vid, We don't protect the slave list iteration with a
407 * a. This operation is performed in IOCTL context,
408 * b. The operation is protected by the RTNL semaphore in the 8021q code,
409 * c. Holding a lock with BH disabled while directly calling a base driver
410 * entry point is generally a BAD idea.
412 * The design of synchronization/protection for this operation in the 8021q
413 * module is good for one or more VLAN devices over a single physical device
414 * and cannot be extended for a teaming solution like bonding, so there is a
415 * potential race condition here where a net device from the vlan group might
416 * be referenced (either by a base driver or the 8021q code) while it is being
417 * removed from the system. However, it turns out we're not making matters
418 * worse, and if it works for regular VLAN usage it will work here too.
422 * bond_vlan_rx_register - Propagates registration to slaves
423 * @bond_dev: bonding net device that got called
424 * @grp: vlan group being registered
426 static void bond_vlan_rx_register(struct net_device
*bond_dev
, struct vlan_group
*grp
)
428 struct bonding
*bond
= bond_dev
->priv
;
434 bond_for_each_slave(bond
, slave
, i
) {
435 struct net_device
*slave_dev
= slave
->dev
;
437 if ((slave_dev
->features
& NETIF_F_HW_VLAN_RX
) &&
438 slave_dev
->vlan_rx_register
) {
439 slave_dev
->vlan_rx_register(slave_dev
, grp
);
445 * bond_vlan_rx_add_vid - Propagates adding an id to slaves
446 * @bond_dev: bonding net device that got called
447 * @vid: vlan id being added
449 static void bond_vlan_rx_add_vid(struct net_device
*bond_dev
, uint16_t vid
)
451 struct bonding
*bond
= bond_dev
->priv
;
455 bond_for_each_slave(bond
, slave
, i
) {
456 struct net_device
*slave_dev
= slave
->dev
;
458 if ((slave_dev
->features
& NETIF_F_HW_VLAN_FILTER
) &&
459 slave_dev
->vlan_rx_add_vid
) {
460 slave_dev
->vlan_rx_add_vid(slave_dev
, vid
);
464 res
= bond_add_vlan(bond
, vid
);
466 printk(KERN_ERR DRV_NAME
467 ": %s: Error: Failed to add vlan id %d\n",
468 bond_dev
->name
, vid
);
473 * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves
474 * @bond_dev: bonding net device that got called
475 * @vid: vlan id being removed
477 static void bond_vlan_rx_kill_vid(struct net_device
*bond_dev
, uint16_t vid
)
479 struct bonding
*bond
= bond_dev
->priv
;
481 struct net_device
*vlan_dev
;
484 bond_for_each_slave(bond
, slave
, i
) {
485 struct net_device
*slave_dev
= slave
->dev
;
487 if ((slave_dev
->features
& NETIF_F_HW_VLAN_FILTER
) &&
488 slave_dev
->vlan_rx_kill_vid
) {
489 /* Save and then restore vlan_dev in the grp array,
490 * since the slave's driver might clear it.
492 vlan_dev
= vlan_group_get_device(bond
->vlgrp
, vid
);
493 slave_dev
->vlan_rx_kill_vid(slave_dev
, vid
);
494 vlan_group_set_device(bond
->vlgrp
, vid
, vlan_dev
);
498 res
= bond_del_vlan(bond
, vid
);
500 printk(KERN_ERR DRV_NAME
501 ": %s: Error: Failed to remove vlan id %d\n",
502 bond_dev
->name
, vid
);
506 static void bond_add_vlans_on_slave(struct bonding
*bond
, struct net_device
*slave_dev
)
508 struct vlan_entry
*vlan
;
510 write_lock_bh(&bond
->lock
);
512 if (list_empty(&bond
->vlan_list
)) {
516 if ((slave_dev
->features
& NETIF_F_HW_VLAN_RX
) &&
517 slave_dev
->vlan_rx_register
) {
518 slave_dev
->vlan_rx_register(slave_dev
, bond
->vlgrp
);
521 if (!(slave_dev
->features
& NETIF_F_HW_VLAN_FILTER
) ||
522 !(slave_dev
->vlan_rx_add_vid
)) {
526 list_for_each_entry(vlan
, &bond
->vlan_list
, vlan_list
) {
527 slave_dev
->vlan_rx_add_vid(slave_dev
, vlan
->vlan_id
);
531 write_unlock_bh(&bond
->lock
);
534 static void bond_del_vlans_from_slave(struct bonding
*bond
, struct net_device
*slave_dev
)
536 struct vlan_entry
*vlan
;
537 struct net_device
*vlan_dev
;
539 write_lock_bh(&bond
->lock
);
541 if (list_empty(&bond
->vlan_list
)) {
545 if (!(slave_dev
->features
& NETIF_F_HW_VLAN_FILTER
) ||
546 !(slave_dev
->vlan_rx_kill_vid
)) {
550 list_for_each_entry(vlan
, &bond
->vlan_list
, vlan_list
) {
551 /* Save and then restore vlan_dev in the grp array,
552 * since the slave's driver might clear it.
554 vlan_dev
= vlan_group_get_device(bond
->vlgrp
, vlan
->vlan_id
);
555 slave_dev
->vlan_rx_kill_vid(slave_dev
, vlan
->vlan_id
);
556 vlan_group_set_device(bond
->vlgrp
, vlan
->vlan_id
, vlan_dev
);
560 if ((slave_dev
->features
& NETIF_F_HW_VLAN_RX
) &&
561 slave_dev
->vlan_rx_register
) {
562 slave_dev
->vlan_rx_register(slave_dev
, NULL
);
566 write_unlock_bh(&bond
->lock
);
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 static int (* ioctl
)(struct net_device
*, struct ifreq
*, int);
618 struct ethtool_cmd etool
;
620 /* Fake speed and duplex */
621 slave
->speed
= SPEED_100
;
622 slave
->duplex
= DUPLEX_FULL
;
624 if (slave_dev
->ethtool_ops
) {
627 if (!slave_dev
->ethtool_ops
->get_settings
) {
631 res
= slave_dev
->ethtool_ops
->get_settings(slave_dev
, &etool
);
639 ioctl
= slave_dev
->do_ioctl
;
640 strncpy(ifr
.ifr_name
, slave_dev
->name
, IFNAMSIZ
);
641 etool
.cmd
= ETHTOOL_GSET
;
642 ifr
.ifr_data
= (char*)&etool
;
643 if (!ioctl
|| (IOCTL(slave_dev
, &ifr
, SIOCETHTOOL
) < 0)) {
648 switch (etool
.speed
) {
658 switch (etool
.duplex
) {
666 slave
->speed
= etool
.speed
;
667 slave
->duplex
= etool
.duplex
;
673 * if <dev> supports MII link status reporting, check its link status.
675 * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(),
676 * depening upon the setting of the use_carrier parameter.
678 * Return either BMSR_LSTATUS, meaning that the link is up (or we
679 * can't tell and just pretend it is), or 0, meaning that the link is
682 * If reporting is non-zero, instead of faking link up, return -1 if
683 * both ETHTOOL and MII ioctls fail (meaning the device does not
684 * support them). If use_carrier is set, return whatever it says.
685 * It'd be nice if there was a good way to tell if a driver supports
686 * netif_carrier, but there really isn't.
688 static int bond_check_dev_link(struct bonding
*bond
, struct net_device
*slave_dev
, int reporting
)
690 static int (* ioctl
)(struct net_device
*, struct ifreq
*, int);
692 struct mii_ioctl_data
*mii
;
693 struct ethtool_value etool
;
695 if (bond
->params
.use_carrier
) {
696 return netif_carrier_ok(slave_dev
) ? BMSR_LSTATUS
: 0;
699 ioctl
= slave_dev
->do_ioctl
;
701 /* TODO: set pointer to correct ioctl on a per team member */
702 /* bases to make this more efficient. that is, once */
703 /* we determine the correct ioctl, we will always */
704 /* call it and not the others for that team */
708 * We cannot assume that SIOCGMIIPHY will also read a
709 * register; not all network drivers (e.g., e100)
713 /* Yes, the mii is overlaid on the ifreq.ifr_ifru */
714 strncpy(ifr
.ifr_name
, slave_dev
->name
, IFNAMSIZ
);
716 if (IOCTL(slave_dev
, &ifr
, SIOCGMIIPHY
) == 0) {
717 mii
->reg_num
= MII_BMSR
;
718 if (IOCTL(slave_dev
, &ifr
, SIOCGMIIREG
) == 0) {
719 return (mii
->val_out
& BMSR_LSTATUS
);
724 /* try SIOCETHTOOL ioctl, some drivers cache ETHTOOL_GLINK */
725 /* for a period of time so we attempt to get link status */
726 /* from it last if the above MII ioctls fail... */
727 if (slave_dev
->ethtool_ops
) {
728 if (slave_dev
->ethtool_ops
->get_link
) {
731 link
= slave_dev
->ethtool_ops
->get_link(slave_dev
);
733 return link
? BMSR_LSTATUS
: 0;
738 strncpy(ifr
.ifr_name
, slave_dev
->name
, IFNAMSIZ
);
739 etool
.cmd
= ETHTOOL_GLINK
;
740 ifr
.ifr_data
= (char*)&etool
;
741 if (IOCTL(slave_dev
, &ifr
, SIOCETHTOOL
) == 0) {
742 if (etool
.data
== 1) {
745 dprintk("SIOCETHTOOL shows link down\n");
752 * If reporting, report that either there's no dev->do_ioctl,
753 * or both SIOCGMIIREG and SIOCETHTOOL failed (meaning that we
754 * cannot report link status). If not reporting, pretend
757 return (reporting
? -1 : BMSR_LSTATUS
);
760 /*----------------------------- Multicast list ------------------------------*/
763 * Returns 0 if dmi1 and dmi2 are the same, non-0 otherwise
765 static inline int bond_is_dmi_same(struct dev_mc_list
*dmi1
, struct dev_mc_list
*dmi2
)
767 return memcmp(dmi1
->dmi_addr
, dmi2
->dmi_addr
, dmi1
->dmi_addrlen
) == 0 &&
768 dmi1
->dmi_addrlen
== dmi2
->dmi_addrlen
;
772 * returns dmi entry if found, NULL otherwise
774 static struct dev_mc_list
*bond_mc_list_find_dmi(struct dev_mc_list
*dmi
, struct dev_mc_list
*mc_list
)
776 struct dev_mc_list
*idmi
;
778 for (idmi
= mc_list
; idmi
; idmi
= idmi
->next
) {
779 if (bond_is_dmi_same(dmi
, idmi
)) {
788 * Push the promiscuity flag down to appropriate slaves
790 static void bond_set_promiscuity(struct bonding
*bond
, int inc
)
792 if (USES_PRIMARY(bond
->params
.mode
)) {
793 /* write lock already acquired */
794 if (bond
->curr_active_slave
) {
795 dev_set_promiscuity(bond
->curr_active_slave
->dev
, inc
);
800 bond_for_each_slave(bond
, slave
, i
) {
801 dev_set_promiscuity(slave
->dev
, inc
);
807 * Push the allmulti flag down to all slaves
809 static void bond_set_allmulti(struct bonding
*bond
, int inc
)
811 if (USES_PRIMARY(bond
->params
.mode
)) {
812 /* write lock already acquired */
813 if (bond
->curr_active_slave
) {
814 dev_set_allmulti(bond
->curr_active_slave
->dev
, inc
);
819 bond_for_each_slave(bond
, slave
, i
) {
820 dev_set_allmulti(slave
->dev
, inc
);
826 * Add a Multicast address to slaves
829 static void bond_mc_add(struct bonding
*bond
, void *addr
, int alen
)
831 if (USES_PRIMARY(bond
->params
.mode
)) {
832 /* write lock already acquired */
833 if (bond
->curr_active_slave
) {
834 dev_mc_add(bond
->curr_active_slave
->dev
, addr
, alen
, 0);
839 bond_for_each_slave(bond
, slave
, i
) {
840 dev_mc_add(slave
->dev
, addr
, alen
, 0);
846 * Remove a multicast address from slave
849 static void bond_mc_delete(struct bonding
*bond
, void *addr
, int alen
)
851 if (USES_PRIMARY(bond
->params
.mode
)) {
852 /* write lock already acquired */
853 if (bond
->curr_active_slave
) {
854 dev_mc_delete(bond
->curr_active_slave
->dev
, addr
, alen
, 0);
859 bond_for_each_slave(bond
, slave
, i
) {
860 dev_mc_delete(slave
->dev
, addr
, alen
, 0);
867 * Retrieve the list of registered multicast addresses for the bonding
868 * device and retransmit an IGMP JOIN request to the current active
871 static void bond_resend_igmp_join_requests(struct bonding
*bond
)
873 struct in_device
*in_dev
;
874 struct ip_mc_list
*im
;
877 in_dev
= __in_dev_get_rcu(bond
->dev
);
879 for (im
= in_dev
->mc_list
; im
; im
= im
->next
) {
880 ip_mc_rejoin_group(im
);
888 * Totally destroys the mc_list in bond
890 static void bond_mc_list_destroy(struct bonding
*bond
)
892 struct dev_mc_list
*dmi
;
896 bond
->mc_list
= dmi
->next
;
900 bond
->mc_list
= NULL
;
904 * Copy all the Multicast addresses from src to the bonding device dst
906 static int bond_mc_list_copy(struct dev_mc_list
*mc_list
, struct bonding
*bond
,
909 struct dev_mc_list
*dmi
, *new_dmi
;
911 for (dmi
= mc_list
; dmi
; dmi
= dmi
->next
) {
912 new_dmi
= kmalloc(sizeof(struct dev_mc_list
), gfp_flag
);
915 /* FIXME: Potential memory leak !!! */
919 new_dmi
->next
= bond
->mc_list
;
920 bond
->mc_list
= new_dmi
;
921 new_dmi
->dmi_addrlen
= dmi
->dmi_addrlen
;
922 memcpy(new_dmi
->dmi_addr
, dmi
->dmi_addr
, dmi
->dmi_addrlen
);
923 new_dmi
->dmi_users
= dmi
->dmi_users
;
924 new_dmi
->dmi_gusers
= dmi
->dmi_gusers
;
931 * flush all members of flush->mc_list from device dev->mc_list
933 static void bond_mc_list_flush(struct net_device
*bond_dev
, struct net_device
*slave_dev
)
935 struct bonding
*bond
= bond_dev
->priv
;
936 struct dev_mc_list
*dmi
;
938 for (dmi
= bond_dev
->mc_list
; dmi
; dmi
= dmi
->next
) {
939 dev_mc_delete(slave_dev
, dmi
->dmi_addr
, dmi
->dmi_addrlen
, 0);
942 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
943 /* del lacpdu mc addr from mc list */
944 u8 lacpdu_multicast
[ETH_ALEN
] = MULTICAST_LACPDU_ADDR
;
946 dev_mc_delete(slave_dev
, lacpdu_multicast
, ETH_ALEN
, 0);
950 /*--------------------------- Active slave change ---------------------------*/
953 * Update the mc list and multicast-related flags for the new and
954 * old active slaves (if any) according to the multicast mode, and
955 * promiscuous flags unconditionally.
957 static void bond_mc_swap(struct bonding
*bond
, struct slave
*new_active
, struct slave
*old_active
)
959 struct dev_mc_list
*dmi
;
961 if (!USES_PRIMARY(bond
->params
.mode
)) {
962 /* nothing to do - mc list is already up-to-date on
969 if (bond
->dev
->flags
& IFF_PROMISC
) {
970 dev_set_promiscuity(old_active
->dev
, -1);
973 if (bond
->dev
->flags
& IFF_ALLMULTI
) {
974 dev_set_allmulti(old_active
->dev
, -1);
977 for (dmi
= bond
->dev
->mc_list
; dmi
; dmi
= dmi
->next
) {
978 dev_mc_delete(old_active
->dev
, dmi
->dmi_addr
, dmi
->dmi_addrlen
, 0);
983 if (bond
->dev
->flags
& IFF_PROMISC
) {
984 dev_set_promiscuity(new_active
->dev
, 1);
987 if (bond
->dev
->flags
& IFF_ALLMULTI
) {
988 dev_set_allmulti(new_active
->dev
, 1);
991 for (dmi
= bond
->dev
->mc_list
; dmi
; dmi
= dmi
->next
) {
992 dev_mc_add(new_active
->dev
, dmi
->dmi_addr
, dmi
->dmi_addrlen
, 0);
994 bond_resend_igmp_join_requests(bond
);
999 * find_best_interface - select the best available slave to be the active one
1000 * @bond: our bonding struct
1002 * Warning: Caller must hold curr_slave_lock for writing.
1004 static struct slave
*bond_find_best_slave(struct bonding
*bond
)
1006 struct slave
*new_active
, *old_active
;
1007 struct slave
*bestslave
= NULL
;
1008 int mintime
= bond
->params
.updelay
;
1011 new_active
= old_active
= bond
->curr_active_slave
;
1013 if (!new_active
) { /* there were no active slaves left */
1014 if (bond
->slave_cnt
> 0) { /* found one slave */
1015 new_active
= bond
->first_slave
;
1017 return NULL
; /* still no slave, return NULL */
1021 /* first try the primary link; if arping, a link must tx/rx traffic
1022 * before it can be considered the curr_active_slave - also, we would skip
1023 * slaves between the curr_active_slave and primary_slave that may be up
1026 if ((bond
->primary_slave
) &&
1027 (!bond
->params
.arp_interval
) &&
1028 (IS_UP(bond
->primary_slave
->dev
))) {
1029 new_active
= bond
->primary_slave
;
1032 /* remember where to stop iterating over the slaves */
1033 old_active
= new_active
;
1035 bond_for_each_slave_from(bond
, new_active
, i
, old_active
) {
1036 if (IS_UP(new_active
->dev
)) {
1037 if (new_active
->link
== BOND_LINK_UP
) {
1039 } else if (new_active
->link
== BOND_LINK_BACK
) {
1040 /* link up, but waiting for stabilization */
1041 if (new_active
->delay
< mintime
) {
1042 mintime
= new_active
->delay
;
1043 bestslave
= new_active
;
1053 * change_active_interface - change the active slave into the specified one
1054 * @bond: our bonding struct
1055 * @new: the new slave to make the active one
1057 * Set the new slave to the bond's settings and unset them on the old
1058 * curr_active_slave.
1059 * Setting include flags, mc-list, promiscuity, allmulti, etc.
1061 * If @new's link state is %BOND_LINK_BACK we'll set it to %BOND_LINK_UP,
1062 * because it is apparently the best available slave we have, even though its
1063 * updelay hasn't timed out yet.
1065 * Warning: Caller must hold curr_slave_lock for writing.
1067 void bond_change_active_slave(struct bonding
*bond
, struct slave
*new_active
)
1069 struct slave
*old_active
= bond
->curr_active_slave
;
1071 if (old_active
== new_active
) {
1076 if (new_active
->link
== BOND_LINK_BACK
) {
1077 if (USES_PRIMARY(bond
->params
.mode
)) {
1078 printk(KERN_INFO DRV_NAME
1079 ": %s: making interface %s the new "
1080 "active one %d ms earlier.\n",
1081 bond
->dev
->name
, new_active
->dev
->name
,
1082 (bond
->params
.updelay
- new_active
->delay
) * bond
->params
.miimon
);
1085 new_active
->delay
= 0;
1086 new_active
->link
= BOND_LINK_UP
;
1087 new_active
->jiffies
= jiffies
;
1089 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1090 bond_3ad_handle_link_change(new_active
, BOND_LINK_UP
);
1093 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
1094 (bond
->params
.mode
== BOND_MODE_ALB
)) {
1095 bond_alb_handle_link_change(bond
, new_active
, BOND_LINK_UP
);
1098 if (USES_PRIMARY(bond
->params
.mode
)) {
1099 printk(KERN_INFO DRV_NAME
1100 ": %s: making interface %s the new "
1102 bond
->dev
->name
, new_active
->dev
->name
);
1107 if (USES_PRIMARY(bond
->params
.mode
)) {
1108 bond_mc_swap(bond
, new_active
, old_active
);
1111 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
1112 (bond
->params
.mode
== BOND_MODE_ALB
)) {
1113 bond_alb_handle_active_change(bond
, new_active
);
1115 bond_set_slave_inactive_flags(old_active
);
1117 bond_set_slave_active_flags(new_active
);
1119 bond
->curr_active_slave
= new_active
;
1122 if (bond
->params
.mode
== BOND_MODE_ACTIVEBACKUP
) {
1124 bond_set_slave_inactive_flags(old_active
);
1128 bond_set_slave_active_flags(new_active
);
1130 bond_send_gratuitous_arp(bond
);
1135 * bond_select_active_slave - select a new active slave, if needed
1136 * @bond: our bonding struct
1138 * This functions shoud be called when one of the following occurs:
1139 * - The old curr_active_slave has been released or lost its link.
1140 * - The primary_slave has got its link back.
1141 * - A slave has got its link back and there's no old curr_active_slave.
1143 * Warning: Caller must hold curr_slave_lock for writing.
1145 void bond_select_active_slave(struct bonding
*bond
)
1147 struct slave
*best_slave
;
1150 best_slave
= bond_find_best_slave(bond
);
1151 if (best_slave
!= bond
->curr_active_slave
) {
1152 bond_change_active_slave(bond
, best_slave
);
1153 rv
= bond_set_carrier(bond
);
1157 if (netif_carrier_ok(bond
->dev
)) {
1158 printk(KERN_INFO DRV_NAME
1159 ": %s: first active interface up!\n",
1162 printk(KERN_INFO DRV_NAME
": %s: "
1163 "now running without any active interface !\n",
1169 /*--------------------------- slave list handling ---------------------------*/
1172 * This function attaches the slave to the end of list.
1174 * bond->lock held for writing by caller.
1176 static void bond_attach_slave(struct bonding
*bond
, struct slave
*new_slave
)
1178 if (bond
->first_slave
== NULL
) { /* attaching the first slave */
1179 new_slave
->next
= new_slave
;
1180 new_slave
->prev
= new_slave
;
1181 bond
->first_slave
= new_slave
;
1183 new_slave
->next
= bond
->first_slave
;
1184 new_slave
->prev
= bond
->first_slave
->prev
;
1185 new_slave
->next
->prev
= new_slave
;
1186 new_slave
->prev
->next
= new_slave
;
1193 * This function detaches the slave from the list.
1194 * WARNING: no check is made to verify if the slave effectively
1195 * belongs to <bond>.
1196 * Nothing is freed on return, structures are just unchained.
1197 * If any slave pointer in bond was pointing to <slave>,
1198 * it should be changed by the calling function.
1200 * bond->lock held for writing by caller.
1202 static void bond_detach_slave(struct bonding
*bond
, struct slave
*slave
)
1205 slave
->next
->prev
= slave
->prev
;
1209 slave
->prev
->next
= slave
->next
;
1212 if (bond
->first_slave
== slave
) { /* slave is the first slave */
1213 if (bond
->slave_cnt
> 1) { /* there are more slave */
1214 bond
->first_slave
= slave
->next
;
1216 bond
->first_slave
= NULL
; /* slave was the last one */
1225 /*---------------------------------- IOCTL ----------------------------------*/
1227 int bond_sethwaddr(struct net_device
*bond_dev
, struct net_device
*slave_dev
)
1229 dprintk("bond_dev=%p\n", bond_dev
);
1230 dprintk("slave_dev=%p\n", slave_dev
);
1231 dprintk("slave_dev->addr_len=%d\n", slave_dev
->addr_len
);
1232 memcpy(bond_dev
->dev_addr
, slave_dev
->dev_addr
, slave_dev
->addr_len
);
1236 #define BOND_VLAN_FEATURES \
1237 (NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | \
1238 NETIF_F_HW_VLAN_FILTER)
1241 * Compute the common dev->feature set available to all slaves. Some
1242 * feature bits are managed elsewhere, so preserve those feature bits
1243 * on the master device.
1245 static int bond_compute_features(struct bonding
*bond
)
1247 struct slave
*slave
;
1248 struct net_device
*bond_dev
= bond
->dev
;
1249 unsigned long features
= bond_dev
->features
& ~BOND_VLAN_FEATURES
;
1250 unsigned short max_hard_header_len
= ETH_HLEN
;
1253 bond_for_each_slave(bond
, slave
, i
) {
1254 features
= netdev_compute_features(features
,
1255 slave
->dev
->features
);
1256 if (slave
->dev
->hard_header_len
> max_hard_header_len
)
1257 max_hard_header_len
= slave
->dev
->hard_header_len
;
1260 features
|= (bond_dev
->features
& BOND_VLAN_FEATURES
);
1261 bond_dev
->features
= features
;
1262 bond_dev
->hard_header_len
= max_hard_header_len
;
1267 /* enslave device <slave> to bond device <master> */
1268 int bond_enslave(struct net_device
*bond_dev
, struct net_device
*slave_dev
)
1270 struct bonding
*bond
= bond_dev
->priv
;
1271 struct slave
*new_slave
= NULL
;
1272 struct dev_mc_list
*dmi
;
1273 struct sockaddr addr
;
1275 int old_features
= bond_dev
->features
;
1278 if (!bond
->params
.use_carrier
&& slave_dev
->ethtool_ops
== NULL
&&
1279 slave_dev
->do_ioctl
== NULL
) {
1280 printk(KERN_WARNING DRV_NAME
1281 ": %s: Warning: no link monitoring support for %s\n",
1282 bond_dev
->name
, slave_dev
->name
);
1285 /* bond must be initialized by bond_open() before enslaving */
1286 if (!(bond_dev
->flags
& IFF_UP
)) {
1287 dprintk("Error, master_dev is not up\n");
1291 /* already enslaved */
1292 if (slave_dev
->flags
& IFF_SLAVE
) {
1293 dprintk("Error, Device was already enslaved\n");
1297 /* vlan challenged mutual exclusion */
1298 /* no need to lock since we're protected by rtnl_lock */
1299 if (slave_dev
->features
& NETIF_F_VLAN_CHALLENGED
) {
1300 dprintk("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev
->name
);
1301 if (!list_empty(&bond
->vlan_list
)) {
1302 printk(KERN_ERR DRV_NAME
1303 ": %s: Error: cannot enslave VLAN "
1304 "challenged slave %s on VLAN enabled "
1305 "bond %s\n", bond_dev
->name
, slave_dev
->name
,
1309 printk(KERN_WARNING DRV_NAME
1310 ": %s: Warning: enslaved VLAN challenged "
1311 "slave %s. Adding VLANs will be blocked as "
1312 "long as %s is part of bond %s\n",
1313 bond_dev
->name
, slave_dev
->name
, slave_dev
->name
,
1315 bond_dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
1318 dprintk("%s: ! NETIF_F_VLAN_CHALLENGED\n", slave_dev
->name
);
1319 if (bond
->slave_cnt
== 0) {
1320 /* First slave, and it is not VLAN challenged,
1321 * so remove the block of adding VLANs over the bond.
1323 bond_dev
->features
&= ~NETIF_F_VLAN_CHALLENGED
;
1328 * Old ifenslave binaries are no longer supported. These can
1329 * be identified with moderate accurary by the state of the slave:
1330 * the current ifenslave will set the interface down prior to
1331 * enslaving it; the old ifenslave will not.
1333 if ((slave_dev
->flags
& IFF_UP
)) {
1334 printk(KERN_ERR DRV_NAME
": %s is up. "
1335 "This may be due to an out of date ifenslave.\n",
1338 goto err_undo_flags
;
1341 if (slave_dev
->set_mac_address
== NULL
) {
1342 printk(KERN_ERR DRV_NAME
1343 ": %s: Error: The slave device you specified does "
1344 "not support setting the MAC address. "
1345 "Your kernel likely does not support slave "
1346 "devices.\n", bond_dev
->name
);
1348 goto err_undo_flags
;
1351 new_slave
= kzalloc(sizeof(struct slave
), GFP_KERNEL
);
1354 goto err_undo_flags
;
1357 /* save slave's original flags before calling
1358 * netdev_set_master and dev_open
1360 new_slave
->original_flags
= slave_dev
->flags
;
1363 * Save slave's original ("permanent") mac address for modes
1364 * that need it, and for restoring it upon release, and then
1365 * set it to the master's address
1367 memcpy(new_slave
->perm_hwaddr
, slave_dev
->dev_addr
, ETH_ALEN
);
1370 * Set slave to master's mac address. The application already
1371 * set the master's mac address to that of the first slave
1373 memcpy(addr
.sa_data
, bond_dev
->dev_addr
, bond_dev
->addr_len
);
1374 addr
.sa_family
= slave_dev
->type
;
1375 res
= dev_set_mac_address(slave_dev
, &addr
);
1377 dprintk("Error %d calling set_mac_address\n", res
);
1381 res
= netdev_set_master(slave_dev
, bond_dev
);
1383 dprintk("Error %d calling netdev_set_master\n", res
);
1384 goto err_restore_mac
;
1387 /* open the slave since the application closed it */
1388 res
= dev_open(slave_dev
);
1390 dprintk("Openning slave %s failed\n", slave_dev
->name
);
1391 goto err_unset_master
;
1394 new_slave
->dev
= slave_dev
;
1395 slave_dev
->priv_flags
|= IFF_BONDING
;
1397 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
1398 (bond
->params
.mode
== BOND_MODE_ALB
)) {
1399 /* bond_alb_init_slave() must be called before all other stages since
1400 * it might fail and we do not want to have to undo everything
1402 res
= bond_alb_init_slave(bond
, new_slave
);
1408 /* If the mode USES_PRIMARY, then the new slave gets the
1409 * master's promisc (and mc) settings only if it becomes the
1410 * curr_active_slave, and that is taken care of later when calling
1411 * bond_change_active()
1413 if (!USES_PRIMARY(bond
->params
.mode
)) {
1414 /* set promiscuity level to new slave */
1415 if (bond_dev
->flags
& IFF_PROMISC
) {
1416 dev_set_promiscuity(slave_dev
, 1);
1419 /* set allmulti level to new slave */
1420 if (bond_dev
->flags
& IFF_ALLMULTI
) {
1421 dev_set_allmulti(slave_dev
, 1);
1424 /* upload master's mc_list to new slave */
1425 for (dmi
= bond_dev
->mc_list
; dmi
; dmi
= dmi
->next
) {
1426 dev_mc_add (slave_dev
, dmi
->dmi_addr
, dmi
->dmi_addrlen
, 0);
1430 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1431 /* add lacpdu mc addr to mc list */
1432 u8 lacpdu_multicast
[ETH_ALEN
] = MULTICAST_LACPDU_ADDR
;
1434 dev_mc_add(slave_dev
, lacpdu_multicast
, ETH_ALEN
, 0);
1437 bond_add_vlans_on_slave(bond
, slave_dev
);
1439 write_lock_bh(&bond
->lock
);
1441 bond_attach_slave(bond
, new_slave
);
1443 new_slave
->delay
= 0;
1444 new_slave
->link_failure_count
= 0;
1446 bond_compute_features(bond
);
1448 new_slave
->last_arp_rx
= jiffies
;
1450 if (bond
->params
.miimon
&& !bond
->params
.use_carrier
) {
1451 link_reporting
= bond_check_dev_link(bond
, slave_dev
, 1);
1453 if ((link_reporting
== -1) && !bond
->params
.arp_interval
) {
1455 * miimon is set but a bonded network driver
1456 * does not support ETHTOOL/MII and
1457 * arp_interval is not set. Note: if
1458 * use_carrier is enabled, we will never go
1459 * here (because netif_carrier is always
1460 * supported); thus, we don't need to change
1461 * the messages for netif_carrier.
1463 printk(KERN_WARNING DRV_NAME
1464 ": %s: Warning: MII and ETHTOOL support not "
1465 "available for interface %s, and "
1466 "arp_interval/arp_ip_target module parameters "
1467 "not specified, thus bonding will not detect "
1468 "link failures! see bonding.txt for details.\n",
1469 bond_dev
->name
, slave_dev
->name
);
1470 } else if (link_reporting
== -1) {
1471 /* unable get link status using mii/ethtool */
1472 printk(KERN_WARNING DRV_NAME
1473 ": %s: Warning: can't get link status from "
1474 "interface %s; the network driver associated "
1475 "with this interface does not support MII or "
1476 "ETHTOOL link status reporting, thus miimon "
1477 "has no effect on this interface.\n",
1478 bond_dev
->name
, slave_dev
->name
);
1482 /* check for initial state */
1483 if (!bond
->params
.miimon
||
1484 (bond_check_dev_link(bond
, slave_dev
, 0) == BMSR_LSTATUS
)) {
1485 if (bond
->params
.updelay
) {
1486 dprintk("Initial state of slave_dev is "
1487 "BOND_LINK_BACK\n");
1488 new_slave
->link
= BOND_LINK_BACK
;
1489 new_slave
->delay
= bond
->params
.updelay
;
1491 dprintk("Initial state of slave_dev is "
1493 new_slave
->link
= BOND_LINK_UP
;
1495 new_slave
->jiffies
= jiffies
;
1497 dprintk("Initial state of slave_dev is "
1498 "BOND_LINK_DOWN\n");
1499 new_slave
->link
= BOND_LINK_DOWN
;
1502 if (bond_update_speed_duplex(new_slave
) &&
1503 (new_slave
->link
!= BOND_LINK_DOWN
)) {
1504 printk(KERN_WARNING DRV_NAME
1505 ": %s: Warning: failed to get speed and duplex from %s, "
1506 "assumed to be 100Mb/sec and Full.\n",
1507 bond_dev
->name
, new_slave
->dev
->name
);
1509 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1510 printk(KERN_WARNING DRV_NAME
1511 ": %s: Warning: Operation of 802.3ad mode requires ETHTOOL "
1512 "support in base driver for proper aggregator "
1513 "selection.\n", bond_dev
->name
);
1517 if (USES_PRIMARY(bond
->params
.mode
) && bond
->params
.primary
[0]) {
1518 /* if there is a primary slave, remember it */
1519 if (strcmp(bond
->params
.primary
, new_slave
->dev
->name
) == 0) {
1520 bond
->primary_slave
= new_slave
;
1524 switch (bond
->params
.mode
) {
1525 case BOND_MODE_ACTIVEBACKUP
:
1526 bond_set_slave_inactive_flags(new_slave
);
1527 bond_select_active_slave(bond
);
1529 case BOND_MODE_8023AD
:
1530 /* in 802.3ad mode, the internal mechanism
1531 * will activate the slaves in the selected
1534 bond_set_slave_inactive_flags(new_slave
);
1535 /* if this is the first slave */
1536 if (bond
->slave_cnt
== 1) {
1537 SLAVE_AD_INFO(new_slave
).id
= 1;
1538 /* Initialize AD with the number of times that the AD timer is called in 1 second
1539 * can be called only after the mac address of the bond is set
1541 bond_3ad_initialize(bond
, 1000/AD_TIMER_INTERVAL
,
1542 bond
->params
.lacp_fast
);
1544 SLAVE_AD_INFO(new_slave
).id
=
1545 SLAVE_AD_INFO(new_slave
->prev
).id
+ 1;
1548 bond_3ad_bind_slave(new_slave
);
1552 new_slave
->state
= BOND_STATE_ACTIVE
;
1553 if ((!bond
->curr_active_slave
) &&
1554 (new_slave
->link
!= BOND_LINK_DOWN
)) {
1555 /* first slave or no active slave yet, and this link
1556 * is OK, so make this interface the active one
1558 bond_change_active_slave(bond
, new_slave
);
1560 bond_set_slave_inactive_flags(new_slave
);
1564 dprintk("This slave is always active in trunk mode\n");
1566 /* always active in trunk mode */
1567 new_slave
->state
= BOND_STATE_ACTIVE
;
1569 /* In trunking mode there is little meaning to curr_active_slave
1570 * anyway (it holds no special properties of the bond device),
1571 * so we can change it without calling change_active_interface()
1573 if (!bond
->curr_active_slave
) {
1574 bond
->curr_active_slave
= new_slave
;
1577 } /* switch(bond_mode) */
1579 bond_set_carrier(bond
);
1581 write_unlock_bh(&bond
->lock
);
1583 res
= bond_create_slave_symlinks(bond_dev
, slave_dev
);
1587 printk(KERN_INFO DRV_NAME
1588 ": %s: enslaving %s as a%s interface with a%s link.\n",
1589 bond_dev
->name
, slave_dev
->name
,
1590 new_slave
->state
== BOND_STATE_ACTIVE
? "n active" : " backup",
1591 new_slave
->link
!= BOND_LINK_DOWN
? "n up" : " down");
1593 /* enslave is successful */
1596 /* Undo stages on error */
1598 dev_close(slave_dev
);
1601 netdev_set_master(slave_dev
, NULL
);
1604 memcpy(addr
.sa_data
, new_slave
->perm_hwaddr
, ETH_ALEN
);
1605 addr
.sa_family
= slave_dev
->type
;
1606 dev_set_mac_address(slave_dev
, &addr
);
1612 bond_dev
->features
= old_features
;
1618 * Try to release the slave device <slave> from the bond device <master>
1619 * It is legal to access curr_active_slave without a lock because all the function
1622 * The rules for slave state should be:
1623 * for Active/Backup:
1624 * Active stays on all backups go down
1625 * for Bonded connections:
1626 * The first up interface should be left on and all others downed.
1628 int bond_release(struct net_device
*bond_dev
, struct net_device
*slave_dev
)
1630 struct bonding
*bond
= bond_dev
->priv
;
1631 struct slave
*slave
, *oldcurrent
;
1632 struct sockaddr addr
;
1633 int mac_addr_differ
;
1635 /* slave is not a slave or master is not master of this slave */
1636 if (!(slave_dev
->flags
& IFF_SLAVE
) ||
1637 (slave_dev
->master
!= bond_dev
)) {
1638 printk(KERN_ERR DRV_NAME
1639 ": %s: Error: cannot release %s.\n",
1640 bond_dev
->name
, slave_dev
->name
);
1644 write_lock_bh(&bond
->lock
);
1646 slave
= bond_get_slave_by_dev(bond
, slave_dev
);
1648 /* not a slave of this bond */
1649 printk(KERN_INFO DRV_NAME
1650 ": %s: %s not enslaved\n",
1651 bond_dev
->name
, slave_dev
->name
);
1652 write_unlock_bh(&bond
->lock
);
1656 mac_addr_differ
= memcmp(bond_dev
->dev_addr
,
1659 if (!mac_addr_differ
&& (bond
->slave_cnt
> 1)) {
1660 printk(KERN_WARNING DRV_NAME
1661 ": %s: Warning: the permanent HWaddr of %s "
1662 "- %02X:%02X:%02X:%02X:%02X:%02X - is "
1663 "still in use by %s. Set the HWaddr of "
1664 "%s to a different address to avoid "
1668 slave
->perm_hwaddr
[0],
1669 slave
->perm_hwaddr
[1],
1670 slave
->perm_hwaddr
[2],
1671 slave
->perm_hwaddr
[3],
1672 slave
->perm_hwaddr
[4],
1673 slave
->perm_hwaddr
[5],
1678 /* Inform AD package of unbinding of slave. */
1679 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1680 /* must be called before the slave is
1681 * detached from the list
1683 bond_3ad_unbind_slave(slave
);
1686 printk(KERN_INFO DRV_NAME
1687 ": %s: releasing %s interface %s\n",
1689 (slave
->state
== BOND_STATE_ACTIVE
)
1690 ? "active" : "backup",
1693 oldcurrent
= bond
->curr_active_slave
;
1695 bond
->current_arp_slave
= NULL
;
1697 /* release the slave from its bond */
1698 bond_detach_slave(bond
, slave
);
1700 bond_compute_features(bond
);
1702 if (bond
->primary_slave
== slave
) {
1703 bond
->primary_slave
= NULL
;
1706 if (oldcurrent
== slave
) {
1707 bond_change_active_slave(bond
, NULL
);
1710 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
1711 (bond
->params
.mode
== BOND_MODE_ALB
)) {
1712 /* Must be called only after the slave has been
1713 * detached from the list and the curr_active_slave
1714 * has been cleared (if our_slave == old_current),
1715 * but before a new active slave is selected.
1717 bond_alb_deinit_slave(bond
, slave
);
1720 if (oldcurrent
== slave
)
1721 bond_select_active_slave(bond
);
1723 if (bond
->slave_cnt
== 0) {
1724 bond_set_carrier(bond
);
1726 /* if the last slave was removed, zero the mac address
1727 * of the master so it will be set by the application
1728 * to the mac address of the first slave
1730 memset(bond_dev
->dev_addr
, 0, bond_dev
->addr_len
);
1732 if (list_empty(&bond
->vlan_list
)) {
1733 bond_dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
1735 printk(KERN_WARNING DRV_NAME
1736 ": %s: Warning: clearing HW address of %s while it "
1737 "still has VLANs.\n",
1738 bond_dev
->name
, bond_dev
->name
);
1739 printk(KERN_WARNING DRV_NAME
1740 ": %s: When re-adding slaves, make sure the bond's "
1741 "HW address matches its VLANs'.\n",
1744 } else if ((bond_dev
->features
& NETIF_F_VLAN_CHALLENGED
) &&
1745 !bond_has_challenged_slaves(bond
)) {
1746 printk(KERN_INFO DRV_NAME
1747 ": %s: last VLAN challenged slave %s "
1748 "left bond %s. VLAN blocking is removed\n",
1749 bond_dev
->name
, slave_dev
->name
, bond_dev
->name
);
1750 bond_dev
->features
&= ~NETIF_F_VLAN_CHALLENGED
;
1753 write_unlock_bh(&bond
->lock
);
1755 /* must do this from outside any spinlocks */
1756 bond_destroy_slave_symlinks(bond_dev
, slave_dev
);
1758 bond_del_vlans_from_slave(bond
, slave_dev
);
1760 /* If the mode USES_PRIMARY, then we should only remove its
1761 * promisc and mc settings if it was the curr_active_slave, but that was
1762 * already taken care of above when we detached the slave
1764 if (!USES_PRIMARY(bond
->params
.mode
)) {
1765 /* unset promiscuity level from slave */
1766 if (bond_dev
->flags
& IFF_PROMISC
) {
1767 dev_set_promiscuity(slave_dev
, -1);
1770 /* unset allmulti level from slave */
1771 if (bond_dev
->flags
& IFF_ALLMULTI
) {
1772 dev_set_allmulti(slave_dev
, -1);
1775 /* flush master's mc_list from slave */
1776 bond_mc_list_flush(bond_dev
, slave_dev
);
1779 netdev_set_master(slave_dev
, NULL
);
1781 /* close slave before restoring its mac address */
1782 dev_close(slave_dev
);
1784 /* restore original ("permanent") mac address */
1785 memcpy(addr
.sa_data
, slave
->perm_hwaddr
, ETH_ALEN
);
1786 addr
.sa_family
= slave_dev
->type
;
1787 dev_set_mac_address(slave_dev
, &addr
);
1789 slave_dev
->priv_flags
&= ~(IFF_MASTER_8023AD
| IFF_MASTER_ALB
|
1790 IFF_SLAVE_INACTIVE
| IFF_BONDING
|
1795 return 0; /* deletion OK */
1799 * This function releases all slaves.
1801 static int bond_release_all(struct net_device
*bond_dev
)
1803 struct bonding
*bond
= bond_dev
->priv
;
1804 struct slave
*slave
;
1805 struct net_device
*slave_dev
;
1806 struct sockaddr addr
;
1808 write_lock_bh(&bond
->lock
);
1810 netif_carrier_off(bond_dev
);
1812 if (bond
->slave_cnt
== 0) {
1816 bond
->current_arp_slave
= NULL
;
1817 bond
->primary_slave
= NULL
;
1818 bond_change_active_slave(bond
, NULL
);
1820 while ((slave
= bond
->first_slave
) != NULL
) {
1821 /* Inform AD package of unbinding of slave
1822 * before slave is detached from the list.
1824 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
1825 bond_3ad_unbind_slave(slave
);
1828 slave_dev
= slave
->dev
;
1829 bond_detach_slave(bond
, slave
);
1831 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
1832 (bond
->params
.mode
== BOND_MODE_ALB
)) {
1833 /* must be called only after the slave
1834 * has been detached from the list
1836 bond_alb_deinit_slave(bond
, slave
);
1839 bond_compute_features(bond
);
1841 /* now that the slave is detached, unlock and perform
1842 * all the undo steps that should not be called from
1845 write_unlock_bh(&bond
->lock
);
1847 bond_destroy_slave_symlinks(bond_dev
, slave_dev
);
1848 bond_del_vlans_from_slave(bond
, slave_dev
);
1850 /* If the mode USES_PRIMARY, then we should only remove its
1851 * promisc and mc settings if it was the curr_active_slave, but that was
1852 * already taken care of above when we detached the slave
1854 if (!USES_PRIMARY(bond
->params
.mode
)) {
1855 /* unset promiscuity level from slave */
1856 if (bond_dev
->flags
& IFF_PROMISC
) {
1857 dev_set_promiscuity(slave_dev
, -1);
1860 /* unset allmulti level from slave */
1861 if (bond_dev
->flags
& IFF_ALLMULTI
) {
1862 dev_set_allmulti(slave_dev
, -1);
1865 /* flush master's mc_list from slave */
1866 bond_mc_list_flush(bond_dev
, slave_dev
);
1869 netdev_set_master(slave_dev
, NULL
);
1871 /* close slave before restoring its mac address */
1872 dev_close(slave_dev
);
1874 /* restore original ("permanent") mac address*/
1875 memcpy(addr
.sa_data
, slave
->perm_hwaddr
, ETH_ALEN
);
1876 addr
.sa_family
= slave_dev
->type
;
1877 dev_set_mac_address(slave_dev
, &addr
);
1879 slave_dev
->priv_flags
&= ~(IFF_MASTER_8023AD
| IFF_MASTER_ALB
|
1880 IFF_SLAVE_INACTIVE
);
1884 /* re-acquire the lock before getting the next slave */
1885 write_lock_bh(&bond
->lock
);
1888 /* zero the mac address of the master so it will be
1889 * set by the application to the mac address of the
1892 memset(bond_dev
->dev_addr
, 0, bond_dev
->addr_len
);
1894 if (list_empty(&bond
->vlan_list
)) {
1895 bond_dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
1897 printk(KERN_WARNING DRV_NAME
1898 ": %s: Warning: clearing HW address of %s while it "
1899 "still has VLANs.\n",
1900 bond_dev
->name
, bond_dev
->name
);
1901 printk(KERN_WARNING DRV_NAME
1902 ": %s: When re-adding slaves, make sure the bond's "
1903 "HW address matches its VLANs'.\n",
1907 printk(KERN_INFO DRV_NAME
1908 ": %s: released all slaves\n",
1912 write_unlock_bh(&bond
->lock
);
1918 * This function changes the active slave to slave <slave_dev>.
1919 * It returns -EINVAL in the following cases.
1920 * - <slave_dev> is not found in the list.
1921 * - There is not active slave now.
1922 * - <slave_dev> is already active.
1923 * - The link state of <slave_dev> is not BOND_LINK_UP.
1924 * - <slave_dev> is not running.
1925 * In these cases, this fuction does nothing.
1926 * In the other cases, currnt_slave pointer is changed and 0 is returned.
1928 static int bond_ioctl_change_active(struct net_device
*bond_dev
, struct net_device
*slave_dev
)
1930 struct bonding
*bond
= bond_dev
->priv
;
1931 struct slave
*old_active
= NULL
;
1932 struct slave
*new_active
= NULL
;
1935 if (!USES_PRIMARY(bond
->params
.mode
)) {
1939 /* Verify that master_dev is indeed the master of slave_dev */
1940 if (!(slave_dev
->flags
& IFF_SLAVE
) ||
1941 (slave_dev
->master
!= bond_dev
)) {
1945 write_lock_bh(&bond
->lock
);
1947 old_active
= bond
->curr_active_slave
;
1948 new_active
= bond_get_slave_by_dev(bond
, slave_dev
);
1951 * Changing to the current active: do nothing; return success.
1953 if (new_active
&& (new_active
== old_active
)) {
1954 write_unlock_bh(&bond
->lock
);
1960 (new_active
->link
== BOND_LINK_UP
) &&
1961 IS_UP(new_active
->dev
)) {
1962 bond_change_active_slave(bond
, new_active
);
1967 write_unlock_bh(&bond
->lock
);
1972 static int bond_info_query(struct net_device
*bond_dev
, struct ifbond
*info
)
1974 struct bonding
*bond
= bond_dev
->priv
;
1976 info
->bond_mode
= bond
->params
.mode
;
1977 info
->miimon
= bond
->params
.miimon
;
1979 read_lock_bh(&bond
->lock
);
1980 info
->num_slaves
= bond
->slave_cnt
;
1981 read_unlock_bh(&bond
->lock
);
1986 static int bond_slave_info_query(struct net_device
*bond_dev
, struct ifslave
*info
)
1988 struct bonding
*bond
= bond_dev
->priv
;
1989 struct slave
*slave
;
1992 if (info
->slave_id
< 0) {
1996 read_lock_bh(&bond
->lock
);
1998 bond_for_each_slave(bond
, slave
, i
) {
1999 if (i
== (int)info
->slave_id
) {
2005 read_unlock_bh(&bond
->lock
);
2008 strcpy(info
->slave_name
, slave
->dev
->name
);
2009 info
->link
= slave
->link
;
2010 info
->state
= slave
->state
;
2011 info
->link_failure_count
= slave
->link_failure_count
;
2019 /*-------------------------------- Monitoring -------------------------------*/
2021 /* this function is called regularly to monitor each slave's link. */
2022 void bond_mii_monitor(struct net_device
*bond_dev
)
2024 struct bonding
*bond
= bond_dev
->priv
;
2025 struct slave
*slave
, *oldcurrent
;
2026 int do_failover
= 0;
2030 read_lock(&bond
->lock
);
2032 delta_in_ticks
= (bond
->params
.miimon
* HZ
) / 1000;
2034 if (bond
->kill_timers
) {
2038 if (bond
->slave_cnt
== 0) {
2042 /* we will try to read the link status of each of our slaves, and
2043 * set their IFF_RUNNING flag appropriately. For each slave not
2044 * supporting MII status, we won't do anything so that a user-space
2045 * program could monitor the link itself if needed.
2048 read_lock(&bond
->curr_slave_lock
);
2049 oldcurrent
= bond
->curr_active_slave
;
2050 read_unlock(&bond
->curr_slave_lock
);
2052 bond_for_each_slave(bond
, slave
, i
) {
2053 struct net_device
*slave_dev
= slave
->dev
;
2055 u16 old_speed
= slave
->speed
;
2056 u8 old_duplex
= slave
->duplex
;
2058 link_state
= bond_check_dev_link(bond
, slave_dev
, 0);
2060 switch (slave
->link
) {
2061 case BOND_LINK_UP
: /* the link was up */
2062 if (link_state
== BMSR_LSTATUS
) {
2063 /* link stays up, nothing more to do */
2065 } else { /* link going down */
2066 slave
->link
= BOND_LINK_FAIL
;
2067 slave
->delay
= bond
->params
.downdelay
;
2069 if (slave
->link_failure_count
< UINT_MAX
) {
2070 slave
->link_failure_count
++;
2073 if (bond
->params
.downdelay
) {
2074 printk(KERN_INFO DRV_NAME
2075 ": %s: link status down for %s "
2076 "interface %s, disabling it in "
2080 ? ((bond
->params
.mode
== BOND_MODE_ACTIVEBACKUP
)
2081 ? ((slave
== oldcurrent
)
2082 ? "active " : "backup ")
2086 bond
->params
.downdelay
* bond
->params
.miimon
);
2089 /* no break ! fall through the BOND_LINK_FAIL test to
2090 ensure proper action to be taken
2092 case BOND_LINK_FAIL
: /* the link has just gone down */
2093 if (link_state
!= BMSR_LSTATUS
) {
2094 /* link stays down */
2095 if (slave
->delay
<= 0) {
2096 /* link down for too long time */
2097 slave
->link
= BOND_LINK_DOWN
;
2099 /* in active/backup mode, we must
2100 * completely disable this interface
2102 if ((bond
->params
.mode
== BOND_MODE_ACTIVEBACKUP
) ||
2103 (bond
->params
.mode
== BOND_MODE_8023AD
)) {
2104 bond_set_slave_inactive_flags(slave
);
2107 printk(KERN_INFO DRV_NAME
2108 ": %s: link status definitely "
2109 "down for interface %s, "
2114 /* notify ad that the link status has changed */
2115 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
2116 bond_3ad_handle_link_change(slave
, BOND_LINK_DOWN
);
2119 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
2120 (bond
->params
.mode
== BOND_MODE_ALB
)) {
2121 bond_alb_handle_link_change(bond
, slave
, BOND_LINK_DOWN
);
2124 if (slave
== oldcurrent
) {
2132 slave
->link
= BOND_LINK_UP
;
2133 slave
->jiffies
= jiffies
;
2134 printk(KERN_INFO DRV_NAME
2135 ": %s: link status up again after %d "
2136 "ms for interface %s.\n",
2138 (bond
->params
.downdelay
- slave
->delay
) * bond
->params
.miimon
,
2142 case BOND_LINK_DOWN
: /* the link was down */
2143 if (link_state
!= BMSR_LSTATUS
) {
2144 /* the link stays down, nothing more to do */
2146 } else { /* link going up */
2147 slave
->link
= BOND_LINK_BACK
;
2148 slave
->delay
= bond
->params
.updelay
;
2150 if (bond
->params
.updelay
) {
2151 /* if updelay == 0, no need to
2152 advertise about a 0 ms delay */
2153 printk(KERN_INFO DRV_NAME
2154 ": %s: link status up for "
2155 "interface %s, enabling it "
2159 bond
->params
.updelay
* bond
->params
.miimon
);
2162 /* no break ! fall through the BOND_LINK_BACK state in
2163 case there's something to do.
2165 case BOND_LINK_BACK
: /* the link has just come back */
2166 if (link_state
!= BMSR_LSTATUS
) {
2167 /* link down again */
2168 slave
->link
= BOND_LINK_DOWN
;
2170 printk(KERN_INFO DRV_NAME
2171 ": %s: link status down again after %d "
2172 "ms for interface %s.\n",
2174 (bond
->params
.updelay
- slave
->delay
) * bond
->params
.miimon
,
2178 if (slave
->delay
== 0) {
2179 /* now the link has been up for long time enough */
2180 slave
->link
= BOND_LINK_UP
;
2181 slave
->jiffies
= jiffies
;
2183 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
2184 /* prevent it from being the active one */
2185 slave
->state
= BOND_STATE_BACKUP
;
2186 } else if (bond
->params
.mode
!= BOND_MODE_ACTIVEBACKUP
) {
2187 /* make it immediately active */
2188 slave
->state
= BOND_STATE_ACTIVE
;
2189 } else if (slave
!= bond
->primary_slave
) {
2190 /* prevent it from being the active one */
2191 slave
->state
= BOND_STATE_BACKUP
;
2194 printk(KERN_INFO DRV_NAME
2195 ": %s: link status definitely "
2196 "up for interface %s.\n",
2200 /* notify ad that the link status has changed */
2201 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
2202 bond_3ad_handle_link_change(slave
, BOND_LINK_UP
);
2205 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
2206 (bond
->params
.mode
== BOND_MODE_ALB
)) {
2207 bond_alb_handle_link_change(bond
, slave
, BOND_LINK_UP
);
2210 if ((!oldcurrent
) ||
2211 (slave
== bond
->primary_slave
)) {
2220 /* Should not happen */
2221 printk(KERN_ERR DRV_NAME
2222 ": %s: Error: %s Illegal value (link=%d)\n",
2227 } /* end of switch (slave->link) */
2229 bond_update_speed_duplex(slave
);
2231 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
2232 if (old_speed
!= slave
->speed
) {
2233 bond_3ad_adapter_speed_changed(slave
);
2236 if (old_duplex
!= slave
->duplex
) {
2237 bond_3ad_adapter_duplex_changed(slave
);
2244 write_lock(&bond
->curr_slave_lock
);
2246 bond_select_active_slave(bond
);
2248 write_unlock(&bond
->curr_slave_lock
);
2250 bond_set_carrier(bond
);
2253 if (bond
->params
.miimon
) {
2254 mod_timer(&bond
->mii_timer
, jiffies
+ delta_in_ticks
);
2257 read_unlock(&bond
->lock
);
2261 static u32
bond_glean_dev_ip(struct net_device
*dev
)
2263 struct in_device
*idev
;
2264 struct in_ifaddr
*ifa
;
2271 idev
= __in_dev_get_rcu(dev
);
2275 ifa
= idev
->ifa_list
;
2279 addr
= ifa
->ifa_local
;
2285 static int bond_has_ip(struct bonding
*bond
)
2287 struct vlan_entry
*vlan
, *vlan_next
;
2289 if (bond
->master_ip
)
2292 if (list_empty(&bond
->vlan_list
))
2295 list_for_each_entry_safe(vlan
, vlan_next
, &bond
->vlan_list
,
2304 static int bond_has_this_ip(struct bonding
*bond
, u32 ip
)
2306 struct vlan_entry
*vlan
, *vlan_next
;
2308 if (ip
== bond
->master_ip
)
2311 if (list_empty(&bond
->vlan_list
))
2314 list_for_each_entry_safe(vlan
, vlan_next
, &bond
->vlan_list
,
2316 if (ip
== vlan
->vlan_ip
)
2324 * We go to the (large) trouble of VLAN tagging ARP frames because
2325 * switches in VLAN mode (especially if ports are configured as
2326 * "native" to a VLAN) might not pass non-tagged frames.
2328 static void bond_arp_send(struct net_device
*slave_dev
, int arp_op
, u32 dest_ip
, u32 src_ip
, unsigned short vlan_id
)
2330 struct sk_buff
*skb
;
2332 dprintk("arp %d on slave %s: dst %x src %x vid %d\n", arp_op
,
2333 slave_dev
->name
, dest_ip
, src_ip
, vlan_id
);
2335 skb
= arp_create(arp_op
, ETH_P_ARP
, dest_ip
, slave_dev
, src_ip
,
2336 NULL
, slave_dev
->dev_addr
, NULL
);
2339 printk(KERN_ERR DRV_NAME
": ARP packet allocation failed\n");
2343 skb
= vlan_put_tag(skb
, vlan_id
);
2345 printk(KERN_ERR DRV_NAME
": failed to insert VLAN tag\n");
2353 static void bond_arp_send_all(struct bonding
*bond
, struct slave
*slave
)
2356 u32
*targets
= bond
->params
.arp_targets
;
2357 struct vlan_entry
*vlan
, *vlan_next
;
2358 struct net_device
*vlan_dev
;
2362 for (i
= 0; (i
< BOND_MAX_ARP_TARGETS
); i
++) {
2365 dprintk("basa: target %x\n", targets
[i
]);
2366 if (list_empty(&bond
->vlan_list
)) {
2367 dprintk("basa: empty vlan: arp_send\n");
2368 bond_arp_send(slave
->dev
, ARPOP_REQUEST
, targets
[i
],
2369 bond
->master_ip
, 0);
2374 * If VLANs are configured, we do a route lookup to
2375 * determine which VLAN interface would be used, so we
2376 * can tag the ARP with the proper VLAN tag.
2378 memset(&fl
, 0, sizeof(fl
));
2379 fl
.fl4_dst
= targets
[i
];
2380 fl
.fl4_tos
= RTO_ONLINK
;
2382 rv
= ip_route_output_key(&rt
, &fl
);
2384 if (net_ratelimit()) {
2385 printk(KERN_WARNING DRV_NAME
2386 ": %s: no route to arp_ip_target %u.%u.%u.%u\n",
2387 bond
->dev
->name
, NIPQUAD(fl
.fl4_dst
));
2393 * This target is not on a VLAN
2395 if (rt
->u
.dst
.dev
== bond
->dev
) {
2397 dprintk("basa: rtdev == bond->dev: arp_send\n");
2398 bond_arp_send(slave
->dev
, ARPOP_REQUEST
, targets
[i
],
2399 bond
->master_ip
, 0);
2404 list_for_each_entry_safe(vlan
, vlan_next
, &bond
->vlan_list
,
2406 vlan_dev
= vlan_group_get_device(bond
->vlgrp
, vlan
->vlan_id
);
2407 if (vlan_dev
== rt
->u
.dst
.dev
) {
2408 vlan_id
= vlan
->vlan_id
;
2409 dprintk("basa: vlan match on %s %d\n",
2410 vlan_dev
->name
, vlan_id
);
2417 bond_arp_send(slave
->dev
, ARPOP_REQUEST
, targets
[i
],
2418 vlan
->vlan_ip
, vlan_id
);
2422 if (net_ratelimit()) {
2423 printk(KERN_WARNING DRV_NAME
2424 ": %s: no path to arp_ip_target %u.%u.%u.%u via rt.dev %s\n",
2425 bond
->dev
->name
, NIPQUAD(fl
.fl4_dst
),
2426 rt
->u
.dst
.dev
? rt
->u
.dst
.dev
->name
: "NULL");
2433 * Kick out a gratuitous ARP for an IP on the bonding master plus one
2434 * for each VLAN above us.
2436 static void bond_send_gratuitous_arp(struct bonding
*bond
)
2438 struct slave
*slave
= bond
->curr_active_slave
;
2439 struct vlan_entry
*vlan
;
2440 struct net_device
*vlan_dev
;
2442 dprintk("bond_send_grat_arp: bond %s slave %s\n", bond
->dev
->name
,
2443 slave
? slave
->dev
->name
: "NULL");
2447 if (bond
->master_ip
) {
2448 bond_arp_send(slave
->dev
, ARPOP_REPLY
, bond
->master_ip
,
2449 bond
->master_ip
, 0);
2452 list_for_each_entry(vlan
, &bond
->vlan_list
, vlan_list
) {
2453 vlan_dev
= vlan_group_get_device(bond
->vlgrp
, vlan
->vlan_id
);
2454 if (vlan
->vlan_ip
) {
2455 bond_arp_send(slave
->dev
, ARPOP_REPLY
, vlan
->vlan_ip
,
2456 vlan
->vlan_ip
, vlan
->vlan_id
);
2461 static void bond_validate_arp(struct bonding
*bond
, struct slave
*slave
, u32 sip
, u32 tip
)
2464 u32
*targets
= bond
->params
.arp_targets
;
2466 targets
= bond
->params
.arp_targets
;
2467 for (i
= 0; (i
< BOND_MAX_ARP_TARGETS
) && targets
[i
]; i
++) {
2468 dprintk("bva: sip %u.%u.%u.%u tip %u.%u.%u.%u t[%d] "
2469 "%u.%u.%u.%u bhti(tip) %d\n",
2470 NIPQUAD(sip
), NIPQUAD(tip
), i
, NIPQUAD(targets
[i
]),
2471 bond_has_this_ip(bond
, tip
));
2472 if (sip
== targets
[i
]) {
2473 if (bond_has_this_ip(bond
, tip
))
2474 slave
->last_arp_rx
= jiffies
;
2480 static int bond_arp_rcv(struct sk_buff
*skb
, struct net_device
*dev
, struct packet_type
*pt
, struct net_device
*orig_dev
)
2483 struct slave
*slave
;
2484 struct bonding
*bond
;
2485 unsigned char *arp_ptr
;
2488 if (!(dev
->priv_flags
& IFF_BONDING
) || !(dev
->flags
& IFF_MASTER
))
2492 read_lock(&bond
->lock
);
2494 dprintk("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n",
2495 bond
->dev
->name
, skb
->dev
? skb
->dev
->name
: "NULL",
2496 orig_dev
? orig_dev
->name
: "NULL");
2498 slave
= bond_get_slave_by_dev(bond
, orig_dev
);
2499 if (!slave
|| !slave_do_arp_validate(bond
, slave
))
2502 /* ARP header, plus 2 device addresses, plus 2 IP addresses. */
2503 if (!pskb_may_pull(skb
, (sizeof(struct arphdr
) +
2504 (2 * dev
->addr_len
) +
2505 (2 * sizeof(u32
)))))
2509 if (arp
->ar_hln
!= dev
->addr_len
||
2510 skb
->pkt_type
== PACKET_OTHERHOST
||
2511 skb
->pkt_type
== PACKET_LOOPBACK
||
2512 arp
->ar_hrd
!= htons(ARPHRD_ETHER
) ||
2513 arp
->ar_pro
!= htons(ETH_P_IP
) ||
2517 arp_ptr
= (unsigned char *)(arp
+ 1);
2518 arp_ptr
+= dev
->addr_len
;
2519 memcpy(&sip
, arp_ptr
, 4);
2520 arp_ptr
+= 4 + dev
->addr_len
;
2521 memcpy(&tip
, arp_ptr
, 4);
2523 dprintk("bond_arp_rcv: %s %s/%d av %d sv %d sip %u.%u.%u.%u"
2524 " tip %u.%u.%u.%u\n", bond
->dev
->name
, slave
->dev
->name
,
2525 slave
->state
, bond
->params
.arp_validate
,
2526 slave_do_arp_validate(bond
, slave
), NIPQUAD(sip
), NIPQUAD(tip
));
2529 * Backup slaves won't see the ARP reply, but do come through
2530 * here for each ARP probe (so we swap the sip/tip to validate
2531 * the probe). In a "redundant switch, common router" type of
2532 * configuration, the ARP probe will (hopefully) travel from
2533 * the active, through one switch, the router, then the other
2534 * switch before reaching the backup.
2536 if (slave
->state
== BOND_STATE_ACTIVE
)
2537 bond_validate_arp(bond
, slave
, sip
, tip
);
2539 bond_validate_arp(bond
, slave
, tip
, sip
);
2542 read_unlock(&bond
->lock
);
2545 return NET_RX_SUCCESS
;
2549 * this function is called regularly to monitor each slave's link
2550 * ensuring that traffic is being sent and received when arp monitoring
2551 * is used in load-balancing mode. if the adapter has been dormant, then an
2552 * arp is transmitted to generate traffic. see activebackup_arp_monitor for
2553 * arp monitoring in active backup mode.
2555 void bond_loadbalance_arp_mon(struct net_device
*bond_dev
)
2557 struct bonding
*bond
= bond_dev
->priv
;
2558 struct slave
*slave
, *oldcurrent
;
2559 int do_failover
= 0;
2563 read_lock(&bond
->lock
);
2565 delta_in_ticks
= (bond
->params
.arp_interval
* HZ
) / 1000;
2567 if (bond
->kill_timers
) {
2571 if (bond
->slave_cnt
== 0) {
2575 read_lock(&bond
->curr_slave_lock
);
2576 oldcurrent
= bond
->curr_active_slave
;
2577 read_unlock(&bond
->curr_slave_lock
);
2579 /* see if any of the previous devices are up now (i.e. they have
2580 * xmt and rcv traffic). the curr_active_slave does not come into
2581 * the picture unless it is null. also, slave->jiffies is not needed
2582 * here because we send an arp on each slave and give a slave as
2583 * long as it needs to get the tx/rx within the delta.
2584 * TODO: what about up/down delay in arp mode? it wasn't here before
2587 bond_for_each_slave(bond
, slave
, i
) {
2588 if (slave
->link
!= BOND_LINK_UP
) {
2589 if (((jiffies
- slave
->dev
->trans_start
) <= delta_in_ticks
) &&
2590 ((jiffies
- slave
->dev
->last_rx
) <= delta_in_ticks
)) {
2592 slave
->link
= BOND_LINK_UP
;
2593 slave
->state
= BOND_STATE_ACTIVE
;
2595 /* primary_slave has no meaning in round-robin
2596 * mode. the window of a slave being up and
2597 * curr_active_slave being null after enslaving
2601 printk(KERN_INFO DRV_NAME
2602 ": %s: link status definitely "
2603 "up for interface %s, ",
2608 printk(KERN_INFO DRV_NAME
2609 ": %s: interface %s is now up\n",
2615 /* slave->link == BOND_LINK_UP */
2617 /* not all switches will respond to an arp request
2618 * when the source ip is 0, so don't take the link down
2619 * if we don't know our ip yet
2621 if (((jiffies
- slave
->dev
->trans_start
) >= (2*delta_in_ticks
)) ||
2622 (((jiffies
- slave
->dev
->last_rx
) >= (2*delta_in_ticks
)) &&
2623 bond_has_ip(bond
))) {
2625 slave
->link
= BOND_LINK_DOWN
;
2626 slave
->state
= BOND_STATE_BACKUP
;
2628 if (slave
->link_failure_count
< UINT_MAX
) {
2629 slave
->link_failure_count
++;
2632 printk(KERN_INFO DRV_NAME
2633 ": %s: interface %s is now down.\n",
2637 if (slave
== oldcurrent
) {
2643 /* note: if switch is in round-robin mode, all links
2644 * must tx arp to ensure all links rx an arp - otherwise
2645 * links may oscillate or not come up at all; if switch is
2646 * in something like xor mode, there is nothing we can
2647 * do - all replies will be rx'ed on same link causing slaves
2648 * to be unstable during low/no traffic periods
2650 if (IS_UP(slave
->dev
)) {
2651 bond_arp_send_all(bond
, slave
);
2656 write_lock(&bond
->curr_slave_lock
);
2658 bond_select_active_slave(bond
);
2660 write_unlock(&bond
->curr_slave_lock
);
2664 if (bond
->params
.arp_interval
) {
2665 mod_timer(&bond
->arp_timer
, jiffies
+ delta_in_ticks
);
2668 read_unlock(&bond
->lock
);
2672 * When using arp monitoring in active-backup mode, this function is
2673 * called to determine if any backup slaves have went down or a new
2674 * current slave needs to be found.
2675 * The backup slaves never generate traffic, they are considered up by merely
2676 * receiving traffic. If the current slave goes down, each backup slave will
2677 * be given the opportunity to tx/rx an arp before being taken down - this
2678 * prevents all slaves from being taken down due to the current slave not
2679 * sending any traffic for the backups to receive. The arps are not necessarily
2680 * necessary, any tx and rx traffic will keep the current slave up. While any
2681 * rx traffic will keep the backup slaves up, the current slave is responsible
2682 * for generating traffic to keep them up regardless of any other traffic they
2683 * may have received.
2684 * see loadbalance_arp_monitor for arp monitoring in load balancing mode
2686 void bond_activebackup_arp_mon(struct net_device
*bond_dev
)
2688 struct bonding
*bond
= bond_dev
->priv
;
2689 struct slave
*slave
;
2693 read_lock(&bond
->lock
);
2695 delta_in_ticks
= (bond
->params
.arp_interval
* HZ
) / 1000;
2697 if (bond
->kill_timers
) {
2701 if (bond
->slave_cnt
== 0) {
2705 /* determine if any slave has come up or any backup slave has
2707 * TODO: what about up/down delay in arp mode? it wasn't here before
2710 bond_for_each_slave(bond
, slave
, i
) {
2711 if (slave
->link
!= BOND_LINK_UP
) {
2712 if ((jiffies
- slave_last_rx(bond
, slave
)) <=
2715 slave
->link
= BOND_LINK_UP
;
2717 write_lock(&bond
->curr_slave_lock
);
2719 if ((!bond
->curr_active_slave
) &&
2720 ((jiffies
- slave
->dev
->trans_start
) <= delta_in_ticks
)) {
2721 bond_change_active_slave(bond
, slave
);
2722 bond
->current_arp_slave
= NULL
;
2723 } else if (bond
->curr_active_slave
!= slave
) {
2724 /* this slave has just come up but we
2725 * already have a current slave; this
2726 * can also happen if bond_enslave adds
2727 * a new slave that is up while we are
2728 * searching for a new slave
2730 bond_set_slave_inactive_flags(slave
);
2731 bond
->current_arp_slave
= NULL
;
2734 bond_set_carrier(bond
);
2736 if (slave
== bond
->curr_active_slave
) {
2737 printk(KERN_INFO DRV_NAME
2738 ": %s: %s is up and now the "
2739 "active interface\n",
2742 netif_carrier_on(bond
->dev
);
2744 printk(KERN_INFO DRV_NAME
2745 ": %s: backup interface %s is "
2751 write_unlock(&bond
->curr_slave_lock
);
2754 read_lock(&bond
->curr_slave_lock
);
2756 if ((slave
!= bond
->curr_active_slave
) &&
2757 (!bond
->current_arp_slave
) &&
2758 (((jiffies
- slave_last_rx(bond
, slave
)) >= 3*delta_in_ticks
) &&
2759 bond_has_ip(bond
))) {
2760 /* a backup slave has gone down; three times
2761 * the delta allows the current slave to be
2762 * taken out before the backup slave.
2763 * note: a non-null current_arp_slave indicates
2764 * the curr_active_slave went down and we are
2765 * searching for a new one; under this
2766 * condition we only take the curr_active_slave
2767 * down - this gives each slave a chance to
2768 * tx/rx traffic before being taken out
2771 read_unlock(&bond
->curr_slave_lock
);
2773 slave
->link
= BOND_LINK_DOWN
;
2775 if (slave
->link_failure_count
< UINT_MAX
) {
2776 slave
->link_failure_count
++;
2779 bond_set_slave_inactive_flags(slave
);
2781 printk(KERN_INFO DRV_NAME
2782 ": %s: backup interface %s is now down\n",
2786 read_unlock(&bond
->curr_slave_lock
);
2791 read_lock(&bond
->curr_slave_lock
);
2792 slave
= bond
->curr_active_slave
;
2793 read_unlock(&bond
->curr_slave_lock
);
2796 /* if we have sent traffic in the past 2*arp_intervals but
2797 * haven't xmit and rx traffic in that time interval, select
2798 * a different slave. slave->jiffies is only updated when
2799 * a slave first becomes the curr_active_slave - not necessarily
2800 * after every arp; this ensures the slave has a full 2*delta
2801 * before being taken out. if a primary is being used, check
2802 * if it is up and needs to take over as the curr_active_slave
2804 if ((((jiffies
- slave
->dev
->trans_start
) >= (2*delta_in_ticks
)) ||
2805 (((jiffies
- slave_last_rx(bond
, slave
)) >= (2*delta_in_ticks
)) &&
2806 bond_has_ip(bond
))) &&
2807 ((jiffies
- slave
->jiffies
) >= 2*delta_in_ticks
)) {
2809 slave
->link
= BOND_LINK_DOWN
;
2811 if (slave
->link_failure_count
< UINT_MAX
) {
2812 slave
->link_failure_count
++;
2815 printk(KERN_INFO DRV_NAME
2816 ": %s: link status down for active interface "
2817 "%s, disabling it\n",
2821 write_lock(&bond
->curr_slave_lock
);
2823 bond_select_active_slave(bond
);
2824 slave
= bond
->curr_active_slave
;
2826 write_unlock(&bond
->curr_slave_lock
);
2828 bond
->current_arp_slave
= slave
;
2831 slave
->jiffies
= jiffies
;
2833 } else if ((bond
->primary_slave
) &&
2834 (bond
->primary_slave
!= slave
) &&
2835 (bond
->primary_slave
->link
== BOND_LINK_UP
)) {
2836 /* at this point, slave is the curr_active_slave */
2837 printk(KERN_INFO DRV_NAME
2838 ": %s: changing from interface %s to primary "
2842 bond
->primary_slave
->dev
->name
);
2844 /* primary is up so switch to it */
2845 write_lock(&bond
->curr_slave_lock
);
2846 bond_change_active_slave(bond
, bond
->primary_slave
);
2847 write_unlock(&bond
->curr_slave_lock
);
2849 slave
= bond
->primary_slave
;
2850 slave
->jiffies
= jiffies
;
2852 bond
->current_arp_slave
= NULL
;
2855 /* the current slave must tx an arp to ensure backup slaves
2858 if (slave
&& bond_has_ip(bond
)) {
2859 bond_arp_send_all(bond
, slave
);
2863 /* if we don't have a curr_active_slave, search for the next available
2864 * backup slave from the current_arp_slave and make it the candidate
2865 * for becoming the curr_active_slave
2868 if (!bond
->current_arp_slave
) {
2869 bond
->current_arp_slave
= bond
->first_slave
;
2872 if (bond
->current_arp_slave
) {
2873 bond_set_slave_inactive_flags(bond
->current_arp_slave
);
2875 /* search for next candidate */
2876 bond_for_each_slave_from(bond
, slave
, i
, bond
->current_arp_slave
->next
) {
2877 if (IS_UP(slave
->dev
)) {
2878 slave
->link
= BOND_LINK_BACK
;
2879 bond_set_slave_active_flags(slave
);
2880 bond_arp_send_all(bond
, slave
);
2881 slave
->jiffies
= jiffies
;
2882 bond
->current_arp_slave
= slave
;
2886 /* if the link state is up at this point, we
2887 * mark it down - this can happen if we have
2888 * simultaneous link failures and
2889 * reselect_active_interface doesn't make this
2890 * one the current slave so it is still marked
2891 * up when it is actually down
2893 if (slave
->link
== BOND_LINK_UP
) {
2894 slave
->link
= BOND_LINK_DOWN
;
2895 if (slave
->link_failure_count
< UINT_MAX
) {
2896 slave
->link_failure_count
++;
2899 bond_set_slave_inactive_flags(slave
);
2901 printk(KERN_INFO DRV_NAME
2902 ": %s: backup interface %s is "
2912 if (bond
->params
.arp_interval
) {
2913 mod_timer(&bond
->arp_timer
, jiffies
+ delta_in_ticks
);
2916 read_unlock(&bond
->lock
);
2919 /*------------------------------ proc/seq_file-------------------------------*/
2921 #ifdef CONFIG_PROC_FS
2923 #define SEQ_START_TOKEN ((void *)1)
2925 static void *bond_info_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2927 struct bonding
*bond
= seq
->private;
2929 struct slave
*slave
;
2932 /* make sure the bond won't be taken away */
2933 read_lock(&dev_base_lock
);
2934 read_lock_bh(&bond
->lock
);
2937 return SEQ_START_TOKEN
;
2940 bond_for_each_slave(bond
, slave
, i
) {
2941 if (++off
== *pos
) {
2949 static void *bond_info_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2951 struct bonding
*bond
= seq
->private;
2952 struct slave
*slave
= v
;
2955 if (v
== SEQ_START_TOKEN
) {
2956 return bond
->first_slave
;
2959 slave
= slave
->next
;
2961 return (slave
== bond
->first_slave
) ? NULL
: slave
;
2964 static void bond_info_seq_stop(struct seq_file
*seq
, void *v
)
2966 struct bonding
*bond
= seq
->private;
2968 read_unlock_bh(&bond
->lock
);
2969 read_unlock(&dev_base_lock
);
2972 static void bond_info_show_master(struct seq_file
*seq
)
2974 struct bonding
*bond
= seq
->private;
2979 read_lock(&bond
->curr_slave_lock
);
2980 curr
= bond
->curr_active_slave
;
2981 read_unlock(&bond
->curr_slave_lock
);
2983 seq_printf(seq
, "Bonding Mode: %s\n",
2984 bond_mode_name(bond
->params
.mode
));
2986 if (bond
->params
.mode
== BOND_MODE_XOR
||
2987 bond
->params
.mode
== BOND_MODE_8023AD
) {
2988 seq_printf(seq
, "Transmit Hash Policy: %s (%d)\n",
2989 xmit_hashtype_tbl
[bond
->params
.xmit_policy
].modename
,
2990 bond
->params
.xmit_policy
);
2993 if (USES_PRIMARY(bond
->params
.mode
)) {
2994 seq_printf(seq
, "Primary Slave: %s\n",
2995 (bond
->primary_slave
) ?
2996 bond
->primary_slave
->dev
->name
: "None");
2998 seq_printf(seq
, "Currently Active Slave: %s\n",
2999 (curr
) ? curr
->dev
->name
: "None");
3002 seq_printf(seq
, "MII Status: %s\n", netif_carrier_ok(bond
->dev
) ?
3004 seq_printf(seq
, "MII Polling Interval (ms): %d\n", bond
->params
.miimon
);
3005 seq_printf(seq
, "Up Delay (ms): %d\n",
3006 bond
->params
.updelay
* bond
->params
.miimon
);
3007 seq_printf(seq
, "Down Delay (ms): %d\n",
3008 bond
->params
.downdelay
* bond
->params
.miimon
);
3011 /* ARP information */
3012 if(bond
->params
.arp_interval
> 0) {
3014 seq_printf(seq
, "ARP Polling Interval (ms): %d\n",
3015 bond
->params
.arp_interval
);
3017 seq_printf(seq
, "ARP IP target/s (n.n.n.n form):");
3019 for(i
= 0; (i
< BOND_MAX_ARP_TARGETS
) ;i
++) {
3020 if (!bond
->params
.arp_targets
[i
])
3023 seq_printf(seq
, ",");
3024 target
= ntohl(bond
->params
.arp_targets
[i
]);
3025 seq_printf(seq
, " %d.%d.%d.%d", HIPQUAD(target
));
3028 seq_printf(seq
, "\n");
3031 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
3032 struct ad_info ad_info
;
3034 seq_puts(seq
, "\n802.3ad info\n");
3035 seq_printf(seq
, "LACP rate: %s\n",
3036 (bond
->params
.lacp_fast
) ? "fast" : "slow");
3038 if (bond_3ad_get_active_agg_info(bond
, &ad_info
)) {
3039 seq_printf(seq
, "bond %s has no active aggregator\n",
3042 seq_printf(seq
, "Active Aggregator Info:\n");
3044 seq_printf(seq
, "\tAggregator ID: %d\n",
3045 ad_info
.aggregator_id
);
3046 seq_printf(seq
, "\tNumber of ports: %d\n",
3048 seq_printf(seq
, "\tActor Key: %d\n",
3050 seq_printf(seq
, "\tPartner Key: %d\n",
3051 ad_info
.partner_key
);
3052 seq_printf(seq
, "\tPartner Mac Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
3053 ad_info
.partner_system
[0],
3054 ad_info
.partner_system
[1],
3055 ad_info
.partner_system
[2],
3056 ad_info
.partner_system
[3],
3057 ad_info
.partner_system
[4],
3058 ad_info
.partner_system
[5]);
3063 static void bond_info_show_slave(struct seq_file
*seq
, const struct slave
*slave
)
3065 struct bonding
*bond
= seq
->private;
3067 seq_printf(seq
, "\nSlave Interface: %s\n", slave
->dev
->name
);
3068 seq_printf(seq
, "MII Status: %s\n",
3069 (slave
->link
== BOND_LINK_UP
) ? "up" : "down");
3070 seq_printf(seq
, "Link Failure Count: %u\n",
3071 slave
->link_failure_count
);
3074 "Permanent HW addr: %02x:%02x:%02x:%02x:%02x:%02x\n",
3075 slave
->perm_hwaddr
[0], slave
->perm_hwaddr
[1],
3076 slave
->perm_hwaddr
[2], slave
->perm_hwaddr
[3],
3077 slave
->perm_hwaddr
[4], slave
->perm_hwaddr
[5]);
3079 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
3080 const struct aggregator
*agg
3081 = SLAVE_AD_INFO(slave
).port
.aggregator
;
3084 seq_printf(seq
, "Aggregator ID: %d\n",
3085 agg
->aggregator_identifier
);
3087 seq_puts(seq
, "Aggregator ID: N/A\n");
3092 static int bond_info_seq_show(struct seq_file
*seq
, void *v
)
3094 if (v
== SEQ_START_TOKEN
) {
3095 seq_printf(seq
, "%s\n", version
);
3096 bond_info_show_master(seq
);
3098 bond_info_show_slave(seq
, v
);
3104 static struct seq_operations bond_info_seq_ops
= {
3105 .start
= bond_info_seq_start
,
3106 .next
= bond_info_seq_next
,
3107 .stop
= bond_info_seq_stop
,
3108 .show
= bond_info_seq_show
,
3111 static int bond_info_open(struct inode
*inode
, struct file
*file
)
3113 struct seq_file
*seq
;
3114 struct proc_dir_entry
*proc
;
3117 res
= seq_open(file
, &bond_info_seq_ops
);
3119 /* recover the pointer buried in proc_dir_entry data */
3120 seq
= file
->private_data
;
3122 seq
->private = proc
->data
;
3128 static const struct file_operations bond_info_fops
= {
3129 .owner
= THIS_MODULE
,
3130 .open
= bond_info_open
,
3132 .llseek
= seq_lseek
,
3133 .release
= seq_release
,
3136 static int bond_create_proc_entry(struct bonding
*bond
)
3138 struct net_device
*bond_dev
= bond
->dev
;
3140 if (bond_proc_dir
) {
3141 bond
->proc_entry
= create_proc_entry(bond_dev
->name
,
3144 if (bond
->proc_entry
== NULL
) {
3145 printk(KERN_WARNING DRV_NAME
3146 ": Warning: Cannot create /proc/net/%s/%s\n",
3147 DRV_NAME
, bond_dev
->name
);
3149 bond
->proc_entry
->data
= bond
;
3150 bond
->proc_entry
->proc_fops
= &bond_info_fops
;
3151 bond
->proc_entry
->owner
= THIS_MODULE
;
3152 memcpy(bond
->proc_file_name
, bond_dev
->name
, IFNAMSIZ
);
3159 static void bond_remove_proc_entry(struct bonding
*bond
)
3161 if (bond_proc_dir
&& bond
->proc_entry
) {
3162 remove_proc_entry(bond
->proc_file_name
, bond_proc_dir
);
3163 memset(bond
->proc_file_name
, 0, IFNAMSIZ
);
3164 bond
->proc_entry
= NULL
;
3168 /* Create the bonding directory under /proc/net, if doesn't exist yet.
3169 * Caller must hold rtnl_lock.
3171 static void bond_create_proc_dir(void)
3173 int len
= strlen(DRV_NAME
);
3175 for (bond_proc_dir
= proc_net
->subdir
; bond_proc_dir
;
3176 bond_proc_dir
= bond_proc_dir
->next
) {
3177 if ((bond_proc_dir
->namelen
== len
) &&
3178 !memcmp(bond_proc_dir
->name
, DRV_NAME
, len
)) {
3183 if (!bond_proc_dir
) {
3184 bond_proc_dir
= proc_mkdir(DRV_NAME
, proc_net
);
3185 if (bond_proc_dir
) {
3186 bond_proc_dir
->owner
= THIS_MODULE
;
3188 printk(KERN_WARNING DRV_NAME
3189 ": Warning: cannot create /proc/net/%s\n",
3195 /* Destroy the bonding directory under /proc/net, if empty.
3196 * Caller must hold rtnl_lock.
3198 static void bond_destroy_proc_dir(void)
3200 struct proc_dir_entry
*de
;
3202 if (!bond_proc_dir
) {
3206 /* verify that the /proc dir is empty */
3207 for (de
= bond_proc_dir
->subdir
; de
; de
= de
->next
) {
3208 /* ignore . and .. */
3209 if (*(de
->name
) != '.') {
3215 if (bond_proc_dir
->owner
== THIS_MODULE
) {
3216 bond_proc_dir
->owner
= NULL
;
3219 remove_proc_entry(DRV_NAME
, proc_net
);
3220 bond_proc_dir
= NULL
;
3223 #endif /* CONFIG_PROC_FS */
3225 /*-------------------------- netdev event handling --------------------------*/
3228 * Change device name
3230 static int bond_event_changename(struct bonding
*bond
)
3232 #ifdef CONFIG_PROC_FS
3233 bond_remove_proc_entry(bond
);
3234 bond_create_proc_entry(bond
);
3236 down_write(&(bonding_rwsem
));
3237 bond_destroy_sysfs_entry(bond
);
3238 bond_create_sysfs_entry(bond
);
3239 up_write(&(bonding_rwsem
));
3243 static int bond_master_netdev_event(unsigned long event
, struct net_device
*bond_dev
)
3245 struct bonding
*event_bond
= bond_dev
->priv
;
3248 case NETDEV_CHANGENAME
:
3249 return bond_event_changename(event_bond
);
3250 case NETDEV_UNREGISTER
:
3252 * TODO: remove a bond from the list?
3262 static int bond_slave_netdev_event(unsigned long event
, struct net_device
*slave_dev
)
3264 struct net_device
*bond_dev
= slave_dev
->master
;
3265 struct bonding
*bond
= bond_dev
->priv
;
3268 case NETDEV_UNREGISTER
:
3270 bond_release(bond_dev
, slave_dev
);
3275 * TODO: is this what we get if somebody
3276 * sets up a hierarchical bond, then rmmod's
3277 * one of the slave bonding devices?
3282 * ... Or is it this?
3285 case NETDEV_CHANGEMTU
:
3287 * TODO: Should slaves be allowed to
3288 * independently alter their MTU? For
3289 * an active-backup bond, slaves need
3290 * not be the same type of device, so
3291 * MTUs may vary. For other modes,
3292 * slaves arguably should have the
3293 * same MTUs. To do this, we'd need to
3294 * take over the slave's change_mtu
3295 * function for the duration of their
3299 case NETDEV_CHANGENAME
:
3301 * TODO: handle changing the primary's name
3304 case NETDEV_FEAT_CHANGE
:
3305 bond_compute_features(bond
);
3315 * bond_netdev_event: handle netdev notifier chain events.
3317 * This function receives events for the netdev chain. The caller (an
3318 * ioctl handler calling blocking_notifier_call_chain) holds the necessary
3319 * locks for us to safely manipulate the slave devices (RTNL lock,
3322 static int bond_netdev_event(struct notifier_block
*this, unsigned long event
, void *ptr
)
3324 struct net_device
*event_dev
= (struct net_device
*)ptr
;
3326 dprintk("event_dev: %s, event: %lx\n",
3327 (event_dev
? event_dev
->name
: "None"),
3330 if (!(event_dev
->priv_flags
& IFF_BONDING
))
3333 if (event_dev
->flags
& IFF_MASTER
) {
3334 dprintk("IFF_MASTER\n");
3335 return bond_master_netdev_event(event
, event_dev
);
3338 if (event_dev
->flags
& IFF_SLAVE
) {
3339 dprintk("IFF_SLAVE\n");
3340 return bond_slave_netdev_event(event
, event_dev
);
3347 * bond_inetaddr_event: handle inetaddr notifier chain events.
3349 * We keep track of device IPs primarily to use as source addresses in
3350 * ARP monitor probes (rather than spewing out broadcasts all the time).
3352 * We track one IP for the main device (if it has one), plus one per VLAN.
3354 static int bond_inetaddr_event(struct notifier_block
*this, unsigned long event
, void *ptr
)
3356 struct in_ifaddr
*ifa
= ptr
;
3357 struct net_device
*vlan_dev
, *event_dev
= ifa
->ifa_dev
->dev
;
3358 struct bonding
*bond
, *bond_next
;
3359 struct vlan_entry
*vlan
, *vlan_next
;
3361 list_for_each_entry_safe(bond
, bond_next
, &bond_dev_list
, bond_list
) {
3362 if (bond
->dev
== event_dev
) {
3365 bond
->master_ip
= ifa
->ifa_local
;
3368 bond
->master_ip
= bond_glean_dev_ip(bond
->dev
);
3375 if (list_empty(&bond
->vlan_list
))
3378 list_for_each_entry_safe(vlan
, vlan_next
, &bond
->vlan_list
,
3380 vlan_dev
= vlan_group_get_device(bond
->vlgrp
, vlan
->vlan_id
);
3381 if (vlan_dev
== event_dev
) {
3384 vlan
->vlan_ip
= ifa
->ifa_local
;
3388 bond_glean_dev_ip(vlan_dev
);
3399 static struct notifier_block bond_netdev_notifier
= {
3400 .notifier_call
= bond_netdev_event
,
3403 static struct notifier_block bond_inetaddr_notifier
= {
3404 .notifier_call
= bond_inetaddr_event
,
3407 /*-------------------------- Packet type handling ---------------------------*/
3409 /* register to receive lacpdus on a bond */
3410 static void bond_register_lacpdu(struct bonding
*bond
)
3412 struct packet_type
*pk_type
= &(BOND_AD_INFO(bond
).ad_pkt_type
);
3414 /* initialize packet type */
3415 pk_type
->type
= PKT_TYPE_LACPDU
;
3416 pk_type
->dev
= bond
->dev
;
3417 pk_type
->func
= bond_3ad_lacpdu_recv
;
3419 dev_add_pack(pk_type
);
3422 /* unregister to receive lacpdus on a bond */
3423 static void bond_unregister_lacpdu(struct bonding
*bond
)
3425 dev_remove_pack(&(BOND_AD_INFO(bond
).ad_pkt_type
));
3428 void bond_register_arp(struct bonding
*bond
)
3430 struct packet_type
*pt
= &bond
->arp_mon_pt
;
3435 pt
->type
= htons(ETH_P_ARP
);
3436 pt
->dev
= bond
->dev
;
3437 pt
->func
= bond_arp_rcv
;
3441 void bond_unregister_arp(struct bonding
*bond
)
3443 struct packet_type
*pt
= &bond
->arp_mon_pt
;
3445 dev_remove_pack(pt
);
3449 /*---------------------------- Hashing Policies -----------------------------*/
3452 * Hash for the output device based upon layer 3 and layer 4 data. If
3453 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3454 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3456 static int bond_xmit_hash_policy_l34(struct sk_buff
*skb
,
3457 struct net_device
*bond_dev
, int count
)
3459 struct ethhdr
*data
= (struct ethhdr
*)skb
->data
;
3460 struct iphdr
*iph
= ip_hdr(skb
);
3461 u16
*layer4hdr
= (u16
*)((u32
*)iph
+ iph
->ihl
);
3464 if (skb
->protocol
== __constant_htons(ETH_P_IP
)) {
3465 if (!(iph
->frag_off
& __constant_htons(IP_MF
|IP_OFFSET
)) &&
3466 (iph
->protocol
== IPPROTO_TCP
||
3467 iph
->protocol
== IPPROTO_UDP
)) {
3468 layer4_xor
= htons((*layer4hdr
^ *(layer4hdr
+ 1)));
3470 return (layer4_xor
^
3471 ((ntohl(iph
->saddr
^ iph
->daddr
)) & 0xffff)) % count
;
3475 return (data
->h_dest
[5] ^ bond_dev
->dev_addr
[5]) % count
;
3479 * Hash for the output device based upon layer 2 data
3481 static int bond_xmit_hash_policy_l2(struct sk_buff
*skb
,
3482 struct net_device
*bond_dev
, int count
)
3484 struct ethhdr
*data
= (struct ethhdr
*)skb
->data
;
3486 return (data
->h_dest
[5] ^ bond_dev
->dev_addr
[5]) % count
;
3489 /*-------------------------- Device entry points ----------------------------*/
3491 static int bond_open(struct net_device
*bond_dev
)
3493 struct bonding
*bond
= bond_dev
->priv
;
3494 struct timer_list
*mii_timer
= &bond
->mii_timer
;
3495 struct timer_list
*arp_timer
= &bond
->arp_timer
;
3497 bond
->kill_timers
= 0;
3499 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
3500 (bond
->params
.mode
== BOND_MODE_ALB
)) {
3501 struct timer_list
*alb_timer
= &(BOND_ALB_INFO(bond
).alb_timer
);
3503 /* bond_alb_initialize must be called before the timer
3506 if (bond_alb_initialize(bond
, (bond
->params
.mode
== BOND_MODE_ALB
))) {
3507 /* something went wrong - fail the open operation */
3511 init_timer(alb_timer
);
3512 alb_timer
->expires
= jiffies
+ 1;
3513 alb_timer
->data
= (unsigned long)bond
;
3514 alb_timer
->function
= (void *)&bond_alb_monitor
;
3515 add_timer(alb_timer
);
3518 if (bond
->params
.miimon
) { /* link check interval, in milliseconds. */
3519 init_timer(mii_timer
);
3520 mii_timer
->expires
= jiffies
+ 1;
3521 mii_timer
->data
= (unsigned long)bond_dev
;
3522 mii_timer
->function
= (void *)&bond_mii_monitor
;
3523 add_timer(mii_timer
);
3526 if (bond
->params
.arp_interval
) { /* arp interval, in milliseconds. */
3527 init_timer(arp_timer
);
3528 arp_timer
->expires
= jiffies
+ 1;
3529 arp_timer
->data
= (unsigned long)bond_dev
;
3530 if (bond
->params
.mode
== BOND_MODE_ACTIVEBACKUP
) {
3531 arp_timer
->function
= (void *)&bond_activebackup_arp_mon
;
3533 arp_timer
->function
= (void *)&bond_loadbalance_arp_mon
;
3535 if (bond
->params
.arp_validate
)
3536 bond_register_arp(bond
);
3538 add_timer(arp_timer
);
3541 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
3542 struct timer_list
*ad_timer
= &(BOND_AD_INFO(bond
).ad_timer
);
3543 init_timer(ad_timer
);
3544 ad_timer
->expires
= jiffies
+ 1;
3545 ad_timer
->data
= (unsigned long)bond
;
3546 ad_timer
->function
= (void *)&bond_3ad_state_machine_handler
;
3547 add_timer(ad_timer
);
3549 /* register to receive LACPDUs */
3550 bond_register_lacpdu(bond
);
3556 static int bond_close(struct net_device
*bond_dev
)
3558 struct bonding
*bond
= bond_dev
->priv
;
3560 if (bond
->params
.mode
== BOND_MODE_8023AD
) {
3561 /* Unregister the receive of LACPDUs */
3562 bond_unregister_lacpdu(bond
);
3565 if (bond
->params
.arp_validate
)
3566 bond_unregister_arp(bond
);
3568 write_lock_bh(&bond
->lock
);
3571 /* signal timers not to re-arm */
3572 bond
->kill_timers
= 1;
3574 write_unlock_bh(&bond
->lock
);
3576 /* del_timer_sync must run without holding the bond->lock
3577 * because a running timer might be trying to hold it too
3580 if (bond
->params
.miimon
) { /* link check interval, in milliseconds. */
3581 del_timer_sync(&bond
->mii_timer
);
3584 if (bond
->params
.arp_interval
) { /* arp interval, in milliseconds. */
3585 del_timer_sync(&bond
->arp_timer
);
3588 switch (bond
->params
.mode
) {
3589 case BOND_MODE_8023AD
:
3590 del_timer_sync(&(BOND_AD_INFO(bond
).ad_timer
));
3594 del_timer_sync(&(BOND_ALB_INFO(bond
).alb_timer
));
3601 if ((bond
->params
.mode
== BOND_MODE_TLB
) ||
3602 (bond
->params
.mode
== BOND_MODE_ALB
)) {
3603 /* Must be called only after all
3604 * slaves have been released
3606 bond_alb_deinitialize(bond
);
3612 static struct net_device_stats
*bond_get_stats(struct net_device
*bond_dev
)
3614 struct bonding
*bond
= bond_dev
->priv
;
3615 struct net_device_stats
*stats
= &(bond
->stats
), *sstats
;
3616 struct slave
*slave
;
3619 memset(stats
, 0, sizeof(struct net_device_stats
));
3621 read_lock_bh(&bond
->lock
);
3623 bond_for_each_slave(bond
, slave
, i
) {
3624 sstats
= slave
->dev
->get_stats(slave
->dev
);
3625 stats
->rx_packets
+= sstats
->rx_packets
;
3626 stats
->rx_bytes
+= sstats
->rx_bytes
;
3627 stats
->rx_errors
+= sstats
->rx_errors
;
3628 stats
->rx_dropped
+= sstats
->rx_dropped
;
3630 stats
->tx_packets
+= sstats
->tx_packets
;
3631 stats
->tx_bytes
+= sstats
->tx_bytes
;
3632 stats
->tx_errors
+= sstats
->tx_errors
;
3633 stats
->tx_dropped
+= sstats
->tx_dropped
;
3635 stats
->multicast
+= sstats
->multicast
;
3636 stats
->collisions
+= sstats
->collisions
;
3638 stats
->rx_length_errors
+= sstats
->rx_length_errors
;
3639 stats
->rx_over_errors
+= sstats
->rx_over_errors
;
3640 stats
->rx_crc_errors
+= sstats
->rx_crc_errors
;
3641 stats
->rx_frame_errors
+= sstats
->rx_frame_errors
;
3642 stats
->rx_fifo_errors
+= sstats
->rx_fifo_errors
;
3643 stats
->rx_missed_errors
+= sstats
->rx_missed_errors
;
3645 stats
->tx_aborted_errors
+= sstats
->tx_aborted_errors
;
3646 stats
->tx_carrier_errors
+= sstats
->tx_carrier_errors
;
3647 stats
->tx_fifo_errors
+= sstats
->tx_fifo_errors
;
3648 stats
->tx_heartbeat_errors
+= sstats
->tx_heartbeat_errors
;
3649 stats
->tx_window_errors
+= sstats
->tx_window_errors
;
3652 read_unlock_bh(&bond
->lock
);
3657 static int bond_do_ioctl(struct net_device
*bond_dev
, struct ifreq
*ifr
, int cmd
)
3659 struct net_device
*slave_dev
= NULL
;
3660 struct ifbond k_binfo
;
3661 struct ifbond __user
*u_binfo
= NULL
;
3662 struct ifslave k_sinfo
;
3663 struct ifslave __user
*u_sinfo
= NULL
;
3664 struct mii_ioctl_data
*mii
= NULL
;
3667 dprintk("bond_ioctl: master=%s, cmd=%d\n",
3668 bond_dev
->name
, cmd
);
3680 * We do this again just in case we were called by SIOCGMIIREG
3681 * instead of SIOCGMIIPHY.
3688 if (mii
->reg_num
== 1) {
3689 struct bonding
*bond
= bond_dev
->priv
;
3691 read_lock_bh(&bond
->lock
);
3692 read_lock(&bond
->curr_slave_lock
);
3693 if (netif_carrier_ok(bond
->dev
)) {
3694 mii
->val_out
= BMSR_LSTATUS
;
3696 read_unlock(&bond
->curr_slave_lock
);
3697 read_unlock_bh(&bond
->lock
);
3701 case BOND_INFO_QUERY_OLD
:
3702 case SIOCBONDINFOQUERY
:
3703 u_binfo
= (struct ifbond __user
*)ifr
->ifr_data
;
3705 if (copy_from_user(&k_binfo
, u_binfo
, sizeof(ifbond
))) {
3709 res
= bond_info_query(bond_dev
, &k_binfo
);
3711 if (copy_to_user(u_binfo
, &k_binfo
, sizeof(ifbond
))) {
3717 case BOND_SLAVE_INFO_QUERY_OLD
:
3718 case SIOCBONDSLAVEINFOQUERY
:
3719 u_sinfo
= (struct ifslave __user
*)ifr
->ifr_data
;
3721 if (copy_from_user(&k_sinfo
, u_sinfo
, sizeof(ifslave
))) {
3725 res
= bond_slave_info_query(bond_dev
, &k_sinfo
);
3727 if (copy_to_user(u_sinfo
, &k_sinfo
, sizeof(ifslave
))) {
3738 if (!capable(CAP_NET_ADMIN
)) {
3742 down_write(&(bonding_rwsem
));
3743 slave_dev
= dev_get_by_name(ifr
->ifr_slave
);
3745 dprintk("slave_dev=%p: \n", slave_dev
);
3750 dprintk("slave_dev->name=%s: \n", slave_dev
->name
);
3752 case BOND_ENSLAVE_OLD
:
3753 case SIOCBONDENSLAVE
:
3754 res
= bond_enslave(bond_dev
, slave_dev
);
3756 case BOND_RELEASE_OLD
:
3757 case SIOCBONDRELEASE
:
3758 res
= bond_release(bond_dev
, slave_dev
);
3760 case BOND_SETHWADDR_OLD
:
3761 case SIOCBONDSETHWADDR
:
3762 res
= bond_sethwaddr(bond_dev
, slave_dev
);
3764 case BOND_CHANGE_ACTIVE_OLD
:
3765 case SIOCBONDCHANGEACTIVE
:
3766 res
= bond_ioctl_change_active(bond_dev
, slave_dev
);
3775 up_write(&(bonding_rwsem
));
3779 static void bond_set_multicast_list(struct net_device
*bond_dev
)
3781 struct bonding
*bond
= bond_dev
->priv
;
3782 struct dev_mc_list
*dmi
;
3784 write_lock_bh(&bond
->lock
);
3787 * Do promisc before checking multicast_mode
3789 if ((bond_dev
->flags
& IFF_PROMISC
) && !(bond
->flags
& IFF_PROMISC
)) {
3790 bond_set_promiscuity(bond
, 1);
3793 if (!(bond_dev
->flags
& IFF_PROMISC
) && (bond
->flags
& IFF_PROMISC
)) {
3794 bond_set_promiscuity(bond
, -1);
3797 /* set allmulti flag to slaves */
3798 if ((bond_dev
->flags
& IFF_ALLMULTI
) && !(bond
->flags
& IFF_ALLMULTI
)) {
3799 bond_set_allmulti(bond
, 1);
3802 if (!(bond_dev
->flags
& IFF_ALLMULTI
) && (bond
->flags
& IFF_ALLMULTI
)) {
3803 bond_set_allmulti(bond
, -1);
3806 bond
->flags
= bond_dev
->flags
;
3808 /* looking for addresses to add to slaves' mc list */
3809 for (dmi
= bond_dev
->mc_list
; dmi
; dmi
= dmi
->next
) {
3810 if (!bond_mc_list_find_dmi(dmi
, bond
->mc_list
)) {
3811 bond_mc_add(bond
, dmi
->dmi_addr
, dmi
->dmi_addrlen
);
3815 /* looking for addresses to delete from slaves' list */
3816 for (dmi
= bond
->mc_list
; dmi
; dmi
= dmi
->next
) {
3817 if (!bond_mc_list_find_dmi(dmi
, bond_dev
->mc_list
)) {
3818 bond_mc_delete(bond
, dmi
->dmi_addr
, dmi
->dmi_addrlen
);
3822 /* save master's multicast list */
3823 bond_mc_list_destroy(bond
);
3824 bond_mc_list_copy(bond_dev
->mc_list
, bond
, GFP_ATOMIC
);
3826 write_unlock_bh(&bond
->lock
);
3830 * Change the MTU of all of a master's slaves to match the master
3832 static int bond_change_mtu(struct net_device
*bond_dev
, int new_mtu
)
3834 struct bonding
*bond
= bond_dev
->priv
;
3835 struct slave
*slave
, *stop_at
;
3839 dprintk("bond=%p, name=%s, new_mtu=%d\n", bond
,
3840 (bond_dev
? bond_dev
->name
: "None"), new_mtu
);
3842 /* Can't hold bond->lock with bh disabled here since
3843 * some base drivers panic. On the other hand we can't
3844 * hold bond->lock without bh disabled because we'll
3845 * deadlock. The only solution is to rely on the fact
3846 * that we're under rtnl_lock here, and the slaves
3847 * list won't change. This doesn't solve the problem
3848 * of setting the slave's MTU while it is
3849 * transmitting, but the assumption is that the base
3850 * driver can handle that.
3852 * TODO: figure out a way to safely iterate the slaves
3853 * list, but without holding a lock around the actual
3854 * call to the base driver.
3857 bond_for_each_slave(bond
, slave
, i
) {
3858 dprintk("s %p s->p %p c_m %p\n", slave
,
3859 slave
->prev
, slave
->dev
->change_mtu
);
3861 res
= dev_set_mtu(slave
->dev
, new_mtu
);
3864 /* If we failed to set the slave's mtu to the new value
3865 * we must abort the operation even in ACTIVE_BACKUP
3866 * mode, because if we allow the backup slaves to have
3867 * different mtu values than the active slave we'll
3868 * need to change their mtu when doing a failover. That
3869 * means changing their mtu from timer context, which
3870 * is probably not a good idea.
3872 dprintk("err %d %s\n", res
, slave
->dev
->name
);
3877 bond_dev
->mtu
= new_mtu
;
3882 /* unwind from head to the slave that failed */
3884 bond_for_each_slave_from_to(bond
, slave
, i
, bond
->first_slave
, stop_at
) {
3887 tmp_res
= dev_set_mtu(slave
->dev
, bond_dev
->mtu
);
3889 dprintk("unwind err %d dev %s\n", tmp_res
,
3900 * Note that many devices must be down to change the HW address, and
3901 * downing the master releases all slaves. We can make bonds full of
3902 * bonding devices to test this, however.
3904 static int bond_set_mac_address(struct net_device
*bond_dev
, void *addr
)
3906 struct bonding
*bond
= bond_dev
->priv
;
3907 struct sockaddr
*sa
= addr
, tmp_sa
;
3908 struct slave
*slave
, *stop_at
;
3912 dprintk("bond=%p, name=%s\n", bond
, (bond_dev
? bond_dev
->name
: "None"));
3914 if (!is_valid_ether_addr(sa
->sa_data
)) {
3915 return -EADDRNOTAVAIL
;
3918 /* Can't hold bond->lock with bh disabled here since
3919 * some base drivers panic. On the other hand we can't
3920 * hold bond->lock without bh disabled because we'll
3921 * deadlock. The only solution is to rely on the fact
3922 * that we're under rtnl_lock here, and the slaves
3923 * list won't change. This doesn't solve the problem
3924 * of setting the slave's hw address while it is
3925 * transmitting, but the assumption is that the base
3926 * driver can handle that.
3928 * TODO: figure out a way to safely iterate the slaves
3929 * list, but without holding a lock around the actual
3930 * call to the base driver.
3933 bond_for_each_slave(bond
, slave
, i
) {
3934 dprintk("slave %p %s\n", slave
, slave
->dev
->name
);
3936 if (slave
->dev
->set_mac_address
== NULL
) {
3938 dprintk("EOPNOTSUPP %s\n", slave
->dev
->name
);
3942 res
= dev_set_mac_address(slave
->dev
, addr
);
3944 /* TODO: consider downing the slave
3946 * User should expect communications
3947 * breakage anyway until ARP finish
3950 dprintk("err %d %s\n", res
, slave
->dev
->name
);
3956 memcpy(bond_dev
->dev_addr
, sa
->sa_data
, bond_dev
->addr_len
);
3960 memcpy(tmp_sa
.sa_data
, bond_dev
->dev_addr
, bond_dev
->addr_len
);
3961 tmp_sa
.sa_family
= bond_dev
->type
;
3963 /* unwind from head to the slave that failed */
3965 bond_for_each_slave_from_to(bond
, slave
, i
, bond
->first_slave
, stop_at
) {
3968 tmp_res
= dev_set_mac_address(slave
->dev
, &tmp_sa
);
3970 dprintk("unwind err %d dev %s\n", tmp_res
,
3978 static int bond_xmit_roundrobin(struct sk_buff
*skb
, struct net_device
*bond_dev
)
3980 struct bonding
*bond
= bond_dev
->priv
;
3981 struct slave
*slave
, *start_at
;
3985 read_lock(&bond
->lock
);
3987 if (!BOND_IS_OK(bond
)) {
3991 read_lock(&bond
->curr_slave_lock
);
3992 slave
= start_at
= bond
->curr_active_slave
;
3993 read_unlock(&bond
->curr_slave_lock
);
3999 bond_for_each_slave_from(bond
, slave
, i
, start_at
) {
4000 if (IS_UP(slave
->dev
) &&
4001 (slave
->link
== BOND_LINK_UP
) &&
4002 (slave
->state
== BOND_STATE_ACTIVE
)) {
4003 res
= bond_dev_queue_xmit(bond
, skb
, slave
->dev
);
4005 write_lock(&bond
->curr_slave_lock
);
4006 bond
->curr_active_slave
= slave
->next
;
4007 write_unlock(&bond
->curr_slave_lock
);
4016 /* no suitable interface, frame not sent */
4019 read_unlock(&bond
->lock
);
4025 * in active-backup mode, we know that bond->curr_active_slave is always valid if
4026 * the bond has a usable interface.
4028 static int bond_xmit_activebackup(struct sk_buff
*skb
, struct net_device
*bond_dev
)
4030 struct bonding
*bond
= bond_dev
->priv
;
4033 read_lock(&bond
->lock
);
4034 read_lock(&bond
->curr_slave_lock
);
4036 if (!BOND_IS_OK(bond
)) {
4040 if (!bond
->curr_active_slave
)
4043 res
= bond_dev_queue_xmit(bond
, skb
, bond
->curr_active_slave
->dev
);
4047 /* no suitable interface, frame not sent */
4050 read_unlock(&bond
->curr_slave_lock
);
4051 read_unlock(&bond
->lock
);
4056 * In bond_xmit_xor() , we determine the output device by using a pre-
4057 * determined xmit_hash_policy(), If the selected device is not enabled,
4058 * find the next active slave.
4060 static int bond_xmit_xor(struct sk_buff
*skb
, struct net_device
*bond_dev
)
4062 struct bonding
*bond
= bond_dev
->priv
;
4063 struct slave
*slave
, *start_at
;
4068 read_lock(&bond
->lock
);
4070 if (!BOND_IS_OK(bond
)) {
4074 slave_no
= bond
->xmit_hash_policy(skb
, bond_dev
, bond
->slave_cnt
);
4076 bond_for_each_slave(bond
, slave
, i
) {
4085 bond_for_each_slave_from(bond
, slave
, i
, start_at
) {
4086 if (IS_UP(slave
->dev
) &&
4087 (slave
->link
== BOND_LINK_UP
) &&
4088 (slave
->state
== BOND_STATE_ACTIVE
)) {
4089 res
= bond_dev_queue_xmit(bond
, skb
, slave
->dev
);
4096 /* no suitable interface, frame not sent */
4099 read_unlock(&bond
->lock
);
4104 * in broadcast mode, we send everything to all usable interfaces.
4106 static int bond_xmit_broadcast(struct sk_buff
*skb
, struct net_device
*bond_dev
)
4108 struct bonding
*bond
= bond_dev
->priv
;
4109 struct slave
*slave
, *start_at
;
4110 struct net_device
*tx_dev
= NULL
;
4114 read_lock(&bond
->lock
);
4116 if (!BOND_IS_OK(bond
)) {
4120 read_lock(&bond
->curr_slave_lock
);
4121 start_at
= bond
->curr_active_slave
;
4122 read_unlock(&bond
->curr_slave_lock
);
4128 bond_for_each_slave_from(bond
, slave
, i
, start_at
) {
4129 if (IS_UP(slave
->dev
) &&
4130 (slave
->link
== BOND_LINK_UP
) &&
4131 (slave
->state
== BOND_STATE_ACTIVE
)) {
4133 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
4135 printk(KERN_ERR DRV_NAME
4136 ": %s: Error: bond_xmit_broadcast(): "
4137 "skb_clone() failed\n",
4142 res
= bond_dev_queue_xmit(bond
, skb2
, tx_dev
);
4144 dev_kfree_skb(skb2
);
4148 tx_dev
= slave
->dev
;
4153 res
= bond_dev_queue_xmit(bond
, skb
, tx_dev
);
4158 /* no suitable interface, frame not sent */
4161 /* frame sent to all suitable interfaces */
4162 read_unlock(&bond
->lock
);
4166 /*------------------------- Device initialization ---------------------------*/
4169 * set bond mode specific net device operations
4171 void bond_set_mode_ops(struct bonding
*bond
, int mode
)
4173 struct net_device
*bond_dev
= bond
->dev
;
4176 case BOND_MODE_ROUNDROBIN
:
4177 bond_dev
->hard_start_xmit
= bond_xmit_roundrobin
;
4179 case BOND_MODE_ACTIVEBACKUP
:
4180 bond_dev
->hard_start_xmit
= bond_xmit_activebackup
;
4183 bond_dev
->hard_start_xmit
= bond_xmit_xor
;
4184 if (bond
->params
.xmit_policy
== BOND_XMIT_POLICY_LAYER34
)
4185 bond
->xmit_hash_policy
= bond_xmit_hash_policy_l34
;
4187 bond
->xmit_hash_policy
= bond_xmit_hash_policy_l2
;
4189 case BOND_MODE_BROADCAST
:
4190 bond_dev
->hard_start_xmit
= bond_xmit_broadcast
;
4192 case BOND_MODE_8023AD
:
4193 bond_set_master_3ad_flags(bond
);
4194 bond_dev
->hard_start_xmit
= bond_3ad_xmit_xor
;
4195 if (bond
->params
.xmit_policy
== BOND_XMIT_POLICY_LAYER34
)
4196 bond
->xmit_hash_policy
= bond_xmit_hash_policy_l34
;
4198 bond
->xmit_hash_policy
= bond_xmit_hash_policy_l2
;
4201 bond_set_master_alb_flags(bond
);
4204 bond_dev
->hard_start_xmit
= bond_alb_xmit
;
4205 bond_dev
->set_mac_address
= bond_alb_set_mac_address
;
4208 /* Should never happen, mode already checked */
4209 printk(KERN_ERR DRV_NAME
4210 ": %s: Error: Unknown bonding mode %d\n",
4217 static void bond_ethtool_get_drvinfo(struct net_device
*bond_dev
,
4218 struct ethtool_drvinfo
*drvinfo
)
4220 strncpy(drvinfo
->driver
, DRV_NAME
, 32);
4221 strncpy(drvinfo
->version
, DRV_VERSION
, 32);
4222 snprintf(drvinfo
->fw_version
, 32, "%d", BOND_ABI_VERSION
);
4225 static const struct ethtool_ops bond_ethtool_ops
= {
4226 .get_tx_csum
= ethtool_op_get_tx_csum
,
4227 .get_tso
= ethtool_op_get_tso
,
4228 .get_ufo
= ethtool_op_get_ufo
,
4229 .get_sg
= ethtool_op_get_sg
,
4230 .get_drvinfo
= bond_ethtool_get_drvinfo
,
4234 * Does not allocate but creates a /proc entry.
4237 static int bond_init(struct net_device
*bond_dev
, struct bond_params
*params
)
4239 struct bonding
*bond
= bond_dev
->priv
;
4241 dprintk("Begin bond_init for %s\n", bond_dev
->name
);
4243 /* initialize rwlocks */
4244 rwlock_init(&bond
->lock
);
4245 rwlock_init(&bond
->curr_slave_lock
);
4247 bond
->params
= *params
; /* copy params struct */
4249 /* Initialize pointers */
4250 bond
->first_slave
= NULL
;
4251 bond
->curr_active_slave
= NULL
;
4252 bond
->current_arp_slave
= NULL
;
4253 bond
->primary_slave
= NULL
;
4254 bond
->dev
= bond_dev
;
4255 INIT_LIST_HEAD(&bond
->vlan_list
);
4257 /* Initialize the device entry points */
4258 bond_dev
->open
= bond_open
;
4259 bond_dev
->stop
= bond_close
;
4260 bond_dev
->get_stats
= bond_get_stats
;
4261 bond_dev
->do_ioctl
= bond_do_ioctl
;
4262 bond_dev
->ethtool_ops
= &bond_ethtool_ops
;
4263 bond_dev
->set_multicast_list
= bond_set_multicast_list
;
4264 bond_dev
->change_mtu
= bond_change_mtu
;
4265 bond_dev
->set_mac_address
= bond_set_mac_address
;
4267 bond_set_mode_ops(bond
, bond
->params
.mode
);
4269 bond_dev
->destructor
= free_netdev
;
4271 /* Initialize the device options */
4272 bond_dev
->tx_queue_len
= 0;
4273 bond_dev
->flags
|= IFF_MASTER
|IFF_MULTICAST
;
4274 bond_dev
->priv_flags
|= IFF_BONDING
;
4276 /* At first, we block adding VLANs. That's the only way to
4277 * prevent problems that occur when adding VLANs over an
4278 * empty bond. The block will be removed once non-challenged
4279 * slaves are enslaved.
4281 bond_dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
4283 /* don't acquire bond device's netif_tx_lock when
4285 bond_dev
->features
|= NETIF_F_LLTX
;
4287 /* By default, we declare the bond to be fully
4288 * VLAN hardware accelerated capable. Special
4289 * care is taken in the various xmit functions
4290 * when there are slaves that are not hw accel
4293 bond_dev
->vlan_rx_register
= bond_vlan_rx_register
;
4294 bond_dev
->vlan_rx_add_vid
= bond_vlan_rx_add_vid
;
4295 bond_dev
->vlan_rx_kill_vid
= bond_vlan_rx_kill_vid
;
4296 bond_dev
->features
|= (NETIF_F_HW_VLAN_TX
|
4297 NETIF_F_HW_VLAN_RX
|
4298 NETIF_F_HW_VLAN_FILTER
);
4300 #ifdef CONFIG_PROC_FS
4301 bond_create_proc_entry(bond
);
4304 list_add_tail(&bond
->bond_list
, &bond_dev_list
);
4309 /* De-initialize device specific data.
4310 * Caller must hold rtnl_lock.
4312 void bond_deinit(struct net_device
*bond_dev
)
4314 struct bonding
*bond
= bond_dev
->priv
;
4316 list_del(&bond
->bond_list
);
4318 #ifdef CONFIG_PROC_FS
4319 bond_remove_proc_entry(bond
);
4323 /* Unregister and free all bond devices.
4324 * Caller must hold rtnl_lock.
4326 static void bond_free_all(void)
4328 struct bonding
*bond
, *nxt
;
4330 list_for_each_entry_safe(bond
, nxt
, &bond_dev_list
, bond_list
) {
4331 struct net_device
*bond_dev
= bond
->dev
;
4333 bond_mc_list_destroy(bond
);
4334 /* Release the bonded slaves */
4335 bond_release_all(bond_dev
);
4336 bond_deinit(bond_dev
);
4337 unregister_netdevice(bond_dev
);
4340 #ifdef CONFIG_PROC_FS
4341 bond_destroy_proc_dir();
4345 /*------------------------- Module initialization ---------------------------*/
4348 * Convert string input module parms. Accept either the
4349 * number of the mode or its string name.
4351 int bond_parse_parm(char *mode_arg
, struct bond_parm_tbl
*tbl
)
4355 for (i
= 0; tbl
[i
].modename
; i
++) {
4356 if ((isdigit(*mode_arg
) &&
4357 tbl
[i
].mode
== simple_strtol(mode_arg
, NULL
, 0)) ||
4358 (strncmp(mode_arg
, tbl
[i
].modename
,
4359 strlen(tbl
[i
].modename
)) == 0)) {
4367 static int bond_check_params(struct bond_params
*params
)
4369 int arp_validate_value
;
4372 * Convert string parameters.
4375 bond_mode
= bond_parse_parm(mode
, bond_mode_tbl
);
4376 if (bond_mode
== -1) {
4377 printk(KERN_ERR DRV_NAME
4378 ": Error: Invalid bonding mode \"%s\"\n",
4379 mode
== NULL
? "NULL" : mode
);
4384 if (xmit_hash_policy
) {
4385 if ((bond_mode
!= BOND_MODE_XOR
) &&
4386 (bond_mode
!= BOND_MODE_8023AD
)) {
4387 printk(KERN_INFO DRV_NAME
4388 ": xor_mode param is irrelevant in mode %s\n",
4389 bond_mode_name(bond_mode
));
4391 xmit_hashtype
= bond_parse_parm(xmit_hash_policy
,
4393 if (xmit_hashtype
== -1) {
4394 printk(KERN_ERR DRV_NAME
4395 ": Error: Invalid xmit_hash_policy \"%s\"\n",
4396 xmit_hash_policy
== NULL
? "NULL" :
4404 if (bond_mode
!= BOND_MODE_8023AD
) {
4405 printk(KERN_INFO DRV_NAME
4406 ": lacp_rate param is irrelevant in mode %s\n",
4407 bond_mode_name(bond_mode
));
4409 lacp_fast
= bond_parse_parm(lacp_rate
, bond_lacp_tbl
);
4410 if (lacp_fast
== -1) {
4411 printk(KERN_ERR DRV_NAME
4412 ": Error: Invalid lacp rate \"%s\"\n",
4413 lacp_rate
== NULL
? "NULL" : lacp_rate
);
4419 if (max_bonds
< 1 || max_bonds
> INT_MAX
) {
4420 printk(KERN_WARNING DRV_NAME
4421 ": Warning: max_bonds (%d) not in range %d-%d, so it "
4422 "was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
4423 max_bonds
, 1, INT_MAX
, BOND_DEFAULT_MAX_BONDS
);
4424 max_bonds
= BOND_DEFAULT_MAX_BONDS
;
4428 printk(KERN_WARNING DRV_NAME
4429 ": Warning: miimon module parameter (%d), "
4430 "not in range 0-%d, so it was reset to %d\n",
4431 miimon
, INT_MAX
, BOND_LINK_MON_INTERV
);
4432 miimon
= BOND_LINK_MON_INTERV
;
4436 printk(KERN_WARNING DRV_NAME
4437 ": Warning: updelay module parameter (%d), "
4438 "not in range 0-%d, so it was reset to 0\n",
4443 if (downdelay
< 0) {
4444 printk(KERN_WARNING DRV_NAME
4445 ": Warning: downdelay module parameter (%d), "
4446 "not in range 0-%d, so it was reset to 0\n",
4447 downdelay
, INT_MAX
);
4451 if ((use_carrier
!= 0) && (use_carrier
!= 1)) {
4452 printk(KERN_WARNING DRV_NAME
4453 ": Warning: use_carrier module parameter (%d), "
4454 "not of valid value (0/1), so it was set to 1\n",
4459 /* reset values for 802.3ad */
4460 if (bond_mode
== BOND_MODE_8023AD
) {
4462 printk(KERN_WARNING DRV_NAME
4463 ": Warning: miimon must be specified, "
4464 "otherwise bonding will not detect link "
4465 "failure, speed and duplex which are "
4466 "essential for 802.3ad operation\n");
4467 printk(KERN_WARNING
"Forcing miimon to 100msec\n");
4472 /* reset values for TLB/ALB */
4473 if ((bond_mode
== BOND_MODE_TLB
) ||
4474 (bond_mode
== BOND_MODE_ALB
)) {
4476 printk(KERN_WARNING DRV_NAME
4477 ": Warning: miimon must be specified, "
4478 "otherwise bonding will not detect link "
4479 "failure and link speed which are essential "
4480 "for TLB/ALB load balancing\n");
4481 printk(KERN_WARNING
"Forcing miimon to 100msec\n");
4486 if (bond_mode
== BOND_MODE_ALB
) {
4487 printk(KERN_NOTICE DRV_NAME
4488 ": In ALB mode you might experience client "
4489 "disconnections upon reconnection of a link if the "
4490 "bonding module updelay parameter (%d msec) is "
4491 "incompatible with the forwarding delay time of the "
4497 if (updelay
|| downdelay
) {
4498 /* just warn the user the up/down delay will have
4499 * no effect since miimon is zero...
4501 printk(KERN_WARNING DRV_NAME
4502 ": Warning: miimon module parameter not set "
4503 "and updelay (%d) or downdelay (%d) module "
4504 "parameter is set; updelay and downdelay have "
4505 "no effect unless miimon is set\n",
4506 updelay
, downdelay
);
4509 /* don't allow arp monitoring */
4511 printk(KERN_WARNING DRV_NAME
4512 ": Warning: miimon (%d) and arp_interval (%d) "
4513 "can't be used simultaneously, disabling ARP "
4515 miimon
, arp_interval
);
4519 if ((updelay
% miimon
) != 0) {
4520 printk(KERN_WARNING DRV_NAME
4521 ": Warning: updelay (%d) is not a multiple "
4522 "of miimon (%d), updelay rounded to %d ms\n",
4523 updelay
, miimon
, (updelay
/ miimon
) * miimon
);
4528 if ((downdelay
% miimon
) != 0) {
4529 printk(KERN_WARNING DRV_NAME
4530 ": Warning: downdelay (%d) is not a multiple "
4531 "of miimon (%d), downdelay rounded to %d ms\n",
4533 (downdelay
/ miimon
) * miimon
);
4536 downdelay
/= miimon
;
4539 if (arp_interval
< 0) {
4540 printk(KERN_WARNING DRV_NAME
4541 ": Warning: arp_interval module parameter (%d) "
4542 ", not in range 0-%d, so it was reset to %d\n",
4543 arp_interval
, INT_MAX
, BOND_LINK_ARP_INTERV
);
4544 arp_interval
= BOND_LINK_ARP_INTERV
;
4547 for (arp_ip_count
= 0;
4548 (arp_ip_count
< BOND_MAX_ARP_TARGETS
) && arp_ip_target
[arp_ip_count
];
4550 /* not complete check, but should be good enough to
4552 if (!isdigit(arp_ip_target
[arp_ip_count
][0])) {
4553 printk(KERN_WARNING DRV_NAME
4554 ": Warning: bad arp_ip_target module parameter "
4555 "(%s), ARP monitoring will not be performed\n",
4556 arp_ip_target
[arp_ip_count
]);
4559 u32 ip
= in_aton(arp_ip_target
[arp_ip_count
]);
4560 arp_target
[arp_ip_count
] = ip
;
4564 if (arp_interval
&& !arp_ip_count
) {
4565 /* don't allow arping if no arp_ip_target given... */
4566 printk(KERN_WARNING DRV_NAME
4567 ": Warning: arp_interval module parameter (%d) "
4568 "specified without providing an arp_ip_target "
4569 "parameter, arp_interval was reset to 0\n",
4575 if (bond_mode
!= BOND_MODE_ACTIVEBACKUP
) {
4576 printk(KERN_ERR DRV_NAME
4577 ": arp_validate only supported in active-backup mode\n");
4580 if (!arp_interval
) {
4581 printk(KERN_ERR DRV_NAME
4582 ": arp_validate requires arp_interval\n");
4586 arp_validate_value
= bond_parse_parm(arp_validate
,
4588 if (arp_validate_value
== -1) {
4589 printk(KERN_ERR DRV_NAME
4590 ": Error: invalid arp_validate \"%s\"\n",
4591 arp_validate
== NULL
? "NULL" : arp_validate
);
4595 arp_validate_value
= 0;
4598 printk(KERN_INFO DRV_NAME
4599 ": MII link monitoring set to %d ms\n",
4601 } else if (arp_interval
) {
4604 printk(KERN_INFO DRV_NAME
4605 ": ARP monitoring set to %d ms, validate %s, with %d target(s):",
4607 arp_validate_tbl
[arp_validate_value
].modename
,
4610 for (i
= 0; i
< arp_ip_count
; i
++)
4611 printk (" %s", arp_ip_target
[i
]);
4616 /* miimon and arp_interval not set, we need one so things
4617 * work as expected, see bonding.txt for details
4619 printk(KERN_WARNING DRV_NAME
4620 ": Warning: either miimon or arp_interval and "
4621 "arp_ip_target module parameters must be specified, "
4622 "otherwise bonding will not detect link failures! see "
4623 "bonding.txt for details.\n");
4626 if (primary
&& !USES_PRIMARY(bond_mode
)) {
4627 /* currently, using a primary only makes sense
4628 * in active backup, TLB or ALB modes
4630 printk(KERN_WARNING DRV_NAME
4631 ": Warning: %s primary device specified but has no "
4632 "effect in %s mode\n",
4633 primary
, bond_mode_name(bond_mode
));
4637 /* fill params struct with the proper values */
4638 params
->mode
= bond_mode
;
4639 params
->xmit_policy
= xmit_hashtype
;
4640 params
->miimon
= miimon
;
4641 params
->arp_interval
= arp_interval
;
4642 params
->arp_validate
= arp_validate_value
;
4643 params
->updelay
= updelay
;
4644 params
->downdelay
= downdelay
;
4645 params
->use_carrier
= use_carrier
;
4646 params
->lacp_fast
= lacp_fast
;
4647 params
->primary
[0] = 0;
4650 strncpy(params
->primary
, primary
, IFNAMSIZ
);
4651 params
->primary
[IFNAMSIZ
- 1] = 0;
4654 memcpy(params
->arp_targets
, arp_target
, sizeof(arp_target
));
4659 static struct lock_class_key bonding_netdev_xmit_lock_key
;
4661 /* Create a new bond based on the specified name and bonding parameters.
4662 * If name is NULL, obtain a suitable "bond%d" name for us.
4663 * Caller must NOT hold rtnl_lock; we need to release it here before we
4664 * set up our sysfs entries.
4666 int bond_create(char *name
, struct bond_params
*params
, struct bonding
**newbond
)
4668 struct net_device
*bond_dev
;
4672 bond_dev
= alloc_netdev(sizeof(struct bonding
), name
? name
: "",
4675 printk(KERN_ERR DRV_NAME
4676 ": %s: eek! can't alloc netdev!\n",
4683 res
= dev_alloc_name(bond_dev
, "bond%d");
4688 /* bond_init() must be called after dev_alloc_name() (for the
4689 * /proc files), but before register_netdevice(), because we
4690 * need to set function pointers.
4693 res
= bond_init(bond_dev
, params
);
4698 SET_MODULE_OWNER(bond_dev
);
4700 res
= register_netdevice(bond_dev
);
4705 lockdep_set_class(&bond_dev
->_xmit_lock
, &bonding_netdev_xmit_lock_key
);
4708 *newbond
= bond_dev
->priv
;
4710 netif_carrier_off(bond_dev
);
4712 rtnl_unlock(); /* allows sysfs registration of net device */
4713 res
= bond_create_sysfs_entry(bond_dev
->priv
);
4722 bond_deinit(bond_dev
);
4724 free_netdev(bond_dev
);
4730 static int __init
bonding_init(void)
4735 printk(KERN_INFO
"%s", version
);
4737 res
= bond_check_params(&bonding_defaults
);
4742 #ifdef CONFIG_PROC_FS
4743 bond_create_proc_dir();
4745 for (i
= 0; i
< max_bonds
; i
++) {
4746 res
= bond_create(NULL
, &bonding_defaults
, NULL
);
4751 res
= bond_create_sysfs();
4755 register_netdevice_notifier(&bond_netdev_notifier
);
4756 register_inetaddr_notifier(&bond_inetaddr_notifier
);
4762 bond_destroy_sysfs();
4769 static void __exit
bonding_exit(void)
4771 unregister_netdevice_notifier(&bond_netdev_notifier
);
4772 unregister_inetaddr_notifier(&bond_inetaddr_notifier
);
4776 bond_destroy_sysfs();
4780 module_init(bonding_init
);
4781 module_exit(bonding_exit
);
4782 MODULE_LICENSE("GPL");
4783 MODULE_VERSION(DRV_VERSION
);
4784 MODULE_DESCRIPTION(DRV_DESCRIPTION
", v" DRV_VERSION
);
4785 MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
4786 MODULE_SUPPORTED_DEVICE("most ethernet devices");