Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * originally based on the dummy device. |
| 3 | * |
| 4 | * Copyright 1999, Thomas Davis, tadavis@lbl.gov. |
| 5 | * Licensed under the GPL. Based on dummy.c, and eql.c devices. |
| 6 | * |
| 7 | * bonding.c: an Ethernet Bonding driver |
| 8 | * |
| 9 | * This is useful to talk to a Cisco EtherChannel compatible equipment: |
| 10 | * Cisco 5500 |
| 11 | * Sun Trunking (Solaris) |
| 12 | * Alteon AceDirector Trunks |
| 13 | * Linux Bonding |
| 14 | * and probably many L2 switches ... |
| 15 | * |
| 16 | * How it works: |
| 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. |
| 22 | * |
| 23 | * ifconfig bond0 down |
| 24 | * will release all slaves, marking them as down. |
| 25 | * |
| 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. |
| 31 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | */ |
| 33 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 34 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/kernel.h> |
| 37 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 43 | #include <linux/in.h> |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 44 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/ip.h> |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 46 | #include <linux/tcp.h> |
| 47 | #include <linux/udp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 56 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <asm/dma.h> |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 59 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <linux/errno.h> |
| 61 | #include <linux/netdevice.h> |
| 62 | #include <linux/inetdevice.h> |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 63 | #include <linux/igmp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <linux/etherdevice.h> |
| 65 | #include <linux/skbuff.h> |
| 66 | #include <net/sock.h> |
| 67 | #include <linux/rtnetlink.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/smp.h> |
| 69 | #include <linux/if_ether.h> |
| 70 | #include <net/arp.h> |
| 71 | #include <linux/mii.h> |
| 72 | #include <linux/ethtool.h> |
| 73 | #include <linux/if_vlan.h> |
| 74 | #include <linux/if_bonding.h> |
David Sterba | b63bb73 | 2007-12-06 23:40:33 -0800 | [diff] [blame] | 75 | #include <linux/jiffies.h> |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 76 | #include <linux/preempt.h> |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 77 | #include <net/route.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 78 | #include <net/net_namespace.h> |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 79 | #include <net/netns/generic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #include "bonding.h" |
| 81 | #include "bond_3ad.h" |
| 82 | #include "bond_alb.h" |
| 83 | |
| 84 | /*---------------------------- Module parameters ----------------------------*/ |
| 85 | |
| 86 | /* monitor all links that often (in milliseconds). <=0 disables monitoring */ |
| 87 | #define BOND_LINK_MON_INTERV 0 |
| 88 | #define BOND_LINK_ARP_INTERV 0 |
| 89 | |
| 90 | static int max_bonds = BOND_DEFAULT_MAX_BONDS; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 91 | static int tx_queues = BOND_DEFAULT_TX_QUEUES; |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 92 | static int num_peer_notif = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int miimon = BOND_LINK_MON_INTERV; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 94 | static int updelay; |
| 95 | static int downdelay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | static int use_carrier = 1; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 97 | static char *mode; |
| 98 | static char *primary; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 99 | static char *primary_reselect; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 100 | static char *lacp_rate; |
| 101 | static char *ad_select; |
| 102 | static char *xmit_hash_policy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | static int arp_interval = BOND_LINK_ARP_INTERV; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 104 | static char *arp_ip_target[BOND_MAX_ARP_TARGETS]; |
| 105 | static char *arp_validate; |
| 106 | static char *fail_over_mac; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 107 | static int all_slaves_active = 0; |
Stephen Hemminger | d2991f7 | 2009-06-12 19:02:44 +0000 | [diff] [blame] | 108 | static struct bond_params bonding_defaults; |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 109 | static int resend_igmp = BOND_DEFAULT_RESEND_IGMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | module_param(max_bonds, int, 0); |
| 112 | MODULE_PARM_DESC(max_bonds, "Max number of bonded devices"); |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 113 | module_param(tx_queues, int, 0); |
| 114 | MODULE_PARM_DESC(tx_queues, "Max number of transmit queues (default = 16)"); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 115 | module_param_named(num_grat_arp, num_peer_notif, int, 0644); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 116 | MODULE_PARM_DESC(num_grat_arp, "Number of peer notifications to send on " |
| 117 | "failover event (alias of num_unsol_na)"); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 118 | module_param_named(num_unsol_na, num_peer_notif, int, 0644); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 119 | MODULE_PARM_DESC(num_unsol_na, "Number of peer notifications to send on " |
| 120 | "failover event (alias of num_grat_arp)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | module_param(miimon, int, 0); |
| 122 | MODULE_PARM_DESC(miimon, "Link check interval in milliseconds"); |
| 123 | module_param(updelay, int, 0); |
| 124 | MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds"); |
| 125 | module_param(downdelay, int, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 126 | MODULE_PARM_DESC(downdelay, "Delay before considering link down, " |
| 127 | "in milliseconds"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | module_param(use_carrier, int, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 129 | MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; " |
| 130 | "0 for off, 1 for on (default)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | module_param(mode, charp, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 132 | MODULE_PARM_DESC(mode, "Mode of operation; 0 for balance-rr, " |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 133 | "1 for active-backup, 2 for balance-xor, " |
| 134 | "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, " |
| 135 | "6 for balance-alb"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | module_param(primary, charp, 0); |
| 137 | MODULE_PARM_DESC(primary, "Primary network device to use"); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 138 | module_param(primary_reselect, charp, 0); |
| 139 | MODULE_PARM_DESC(primary_reselect, "Reselect primary slave " |
| 140 | "once it comes up; " |
| 141 | "0 for always (default), " |
| 142 | "1 for only if speed of primary is " |
| 143 | "better, " |
| 144 | "2 for only on active slave " |
| 145 | "failure"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | module_param(lacp_rate, charp, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 147 | MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner; " |
| 148 | "0 for slow, 1 for fast"); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 149 | module_param(ad_select, charp, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 150 | MODULE_PARM_DESC(ad_select, "803.ad aggregation selection logic; " |
| 151 | "0 for stable (default), 1 for bandwidth, " |
| 152 | "2 for count"); |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 153 | module_param(xmit_hash_policy, charp, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 154 | MODULE_PARM_DESC(xmit_hash_policy, "balance-xor and 802.3ad hashing method; " |
| 155 | "0 for layer 2 (default), 1 for layer 3+4, " |
| 156 | "2 for layer 2+3"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | module_param(arp_interval, int, 0); |
| 158 | MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds"); |
| 159 | module_param_array(arp_ip_target, charp, NULL, 0); |
| 160 | MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form"); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 161 | module_param(arp_validate, charp, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 162 | MODULE_PARM_DESC(arp_validate, "validate src/dst of ARP probes; " |
| 163 | "0 for none (default), 1 for active, " |
| 164 | "2 for backup, 3 for all"); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 165 | module_param(fail_over_mac, charp, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 166 | MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to " |
| 167 | "the same MAC; 0 for none (default), " |
| 168 | "1 for active, 2 for follow"); |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 169 | module_param(all_slaves_active, int, 0); |
| 170 | MODULE_PARM_DESC(all_slaves_active, "Keep all frames received on an interface" |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 171 | "by setting active flag for all slaves; " |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 172 | "0 for never (default), 1 for always."); |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 173 | module_param(resend_igmp, int, 0); |
Andy Gospodarek | 90e6247 | 2011-05-25 04:41:59 +0000 | [diff] [blame] | 174 | MODULE_PARM_DESC(resend_igmp, "Number of IGMP membership reports to send on " |
| 175 | "link failure"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /*----------------------------- Global variables ----------------------------*/ |
| 178 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 179 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Neil Horman | fb4fa76 | 2010-12-06 09:05:50 +0000 | [diff] [blame] | 180 | atomic_t netpoll_block_tx = ATOMIC_INIT(0); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
Eric Dumazet | f99189b | 2009-11-17 10:42:49 +0000 | [diff] [blame] | 183 | int bond_net_id __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 185 | static __be32 arp_target[BOND_MAX_ARP_TARGETS]; |
| 186 | static int arp_ip_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | static int bond_mode = BOND_MODE_ROUNDROBIN; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 188 | static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2; |
| 189 | static int lacp_fast; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 191 | const struct bond_parm_tbl bond_lacp_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { "slow", AD_LACP_SLOW}, |
| 193 | { "fast", AD_LACP_FAST}, |
| 194 | { NULL, -1}, |
| 195 | }; |
| 196 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 197 | const struct bond_parm_tbl bond_mode_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { "balance-rr", BOND_MODE_ROUNDROBIN}, |
| 199 | { "active-backup", BOND_MODE_ACTIVEBACKUP}, |
| 200 | { "balance-xor", BOND_MODE_XOR}, |
| 201 | { "broadcast", BOND_MODE_BROADCAST}, |
| 202 | { "802.3ad", BOND_MODE_8023AD}, |
| 203 | { "balance-tlb", BOND_MODE_TLB}, |
| 204 | { "balance-alb", BOND_MODE_ALB}, |
| 205 | { NULL, -1}, |
| 206 | }; |
| 207 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 208 | const struct bond_parm_tbl xmit_hashtype_tbl[] = { |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 209 | { "layer2", BOND_XMIT_POLICY_LAYER2}, |
| 210 | { "layer3+4", BOND_XMIT_POLICY_LAYER34}, |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 211 | { "layer2+3", BOND_XMIT_POLICY_LAYER23}, |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 212 | { NULL, -1}, |
| 213 | }; |
| 214 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 215 | const struct bond_parm_tbl arp_validate_tbl[] = { |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 216 | { "none", BOND_ARP_VALIDATE_NONE}, |
| 217 | { "active", BOND_ARP_VALIDATE_ACTIVE}, |
| 218 | { "backup", BOND_ARP_VALIDATE_BACKUP}, |
| 219 | { "all", BOND_ARP_VALIDATE_ALL}, |
| 220 | { NULL, -1}, |
| 221 | }; |
| 222 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 223 | const struct bond_parm_tbl fail_over_mac_tbl[] = { |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 224 | { "none", BOND_FOM_NONE}, |
| 225 | { "active", BOND_FOM_ACTIVE}, |
| 226 | { "follow", BOND_FOM_FOLLOW}, |
| 227 | { NULL, -1}, |
| 228 | }; |
| 229 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 230 | const struct bond_parm_tbl pri_reselect_tbl[] = { |
| 231 | { "always", BOND_PRI_RESELECT_ALWAYS}, |
| 232 | { "better", BOND_PRI_RESELECT_BETTER}, |
| 233 | { "failure", BOND_PRI_RESELECT_FAILURE}, |
| 234 | { NULL, -1}, |
| 235 | }; |
| 236 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 237 | struct bond_parm_tbl ad_select_tbl[] = { |
| 238 | { "stable", BOND_AD_STABLE}, |
| 239 | { "bandwidth", BOND_AD_BANDWIDTH}, |
| 240 | { "count", BOND_AD_COUNT}, |
| 241 | { NULL, -1}, |
| 242 | }; |
| 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | /*-------------------------- Forward declarations ---------------------------*/ |
| 245 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 246 | static int bond_init(struct net_device *bond_dev); |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 247 | static void bond_uninit(struct net_device *bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | /*---------------------------- General routines -----------------------------*/ |
| 250 | |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 251 | const char *bond_mode_name(int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Holger Eitzenberger | 77afc92 | 2008-12-09 23:08:09 -0800 | [diff] [blame] | 253 | static const char *names[] = { |
| 254 | [BOND_MODE_ROUNDROBIN] = "load balancing (round-robin)", |
| 255 | [BOND_MODE_ACTIVEBACKUP] = "fault-tolerance (active-backup)", |
| 256 | [BOND_MODE_XOR] = "load balancing (xor)", |
| 257 | [BOND_MODE_BROADCAST] = "fault-tolerance (broadcast)", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 258 | [BOND_MODE_8023AD] = "IEEE 802.3ad Dynamic link aggregation", |
Holger Eitzenberger | 77afc92 | 2008-12-09 23:08:09 -0800 | [diff] [blame] | 259 | [BOND_MODE_TLB] = "transmit load balancing", |
| 260 | [BOND_MODE_ALB] = "adaptive load balancing", |
| 261 | }; |
| 262 | |
| 263 | if (mode < 0 || mode > BOND_MODE_ALB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return "unknown"; |
Holger Eitzenberger | 77afc92 | 2008-12-09 23:08:09 -0800 | [diff] [blame] | 265 | |
| 266 | return names[mode]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /*---------------------------------- VLAN -----------------------------------*/ |
| 270 | |
| 271 | /** |
| 272 | * bond_add_vlan - add a new vlan id on bond |
| 273 | * @bond: bond that got the notification |
| 274 | * @vlan_id: the vlan id to add |
| 275 | * |
| 276 | * Returns -ENOMEM if allocation failed. |
| 277 | */ |
| 278 | static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id) |
| 279 | { |
| 280 | struct vlan_entry *vlan; |
| 281 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 282 | pr_debug("bond: %s, vlan id %d\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 283 | (bond ? bond->dev->name : "None"), vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 285 | vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 286 | if (!vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | INIT_LIST_HEAD(&vlan->vlan_list); |
| 290 | vlan->vlan_id = vlan_id; |
| 291 | |
| 292 | write_lock_bh(&bond->lock); |
| 293 | |
| 294 | list_add_tail(&vlan->vlan_list, &bond->vlan_list); |
| 295 | |
| 296 | write_unlock_bh(&bond->lock); |
| 297 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 298 | pr_debug("added VLAN ID %d on bond %s\n", vlan_id, bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * bond_del_vlan - delete a vlan id from bond |
| 305 | * @bond: bond that got the notification |
| 306 | * @vlan_id: the vlan id to delete |
| 307 | * |
| 308 | * returns -ENODEV if @vlan_id was not found in @bond. |
| 309 | */ |
| 310 | static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id) |
| 311 | { |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 312 | struct vlan_entry *vlan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | int res = -ENODEV; |
| 314 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 315 | pr_debug("bond: %s, vlan id %d\n", bond->dev->name, vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 317 | block_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | write_lock_bh(&bond->lock); |
| 319 | |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 320 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | if (vlan->vlan_id == vlan_id) { |
| 322 | list_del(&vlan->vlan_list); |
| 323 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 324 | if (bond_is_lb(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | bond_alb_clear_vlan(bond, vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 327 | pr_debug("removed VLAN ID %d from bond %s\n", |
| 328 | vlan_id, bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | kfree(vlan); |
| 331 | |
| 332 | if (list_empty(&bond->vlan_list) && |
| 333 | (bond->slave_cnt == 0)) { |
| 334 | /* Last VLAN removed and no slaves, so |
| 335 | * restore block on adding VLANs. This will |
| 336 | * be removed once new slaves that are not |
| 337 | * VLAN challenged will be added. |
| 338 | */ |
| 339 | bond->dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 340 | } |
| 341 | |
| 342 | res = 0; |
| 343 | goto out; |
| 344 | } |
| 345 | } |
| 346 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 347 | pr_debug("couldn't find VLAN ID %d in bond %s\n", |
| 348 | vlan_id, bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | out: |
| 351 | write_unlock_bh(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 352 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return res; |
| 354 | } |
| 355 | |
| 356 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | * bond_next_vlan - safely skip to the next item in the vlans list. |
| 358 | * @bond: the bond we're working on |
| 359 | * @curr: item we're advancing from |
| 360 | * |
| 361 | * Returns %NULL if list is empty, bond->next_vlan if @curr is %NULL, |
| 362 | * or @curr->next otherwise (even if it is @curr itself again). |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 363 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | * Caller must hold bond->lock |
| 365 | */ |
| 366 | struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr) |
| 367 | { |
| 368 | struct vlan_entry *next, *last; |
| 369 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 370 | if (list_empty(&bond->vlan_list)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | if (!curr) { |
| 374 | next = list_entry(bond->vlan_list.next, |
| 375 | struct vlan_entry, vlan_list); |
| 376 | } else { |
| 377 | last = list_entry(bond->vlan_list.prev, |
| 378 | struct vlan_entry, vlan_list); |
| 379 | if (last == curr) { |
| 380 | next = list_entry(bond->vlan_list.next, |
| 381 | struct vlan_entry, vlan_list); |
| 382 | } else { |
| 383 | next = list_entry(curr->vlan_list.next, |
| 384 | struct vlan_entry, vlan_list); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | return next; |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * bond_dev_queue_xmit - Prepare skb for xmit. |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 393 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | * @bond: bond device that got this skb for tx. |
| 395 | * @skb: hw accel VLAN tagged skb to transmit |
| 396 | * @slave_dev: slave that is supposed to xmit this skbuff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 398 | int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, |
| 399 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
Ben Hutchings | 8387451 | 2010-12-13 08:19:28 +0000 | [diff] [blame] | 401 | skb->dev = slave_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | skb->priority = 1; |
Amerigo Wang | 080e413 | 2011-02-17 23:43:33 +0000 | [diff] [blame] | 403 | if (unlikely(netpoll_tx_running(slave_dev))) |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 404 | bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb); |
Amerigo Wang | 080e413 | 2011-02-17 23:43:33 +0000 | [diff] [blame] | 405 | else |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 406 | dev_queue_xmit(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | /* |
| 412 | * In the following 3 functions, bond_vlan_rx_register(), bond_vlan_rx_add_vid |
| 413 | * and bond_vlan_rx_kill_vid, We don't protect the slave list iteration with a |
| 414 | * lock because: |
| 415 | * a. This operation is performed in IOCTL context, |
| 416 | * b. The operation is protected by the RTNL semaphore in the 8021q code, |
| 417 | * c. Holding a lock with BH disabled while directly calling a base driver |
| 418 | * entry point is generally a BAD idea. |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 419 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | * The design of synchronization/protection for this operation in the 8021q |
| 421 | * module is good for one or more VLAN devices over a single physical device |
| 422 | * and cannot be extended for a teaming solution like bonding, so there is a |
| 423 | * potential race condition here where a net device from the vlan group might |
| 424 | * be referenced (either by a base driver or the 8021q code) while it is being |
| 425 | * removed from the system. However, it turns out we're not making matters |
| 426 | * worse, and if it works for regular VLAN usage it will work here too. |
| 427 | */ |
| 428 | |
| 429 | /** |
| 430 | * bond_vlan_rx_register - Propagates registration to slaves |
| 431 | * @bond_dev: bonding net device that got called |
| 432 | * @grp: vlan group being registered |
| 433 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 434 | static void bond_vlan_rx_register(struct net_device *bond_dev, |
| 435 | struct vlan_group *grp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 437 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | struct slave *slave; |
| 439 | int i; |
| 440 | |
Jarek Poplawski | a71fb88 | 2010-10-27 07:08:22 +0000 | [diff] [blame] | 441 | write_lock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | bond->vlgrp = grp; |
Jarek Poplawski | a71fb88 | 2010-10-27 07:08:22 +0000 | [diff] [blame] | 443 | write_unlock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | bond_for_each_slave(bond, slave, i) { |
| 446 | struct net_device *slave_dev = slave->dev; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 447 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 450 | slave_ops->ndo_vlan_rx_register) { |
| 451 | slave_ops->ndo_vlan_rx_register(slave_dev, grp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * bond_vlan_rx_add_vid - Propagates adding an id to slaves |
| 458 | * @bond_dev: bonding net device that got called |
| 459 | * @vid: vlan id being added |
| 460 | */ |
| 461 | static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid) |
| 462 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 463 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | struct slave *slave; |
| 465 | int i, res; |
| 466 | |
| 467 | bond_for_each_slave(bond, slave, i) { |
| 468 | struct net_device *slave_dev = slave->dev; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 469 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 472 | slave_ops->ndo_vlan_rx_add_vid) { |
| 473 | slave_ops->ndo_vlan_rx_add_vid(slave_dev, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
| 477 | res = bond_add_vlan(bond, vid); |
| 478 | if (res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 479 | pr_err("%s: Error: Failed to add vlan id %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | bond_dev->name, vid); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves |
| 486 | * @bond_dev: bonding net device that got called |
| 487 | * @vid: vlan id being removed |
| 488 | */ |
| 489 | static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid) |
| 490 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 491 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | struct slave *slave; |
| 493 | struct net_device *vlan_dev; |
| 494 | int i, res; |
| 495 | |
| 496 | bond_for_each_slave(bond, slave, i) { |
| 497 | struct net_device *slave_dev = slave->dev; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 498 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 501 | slave_ops->ndo_vlan_rx_kill_vid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | /* Save and then restore vlan_dev in the grp array, |
| 503 | * since the slave's driver might clear it. |
| 504 | */ |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 505 | vlan_dev = vlan_group_get_device(bond->vlgrp, vid); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 506 | slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vid); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 507 | vlan_group_set_device(bond->vlgrp, vid, vlan_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | |
| 511 | res = bond_del_vlan(bond, vid); |
| 512 | if (res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 513 | pr_err("%s: Error: Failed to remove vlan id %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | bond_dev->name, vid); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | static void bond_add_vlans_on_slave(struct bonding *bond, struct net_device *slave_dev) |
| 519 | { |
| 520 | struct vlan_entry *vlan; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 521 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 523 | if (!bond->vlgrp) |
Jay Vosburgh | 03dc2f4 | 2010-07-21 12:14:48 +0000 | [diff] [blame] | 524 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 527 | slave_ops->ndo_vlan_rx_register) |
| 528 | slave_ops->ndo_vlan_rx_register(slave_dev, bond->vlgrp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) || |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 531 | !(slave_ops->ndo_vlan_rx_add_vid)) |
Jay Vosburgh | 03dc2f4 | 2010-07-21 12:14:48 +0000 | [diff] [blame] | 532 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 534 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) |
| 535 | slave_ops->ndo_vlan_rx_add_vid(slave_dev, vlan->vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 538 | static void bond_del_vlans_from_slave(struct bonding *bond, |
| 539 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 541 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | struct vlan_entry *vlan; |
| 543 | struct net_device *vlan_dev; |
| 544 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 545 | if (!bond->vlgrp) |
Jay Vosburgh | 03dc2f4 | 2010-07-21 12:14:48 +0000 | [diff] [blame] | 546 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
| 548 | if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) || |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 549 | !(slave_ops->ndo_vlan_rx_kill_vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | goto unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 553 | if (!vlan->vlan_id) |
| 554 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | /* Save and then restore vlan_dev in the grp array, |
| 556 | * since the slave's driver might clear it. |
| 557 | */ |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 558 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 559 | slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vlan->vlan_id); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 560 | vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | unreg: |
| 564 | if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 565 | slave_ops->ndo_vlan_rx_register) |
| 566 | slave_ops->ndo_vlan_rx_register(slave_dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /*------------------------------- Link status -------------------------------*/ |
| 570 | |
| 571 | /* |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 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. |
| 575 | * |
| 576 | * Returns zero if carrier state does not change, nonzero if it does. |
| 577 | */ |
| 578 | static int bond_set_carrier(struct bonding *bond) |
| 579 | { |
| 580 | struct slave *slave; |
| 581 | int i; |
| 582 | |
| 583 | if (bond->slave_cnt == 0) |
| 584 | goto down; |
| 585 | |
| 586 | if (bond->params.mode == BOND_MODE_8023AD) |
| 587 | return bond_3ad_set_carrier(bond); |
| 588 | |
| 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); |
| 593 | return 1; |
| 594 | } |
| 595 | return 0; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | down: |
| 600 | if (netif_carrier_ok(bond->dev)) { |
| 601 | netif_carrier_off(bond->dev); |
| 602 | return 1; |
| 603 | } |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
| 611 | * and return error. |
| 612 | */ |
| 613 | static int bond_update_speed_duplex(struct slave *slave) |
| 614 | { |
| 615 | struct net_device *slave_dev = slave->dev; |
David Decotigny | 5d30530 | 2011-04-13 15:22:31 +0000 | [diff] [blame] | 616 | struct ethtool_cmd etool = { .cmd = ETHTOOL_GSET }; |
| 617 | u32 slave_speed; |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 618 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | /* Fake speed and duplex */ |
| 621 | slave->speed = SPEED_100; |
| 622 | slave->duplex = DUPLEX_FULL; |
| 623 | |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 624 | if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 627 | res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool); |
| 628 | if (res < 0) |
| 629 | return -1; |
| 630 | |
David Decotigny | 5d30530 | 2011-04-13 15:22:31 +0000 | [diff] [blame] | 631 | slave_speed = ethtool_cmd_speed(&etool); |
| 632 | switch (slave_speed) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | case SPEED_10: |
| 634 | case SPEED_100: |
| 635 | case SPEED_1000: |
Jay Vosburgh | 94dbffd | 2006-09-22 21:52:15 -0700 | [diff] [blame] | 636 | case SPEED_10000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | break; |
| 638 | default: |
| 639 | return -1; |
| 640 | } |
| 641 | |
| 642 | switch (etool.duplex) { |
| 643 | case DUPLEX_FULL: |
| 644 | case DUPLEX_HALF: |
| 645 | break; |
| 646 | default: |
| 647 | return -1; |
| 648 | } |
| 649 | |
David Decotigny | 5d30530 | 2011-04-13 15:22:31 +0000 | [diff] [blame] | 650 | slave->speed = slave_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | slave->duplex = etool.duplex; |
| 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * if <dev> supports MII link status reporting, check its link status. |
| 658 | * |
| 659 | * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(), |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 660 | * depending upon the setting of the use_carrier parameter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | * |
| 662 | * Return either BMSR_LSTATUS, meaning that the link is up (or we |
| 663 | * can't tell and just pretend it is), or 0, meaning that the link is |
| 664 | * down. |
| 665 | * |
| 666 | * If reporting is non-zero, instead of faking link up, return -1 if |
| 667 | * both ETHTOOL and MII ioctls fail (meaning the device does not |
| 668 | * support them). If use_carrier is set, return whatever it says. |
| 669 | * It'd be nice if there was a good way to tell if a driver supports |
| 670 | * netif_carrier, but there really isn't. |
| 671 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 672 | static int bond_check_dev_link(struct bonding *bond, |
| 673 | struct net_device *slave_dev, int reporting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 675 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Jiri Bohac | d9d5283 | 2009-10-28 22:23:54 -0700 | [diff] [blame] | 676 | int (*ioctl)(struct net_device *, struct ifreq *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | struct ifreq ifr; |
| 678 | struct mii_ioctl_data *mii; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Petri Gynther | 6c98885 | 2009-08-28 12:05:15 +0000 | [diff] [blame] | 680 | if (!reporting && !netif_running(slave_dev)) |
| 681 | return 0; |
| 682 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 683 | if (bond->params.use_carrier) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Jiri Pirko | 29112f4 | 2009-04-24 01:58:23 +0000 | [diff] [blame] | 686 | /* Try to get link status using Ethtool first. */ |
| 687 | if (slave_dev->ethtool_ops) { |
| 688 | if (slave_dev->ethtool_ops->get_link) { |
| 689 | u32 link; |
| 690 | |
| 691 | link = slave_dev->ethtool_ops->get_link(slave_dev); |
| 692 | |
| 693 | return link ? BMSR_LSTATUS : 0; |
| 694 | } |
| 695 | } |
| 696 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 697 | /* Ethtool can't be used, fallback to MII ioctls. */ |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 698 | ioctl = slave_ops->ndo_do_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | if (ioctl) { |
| 700 | /* TODO: set pointer to correct ioctl on a per team member */ |
| 701 | /* bases to make this more efficient. that is, once */ |
| 702 | /* we determine the correct ioctl, we will always */ |
| 703 | /* call it and not the others for that team */ |
| 704 | /* member. */ |
| 705 | |
| 706 | /* |
| 707 | * We cannot assume that SIOCGMIIPHY will also read a |
| 708 | * register; not all network drivers (e.g., e100) |
| 709 | * support that. |
| 710 | */ |
| 711 | |
| 712 | /* Yes, the mii is overlaid on the ifreq.ifr_ifru */ |
| 713 | strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ); |
| 714 | mii = if_mii(&ifr); |
| 715 | if (IOCTL(slave_dev, &ifr, SIOCGMIIPHY) == 0) { |
| 716 | mii->reg_num = MII_BMSR; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 717 | if (IOCTL(slave_dev, &ifr, SIOCGMIIREG) == 0) |
| 718 | return mii->val_out & BMSR_LSTATUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 722 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | * If reporting, report that either there's no dev->do_ioctl, |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 724 | * or both SIOCGMIIREG and get_link failed (meaning that we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | * cannot report link status). If not reporting, pretend |
| 726 | * we're ok. |
| 727 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 728 | return reporting ? -1 : BMSR_LSTATUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /*----------------------------- Multicast list ------------------------------*/ |
| 732 | |
| 733 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | * Push the promiscuity flag down to appropriate slaves |
| 735 | */ |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 736 | static int bond_set_promiscuity(struct bonding *bond, int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 738 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | if (USES_PRIMARY(bond->params.mode)) { |
| 740 | /* write lock already acquired */ |
| 741 | if (bond->curr_active_slave) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 742 | err = dev_set_promiscuity(bond->curr_active_slave->dev, |
| 743 | inc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | } else { |
| 746 | struct slave *slave; |
| 747 | int i; |
| 748 | bond_for_each_slave(bond, slave, i) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 749 | err = dev_set_promiscuity(slave->dev, inc); |
| 750 | if (err) |
| 751 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | } |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 754 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /* |
| 758 | * Push the allmulti flag down to all slaves |
| 759 | */ |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 760 | static int bond_set_allmulti(struct bonding *bond, int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 762 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | if (USES_PRIMARY(bond->params.mode)) { |
| 764 | /* write lock already acquired */ |
| 765 | if (bond->curr_active_slave) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 766 | err = dev_set_allmulti(bond->curr_active_slave->dev, |
| 767 | inc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | } |
| 769 | } else { |
| 770 | struct slave *slave; |
| 771 | int i; |
| 772 | bond_for_each_slave(bond, slave, i) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 773 | err = dev_set_allmulti(slave->dev, inc); |
| 774 | if (err) |
| 775 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 778 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* |
| 782 | * Add a Multicast address to slaves |
| 783 | * according to mode |
| 784 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 785 | static void bond_mc_add(struct bonding *bond, void *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | { |
| 787 | if (USES_PRIMARY(bond->params.mode)) { |
| 788 | /* write lock already acquired */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 789 | if (bond->curr_active_slave) |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 790 | dev_mc_add(bond->curr_active_slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } else { |
| 792 | struct slave *slave; |
| 793 | int i; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 794 | |
| 795 | bond_for_each_slave(bond, slave, i) |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 796 | dev_mc_add(slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * Remove a multicast address from slave |
| 802 | * according to mode |
| 803 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 804 | static void bond_mc_del(struct bonding *bond, void *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | { |
| 806 | if (USES_PRIMARY(bond->params.mode)) { |
| 807 | /* write lock already acquired */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 808 | if (bond->curr_active_slave) |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 809 | dev_mc_del(bond->curr_active_slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | } else { |
| 811 | struct slave *slave; |
| 812 | int i; |
| 813 | bond_for_each_slave(bond, slave, i) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 814 | dev_mc_del(slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 819 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 820 | static void __bond_resend_igmp_join_requests(struct net_device *dev) |
| 821 | { |
| 822 | struct in_device *in_dev; |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 823 | |
| 824 | rcu_read_lock(); |
| 825 | in_dev = __in_dev_get_rcu(dev); |
Eric Dumazet | 866f3b2 | 2010-11-18 09:33:19 -0800 | [diff] [blame] | 826 | if (in_dev) |
David S. Miller | 2491242 | 2010-11-19 13:13:47 -0800 | [diff] [blame] | 827 | ip_mc_rejoin_groups(in_dev); |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 828 | rcu_read_unlock(); |
| 829 | } |
| 830 | |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 831 | /* |
| 832 | * Retrieve the list of registered multicast addresses for the bonding |
| 833 | * device and retransmit an IGMP JOIN request to the current active |
| 834 | * slave. |
| 835 | */ |
| 836 | static void bond_resend_igmp_join_requests(struct bonding *bond) |
| 837 | { |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 838 | struct net_device *vlan_dev; |
| 839 | struct vlan_entry *vlan; |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 840 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 841 | read_lock(&bond->lock); |
| 842 | |
| 843 | /* rejoin all groups on bond device */ |
| 844 | __bond_resend_igmp_join_requests(bond->dev); |
| 845 | |
| 846 | /* rejoin all groups on vlan devices */ |
| 847 | if (bond->vlgrp) { |
| 848 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
| 849 | vlan_dev = vlan_group_get_device(bond->vlgrp, |
| 850 | vlan->vlan_id); |
| 851 | if (vlan_dev) |
| 852 | __bond_resend_igmp_join_requests(vlan_dev); |
| 853 | } |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 854 | } |
| 855 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 856 | if (--bond->igmp_retrans > 0) |
| 857 | queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5); |
| 858 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 859 | read_unlock(&bond->lock); |
| 860 | } |
| 861 | |
stephen hemminger | 379b738 | 2010-10-15 11:02:56 +0000 | [diff] [blame] | 862 | static void bond_resend_igmp_join_requests_delayed(struct work_struct *work) |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 863 | { |
| 864 | struct bonding *bond = container_of(work, struct bonding, |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 865 | mcast_work.work); |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 866 | bond_resend_igmp_join_requests(bond); |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | * flush all members of flush->mc_list from device dev->mc_list |
| 871 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 872 | static void bond_mc_list_flush(struct net_device *bond_dev, |
| 873 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 875 | struct bonding *bond = netdev_priv(bond_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 876 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 878 | netdev_for_each_mc_addr(ha, bond_dev) |
| 879 | dev_mc_del(slave_dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 882 | /* del lacpdu mc addr from mc list */ |
| 883 | u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
| 884 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 885 | dev_mc_del(slave_dev, lacpdu_multicast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
| 889 | /*--------------------------- Active slave change ---------------------------*/ |
| 890 | |
| 891 | /* |
| 892 | * Update the mc list and multicast-related flags for the new and |
| 893 | * old active slaves (if any) according to the multicast mode, and |
| 894 | * promiscuous flags unconditionally. |
| 895 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 896 | static void bond_mc_swap(struct bonding *bond, struct slave *new_active, |
| 897 | struct slave *old_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 899 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 901 | if (!USES_PRIMARY(bond->params.mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | /* nothing to do - mc list is already up-to-date on |
| 903 | * all slaves |
| 904 | */ |
| 905 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | if (old_active) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 908 | if (bond->dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | dev_set_promiscuity(old_active->dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 911 | if (bond->dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | dev_set_allmulti(old_active->dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 914 | netdev_for_each_mc_addr(ha, bond->dev) |
| 915 | dev_mc_del(old_active->dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | if (new_active) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 919 | /* FIXME: Signal errors upstream. */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 920 | if (bond->dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | dev_set_promiscuity(new_active->dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 923 | if (bond->dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | dev_set_allmulti(new_active->dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 926 | netdev_for_each_mc_addr(ha, bond->dev) |
| 927 | dev_mc_add(new_active->dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 931 | /* |
| 932 | * bond_do_fail_over_mac |
| 933 | * |
| 934 | * Perform special MAC address swapping for fail_over_mac settings |
| 935 | * |
| 936 | * Called with RTNL, bond->lock for read, curr_slave_lock for write_bh. |
| 937 | */ |
| 938 | static void bond_do_fail_over_mac(struct bonding *bond, |
| 939 | struct slave *new_active, |
| 940 | struct slave *old_active) |
Hannes Eder | 1f78d9f | 2009-02-14 11:15:33 +0000 | [diff] [blame] | 941 | __releases(&bond->curr_slave_lock) |
| 942 | __releases(&bond->lock) |
| 943 | __acquires(&bond->lock) |
| 944 | __acquires(&bond->curr_slave_lock) |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 945 | { |
| 946 | u8 tmp_mac[ETH_ALEN]; |
| 947 | struct sockaddr saddr; |
| 948 | int rv; |
| 949 | |
| 950 | switch (bond->params.fail_over_mac) { |
| 951 | case BOND_FOM_ACTIVE: |
| 952 | if (new_active) |
| 953 | memcpy(bond->dev->dev_addr, new_active->dev->dev_addr, |
| 954 | new_active->dev->addr_len); |
| 955 | break; |
| 956 | case BOND_FOM_FOLLOW: |
| 957 | /* |
| 958 | * if new_active && old_active, swap them |
| 959 | * if just old_active, do nothing (going to no active slave) |
| 960 | * if just new_active, set new_active to bond's MAC |
| 961 | */ |
| 962 | if (!new_active) |
| 963 | return; |
| 964 | |
| 965 | write_unlock_bh(&bond->curr_slave_lock); |
| 966 | read_unlock(&bond->lock); |
| 967 | |
| 968 | if (old_active) { |
| 969 | memcpy(tmp_mac, new_active->dev->dev_addr, ETH_ALEN); |
| 970 | memcpy(saddr.sa_data, old_active->dev->dev_addr, |
| 971 | ETH_ALEN); |
| 972 | saddr.sa_family = new_active->dev->type; |
| 973 | } else { |
| 974 | memcpy(saddr.sa_data, bond->dev->dev_addr, ETH_ALEN); |
| 975 | saddr.sa_family = bond->dev->type; |
| 976 | } |
| 977 | |
| 978 | rv = dev_set_mac_address(new_active->dev, &saddr); |
| 979 | if (rv) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 980 | pr_err("%s: Error %d setting MAC of slave %s\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 981 | bond->dev->name, -rv, new_active->dev->name); |
| 982 | goto out; |
| 983 | } |
| 984 | |
| 985 | if (!old_active) |
| 986 | goto out; |
| 987 | |
| 988 | memcpy(saddr.sa_data, tmp_mac, ETH_ALEN); |
| 989 | saddr.sa_family = old_active->dev->type; |
| 990 | |
| 991 | rv = dev_set_mac_address(old_active->dev, &saddr); |
| 992 | if (rv) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 993 | pr_err("%s: Error %d setting MAC of slave %s\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 994 | bond->dev->name, -rv, new_active->dev->name); |
| 995 | out: |
| 996 | read_lock(&bond->lock); |
| 997 | write_lock_bh(&bond->curr_slave_lock); |
| 998 | break; |
| 999 | default: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1000 | pr_err("%s: bond_do_fail_over_mac impossible: bad policy %d\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1001 | bond->dev->name, bond->params.fail_over_mac); |
| 1002 | break; |
| 1003 | } |
| 1004 | |
| 1005 | } |
| 1006 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1007 | static bool bond_should_change_active(struct bonding *bond) |
| 1008 | { |
| 1009 | struct slave *prim = bond->primary_slave; |
| 1010 | struct slave *curr = bond->curr_active_slave; |
| 1011 | |
| 1012 | if (!prim || !curr || curr->link != BOND_LINK_UP) |
| 1013 | return true; |
| 1014 | if (bond->force_primary) { |
| 1015 | bond->force_primary = false; |
| 1016 | return true; |
| 1017 | } |
| 1018 | if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER && |
| 1019 | (prim->speed < curr->speed || |
| 1020 | (prim->speed == curr->speed && prim->duplex <= curr->duplex))) |
| 1021 | return false; |
| 1022 | if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE) |
| 1023 | return false; |
| 1024 | return true; |
| 1025 | } |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | /** |
| 1028 | * find_best_interface - select the best available slave to be the active one |
| 1029 | * @bond: our bonding struct |
| 1030 | * |
| 1031 | * Warning: Caller must hold curr_slave_lock for writing. |
| 1032 | */ |
| 1033 | static struct slave *bond_find_best_slave(struct bonding *bond) |
| 1034 | { |
| 1035 | struct slave *new_active, *old_active; |
| 1036 | struct slave *bestslave = NULL; |
| 1037 | int mintime = bond->params.updelay; |
| 1038 | int i; |
| 1039 | |
Nicolas de Pesloüan | 49b4ad9 | 2009-10-07 14:11:00 -0700 | [diff] [blame] | 1040 | new_active = bond->curr_active_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
| 1042 | if (!new_active) { /* there were no active slaves left */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1043 | if (bond->slave_cnt > 0) /* found one slave */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | new_active = bond->first_slave; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1045 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | return NULL; /* still no slave, return NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | if ((bond->primary_slave) && |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1050 | bond->primary_slave->link == BOND_LINK_UP && |
| 1051 | bond_should_change_active(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | new_active = bond->primary_slave; |
| 1053 | } |
| 1054 | |
| 1055 | /* remember where to stop iterating over the slaves */ |
| 1056 | old_active = new_active; |
| 1057 | |
| 1058 | bond_for_each_slave_from(bond, new_active, i, old_active) { |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 1059 | if (new_active->link == BOND_LINK_UP) { |
| 1060 | return new_active; |
| 1061 | } else if (new_active->link == BOND_LINK_BACK && |
| 1062 | IS_UP(new_active->dev)) { |
| 1063 | /* link up, but waiting for stabilization */ |
| 1064 | if (new_active->delay < mintime) { |
| 1065 | mintime = new_active->delay; |
| 1066 | bestslave = new_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | return bestslave; |
| 1072 | } |
| 1073 | |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1074 | static bool bond_should_notify_peers(struct bonding *bond) |
| 1075 | { |
| 1076 | struct slave *slave = bond->curr_active_slave; |
| 1077 | |
| 1078 | pr_debug("bond_should_notify_peers: bond %s slave %s\n", |
| 1079 | bond->dev->name, slave ? slave->dev->name : "NULL"); |
| 1080 | |
| 1081 | if (!slave || !bond->send_peer_notif || |
| 1082 | test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state)) |
| 1083 | return false; |
| 1084 | |
| 1085 | bond->send_peer_notif--; |
| 1086 | return true; |
| 1087 | } |
| 1088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | /** |
| 1090 | * change_active_interface - change the active slave into the specified one |
| 1091 | * @bond: our bonding struct |
| 1092 | * @new: the new slave to make the active one |
| 1093 | * |
| 1094 | * Set the new slave to the bond's settings and unset them on the old |
| 1095 | * curr_active_slave. |
| 1096 | * Setting include flags, mc-list, promiscuity, allmulti, etc. |
| 1097 | * |
| 1098 | * If @new's link state is %BOND_LINK_BACK we'll set it to %BOND_LINK_UP, |
| 1099 | * because it is apparently the best available slave we have, even though its |
| 1100 | * updelay hasn't timed out yet. |
| 1101 | * |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1102 | * If new_active is not NULL, caller must hold bond->lock for read and |
| 1103 | * curr_slave_lock for write_bh. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1105 | void bond_change_active_slave(struct bonding *bond, struct slave *new_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | { |
| 1107 | struct slave *old_active = bond->curr_active_slave; |
| 1108 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1109 | if (old_active == new_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | |
| 1112 | if (new_active) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 1113 | new_active->jiffies = jiffies; |
| 1114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | if (new_active->link == BOND_LINK_BACK) { |
| 1116 | if (USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1117 | pr_info("%s: making interface %s the new active one %d ms earlier.\n", |
| 1118 | bond->dev->name, new_active->dev->name, |
| 1119 | (bond->params.updelay - new_active->delay) * bond->params.miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | new_active->delay = 0; |
| 1123 | new_active->link = BOND_LINK_UP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1125 | if (bond->params.mode == BOND_MODE_8023AD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | bond_3ad_handle_link_change(new_active, BOND_LINK_UP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1128 | if (bond_is_lb(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | } else { |
| 1131 | if (USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1132 | pr_info("%s: making interface %s the new active one.\n", |
| 1133 | bond->dev->name, new_active->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1138 | if (USES_PRIMARY(bond->params.mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | bond_mc_swap(bond, new_active, old_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1141 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | bond_alb_handle_active_change(bond, new_active); |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 1143 | if (old_active) |
| 1144 | bond_set_slave_inactive_flags(old_active); |
| 1145 | if (new_active) |
| 1146 | bond_set_slave_active_flags(new_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | } else { |
| 1148 | bond->curr_active_slave = new_active; |
| 1149 | } |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1150 | |
| 1151 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1152 | if (old_active) |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1153 | bond_set_slave_inactive_flags(old_active); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1154 | |
| 1155 | if (new_active) { |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1156 | bool should_notify_peers = false; |
| 1157 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1158 | bond_set_slave_active_flags(new_active); |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1159 | |
Or Gerlitz | 709f8a4 | 2008-06-13 18:12:01 -0700 | [diff] [blame] | 1160 | if (bond->params.fail_over_mac) |
| 1161 | bond_do_fail_over_mac(bond, new_active, |
| 1162 | old_active); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1163 | |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1164 | if (netif_running(bond->dev)) { |
| 1165 | bond->send_peer_notif = |
| 1166 | bond->params.num_peer_notif; |
| 1167 | should_notify_peers = |
| 1168 | bond_should_notify_peers(bond); |
| 1169 | } |
| 1170 | |
Or Gerlitz | 01f3109 | 2008-06-13 18:12:02 -0700 | [diff] [blame] | 1171 | write_unlock_bh(&bond->curr_slave_lock); |
| 1172 | read_unlock(&bond->lock); |
| 1173 | |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1174 | netdev_bonding_change(bond->dev, NETDEV_BONDING_FAILOVER); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 1175 | if (should_notify_peers) |
| 1176 | netdev_bonding_change(bond->dev, |
| 1177 | NETDEV_NOTIFY_PEERS); |
Or Gerlitz | 01f3109 | 2008-06-13 18:12:02 -0700 | [diff] [blame] | 1178 | |
| 1179 | read_lock(&bond->lock); |
| 1180 | write_lock_bh(&bond->curr_slave_lock); |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 1181 | } |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1182 | } |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 1183 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 1184 | /* resend IGMP joins since active slave has changed or |
Flavio Leitner | 94265cf | 2011-05-25 08:38:58 +0000 | [diff] [blame] | 1185 | * all were sent on curr_active_slave. |
| 1186 | * resend only if bond is brought up with the affected |
| 1187 | * bonding modes and the retransmission is enabled */ |
| 1188 | if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) && |
| 1189 | ((USES_PRIMARY(bond->params.mode) && new_active) || |
| 1190 | bond->params.mode == BOND_MODE_ROUNDROBIN)) { |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1191 | bond->igmp_retrans = bond->params.resend_igmp; |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 1192 | queue_delayed_work(bond->wq, &bond->mcast_work, 0); |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 1193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * bond_select_active_slave - select a new active slave, if needed |
| 1198 | * @bond: our bonding struct |
| 1199 | * |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1200 | * This functions should be called when one of the following occurs: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | * - The old curr_active_slave has been released or lost its link. |
| 1202 | * - The primary_slave has got its link back. |
| 1203 | * - A slave has got its link back and there's no old curr_active_slave. |
| 1204 | * |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1205 | * Caller must hold bond->lock for read and curr_slave_lock for write_bh. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1207 | void bond_select_active_slave(struct bonding *bond) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | { |
| 1209 | struct slave *best_slave; |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1210 | int rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
| 1212 | best_slave = bond_find_best_slave(bond); |
| 1213 | if (best_slave != bond->curr_active_slave) { |
| 1214 | bond_change_active_slave(bond, best_slave); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1215 | rv = bond_set_carrier(bond); |
| 1216 | if (!rv) |
| 1217 | return; |
| 1218 | |
| 1219 | if (netif_carrier_ok(bond->dev)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1220 | pr_info("%s: first active interface up!\n", |
| 1221 | bond->dev->name); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1222 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1223 | pr_info("%s: now running without any active interface !\n", |
| 1224 | bond->dev->name); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | /*--------------------------- slave list handling ---------------------------*/ |
| 1230 | |
| 1231 | /* |
| 1232 | * This function attaches the slave to the end of list. |
| 1233 | * |
| 1234 | * bond->lock held for writing by caller. |
| 1235 | */ |
| 1236 | static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) |
| 1237 | { |
| 1238 | if (bond->first_slave == NULL) { /* attaching the first slave */ |
| 1239 | new_slave->next = new_slave; |
| 1240 | new_slave->prev = new_slave; |
| 1241 | bond->first_slave = new_slave; |
| 1242 | } else { |
| 1243 | new_slave->next = bond->first_slave; |
| 1244 | new_slave->prev = bond->first_slave->prev; |
| 1245 | new_slave->next->prev = new_slave; |
| 1246 | new_slave->prev->next = new_slave; |
| 1247 | } |
| 1248 | |
| 1249 | bond->slave_cnt++; |
| 1250 | } |
| 1251 | |
| 1252 | /* |
| 1253 | * This function detaches the slave from the list. |
| 1254 | * WARNING: no check is made to verify if the slave effectively |
| 1255 | * belongs to <bond>. |
| 1256 | * Nothing is freed on return, structures are just unchained. |
| 1257 | * If any slave pointer in bond was pointing to <slave>, |
| 1258 | * it should be changed by the calling function. |
| 1259 | * |
| 1260 | * bond->lock held for writing by caller. |
| 1261 | */ |
| 1262 | static void bond_detach_slave(struct bonding *bond, struct slave *slave) |
| 1263 | { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1264 | if (slave->next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | slave->next->prev = slave->prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1267 | if (slave->prev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | slave->prev->next = slave->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
| 1270 | if (bond->first_slave == slave) { /* slave is the first slave */ |
| 1271 | if (bond->slave_cnt > 1) { /* there are more slave */ |
| 1272 | bond->first_slave = slave->next; |
| 1273 | } else { |
| 1274 | bond->first_slave = NULL; /* slave was the last one */ |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | slave->next = NULL; |
| 1279 | slave->prev = NULL; |
| 1280 | bond->slave_cnt--; |
| 1281 | } |
| 1282 | |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1283 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1284 | static inline int slave_enable_netpoll(struct slave *slave) |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1285 | { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1286 | struct netpoll *np; |
| 1287 | int err = 0; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1288 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1289 | np = kzalloc(sizeof(*np), GFP_KERNEL); |
| 1290 | err = -ENOMEM; |
| 1291 | if (!np) |
| 1292 | goto out; |
| 1293 | |
| 1294 | np->dev = slave->dev; |
| 1295 | err = __netpoll_setup(np); |
| 1296 | if (err) { |
| 1297 | kfree(np); |
| 1298 | goto out; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1299 | } |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1300 | slave->np = np; |
| 1301 | out: |
| 1302 | return err; |
| 1303 | } |
| 1304 | static inline void slave_disable_netpoll(struct slave *slave) |
| 1305 | { |
| 1306 | struct netpoll *np = slave->np; |
| 1307 | |
| 1308 | if (!np) |
| 1309 | return; |
| 1310 | |
| 1311 | slave->np = NULL; |
| 1312 | synchronize_rcu_bh(); |
| 1313 | __netpoll_cleanup(np); |
| 1314 | kfree(np); |
| 1315 | } |
| 1316 | static inline bool slave_dev_support_netpoll(struct net_device *slave_dev) |
| 1317 | { |
| 1318 | if (slave_dev->priv_flags & IFF_DISABLE_NETPOLL) |
| 1319 | return false; |
| 1320 | if (!slave_dev->netdev_ops->ndo_poll_controller) |
| 1321 | return false; |
| 1322 | return true; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static void bond_poll_controller(struct net_device *bond_dev) |
| 1326 | { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | static void __bond_netpoll_cleanup(struct bonding *bond) |
| 1330 | { |
Neil Horman | c2355e1 | 2010-10-13 16:01:49 +0000 | [diff] [blame] | 1331 | struct slave *slave; |
| 1332 | int i; |
| 1333 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1334 | bond_for_each_slave(bond, slave, i) |
| 1335 | if (IS_UP(slave->dev)) |
| 1336 | slave_disable_netpoll(slave); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1337 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1338 | static void bond_netpoll_cleanup(struct net_device *bond_dev) |
| 1339 | { |
| 1340 | struct bonding *bond = netdev_priv(bond_dev); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1341 | |
| 1342 | read_lock(&bond->lock); |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1343 | __bond_netpoll_cleanup(bond); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1344 | read_unlock(&bond->lock); |
| 1345 | } |
| 1346 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1347 | static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni) |
| 1348 | { |
| 1349 | struct bonding *bond = netdev_priv(dev); |
| 1350 | struct slave *slave; |
| 1351 | int i, err = 0; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1352 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1353 | read_lock(&bond->lock); |
| 1354 | bond_for_each_slave(bond, slave, i) { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1355 | err = slave_enable_netpoll(slave); |
| 1356 | if (err) { |
| 1357 | __bond_netpoll_cleanup(bond); |
| 1358 | break; |
| 1359 | } |
| 1360 | } |
| 1361 | read_unlock(&bond->lock); |
| 1362 | return err; |
| 1363 | } |
| 1364 | |
| 1365 | static struct netpoll_info *bond_netpoll_info(struct bonding *bond) |
| 1366 | { |
| 1367 | return bond->dev->npinfo; |
| 1368 | } |
| 1369 | |
| 1370 | #else |
| 1371 | static inline int slave_enable_netpoll(struct slave *slave) |
| 1372 | { |
| 1373 | return 0; |
| 1374 | } |
| 1375 | static inline void slave_disable_netpoll(struct slave *slave) |
| 1376 | { |
| 1377 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1378 | static void bond_netpoll_cleanup(struct net_device *bond_dev) |
| 1379 | { |
| 1380 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1381 | #endif |
| 1382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | /*---------------------------------- IOCTL ----------------------------------*/ |
| 1384 | |
Adrian Bunk | 4ad072c | 2007-07-09 11:51:12 -0700 | [diff] [blame] | 1385 | static int bond_sethwaddr(struct net_device *bond_dev, |
| 1386 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1388 | pr_debug("bond_dev=%p\n", bond_dev); |
| 1389 | pr_debug("slave_dev=%p\n", slave_dev); |
| 1390 | pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len); |
| 1392 | return 0; |
| 1393 | } |
| 1394 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1395 | static u32 bond_fix_features(struct net_device *dev, u32 features) |
| 1396 | { |
| 1397 | struct slave *slave; |
| 1398 | struct bonding *bond = netdev_priv(dev); |
| 1399 | u32 mask; |
| 1400 | int i; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1401 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1402 | read_lock(&bond->lock); |
| 1403 | |
| 1404 | if (!bond->first_slave) { |
| 1405 | /* Disable adding VLANs to empty bond. But why? --mq */ |
| 1406 | features |= NETIF_F_VLAN_CHALLENGED; |
| 1407 | goto out; |
| 1408 | } |
| 1409 | |
| 1410 | mask = features; |
| 1411 | features &= ~NETIF_F_ONE_FOR_ALL; |
| 1412 | features |= NETIF_F_ALL_FOR_ALL; |
| 1413 | |
| 1414 | bond_for_each_slave(bond, slave, i) { |
| 1415 | features = netdev_increment_features(features, |
| 1416 | slave->dev->features, |
| 1417 | mask); |
| 1418 | } |
| 1419 | |
| 1420 | out: |
| 1421 | read_unlock(&bond->lock); |
| 1422 | return features; |
| 1423 | } |
| 1424 | |
| 1425 | #define BOND_VLAN_FEATURES (NETIF_F_ALL_TX_OFFLOADS | \ |
| 1426 | NETIF_F_SOFT_FEATURES | \ |
| 1427 | NETIF_F_LRO) |
| 1428 | |
| 1429 | static void bond_compute_features(struct bonding *bond) |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1430 | { |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1431 | struct slave *slave; |
| 1432 | struct net_device *bond_dev = bond->dev; |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1433 | u32 vlan_features = BOND_VLAN_FEATURES; |
| 1434 | unsigned short max_hard_header_len = ETH_HLEN; |
Jay Vosburgh | 8e3babc | 2005-11-04 18:45:45 -0800 | [diff] [blame] | 1435 | int i; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1436 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1437 | read_lock(&bond->lock); |
Herbert Xu | b63365a | 2008-10-23 01:11:29 -0700 | [diff] [blame] | 1438 | |
| 1439 | if (!bond->first_slave) |
| 1440 | goto done; |
| 1441 | |
Jay Vosburgh | 54ef313 | 2006-09-22 21:53:39 -0700 | [diff] [blame] | 1442 | bond_for_each_slave(bond, slave, i) { |
Jay Vosburgh | 278339a | 2009-08-28 12:05:12 +0000 | [diff] [blame] | 1443 | vlan_features = netdev_increment_features(vlan_features, |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1444 | slave->dev->vlan_features, BOND_VLAN_FEATURES); |
| 1445 | |
Jay Vosburgh | 54ef313 | 2006-09-22 21:53:39 -0700 | [diff] [blame] | 1446 | if (slave->dev->hard_header_len > max_hard_header_len) |
| 1447 | max_hard_header_len = slave->dev->hard_header_len; |
| 1448 | } |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1449 | |
Herbert Xu | b63365a | 2008-10-23 01:11:29 -0700 | [diff] [blame] | 1450 | done: |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1451 | bond_dev->vlan_features = vlan_features; |
Jay Vosburgh | 54ef313 | 2006-09-22 21:53:39 -0700 | [diff] [blame] | 1452 | bond_dev->hard_header_len = max_hard_header_len; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1453 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1454 | read_unlock(&bond->lock); |
| 1455 | |
| 1456 | netdev_change_features(bond_dev); |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1457 | } |
| 1458 | |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1459 | static void bond_setup_by_slave(struct net_device *bond_dev, |
| 1460 | struct net_device *slave_dev) |
| 1461 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1462 | struct bonding *bond = netdev_priv(bond_dev); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 1463 | |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 1464 | bond_dev->header_ops = slave_dev->header_ops; |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1465 | |
| 1466 | bond_dev->type = slave_dev->type; |
| 1467 | bond_dev->hard_header_len = slave_dev->hard_header_len; |
| 1468 | bond_dev->addr_len = slave_dev->addr_len; |
| 1469 | |
| 1470 | memcpy(bond_dev->broadcast, slave_dev->broadcast, |
| 1471 | slave_dev->addr_len); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 1472 | bond->setup_by_slave = 1; |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1473 | } |
| 1474 | |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1475 | /* On bonding slaves other than the currently active slave, suppress |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 1476 | * duplicates except for alb non-mcast/bcast. |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1477 | */ |
| 1478 | static bool bond_should_deliver_exact_match(struct sk_buff *skb, |
Jiri Pirko | 0bd80da | 2011-03-16 08:45:23 +0000 | [diff] [blame] | 1479 | struct slave *slave, |
| 1480 | struct bonding *bond) |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1481 | { |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 1482 | if (bond_is_slave_inactive(slave)) { |
Jiri Pirko | 0bd80da | 2011-03-16 08:45:23 +0000 | [diff] [blame] | 1483 | if (bond->params.mode == BOND_MODE_ALB && |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1484 | skb->pkt_type != PACKET_BROADCAST && |
| 1485 | skb->pkt_type != PACKET_MULTICAST) |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1486 | return false; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1487 | return true; |
| 1488 | } |
| 1489 | return false; |
| 1490 | } |
| 1491 | |
Jiri Pirko | 8a4eb57 | 2011-03-12 03:14:39 +0000 | [diff] [blame] | 1492 | static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb) |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1493 | { |
Jiri Pirko | 8a4eb57 | 2011-03-12 03:14:39 +0000 | [diff] [blame] | 1494 | struct sk_buff *skb = *pskb; |
Jiri Pirko | f1c1775 | 2011-03-12 03:14:35 +0000 | [diff] [blame] | 1495 | struct slave *slave; |
Jiri Pirko | 0bd80da | 2011-03-16 08:45:23 +0000 | [diff] [blame] | 1496 | struct bonding *bond; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1497 | |
Jiri Pirko | 8a4eb57 | 2011-03-12 03:14:39 +0000 | [diff] [blame] | 1498 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 1499 | if (unlikely(!skb)) |
| 1500 | return RX_HANDLER_CONSUMED; |
| 1501 | |
| 1502 | *pskb = skb; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1503 | |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1504 | slave = bond_slave_get_rcu(skb->dev); |
| 1505 | bond = slave->bond; |
Jiri Pirko | 0bd80da | 2011-03-16 08:45:23 +0000 | [diff] [blame] | 1506 | |
| 1507 | if (bond->params.arp_interval) |
Jiri Pirko | f1c1775 | 2011-03-12 03:14:35 +0000 | [diff] [blame] | 1508 | slave->dev->last_rx = jiffies; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1509 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 1510 | if (bond->recv_probe) { |
| 1511 | struct sk_buff *nskb = skb_clone(skb, GFP_ATOMIC); |
| 1512 | |
| 1513 | if (likely(nskb)) { |
| 1514 | bond->recv_probe(nskb, bond, slave); |
| 1515 | dev_kfree_skb(nskb); |
| 1516 | } |
| 1517 | } |
| 1518 | |
Jiri Pirko | 0bd80da | 2011-03-16 08:45:23 +0000 | [diff] [blame] | 1519 | if (bond_should_deliver_exact_match(skb, slave, bond)) { |
Jiri Pirko | 8a4eb57 | 2011-03-12 03:14:39 +0000 | [diff] [blame] | 1520 | return RX_HANDLER_EXACT; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1523 | skb->dev = bond->dev; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1524 | |
Jiri Pirko | 0bd80da | 2011-03-16 08:45:23 +0000 | [diff] [blame] | 1525 | if (bond->params.mode == BOND_MODE_ALB && |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1526 | bond->dev->priv_flags & IFF_BRIDGE_PORT && |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1527 | skb->pkt_type == PACKET_HOST) { |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1528 | |
Changli Gao | 541ac7c | 2011-03-02 21:07:14 +0000 | [diff] [blame] | 1529 | if (unlikely(skb_cow_head(skb, |
| 1530 | skb->data - skb_mac_header(skb)))) { |
| 1531 | kfree_skb(skb); |
Jiri Pirko | 8a4eb57 | 2011-03-12 03:14:39 +0000 | [diff] [blame] | 1532 | return RX_HANDLER_CONSUMED; |
Changli Gao | 541ac7c | 2011-03-02 21:07:14 +0000 | [diff] [blame] | 1533 | } |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1534 | memcpy(eth_hdr(skb)->h_dest, bond->dev->dev_addr, ETH_ALEN); |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
Jiri Pirko | 8a4eb57 | 2011-03-12 03:14:39 +0000 | [diff] [blame] | 1537 | return RX_HANDLER_ANOTHER; |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | /* enslave device <slave> to bond device <master> */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1541 | int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1543 | struct bonding *bond = netdev_priv(bond_dev); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1544 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | struct slave *new_slave = NULL; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1546 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | struct sockaddr addr; |
| 1548 | int link_reporting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | int res = 0; |
| 1550 | |
nsxfreddy@gmail.com | 552709d | 2005-09-21 14:18:04 -0500 | [diff] [blame] | 1551 | if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1552 | slave_ops->ndo_do_ioctl == NULL) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1553 | pr_warning("%s: Warning: no link monitoring support for %s\n", |
| 1554 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | /* already enslaved */ |
| 1558 | if (slave_dev->flags & IFF_SLAVE) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1559 | pr_debug("Error, Device was already enslaved\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | return -EBUSY; |
| 1561 | } |
| 1562 | |
| 1563 | /* vlan challenged mutual exclusion */ |
| 1564 | /* no need to lock since we're protected by rtnl_lock */ |
| 1565 | if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1566 | pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 1567 | if (bond->vlgrp) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1568 | pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n", |
| 1569 | bond_dev->name, slave_dev->name, bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | return -EPERM; |
| 1571 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1572 | pr_warning("%s: Warning: enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n", |
| 1573 | bond_dev->name, slave_dev->name, |
| 1574 | slave_dev->name, bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | } else { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1577 | pr_debug("%s: ! NETIF_F_VLAN_CHALLENGED\n", slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1580 | /* |
| 1581 | * Old ifenslave binaries are no longer supported. These can |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1582 | * be identified with moderate accuracy by the state of the slave: |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1583 | * the current ifenslave will set the interface down prior to |
| 1584 | * enslaving it; the old ifenslave will not. |
| 1585 | */ |
| 1586 | if ((slave_dev->flags & IFF_UP)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1587 | pr_err("%s is up. This may be due to an out of date ifenslave.\n", |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1588 | slave_dev->name); |
| 1589 | res = -EPERM; |
| 1590 | goto err_undo_flags; |
| 1591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1593 | /* set bonding device ether type by slave - bonding netdevices are |
| 1594 | * created with ether_setup, so when the slave type is not ARPHRD_ETHER |
| 1595 | * there is a need to override some of the type dependent attribs/funcs. |
| 1596 | * |
| 1597 | * bond ether type mutual exclusion - don't allow slaves of dissimilar |
| 1598 | * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond |
| 1599 | */ |
| 1600 | if (bond->slave_cnt == 0) { |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1601 | if (bond_dev->type != slave_dev->type) { |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1602 | pr_debug("%s: change device type from %d to %d\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1603 | bond_dev->name, |
| 1604 | bond_dev->type, slave_dev->type); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1605 | |
Jiri Pirko | 3ca5b40 | 2010-03-10 10:29:35 +0000 | [diff] [blame] | 1606 | res = netdev_bonding_change(bond_dev, |
| 1607 | NETDEV_PRE_TYPE_CHANGE); |
| 1608 | res = notifier_to_errno(res); |
| 1609 | if (res) { |
| 1610 | pr_err("%s: refused to change device type\n", |
| 1611 | bond_dev->name); |
| 1612 | res = -EBUSY; |
| 1613 | goto err_undo_flags; |
| 1614 | } |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1615 | |
Jiri Pirko | 32a806c | 2010-03-19 04:00:23 +0000 | [diff] [blame] | 1616 | /* Flush unicast and multicast addresses */ |
Jiri Pirko | a748ee2 | 2010-04-01 21:22:09 +0000 | [diff] [blame] | 1617 | dev_uc_flush(bond_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1618 | dev_mc_flush(bond_dev); |
Jiri Pirko | 32a806c | 2010-03-19 04:00:23 +0000 | [diff] [blame] | 1619 | |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1620 | if (slave_dev->type != ARPHRD_ETHER) |
| 1621 | bond_setup_by_slave(bond_dev, slave_dev); |
| 1622 | else |
| 1623 | ether_setup(bond_dev); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1624 | |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 1625 | netdev_bonding_change(bond_dev, |
| 1626 | NETDEV_POST_TYPE_CHANGE); |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1627 | } |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1628 | } else if (bond_dev->type != slave_dev->type) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1629 | pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n", |
| 1630 | slave_dev->name, |
| 1631 | slave_dev->type, bond_dev->type); |
| 1632 | res = -EINVAL; |
| 1633 | goto err_undo_flags; |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1636 | if (slave_ops->ndo_set_mac_address == NULL) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1637 | if (bond->slave_cnt == 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1638 | pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", |
| 1639 | bond_dev->name); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1640 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; |
| 1641 | } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1642 | pr_err("%s: Error: The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active.\n", |
| 1643 | bond_dev->name); |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1644 | res = -EOPNOTSUPP; |
| 1645 | goto err_undo_flags; |
| 1646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Amerigo Wang | 8d8fc29 | 2011-05-19 21:39:10 +0000 | [diff] [blame] | 1649 | call_netdevice_notifiers(NETDEV_JOIN, slave_dev); |
| 1650 | |
Jiri Pirko | c20811a | 2010-05-19 01:14:29 +0000 | [diff] [blame] | 1651 | /* If this is the first slave, then we need to set the master's hardware |
| 1652 | * address to be the same as the slave's. */ |
David Strand | d13a2cb | 2010-12-01 11:43:08 -0800 | [diff] [blame] | 1653 | if (is_zero_ether_addr(bond->dev->dev_addr)) |
Jiri Pirko | c20811a | 2010-05-19 01:14:29 +0000 | [diff] [blame] | 1654 | memcpy(bond->dev->dev_addr, slave_dev->dev_addr, |
| 1655 | slave_dev->addr_len); |
| 1656 | |
| 1657 | |
Joe Jin | 243cb4e | 2007-02-06 14:16:40 -0800 | [diff] [blame] | 1658 | new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | if (!new_slave) { |
| 1660 | res = -ENOMEM; |
| 1661 | goto err_undo_flags; |
| 1662 | } |
| 1663 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1664 | /* |
| 1665 | * Set the new_slave's queue_id to be zero. Queue ID mapping |
| 1666 | * is set via sysfs or module option if desired. |
| 1667 | */ |
| 1668 | new_slave->queue_id = 0; |
| 1669 | |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 1670 | /* Save slave's original mtu and then set it to match the bond */ |
| 1671 | new_slave->original_mtu = slave_dev->mtu; |
| 1672 | res = dev_set_mtu(slave_dev, bond->dev->mtu); |
| 1673 | if (res) { |
| 1674 | pr_debug("Error %d calling dev_set_mtu\n", res); |
| 1675 | goto err_free; |
| 1676 | } |
| 1677 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1678 | /* |
| 1679 | * Save slave's original ("permanent") mac address for modes |
| 1680 | * that need it, and for restoring it upon release, and then |
| 1681 | * set it to the master's address |
| 1682 | */ |
| 1683 | memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1685 | if (!bond->params.fail_over_mac) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1686 | /* |
| 1687 | * Set slave to master's mac address. The application already |
| 1688 | * set the master's mac address to that of the first slave |
| 1689 | */ |
| 1690 | memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len); |
| 1691 | addr.sa_family = slave_dev->type; |
| 1692 | res = dev_set_mac_address(slave_dev, &addr); |
| 1693 | if (res) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1694 | pr_debug("Error %d calling set_mac_address\n", res); |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 1695 | goto err_restore_mtu; |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1696 | } |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 1699 | res = netdev_set_bond_master(slave_dev, bond_dev); |
Jay Vosburgh | c2edacf | 2007-07-09 10:42:47 -0700 | [diff] [blame] | 1700 | if (res) { |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 1701 | pr_debug("Error %d calling netdev_set_bond_master\n", res); |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1702 | goto err_restore_mac; |
Jay Vosburgh | c2edacf | 2007-07-09 10:42:47 -0700 | [diff] [blame] | 1703 | } |
Jiri Pirko | 5b2c4dd | 2011-02-23 09:05:42 +0000 | [diff] [blame] | 1704 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1705 | /* open the slave since the application closed it */ |
| 1706 | res = dev_open(slave_dev); |
| 1707 | if (res) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1708 | pr_debug("Opening slave %s failed\n", slave_dev->name); |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1709 | goto err_unset_master; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1712 | new_slave->bond = bond; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | new_slave->dev = slave_dev; |
Jay Vosburgh | 0b680e7 | 2006-09-22 21:54:10 -0700 | [diff] [blame] | 1714 | slave_dev->priv_flags |= IFF_BONDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1716 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | /* bond_alb_init_slave() must be called before all other stages since |
| 1718 | * it might fail and we do not want to have to undo everything |
| 1719 | */ |
| 1720 | res = bond_alb_init_slave(bond, new_slave); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1721 | if (res) |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1722 | goto err_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | /* If the mode USES_PRIMARY, then the new slave gets the |
| 1726 | * master's promisc (and mc) settings only if it becomes the |
| 1727 | * curr_active_slave, and that is taken care of later when calling |
| 1728 | * bond_change_active() |
| 1729 | */ |
| 1730 | if (!USES_PRIMARY(bond->params.mode)) { |
| 1731 | /* set promiscuity level to new slave */ |
| 1732 | if (bond_dev->flags & IFF_PROMISC) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 1733 | res = dev_set_promiscuity(slave_dev, 1); |
| 1734 | if (res) |
| 1735 | goto err_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | /* set allmulti level to new slave */ |
| 1739 | if (bond_dev->flags & IFF_ALLMULTI) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 1740 | res = dev_set_allmulti(slave_dev, 1); |
| 1741 | if (res) |
| 1742 | goto err_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 1745 | netif_addr_lock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | /* upload master's mc_list to new slave */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1747 | netdev_for_each_mc_addr(ha, bond_dev) |
| 1748 | dev_mc_add(slave_dev, ha->addr); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 1749 | netif_addr_unlock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1753 | /* add lacpdu mc addr to mc list */ |
| 1754 | u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
| 1755 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1756 | dev_mc_add(slave_dev, lacpdu_multicast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | bond_add_vlans_on_slave(bond, slave_dev); |
| 1760 | |
| 1761 | write_lock_bh(&bond->lock); |
| 1762 | |
| 1763 | bond_attach_slave(bond, new_slave); |
| 1764 | |
| 1765 | new_slave->delay = 0; |
| 1766 | new_slave->link_failure_count = 0; |
| 1767 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1768 | write_unlock_bh(&bond->lock); |
| 1769 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1770 | bond_compute_features(bond); |
| 1771 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1772 | read_lock(&bond->lock); |
| 1773 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 1774 | new_slave->last_arp_rx = jiffies; |
| 1775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | if (bond->params.miimon && !bond->params.use_carrier) { |
| 1777 | link_reporting = bond_check_dev_link(bond, slave_dev, 1); |
| 1778 | |
| 1779 | if ((link_reporting == -1) && !bond->params.arp_interval) { |
| 1780 | /* |
| 1781 | * miimon is set but a bonded network driver |
| 1782 | * does not support ETHTOOL/MII and |
| 1783 | * arp_interval is not set. Note: if |
| 1784 | * use_carrier is enabled, we will never go |
| 1785 | * here (because netif_carrier is always |
| 1786 | * supported); thus, we don't need to change |
| 1787 | * the messages for netif_carrier. |
| 1788 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1789 | pr_warning("%s: Warning: MII and ETHTOOL support not available for interface %s, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details.\n", |
Mitch Williams | 4e0952c | 2005-11-09 10:34:57 -0800 | [diff] [blame] | 1790 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | } else if (link_reporting == -1) { |
| 1792 | /* unable get link status using mii/ethtool */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1793 | pr_warning("%s: Warning: can't get link status from interface %s; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface.\n", |
| 1794 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | /* check for initial state */ |
| 1799 | if (!bond->params.miimon || |
| 1800 | (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) { |
| 1801 | if (bond->params.updelay) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1802 | pr_debug("Initial state of slave_dev is BOND_LINK_BACK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | new_slave->link = BOND_LINK_BACK; |
| 1804 | new_slave->delay = bond->params.updelay; |
| 1805 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1806 | pr_debug("Initial state of slave_dev is BOND_LINK_UP\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | new_slave->link = BOND_LINK_UP; |
| 1808 | } |
| 1809 | new_slave->jiffies = jiffies; |
| 1810 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1811 | pr_debug("Initial state of slave_dev is BOND_LINK_DOWN\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | new_slave->link = BOND_LINK_DOWN; |
| 1813 | } |
| 1814 | |
| 1815 | if (bond_update_speed_duplex(new_slave) && |
| 1816 | (new_slave->link != BOND_LINK_DOWN)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1817 | pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n", |
| 1818 | bond_dev->name, new_slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
| 1820 | if (bond->params.mode == BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1821 | pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n", |
| 1822 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) { |
| 1827 | /* if there is a primary slave, remember it */ |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1828 | if (strcmp(bond->params.primary, new_slave->dev->name) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | bond->primary_slave = new_slave; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1830 | bond->force_primary = true; |
| 1831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1834 | write_lock_bh(&bond->curr_slave_lock); |
| 1835 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | switch (bond->params.mode) { |
| 1837 | case BOND_MODE_ACTIVEBACKUP: |
Jay Vosburgh | 8a8e447 | 2006-09-22 21:56:15 -0700 | [diff] [blame] | 1838 | bond_set_slave_inactive_flags(new_slave); |
| 1839 | bond_select_active_slave(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | break; |
| 1841 | case BOND_MODE_8023AD: |
| 1842 | /* in 802.3ad mode, the internal mechanism |
| 1843 | * will activate the slaves in the selected |
| 1844 | * aggregator |
| 1845 | */ |
| 1846 | bond_set_slave_inactive_flags(new_slave); |
| 1847 | /* if this is the first slave */ |
| 1848 | if (bond->slave_cnt == 1) { |
| 1849 | SLAVE_AD_INFO(new_slave).id = 1; |
| 1850 | /* Initialize AD with the number of times that the AD timer is called in 1 second |
| 1851 | * can be called only after the mac address of the bond is set |
| 1852 | */ |
| 1853 | bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL, |
| 1854 | bond->params.lacp_fast); |
| 1855 | } else { |
| 1856 | SLAVE_AD_INFO(new_slave).id = |
| 1857 | SLAVE_AD_INFO(new_slave->prev).id + 1; |
| 1858 | } |
| 1859 | |
| 1860 | bond_3ad_bind_slave(new_slave); |
| 1861 | break; |
| 1862 | case BOND_MODE_TLB: |
| 1863 | case BOND_MODE_ALB: |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1864 | bond_set_active_slave(new_slave); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1865 | bond_set_slave_inactive_flags(new_slave); |
Jiri Pirko | 5a29f78 | 2009-03-25 17:23:38 -0700 | [diff] [blame] | 1866 | bond_select_active_slave(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | break; |
| 1868 | default: |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1869 | pr_debug("This slave is always active in trunk mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
| 1871 | /* always active in trunk mode */ |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1872 | bond_set_active_slave(new_slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | |
| 1874 | /* In trunking mode there is little meaning to curr_active_slave |
| 1875 | * anyway (it holds no special properties of the bond device), |
| 1876 | * so we can change it without calling change_active_interface() |
| 1877 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1878 | if (!bond->curr_active_slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | bond->curr_active_slave = new_slave; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | break; |
| 1882 | } /* switch(bond_mode) */ |
| 1883 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1884 | write_unlock_bh(&bond->curr_slave_lock); |
| 1885 | |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1886 | bond_set_carrier(bond); |
| 1887 | |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1888 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1889 | slave_dev->npinfo = bond_netpoll_info(bond); |
| 1890 | if (slave_dev->npinfo) { |
| 1891 | if (slave_enable_netpoll(new_slave)) { |
| 1892 | read_unlock(&bond->lock); |
| 1893 | pr_info("Error, %s: master_dev is using netpoll, " |
| 1894 | "but new slave device does not support netpoll.\n", |
| 1895 | bond_dev->name); |
| 1896 | res = -EBUSY; |
| 1897 | goto err_close; |
| 1898 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1899 | } |
| 1900 | #endif |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 1901 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1902 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1904 | res = bond_create_slave_symlinks(bond_dev, slave_dev); |
| 1905 | if (res) |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1906 | goto err_close; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1907 | |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1908 | res = netdev_rx_handler_register(slave_dev, bond_handle_frame, |
| 1909 | new_slave); |
| 1910 | if (res) { |
| 1911 | pr_debug("Error %d calling netdev_rx_handler_register\n", res); |
| 1912 | goto err_dest_symlinks; |
| 1913 | } |
| 1914 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1915 | pr_info("%s: enslaving %s as a%s interface with a%s link.\n", |
| 1916 | bond_dev->name, slave_dev->name, |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 1917 | bond_is_active_slave(new_slave) ? "n active" : " backup", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1918 | new_slave->link != BOND_LINK_DOWN ? "n up" : " down"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
| 1920 | /* enslave is successful */ |
| 1921 | return 0; |
| 1922 | |
| 1923 | /* Undo stages on error */ |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1924 | err_dest_symlinks: |
| 1925 | bond_destroy_slave_symlinks(bond_dev, slave_dev); |
| 1926 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | err_close: |
| 1928 | dev_close(slave_dev); |
| 1929 | |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1930 | err_unset_master: |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 1931 | netdev_set_bond_master(slave_dev, NULL); |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | err_restore_mac: |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1934 | if (!bond->params.fail_over_mac) { |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1935 | /* XXX TODO - fom follow mode needs to change master's |
| 1936 | * MAC if this slave's MAC is in use by the bond, or at |
| 1937 | * least print a warning. |
| 1938 | */ |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1939 | memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN); |
| 1940 | addr.sa_family = slave_dev->type; |
| 1941 | dev_set_mac_address(slave_dev, &addr); |
| 1942 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 1944 | err_restore_mtu: |
| 1945 | dev_set_mtu(slave_dev, new_slave->original_mtu); |
| 1946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | err_free: |
| 1948 | kfree(new_slave); |
| 1949 | |
| 1950 | err_undo_flags: |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1951 | bond_compute_features(bond); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | return res; |
| 1954 | } |
| 1955 | |
| 1956 | /* |
| 1957 | * Try to release the slave device <slave> from the bond device <master> |
| 1958 | * It is legal to access curr_active_slave without a lock because all the function |
| 1959 | * is write-locked. |
| 1960 | * |
| 1961 | * The rules for slave state should be: |
| 1962 | * for Active/Backup: |
| 1963 | * Active stays on all backups go down |
| 1964 | * for Bonded connections: |
| 1965 | * The first up interface should be left on and all others downed. |
| 1966 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1967 | int bond_release(struct net_device *bond_dev, struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1969 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | struct slave *slave, *oldcurrent; |
| 1971 | struct sockaddr addr; |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 1972 | u32 old_features = bond_dev->features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | |
| 1974 | /* slave is not a slave or master is not master of this slave */ |
| 1975 | if (!(slave_dev->flags & IFF_SLAVE) || |
| 1976 | (slave_dev->master != bond_dev)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1977 | pr_err("%s: Error: cannot release %s.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | bond_dev->name, slave_dev->name); |
| 1979 | return -EINVAL; |
| 1980 | } |
| 1981 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1982 | block_netpoll_tx(); |
Amerigo Wang | daf9209 | 2011-05-19 21:39:12 +0000 | [diff] [blame] | 1983 | netdev_bonding_change(bond_dev, NETDEV_RELEASE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | write_lock_bh(&bond->lock); |
| 1985 | |
| 1986 | slave = bond_get_slave_by_dev(bond, slave_dev); |
| 1987 | if (!slave) { |
| 1988 | /* not a slave of this bond */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1989 | pr_info("%s: %s not enslaved\n", |
| 1990 | bond_dev->name, slave_dev->name); |
Jay Vosburgh | f5e2a7b | 2006-02-07 21:17:22 -0800 | [diff] [blame] | 1991 | write_unlock_bh(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1992 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | return -EINVAL; |
| 1994 | } |
| 1995 | |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 1996 | /* unregister rx_handler early so bond_handle_frame wouldn't be called |
| 1997 | * for this slave anymore. |
| 1998 | */ |
| 1999 | netdev_rx_handler_unregister(slave_dev); |
| 2000 | write_unlock_bh(&bond->lock); |
| 2001 | synchronize_net(); |
| 2002 | write_lock_bh(&bond->lock); |
| 2003 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 2004 | if (!bond->params.fail_over_mac) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 2005 | if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) && |
| 2006 | bond->slave_cnt > 1) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2007 | pr_warning("%s: Warning: the permanent HWaddr of %s - %pM - is still in use by %s. Set the HWaddr of %s to a different address to avoid conflicts.\n", |
| 2008 | bond_dev->name, slave_dev->name, |
| 2009 | slave->perm_hwaddr, |
| 2010 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /* Inform AD package of unbinding of slave. */ |
| 2014 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 2015 | /* must be called before the slave is |
| 2016 | * detached from the list |
| 2017 | */ |
| 2018 | bond_3ad_unbind_slave(slave); |
| 2019 | } |
| 2020 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2021 | pr_info("%s: releasing %s interface %s\n", |
| 2022 | bond_dev->name, |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2023 | bond_is_active_slave(slave) ? "active" : "backup", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2024 | slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | |
| 2026 | oldcurrent = bond->curr_active_slave; |
| 2027 | |
| 2028 | bond->current_arp_slave = NULL; |
| 2029 | |
| 2030 | /* release the slave from its bond */ |
| 2031 | bond_detach_slave(bond, slave); |
| 2032 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2033 | if (bond->primary_slave == slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | bond->primary_slave = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2036 | if (oldcurrent == slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | bond_change_active_slave(bond, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 2039 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | /* Must be called only after the slave has been |
| 2041 | * detached from the list and the curr_active_slave |
| 2042 | * has been cleared (if our_slave == old_current), |
| 2043 | * but before a new active slave is selected. |
| 2044 | */ |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 2045 | write_unlock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | bond_alb_deinit_slave(bond, slave); |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 2047 | write_lock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2050 | if (oldcurrent == slave) { |
| 2051 | /* |
| 2052 | * Note that we hold RTNL over this sequence, so there |
| 2053 | * is no concern that another slave add/remove event |
| 2054 | * will interfere. |
| 2055 | */ |
| 2056 | write_unlock_bh(&bond->lock); |
| 2057 | read_lock(&bond->lock); |
| 2058 | write_lock_bh(&bond->curr_slave_lock); |
| 2059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | bond_select_active_slave(bond); |
| 2061 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2062 | write_unlock_bh(&bond->curr_slave_lock); |
| 2063 | read_unlock(&bond->lock); |
| 2064 | write_lock_bh(&bond->lock); |
| 2065 | } |
| 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | if (bond->slave_cnt == 0) { |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2068 | bond_set_carrier(bond); |
| 2069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | /* if the last slave was removed, zero the mac address |
| 2071 | * of the master so it will be set by the application |
| 2072 | * to the mac address of the first slave |
| 2073 | */ |
| 2074 | memset(bond_dev->dev_addr, 0, bond_dev->addr_len); |
| 2075 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 2076 | if (bond->vlgrp) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2077 | pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", |
| 2078 | bond_dev->name, bond_dev->name); |
| 2079 | pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n", |
| 2080 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | write_unlock_bh(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2085 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 2087 | bond_compute_features(bond); |
| 2088 | if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) && |
| 2089 | (old_features & NETIF_F_VLAN_CHALLENGED)) |
| 2090 | pr_info("%s: last VLAN challenged slave %s left bond %s. VLAN blocking is removed\n", |
| 2091 | bond_dev->name, slave_dev->name, bond_dev->name); |
| 2092 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 2093 | /* must do this from outside any spinlocks */ |
| 2094 | bond_destroy_slave_symlinks(bond_dev, slave_dev); |
| 2095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | bond_del_vlans_from_slave(bond, slave_dev); |
| 2097 | |
| 2098 | /* If the mode USES_PRIMARY, then we should only remove its |
| 2099 | * promisc and mc settings if it was the curr_active_slave, but that was |
| 2100 | * already taken care of above when we detached the slave |
| 2101 | */ |
| 2102 | if (!USES_PRIMARY(bond->params.mode)) { |
| 2103 | /* unset promiscuity level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2104 | if (bond_dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | dev_set_promiscuity(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
| 2107 | /* unset allmulti level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2108 | if (bond_dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | dev_set_allmulti(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | |
| 2111 | /* flush master's mc_list from slave */ |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2112 | netif_addr_lock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | bond_mc_list_flush(bond_dev, slave_dev); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2114 | netif_addr_unlock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 2117 | netdev_set_bond_master(slave_dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 2119 | slave_disable_netpoll(slave); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 2120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | /* close slave before restoring its mac address */ |
| 2122 | dev_close(slave_dev); |
| 2123 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 2124 | if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 2125 | /* restore original ("permanent") mac address */ |
| 2126 | memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); |
| 2127 | addr.sa_family = slave_dev->type; |
| 2128 | dev_set_mac_address(slave_dev, &addr); |
| 2129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 2131 | dev_set_mtu(slave_dev, slave->original_mtu); |
| 2132 | |
Jiri Pirko | 2d7011c | 2011-03-16 08:46:43 +0000 | [diff] [blame] | 2133 | slave_dev->priv_flags &= ~IFF_BONDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | |
| 2135 | kfree(slave); |
| 2136 | |
| 2137 | return 0; /* deletion OK */ |
| 2138 | } |
| 2139 | |
| 2140 | /* |
Nicolas de Pesloüan | dadaa10 | 2011-03-19 13:36:18 -0700 | [diff] [blame] | 2141 | * First release a slave and then destroy the bond if no more slaves are left. |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2142 | * Must be under rtnl_lock when this function is called. |
| 2143 | */ |
stephen hemminger | 26d8ee7 | 2010-10-15 05:09:34 +0000 | [diff] [blame] | 2144 | static int bond_release_and_destroy(struct net_device *bond_dev, |
| 2145 | struct net_device *slave_dev) |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2146 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2147 | struct bonding *bond = netdev_priv(bond_dev); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2148 | int ret; |
| 2149 | |
| 2150 | ret = bond_release(bond_dev, slave_dev); |
| 2151 | if ((ret == 0) && (bond->slave_cnt == 0)) { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 2152 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2153 | pr_info("%s: destroying bond %s.\n", |
| 2154 | bond_dev->name, bond_dev->name); |
Stephen Hemminger | 9e71626 | 2009-06-12 19:02:47 +0000 | [diff] [blame] | 2155 | unregister_netdevice(bond_dev); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2156 | } |
| 2157 | return ret; |
| 2158 | } |
| 2159 | |
| 2160 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | * This function releases all slaves. |
| 2162 | */ |
| 2163 | static int bond_release_all(struct net_device *bond_dev) |
| 2164 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2165 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | struct slave *slave; |
| 2167 | struct net_device *slave_dev; |
| 2168 | struct sockaddr addr; |
| 2169 | |
| 2170 | write_lock_bh(&bond->lock); |
| 2171 | |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2172 | netif_carrier_off(bond_dev); |
| 2173 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2174 | if (bond->slave_cnt == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | |
| 2177 | bond->current_arp_slave = NULL; |
| 2178 | bond->primary_slave = NULL; |
| 2179 | bond_change_active_slave(bond, NULL); |
| 2180 | |
| 2181 | while ((slave = bond->first_slave) != NULL) { |
| 2182 | /* Inform AD package of unbinding of slave |
| 2183 | * before slave is detached from the list. |
| 2184 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2185 | if (bond->params.mode == BOND_MODE_8023AD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | bond_3ad_unbind_slave(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | |
| 2188 | slave_dev = slave->dev; |
| 2189 | bond_detach_slave(bond, slave); |
| 2190 | |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 2191 | /* now that the slave is detached, unlock and perform |
| 2192 | * all the undo steps that should not be called from |
| 2193 | * within a lock. |
| 2194 | */ |
| 2195 | write_unlock_bh(&bond->lock); |
| 2196 | |
Jiri Pirko | 35d4890 | 2011-03-22 02:38:12 +0000 | [diff] [blame] | 2197 | /* unregister rx_handler early so bond_handle_frame wouldn't |
| 2198 | * be called for this slave anymore. |
| 2199 | */ |
| 2200 | netdev_rx_handler_unregister(slave_dev); |
| 2201 | synchronize_net(); |
| 2202 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 2203 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | /* must be called only after the slave |
| 2205 | * has been detached from the list |
| 2206 | */ |
| 2207 | bond_alb_deinit_slave(bond, slave); |
| 2208 | } |
| 2209 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 2210 | bond_destroy_slave_symlinks(bond_dev, slave_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | bond_del_vlans_from_slave(bond, slave_dev); |
| 2212 | |
| 2213 | /* If the mode USES_PRIMARY, then we should only remove its |
| 2214 | * promisc and mc settings if it was the curr_active_slave, but that was |
| 2215 | * already taken care of above when we detached the slave |
| 2216 | */ |
| 2217 | if (!USES_PRIMARY(bond->params.mode)) { |
| 2218 | /* unset promiscuity level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2219 | if (bond_dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | dev_set_promiscuity(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
| 2222 | /* unset allmulti level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2223 | if (bond_dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | dev_set_allmulti(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
| 2226 | /* flush master's mc_list from slave */ |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2227 | netif_addr_lock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | bond_mc_list_flush(bond_dev, slave_dev); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2229 | netif_addr_unlock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 2232 | netdev_set_bond_master(slave_dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 2234 | slave_disable_netpoll(slave); |
| 2235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | /* close slave before restoring its mac address */ |
| 2237 | dev_close(slave_dev); |
| 2238 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 2239 | if (!bond->params.fail_over_mac) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 2240 | /* restore original ("permanent") mac address*/ |
| 2241 | memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); |
| 2242 | addr.sa_family = slave_dev->type; |
| 2243 | dev_set_mac_address(slave_dev, &addr); |
| 2244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | kfree(slave); |
| 2247 | |
| 2248 | /* re-acquire the lock before getting the next slave */ |
| 2249 | write_lock_bh(&bond->lock); |
| 2250 | } |
| 2251 | |
| 2252 | /* zero the mac address of the master so it will be |
| 2253 | * set by the application to the mac address of the |
| 2254 | * first slave |
| 2255 | */ |
| 2256 | memset(bond_dev->dev_addr, 0, bond_dev->addr_len); |
| 2257 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 2258 | if (bond->vlgrp) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2259 | pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", |
| 2260 | bond_dev->name, bond_dev->name); |
| 2261 | pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n", |
| 2262 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2265 | pr_info("%s: released all slaves\n", bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
| 2267 | out: |
| 2268 | write_unlock_bh(&bond->lock); |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 2269 | |
| 2270 | bond_compute_features(bond); |
| 2271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | return 0; |
| 2273 | } |
| 2274 | |
| 2275 | /* |
| 2276 | * This function changes the active slave to slave <slave_dev>. |
| 2277 | * It returns -EINVAL in the following cases. |
| 2278 | * - <slave_dev> is not found in the list. |
| 2279 | * - There is not active slave now. |
| 2280 | * - <slave_dev> is already active. |
| 2281 | * - The link state of <slave_dev> is not BOND_LINK_UP. |
| 2282 | * - <slave_dev> is not running. |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2283 | * In these cases, this function does nothing. |
| 2284 | * In the other cases, current_slave pointer is changed and 0 is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2285 | */ |
| 2286 | static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev) |
| 2287 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2288 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | struct slave *old_active = NULL; |
| 2290 | struct slave *new_active = NULL; |
| 2291 | int res = 0; |
| 2292 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2293 | if (!USES_PRIMARY(bond->params.mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | |
| 2296 | /* Verify that master_dev is indeed the master of slave_dev */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2297 | if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != bond_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2300 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2302 | read_lock(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | old_active = bond->curr_active_slave; |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2304 | read_unlock(&bond->curr_slave_lock); |
| 2305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | new_active = bond_get_slave_by_dev(bond, slave_dev); |
| 2307 | |
| 2308 | /* |
| 2309 | * Changing to the current active: do nothing; return success. |
| 2310 | */ |
| 2311 | if (new_active && (new_active == old_active)) { |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2312 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | return 0; |
| 2314 | } |
| 2315 | |
| 2316 | if ((new_active) && |
| 2317 | (old_active) && |
| 2318 | (new_active->link == BOND_LINK_UP) && |
| 2319 | IS_UP(new_active->dev)) { |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2320 | block_netpoll_tx(); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2321 | write_lock_bh(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | bond_change_active_slave(bond, new_active); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2323 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2324 | unblock_netpoll_tx(); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2325 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | res = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2327 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2328 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
| 2330 | return res; |
| 2331 | } |
| 2332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | static int bond_info_query(struct net_device *bond_dev, struct ifbond *info) |
| 2334 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2335 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | |
| 2337 | info->bond_mode = bond->params.mode; |
| 2338 | info->miimon = bond->params.miimon; |
| 2339 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2340 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | info->num_slaves = bond->slave_cnt; |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2342 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | |
| 2344 | return 0; |
| 2345 | } |
| 2346 | |
| 2347 | static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info) |
| 2348 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2349 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | struct slave *slave; |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2351 | int i, res = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2353 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | |
| 2355 | bond_for_each_slave(bond, slave, i) { |
| 2356 | if (i == (int)info->slave_id) { |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2357 | res = 0; |
| 2358 | strcpy(info->slave_name, slave->dev->name); |
| 2359 | info->link = slave->link; |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2360 | info->state = bond_slave_state(slave); |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2361 | info->link_failure_count = slave->link_failure_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | break; |
| 2363 | } |
| 2364 | } |
| 2365 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2366 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2368 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | /*-------------------------------- Monitoring -------------------------------*/ |
| 2372 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2373 | |
| 2374 | static int bond_miimon_inspect(struct bonding *bond) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | { |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2376 | struct slave *slave; |
| 2377 | int i, link_state, commit = 0; |
Jiri Pirko | 41f8910 | 2009-04-24 03:57:29 +0000 | [diff] [blame] | 2378 | bool ignore_updelay; |
| 2379 | |
| 2380 | ignore_updelay = !bond->curr_active_slave ? true : false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | |
| 2382 | bond_for_each_slave(bond, slave, i) { |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2383 | slave->new_link = BOND_LINK_NOCHANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2385 | link_state = bond_check_dev_link(bond, slave->dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | |
| 2387 | switch (slave->link) { |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2388 | case BOND_LINK_UP: |
| 2389 | if (link_state) |
| 2390 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2392 | slave->link = BOND_LINK_FAIL; |
| 2393 | slave->delay = bond->params.downdelay; |
| 2394 | if (slave->delay) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2395 | pr_info("%s: link status down for %sinterface %s, disabling it in %d ms.\n", |
| 2396 | bond->dev->name, |
| 2397 | (bond->params.mode == |
| 2398 | BOND_MODE_ACTIVEBACKUP) ? |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2399 | (bond_is_active_slave(slave) ? |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2400 | "active " : "backup ") : "", |
| 2401 | slave->dev->name, |
| 2402 | bond->params.downdelay * bond->params.miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2404 | /*FALLTHRU*/ |
| 2405 | case BOND_LINK_FAIL: |
| 2406 | if (link_state) { |
| 2407 | /* |
| 2408 | * recovered before downdelay expired |
| 2409 | */ |
| 2410 | slave->link = BOND_LINK_UP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | slave->jiffies = jiffies; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2412 | pr_info("%s: link status up again after %d ms for interface %s.\n", |
| 2413 | bond->dev->name, |
| 2414 | (bond->params.downdelay - slave->delay) * |
| 2415 | bond->params.miimon, |
| 2416 | slave->dev->name); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2417 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2419 | |
| 2420 | if (slave->delay <= 0) { |
| 2421 | slave->new_link = BOND_LINK_DOWN; |
| 2422 | commit++; |
| 2423 | continue; |
| 2424 | } |
| 2425 | |
| 2426 | slave->delay--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2429 | case BOND_LINK_DOWN: |
| 2430 | if (!link_state) |
| 2431 | continue; |
| 2432 | |
| 2433 | slave->link = BOND_LINK_BACK; |
| 2434 | slave->delay = bond->params.updelay; |
| 2435 | |
| 2436 | if (slave->delay) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2437 | pr_info("%s: link status up for interface %s, enabling it in %d ms.\n", |
| 2438 | bond->dev->name, slave->dev->name, |
| 2439 | ignore_updelay ? 0 : |
| 2440 | bond->params.updelay * |
| 2441 | bond->params.miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2443 | /*FALLTHRU*/ |
| 2444 | case BOND_LINK_BACK: |
| 2445 | if (!link_state) { |
| 2446 | slave->link = BOND_LINK_DOWN; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2447 | pr_info("%s: link status down again after %d ms for interface %s.\n", |
| 2448 | bond->dev->name, |
| 2449 | (bond->params.updelay - slave->delay) * |
| 2450 | bond->params.miimon, |
| 2451 | slave->dev->name); |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2452 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2453 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2455 | |
Jiri Pirko | 41f8910 | 2009-04-24 03:57:29 +0000 | [diff] [blame] | 2456 | if (ignore_updelay) |
| 2457 | slave->delay = 0; |
| 2458 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2459 | if (slave->delay <= 0) { |
| 2460 | slave->new_link = BOND_LINK_UP; |
| 2461 | commit++; |
Jiri Pirko | 41f8910 | 2009-04-24 03:57:29 +0000 | [diff] [blame] | 2462 | ignore_updelay = false; |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2463 | continue; |
| 2464 | } |
| 2465 | |
| 2466 | slave->delay--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | break; |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | return commit; |
| 2472 | } |
| 2473 | |
| 2474 | static void bond_miimon_commit(struct bonding *bond) |
| 2475 | { |
| 2476 | struct slave *slave; |
| 2477 | int i; |
| 2478 | |
| 2479 | bond_for_each_slave(bond, slave, i) { |
| 2480 | switch (slave->new_link) { |
| 2481 | case BOND_LINK_NOCHANGE: |
| 2482 | continue; |
| 2483 | |
| 2484 | case BOND_LINK_UP: |
| 2485 | slave->link = BOND_LINK_UP; |
| 2486 | slave->jiffies = jiffies; |
| 2487 | |
| 2488 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 2489 | /* prevent it from being the active one */ |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2490 | bond_set_backup_slave(slave); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2491 | } else if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
| 2492 | /* make it immediately active */ |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2493 | bond_set_active_slave(slave); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2494 | } else if (slave != bond->primary_slave) { |
| 2495 | /* prevent it from being the active one */ |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2496 | bond_set_backup_slave(slave); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Krzysztof Piotr Oledzki | 546add7 | 2010-10-06 14:28:22 -0700 | [diff] [blame] | 2499 | bond_update_speed_duplex(slave); |
| 2500 | |
David Decotigny | 5d30530 | 2011-04-13 15:22:31 +0000 | [diff] [blame] | 2501 | pr_info("%s: link status definitely up for interface %s, %u Mbps %s duplex.\n", |
Krzysztof Piotr Oledzki | 700c2a7 | 2010-10-06 14:25:06 -0700 | [diff] [blame] | 2502 | bond->dev->name, slave->dev->name, |
| 2503 | slave->speed, slave->duplex ? "full" : "half"); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2504 | |
| 2505 | /* notify ad that the link status has changed */ |
| 2506 | if (bond->params.mode == BOND_MODE_8023AD) |
| 2507 | bond_3ad_handle_link_change(slave, BOND_LINK_UP); |
| 2508 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 2509 | if (bond_is_lb(bond)) |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2510 | bond_alb_handle_link_change(bond, slave, |
| 2511 | BOND_LINK_UP); |
| 2512 | |
| 2513 | if (!bond->curr_active_slave || |
| 2514 | (slave == bond->primary_slave)) |
| 2515 | goto do_failover; |
| 2516 | |
| 2517 | continue; |
| 2518 | |
| 2519 | case BOND_LINK_DOWN: |
Jay Vosburgh | fba4acd | 2008-10-30 17:41:14 -0700 | [diff] [blame] | 2520 | if (slave->link_failure_count < UINT_MAX) |
| 2521 | slave->link_failure_count++; |
| 2522 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2523 | slave->link = BOND_LINK_DOWN; |
| 2524 | |
| 2525 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP || |
| 2526 | bond->params.mode == BOND_MODE_8023AD) |
| 2527 | bond_set_slave_inactive_flags(slave); |
| 2528 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2529 | pr_info("%s: link status definitely down for interface %s, disabling it\n", |
| 2530 | bond->dev->name, slave->dev->name); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2531 | |
| 2532 | if (bond->params.mode == BOND_MODE_8023AD) |
| 2533 | bond_3ad_handle_link_change(slave, |
| 2534 | BOND_LINK_DOWN); |
| 2535 | |
Jiri Pirko | ae63e80 | 2009-05-27 05:42:36 +0000 | [diff] [blame] | 2536 | if (bond_is_lb(bond)) |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2537 | bond_alb_handle_link_change(bond, slave, |
| 2538 | BOND_LINK_DOWN); |
| 2539 | |
| 2540 | if (slave == bond->curr_active_slave) |
| 2541 | goto do_failover; |
| 2542 | |
| 2543 | continue; |
| 2544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | default: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2546 | pr_err("%s: invalid new link %d on slave %s\n", |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2547 | bond->dev->name, slave->new_link, |
| 2548 | slave->dev->name); |
| 2549 | slave->new_link = BOND_LINK_NOCHANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2551 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2554 | do_failover: |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2555 | ASSERT_RTNL(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2556 | block_netpoll_tx(); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2557 | write_lock_bh(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | bond_select_active_slave(bond); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2559 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2560 | unblock_netpoll_tx(); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2561 | } |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2562 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2563 | bond_set_carrier(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2566 | /* |
| 2567 | * bond_mii_monitor |
| 2568 | * |
| 2569 | * Really a wrapper that splits the mii monitor into two phases: an |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2570 | * inspection, then (if inspection indicates something needs to be done) |
| 2571 | * an acquisition of appropriate locks followed by a commit phase to |
| 2572 | * implement whatever link state changes are indicated. |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2573 | */ |
| 2574 | void bond_mii_monitor(struct work_struct *work) |
| 2575 | { |
| 2576 | struct bonding *bond = container_of(work, struct bonding, |
| 2577 | mii_work.work); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 2578 | bool should_notify_peers = false; |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2579 | |
| 2580 | read_lock(&bond->lock); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2581 | if (bond->kill_timers) |
| 2582 | goto out; |
| 2583 | |
| 2584 | if (bond->slave_cnt == 0) |
| 2585 | goto re_arm; |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 2586 | |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 2587 | should_notify_peers = bond_should_notify_peers(bond); |
| 2588 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2589 | if (bond_miimon_inspect(bond)) { |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2590 | read_unlock(&bond->lock); |
| 2591 | rtnl_lock(); |
| 2592 | read_lock(&bond->lock); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2593 | |
| 2594 | bond_miimon_commit(bond); |
| 2595 | |
Jay Vosburgh | 5655662 | 2008-01-17 16:25:03 -0800 | [diff] [blame] | 2596 | read_unlock(&bond->lock); |
| 2597 | rtnl_unlock(); /* might sleep, hold no other locks */ |
| 2598 | read_lock(&bond->lock); |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2601 | re_arm: |
| 2602 | if (bond->params.miimon) |
| 2603 | queue_delayed_work(bond->wq, &bond->mii_work, |
| 2604 | msecs_to_jiffies(bond->params.miimon)); |
| 2605 | out: |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2606 | read_unlock(&bond->lock); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 2607 | |
| 2608 | if (should_notify_peers) { |
| 2609 | rtnl_lock(); |
| 2610 | netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS); |
| 2611 | rtnl_unlock(); |
| 2612 | } |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2613 | } |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2614 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2615 | static __be32 bond_glean_dev_ip(struct net_device *dev) |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2616 | { |
| 2617 | struct in_device *idev; |
| 2618 | struct in_ifaddr *ifa; |
Al Viro | a144ea4 | 2006-09-28 18:00:55 -0700 | [diff] [blame] | 2619 | __be32 addr = 0; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2620 | |
| 2621 | if (!dev) |
| 2622 | return 0; |
| 2623 | |
| 2624 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 2625 | idev = __in_dev_get_rcu(dev); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2626 | if (!idev) |
| 2627 | goto out; |
| 2628 | |
| 2629 | ifa = idev->ifa_list; |
| 2630 | if (!ifa) |
| 2631 | goto out; |
| 2632 | |
| 2633 | addr = ifa->ifa_local; |
| 2634 | out: |
| 2635 | rcu_read_unlock(); |
| 2636 | return addr; |
| 2637 | } |
| 2638 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2639 | static int bond_has_this_ip(struct bonding *bond, __be32 ip) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2640 | { |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2641 | struct vlan_entry *vlan; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2642 | |
| 2643 | if (ip == bond->master_ip) |
| 2644 | return 1; |
| 2645 | |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2646 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2647 | if (ip == vlan->vlan_ip) |
| 2648 | return 1; |
| 2649 | } |
| 2650 | |
| 2651 | return 0; |
| 2652 | } |
| 2653 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2654 | /* |
| 2655 | * We go to the (large) trouble of VLAN tagging ARP frames because |
| 2656 | * switches in VLAN mode (especially if ports are configured as |
| 2657 | * "native" to a VLAN) might not pass non-tagged frames. |
| 2658 | */ |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2659 | static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_ip, __be32 src_ip, unsigned short vlan_id) |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2660 | { |
| 2661 | struct sk_buff *skb; |
| 2662 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2663 | pr_debug("arp %d on slave %s: dst %x src %x vid %d\n", arp_op, |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2664 | slave_dev->name, dest_ip, src_ip, vlan_id); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2665 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2666 | skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip, |
| 2667 | NULL, slave_dev->dev_addr, NULL); |
| 2668 | |
| 2669 | if (!skb) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2670 | pr_err("ARP packet allocation failed\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2671 | return; |
| 2672 | } |
| 2673 | if (vlan_id) { |
| 2674 | skb = vlan_put_tag(skb, vlan_id); |
| 2675 | if (!skb) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2676 | pr_err("failed to insert VLAN tag\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2677 | return; |
| 2678 | } |
| 2679 | } |
| 2680 | arp_xmit(skb); |
| 2681 | } |
| 2682 | |
| 2683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | static void bond_arp_send_all(struct bonding *bond, struct slave *slave) |
| 2685 | { |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 2686 | int i, vlan_id; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2687 | __be32 *targets = bond->params.arp_targets; |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2688 | struct vlan_entry *vlan; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2689 | struct net_device *vlan_dev; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2690 | struct rtable *rt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | |
Mitch Williams | 6b78056 | 2005-11-09 10:36:19 -0800 | [diff] [blame] | 2692 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
| 2693 | if (!targets[i]) |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 2694 | break; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2695 | pr_debug("basa: target %x\n", targets[i]); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 2696 | if (!bond->vlgrp) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2697 | pr_debug("basa: empty vlan: arp_send\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2698 | bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
| 2699 | bond->master_ip, 0); |
| 2700 | continue; |
| 2701 | } |
| 2702 | |
| 2703 | /* |
| 2704 | * If VLANs are configured, we do a route lookup to |
| 2705 | * determine which VLAN interface would be used, so we |
| 2706 | * can tag the ARP with the proper VLAN tag. |
| 2707 | */ |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 2708 | rt = ip_route_output(dev_net(bond->dev), targets[i], 0, |
| 2709 | RTO_ONLINK, 0); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 2710 | if (IS_ERR(rt)) { |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2711 | if (net_ratelimit()) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2712 | pr_warning("%s: no route to arp_ip_target %pI4\n", |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 2713 | bond->dev->name, &targets[i]); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2714 | } |
| 2715 | continue; |
| 2716 | } |
| 2717 | |
| 2718 | /* |
| 2719 | * This target is not on a VLAN |
| 2720 | */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2721 | if (rt->dst.dev == bond->dev) { |
Jay Vosburgh | ed4b9f8 | 2005-09-14 14:52:09 -0700 | [diff] [blame] | 2722 | ip_rt_put(rt); |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2723 | pr_debug("basa: rtdev == bond->dev: arp_send\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2724 | bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
| 2725 | bond->master_ip, 0); |
| 2726 | continue; |
| 2727 | } |
| 2728 | |
| 2729 | vlan_id = 0; |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2730 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 2731 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2732 | if (vlan_dev == rt->dst.dev) { |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2733 | vlan_id = vlan->vlan_id; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2734 | pr_debug("basa: vlan match on %s %d\n", |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2735 | vlan_dev->name, vlan_id); |
| 2736 | break; |
| 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | if (vlan_id) { |
Jay Vosburgh | ed4b9f8 | 2005-09-14 14:52:09 -0700 | [diff] [blame] | 2741 | ip_rt_put(rt); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2742 | bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
| 2743 | vlan->vlan_ip, vlan_id); |
| 2744 | continue; |
| 2745 | } |
| 2746 | |
| 2747 | if (net_ratelimit()) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2748 | pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n", |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 2749 | bond->dev->name, &targets[i], |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2750 | rt->dst.dev ? rt->dst.dev->name : "NULL"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2751 | } |
Jay Vosburgh | ed4b9f8 | 2005-09-14 14:52:09 -0700 | [diff] [blame] | 2752 | ip_rt_put(rt); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2753 | } |
| 2754 | } |
| 2755 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2756 | static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2757 | { |
| 2758 | int i; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2759 | __be32 *targets = bond->params.arp_targets; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2760 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2761 | for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2762 | pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2763 | &sip, &tip, i, &targets[i], |
| 2764 | bond_has_this_ip(bond, tip)); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2765 | if (sip == targets[i]) { |
| 2766 | if (bond_has_this_ip(bond, tip)) |
| 2767 | slave->last_arp_rx = jiffies; |
| 2768 | return; |
| 2769 | } |
| 2770 | } |
| 2771 | } |
| 2772 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2773 | static void bond_arp_rcv(struct sk_buff *skb, struct bonding *bond, |
| 2774 | struct slave *slave) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2775 | { |
| 2776 | struct arphdr *arp; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2777 | unsigned char *arp_ptr; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2778 | __be32 sip, tip; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2779 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2780 | if (skb->protocol != __cpu_to_be16(ETH_P_ARP)) |
| 2781 | return; |
Andy Gospodarek | 1f3c880 | 2009-12-14 10:48:58 +0000 | [diff] [blame] | 2782 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2783 | read_lock(&bond->lock); |
| 2784 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2785 | pr_debug("bond_arp_rcv: bond %s skb->dev %s\n", |
| 2786 | bond->dev->name, skb->dev->name); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2787 | |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2788 | if (!pskb_may_pull(skb, arp_hdr_len(bond->dev))) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2789 | goto out_unlock; |
| 2790 | |
Arnaldo Carvalho de Melo | d0a92be | 2007-03-12 20:56:31 -0300 | [diff] [blame] | 2791 | arp = arp_hdr(skb); |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2792 | if (arp->ar_hln != bond->dev->addr_len || |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2793 | skb->pkt_type == PACKET_OTHERHOST || |
| 2794 | skb->pkt_type == PACKET_LOOPBACK || |
| 2795 | arp->ar_hrd != htons(ARPHRD_ETHER) || |
| 2796 | arp->ar_pro != htons(ETH_P_IP) || |
| 2797 | arp->ar_pln != 4) |
| 2798 | goto out_unlock; |
| 2799 | |
| 2800 | arp_ptr = (unsigned char *)(arp + 1); |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2801 | arp_ptr += bond->dev->addr_len; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2802 | memcpy(&sip, arp_ptr, 4); |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 2803 | arp_ptr += 4 + bond->dev->addr_len; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2804 | memcpy(&tip, arp_ptr, 4); |
| 2805 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2806 | pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n", |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2807 | bond->dev->name, slave->dev->name, bond_slave_state(slave), |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2808 | bond->params.arp_validate, slave_do_arp_validate(bond, slave), |
| 2809 | &sip, &tip); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2810 | |
| 2811 | /* |
| 2812 | * Backup slaves won't see the ARP reply, but do come through |
| 2813 | * here for each ARP probe (so we swap the sip/tip to validate |
| 2814 | * the probe). In a "redundant switch, common router" type of |
| 2815 | * configuration, the ARP probe will (hopefully) travel from |
| 2816 | * the active, through one switch, the router, then the other |
| 2817 | * switch before reaching the backup. |
| 2818 | */ |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2819 | if (bond_is_active_slave(slave)) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2820 | bond_validate_arp(bond, slave, sip, tip); |
| 2821 | else |
| 2822 | bond_validate_arp(bond, slave, tip, sip); |
| 2823 | |
| 2824 | out_unlock: |
| 2825 | read_unlock(&bond->lock); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | /* |
| 2829 | * this function is called regularly to monitor each slave's link |
| 2830 | * ensuring that traffic is being sent and received when arp monitoring |
| 2831 | * is used in load-balancing mode. if the adapter has been dormant, then an |
| 2832 | * arp is transmitted to generate traffic. see activebackup_arp_monitor for |
| 2833 | * arp monitoring in active backup mode. |
| 2834 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2835 | void bond_loadbalance_arp_mon(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2836 | { |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2837 | struct bonding *bond = container_of(work, struct bonding, |
| 2838 | arp_work.work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | struct slave *slave, *oldcurrent; |
| 2840 | int do_failover = 0; |
| 2841 | int delta_in_ticks; |
| 2842 | int i; |
| 2843 | |
| 2844 | read_lock(&bond->lock); |
| 2845 | |
Jay Vosburgh | 5ce0da8 | 2008-05-17 21:10:07 -0700 | [diff] [blame] | 2846 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2848 | if (bond->kill_timers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2851 | if (bond->slave_cnt == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | goto re_arm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | |
| 2854 | read_lock(&bond->curr_slave_lock); |
| 2855 | oldcurrent = bond->curr_active_slave; |
| 2856 | read_unlock(&bond->curr_slave_lock); |
| 2857 | |
| 2858 | /* see if any of the previous devices are up now (i.e. they have |
| 2859 | * xmt and rcv traffic). the curr_active_slave does not come into |
| 2860 | * the picture unless it is null. also, slave->jiffies is not needed |
| 2861 | * here because we send an arp on each slave and give a slave as |
| 2862 | * long as it needs to get the tx/rx within the delta. |
| 2863 | * TODO: what about up/down delay in arp mode? it wasn't here before |
| 2864 | * so it can wait |
| 2865 | */ |
| 2866 | bond_for_each_slave(bond, slave, i) { |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2867 | unsigned long trans_start = dev_trans_start(slave->dev); |
| 2868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | if (slave->link != BOND_LINK_UP) { |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2870 | if (time_in_range(jiffies, |
| 2871 | trans_start - delta_in_ticks, |
| 2872 | trans_start + delta_in_ticks) && |
| 2873 | time_in_range(jiffies, |
| 2874 | slave->dev->last_rx - delta_in_ticks, |
| 2875 | slave->dev->last_rx + delta_in_ticks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | |
| 2877 | slave->link = BOND_LINK_UP; |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2878 | bond_set_active_slave(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | |
| 2880 | /* primary_slave has no meaning in round-robin |
| 2881 | * mode. the window of a slave being up and |
| 2882 | * curr_active_slave being null after enslaving |
| 2883 | * is closed. |
| 2884 | */ |
| 2885 | if (!oldcurrent) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2886 | pr_info("%s: link status definitely up for interface %s, ", |
| 2887 | bond->dev->name, |
| 2888 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | do_failover = 1; |
| 2890 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2891 | pr_info("%s: interface %s is now up\n", |
| 2892 | bond->dev->name, |
| 2893 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | } |
| 2895 | } |
| 2896 | } else { |
| 2897 | /* slave->link == BOND_LINK_UP */ |
| 2898 | |
| 2899 | /* not all switches will respond to an arp request |
| 2900 | * when the source ip is 0, so don't take the link down |
| 2901 | * if we don't know our ip yet |
| 2902 | */ |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2903 | if (!time_in_range(jiffies, |
| 2904 | trans_start - delta_in_ticks, |
| 2905 | trans_start + 2 * delta_in_ticks) || |
| 2906 | !time_in_range(jiffies, |
| 2907 | slave->dev->last_rx - delta_in_ticks, |
| 2908 | slave->dev->last_rx + 2 * delta_in_ticks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | |
| 2910 | slave->link = BOND_LINK_DOWN; |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 2911 | bond_set_backup_slave(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2913 | if (slave->link_failure_count < UINT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | slave->link_failure_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2916 | pr_info("%s: interface %s is now down.\n", |
| 2917 | bond->dev->name, |
| 2918 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2920 | if (slave == oldcurrent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2921 | do_failover = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | /* note: if switch is in round-robin mode, all links |
| 2926 | * must tx arp to ensure all links rx an arp - otherwise |
| 2927 | * links may oscillate or not come up at all; if switch is |
| 2928 | * in something like xor mode, there is nothing we can |
| 2929 | * do - all replies will be rx'ed on same link causing slaves |
| 2930 | * to be unstable during low/no traffic periods |
| 2931 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2932 | if (IS_UP(slave->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | bond_arp_send_all(bond, slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | if (do_failover) { |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2937 | block_netpoll_tx(); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2938 | write_lock_bh(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | |
| 2940 | bond_select_active_slave(bond); |
| 2941 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2942 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2943 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | re_arm: |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2947 | if (bond->params.arp_interval) |
| 2948 | queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | out: |
| 2950 | read_unlock(&bond->lock); |
| 2951 | } |
| 2952 | |
| 2953 | /* |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2954 | * Called to inspect slaves for active-backup mode ARP monitor link state |
| 2955 | * changes. Sets new_link in slaves to specify what action should take |
| 2956 | * place for the slave. Returns 0 if no changes are found, >0 if changes |
| 2957 | * to link states must be committed. |
| 2958 | * |
| 2959 | * Called with bond->lock held for read. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | */ |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2961 | static int bond_ab_arp_inspect(struct bonding *bond, int delta_in_ticks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | struct slave *slave; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2964 | int i, commit = 0; |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2965 | unsigned long trans_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | bond_for_each_slave(bond, slave, i) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2968 | slave->new_link = BOND_LINK_NOCHANGE; |
| 2969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | if (slave->link != BOND_LINK_UP) { |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2971 | if (time_in_range(jiffies, |
| 2972 | slave_last_rx(bond, slave) - delta_in_ticks, |
| 2973 | slave_last_rx(bond, slave) + delta_in_ticks)) { |
| 2974 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2975 | slave->new_link = BOND_LINK_UP; |
| 2976 | commit++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2979 | continue; |
| 2980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2982 | /* |
| 2983 | * Give slaves 2*delta after being enslaved or made |
| 2984 | * active. This avoids bouncing, as the last receive |
| 2985 | * times need a full ARP monitor cycle to be updated. |
| 2986 | */ |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2987 | if (time_in_range(jiffies, |
| 2988 | slave->jiffies - delta_in_ticks, |
| 2989 | slave->jiffies + 2 * delta_in_ticks)) |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2990 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2992 | /* |
| 2993 | * Backup slave is down if: |
| 2994 | * - No current_arp_slave AND |
| 2995 | * - more than 3*delta since last receive AND |
| 2996 | * - the bond has an IP address |
| 2997 | * |
| 2998 | * Note: a non-null current_arp_slave indicates |
| 2999 | * the curr_active_slave went down and we are |
| 3000 | * searching for a new one; under this condition |
| 3001 | * we only take the curr_active_slave down - this |
| 3002 | * gives each slave a chance to tx/rx traffic |
| 3003 | * before being taken out |
| 3004 | */ |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 3005 | if (!bond_is_active_slave(slave) && |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3006 | !bond->current_arp_slave && |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3007 | !time_in_range(jiffies, |
| 3008 | slave_last_rx(bond, slave) - delta_in_ticks, |
| 3009 | slave_last_rx(bond, slave) + 3 * delta_in_ticks)) { |
| 3010 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3011 | slave->new_link = BOND_LINK_DOWN; |
| 3012 | commit++; |
| 3013 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3015 | /* |
| 3016 | * Active slave is down if: |
| 3017 | * - more than 2*delta since transmitting OR |
| 3018 | * - (more than 2*delta since receive AND |
| 3019 | * the bond has an IP address) |
| 3020 | */ |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3021 | trans_start = dev_trans_start(slave->dev); |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 3022 | if (bond_is_active_slave(slave) && |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3023 | (!time_in_range(jiffies, |
| 3024 | trans_start - delta_in_ticks, |
| 3025 | trans_start + 2 * delta_in_ticks) || |
| 3026 | !time_in_range(jiffies, |
| 3027 | slave_last_rx(bond, slave) - delta_in_ticks, |
| 3028 | slave_last_rx(bond, slave) + 2 * delta_in_ticks))) { |
| 3029 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3030 | slave->new_link = BOND_LINK_DOWN; |
| 3031 | commit++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3035 | return commit; |
| 3036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3038 | /* |
| 3039 | * Called to commit link state changes noted by inspection step of |
| 3040 | * active-backup mode ARP monitor. |
| 3041 | * |
| 3042 | * Called with RTNL and bond->lock for read. |
| 3043 | */ |
| 3044 | static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks) |
| 3045 | { |
| 3046 | struct slave *slave; |
| 3047 | int i; |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3048 | unsigned long trans_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3050 | bond_for_each_slave(bond, slave, i) { |
| 3051 | switch (slave->new_link) { |
| 3052 | case BOND_LINK_NOCHANGE: |
| 3053 | continue; |
| 3054 | |
| 3055 | case BOND_LINK_UP: |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3056 | trans_start = dev_trans_start(slave->dev); |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3057 | if ((!bond->curr_active_slave && |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3058 | time_in_range(jiffies, |
| 3059 | trans_start - delta_in_ticks, |
| 3060 | trans_start + delta_in_ticks)) || |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3061 | bond->curr_active_slave != slave) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3062 | slave->link = BOND_LINK_UP; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3063 | bond->current_arp_slave = NULL; |
| 3064 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3065 | pr_info("%s: link status definitely up for interface %s.\n", |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3066 | bond->dev->name, slave->dev->name); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3067 | |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3068 | if (!bond->curr_active_slave || |
| 3069 | (slave == bond->primary_slave)) |
| 3070 | goto do_failover; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3071 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3074 | continue; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3075 | |
| 3076 | case BOND_LINK_DOWN: |
| 3077 | if (slave->link_failure_count < UINT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | slave->link_failure_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3080 | slave->link = BOND_LINK_DOWN; |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3081 | bond_set_slave_inactive_flags(slave); |
| 3082 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3083 | pr_info("%s: link status definitely down for interface %s, disabling it\n", |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3084 | bond->dev->name, slave->dev->name); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3085 | |
| 3086 | if (slave == bond->curr_active_slave) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3087 | bond->current_arp_slave = NULL; |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3088 | goto do_failover; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3089 | } |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3090 | |
| 3091 | continue; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3092 | |
| 3093 | default: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3094 | pr_err("%s: impossible: new_link %d on slave %s\n", |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3095 | bond->dev->name, slave->new_link, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | slave->dev->name); |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3097 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3099 | |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3100 | do_failover: |
| 3101 | ASSERT_RTNL(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 3102 | block_netpoll_tx(); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3103 | write_lock_bh(&bond->curr_slave_lock); |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3104 | bond_select_active_slave(bond); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3105 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 3106 | unblock_netpoll_tx(); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
| 3109 | bond_set_carrier(bond); |
| 3110 | } |
| 3111 | |
| 3112 | /* |
| 3113 | * Send ARP probes for active-backup mode ARP monitor. |
| 3114 | * |
| 3115 | * Called with bond->lock held for read. |
| 3116 | */ |
| 3117 | static void bond_ab_arp_probe(struct bonding *bond) |
| 3118 | { |
| 3119 | struct slave *slave; |
| 3120 | int i; |
| 3121 | |
| 3122 | read_lock(&bond->curr_slave_lock); |
| 3123 | |
| 3124 | if (bond->current_arp_slave && bond->curr_active_slave) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3125 | pr_info("PROBE: c_arp %s && cas %s BAD\n", |
| 3126 | bond->current_arp_slave->dev->name, |
| 3127 | bond->curr_active_slave->dev->name); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3128 | |
| 3129 | if (bond->curr_active_slave) { |
| 3130 | bond_arp_send_all(bond, bond->curr_active_slave); |
| 3131 | read_unlock(&bond->curr_slave_lock); |
| 3132 | return; |
| 3133 | } |
| 3134 | |
| 3135 | read_unlock(&bond->curr_slave_lock); |
| 3136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | /* if we don't have a curr_active_slave, search for the next available |
| 3138 | * backup slave from the current_arp_slave and make it the candidate |
| 3139 | * for becoming the curr_active_slave |
| 3140 | */ |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3141 | |
| 3142 | if (!bond->current_arp_slave) { |
| 3143 | bond->current_arp_slave = bond->first_slave; |
| 3144 | if (!bond->current_arp_slave) |
| 3145 | return; |
| 3146 | } |
| 3147 | |
| 3148 | bond_set_slave_inactive_flags(bond->current_arp_slave); |
| 3149 | |
| 3150 | /* search for next candidate */ |
| 3151 | bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave->next) { |
| 3152 | if (IS_UP(slave->dev)) { |
| 3153 | slave->link = BOND_LINK_BACK; |
| 3154 | bond_set_slave_active_flags(slave); |
| 3155 | bond_arp_send_all(bond, slave); |
| 3156 | slave->jiffies = jiffies; |
| 3157 | bond->current_arp_slave = slave; |
| 3158 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3161 | /* if the link state is up at this point, we |
| 3162 | * mark it down - this can happen if we have |
| 3163 | * simultaneous link failures and |
| 3164 | * reselect_active_interface doesn't make this |
| 3165 | * one the current slave so it is still marked |
| 3166 | * up when it is actually down |
| 3167 | */ |
| 3168 | if (slave->link == BOND_LINK_UP) { |
| 3169 | slave->link = BOND_LINK_DOWN; |
| 3170 | if (slave->link_failure_count < UINT_MAX) |
| 3171 | slave->link_failure_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3173 | bond_set_slave_inactive_flags(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3175 | pr_info("%s: backup interface %s is now down.\n", |
| 3176 | bond->dev->name, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | } |
| 3178 | } |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | void bond_activebackup_arp_mon(struct work_struct *work) |
| 3182 | { |
| 3183 | struct bonding *bond = container_of(work, struct bonding, |
| 3184 | arp_work.work); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 3185 | bool should_notify_peers = false; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3186 | int delta_in_ticks; |
| 3187 | |
| 3188 | read_lock(&bond->lock); |
| 3189 | |
| 3190 | if (bond->kill_timers) |
| 3191 | goto out; |
| 3192 | |
| 3193 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
| 3194 | |
| 3195 | if (bond->slave_cnt == 0) |
| 3196 | goto re_arm; |
| 3197 | |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 3198 | should_notify_peers = bond_should_notify_peers(bond); |
| 3199 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3200 | if (bond_ab_arp_inspect(bond, delta_in_ticks)) { |
| 3201 | read_unlock(&bond->lock); |
| 3202 | rtnl_lock(); |
| 3203 | read_lock(&bond->lock); |
| 3204 | |
| 3205 | bond_ab_arp_commit(bond, delta_in_ticks); |
| 3206 | |
| 3207 | read_unlock(&bond->lock); |
| 3208 | rtnl_unlock(); |
| 3209 | read_lock(&bond->lock); |
| 3210 | } |
| 3211 | |
| 3212 | bond_ab_arp_probe(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | |
| 3214 | re_arm: |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3215 | if (bond->params.arp_interval) |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3216 | queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | out: |
| 3218 | read_unlock(&bond->lock); |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 3219 | |
| 3220 | if (should_notify_peers) { |
| 3221 | rtnl_lock(); |
| 3222 | netdev_bonding_change(bond->dev, NETDEV_NOTIFY_PEERS); |
| 3223 | rtnl_unlock(); |
| 3224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | /*-------------------------- netdev event handling --------------------------*/ |
| 3228 | |
| 3229 | /* |
| 3230 | * Change device name |
| 3231 | */ |
| 3232 | static int bond_event_changename(struct bonding *bond) |
| 3233 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | bond_remove_proc_entry(bond); |
| 3235 | bond_create_proc_entry(bond); |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 3236 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 3237 | bond_debug_reregister(bond); |
| 3238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | return NOTIFY_DONE; |
| 3240 | } |
| 3241 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3242 | static int bond_master_netdev_event(unsigned long event, |
| 3243 | struct net_device *bond_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3245 | struct bonding *event_bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | |
| 3247 | switch (event) { |
| 3248 | case NETDEV_CHANGENAME: |
| 3249 | return bond_event_changename(event_bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | default: |
| 3251 | break; |
| 3252 | } |
| 3253 | |
| 3254 | return NOTIFY_DONE; |
| 3255 | } |
| 3256 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3257 | static int bond_slave_netdev_event(unsigned long event, |
| 3258 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | { |
| 3260 | struct net_device *bond_dev = slave_dev->master; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3261 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3262 | |
| 3263 | switch (event) { |
| 3264 | case NETDEV_UNREGISTER: |
| 3265 | if (bond_dev) { |
Jay Vosburgh | 1284cd3 | 2007-10-15 16:44:27 -0700 | [diff] [blame] | 3266 | if (bond->setup_by_slave) |
| 3267 | bond_release_and_destroy(bond_dev, slave_dev); |
| 3268 | else |
| 3269 | bond_release(bond_dev, slave_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | } |
| 3271 | break; |
| 3272 | case NETDEV_CHANGE: |
Jay Vosburgh | 17d0450 | 2009-03-18 18:38:25 -0700 | [diff] [blame] | 3273 | if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) { |
| 3274 | struct slave *slave; |
| 3275 | |
| 3276 | slave = bond_get_slave_by_dev(bond, slave_dev); |
| 3277 | if (slave) { |
David Decotigny | 5d30530 | 2011-04-13 15:22:31 +0000 | [diff] [blame] | 3278 | u32 old_speed = slave->speed; |
David Decotigny | 65cce19 | 2011-04-13 15:22:30 +0000 | [diff] [blame] | 3279 | u8 old_duplex = slave->duplex; |
Jay Vosburgh | 17d0450 | 2009-03-18 18:38:25 -0700 | [diff] [blame] | 3280 | |
| 3281 | bond_update_speed_duplex(slave); |
| 3282 | |
| 3283 | if (bond_is_lb(bond)) |
| 3284 | break; |
| 3285 | |
| 3286 | if (old_speed != slave->speed) |
| 3287 | bond_3ad_adapter_speed_changed(slave); |
| 3288 | if (old_duplex != slave->duplex) |
| 3289 | bond_3ad_adapter_duplex_changed(slave); |
| 3290 | } |
| 3291 | } |
| 3292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | break; |
| 3294 | case NETDEV_DOWN: |
| 3295 | /* |
| 3296 | * ... Or is it this? |
| 3297 | */ |
| 3298 | break; |
| 3299 | case NETDEV_CHANGEMTU: |
| 3300 | /* |
| 3301 | * TODO: Should slaves be allowed to |
| 3302 | * independently alter their MTU? For |
| 3303 | * an active-backup bond, slaves need |
| 3304 | * not be the same type of device, so |
| 3305 | * MTUs may vary. For other modes, |
| 3306 | * slaves arguably should have the |
| 3307 | * same MTUs. To do this, we'd need to |
| 3308 | * take over the slave's change_mtu |
| 3309 | * function for the duration of their |
| 3310 | * servitude. |
| 3311 | */ |
| 3312 | break; |
| 3313 | case NETDEV_CHANGENAME: |
| 3314 | /* |
| 3315 | * TODO: handle changing the primary's name |
| 3316 | */ |
| 3317 | break; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 3318 | case NETDEV_FEAT_CHANGE: |
| 3319 | bond_compute_features(bond); |
| 3320 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3321 | default: |
| 3322 | break; |
| 3323 | } |
| 3324 | |
| 3325 | return NOTIFY_DONE; |
| 3326 | } |
| 3327 | |
| 3328 | /* |
| 3329 | * bond_netdev_event: handle netdev notifier chain events. |
| 3330 | * |
| 3331 | * This function receives events for the netdev chain. The caller (an |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 3332 | * ioctl handler calling blocking_notifier_call_chain) holds the necessary |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | * locks for us to safely manipulate the slave devices (RTNL lock, |
| 3334 | * dev_probe_lock). |
| 3335 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3336 | static int bond_netdev_event(struct notifier_block *this, |
| 3337 | unsigned long event, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3338 | { |
| 3339 | struct net_device *event_dev = (struct net_device *)ptr; |
| 3340 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3341 | pr_debug("event_dev: %s, event: %lx\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3342 | event_dev ? event_dev->name : "None", |
| 3343 | event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | |
Jay Vosburgh | 0b680e7 | 2006-09-22 21:54:10 -0700 | [diff] [blame] | 3345 | if (!(event_dev->priv_flags & IFF_BONDING)) |
| 3346 | return NOTIFY_DONE; |
| 3347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3348 | if (event_dev->flags & IFF_MASTER) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3349 | pr_debug("IFF_MASTER\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | return bond_master_netdev_event(event, event_dev); |
| 3351 | } |
| 3352 | |
| 3353 | if (event_dev->flags & IFF_SLAVE) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3354 | pr_debug("IFF_SLAVE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | return bond_slave_netdev_event(event, event_dev); |
| 3356 | } |
| 3357 | |
| 3358 | return NOTIFY_DONE; |
| 3359 | } |
| 3360 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3361 | /* |
| 3362 | * bond_inetaddr_event: handle inetaddr notifier chain events. |
| 3363 | * |
| 3364 | * We keep track of device IPs primarily to use as source addresses in |
| 3365 | * ARP monitor probes (rather than spewing out broadcasts all the time). |
| 3366 | * |
| 3367 | * We track one IP for the main device (if it has one), plus one per VLAN. |
| 3368 | */ |
| 3369 | static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 3370 | { |
| 3371 | struct in_ifaddr *ifa = ptr; |
| 3372 | struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev; |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3373 | struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id); |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 3374 | struct bonding *bond; |
| 3375 | struct vlan_entry *vlan; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3376 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3377 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3378 | if (bond->dev == event_dev) { |
| 3379 | switch (event) { |
| 3380 | case NETDEV_UP: |
| 3381 | bond->master_ip = ifa->ifa_local; |
| 3382 | return NOTIFY_OK; |
| 3383 | case NETDEV_DOWN: |
| 3384 | bond->master_ip = bond_glean_dev_ip(bond->dev); |
| 3385 | return NOTIFY_OK; |
| 3386 | default: |
| 3387 | return NOTIFY_DONE; |
| 3388 | } |
| 3389 | } |
| 3390 | |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 3391 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 3392 | if (!bond->vlgrp) |
| 3393 | continue; |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 3394 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3395 | if (vlan_dev == event_dev) { |
| 3396 | switch (event) { |
| 3397 | case NETDEV_UP: |
| 3398 | vlan->vlan_ip = ifa->ifa_local; |
| 3399 | return NOTIFY_OK; |
| 3400 | case NETDEV_DOWN: |
| 3401 | vlan->vlan_ip = |
| 3402 | bond_glean_dev_ip(vlan_dev); |
| 3403 | return NOTIFY_OK; |
| 3404 | default: |
| 3405 | return NOTIFY_DONE; |
| 3406 | } |
| 3407 | } |
| 3408 | } |
| 3409 | } |
| 3410 | return NOTIFY_DONE; |
| 3411 | } |
| 3412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | static struct notifier_block bond_netdev_notifier = { |
| 3414 | .notifier_call = bond_netdev_event, |
| 3415 | }; |
| 3416 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3417 | static struct notifier_block bond_inetaddr_notifier = { |
| 3418 | .notifier_call = bond_inetaddr_event, |
| 3419 | }; |
| 3420 | |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3421 | /*---------------------------- Hashing Policies -----------------------------*/ |
| 3422 | |
| 3423 | /* |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3424 | * Hash for the output device based upon layer 2 and layer 3 data. If |
| 3425 | * the packet is not IP mimic bond_xmit_hash_policy_l2() |
| 3426 | */ |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 3427 | static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count) |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3428 | { |
| 3429 | struct ethhdr *data = (struct ethhdr *)skb->data; |
| 3430 | struct iphdr *iph = ip_hdr(skb); |
| 3431 | |
Brian Haley | f14c4e4 | 2008-09-02 10:08:08 -0400 | [diff] [blame] | 3432 | if (skb->protocol == htons(ETH_P_IP)) { |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3433 | return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^ |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3434 | (data->h_dest[5] ^ data->h_source[5])) % count; |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3435 | } |
| 3436 | |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3437 | return (data->h_dest[5] ^ data->h_source[5]) % count; |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3438 | } |
| 3439 | |
| 3440 | /* |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 3441 | * Hash for the output device based upon layer 3 and layer 4 data. If |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3442 | * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is |
| 3443 | * altogether not IP, mimic bond_xmit_hash_policy_l2() |
| 3444 | */ |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 3445 | static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count) |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3446 | { |
| 3447 | struct ethhdr *data = (struct ethhdr *)skb->data; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 3448 | struct iphdr *iph = ip_hdr(skb); |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 3449 | __be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl); |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3450 | int layer4_xor = 0; |
| 3451 | |
Brian Haley | f14c4e4 | 2008-09-02 10:08:08 -0400 | [diff] [blame] | 3452 | if (skb->protocol == htons(ETH_P_IP)) { |
| 3453 | if (!(iph->frag_off & htons(IP_MF|IP_OFFSET)) && |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3454 | (iph->protocol == IPPROTO_TCP || |
| 3455 | iph->protocol == IPPROTO_UDP)) { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 3456 | layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1))); |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3457 | } |
| 3458 | return (layer4_xor ^ |
| 3459 | ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count; |
| 3460 | |
| 3461 | } |
| 3462 | |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3463 | return (data->h_dest[5] ^ data->h_source[5]) % count; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | /* |
| 3467 | * Hash for the output device based upon layer 2 data |
| 3468 | */ |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 3469 | static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count) |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3470 | { |
| 3471 | struct ethhdr *data = (struct ethhdr *)skb->data; |
| 3472 | |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3473 | return (data->h_dest[5] ^ data->h_source[5]) % count; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3474 | } |
| 3475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | /*-------------------------- Device entry points ----------------------------*/ |
| 3477 | |
| 3478 | static int bond_open(struct net_device *bond_dev) |
| 3479 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3480 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3481 | |
| 3482 | bond->kill_timers = 0; |
| 3483 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 3484 | INIT_DELAYED_WORK(&bond->mcast_work, bond_resend_igmp_join_requests_delayed); |
| 3485 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 3486 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | /* bond_alb_initialize must be called before the timer |
| 3488 | * is started. |
| 3489 | */ |
| 3490 | if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) { |
| 3491 | /* something went wrong - fail the open operation */ |
stephen hemminger | b473946 | 2010-01-25 23:34:15 +0000 | [diff] [blame] | 3492 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | } |
| 3494 | |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3495 | INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor); |
| 3496 | queue_delayed_work(bond->wq, &bond->alb_work, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | if (bond->params.miimon) { /* link check interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3500 | INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor); |
| 3501 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
| 3504 | if (bond->params.arp_interval) { /* arp interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3505 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) |
| 3506 | INIT_DELAYED_WORK(&bond->arp_work, |
| 3507 | bond_activebackup_arp_mon); |
| 3508 | else |
| 3509 | INIT_DELAYED_WORK(&bond->arp_work, |
| 3510 | bond_loadbalance_arp_mon); |
| 3511 | |
| 3512 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3513 | if (bond->params.arp_validate) |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 3514 | bond->recv_probe = bond_arp_rcv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | if (bond->params.mode == BOND_MODE_8023AD) { |
Adrian Bunk | a40745f | 2007-10-24 18:27:43 +0200 | [diff] [blame] | 3518 | INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler); |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3519 | queue_delayed_work(bond->wq, &bond->ad_work, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3520 | /* register to receive LACPDUs */ |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 3521 | bond->recv_probe = bond_3ad_lacpdu_recv; |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 3522 | bond_3ad_initiate_agg_selection(bond, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | return 0; |
| 3526 | } |
| 3527 | |
| 3528 | static int bond_close(struct net_device *bond_dev) |
| 3529 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3530 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | write_lock_bh(&bond->lock); |
| 3533 | |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 3534 | bond->send_peer_notif = 0; |
| 3535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | /* signal timers not to re-arm */ |
| 3537 | bond->kill_timers = 1; |
| 3538 | |
| 3539 | write_unlock_bh(&bond->lock); |
| 3540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | if (bond->params.miimon) { /* link check interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3542 | cancel_delayed_work(&bond->mii_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | if (bond->params.arp_interval) { /* arp interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3546 | cancel_delayed_work(&bond->arp_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | switch (bond->params.mode) { |
| 3550 | case BOND_MODE_8023AD: |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3551 | cancel_delayed_work(&bond->ad_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3552 | break; |
| 3553 | case BOND_MODE_TLB: |
| 3554 | case BOND_MODE_ALB: |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3555 | cancel_delayed_work(&bond->alb_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | break; |
| 3557 | default: |
| 3558 | break; |
| 3559 | } |
| 3560 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 3561 | if (delayed_work_pending(&bond->mcast_work)) |
| 3562 | cancel_delayed_work(&bond->mcast_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 3564 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | /* Must be called only after all |
| 3566 | * slaves have been released |
| 3567 | */ |
| 3568 | bond_alb_deinitialize(bond); |
| 3569 | } |
Jiri Pirko | 3aba891 | 2011-04-19 03:48:16 +0000 | [diff] [blame] | 3570 | bond->recv_probe = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | |
| 3572 | return 0; |
| 3573 | } |
| 3574 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3575 | static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev, |
| 3576 | struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3578 | struct bonding *bond = netdev_priv(bond_dev); |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3579 | struct rtnl_link_stats64 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | struct slave *slave; |
| 3581 | int i; |
| 3582 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3583 | memset(stats, 0, sizeof(*stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | |
| 3585 | read_lock_bh(&bond->lock); |
| 3586 | |
| 3587 | bond_for_each_slave(bond, slave, i) { |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 3588 | const struct rtnl_link_stats64 *sstats = |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3589 | dev_get_stats(slave->dev, &temp); |
Stephen Hemminger | eeda3fd | 2008-11-19 21:40:23 -0800 | [diff] [blame] | 3590 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3591 | stats->rx_packets += sstats->rx_packets; |
| 3592 | stats->rx_bytes += sstats->rx_bytes; |
| 3593 | stats->rx_errors += sstats->rx_errors; |
| 3594 | stats->rx_dropped += sstats->rx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3596 | stats->tx_packets += sstats->tx_packets; |
| 3597 | stats->tx_bytes += sstats->tx_bytes; |
| 3598 | stats->tx_errors += sstats->tx_errors; |
| 3599 | stats->tx_dropped += sstats->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3601 | stats->multicast += sstats->multicast; |
| 3602 | stats->collisions += sstats->collisions; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3604 | stats->rx_length_errors += sstats->rx_length_errors; |
| 3605 | stats->rx_over_errors += sstats->rx_over_errors; |
| 3606 | stats->rx_crc_errors += sstats->rx_crc_errors; |
| 3607 | stats->rx_frame_errors += sstats->rx_frame_errors; |
| 3608 | stats->rx_fifo_errors += sstats->rx_fifo_errors; |
| 3609 | stats->rx_missed_errors += sstats->rx_missed_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3611 | stats->tx_aborted_errors += sstats->tx_aborted_errors; |
| 3612 | stats->tx_carrier_errors += sstats->tx_carrier_errors; |
| 3613 | stats->tx_fifo_errors += sstats->tx_fifo_errors; |
| 3614 | stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors; |
| 3615 | stats->tx_window_errors += sstats->tx_window_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | read_unlock_bh(&bond->lock); |
| 3619 | |
| 3620 | return stats; |
| 3621 | } |
| 3622 | |
| 3623 | static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd) |
| 3624 | { |
| 3625 | struct net_device *slave_dev = NULL; |
| 3626 | struct ifbond k_binfo; |
| 3627 | struct ifbond __user *u_binfo = NULL; |
| 3628 | struct ifslave k_sinfo; |
| 3629 | struct ifslave __user *u_sinfo = NULL; |
| 3630 | struct mii_ioctl_data *mii = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3631 | int res = 0; |
| 3632 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3633 | pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | |
| 3635 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | case SIOCGMIIPHY: |
| 3637 | mii = if_mii(ifr); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3638 | if (!mii) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | return -EINVAL; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | mii->phy_id = 0; |
| 3642 | /* Fall Through */ |
| 3643 | case SIOCGMIIREG: |
| 3644 | /* |
| 3645 | * We do this again just in case we were called by SIOCGMIIREG |
| 3646 | * instead of SIOCGMIIPHY. |
| 3647 | */ |
| 3648 | mii = if_mii(ifr); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3649 | if (!mii) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | return -EINVAL; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | |
| 3653 | if (mii->reg_num == 1) { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3654 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | mii->val_out = 0; |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 3656 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | read_lock(&bond->curr_slave_lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3658 | if (netif_carrier_ok(bond->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | mii->val_out = BMSR_LSTATUS; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | read_unlock(&bond->curr_slave_lock); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 3662 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | return 0; |
| 3666 | case BOND_INFO_QUERY_OLD: |
| 3667 | case SIOCBONDINFOQUERY: |
| 3668 | u_binfo = (struct ifbond __user *)ifr->ifr_data; |
| 3669 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3670 | if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | |
| 3673 | res = bond_info_query(bond_dev, &k_binfo); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3674 | if (res == 0 && |
| 3675 | copy_to_user(u_binfo, &k_binfo, sizeof(ifbond))) |
| 3676 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | |
| 3678 | return res; |
| 3679 | case BOND_SLAVE_INFO_QUERY_OLD: |
| 3680 | case SIOCBONDSLAVEINFOQUERY: |
| 3681 | u_sinfo = (struct ifslave __user *)ifr->ifr_data; |
| 3682 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3683 | if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
| 3686 | res = bond_slave_info_query(bond_dev, &k_sinfo); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3687 | if (res == 0 && |
| 3688 | copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave))) |
| 3689 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | |
| 3691 | return res; |
| 3692 | default: |
| 3693 | /* Go on */ |
| 3694 | break; |
| 3695 | } |
| 3696 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3697 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3700 | slave_dev = dev_get_by_name(dev_net(bond_dev), ifr->ifr_slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3702 | pr_debug("slave_dev=%p:\n", slave_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3704 | if (!slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | res = -ENODEV; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3706 | else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3707 | pr_debug("slave_dev->name=%s:\n", slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | switch (cmd) { |
| 3709 | case BOND_ENSLAVE_OLD: |
| 3710 | case SIOCBONDENSLAVE: |
| 3711 | res = bond_enslave(bond_dev, slave_dev); |
| 3712 | break; |
| 3713 | case BOND_RELEASE_OLD: |
| 3714 | case SIOCBONDRELEASE: |
| 3715 | res = bond_release(bond_dev, slave_dev); |
| 3716 | break; |
| 3717 | case BOND_SETHWADDR_OLD: |
| 3718 | case SIOCBONDSETHWADDR: |
| 3719 | res = bond_sethwaddr(bond_dev, slave_dev); |
| 3720 | break; |
| 3721 | case BOND_CHANGE_ACTIVE_OLD: |
| 3722 | case SIOCBONDCHANGEACTIVE: |
| 3723 | res = bond_ioctl_change_active(bond_dev, slave_dev); |
| 3724 | break; |
| 3725 | default: |
| 3726 | res = -EOPNOTSUPP; |
| 3727 | } |
| 3728 | |
| 3729 | dev_put(slave_dev); |
| 3730 | } |
| 3731 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3732 | return res; |
| 3733 | } |
| 3734 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3735 | static bool bond_addr_in_mc_list(unsigned char *addr, |
| 3736 | struct netdev_hw_addr_list *list, |
| 3737 | int addrlen) |
| 3738 | { |
| 3739 | struct netdev_hw_addr *ha; |
| 3740 | |
| 3741 | netdev_hw_addr_list_for_each(ha, list) |
| 3742 | if (!memcmp(ha->addr, addr, addrlen)) |
| 3743 | return true; |
| 3744 | |
| 3745 | return false; |
| 3746 | } |
| 3747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | static void bond_set_multicast_list(struct net_device *bond_dev) |
| 3749 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3750 | struct bonding *bond = netdev_priv(bond_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3751 | struct netdev_hw_addr *ha; |
| 3752 | bool found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3754 | /* |
| 3755 | * Do promisc before checking multicast_mode |
| 3756 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3757 | if ((bond_dev->flags & IFF_PROMISC) && !(bond->flags & IFF_PROMISC)) |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 3758 | /* |
| 3759 | * FIXME: Need to handle the error when one of the multi-slaves |
| 3760 | * encounters error. |
| 3761 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | bond_set_promiscuity(bond, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3764 | |
| 3765 | if (!(bond_dev->flags & IFF_PROMISC) && (bond->flags & IFF_PROMISC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | bond_set_promiscuity(bond, -1); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3767 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | |
| 3769 | /* set allmulti flag to slaves */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3770 | if ((bond_dev->flags & IFF_ALLMULTI) && !(bond->flags & IFF_ALLMULTI)) |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 3771 | /* |
| 3772 | * FIXME: Need to handle the error when one of the multi-slaves |
| 3773 | * encounters error. |
| 3774 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | bond_set_allmulti(bond, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3777 | |
| 3778 | if (!(bond_dev->flags & IFF_ALLMULTI) && (bond->flags & IFF_ALLMULTI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | bond_set_allmulti(bond, -1); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
Jay Vosburgh | 80ee5ad | 2008-01-29 18:07:44 -0800 | [diff] [blame] | 3782 | read_lock(&bond->lock); |
| 3783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | bond->flags = bond_dev->flags; |
| 3785 | |
| 3786 | /* looking for addresses to add to slaves' mc list */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3787 | netdev_for_each_mc_addr(ha, bond_dev) { |
| 3788 | found = bond_addr_in_mc_list(ha->addr, &bond->mc_list, |
| 3789 | bond_dev->addr_len); |
| 3790 | if (!found) |
| 3791 | bond_mc_add(bond, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | /* looking for addresses to delete from slaves' list */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3795 | netdev_hw_addr_list_for_each(ha, &bond->mc_list) { |
| 3796 | found = bond_addr_in_mc_list(ha->addr, &bond_dev->mc, |
| 3797 | bond_dev->addr_len); |
| 3798 | if (!found) |
| 3799 | bond_mc_del(bond, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | /* save master's multicast list */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3803 | __hw_addr_flush(&bond->mc_list); |
| 3804 | __hw_addr_add_multiple(&bond->mc_list, &bond_dev->mc, |
| 3805 | bond_dev->addr_len, NETDEV_HW_ADDR_T_MULTICAST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | |
Jay Vosburgh | 80ee5ad | 2008-01-29 18:07:44 -0800 | [diff] [blame] | 3807 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3810 | static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms) |
| 3811 | { |
| 3812 | struct bonding *bond = netdev_priv(dev); |
| 3813 | struct slave *slave = bond->first_slave; |
| 3814 | |
| 3815 | if (slave) { |
| 3816 | const struct net_device_ops *slave_ops |
| 3817 | = slave->dev->netdev_ops; |
| 3818 | if (slave_ops->ndo_neigh_setup) |
Patrick McHardy | 72e2240 | 2009-03-05 01:57:44 -0800 | [diff] [blame] | 3819 | return slave_ops->ndo_neigh_setup(slave->dev, parms); |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3820 | } |
| 3821 | return 0; |
| 3822 | } |
| 3823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | /* |
| 3825 | * Change the MTU of all of a master's slaves to match the master |
| 3826 | */ |
| 3827 | static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) |
| 3828 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3829 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | struct slave *slave, *stop_at; |
| 3831 | int res = 0; |
| 3832 | int i; |
| 3833 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3834 | pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3835 | (bond_dev ? bond_dev->name : "None"), new_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3836 | |
| 3837 | /* Can't hold bond->lock with bh disabled here since |
| 3838 | * some base drivers panic. On the other hand we can't |
| 3839 | * hold bond->lock without bh disabled because we'll |
| 3840 | * deadlock. The only solution is to rely on the fact |
| 3841 | * that we're under rtnl_lock here, and the slaves |
| 3842 | * list won't change. This doesn't solve the problem |
| 3843 | * of setting the slave's MTU while it is |
| 3844 | * transmitting, but the assumption is that the base |
| 3845 | * driver can handle that. |
| 3846 | * |
| 3847 | * TODO: figure out a way to safely iterate the slaves |
| 3848 | * list, but without holding a lock around the actual |
| 3849 | * call to the base driver. |
| 3850 | */ |
| 3851 | |
| 3852 | bond_for_each_slave(bond, slave, i) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3853 | pr_debug("s %p s->p %p c_m %p\n", |
| 3854 | slave, |
| 3855 | slave->prev, |
| 3856 | slave->dev->netdev_ops->ndo_change_mtu); |
Mitch Williams | e944ef7 | 2005-11-09 10:36:50 -0800 | [diff] [blame] | 3857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3858 | res = dev_set_mtu(slave->dev, new_mtu); |
| 3859 | |
| 3860 | if (res) { |
| 3861 | /* If we failed to set the slave's mtu to the new value |
| 3862 | * we must abort the operation even in ACTIVE_BACKUP |
| 3863 | * mode, because if we allow the backup slaves to have |
| 3864 | * different mtu values than the active slave we'll |
| 3865 | * need to change their mtu when doing a failover. That |
| 3866 | * means changing their mtu from timer context, which |
| 3867 | * is probably not a good idea. |
| 3868 | */ |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3869 | pr_debug("err %d %s\n", res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | goto unwind; |
| 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | bond_dev->mtu = new_mtu; |
| 3875 | |
| 3876 | return 0; |
| 3877 | |
| 3878 | unwind: |
| 3879 | /* unwind from head to the slave that failed */ |
| 3880 | stop_at = slave; |
| 3881 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { |
| 3882 | int tmp_res; |
| 3883 | |
| 3884 | tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu); |
| 3885 | if (tmp_res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3886 | pr_debug("unwind err %d dev %s\n", |
| 3887 | tmp_res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | return res; |
| 3892 | } |
| 3893 | |
| 3894 | /* |
| 3895 | * Change HW address |
| 3896 | * |
| 3897 | * Note that many devices must be down to change the HW address, and |
| 3898 | * downing the master releases all slaves. We can make bonds full of |
| 3899 | * bonding devices to test this, however. |
| 3900 | */ |
| 3901 | static int bond_set_mac_address(struct net_device *bond_dev, void *addr) |
| 3902 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3903 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | struct sockaddr *sa = addr, tmp_sa; |
| 3905 | struct slave *slave, *stop_at; |
| 3906 | int res = 0; |
| 3907 | int i; |
| 3908 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 3909 | if (bond->params.mode == BOND_MODE_ALB) |
| 3910 | return bond_alb_set_mac_address(bond_dev, addr); |
| 3911 | |
| 3912 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3913 | pr_debug("bond=%p, name=%s\n", |
| 3914 | bond, bond_dev ? bond_dev->name : "None"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 3916 | /* |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 3917 | * If fail_over_mac is set to active, do nothing and return |
| 3918 | * success. Returning an error causes ifenslave to fail. |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 3919 | */ |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 3920 | if (bond->params.fail_over_mac == BOND_FOM_ACTIVE) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 3921 | return 0; |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 3922 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3923 | if (!is_valid_ether_addr(sa->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3924 | return -EADDRNOTAVAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | |
| 3926 | /* Can't hold bond->lock with bh disabled here since |
| 3927 | * some base drivers panic. On the other hand we can't |
| 3928 | * hold bond->lock without bh disabled because we'll |
| 3929 | * deadlock. The only solution is to rely on the fact |
| 3930 | * that we're under rtnl_lock here, and the slaves |
| 3931 | * list won't change. This doesn't solve the problem |
| 3932 | * of setting the slave's hw address while it is |
| 3933 | * transmitting, but the assumption is that the base |
| 3934 | * driver can handle that. |
| 3935 | * |
| 3936 | * TODO: figure out a way to safely iterate the slaves |
| 3937 | * list, but without holding a lock around the actual |
| 3938 | * call to the base driver. |
| 3939 | */ |
| 3940 | |
| 3941 | bond_for_each_slave(bond, slave, i) { |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 3942 | const struct net_device_ops *slave_ops = slave->dev->netdev_ops; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3943 | pr_debug("slave %p %s\n", slave, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 3945 | if (slave_ops->ndo_set_mac_address == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | res = -EOPNOTSUPP; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3947 | pr_debug("EOPNOTSUPP %s\n", slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | goto unwind; |
| 3949 | } |
| 3950 | |
| 3951 | res = dev_set_mac_address(slave->dev, addr); |
| 3952 | if (res) { |
| 3953 | /* TODO: consider downing the slave |
| 3954 | * and retry ? |
| 3955 | * User should expect communications |
| 3956 | * breakage anyway until ARP finish |
| 3957 | * updating, so... |
| 3958 | */ |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3959 | pr_debug("err %d %s\n", res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | goto unwind; |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | /* success */ |
| 3965 | memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len); |
| 3966 | return 0; |
| 3967 | |
| 3968 | unwind: |
| 3969 | memcpy(tmp_sa.sa_data, bond_dev->dev_addr, bond_dev->addr_len); |
| 3970 | tmp_sa.sa_family = bond_dev->type; |
| 3971 | |
| 3972 | /* unwind from head to the slave that failed */ |
| 3973 | stop_at = slave; |
| 3974 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { |
| 3975 | int tmp_res; |
| 3976 | |
| 3977 | tmp_res = dev_set_mac_address(slave->dev, &tmp_sa); |
| 3978 | if (tmp_res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3979 | pr_debug("unwind err %d dev %s\n", |
| 3980 | tmp_res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | return res; |
| 3985 | } |
| 3986 | |
| 3987 | static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev) |
| 3988 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3989 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3990 | struct slave *slave, *start_at; |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 3991 | int i, slave_no, res = 1; |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 3992 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 3994 | /* |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 3995 | * Start with the curr_active_slave that joined the bond as the |
| 3996 | * default for sending IGMP traffic. For failover purposes one |
| 3997 | * needs to maintain some consistency for the interface that will |
| 3998 | * send the join/membership reports. The curr_active_slave found |
| 3999 | * will send all of this type of traffic. |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 4000 | */ |
Eric Dumazet | 00ae702 | 2010-03-30 23:08:37 +0000 | [diff] [blame] | 4001 | if ((iph->protocol == IPPROTO_IGMP) && |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 4002 | (skb->protocol == htons(ETH_P_IP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4003 | |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 4004 | read_lock(&bond->curr_slave_lock); |
| 4005 | slave = bond->curr_active_slave; |
| 4006 | read_unlock(&bond->curr_slave_lock); |
| 4007 | |
| 4008 | if (!slave) |
| 4009 | goto out; |
| 4010 | } else { |
| 4011 | /* |
| 4012 | * Concurrent TX may collide on rr_tx_counter; we accept |
| 4013 | * that as being rare enough not to justify using an |
| 4014 | * atomic op here. |
| 4015 | */ |
| 4016 | slave_no = bond->rr_tx_counter++ % bond->slave_cnt; |
| 4017 | |
| 4018 | bond_for_each_slave(bond, slave, i) { |
| 4019 | slave_no--; |
| 4020 | if (slave_no < 0) |
| 4021 | break; |
| 4022 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 4025 | start_at = slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | bond_for_each_slave_from(bond, slave, i, start_at) { |
| 4027 | if (IS_UP(slave->dev) && |
| 4028 | (slave->link == BOND_LINK_UP) && |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 4029 | bond_is_active_slave(slave)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | break; |
| 4032 | } |
| 4033 | } |
| 4034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | out: |
| 4036 | if (res) { |
| 4037 | /* no suitable interface, frame not sent */ |
| 4038 | dev_kfree_skb(skb); |
| 4039 | } |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4040 | |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4041 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
John W. Linville | 075897c | 2005-09-28 17:50:53 -0400 | [diff] [blame] | 4044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | /* |
| 4046 | * in active-backup mode, we know that bond->curr_active_slave is always valid if |
| 4047 | * the bond has a usable interface. |
| 4048 | */ |
| 4049 | static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_dev) |
| 4050 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4051 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | int res = 1; |
| 4053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | read_lock(&bond->curr_slave_lock); |
| 4055 | |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4056 | if (bond->curr_active_slave) |
| 4057 | res = bond_dev_queue_xmit(bond, skb, |
| 4058 | bond->curr_active_slave->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4060 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | /* no suitable interface, frame not sent */ |
| 4062 | dev_kfree_skb(skb); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | read_unlock(&bond->curr_slave_lock); |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4065 | |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4066 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | /* |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4070 | * In bond_xmit_xor() , we determine the output device by using a pre- |
| 4071 | * determined xmit_hash_policy(), If the selected device is not enabled, |
| 4072 | * find the next active slave. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | */ |
| 4074 | static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) |
| 4075 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4076 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | struct slave *slave, *start_at; |
| 4078 | int slave_no; |
| 4079 | int i; |
| 4080 | int res = 1; |
| 4081 | |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 4082 | slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | |
| 4084 | bond_for_each_slave(bond, slave, i) { |
| 4085 | slave_no--; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4086 | if (slave_no < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | start_at = slave; |
| 4091 | |
| 4092 | bond_for_each_slave_from(bond, slave, i, start_at) { |
| 4093 | if (IS_UP(slave->dev) && |
| 4094 | (slave->link == BOND_LINK_UP) && |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 4095 | bond_is_active_slave(slave)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
| 4097 | break; |
| 4098 | } |
| 4099 | } |
| 4100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | if (res) { |
| 4102 | /* no suitable interface, frame not sent */ |
| 4103 | dev_kfree_skb(skb); |
| 4104 | } |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4105 | |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4106 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | /* |
| 4110 | * in broadcast mode, we send everything to all usable interfaces. |
| 4111 | */ |
| 4112 | static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev) |
| 4113 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4114 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | struct slave *slave, *start_at; |
| 4116 | struct net_device *tx_dev = NULL; |
| 4117 | int i; |
| 4118 | int res = 1; |
| 4119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | read_lock(&bond->curr_slave_lock); |
| 4121 | start_at = bond->curr_active_slave; |
| 4122 | read_unlock(&bond->curr_slave_lock); |
| 4123 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4124 | if (!start_at) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4126 | |
| 4127 | bond_for_each_slave_from(bond, slave, i, start_at) { |
| 4128 | if (IS_UP(slave->dev) && |
| 4129 | (slave->link == BOND_LINK_UP) && |
Jiri Pirko | e30bc06 | 2011-03-12 03:14:37 +0000 | [diff] [blame] | 4130 | bond_is_active_slave(slave)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4131 | if (tx_dev) { |
| 4132 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
| 4133 | if (!skb2) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4134 | pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n", |
Mitch Williams | 4e0952c | 2005-11-09 10:34:57 -0800 | [diff] [blame] | 4135 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | continue; |
| 4137 | } |
| 4138 | |
| 4139 | res = bond_dev_queue_xmit(bond, skb2, tx_dev); |
| 4140 | if (res) { |
| 4141 | dev_kfree_skb(skb2); |
| 4142 | continue; |
| 4143 | } |
| 4144 | } |
| 4145 | tx_dev = slave->dev; |
| 4146 | } |
| 4147 | } |
| 4148 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4149 | if (tx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | res = bond_dev_queue_xmit(bond, skb, tx_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4151 | |
| 4152 | out: |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4153 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | /* no suitable interface, frame not sent */ |
| 4155 | dev_kfree_skb(skb); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4157 | /* frame sent to all suitable interfaces */ |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4158 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | /*------------------------- Device initialization ---------------------------*/ |
| 4162 | |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 4163 | static void bond_set_xmit_hash_policy(struct bonding *bond) |
| 4164 | { |
| 4165 | switch (bond->params.xmit_policy) { |
| 4166 | case BOND_XMIT_POLICY_LAYER23: |
| 4167 | bond->xmit_hash_policy = bond_xmit_hash_policy_l23; |
| 4168 | break; |
| 4169 | case BOND_XMIT_POLICY_LAYER34: |
| 4170 | bond->xmit_hash_policy = bond_xmit_hash_policy_l34; |
| 4171 | break; |
| 4172 | case BOND_XMIT_POLICY_LAYER2: |
| 4173 | default: |
| 4174 | bond->xmit_hash_policy = bond_xmit_hash_policy_l2; |
| 4175 | break; |
| 4176 | } |
| 4177 | } |
| 4178 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4179 | /* |
| 4180 | * Lookup the slave that corresponds to a qid |
| 4181 | */ |
| 4182 | static inline int bond_slave_override(struct bonding *bond, |
| 4183 | struct sk_buff *skb) |
| 4184 | { |
| 4185 | int i, res = 1; |
| 4186 | struct slave *slave = NULL; |
| 4187 | struct slave *check_slave; |
| 4188 | |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4189 | if (!skb->queue_mapping) |
| 4190 | return 1; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4191 | |
| 4192 | /* Find out if any slaves have the same mapping as this skb. */ |
| 4193 | bond_for_each_slave(bond, check_slave, i) { |
| 4194 | if (check_slave->queue_id == skb->queue_mapping) { |
| 4195 | slave = check_slave; |
| 4196 | break; |
| 4197 | } |
| 4198 | } |
| 4199 | |
| 4200 | /* If the slave isn't UP, use default transmit policy. */ |
| 4201 | if (slave && slave->queue_id && IS_UP(slave->dev) && |
| 4202 | (slave->link == BOND_LINK_UP)) { |
| 4203 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
| 4204 | } |
| 4205 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4206 | return res; |
| 4207 | } |
| 4208 | |
| 4209 | static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 4210 | { |
| 4211 | /* |
| 4212 | * This helper function exists to help dev_pick_tx get the correct |
Phil Oester | fd0e435 | 2011-03-14 06:22:04 +0000 | [diff] [blame] | 4213 | * destination queue. Using a helper function skips a call to |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4214 | * skb_tx_hash and will put the skbs in the queue we expect on their |
| 4215 | * way down to the bonding driver. |
| 4216 | */ |
Phil Oester | fd0e435 | 2011-03-14 06:22:04 +0000 | [diff] [blame] | 4217 | u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0; |
| 4218 | |
| 4219 | if (unlikely(txq >= dev->real_num_tx_queues)) { |
David Decotigny | d30ee67 | 2011-04-13 15:22:29 +0000 | [diff] [blame] | 4220 | do { |
Phil Oester | fd0e435 | 2011-03-14 06:22:04 +0000 | [diff] [blame] | 4221 | txq -= dev->real_num_tx_queues; |
David Decotigny | d30ee67 | 2011-04-13 15:22:29 +0000 | [diff] [blame] | 4222 | } while (txq >= dev->real_num_tx_queues); |
Phil Oester | fd0e435 | 2011-03-14 06:22:04 +0000 | [diff] [blame] | 4223 | } |
| 4224 | return txq; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4225 | } |
| 4226 | |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4227 | static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4228 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4229 | struct bonding *bond = netdev_priv(dev); |
| 4230 | |
| 4231 | if (TX_QUEUE_OVERRIDE(bond->params.mode)) { |
| 4232 | if (!bond_slave_override(bond, skb)) |
| 4233 | return NETDEV_TX_OK; |
| 4234 | } |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4235 | |
| 4236 | switch (bond->params.mode) { |
| 4237 | case BOND_MODE_ROUNDROBIN: |
| 4238 | return bond_xmit_roundrobin(skb, dev); |
| 4239 | case BOND_MODE_ACTIVEBACKUP: |
| 4240 | return bond_xmit_activebackup(skb, dev); |
| 4241 | case BOND_MODE_XOR: |
| 4242 | return bond_xmit_xor(skb, dev); |
| 4243 | case BOND_MODE_BROADCAST: |
| 4244 | return bond_xmit_broadcast(skb, dev); |
| 4245 | case BOND_MODE_8023AD: |
| 4246 | return bond_3ad_xmit_xor(skb, dev); |
| 4247 | case BOND_MODE_ALB: |
| 4248 | case BOND_MODE_TLB: |
| 4249 | return bond_alb_xmit(skb, dev); |
| 4250 | default: |
| 4251 | /* Should never happen, mode already checked */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4252 | pr_err("%s: Error: Unknown bonding mode %d\n", |
| 4253 | dev->name, bond->params.mode); |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4254 | WARN_ON_ONCE(1); |
| 4255 | dev_kfree_skb(skb); |
| 4256 | return NETDEV_TX_OK; |
| 4257 | } |
| 4258 | } |
| 4259 | |
Michał Mirosław | 0693e88 | 2011-05-07 01:48:02 +0000 | [diff] [blame] | 4260 | static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 4261 | { |
| 4262 | struct bonding *bond = netdev_priv(dev); |
| 4263 | netdev_tx_t ret = NETDEV_TX_OK; |
| 4264 | |
| 4265 | /* |
| 4266 | * If we risk deadlock from transmitting this in the |
| 4267 | * netpoll path, tell netpoll to queue the frame for later tx |
| 4268 | */ |
| 4269 | if (is_netpoll_tx_blocked(dev)) |
| 4270 | return NETDEV_TX_BUSY; |
| 4271 | |
| 4272 | read_lock(&bond->lock); |
| 4273 | |
| 4274 | if (bond->slave_cnt) |
| 4275 | ret = __bond_start_xmit(skb, dev); |
| 4276 | else |
| 4277 | dev_kfree_skb(skb); |
| 4278 | |
| 4279 | read_unlock(&bond->lock); |
| 4280 | |
| 4281 | return ret; |
| 4282 | } |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | /* |
| 4285 | * set bond mode specific net device operations |
| 4286 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 4287 | void bond_set_mode_ops(struct bonding *bond, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | { |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4289 | struct net_device *bond_dev = bond->dev; |
| 4290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | switch (mode) { |
| 4292 | case BOND_MODE_ROUNDROBIN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | break; |
| 4294 | case BOND_MODE_ACTIVEBACKUP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4295 | break; |
| 4296 | case BOND_MODE_XOR: |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 4297 | bond_set_xmit_hash_policy(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | break; |
| 4299 | case BOND_MODE_BROADCAST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | break; |
| 4301 | case BOND_MODE_8023AD: |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 4302 | bond_set_xmit_hash_policy(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | case BOND_MODE_ALB: |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 4305 | /* FALLTHRU */ |
| 4306 | case BOND_MODE_TLB: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4307 | break; |
| 4308 | default: |
| 4309 | /* Should never happen, mode already checked */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4310 | pr_err("%s: Error: Unknown bonding mode %d\n", |
| 4311 | bond_dev->name, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | break; |
| 4313 | } |
| 4314 | } |
| 4315 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 4316 | static void bond_ethtool_get_drvinfo(struct net_device *bond_dev, |
| 4317 | struct ethtool_drvinfo *drvinfo) |
| 4318 | { |
| 4319 | strncpy(drvinfo->driver, DRV_NAME, 32); |
| 4320 | strncpy(drvinfo->version, DRV_VERSION, 32); |
| 4321 | snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION); |
| 4322 | } |
| 4323 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 4324 | static const struct ethtool_ops bond_ethtool_ops = { |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 4325 | .get_drvinfo = bond_ethtool_get_drvinfo, |
Stephen Hemminger | fa53eba | 2008-09-13 21:17:09 -0400 | [diff] [blame] | 4326 | .get_link = ethtool_op_get_link, |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 4327 | }; |
| 4328 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4329 | static const struct net_device_ops bond_netdev_ops = { |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4330 | .ndo_init = bond_init, |
Stephen Hemminger | 9e71626 | 2009-06-12 19:02:47 +0000 | [diff] [blame] | 4331 | .ndo_uninit = bond_uninit, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4332 | .ndo_open = bond_open, |
| 4333 | .ndo_stop = bond_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4334 | .ndo_start_xmit = bond_start_xmit, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4335 | .ndo_select_queue = bond_select_queue, |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 4336 | .ndo_get_stats64 = bond_get_stats, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4337 | .ndo_do_ioctl = bond_do_ioctl, |
| 4338 | .ndo_set_multicast_list = bond_set_multicast_list, |
| 4339 | .ndo_change_mtu = bond_change_mtu, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4340 | .ndo_set_mac_address = bond_set_mac_address, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4341 | .ndo_neigh_setup = bond_neigh_setup, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4342 | .ndo_vlan_rx_register = bond_vlan_rx_register, |
| 4343 | .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid, |
| 4344 | .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 4345 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame] | 4346 | .ndo_netpoll_setup = bond_netpoll_setup, |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 4347 | .ndo_netpoll_cleanup = bond_netpoll_cleanup, |
| 4348 | .ndo_poll_controller = bond_poll_controller, |
| 4349 | #endif |
Jiri Pirko | 9232ecc | 2011-02-13 09:33:01 +0000 | [diff] [blame] | 4350 | .ndo_add_slave = bond_enslave, |
| 4351 | .ndo_del_slave = bond_release, |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 4352 | .ndo_fix_features = bond_fix_features, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4353 | }; |
| 4354 | |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 4355 | static void bond_destructor(struct net_device *bond_dev) |
| 4356 | { |
| 4357 | struct bonding *bond = netdev_priv(bond_dev); |
| 4358 | if (bond->wq) |
| 4359 | destroy_workqueue(bond->wq); |
| 4360 | free_netdev(bond_dev); |
| 4361 | } |
| 4362 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4363 | static void bond_setup(struct net_device *bond_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4365 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | /* initialize rwlocks */ |
| 4368 | rwlock_init(&bond->lock); |
| 4369 | rwlock_init(&bond->curr_slave_lock); |
| 4370 | |
Stephen Hemminger | d2991f7 | 2009-06-12 19:02:44 +0000 | [diff] [blame] | 4371 | bond->params = bonding_defaults; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4372 | |
| 4373 | /* Initialize pointers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4374 | bond->dev = bond_dev; |
| 4375 | INIT_LIST_HEAD(&bond->vlan_list); |
| 4376 | |
| 4377 | /* Initialize the device entry points */ |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4378 | ether_setup(bond_dev); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4379 | bond_dev->netdev_ops = &bond_netdev_ops; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 4380 | bond_dev->ethtool_ops = &bond_ethtool_ops; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4381 | bond_set_mode_ops(bond, bond->params.mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 4383 | bond_dev->destructor = bond_destructor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | |
| 4385 | /* Initialize the device options */ |
| 4386 | bond_dev->tx_queue_len = 0; |
| 4387 | bond_dev->flags |= IFF_MASTER|IFF_MULTICAST; |
Jay Vosburgh | 0b680e7 | 2006-09-22 21:54:10 -0700 | [diff] [blame] | 4388 | bond_dev->priv_flags |= IFF_BONDING; |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4389 | bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE; |
| 4390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | /* At first, we block adding VLANs. That's the only way to |
| 4392 | * prevent problems that occur when adding VLANs over an |
| 4393 | * empty bond. The block will be removed once non-challenged |
| 4394 | * slaves are enslaved. |
| 4395 | */ |
| 4396 | bond_dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 4397 | |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 4398 | /* don't acquire bond device's netif_tx_lock when |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | * transmitting */ |
| 4400 | bond_dev->features |= NETIF_F_LLTX; |
| 4401 | |
| 4402 | /* By default, we declare the bond to be fully |
| 4403 | * VLAN hardware accelerated capable. Special |
| 4404 | * care is taken in the various xmit functions |
| 4405 | * when there are slaves that are not hw accel |
| 4406 | * capable |
| 4407 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | |
Michał Mirosław | b2a103e | 2011-05-07 03:22:17 +0000 | [diff] [blame] | 4409 | bond_dev->hw_features = BOND_VLAN_FEATURES | |
| 4410 | NETIF_F_HW_VLAN_TX | |
| 4411 | NETIF_F_HW_VLAN_RX | |
| 4412 | NETIF_F_HW_VLAN_FILTER; |
| 4413 | |
| 4414 | bond_dev->hw_features &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_NO_CSUM); |
| 4415 | bond_dev->features |= bond_dev->hw_features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | } |
| 4417 | |
Jay Vosburgh | fdaea7a | 2007-12-06 23:40:35 -0800 | [diff] [blame] | 4418 | static void bond_work_cancel_all(struct bonding *bond) |
| 4419 | { |
| 4420 | write_lock_bh(&bond->lock); |
| 4421 | bond->kill_timers = 1; |
| 4422 | write_unlock_bh(&bond->lock); |
| 4423 | |
| 4424 | if (bond->params.miimon && delayed_work_pending(&bond->mii_work)) |
| 4425 | cancel_delayed_work(&bond->mii_work); |
| 4426 | |
| 4427 | if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work)) |
| 4428 | cancel_delayed_work(&bond->arp_work); |
| 4429 | |
| 4430 | if (bond->params.mode == BOND_MODE_ALB && |
| 4431 | delayed_work_pending(&bond->alb_work)) |
| 4432 | cancel_delayed_work(&bond->alb_work); |
| 4433 | |
| 4434 | if (bond->params.mode == BOND_MODE_8023AD && |
| 4435 | delayed_work_pending(&bond->ad_work)) |
| 4436 | cancel_delayed_work(&bond->ad_work); |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 4437 | |
| 4438 | if (delayed_work_pending(&bond->mcast_work)) |
| 4439 | cancel_delayed_work(&bond->mcast_work); |
Jay Vosburgh | fdaea7a | 2007-12-06 23:40:35 -0800 | [diff] [blame] | 4440 | } |
| 4441 | |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 4442 | /* |
| 4443 | * Destroy a bonding device. |
| 4444 | * Must be under rtnl_lock when this function is called. |
| 4445 | */ |
| 4446 | static void bond_uninit(struct net_device *bond_dev) |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4447 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4448 | struct bonding *bond = netdev_priv(bond_dev); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 4449 | struct vlan_entry *vlan, *tmp; |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4450 | |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 4451 | bond_netpoll_cleanup(bond_dev); |
| 4452 | |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 4453 | /* Release the bonded slaves */ |
| 4454 | bond_release_all(bond_dev); |
| 4455 | |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4456 | list_del(&bond->bond_list); |
| 4457 | |
| 4458 | bond_work_cancel_all(bond); |
| 4459 | |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4460 | bond_remove_proc_entry(bond); |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 4461 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 4462 | bond_debug_unregister(bond); |
| 4463 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4464 | __hw_addr_flush(&bond->mc_list); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 4465 | |
| 4466 | list_for_each_entry_safe(vlan, tmp, &bond->vlan_list, vlan_list) { |
| 4467 | list_del(&vlan->vlan_list); |
| 4468 | kfree(vlan); |
| 4469 | } |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4470 | } |
| 4471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | /*------------------------- Module initialization ---------------------------*/ |
| 4473 | |
| 4474 | /* |
| 4475 | * Convert string input module parms. Accept either the |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4476 | * number of the mode or its string name. A bit complicated because |
| 4477 | * some mode names are substrings of other names, and calls from sysfs |
| 4478 | * may have whitespace in the name (trailing newlines, for example). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4479 | */ |
Holger Eitzenberger | 325dcf7 | 2008-12-09 23:10:17 -0800 | [diff] [blame] | 4480 | int bond_parse_parm(const char *buf, const struct bond_parm_tbl *tbl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | { |
Hannes Eder | 54b8732 | 2009-02-14 11:15:49 +0000 | [diff] [blame] | 4482 | int modeint = -1, i, rv; |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4483 | char *p, modestr[BOND_MAX_MODENAME_LEN + 1] = { 0, }; |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4484 | |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4485 | for (p = (char *)buf; *p; p++) |
| 4486 | if (!(isdigit(*p) || isspace(*p))) |
| 4487 | break; |
| 4488 | |
| 4489 | if (*p) |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4490 | rv = sscanf(buf, "%20s", modestr); |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4491 | else |
Hannes Eder | 54b8732 | 2009-02-14 11:15:49 +0000 | [diff] [blame] | 4492 | rv = sscanf(buf, "%d", &modeint); |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4493 | |
| 4494 | if (!rv) |
| 4495 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4496 | |
| 4497 | for (i = 0; tbl[i].modename; i++) { |
Hannes Eder | 54b8732 | 2009-02-14 11:15:49 +0000 | [diff] [blame] | 4498 | if (modeint == tbl[i].mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | return tbl[i].mode; |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4500 | if (strcmp(modestr, tbl[i].modename) == 0) |
| 4501 | return tbl[i].mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | return -1; |
| 4505 | } |
| 4506 | |
| 4507 | static int bond_check_params(struct bond_params *params) |
| 4508 | { |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 4509 | int arp_validate_value, fail_over_mac_value, primary_reselect_value; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | /* |
| 4512 | * Convert string parameters. |
| 4513 | */ |
| 4514 | if (mode) { |
| 4515 | bond_mode = bond_parse_parm(mode, bond_mode_tbl); |
| 4516 | if (bond_mode == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4517 | pr_err("Error: Invalid bonding mode \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4518 | mode == NULL ? "NULL" : mode); |
| 4519 | return -EINVAL; |
| 4520 | } |
| 4521 | } |
| 4522 | |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4523 | if (xmit_hash_policy) { |
| 4524 | if ((bond_mode != BOND_MODE_XOR) && |
| 4525 | (bond_mode != BOND_MODE_8023AD)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4526 | pr_info("xmit_hash_policy param is irrelevant in mode %s\n", |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4527 | bond_mode_name(bond_mode)); |
| 4528 | } else { |
| 4529 | xmit_hashtype = bond_parse_parm(xmit_hash_policy, |
| 4530 | xmit_hashtype_tbl); |
| 4531 | if (xmit_hashtype == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4532 | pr_err("Error: Invalid xmit_hash_policy \"%s\"\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4533 | xmit_hash_policy == NULL ? "NULL" : |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4534 | xmit_hash_policy); |
| 4535 | return -EINVAL; |
| 4536 | } |
| 4537 | } |
| 4538 | } |
| 4539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | if (lacp_rate) { |
| 4541 | if (bond_mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4542 | pr_info("lacp_rate param is irrelevant in mode %s\n", |
| 4543 | bond_mode_name(bond_mode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | } else { |
| 4545 | lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl); |
| 4546 | if (lacp_fast == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4547 | pr_err("Error: Invalid lacp rate \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4548 | lacp_rate == NULL ? "NULL" : lacp_rate); |
| 4549 | return -EINVAL; |
| 4550 | } |
| 4551 | } |
| 4552 | } |
| 4553 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 4554 | if (ad_select) { |
| 4555 | params->ad_select = bond_parse_parm(ad_select, ad_select_tbl); |
| 4556 | if (params->ad_select == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4557 | pr_err("Error: Invalid ad_select \"%s\"\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 4558 | ad_select == NULL ? "NULL" : ad_select); |
| 4559 | return -EINVAL; |
| 4560 | } |
| 4561 | |
| 4562 | if (bond_mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4563 | pr_warning("ad_select param only affects 802.3ad mode\n"); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 4564 | } |
| 4565 | } else { |
| 4566 | params->ad_select = BOND_AD_STABLE; |
| 4567 | } |
| 4568 | |
Nicolas de Pesloüan | f584130 | 2009-08-28 13:18:34 +0000 | [diff] [blame] | 4569 | if (max_bonds < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4570 | pr_warning("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n", |
| 4571 | max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | max_bonds = BOND_DEFAULT_MAX_BONDS; |
| 4573 | } |
| 4574 | |
| 4575 | if (miimon < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4576 | pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n", |
| 4577 | miimon, INT_MAX, BOND_LINK_MON_INTERV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | miimon = BOND_LINK_MON_INTERV; |
| 4579 | } |
| 4580 | |
| 4581 | if (updelay < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4582 | pr_warning("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n", |
| 4583 | updelay, INT_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4584 | updelay = 0; |
| 4585 | } |
| 4586 | |
| 4587 | if (downdelay < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4588 | pr_warning("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n", |
| 4589 | downdelay, INT_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4590 | downdelay = 0; |
| 4591 | } |
| 4592 | |
| 4593 | if ((use_carrier != 0) && (use_carrier != 1)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4594 | pr_warning("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n", |
| 4595 | use_carrier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | use_carrier = 1; |
| 4597 | } |
| 4598 | |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 4599 | if (num_peer_notif < 0 || num_peer_notif > 255) { |
| 4600 | pr_warning("Warning: num_grat_arp/num_unsol_na (%d) not in range 0-255 so it was reset to 1\n", |
| 4601 | num_peer_notif); |
| 4602 | num_peer_notif = 1; |
| 4603 | } |
| 4604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | /* reset values for 802.3ad */ |
| 4606 | if (bond_mode == BOND_MODE_8023AD) { |
| 4607 | if (!miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4608 | pr_warning("Warning: miimon must be specified, otherwise bonding will not detect link failure, speed and duplex which are essential for 802.3ad operation\n"); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4609 | pr_warning("Forcing miimon to 100msec\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4610 | miimon = 100; |
| 4611 | } |
| 4612 | } |
| 4613 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4614 | if (tx_queues < 1 || tx_queues > 255) { |
| 4615 | pr_warning("Warning: tx_queues (%d) should be between " |
| 4616 | "1 and 255, resetting to %d\n", |
| 4617 | tx_queues, BOND_DEFAULT_TX_QUEUES); |
| 4618 | tx_queues = BOND_DEFAULT_TX_QUEUES; |
| 4619 | } |
| 4620 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 4621 | if ((all_slaves_active != 0) && (all_slaves_active != 1)) { |
| 4622 | pr_warning("Warning: all_slaves_active module parameter (%d), " |
| 4623 | "not of valid value (0/1), so it was set to " |
| 4624 | "0\n", all_slaves_active); |
| 4625 | all_slaves_active = 0; |
| 4626 | } |
| 4627 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 4628 | if (resend_igmp < 0 || resend_igmp > 255) { |
| 4629 | pr_warning("Warning: resend_igmp (%d) should be between " |
| 4630 | "0 and 255, resetting to %d\n", |
| 4631 | resend_igmp, BOND_DEFAULT_RESEND_IGMP); |
| 4632 | resend_igmp = BOND_DEFAULT_RESEND_IGMP; |
| 4633 | } |
| 4634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | /* reset values for TLB/ALB */ |
| 4636 | if ((bond_mode == BOND_MODE_TLB) || |
| 4637 | (bond_mode == BOND_MODE_ALB)) { |
| 4638 | if (!miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4639 | pr_warning("Warning: miimon must be specified, otherwise bonding will not detect link failure and link speed which are essential for TLB/ALB load balancing\n"); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4640 | pr_warning("Forcing miimon to 100msec\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | miimon = 100; |
| 4642 | } |
| 4643 | } |
| 4644 | |
| 4645 | if (bond_mode == BOND_MODE_ALB) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4646 | pr_notice("In ALB mode you might experience client disconnections upon reconnection of a link if the bonding module updelay parameter (%d msec) is incompatible with the forwarding delay time of the switch\n", |
| 4647 | updelay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | if (!miimon) { |
| 4651 | if (updelay || downdelay) { |
| 4652 | /* just warn the user the up/down delay will have |
| 4653 | * no effect since miimon is zero... |
| 4654 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4655 | pr_warning("Warning: miimon module parameter not set and updelay (%d) or downdelay (%d) module parameter is set; updelay and downdelay have no effect unless miimon is set\n", |
| 4656 | updelay, downdelay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4657 | } |
| 4658 | } else { |
| 4659 | /* don't allow arp monitoring */ |
| 4660 | if (arp_interval) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4661 | pr_warning("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n", |
| 4662 | miimon, arp_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | arp_interval = 0; |
| 4664 | } |
| 4665 | |
| 4666 | if ((updelay % miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4667 | pr_warning("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
| 4668 | updelay, miimon, |
| 4669 | (updelay / miimon) * miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | updelay /= miimon; |
| 4673 | |
| 4674 | if ((downdelay % miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4675 | pr_warning("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n", |
| 4676 | downdelay, miimon, |
| 4677 | (downdelay / miimon) * miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | downdelay /= miimon; |
| 4681 | } |
| 4682 | |
| 4683 | if (arp_interval < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4684 | pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n", |
| 4685 | arp_interval, INT_MAX, BOND_LINK_ARP_INTERV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | arp_interval = BOND_LINK_ARP_INTERV; |
| 4687 | } |
| 4688 | |
| 4689 | for (arp_ip_count = 0; |
| 4690 | (arp_ip_count < BOND_MAX_ARP_TARGETS) && arp_ip_target[arp_ip_count]; |
| 4691 | arp_ip_count++) { |
| 4692 | /* not complete check, but should be good enough to |
| 4693 | catch mistakes */ |
| 4694 | if (!isdigit(arp_ip_target[arp_ip_count][0])) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4695 | pr_warning("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n", |
| 4696 | arp_ip_target[arp_ip_count]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4697 | arp_interval = 0; |
| 4698 | } else { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 4699 | __be32 ip = in_aton(arp_ip_target[arp_ip_count]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | arp_target[arp_ip_count] = ip; |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | if (arp_interval && !arp_ip_count) { |
| 4705 | /* don't allow arping if no arp_ip_target given... */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4706 | pr_warning("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n", |
| 4707 | arp_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4708 | arp_interval = 0; |
| 4709 | } |
| 4710 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4711 | if (arp_validate) { |
| 4712 | if (bond_mode != BOND_MODE_ACTIVEBACKUP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4713 | pr_err("arp_validate only supported in active-backup mode\n"); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4714 | return -EINVAL; |
| 4715 | } |
| 4716 | if (!arp_interval) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4717 | pr_err("arp_validate requires arp_interval\n"); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4718 | return -EINVAL; |
| 4719 | } |
| 4720 | |
| 4721 | arp_validate_value = bond_parse_parm(arp_validate, |
| 4722 | arp_validate_tbl); |
| 4723 | if (arp_validate_value == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4724 | pr_err("Error: invalid arp_validate \"%s\"\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4725 | arp_validate == NULL ? "NULL" : arp_validate); |
| 4726 | return -EINVAL; |
| 4727 | } |
| 4728 | } else |
| 4729 | arp_validate_value = 0; |
| 4730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4731 | if (miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4732 | pr_info("MII link monitoring set to %d ms\n", miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | } else if (arp_interval) { |
| 4734 | int i; |
| 4735 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4736 | pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):", |
| 4737 | arp_interval, |
| 4738 | arp_validate_tbl[arp_validate_value].modename, |
| 4739 | arp_ip_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | |
| 4741 | for (i = 0; i < arp_ip_count; i++) |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 4742 | pr_info(" %s", arp_ip_target[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 4744 | pr_info("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4745 | |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 4746 | } else if (max_bonds) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4747 | /* miimon and arp_interval not set, we need one so things |
| 4748 | * work as expected, see bonding.txt for details |
| 4749 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4750 | pr_warning("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | if (primary && !USES_PRIMARY(bond_mode)) { |
| 4754 | /* currently, using a primary only makes sense |
| 4755 | * in active backup, TLB or ALB modes |
| 4756 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4757 | pr_warning("Warning: %s primary device specified but has no effect in %s mode\n", |
| 4758 | primary, bond_mode_name(bond_mode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4759 | primary = NULL; |
| 4760 | } |
| 4761 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 4762 | if (primary && primary_reselect) { |
| 4763 | primary_reselect_value = bond_parse_parm(primary_reselect, |
| 4764 | pri_reselect_tbl); |
| 4765 | if (primary_reselect_value == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4766 | pr_err("Error: Invalid primary_reselect \"%s\"\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 4767 | primary_reselect == |
| 4768 | NULL ? "NULL" : primary_reselect); |
| 4769 | return -EINVAL; |
| 4770 | } |
| 4771 | } else { |
| 4772 | primary_reselect_value = BOND_PRI_RESELECT_ALWAYS; |
| 4773 | } |
| 4774 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 4775 | if (fail_over_mac) { |
| 4776 | fail_over_mac_value = bond_parse_parm(fail_over_mac, |
| 4777 | fail_over_mac_tbl); |
| 4778 | if (fail_over_mac_value == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4779 | pr_err("Error: invalid fail_over_mac \"%s\"\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 4780 | arp_validate == NULL ? "NULL" : arp_validate); |
| 4781 | return -EINVAL; |
| 4782 | } |
| 4783 | |
| 4784 | if (bond_mode != BOND_MODE_ACTIVEBACKUP) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4785 | pr_warning("Warning: fail_over_mac only affects active-backup mode.\n"); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 4786 | } else { |
| 4787 | fail_over_mac_value = BOND_FOM_NONE; |
| 4788 | } |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 4789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4790 | /* fill params struct with the proper values */ |
| 4791 | params->mode = bond_mode; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4792 | params->xmit_policy = xmit_hashtype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4793 | params->miimon = miimon; |
Ben Hutchings | ad246c9 | 2011-04-26 15:25:52 +0000 | [diff] [blame] | 4794 | params->num_peer_notif = num_peer_notif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | params->arp_interval = arp_interval; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4796 | params->arp_validate = arp_validate_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4797 | params->updelay = updelay; |
| 4798 | params->downdelay = downdelay; |
| 4799 | params->use_carrier = use_carrier; |
| 4800 | params->lacp_fast = lacp_fast; |
| 4801 | params->primary[0] = 0; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 4802 | params->primary_reselect = primary_reselect_value; |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 4803 | params->fail_over_mac = fail_over_mac_value; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4804 | params->tx_queues = tx_queues; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 4805 | params->all_slaves_active = all_slaves_active; |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 4806 | params->resend_igmp = resend_igmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4807 | |
| 4808 | if (primary) { |
| 4809 | strncpy(params->primary, primary, IFNAMSIZ); |
| 4810 | params->primary[IFNAMSIZ - 1] = 0; |
| 4811 | } |
| 4812 | |
| 4813 | memcpy(params->arp_targets, arp_target, sizeof(arp_target)); |
| 4814 | |
| 4815 | return 0; |
| 4816 | } |
| 4817 | |
Peter Zijlstra | 0daa2303 | 2006-11-08 19:51:01 -0800 | [diff] [blame] | 4818 | static struct lock_class_key bonding_netdev_xmit_lock_key; |
David S. Miller | cf508b1 | 2008-07-22 14:16:42 -0700 | [diff] [blame] | 4819 | static struct lock_class_key bonding_netdev_addr_lock_key; |
Peter Zijlstra | 0daa2303 | 2006-11-08 19:51:01 -0800 | [diff] [blame] | 4820 | |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 4821 | static void bond_set_lockdep_class_one(struct net_device *dev, |
| 4822 | struct netdev_queue *txq, |
| 4823 | void *_unused) |
David S. Miller | c773e84 | 2008-07-08 23:13:53 -0700 | [diff] [blame] | 4824 | { |
| 4825 | lockdep_set_class(&txq->_xmit_lock, |
| 4826 | &bonding_netdev_xmit_lock_key); |
| 4827 | } |
| 4828 | |
| 4829 | static void bond_set_lockdep_class(struct net_device *dev) |
| 4830 | { |
David S. Miller | cf508b1 | 2008-07-22 14:16:42 -0700 | [diff] [blame] | 4831 | lockdep_set_class(&dev->addr_list_lock, |
| 4832 | &bonding_netdev_addr_lock_key); |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 4833 | netdev_for_each_tx_queue(dev, bond_set_lockdep_class_one, NULL); |
David S. Miller | c773e84 | 2008-07-08 23:13:53 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4836 | /* |
| 4837 | * Called from registration process |
| 4838 | */ |
| 4839 | static int bond_init(struct net_device *bond_dev) |
| 4840 | { |
| 4841 | struct bonding *bond = netdev_priv(bond_dev); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4842 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
Neil Horman | 9fe0617 | 2011-05-25 08:13:01 +0000 | [diff] [blame] | 4843 | struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond)); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4844 | |
| 4845 | pr_debug("Begin bond_init for %s\n", bond_dev->name); |
| 4846 | |
Neil Horman | 9fe0617 | 2011-05-25 08:13:01 +0000 | [diff] [blame] | 4847 | /* |
| 4848 | * Initialize locks that may be required during |
| 4849 | * en/deslave operations. All of the bond_open work |
| 4850 | * (of which this is part) should really be moved to |
| 4851 | * a phase prior to dev_open |
| 4852 | */ |
| 4853 | spin_lock_init(&(bond_info->tx_hashtbl_lock)); |
| 4854 | spin_lock_init(&(bond_info->rx_hashtbl_lock)); |
| 4855 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4856 | bond->wq = create_singlethread_workqueue(bond_dev->name); |
| 4857 | if (!bond->wq) |
| 4858 | return -ENOMEM; |
| 4859 | |
| 4860 | bond_set_lockdep_class(bond_dev); |
| 4861 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4862 | bond_create_proc_entry(bond); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4863 | list_add_tail(&bond->bond_list, &bn->dev_list); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4864 | |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 4865 | bond_prepare_sysfs_group(bond); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4866 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 4867 | bond_debug_register(bond); |
| 4868 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4869 | __hw_addr_init(&bond->mc_list); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4870 | return 0; |
| 4871 | } |
| 4872 | |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4873 | static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) |
| 4874 | { |
| 4875 | if (tb[IFLA_ADDRESS]) { |
| 4876 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) |
| 4877 | return -EINVAL; |
| 4878 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) |
| 4879 | return -EADDRNOTAVAIL; |
| 4880 | } |
| 4881 | return 0; |
| 4882 | } |
| 4883 | |
| 4884 | static struct rtnl_link_ops bond_link_ops __read_mostly = { |
| 4885 | .kind = "bond", |
Eric W. Biederman | 6639104 | 2009-10-29 23:58:54 +0000 | [diff] [blame] | 4886 | .priv_size = sizeof(struct bonding), |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4887 | .setup = bond_setup, |
| 4888 | .validate = bond_validate, |
| 4889 | }; |
| 4890 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4891 | /* Create a new bond based on the specified name and bonding parameters. |
Jay Vosburgh | e4b91c4 | 2007-01-19 18:15:31 -0800 | [diff] [blame] | 4892 | * If name is NULL, obtain a suitable "bond%d" name for us. |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4893 | * Caller must NOT hold rtnl_lock; we need to release it here before we |
| 4894 | * set up our sysfs entries. |
| 4895 | */ |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4896 | int bond_create(struct net *net, const char *name) |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4897 | { |
| 4898 | struct net_device *bond_dev; |
| 4899 | int res; |
| 4900 | |
| 4901 | rtnl_lock(); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 4902 | |
Jiri Pirko | 1c5cae8 | 2011-04-30 01:21:32 +0000 | [diff] [blame] | 4903 | bond_dev = alloc_netdev_mq(sizeof(struct bonding), |
| 4904 | name ? name : "bond%d", |
| 4905 | bond_setup, tx_queues); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4906 | if (!bond_dev) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4907 | pr_err("%s: eek! can't alloc netdev!\n", name); |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 4908 | rtnl_unlock(); |
| 4909 | return -ENOMEM; |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4910 | } |
| 4911 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4912 | dev_net_set(bond_dev, net); |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4913 | bond_dev->rtnl_link_ops = &bond_link_ops; |
| 4914 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4915 | res = register_netdevice(bond_dev); |
Peter Zijlstra | 0daa2303 | 2006-11-08 19:51:01 -0800 | [diff] [blame] | 4916 | |
Phil Oester | e826eaf | 2011-03-14 06:22:05 +0000 | [diff] [blame] | 4917 | netif_carrier_off(bond_dev); |
| 4918 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4919 | rtnl_unlock(); |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 4920 | if (res < 0) |
| 4921 | bond_destructor(bond_dev); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4922 | return res; |
| 4923 | } |
| 4924 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 4925 | static int __net_init bond_net_init(struct net *net) |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4926 | { |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 4927 | struct bond_net *bn = net_generic(net, bond_net_id); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4928 | |
| 4929 | bn->net = net; |
| 4930 | INIT_LIST_HEAD(&bn->dev_list); |
| 4931 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4932 | bond_create_proc_dir(bn); |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 4933 | |
| 4934 | return 0; |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4935 | } |
| 4936 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 4937 | static void __net_exit bond_net_exit(struct net *net) |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4938 | { |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 4939 | struct bond_net *bn = net_generic(net, bond_net_id); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4940 | |
| 4941 | bond_destroy_proc_dir(bn); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | static struct pernet_operations bond_net_ops = { |
| 4945 | .init = bond_net_init, |
| 4946 | .exit = bond_net_exit, |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 4947 | .id = &bond_net_id, |
| 4948 | .size = sizeof(struct bond_net), |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4949 | }; |
| 4950 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | static int __init bonding_init(void) |
| 4952 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | int i; |
| 4954 | int res; |
| 4955 | |
Amerigo Wang | bd33acc | 2011-03-06 21:58:46 +0000 | [diff] [blame] | 4956 | pr_info("%s", bond_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4958 | res = bond_check_params(&bonding_defaults); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4959 | if (res) |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4960 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4961 | |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 4962 | res = register_pernet_subsys(&bond_net_ops); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4963 | if (res) |
| 4964 | goto out; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 4965 | |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4966 | res = rtnl_link_register(&bond_link_ops); |
| 4967 | if (res) |
Eric W. Biederman | 6639104 | 2009-10-29 23:58:54 +0000 | [diff] [blame] | 4968 | goto err_link; |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4969 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 4970 | bond_create_debugfs(); |
| 4971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | for (i = 0; i < max_bonds; i++) { |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4973 | res = bond_create(&init_net, NULL); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4974 | if (res) |
| 4975 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4976 | } |
| 4977 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 4978 | res = bond_create_sysfs(); |
| 4979 | if (res) |
| 4980 | goto err; |
| 4981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | register_netdevice_notifier(&bond_netdev_notifier); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 4983 | register_inetaddr_notifier(&bond_inetaddr_notifier); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4984 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | return res; |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4986 | err: |
| 4987 | rtnl_link_unregister(&bond_link_ops); |
Eric W. Biederman | 6639104 | 2009-10-29 23:58:54 +0000 | [diff] [blame] | 4988 | err_link: |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 4989 | unregister_pernet_subsys(&bond_net_ops); |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 4990 | goto out; |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 4991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
| 4994 | static void __exit bonding_exit(void) |
| 4995 | { |
| 4996 | unregister_netdevice_notifier(&bond_netdev_notifier); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 4997 | unregister_inetaddr_notifier(&bond_inetaddr_notifier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | |
Pavel Emelyanov | ae68c39 | 2008-05-02 17:49:39 -0700 | [diff] [blame] | 4999 | bond_destroy_sysfs(); |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 5000 | bond_destroy_debugfs(); |
Pavel Emelyanov | ae68c39 | 2008-05-02 17:49:39 -0700 | [diff] [blame] | 5001 | |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5002 | rtnl_link_unregister(&bond_link_ops); |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5003 | unregister_pernet_subsys(&bond_net_ops); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 5004 | |
| 5005 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Neil Horman | fb4fa76 | 2010-12-06 09:05:50 +0000 | [diff] [blame] | 5006 | /* |
| 5007 | * Make sure we don't have an imbalance on our netpoll blocking |
| 5008 | */ |
| 5009 | WARN_ON(atomic_read(&netpoll_block_tx)); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 5010 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5011 | } |
| 5012 | |
| 5013 | module_init(bonding_init); |
| 5014 | module_exit(bonding_exit); |
| 5015 | MODULE_LICENSE("GPL"); |
| 5016 | MODULE_VERSION(DRV_VERSION); |
| 5017 | MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION); |
| 5018 | MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others"); |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5019 | MODULE_ALIAS_RTNL_LINK("bond"); |