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