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> |
| 68 | #include <linux/proc_fs.h> |
| 69 | #include <linux/seq_file.h> |
| 70 | #include <linux/smp.h> |
| 71 | #include <linux/if_ether.h> |
| 72 | #include <net/arp.h> |
| 73 | #include <linux/mii.h> |
| 74 | #include <linux/ethtool.h> |
| 75 | #include <linux/if_vlan.h> |
| 76 | #include <linux/if_bonding.h> |
David Sterba | b63bb73 | 2007-12-06 23:40:33 -0800 | [diff] [blame] | 77 | #include <linux/jiffies.h> |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 78 | #include <linux/preempt.h> |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 79 | #include <net/route.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 80 | #include <net/net_namespace.h> |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 81 | #include <net/netns/generic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | #include "bonding.h" |
| 83 | #include "bond_3ad.h" |
| 84 | #include "bond_alb.h" |
| 85 | |
| 86 | /*---------------------------- Module parameters ----------------------------*/ |
| 87 | |
| 88 | /* monitor all links that often (in milliseconds). <=0 disables monitoring */ |
| 89 | #define BOND_LINK_MON_INTERV 0 |
| 90 | #define BOND_LINK_ARP_INTERV 0 |
| 91 | |
| 92 | static int max_bonds = BOND_DEFAULT_MAX_BONDS; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 93 | static int tx_queues = BOND_DEFAULT_TX_QUEUES; |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 94 | static int num_grat_arp = 1; |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 95 | static int num_unsol_na = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | static int miimon = BOND_LINK_MON_INTERV; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 97 | static int updelay; |
| 98 | static int downdelay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static int use_carrier = 1; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 100 | static char *mode; |
| 101 | static char *primary; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 102 | static char *primary_reselect; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 103 | static char *lacp_rate; |
| 104 | static char *ad_select; |
| 105 | static char *xmit_hash_policy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | static int arp_interval = BOND_LINK_ARP_INTERV; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 107 | static char *arp_ip_target[BOND_MAX_ARP_TARGETS]; |
| 108 | static char *arp_validate; |
| 109 | static char *fail_over_mac; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 110 | static int all_slaves_active = 0; |
Stephen Hemminger | d2991f7 | 2009-06-12 19:02:44 +0000 | [diff] [blame] | 111 | static struct bond_params bonding_defaults; |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 112 | static int resend_igmp = BOND_DEFAULT_RESEND_IGMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | module_param(max_bonds, int, 0); |
| 115 | MODULE_PARM_DESC(max_bonds, "Max number of bonded devices"); |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 116 | module_param(tx_queues, int, 0); |
| 117 | MODULE_PARM_DESC(tx_queues, "Max number of transmit queues (default = 16)"); |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 118 | module_param(num_grat_arp, int, 0644); |
| 119 | MODULE_PARM_DESC(num_grat_arp, "Number of gratuitous ARP packets to send on failover event"); |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 120 | module_param(num_unsol_na, int, 0644); |
| 121 | MODULE_PARM_DESC(num_unsol_na, "Number of unsolicited IPv6 Neighbor Advertisements packets to send on failover event"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | module_param(miimon, int, 0); |
| 123 | MODULE_PARM_DESC(miimon, "Link check interval in milliseconds"); |
| 124 | module_param(updelay, int, 0); |
| 125 | MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds"); |
| 126 | module_param(downdelay, int, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 127 | MODULE_PARM_DESC(downdelay, "Delay before considering link down, " |
| 128 | "in milliseconds"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | module_param(use_carrier, int, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 130 | MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; " |
| 131 | "0 for off, 1 for on (default)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | module_param(mode, charp, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 133 | MODULE_PARM_DESC(mode, "Mode of operation : 0 for balance-rr, " |
| 134 | "1 for active-backup, 2 for balance-xor, " |
| 135 | "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, " |
| 136 | "6 for balance-alb"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | module_param(primary, charp, 0); |
| 138 | MODULE_PARM_DESC(primary, "Primary network device to use"); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 139 | module_param(primary_reselect, charp, 0); |
| 140 | MODULE_PARM_DESC(primary_reselect, "Reselect primary slave " |
| 141 | "once it comes up; " |
| 142 | "0 for always (default), " |
| 143 | "1 for only if speed of primary is " |
| 144 | "better, " |
| 145 | "2 for only on active slave " |
| 146 | "failure"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | module_param(lacp_rate, charp, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 148 | MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner " |
| 149 | "(slow/fast)"); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 150 | module_param(ad_select, charp, 0); |
| 151 | MODULE_PARM_DESC(ad_select, "803.ad aggregation selection logic: stable (0, default), bandwidth (1), count (2)"); |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 152 | module_param(xmit_hash_policy, charp, 0); |
Mitch Williams | 2ac4766 | 2005-11-09 10:35:03 -0800 | [diff] [blame] | 153 | MODULE_PARM_DESC(xmit_hash_policy, "XOR hashing method: 0 for layer 2 (default)" |
| 154 | ", 1 for layer 3+4"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | module_param(arp_interval, int, 0); |
| 156 | MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds"); |
| 157 | module_param_array(arp_ip_target, charp, NULL, 0); |
| 158 | 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] | 159 | module_param(arp_validate, charp, 0); |
| 160 | MODULE_PARM_DESC(arp_validate, "validate src/dst of ARP probes: none (default), active, backup or all"); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 161 | module_param(fail_over_mac, charp, 0); |
| 162 | MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to the same MAC. none (default), active or follow"); |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 163 | module_param(all_slaves_active, int, 0); |
| 164 | MODULE_PARM_DESC(all_slaves_active, "Keep all frames received on an interface" |
| 165 | "by setting active flag for all slaves. " |
| 166 | "0 for never (default), 1 for always."); |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 167 | module_param(resend_igmp, int, 0); |
| 168 | MODULE_PARM_DESC(resend_igmp, "Number of IGMP membership reports to send on link failure"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /*----------------------------- Global variables ----------------------------*/ |
| 171 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 172 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Neil Horman | fb4fa76 | 2010-12-06 09:05:50 +0000 | [diff] [blame] | 173 | atomic_t netpoll_block_tx = ATOMIC_INIT(0); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 174 | #endif |
| 175 | |
Arjan van de Ven | f71e130 | 2006-03-03 21:33:57 -0500 | [diff] [blame] | 176 | static const char * const version = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"; |
| 178 | |
Eric Dumazet | f99189b | 2009-11-17 10:42:49 +0000 | [diff] [blame] | 179 | int bond_net_id __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 181 | static __be32 arp_target[BOND_MAX_ARP_TARGETS]; |
| 182 | static int arp_ip_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | static int bond_mode = BOND_MODE_ROUNDROBIN; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 184 | static int xmit_hashtype = BOND_XMIT_POLICY_LAYER2; |
| 185 | static int lacp_fast; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 187 | const struct bond_parm_tbl bond_lacp_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { "slow", AD_LACP_SLOW}, |
| 189 | { "fast", AD_LACP_FAST}, |
| 190 | { NULL, -1}, |
| 191 | }; |
| 192 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 193 | const struct bond_parm_tbl bond_mode_tbl[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { "balance-rr", BOND_MODE_ROUNDROBIN}, |
| 195 | { "active-backup", BOND_MODE_ACTIVEBACKUP}, |
| 196 | { "balance-xor", BOND_MODE_XOR}, |
| 197 | { "broadcast", BOND_MODE_BROADCAST}, |
| 198 | { "802.3ad", BOND_MODE_8023AD}, |
| 199 | { "balance-tlb", BOND_MODE_TLB}, |
| 200 | { "balance-alb", BOND_MODE_ALB}, |
| 201 | { NULL, -1}, |
| 202 | }; |
| 203 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 204 | const struct bond_parm_tbl xmit_hashtype_tbl[] = { |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 205 | { "layer2", BOND_XMIT_POLICY_LAYER2}, |
| 206 | { "layer3+4", BOND_XMIT_POLICY_LAYER34}, |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 207 | { "layer2+3", BOND_XMIT_POLICY_LAYER23}, |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 208 | { NULL, -1}, |
| 209 | }; |
| 210 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 211 | const struct bond_parm_tbl arp_validate_tbl[] = { |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 212 | { "none", BOND_ARP_VALIDATE_NONE}, |
| 213 | { "active", BOND_ARP_VALIDATE_ACTIVE}, |
| 214 | { "backup", BOND_ARP_VALIDATE_BACKUP}, |
| 215 | { "all", BOND_ARP_VALIDATE_ALL}, |
| 216 | { NULL, -1}, |
| 217 | }; |
| 218 | |
Holger Eitzenberger | e97fd7c | 2008-12-09 23:10:38 -0800 | [diff] [blame] | 219 | const struct bond_parm_tbl fail_over_mac_tbl[] = { |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 220 | { "none", BOND_FOM_NONE}, |
| 221 | { "active", BOND_FOM_ACTIVE}, |
| 222 | { "follow", BOND_FOM_FOLLOW}, |
| 223 | { NULL, -1}, |
| 224 | }; |
| 225 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 226 | const struct bond_parm_tbl pri_reselect_tbl[] = { |
| 227 | { "always", BOND_PRI_RESELECT_ALWAYS}, |
| 228 | { "better", BOND_PRI_RESELECT_BETTER}, |
| 229 | { "failure", BOND_PRI_RESELECT_FAILURE}, |
| 230 | { NULL, -1}, |
| 231 | }; |
| 232 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 233 | struct bond_parm_tbl ad_select_tbl[] = { |
| 234 | { "stable", BOND_AD_STABLE}, |
| 235 | { "bandwidth", BOND_AD_BANDWIDTH}, |
| 236 | { "count", BOND_AD_COUNT}, |
| 237 | { NULL, -1}, |
| 238 | }; |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /*-------------------------- Forward declarations ---------------------------*/ |
| 241 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 242 | static void bond_send_gratuitous_arp(struct bonding *bond); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 243 | static int bond_init(struct net_device *bond_dev); |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 244 | static void bond_uninit(struct net_device *bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | /*---------------------------- General routines -----------------------------*/ |
| 247 | |
Adrian Bunk | 4ad072c | 2007-07-09 11:51:12 -0700 | [diff] [blame] | 248 | static const char *bond_mode_name(int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
Holger Eitzenberger | 77afc92 | 2008-12-09 23:08:09 -0800 | [diff] [blame] | 250 | static const char *names[] = { |
| 251 | [BOND_MODE_ROUNDROBIN] = "load balancing (round-robin)", |
| 252 | [BOND_MODE_ACTIVEBACKUP] = "fault-tolerance (active-backup)", |
| 253 | [BOND_MODE_XOR] = "load balancing (xor)", |
| 254 | [BOND_MODE_BROADCAST] = "fault-tolerance (broadcast)", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 255 | [BOND_MODE_8023AD] = "IEEE 802.3ad Dynamic link aggregation", |
Holger Eitzenberger | 77afc92 | 2008-12-09 23:08:09 -0800 | [diff] [blame] | 256 | [BOND_MODE_TLB] = "transmit load balancing", |
| 257 | [BOND_MODE_ALB] = "adaptive load balancing", |
| 258 | }; |
| 259 | |
| 260 | if (mode < 0 || mode > BOND_MODE_ALB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return "unknown"; |
Holger Eitzenberger | 77afc92 | 2008-12-09 23:08:09 -0800 | [diff] [blame] | 262 | |
| 263 | return names[mode]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /*---------------------------------- VLAN -----------------------------------*/ |
| 267 | |
| 268 | /** |
| 269 | * bond_add_vlan - add a new vlan id on bond |
| 270 | * @bond: bond that got the notification |
| 271 | * @vlan_id: the vlan id to add |
| 272 | * |
| 273 | * Returns -ENOMEM if allocation failed. |
| 274 | */ |
| 275 | static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id) |
| 276 | { |
| 277 | struct vlan_entry *vlan; |
| 278 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 279 | pr_debug("bond: %s, vlan id %d\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 280 | (bond ? bond->dev->name : "None"), vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 282 | vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 283 | if (!vlan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | INIT_LIST_HEAD(&vlan->vlan_list); |
| 287 | vlan->vlan_id = vlan_id; |
| 288 | |
| 289 | write_lock_bh(&bond->lock); |
| 290 | |
| 291 | list_add_tail(&vlan->vlan_list, &bond->vlan_list); |
| 292 | |
| 293 | write_unlock_bh(&bond->lock); |
| 294 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 295 | 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] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * bond_del_vlan - delete a vlan id from bond |
| 302 | * @bond: bond that got the notification |
| 303 | * @vlan_id: the vlan id to delete |
| 304 | * |
| 305 | * returns -ENODEV if @vlan_id was not found in @bond. |
| 306 | */ |
| 307 | static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id) |
| 308 | { |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 309 | struct vlan_entry *vlan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | int res = -ENODEV; |
| 311 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 312 | 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] | 313 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 314 | block_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | write_lock_bh(&bond->lock); |
| 316 | |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 317 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (vlan->vlan_id == vlan_id) { |
| 319 | list_del(&vlan->vlan_list); |
| 320 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 321 | if (bond_is_lb(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | bond_alb_clear_vlan(bond, vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 324 | pr_debug("removed VLAN ID %d from bond %s\n", |
| 325 | vlan_id, bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | kfree(vlan); |
| 328 | |
| 329 | if (list_empty(&bond->vlan_list) && |
| 330 | (bond->slave_cnt == 0)) { |
| 331 | /* Last VLAN removed and no slaves, so |
| 332 | * restore block on adding VLANs. This will |
| 333 | * be removed once new slaves that are not |
| 334 | * VLAN challenged will be added. |
| 335 | */ |
| 336 | bond->dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 337 | } |
| 338 | |
| 339 | res = 0; |
| 340 | goto out; |
| 341 | } |
| 342 | } |
| 343 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 344 | pr_debug("couldn't find VLAN ID %d in bond %s\n", |
| 345 | vlan_id, bond->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
| 347 | out: |
| 348 | write_unlock_bh(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 349 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return res; |
| 351 | } |
| 352 | |
| 353 | /** |
| 354 | * bond_has_challenged_slaves |
| 355 | * @bond: the bond we're working on |
| 356 | * |
| 357 | * Searches the slave list. Returns 1 if a vlan challenged slave |
| 358 | * was found, 0 otherwise. |
| 359 | * |
| 360 | * Assumes bond->lock is held. |
| 361 | */ |
| 362 | static int bond_has_challenged_slaves(struct bonding *bond) |
| 363 | { |
| 364 | struct slave *slave; |
| 365 | int i; |
| 366 | |
| 367 | bond_for_each_slave(bond, slave, i) { |
| 368 | if (slave->dev->features & NETIF_F_VLAN_CHALLENGED) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 369 | pr_debug("found VLAN challenged slave - %s\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 370 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return 1; |
| 372 | } |
| 373 | } |
| 374 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 375 | pr_debug("no VLAN challenged slaves found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * bond_next_vlan - safely skip to the next item in the vlans list. |
| 381 | * @bond: the bond we're working on |
| 382 | * @curr: item we're advancing from |
| 383 | * |
| 384 | * Returns %NULL if list is empty, bond->next_vlan if @curr is %NULL, |
| 385 | * or @curr->next otherwise (even if it is @curr itself again). |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 386 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | * Caller must hold bond->lock |
| 388 | */ |
| 389 | struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr) |
| 390 | { |
| 391 | struct vlan_entry *next, *last; |
| 392 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 393 | if (list_empty(&bond->vlan_list)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | if (!curr) { |
| 397 | next = list_entry(bond->vlan_list.next, |
| 398 | struct vlan_entry, vlan_list); |
| 399 | } else { |
| 400 | last = list_entry(bond->vlan_list.prev, |
| 401 | struct vlan_entry, vlan_list); |
| 402 | if (last == curr) { |
| 403 | next = list_entry(bond->vlan_list.next, |
| 404 | struct vlan_entry, vlan_list); |
| 405 | } else { |
| 406 | next = list_entry(curr->vlan_list.next, |
| 407 | struct vlan_entry, vlan_list); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return next; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * bond_dev_queue_xmit - Prepare skb for xmit. |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 416 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | * @bond: bond device that got this skb for tx. |
| 418 | * @skb: hw accel VLAN tagged skb to transmit |
| 419 | * @slave_dev: slave that is supposed to xmit this skbuff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 421 | int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, |
| 422 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
Ben Hutchings | 8387451 | 2010-12-13 08:19:28 +0000 | [diff] [blame] | 424 | skb->dev = slave_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | skb->priority = 1; |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 426 | if (unlikely(netpoll_tx_running(slave_dev))) { |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 427 | slave_dev->priv_flags |= IFF_IN_NETPOLL; |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 428 | bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 429 | slave_dev->priv_flags &= ~IFF_IN_NETPOLL; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 430 | } else |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 431 | dev_queue_xmit(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | /* |
| 437 | * In the following 3 functions, bond_vlan_rx_register(), bond_vlan_rx_add_vid |
| 438 | * and bond_vlan_rx_kill_vid, We don't protect the slave list iteration with a |
| 439 | * lock because: |
| 440 | * a. This operation is performed in IOCTL context, |
| 441 | * b. The operation is protected by the RTNL semaphore in the 8021q code, |
| 442 | * c. Holding a lock with BH disabled while directly calling a base driver |
| 443 | * entry point is generally a BAD idea. |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 444 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | * The design of synchronization/protection for this operation in the 8021q |
| 446 | * module is good for one or more VLAN devices over a single physical device |
| 447 | * and cannot be extended for a teaming solution like bonding, so there is a |
| 448 | * potential race condition here where a net device from the vlan group might |
| 449 | * be referenced (either by a base driver or the 8021q code) while it is being |
| 450 | * removed from the system. However, it turns out we're not making matters |
| 451 | * worse, and if it works for regular VLAN usage it will work here too. |
| 452 | */ |
| 453 | |
| 454 | /** |
| 455 | * bond_vlan_rx_register - Propagates registration to slaves |
| 456 | * @bond_dev: bonding net device that got called |
| 457 | * @grp: vlan group being registered |
| 458 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 459 | static void bond_vlan_rx_register(struct net_device *bond_dev, |
| 460 | struct vlan_group *grp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 462 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | struct slave *slave; |
| 464 | int i; |
| 465 | |
Jarek Poplawski | a71fb88 | 2010-10-27 07:08:22 +0000 | [diff] [blame] | 466 | write_lock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | bond->vlgrp = grp; |
Jarek Poplawski | a71fb88 | 2010-10-27 07:08:22 +0000 | [diff] [blame] | 468 | write_unlock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | bond_for_each_slave(bond, slave, i) { |
| 471 | struct net_device *slave_dev = slave->dev; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 472 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 475 | slave_ops->ndo_vlan_rx_register) { |
| 476 | slave_ops->ndo_vlan_rx_register(slave_dev, grp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * bond_vlan_rx_add_vid - Propagates adding an id to slaves |
| 483 | * @bond_dev: bonding net device that got called |
| 484 | * @vid: vlan id being added |
| 485 | */ |
| 486 | static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid) |
| 487 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 488 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | struct slave *slave; |
| 490 | int i, res; |
| 491 | |
| 492 | bond_for_each_slave(bond, slave, i) { |
| 493 | struct net_device *slave_dev = slave->dev; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 494 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | |
| 496 | if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 497 | slave_ops->ndo_vlan_rx_add_vid) { |
| 498 | slave_ops->ndo_vlan_rx_add_vid(slave_dev, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | res = bond_add_vlan(bond, vid); |
| 503 | if (res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 504 | pr_err("%s: Error: Failed to add vlan id %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | bond_dev->name, vid); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves |
| 511 | * @bond_dev: bonding net device that got called |
| 512 | * @vid: vlan id being removed |
| 513 | */ |
| 514 | static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid) |
| 515 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 516 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | struct slave *slave; |
| 518 | struct net_device *vlan_dev; |
| 519 | int i, res; |
| 520 | |
| 521 | bond_for_each_slave(bond, slave, i) { |
| 522 | struct net_device *slave_dev = slave->dev; |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 523 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | if ((slave_dev->features & NETIF_F_HW_VLAN_FILTER) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 526 | slave_ops->ndo_vlan_rx_kill_vid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | /* Save and then restore vlan_dev in the grp array, |
| 528 | * since the slave's driver might clear it. |
| 529 | */ |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 530 | vlan_dev = vlan_group_get_device(bond->vlgrp, vid); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 531 | slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vid); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 532 | vlan_group_set_device(bond->vlgrp, vid, vlan_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
| 536 | res = bond_del_vlan(bond, vid); |
| 537 | if (res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 538 | pr_err("%s: Error: Failed to remove vlan id %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | bond_dev->name, vid); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | static void bond_add_vlans_on_slave(struct bonding *bond, struct net_device *slave_dev) |
| 544 | { |
| 545 | struct vlan_entry *vlan; |
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 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 548 | if (!bond->vlgrp) |
Jay Vosburgh | 03dc2f4 | 2010-07-21 12:14:48 +0000 | [diff] [blame] | 549 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 552 | slave_ops->ndo_vlan_rx_register) |
| 553 | slave_ops->ndo_vlan_rx_register(slave_dev, bond->vlgrp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) || |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 556 | !(slave_ops->ndo_vlan_rx_add_vid)) |
Jay Vosburgh | 03dc2f4 | 2010-07-21 12:14:48 +0000 | [diff] [blame] | 557 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 559 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) |
| 560 | slave_ops->ndo_vlan_rx_add_vid(slave_dev, vlan->vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 563 | static void bond_del_vlans_from_slave(struct bonding *bond, |
| 564 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 566 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | struct vlan_entry *vlan; |
| 568 | struct net_device *vlan_dev; |
| 569 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 570 | if (!bond->vlgrp) |
Jay Vosburgh | 03dc2f4 | 2010-07-21 12:14:48 +0000 | [diff] [blame] | 571 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | if (!(slave_dev->features & NETIF_F_HW_VLAN_FILTER) || |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 574 | !(slave_ops->ndo_vlan_rx_kill_vid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | goto unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 578 | if (!vlan->vlan_id) |
| 579 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | /* Save and then restore vlan_dev in the grp array, |
| 581 | * since the slave's driver might clear it. |
| 582 | */ |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 583 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 584 | slave_ops->ndo_vlan_rx_kill_vid(slave_dev, vlan->vlan_id); |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 585 | vlan_group_set_device(bond->vlgrp, vlan->vlan_id, vlan_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | unreg: |
| 589 | if ((slave_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 590 | slave_ops->ndo_vlan_rx_register) |
| 591 | slave_ops->ndo_vlan_rx_register(slave_dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /*------------------------------- Link status -------------------------------*/ |
| 595 | |
| 596 | /* |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 597 | * Set the carrier state for the master according to the state of its |
| 598 | * slaves. If any slaves are up, the master is up. In 802.3ad mode, |
| 599 | * do special 802.3ad magic. |
| 600 | * |
| 601 | * Returns zero if carrier state does not change, nonzero if it does. |
| 602 | */ |
| 603 | static int bond_set_carrier(struct bonding *bond) |
| 604 | { |
| 605 | struct slave *slave; |
| 606 | int i; |
| 607 | |
| 608 | if (bond->slave_cnt == 0) |
| 609 | goto down; |
| 610 | |
| 611 | if (bond->params.mode == BOND_MODE_8023AD) |
| 612 | return bond_3ad_set_carrier(bond); |
| 613 | |
| 614 | bond_for_each_slave(bond, slave, i) { |
| 615 | if (slave->link == BOND_LINK_UP) { |
| 616 | if (!netif_carrier_ok(bond->dev)) { |
| 617 | netif_carrier_on(bond->dev); |
| 618 | return 1; |
| 619 | } |
| 620 | return 0; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | down: |
| 625 | if (netif_carrier_ok(bond->dev)) { |
| 626 | netif_carrier_off(bond->dev); |
| 627 | return 1; |
| 628 | } |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | * Get link speed and duplex from the slave's base driver |
| 634 | * using ethtool. If for some reason the call fails or the |
| 635 | * values are invalid, fake speed and duplex to 100/Full |
| 636 | * and return error. |
| 637 | */ |
| 638 | static int bond_update_speed_duplex(struct slave *slave) |
| 639 | { |
| 640 | struct net_device *slave_dev = slave->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | struct ethtool_cmd etool; |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 642 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | /* Fake speed and duplex */ |
| 645 | slave->speed = SPEED_100; |
| 646 | slave->duplex = DUPLEX_FULL; |
| 647 | |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 648 | if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 651 | res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool); |
| 652 | if (res < 0) |
| 653 | return -1; |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | switch (etool.speed) { |
| 656 | case SPEED_10: |
| 657 | case SPEED_100: |
| 658 | case SPEED_1000: |
Jay Vosburgh | 94dbffd | 2006-09-22 21:52:15 -0700 | [diff] [blame] | 659 | case SPEED_10000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | break; |
| 661 | default: |
| 662 | return -1; |
| 663 | } |
| 664 | |
| 665 | switch (etool.duplex) { |
| 666 | case DUPLEX_FULL: |
| 667 | case DUPLEX_HALF: |
| 668 | break; |
| 669 | default: |
| 670 | return -1; |
| 671 | } |
| 672 | |
| 673 | slave->speed = etool.speed; |
| 674 | slave->duplex = etool.duplex; |
| 675 | |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | /* |
| 680 | * if <dev> supports MII link status reporting, check its link status. |
| 681 | * |
| 682 | * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(), |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 683 | * depending upon the setting of the use_carrier parameter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | * |
| 685 | * Return either BMSR_LSTATUS, meaning that the link is up (or we |
| 686 | * can't tell and just pretend it is), or 0, meaning that the link is |
| 687 | * down. |
| 688 | * |
| 689 | * If reporting is non-zero, instead of faking link up, return -1 if |
| 690 | * both ETHTOOL and MII ioctls fail (meaning the device does not |
| 691 | * support them). If use_carrier is set, return whatever it says. |
| 692 | * It'd be nice if there was a good way to tell if a driver supports |
| 693 | * netif_carrier, but there really isn't. |
| 694 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 695 | static int bond_check_dev_link(struct bonding *bond, |
| 696 | struct net_device *slave_dev, int reporting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 698 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Jiri Bohac | d9d5283 | 2009-10-28 22:23:54 -0700 | [diff] [blame] | 699 | int (*ioctl)(struct net_device *, struct ifreq *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | struct ifreq ifr; |
| 701 | struct mii_ioctl_data *mii; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | |
Petri Gynther | 6c98885 | 2009-08-28 12:05:15 +0000 | [diff] [blame] | 703 | if (!reporting && !netif_running(slave_dev)) |
| 704 | return 0; |
| 705 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 706 | if (bond->params.use_carrier) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Jiri Pirko | 29112f4 | 2009-04-24 01:58:23 +0000 | [diff] [blame] | 709 | /* Try to get link status using Ethtool first. */ |
| 710 | if (slave_dev->ethtool_ops) { |
| 711 | if (slave_dev->ethtool_ops->get_link) { |
| 712 | u32 link; |
| 713 | |
| 714 | link = slave_dev->ethtool_ops->get_link(slave_dev); |
| 715 | |
| 716 | return link ? BMSR_LSTATUS : 0; |
| 717 | } |
| 718 | } |
| 719 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 720 | /* Ethtool can't be used, fallback to MII ioctls. */ |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 721 | ioctl = slave_ops->ndo_do_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | if (ioctl) { |
| 723 | /* TODO: set pointer to correct ioctl on a per team member */ |
| 724 | /* bases to make this more efficient. that is, once */ |
| 725 | /* we determine the correct ioctl, we will always */ |
| 726 | /* call it and not the others for that team */ |
| 727 | /* member. */ |
| 728 | |
| 729 | /* |
| 730 | * We cannot assume that SIOCGMIIPHY will also read a |
| 731 | * register; not all network drivers (e.g., e100) |
| 732 | * support that. |
| 733 | */ |
| 734 | |
| 735 | /* Yes, the mii is overlaid on the ifreq.ifr_ifru */ |
| 736 | strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ); |
| 737 | mii = if_mii(&ifr); |
| 738 | if (IOCTL(slave_dev, &ifr, SIOCGMIIPHY) == 0) { |
| 739 | mii->reg_num = MII_BMSR; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 740 | if (IOCTL(slave_dev, &ifr, SIOCGMIIREG) == 0) |
| 741 | return mii->val_out & BMSR_LSTATUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 745 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | * If reporting, report that either there's no dev->do_ioctl, |
Matthew Wilcox | 61a44b9 | 2007-07-31 14:00:02 -0700 | [diff] [blame] | 747 | * or both SIOCGMIIREG and get_link failed (meaning that we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | * cannot report link status). If not reporting, pretend |
| 749 | * we're ok. |
| 750 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 751 | return reporting ? -1 : BMSR_LSTATUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /*----------------------------- Multicast list ------------------------------*/ |
| 755 | |
| 756 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | * Push the promiscuity flag down to appropriate slaves |
| 758 | */ |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 759 | static int bond_set_promiscuity(struct bonding *bond, int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 761 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | if (USES_PRIMARY(bond->params.mode)) { |
| 763 | /* write lock already acquired */ |
| 764 | if (bond->curr_active_slave) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 765 | err = dev_set_promiscuity(bond->curr_active_slave->dev, |
| 766 | inc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
| 768 | } else { |
| 769 | struct slave *slave; |
| 770 | int i; |
| 771 | bond_for_each_slave(bond, slave, i) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 772 | err = dev_set_promiscuity(slave->dev, inc); |
| 773 | if (err) |
| 774 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | } |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 777 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /* |
| 781 | * Push the allmulti flag down to all slaves |
| 782 | */ |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 783 | static int bond_set_allmulti(struct bonding *bond, int inc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 785 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | if (USES_PRIMARY(bond->params.mode)) { |
| 787 | /* write lock already acquired */ |
| 788 | if (bond->curr_active_slave) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 789 | err = dev_set_allmulti(bond->curr_active_slave->dev, |
| 790 | inc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
| 792 | } else { |
| 793 | struct slave *slave; |
| 794 | int i; |
| 795 | bond_for_each_slave(bond, slave, i) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 796 | err = dev_set_allmulti(slave->dev, inc); |
| 797 | if (err) |
| 798 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | } |
| 800 | } |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 801 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | /* |
| 805 | * Add a Multicast address to slaves |
| 806 | * according to mode |
| 807 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 808 | static void bond_mc_add(struct bonding *bond, void *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
| 810 | if (USES_PRIMARY(bond->params.mode)) { |
| 811 | /* write lock already acquired */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 812 | if (bond->curr_active_slave) |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 813 | dev_mc_add(bond->curr_active_slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | } else { |
| 815 | struct slave *slave; |
| 816 | int i; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 817 | |
| 818 | bond_for_each_slave(bond, slave, i) |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 819 | dev_mc_add(slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | * Remove a multicast address from slave |
| 825 | * according to mode |
| 826 | */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 827 | static void bond_mc_del(struct bonding *bond, void *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
| 829 | if (USES_PRIMARY(bond->params.mode)) { |
| 830 | /* write lock already acquired */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 831 | if (bond->curr_active_slave) |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 832 | dev_mc_del(bond->curr_active_slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } else { |
| 834 | struct slave *slave; |
| 835 | int i; |
| 836 | bond_for_each_slave(bond, slave, i) { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 837 | dev_mc_del(slave->dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | } |
| 841 | |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 842 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 843 | static void __bond_resend_igmp_join_requests(struct net_device *dev) |
| 844 | { |
| 845 | struct in_device *in_dev; |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 846 | |
| 847 | rcu_read_lock(); |
| 848 | in_dev = __in_dev_get_rcu(dev); |
Eric Dumazet | 866f3b2 | 2010-11-18 09:33:19 -0800 | [diff] [blame] | 849 | if (in_dev) |
David S. Miller | 2491242 | 2010-11-19 13:13:47 -0800 | [diff] [blame] | 850 | ip_mc_rejoin_groups(in_dev); |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 851 | rcu_read_unlock(); |
| 852 | } |
| 853 | |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 854 | /* |
| 855 | * Retrieve the list of registered multicast addresses for the bonding |
| 856 | * device and retransmit an IGMP JOIN request to the current active |
| 857 | * slave. |
| 858 | */ |
| 859 | static void bond_resend_igmp_join_requests(struct bonding *bond) |
| 860 | { |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 861 | struct net_device *vlan_dev; |
| 862 | struct vlan_entry *vlan; |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 863 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 864 | read_lock(&bond->lock); |
| 865 | |
| 866 | /* rejoin all groups on bond device */ |
| 867 | __bond_resend_igmp_join_requests(bond->dev); |
| 868 | |
| 869 | /* rejoin all groups on vlan devices */ |
| 870 | if (bond->vlgrp) { |
| 871 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
| 872 | vlan_dev = vlan_group_get_device(bond->vlgrp, |
| 873 | vlan->vlan_id); |
| 874 | if (vlan_dev) |
| 875 | __bond_resend_igmp_join_requests(vlan_dev); |
| 876 | } |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 877 | } |
| 878 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 879 | if (--bond->igmp_retrans > 0) |
| 880 | queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5); |
| 881 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 882 | read_unlock(&bond->lock); |
| 883 | } |
| 884 | |
stephen hemminger | 379b738 | 2010-10-15 11:02:56 +0000 | [diff] [blame] | 885 | static void bond_resend_igmp_join_requests_delayed(struct work_struct *work) |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 886 | { |
| 887 | struct bonding *bond = container_of(work, struct bonding, |
| 888 | mcast_work.work); |
| 889 | bond_resend_igmp_join_requests(bond); |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 890 | } |
| 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | * flush all members of flush->mc_list from device dev->mc_list |
| 894 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 895 | static void bond_mc_list_flush(struct net_device *bond_dev, |
| 896 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 898 | struct bonding *bond = netdev_priv(bond_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 899 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 901 | netdev_for_each_mc_addr(ha, bond_dev) |
| 902 | dev_mc_del(slave_dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 905 | /* del lacpdu mc addr from mc list */ |
| 906 | u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
| 907 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 908 | dev_mc_del(slave_dev, lacpdu_multicast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | |
| 912 | /*--------------------------- Active slave change ---------------------------*/ |
| 913 | |
| 914 | /* |
| 915 | * Update the mc list and multicast-related flags for the new and |
| 916 | * old active slaves (if any) according to the multicast mode, and |
| 917 | * promiscuous flags unconditionally. |
| 918 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 919 | static void bond_mc_swap(struct bonding *bond, struct slave *new_active, |
| 920 | struct slave *old_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 922 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 924 | if (!USES_PRIMARY(bond->params.mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | /* nothing to do - mc list is already up-to-date on |
| 926 | * all slaves |
| 927 | */ |
| 928 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
| 930 | if (old_active) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 931 | if (bond->dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | dev_set_promiscuity(old_active->dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 934 | if (bond->dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | dev_set_allmulti(old_active->dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 937 | netdev_for_each_mc_addr(ha, bond->dev) |
| 938 | dev_mc_del(old_active->dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | if (new_active) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 942 | /* FIXME: Signal errors upstream. */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 943 | if (bond->dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | dev_set_promiscuity(new_active->dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 946 | if (bond->dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | dev_set_allmulti(new_active->dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 949 | netdev_for_each_mc_addr(ha, bond->dev) |
| 950 | dev_mc_add(new_active->dev, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 954 | /* |
| 955 | * bond_do_fail_over_mac |
| 956 | * |
| 957 | * Perform special MAC address swapping for fail_over_mac settings |
| 958 | * |
| 959 | * Called with RTNL, bond->lock for read, curr_slave_lock for write_bh. |
| 960 | */ |
| 961 | static void bond_do_fail_over_mac(struct bonding *bond, |
| 962 | struct slave *new_active, |
| 963 | struct slave *old_active) |
Hannes Eder | 1f78d9f | 2009-02-14 11:15:33 +0000 | [diff] [blame] | 964 | __releases(&bond->curr_slave_lock) |
| 965 | __releases(&bond->lock) |
| 966 | __acquires(&bond->lock) |
| 967 | __acquires(&bond->curr_slave_lock) |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 968 | { |
| 969 | u8 tmp_mac[ETH_ALEN]; |
| 970 | struct sockaddr saddr; |
| 971 | int rv; |
| 972 | |
| 973 | switch (bond->params.fail_over_mac) { |
| 974 | case BOND_FOM_ACTIVE: |
| 975 | if (new_active) |
| 976 | memcpy(bond->dev->dev_addr, new_active->dev->dev_addr, |
| 977 | new_active->dev->addr_len); |
| 978 | break; |
| 979 | case BOND_FOM_FOLLOW: |
| 980 | /* |
| 981 | * if new_active && old_active, swap them |
| 982 | * if just old_active, do nothing (going to no active slave) |
| 983 | * if just new_active, set new_active to bond's MAC |
| 984 | */ |
| 985 | if (!new_active) |
| 986 | return; |
| 987 | |
| 988 | write_unlock_bh(&bond->curr_slave_lock); |
| 989 | read_unlock(&bond->lock); |
| 990 | |
| 991 | if (old_active) { |
| 992 | memcpy(tmp_mac, new_active->dev->dev_addr, ETH_ALEN); |
| 993 | memcpy(saddr.sa_data, old_active->dev->dev_addr, |
| 994 | ETH_ALEN); |
| 995 | saddr.sa_family = new_active->dev->type; |
| 996 | } else { |
| 997 | memcpy(saddr.sa_data, bond->dev->dev_addr, ETH_ALEN); |
| 998 | saddr.sa_family = bond->dev->type; |
| 999 | } |
| 1000 | |
| 1001 | rv = dev_set_mac_address(new_active->dev, &saddr); |
| 1002 | if (rv) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1003 | pr_err("%s: Error %d setting MAC of slave %s\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1004 | bond->dev->name, -rv, new_active->dev->name); |
| 1005 | goto out; |
| 1006 | } |
| 1007 | |
| 1008 | if (!old_active) |
| 1009 | goto out; |
| 1010 | |
| 1011 | memcpy(saddr.sa_data, tmp_mac, ETH_ALEN); |
| 1012 | saddr.sa_family = old_active->dev->type; |
| 1013 | |
| 1014 | rv = dev_set_mac_address(old_active->dev, &saddr); |
| 1015 | if (rv) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1016 | pr_err("%s: Error %d setting MAC of slave %s\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1017 | bond->dev->name, -rv, new_active->dev->name); |
| 1018 | out: |
| 1019 | read_lock(&bond->lock); |
| 1020 | write_lock_bh(&bond->curr_slave_lock); |
| 1021 | break; |
| 1022 | default: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1023 | 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] | 1024 | bond->dev->name, bond->params.fail_over_mac); |
| 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | } |
| 1029 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1030 | static bool bond_should_change_active(struct bonding *bond) |
| 1031 | { |
| 1032 | struct slave *prim = bond->primary_slave; |
| 1033 | struct slave *curr = bond->curr_active_slave; |
| 1034 | |
| 1035 | if (!prim || !curr || curr->link != BOND_LINK_UP) |
| 1036 | return true; |
| 1037 | if (bond->force_primary) { |
| 1038 | bond->force_primary = false; |
| 1039 | return true; |
| 1040 | } |
| 1041 | if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER && |
| 1042 | (prim->speed < curr->speed || |
| 1043 | (prim->speed == curr->speed && prim->duplex <= curr->duplex))) |
| 1044 | return false; |
| 1045 | if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE) |
| 1046 | return false; |
| 1047 | return true; |
| 1048 | } |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | /** |
| 1051 | * find_best_interface - select the best available slave to be the active one |
| 1052 | * @bond: our bonding struct |
| 1053 | * |
| 1054 | * Warning: Caller must hold curr_slave_lock for writing. |
| 1055 | */ |
| 1056 | static struct slave *bond_find_best_slave(struct bonding *bond) |
| 1057 | { |
| 1058 | struct slave *new_active, *old_active; |
| 1059 | struct slave *bestslave = NULL; |
| 1060 | int mintime = bond->params.updelay; |
| 1061 | int i; |
| 1062 | |
Nicolas de Pesloüan | 49b4ad9 | 2009-10-07 14:11:00 -0700 | [diff] [blame] | 1063 | new_active = bond->curr_active_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | if (!new_active) { /* there were no active slaves left */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1066 | if (bond->slave_cnt > 0) /* found one slave */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | new_active = bond->first_slave; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1068 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | return NULL; /* still no slave, return NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | if ((bond->primary_slave) && |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1073 | bond->primary_slave->link == BOND_LINK_UP && |
| 1074 | bond_should_change_active(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | new_active = bond->primary_slave; |
| 1076 | } |
| 1077 | |
| 1078 | /* remember where to stop iterating over the slaves */ |
| 1079 | old_active = new_active; |
| 1080 | |
| 1081 | bond_for_each_slave_from(bond, new_active, i, old_active) { |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 1082 | if (new_active->link == BOND_LINK_UP) { |
| 1083 | return new_active; |
| 1084 | } else if (new_active->link == BOND_LINK_BACK && |
| 1085 | IS_UP(new_active->dev)) { |
| 1086 | /* link up, but waiting for stabilization */ |
| 1087 | if (new_active->delay < mintime) { |
| 1088 | mintime = new_active->delay; |
| 1089 | bestslave = new_active; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | return bestslave; |
| 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * change_active_interface - change the active slave into the specified one |
| 1099 | * @bond: our bonding struct |
| 1100 | * @new: the new slave to make the active one |
| 1101 | * |
| 1102 | * Set the new slave to the bond's settings and unset them on the old |
| 1103 | * curr_active_slave. |
| 1104 | * Setting include flags, mc-list, promiscuity, allmulti, etc. |
| 1105 | * |
| 1106 | * If @new's link state is %BOND_LINK_BACK we'll set it to %BOND_LINK_UP, |
| 1107 | * because it is apparently the best available slave we have, even though its |
| 1108 | * updelay hasn't timed out yet. |
| 1109 | * |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1110 | * If new_active is not NULL, caller must hold bond->lock for read and |
| 1111 | * curr_slave_lock for write_bh. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1113 | void bond_change_active_slave(struct bonding *bond, struct slave *new_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | { |
| 1115 | struct slave *old_active = bond->curr_active_slave; |
| 1116 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1117 | if (old_active == new_active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (new_active) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 1121 | new_active->jiffies = jiffies; |
| 1122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | if (new_active->link == BOND_LINK_BACK) { |
| 1124 | if (USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1125 | pr_info("%s: making interface %s the new active one %d ms earlier.\n", |
| 1126 | bond->dev->name, new_active->dev->name, |
| 1127 | (bond->params.updelay - new_active->delay) * bond->params.miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | new_active->delay = 0; |
| 1131 | new_active->link = BOND_LINK_UP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1133 | if (bond->params.mode == BOND_MODE_8023AD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | bond_3ad_handle_link_change(new_active, BOND_LINK_UP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1136 | if (bond_is_lb(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | } else { |
| 1139 | if (USES_PRIMARY(bond->params.mode)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1140 | pr_info("%s: making interface %s the new active one.\n", |
| 1141 | bond->dev->name, new_active->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | } |
| 1145 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1146 | if (USES_PRIMARY(bond->params.mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | bond_mc_swap(bond, new_active, old_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1149 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | bond_alb_handle_active_change(bond, new_active); |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 1151 | if (old_active) |
| 1152 | bond_set_slave_inactive_flags(old_active); |
| 1153 | if (new_active) |
| 1154 | bond_set_slave_active_flags(new_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | } else { |
| 1156 | bond->curr_active_slave = new_active; |
| 1157 | } |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1158 | |
| 1159 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1160 | if (old_active) |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1161 | bond_set_slave_inactive_flags(old_active); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1162 | |
| 1163 | if (new_active) { |
| 1164 | bond_set_slave_active_flags(new_active); |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1165 | |
Or Gerlitz | 709f8a4 | 2008-06-13 18:12:01 -0700 | [diff] [blame] | 1166 | if (bond->params.fail_over_mac) |
| 1167 | bond_do_fail_over_mac(bond, new_active, |
| 1168 | old_active); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1169 | |
Ben Hutchings | ffa95ed | 2010-12-13 08:19:56 +0000 | [diff] [blame] | 1170 | if (netif_running(bond->dev)) { |
| 1171 | bond->send_grat_arp = bond->params.num_grat_arp; |
| 1172 | bond_send_gratuitous_arp(bond); |
Or Gerlitz | 01f3109 | 2008-06-13 18:12:02 -0700 | [diff] [blame] | 1173 | |
Ben Hutchings | ffa95ed | 2010-12-13 08:19:56 +0000 | [diff] [blame] | 1174 | bond->send_unsol_na = bond->params.num_unsol_na; |
| 1175 | bond_send_unsolicited_na(bond); |
| 1176 | } |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 1177 | |
Or Gerlitz | 01f3109 | 2008-06-13 18:12:02 -0700 | [diff] [blame] | 1178 | write_unlock_bh(&bond->curr_slave_lock); |
| 1179 | read_unlock(&bond->lock); |
| 1180 | |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1181 | netdev_bonding_change(bond->dev, NETDEV_BONDING_FAILOVER); |
Or Gerlitz | 01f3109 | 2008-06-13 18:12:02 -0700 | [diff] [blame] | 1182 | |
| 1183 | read_lock(&bond->lock); |
| 1184 | write_lock_bh(&bond->curr_slave_lock); |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 1185 | } |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 1186 | } |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 1187 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 1188 | /* resend IGMP joins since active slave has changed or |
| 1189 | * all were sent on curr_active_slave */ |
Ben Hutchings | ffa95ed | 2010-12-13 08:19:56 +0000 | [diff] [blame] | 1190 | if (((USES_PRIMARY(bond->params.mode) && new_active) || |
| 1191 | bond->params.mode == BOND_MODE_ROUNDROBIN) && |
| 1192 | netif_running(bond->dev)) { |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 1193 | bond->igmp_retrans = bond->params.resend_igmp; |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 1194 | queue_delayed_work(bond->wq, &bond->mcast_work, 0); |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 1195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * bond_select_active_slave - select a new active slave, if needed |
| 1200 | * @bond: our bonding struct |
| 1201 | * |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1202 | * This functions should be called when one of the following occurs: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | * - The old curr_active_slave has been released or lost its link. |
| 1204 | * - The primary_slave has got its link back. |
| 1205 | * - A slave has got its link back and there's no old curr_active_slave. |
| 1206 | * |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1207 | * 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] | 1208 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1209 | void bond_select_active_slave(struct bonding *bond) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | { |
| 1211 | struct slave *best_slave; |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1212 | int rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | best_slave = bond_find_best_slave(bond); |
| 1215 | if (best_slave != bond->curr_active_slave) { |
| 1216 | bond_change_active_slave(bond, best_slave); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1217 | rv = bond_set_carrier(bond); |
| 1218 | if (!rv) |
| 1219 | return; |
| 1220 | |
| 1221 | if (netif_carrier_ok(bond->dev)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1222 | pr_info("%s: first active interface up!\n", |
| 1223 | bond->dev->name); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1224 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1225 | pr_info("%s: now running without any active interface !\n", |
| 1226 | bond->dev->name); |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1227 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | /*--------------------------- slave list handling ---------------------------*/ |
| 1232 | |
| 1233 | /* |
| 1234 | * This function attaches the slave to the end of list. |
| 1235 | * |
| 1236 | * bond->lock held for writing by caller. |
| 1237 | */ |
| 1238 | static void bond_attach_slave(struct bonding *bond, struct slave *new_slave) |
| 1239 | { |
| 1240 | if (bond->first_slave == NULL) { /* attaching the first slave */ |
| 1241 | new_slave->next = new_slave; |
| 1242 | new_slave->prev = new_slave; |
| 1243 | bond->first_slave = new_slave; |
| 1244 | } else { |
| 1245 | new_slave->next = bond->first_slave; |
| 1246 | new_slave->prev = bond->first_slave->prev; |
| 1247 | new_slave->next->prev = new_slave; |
| 1248 | new_slave->prev->next = new_slave; |
| 1249 | } |
| 1250 | |
| 1251 | bond->slave_cnt++; |
| 1252 | } |
| 1253 | |
| 1254 | /* |
| 1255 | * This function detaches the slave from the list. |
| 1256 | * WARNING: no check is made to verify if the slave effectively |
| 1257 | * belongs to <bond>. |
| 1258 | * Nothing is freed on return, structures are just unchained. |
| 1259 | * If any slave pointer in bond was pointing to <slave>, |
| 1260 | * it should be changed by the calling function. |
| 1261 | * |
| 1262 | * bond->lock held for writing by caller. |
| 1263 | */ |
| 1264 | static void bond_detach_slave(struct bonding *bond, struct slave *slave) |
| 1265 | { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1266 | if (slave->next) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | slave->next->prev = slave->prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1269 | if (slave->prev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | slave->prev->next = slave->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
| 1272 | if (bond->first_slave == slave) { /* slave is the first slave */ |
| 1273 | if (bond->slave_cnt > 1) { /* there are more slave */ |
| 1274 | bond->first_slave = slave->next; |
| 1275 | } else { |
| 1276 | bond->first_slave = NULL; /* slave was the last one */ |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | slave->next = NULL; |
| 1281 | slave->prev = NULL; |
| 1282 | bond->slave_cnt--; |
| 1283 | } |
| 1284 | |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1285 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1286 | static inline int slave_enable_netpoll(struct slave *slave) |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1287 | { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1288 | struct netpoll *np; |
| 1289 | int err = 0; |
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 | np = kzalloc(sizeof(*np), GFP_KERNEL); |
| 1292 | err = -ENOMEM; |
| 1293 | if (!np) |
| 1294 | goto out; |
| 1295 | |
| 1296 | np->dev = slave->dev; |
| 1297 | err = __netpoll_setup(np); |
| 1298 | if (err) { |
| 1299 | kfree(np); |
| 1300 | goto out; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1301 | } |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1302 | slave->np = np; |
| 1303 | out: |
| 1304 | return err; |
| 1305 | } |
| 1306 | static inline void slave_disable_netpoll(struct slave *slave) |
| 1307 | { |
| 1308 | struct netpoll *np = slave->np; |
| 1309 | |
| 1310 | if (!np) |
| 1311 | return; |
| 1312 | |
| 1313 | slave->np = NULL; |
| 1314 | synchronize_rcu_bh(); |
| 1315 | __netpoll_cleanup(np); |
| 1316 | kfree(np); |
| 1317 | } |
| 1318 | static inline bool slave_dev_support_netpoll(struct net_device *slave_dev) |
| 1319 | { |
| 1320 | if (slave_dev->priv_flags & IFF_DISABLE_NETPOLL) |
| 1321 | return false; |
| 1322 | if (!slave_dev->netdev_ops->ndo_poll_controller) |
| 1323 | return false; |
| 1324 | return true; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | static void bond_poll_controller(struct net_device *bond_dev) |
| 1328 | { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1329 | } |
| 1330 | |
| 1331 | static void __bond_netpoll_cleanup(struct bonding *bond) |
| 1332 | { |
Neil Horman | c2355e1 | 2010-10-13 16:01:49 +0000 | [diff] [blame] | 1333 | struct slave *slave; |
| 1334 | int i; |
| 1335 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1336 | bond_for_each_slave(bond, slave, i) |
| 1337 | if (IS_UP(slave->dev)) |
| 1338 | slave_disable_netpoll(slave); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1339 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1340 | static void bond_netpoll_cleanup(struct net_device *bond_dev) |
| 1341 | { |
| 1342 | struct bonding *bond = netdev_priv(bond_dev); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1343 | |
| 1344 | read_lock(&bond->lock); |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1345 | __bond_netpoll_cleanup(bond); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1346 | read_unlock(&bond->lock); |
| 1347 | } |
| 1348 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1349 | static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni) |
| 1350 | { |
| 1351 | struct bonding *bond = netdev_priv(dev); |
| 1352 | struct slave *slave; |
| 1353 | int i, err = 0; |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1354 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1355 | read_lock(&bond->lock); |
| 1356 | bond_for_each_slave(bond, slave, i) { |
| 1357 | if (!IS_UP(slave->dev)) |
| 1358 | continue; |
| 1359 | err = slave_enable_netpoll(slave); |
| 1360 | if (err) { |
| 1361 | __bond_netpoll_cleanup(bond); |
| 1362 | break; |
| 1363 | } |
| 1364 | } |
| 1365 | read_unlock(&bond->lock); |
| 1366 | return err; |
| 1367 | } |
| 1368 | |
| 1369 | static struct netpoll_info *bond_netpoll_info(struct bonding *bond) |
| 1370 | { |
| 1371 | return bond->dev->npinfo; |
| 1372 | } |
| 1373 | |
| 1374 | #else |
| 1375 | static inline int slave_enable_netpoll(struct slave *slave) |
| 1376 | { |
| 1377 | return 0; |
| 1378 | } |
| 1379 | static inline void slave_disable_netpoll(struct slave *slave) |
| 1380 | { |
| 1381 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1382 | static void bond_netpoll_cleanup(struct net_device *bond_dev) |
| 1383 | { |
| 1384 | } |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1385 | static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni) |
| 1386 | { |
| 1387 | return 0; |
| 1388 | } |
| 1389 | static struct netpoll_info *bond_netpoll_info(struct bonding *bond) |
| 1390 | { |
| 1391 | return NULL; |
| 1392 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1393 | #endif |
| 1394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | /*---------------------------------- IOCTL ----------------------------------*/ |
| 1396 | |
Adrian Bunk | 4ad072c | 2007-07-09 11:51:12 -0700 | [diff] [blame] | 1397 | static int bond_sethwaddr(struct net_device *bond_dev, |
| 1398 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1400 | pr_debug("bond_dev=%p\n", bond_dev); |
| 1401 | pr_debug("slave_dev=%p\n", slave_dev); |
| 1402 | pr_debug("slave_dev->addr_len=%d\n", slave_dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len); |
| 1404 | return 0; |
| 1405 | } |
| 1406 | |
Herbert Xu | 7f353bf | 2007-08-10 15:47:58 -0700 | [diff] [blame] | 1407 | #define BOND_VLAN_FEATURES \ |
| 1408 | (NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | \ |
| 1409 | NETIF_F_HW_VLAN_FILTER) |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1410 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1411 | /* |
Jay Vosburgh | 8e3babc | 2005-11-04 18:45:45 -0800 | [diff] [blame] | 1412 | * Compute the common dev->feature set available to all slaves. Some |
Herbert Xu | 7f353bf | 2007-08-10 15:47:58 -0700 | [diff] [blame] | 1413 | * feature bits are managed elsewhere, so preserve those feature bits |
| 1414 | * on the master device. |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1415 | */ |
| 1416 | static int bond_compute_features(struct bonding *bond) |
| 1417 | { |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1418 | struct slave *slave; |
| 1419 | struct net_device *bond_dev = bond->dev; |
Michał Mirosław | 04ed3e7 | 2011-01-24 15:32:47 -0800 | [diff] [blame] | 1420 | u32 features = bond_dev->features; |
| 1421 | u32 vlan_features = 0; |
Moni Shoua | 3158bf7 | 2007-10-09 19:43:41 -0700 | [diff] [blame] | 1422 | unsigned short max_hard_header_len = max((u16)ETH_HLEN, |
| 1423 | bond_dev->hard_header_len); |
Jay Vosburgh | 8e3babc | 2005-11-04 18:45:45 -0800 | [diff] [blame] | 1424 | int i; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1425 | |
Herbert Xu | 7f353bf | 2007-08-10 15:47:58 -0700 | [diff] [blame] | 1426 | features &= ~(NETIF_F_ALL_CSUM | BOND_VLAN_FEATURES); |
Herbert Xu | b63365a | 2008-10-23 01:11:29 -0700 | [diff] [blame] | 1427 | features |= NETIF_F_GSO_MASK | NETIF_F_NO_CSUM; |
| 1428 | |
| 1429 | if (!bond->first_slave) |
| 1430 | goto done; |
| 1431 | |
| 1432 | features &= ~NETIF_F_ONE_FOR_ALL; |
Herbert Xu | 7f353bf | 2007-08-10 15:47:58 -0700 | [diff] [blame] | 1433 | |
Jay Vosburgh | 278339a | 2009-08-28 12:05:12 +0000 | [diff] [blame] | 1434 | vlan_features = bond->first_slave->dev->vlan_features; |
Jay Vosburgh | 54ef313 | 2006-09-22 21:53:39 -0700 | [diff] [blame] | 1435 | bond_for_each_slave(bond, slave, i) { |
Herbert Xu | b63365a | 2008-10-23 01:11:29 -0700 | [diff] [blame] | 1436 | features = netdev_increment_features(features, |
| 1437 | slave->dev->features, |
| 1438 | NETIF_F_ONE_FOR_ALL); |
Jay Vosburgh | 278339a | 2009-08-28 12:05:12 +0000 | [diff] [blame] | 1439 | vlan_features = netdev_increment_features(vlan_features, |
| 1440 | slave->dev->vlan_features, |
| 1441 | NETIF_F_ONE_FOR_ALL); |
Jay Vosburgh | 54ef313 | 2006-09-22 21:53:39 -0700 | [diff] [blame] | 1442 | if (slave->dev->hard_header_len > max_hard_header_len) |
| 1443 | max_hard_header_len = slave->dev->hard_header_len; |
| 1444 | } |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1445 | |
Herbert Xu | b63365a | 2008-10-23 01:11:29 -0700 | [diff] [blame] | 1446 | done: |
Herbert Xu | 7f353bf | 2007-08-10 15:47:58 -0700 | [diff] [blame] | 1447 | features |= (bond_dev->features & BOND_VLAN_FEATURES); |
Michał Mirosław | acd1130 | 2011-01-24 15:45:15 -0800 | [diff] [blame] | 1448 | bond_dev->features = netdev_fix_features(bond_dev, features); |
| 1449 | bond_dev->vlan_features = netdev_fix_features(bond_dev, vlan_features); |
Jay Vosburgh | 54ef313 | 2006-09-22 21:53:39 -0700 | [diff] [blame] | 1450 | bond_dev->hard_header_len = max_hard_header_len; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1451 | |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1455 | static void bond_setup_by_slave(struct net_device *bond_dev, |
| 1456 | struct net_device *slave_dev) |
| 1457 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1458 | struct bonding *bond = netdev_priv(bond_dev); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 1459 | |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 1460 | bond_dev->header_ops = slave_dev->header_ops; |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1461 | |
| 1462 | bond_dev->type = slave_dev->type; |
| 1463 | bond_dev->hard_header_len = slave_dev->hard_header_len; |
| 1464 | bond_dev->addr_len = slave_dev->addr_len; |
| 1465 | |
| 1466 | memcpy(bond_dev->broadcast, slave_dev->broadcast, |
| 1467 | slave_dev->addr_len); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 1468 | bond->setup_by_slave = 1; |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | /* enslave device <slave> to bond device <master> */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1472 | 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] | 1473 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1474 | struct bonding *bond = netdev_priv(bond_dev); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1475 | const struct net_device_ops *slave_ops = slave_dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | struct slave *new_slave = NULL; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1477 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | struct sockaddr addr; |
| 1479 | int link_reporting; |
| 1480 | int old_features = bond_dev->features; |
| 1481 | int res = 0; |
| 1482 | |
nsxfreddy@gmail.com | 552709d | 2005-09-21 14:18:04 -0500 | [diff] [blame] | 1483 | if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL && |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1484 | slave_ops->ndo_do_ioctl == NULL) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1485 | pr_warning("%s: Warning: no link monitoring support for %s\n", |
| 1486 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | /* bond must be initialized by bond_open() before enslaving */ |
| 1490 | if (!(bond_dev->flags & IFF_UP)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1491 | pr_warning("%s: master_dev is not up in bond_enslave\n", |
| 1492 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | /* already enslaved */ |
| 1496 | if (slave_dev->flags & IFF_SLAVE) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1497 | pr_debug("Error, Device was already enslaved\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | return -EBUSY; |
| 1499 | } |
| 1500 | |
| 1501 | /* vlan challenged mutual exclusion */ |
| 1502 | /* no need to lock since we're protected by rtnl_lock */ |
| 1503 | if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1504 | pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 1505 | if (bond->vlgrp) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1506 | pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n", |
| 1507 | bond_dev->name, slave_dev->name, bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | return -EPERM; |
| 1509 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1510 | pr_warning("%s: Warning: enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n", |
| 1511 | bond_dev->name, slave_dev->name, |
| 1512 | slave_dev->name, bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | bond_dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 1514 | } |
| 1515 | } else { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1516 | pr_debug("%s: ! NETIF_F_VLAN_CHALLENGED\n", slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | if (bond->slave_cnt == 0) { |
| 1518 | /* First slave, and it is not VLAN challenged, |
| 1519 | * so remove the block of adding VLANs over the bond. |
| 1520 | */ |
| 1521 | bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED; |
| 1522 | } |
| 1523 | } |
| 1524 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1525 | /* |
| 1526 | * Old ifenslave binaries are no longer supported. These can |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1527 | * be identified with moderate accuracy by the state of the slave: |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1528 | * the current ifenslave will set the interface down prior to |
| 1529 | * enslaving it; the old ifenslave will not. |
| 1530 | */ |
| 1531 | if ((slave_dev->flags & IFF_UP)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1532 | 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] | 1533 | slave_dev->name); |
| 1534 | res = -EPERM; |
| 1535 | goto err_undo_flags; |
| 1536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1538 | /* set bonding device ether type by slave - bonding netdevices are |
| 1539 | * created with ether_setup, so when the slave type is not ARPHRD_ETHER |
| 1540 | * there is a need to override some of the type dependent attribs/funcs. |
| 1541 | * |
| 1542 | * bond ether type mutual exclusion - don't allow slaves of dissimilar |
| 1543 | * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond |
| 1544 | */ |
| 1545 | if (bond->slave_cnt == 0) { |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1546 | if (bond_dev->type != slave_dev->type) { |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1547 | pr_debug("%s: change device type from %d to %d\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1548 | bond_dev->name, |
| 1549 | bond_dev->type, slave_dev->type); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1550 | |
Jiri Pirko | 3ca5b40 | 2010-03-10 10:29:35 +0000 | [diff] [blame] | 1551 | res = netdev_bonding_change(bond_dev, |
| 1552 | NETDEV_PRE_TYPE_CHANGE); |
| 1553 | res = notifier_to_errno(res); |
| 1554 | if (res) { |
| 1555 | pr_err("%s: refused to change device type\n", |
| 1556 | bond_dev->name); |
| 1557 | res = -EBUSY; |
| 1558 | goto err_undo_flags; |
| 1559 | } |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1560 | |
Jiri Pirko | 32a806c | 2010-03-19 04:00:23 +0000 | [diff] [blame] | 1561 | /* Flush unicast and multicast addresses */ |
Jiri Pirko | a748ee2 | 2010-04-01 21:22:09 +0000 | [diff] [blame] | 1562 | dev_uc_flush(bond_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1563 | dev_mc_flush(bond_dev); |
Jiri Pirko | 32a806c | 2010-03-19 04:00:23 +0000 | [diff] [blame] | 1564 | |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1565 | if (slave_dev->type != ARPHRD_ETHER) |
| 1566 | bond_setup_by_slave(bond_dev, slave_dev); |
| 1567 | else |
| 1568 | ether_setup(bond_dev); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1569 | |
Jiri Pirko | 93d9b7d | 2010-03-10 10:28:56 +0000 | [diff] [blame] | 1570 | netdev_bonding_change(bond_dev, |
| 1571 | NETDEV_POST_TYPE_CHANGE); |
Moni Shoua | e36b9d1 | 2009-07-15 04:56:31 +0000 | [diff] [blame] | 1572 | } |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1573 | } else if (bond_dev->type != slave_dev->type) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1574 | pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n", |
| 1575 | slave_dev->name, |
| 1576 | slave_dev->type, bond_dev->type); |
| 1577 | res = -EINVAL; |
| 1578 | goto err_undo_flags; |
Moni Shoua | 872254d | 2007-10-09 19:43:38 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 1581 | if (slave_ops->ndo_set_mac_address == NULL) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1582 | if (bond->slave_cnt == 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1583 | pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.", |
| 1584 | bond_dev->name); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1585 | bond->params.fail_over_mac = BOND_FOM_ACTIVE; |
| 1586 | } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1587 | 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", |
| 1588 | bond_dev->name); |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1589 | res = -EOPNOTSUPP; |
| 1590 | goto err_undo_flags; |
| 1591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | } |
| 1593 | |
Jiri Pirko | c20811a | 2010-05-19 01:14:29 +0000 | [diff] [blame] | 1594 | /* If this is the first slave, then we need to set the master's hardware |
| 1595 | * address to be the same as the slave's. */ |
David Strand | d13a2cb | 2010-12-01 11:43:08 -0800 | [diff] [blame] | 1596 | if (is_zero_ether_addr(bond->dev->dev_addr)) |
Jiri Pirko | c20811a | 2010-05-19 01:14:29 +0000 | [diff] [blame] | 1597 | memcpy(bond->dev->dev_addr, slave_dev->dev_addr, |
| 1598 | slave_dev->addr_len); |
| 1599 | |
| 1600 | |
Joe Jin | 243cb4e | 2007-02-06 14:16:40 -0800 | [diff] [blame] | 1601 | new_slave = kzalloc(sizeof(struct slave), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | if (!new_slave) { |
| 1603 | res = -ENOMEM; |
| 1604 | goto err_undo_flags; |
| 1605 | } |
| 1606 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 1607 | /* |
| 1608 | * Set the new_slave's queue_id to be zero. Queue ID mapping |
| 1609 | * is set via sysfs or module option if desired. |
| 1610 | */ |
| 1611 | new_slave->queue_id = 0; |
| 1612 | |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 1613 | /* Save slave's original mtu and then set it to match the bond */ |
| 1614 | new_slave->original_mtu = slave_dev->mtu; |
| 1615 | res = dev_set_mtu(slave_dev, bond->dev->mtu); |
| 1616 | if (res) { |
| 1617 | pr_debug("Error %d calling dev_set_mtu\n", res); |
| 1618 | goto err_free; |
| 1619 | } |
| 1620 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1621 | /* |
| 1622 | * Save slave's original ("permanent") mac address for modes |
| 1623 | * that need it, and for restoring it upon release, and then |
| 1624 | * set it to the master's address |
| 1625 | */ |
| 1626 | memcpy(new_slave->perm_hwaddr, slave_dev->dev_addr, ETH_ALEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1628 | if (!bond->params.fail_over_mac) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1629 | /* |
| 1630 | * Set slave to master's mac address. The application already |
| 1631 | * set the master's mac address to that of the first slave |
| 1632 | */ |
| 1633 | memcpy(addr.sa_data, bond_dev->dev_addr, bond_dev->addr_len); |
| 1634 | addr.sa_family = slave_dev->type; |
| 1635 | res = dev_set_mac_address(slave_dev, &addr); |
| 1636 | if (res) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1637 | pr_debug("Error %d calling set_mac_address\n", res); |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 1638 | goto err_restore_mtu; |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1639 | } |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1640 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 1642 | res = netdev_set_bond_master(slave_dev, bond_dev); |
Jay Vosburgh | c2edacf | 2007-07-09 10:42:47 -0700 | [diff] [blame] | 1643 | if (res) { |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 1644 | pr_debug("Error %d calling netdev_set_bond_master\n", res); |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1645 | goto err_restore_mac; |
Jay Vosburgh | c2edacf | 2007-07-09 10:42:47 -0700 | [diff] [blame] | 1646 | } |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 1647 | /* open the slave since the application closed it */ |
| 1648 | res = dev_open(slave_dev); |
| 1649 | if (res) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1650 | pr_debug("Opening slave %s failed\n", slave_dev->name); |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1651 | goto err_unset_master; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | new_slave->dev = slave_dev; |
Jay Vosburgh | 0b680e7 | 2006-09-22 21:54:10 -0700 | [diff] [blame] | 1655 | slave_dev->priv_flags |= IFF_BONDING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1657 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | /* bond_alb_init_slave() must be called before all other stages since |
| 1659 | * it might fail and we do not want to have to undo everything |
| 1660 | */ |
| 1661 | res = bond_alb_init_slave(bond, new_slave); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1662 | if (res) |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1663 | goto err_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | /* If the mode USES_PRIMARY, then the new slave gets the |
| 1667 | * master's promisc (and mc) settings only if it becomes the |
| 1668 | * curr_active_slave, and that is taken care of later when calling |
| 1669 | * bond_change_active() |
| 1670 | */ |
| 1671 | if (!USES_PRIMARY(bond->params.mode)) { |
| 1672 | /* set promiscuity level to new slave */ |
| 1673 | if (bond_dev->flags & IFF_PROMISC) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 1674 | res = dev_set_promiscuity(slave_dev, 1); |
| 1675 | if (res) |
| 1676 | goto err_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /* set allmulti level to new slave */ |
| 1680 | if (bond_dev->flags & IFF_ALLMULTI) { |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 1681 | res = dev_set_allmulti(slave_dev, 1); |
| 1682 | if (res) |
| 1683 | goto err_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 1686 | netif_addr_lock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | /* upload master's mc_list to new slave */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1688 | netdev_for_each_mc_addr(ha, bond_dev) |
| 1689 | dev_mc_add(slave_dev, ha->addr); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 1690 | netif_addr_unlock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1694 | /* add lacpdu mc addr to mc list */ |
| 1695 | u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR; |
| 1696 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1697 | dev_mc_add(slave_dev, lacpdu_multicast); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | bond_add_vlans_on_slave(bond, slave_dev); |
| 1701 | |
| 1702 | write_lock_bh(&bond->lock); |
| 1703 | |
| 1704 | bond_attach_slave(bond, new_slave); |
| 1705 | |
| 1706 | new_slave->delay = 0; |
| 1707 | new_slave->link_failure_count = 0; |
| 1708 | |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1709 | bond_compute_features(bond); |
| 1710 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1711 | write_unlock_bh(&bond->lock); |
| 1712 | |
| 1713 | read_lock(&bond->lock); |
| 1714 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 1715 | new_slave->last_arp_rx = jiffies; |
| 1716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | if (bond->params.miimon && !bond->params.use_carrier) { |
| 1718 | link_reporting = bond_check_dev_link(bond, slave_dev, 1); |
| 1719 | |
| 1720 | if ((link_reporting == -1) && !bond->params.arp_interval) { |
| 1721 | /* |
| 1722 | * miimon is set but a bonded network driver |
| 1723 | * does not support ETHTOOL/MII and |
| 1724 | * arp_interval is not set. Note: if |
| 1725 | * use_carrier is enabled, we will never go |
| 1726 | * here (because netif_carrier is always |
| 1727 | * supported); thus, we don't need to change |
| 1728 | * the messages for netif_carrier. |
| 1729 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1730 | 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] | 1731 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | } else if (link_reporting == -1) { |
| 1733 | /* unable get link status using mii/ethtool */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1734 | 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", |
| 1735 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | /* check for initial state */ |
| 1740 | if (!bond->params.miimon || |
| 1741 | (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) { |
| 1742 | if (bond->params.updelay) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1743 | pr_debug("Initial state of slave_dev is BOND_LINK_BACK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | new_slave->link = BOND_LINK_BACK; |
| 1745 | new_slave->delay = bond->params.updelay; |
| 1746 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1747 | pr_debug("Initial state of slave_dev is BOND_LINK_UP\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | new_slave->link = BOND_LINK_UP; |
| 1749 | } |
| 1750 | new_slave->jiffies = jiffies; |
| 1751 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1752 | pr_debug("Initial state of slave_dev is BOND_LINK_DOWN\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | new_slave->link = BOND_LINK_DOWN; |
| 1754 | } |
| 1755 | |
| 1756 | if (bond_update_speed_duplex(new_slave) && |
| 1757 | (new_slave->link != BOND_LINK_DOWN)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1758 | pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n", |
| 1759 | bond_dev->name, new_slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | |
| 1761 | if (bond->params.mode == BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1762 | pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n", |
| 1763 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) { |
| 1768 | /* if there is a primary slave, remember it */ |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1769 | if (strcmp(bond->params.primary, new_slave->dev->name) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | bond->primary_slave = new_slave; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 1771 | bond->force_primary = true; |
| 1772 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1775 | write_lock_bh(&bond->curr_slave_lock); |
| 1776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | switch (bond->params.mode) { |
| 1778 | case BOND_MODE_ACTIVEBACKUP: |
Jay Vosburgh | 8a8e447 | 2006-09-22 21:56:15 -0700 | [diff] [blame] | 1779 | bond_set_slave_inactive_flags(new_slave); |
| 1780 | bond_select_active_slave(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | break; |
| 1782 | case BOND_MODE_8023AD: |
| 1783 | /* in 802.3ad mode, the internal mechanism |
| 1784 | * will activate the slaves in the selected |
| 1785 | * aggregator |
| 1786 | */ |
| 1787 | bond_set_slave_inactive_flags(new_slave); |
| 1788 | /* if this is the first slave */ |
| 1789 | if (bond->slave_cnt == 1) { |
| 1790 | SLAVE_AD_INFO(new_slave).id = 1; |
| 1791 | /* Initialize AD with the number of times that the AD timer is called in 1 second |
| 1792 | * can be called only after the mac address of the bond is set |
| 1793 | */ |
| 1794 | bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL, |
| 1795 | bond->params.lacp_fast); |
| 1796 | } else { |
| 1797 | SLAVE_AD_INFO(new_slave).id = |
| 1798 | SLAVE_AD_INFO(new_slave->prev).id + 1; |
| 1799 | } |
| 1800 | |
| 1801 | bond_3ad_bind_slave(new_slave); |
| 1802 | break; |
| 1803 | case BOND_MODE_TLB: |
| 1804 | case BOND_MODE_ALB: |
| 1805 | new_slave->state = BOND_STATE_ACTIVE; |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1806 | bond_set_slave_inactive_flags(new_slave); |
Jiri Pirko | 5a29f78 | 2009-03-25 17:23:38 -0700 | [diff] [blame] | 1807 | bond_select_active_slave(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | break; |
| 1809 | default: |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 1810 | pr_debug("This slave is always active in trunk mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
| 1812 | /* always active in trunk mode */ |
| 1813 | new_slave->state = BOND_STATE_ACTIVE; |
| 1814 | |
| 1815 | /* In trunking mode there is little meaning to curr_active_slave |
| 1816 | * anyway (it holds no special properties of the bond device), |
| 1817 | * so we can change it without calling change_active_interface() |
| 1818 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1819 | if (!bond->curr_active_slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | bond->curr_active_slave = new_slave; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | break; |
| 1823 | } /* switch(bond_mode) */ |
| 1824 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1825 | write_unlock_bh(&bond->curr_slave_lock); |
| 1826 | |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1827 | bond_set_carrier(bond); |
| 1828 | |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1829 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1830 | slave_dev->npinfo = bond_netpoll_info(bond); |
| 1831 | if (slave_dev->npinfo) { |
| 1832 | if (slave_enable_netpoll(new_slave)) { |
| 1833 | read_unlock(&bond->lock); |
| 1834 | pr_info("Error, %s: master_dev is using netpoll, " |
| 1835 | "but new slave device does not support netpoll.\n", |
| 1836 | bond_dev->name); |
| 1837 | res = -EBUSY; |
| 1838 | goto err_close; |
| 1839 | } |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1840 | } |
| 1841 | #endif |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 1842 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1843 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1845 | res = bond_create_slave_symlinks(bond_dev, slave_dev); |
| 1846 | if (res) |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1847 | goto err_close; |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 1848 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1849 | pr_info("%s: enslaving %s as a%s interface with a%s link.\n", |
| 1850 | bond_dev->name, slave_dev->name, |
| 1851 | new_slave->state == BOND_STATE_ACTIVE ? "n active" : " backup", |
| 1852 | new_slave->link != BOND_LINK_DOWN ? "n up" : " down"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | |
| 1854 | /* enslave is successful */ |
| 1855 | return 0; |
| 1856 | |
| 1857 | /* Undo stages on error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | err_close: |
| 1859 | dev_close(slave_dev); |
| 1860 | |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1861 | err_unset_master: |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 1862 | netdev_set_bond_master(slave_dev, NULL); |
Jay Vosburgh | 569f0c4 | 2008-05-02 18:06:02 -0700 | [diff] [blame] | 1863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | err_restore_mac: |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 1865 | if (!bond->params.fail_over_mac) { |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1866 | /* XXX TODO - fom follow mode needs to change master's |
| 1867 | * MAC if this slave's MAC is in use by the bond, or at |
| 1868 | * least print a warning. |
| 1869 | */ |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 1870 | memcpy(addr.sa_data, new_slave->perm_hwaddr, ETH_ALEN); |
| 1871 | addr.sa_family = slave_dev->type; |
| 1872 | dev_set_mac_address(slave_dev, &addr); |
| 1873 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 1875 | err_restore_mtu: |
| 1876 | dev_set_mtu(slave_dev, new_slave->original_mtu); |
| 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | err_free: |
| 1879 | kfree(new_slave); |
| 1880 | |
| 1881 | err_undo_flags: |
| 1882 | bond_dev->features = old_features; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | return res; |
| 1885 | } |
| 1886 | |
| 1887 | /* |
| 1888 | * Try to release the slave device <slave> from the bond device <master> |
| 1889 | * It is legal to access curr_active_slave without a lock because all the function |
| 1890 | * is write-locked. |
| 1891 | * |
| 1892 | * The rules for slave state should be: |
| 1893 | * for Active/Backup: |
| 1894 | * Active stays on all backups go down |
| 1895 | * for Bonded connections: |
| 1896 | * The first up interface should be left on and all others downed. |
| 1897 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 1898 | 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] | 1899 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1900 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | struct slave *slave, *oldcurrent; |
| 1902 | struct sockaddr addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
| 1904 | /* slave is not a slave or master is not master of this slave */ |
| 1905 | if (!(slave_dev->flags & IFF_SLAVE) || |
| 1906 | (slave_dev->master != bond_dev)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1907 | pr_err("%s: Error: cannot release %s.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | bond_dev->name, slave_dev->name); |
| 1909 | return -EINVAL; |
| 1910 | } |
| 1911 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1912 | block_netpoll_tx(); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 1913 | netdev_bonding_change(bond_dev, NETDEV_BONDING_DESLAVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | write_lock_bh(&bond->lock); |
| 1915 | |
| 1916 | slave = bond_get_slave_by_dev(bond, slave_dev); |
| 1917 | if (!slave) { |
| 1918 | /* not a slave of this bond */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1919 | pr_info("%s: %s not enslaved\n", |
| 1920 | bond_dev->name, slave_dev->name); |
Jay Vosburgh | f5e2a7b | 2006-02-07 21:17:22 -0800 | [diff] [blame] | 1921 | write_unlock_bh(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 1922 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | return -EINVAL; |
| 1924 | } |
| 1925 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 1926 | if (!bond->params.fail_over_mac) { |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1927 | if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) && |
| 1928 | bond->slave_cnt > 1) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1929 | 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", |
| 1930 | bond_dev->name, slave_dev->name, |
| 1931 | slave->perm_hwaddr, |
| 1932 | bond_dev->name, slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /* Inform AD package of unbinding of slave. */ |
| 1936 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 1937 | /* must be called before the slave is |
| 1938 | * detached from the list |
| 1939 | */ |
| 1940 | bond_3ad_unbind_slave(slave); |
| 1941 | } |
| 1942 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 1943 | pr_info("%s: releasing %s interface %s\n", |
| 1944 | bond_dev->name, |
| 1945 | (slave->state == BOND_STATE_ACTIVE) ? "active" : "backup", |
| 1946 | slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | |
| 1948 | oldcurrent = bond->curr_active_slave; |
| 1949 | |
| 1950 | bond->current_arp_slave = NULL; |
| 1951 | |
| 1952 | /* release the slave from its bond */ |
| 1953 | bond_detach_slave(bond, slave); |
| 1954 | |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 1955 | bond_compute_features(bond); |
| 1956 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1957 | if (bond->primary_slave == slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | bond->primary_slave = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 1960 | if (oldcurrent == slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | bond_change_active_slave(bond, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 1963 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | /* Must be called only after the slave has been |
| 1965 | * detached from the list and the curr_active_slave |
| 1966 | * has been cleared (if our_slave == old_current), |
| 1967 | * but before a new active slave is selected. |
| 1968 | */ |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 1969 | write_unlock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | bond_alb_deinit_slave(bond, slave); |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 1971 | write_lock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1974 | if (oldcurrent == slave) { |
| 1975 | /* |
| 1976 | * Note that we hold RTNL over this sequence, so there |
| 1977 | * is no concern that another slave add/remove event |
| 1978 | * will interfere. |
| 1979 | */ |
| 1980 | write_unlock_bh(&bond->lock); |
| 1981 | read_lock(&bond->lock); |
| 1982 | write_lock_bh(&bond->curr_slave_lock); |
| 1983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | bond_select_active_slave(bond); |
| 1985 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 1986 | write_unlock_bh(&bond->curr_slave_lock); |
| 1987 | read_unlock(&bond->lock); |
| 1988 | write_lock_bh(&bond->lock); |
| 1989 | } |
| 1990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if (bond->slave_cnt == 0) { |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 1992 | bond_set_carrier(bond); |
| 1993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | /* if the last slave was removed, zero the mac address |
| 1995 | * of the master so it will be set by the application |
| 1996 | * to the mac address of the first slave |
| 1997 | */ |
| 1998 | memset(bond_dev->dev_addr, 0, bond_dev->addr_len); |
| 1999 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 2000 | if (!bond->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | bond_dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 2002 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2003 | pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", |
| 2004 | bond_dev->name, bond_dev->name); |
| 2005 | pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n", |
| 2006 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | } |
| 2008 | } else if ((bond_dev->features & NETIF_F_VLAN_CHALLENGED) && |
| 2009 | !bond_has_challenged_slaves(bond)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2010 | pr_info("%s: last VLAN challenged slave %s left bond %s. VLAN blocking is removed\n", |
| 2011 | bond_dev->name, slave_dev->name, bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED; |
| 2013 | } |
| 2014 | |
| 2015 | write_unlock_bh(&bond->lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2016 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 2018 | /* must do this from outside any spinlocks */ |
| 2019 | bond_destroy_slave_symlinks(bond_dev, slave_dev); |
| 2020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | bond_del_vlans_from_slave(bond, slave_dev); |
| 2022 | |
| 2023 | /* If the mode USES_PRIMARY, then we should only remove its |
| 2024 | * promisc and mc settings if it was the curr_active_slave, but that was |
| 2025 | * already taken care of above when we detached the slave |
| 2026 | */ |
| 2027 | if (!USES_PRIMARY(bond->params.mode)) { |
| 2028 | /* unset promiscuity level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2029 | if (bond_dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | dev_set_promiscuity(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | |
| 2032 | /* unset allmulti level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2033 | if (bond_dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | dev_set_allmulti(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | |
| 2036 | /* flush master's mc_list from slave */ |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2037 | netif_addr_lock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | bond_mc_list_flush(bond_dev, slave_dev); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2039 | netif_addr_unlock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 2042 | netdev_set_bond_master(slave_dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 2044 | slave_disable_netpoll(slave); |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 2045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | /* close slave before restoring its mac address */ |
| 2047 | dev_close(slave_dev); |
| 2048 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 2049 | if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 2050 | /* restore original ("permanent") mac address */ |
| 2051 | memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); |
| 2052 | addr.sa_family = slave_dev->type; |
| 2053 | dev_set_mac_address(slave_dev, &addr); |
| 2054 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
Jiri Pirko | b15ba0f | 2010-05-18 05:42:40 +0000 | [diff] [blame] | 2056 | dev_set_mtu(slave_dev, slave->original_mtu); |
| 2057 | |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 2058 | slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2059 | IFF_SLAVE_INACTIVE | IFF_BONDING | |
| 2060 | IFF_SLAVE_NEEDARP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | |
| 2062 | kfree(slave); |
| 2063 | |
| 2064 | return 0; /* deletion OK */ |
| 2065 | } |
| 2066 | |
| 2067 | /* |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2068 | * First release a slave and than destroy the bond if no more slaves are left. |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2069 | * Must be under rtnl_lock when this function is called. |
| 2070 | */ |
stephen hemminger | 26d8ee7 | 2010-10-15 05:09:34 +0000 | [diff] [blame] | 2071 | static int bond_release_and_destroy(struct net_device *bond_dev, |
| 2072 | struct net_device *slave_dev) |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2073 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2074 | struct bonding *bond = netdev_priv(bond_dev); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2075 | int ret; |
| 2076 | |
| 2077 | ret = bond_release(bond_dev, slave_dev); |
| 2078 | if ((ret == 0) && (bond->slave_cnt == 0)) { |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 2079 | bond_dev->priv_flags |= IFF_DISABLE_NETPOLL; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2080 | pr_info("%s: destroying bond %s.\n", |
| 2081 | bond_dev->name, bond_dev->name); |
Stephen Hemminger | 9e71626 | 2009-06-12 19:02:47 +0000 | [diff] [blame] | 2082 | unregister_netdevice(bond_dev); |
Moni Shoua | d90a162 | 2007-10-09 19:43:43 -0700 | [diff] [blame] | 2083 | } |
| 2084 | return ret; |
| 2085 | } |
| 2086 | |
| 2087 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | * This function releases all slaves. |
| 2089 | */ |
| 2090 | static int bond_release_all(struct net_device *bond_dev) |
| 2091 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2092 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | struct slave *slave; |
| 2094 | struct net_device *slave_dev; |
| 2095 | struct sockaddr addr; |
| 2096 | |
| 2097 | write_lock_bh(&bond->lock); |
| 2098 | |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 2099 | netif_carrier_off(bond_dev); |
| 2100 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2101 | if (bond->slave_cnt == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
| 2104 | bond->current_arp_slave = NULL; |
| 2105 | bond->primary_slave = NULL; |
| 2106 | bond_change_active_slave(bond, NULL); |
| 2107 | |
| 2108 | while ((slave = bond->first_slave) != NULL) { |
| 2109 | /* Inform AD package of unbinding of slave |
| 2110 | * before slave is detached from the list. |
| 2111 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2112 | if (bond->params.mode == BOND_MODE_8023AD) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | bond_3ad_unbind_slave(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | |
| 2115 | slave_dev = slave->dev; |
| 2116 | bond_detach_slave(bond, slave); |
| 2117 | |
Jay Vosburgh | 2543331 | 2008-01-17 16:24:59 -0800 | [diff] [blame] | 2118 | /* now that the slave is detached, unlock and perform |
| 2119 | * all the undo steps that should not be called from |
| 2120 | * within a lock. |
| 2121 | */ |
| 2122 | write_unlock_bh(&bond->lock); |
| 2123 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 2124 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | /* must be called only after the slave |
| 2126 | * has been detached from the list |
| 2127 | */ |
| 2128 | bond_alb_deinit_slave(bond, slave); |
| 2129 | } |
| 2130 | |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 2131 | bond_compute_features(bond); |
| 2132 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 2133 | bond_destroy_slave_symlinks(bond_dev, slave_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | bond_del_vlans_from_slave(bond, slave_dev); |
| 2135 | |
| 2136 | /* If the mode USES_PRIMARY, then we should only remove its |
| 2137 | * promisc and mc settings if it was the curr_active_slave, but that was |
| 2138 | * already taken care of above when we detached the slave |
| 2139 | */ |
| 2140 | if (!USES_PRIMARY(bond->params.mode)) { |
| 2141 | /* unset promiscuity level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2142 | if (bond_dev->flags & IFF_PROMISC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | dev_set_promiscuity(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | |
| 2145 | /* unset allmulti level from slave */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2146 | if (bond_dev->flags & IFF_ALLMULTI) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | dev_set_allmulti(slave_dev, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | |
| 2149 | /* flush master's mc_list from slave */ |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2150 | netif_addr_lock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | bond_mc_list_flush(bond_dev, slave_dev); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 2152 | netif_addr_unlock_bh(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
Jiri Pirko | 1765a57 | 2011-02-12 06:48:36 +0000 | [diff] [blame] | 2155 | netdev_set_bond_master(slave_dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 2157 | slave_disable_netpoll(slave); |
| 2158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | /* close slave before restoring its mac address */ |
| 2160 | dev_close(slave_dev); |
| 2161 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 2162 | if (!bond->params.fail_over_mac) { |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 2163 | /* restore original ("permanent") mac address*/ |
| 2164 | memcpy(addr.sa_data, slave->perm_hwaddr, ETH_ALEN); |
| 2165 | addr.sa_family = slave_dev->type; |
| 2166 | dev_set_mac_address(slave_dev, &addr); |
| 2167 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 2169 | slave_dev->priv_flags &= ~(IFF_MASTER_8023AD | IFF_MASTER_ALB | |
| 2170 | IFF_SLAVE_INACTIVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | |
| 2172 | kfree(slave); |
| 2173 | |
| 2174 | /* re-acquire the lock before getting the next slave */ |
| 2175 | write_lock_bh(&bond->lock); |
| 2176 | } |
| 2177 | |
| 2178 | /* zero the mac address of the master so it will be |
| 2179 | * set by the application to the mac address of the |
| 2180 | * first slave |
| 2181 | */ |
| 2182 | memset(bond_dev->dev_addr, 0, bond_dev->addr_len); |
| 2183 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 2184 | if (!bond->vlgrp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | bond_dev->features |= NETIF_F_VLAN_CHALLENGED; |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 2186 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2187 | pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n", |
| 2188 | bond_dev->name, bond_dev->name); |
| 2189 | pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n", |
| 2190 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2193 | pr_info("%s: released all slaves\n", bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | |
| 2195 | out: |
| 2196 | write_unlock_bh(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | return 0; |
| 2198 | } |
| 2199 | |
| 2200 | /* |
| 2201 | * This function changes the active slave to slave <slave_dev>. |
| 2202 | * It returns -EINVAL in the following cases. |
| 2203 | * - <slave_dev> is not found in the list. |
| 2204 | * - There is not active slave now. |
| 2205 | * - <slave_dev> is already active. |
| 2206 | * - The link state of <slave_dev> is not BOND_LINK_UP. |
| 2207 | * - <slave_dev> is not running. |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2208 | * In these cases, this function does nothing. |
| 2209 | * 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] | 2210 | */ |
| 2211 | static int bond_ioctl_change_active(struct net_device *bond_dev, struct net_device *slave_dev) |
| 2212 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2213 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | struct slave *old_active = NULL; |
| 2215 | struct slave *new_active = NULL; |
| 2216 | int res = 0; |
| 2217 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2218 | if (!USES_PRIMARY(bond->params.mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | |
| 2221 | /* Verify that master_dev is indeed the master of slave_dev */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2222 | if (!(slave_dev->flags & IFF_SLAVE) || (slave_dev->master != bond_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2225 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2227 | read_lock(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | old_active = bond->curr_active_slave; |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2229 | read_unlock(&bond->curr_slave_lock); |
| 2230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2231 | new_active = bond_get_slave_by_dev(bond, slave_dev); |
| 2232 | |
| 2233 | /* |
| 2234 | * Changing to the current active: do nothing; return success. |
| 2235 | */ |
| 2236 | if (new_active && (new_active == old_active)) { |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2237 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | return 0; |
| 2239 | } |
| 2240 | |
| 2241 | if ((new_active) && |
| 2242 | (old_active) && |
| 2243 | (new_active->link == BOND_LINK_UP) && |
| 2244 | IS_UP(new_active->dev)) { |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2245 | block_netpoll_tx(); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2246 | write_lock_bh(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | bond_change_active_slave(bond, new_active); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2248 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2249 | unblock_netpoll_tx(); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2250 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | res = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2253 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | |
| 2255 | return res; |
| 2256 | } |
| 2257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | static int bond_info_query(struct net_device *bond_dev, struct ifbond *info) |
| 2259 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2260 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | |
| 2262 | info->bond_mode = bond->params.mode; |
| 2263 | info->miimon = bond->params.miimon; |
| 2264 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2265 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | info->num_slaves = bond->slave_cnt; |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2267 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
| 2269 | return 0; |
| 2270 | } |
| 2271 | |
| 2272 | static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info) |
| 2273 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2274 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | struct slave *slave; |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2276 | int i, res = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2278 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | |
| 2280 | bond_for_each_slave(bond, slave, i) { |
| 2281 | if (i == (int)info->slave_id) { |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2282 | res = 0; |
| 2283 | strcpy(info->slave_name, slave->dev->name); |
| 2284 | info->link = slave->link; |
| 2285 | info->state = slave->state; |
| 2286 | info->link_failure_count = slave->link_failure_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | break; |
| 2288 | } |
| 2289 | } |
| 2290 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 2291 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | |
Eric Dumazet | 689c96c | 2009-04-23 03:39:04 +0000 | [diff] [blame] | 2293 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /*-------------------------------- Monitoring -------------------------------*/ |
| 2297 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2298 | |
| 2299 | static int bond_miimon_inspect(struct bonding *bond) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | { |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2301 | struct slave *slave; |
| 2302 | int i, link_state, commit = 0; |
Jiri Pirko | 41f8910 | 2009-04-24 03:57:29 +0000 | [diff] [blame] | 2303 | bool ignore_updelay; |
| 2304 | |
| 2305 | ignore_updelay = !bond->curr_active_slave ? true : false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | |
| 2307 | bond_for_each_slave(bond, slave, i) { |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2308 | slave->new_link = BOND_LINK_NOCHANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2310 | link_state = bond_check_dev_link(bond, slave->dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | |
| 2312 | switch (slave->link) { |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2313 | case BOND_LINK_UP: |
| 2314 | if (link_state) |
| 2315 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2317 | slave->link = BOND_LINK_FAIL; |
| 2318 | slave->delay = bond->params.downdelay; |
| 2319 | if (slave->delay) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2320 | pr_info("%s: link status down for %sinterface %s, disabling it in %d ms.\n", |
| 2321 | bond->dev->name, |
| 2322 | (bond->params.mode == |
| 2323 | BOND_MODE_ACTIVEBACKUP) ? |
| 2324 | ((slave->state == BOND_STATE_ACTIVE) ? |
| 2325 | "active " : "backup ") : "", |
| 2326 | slave->dev->name, |
| 2327 | bond->params.downdelay * bond->params.miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2329 | /*FALLTHRU*/ |
| 2330 | case BOND_LINK_FAIL: |
| 2331 | if (link_state) { |
| 2332 | /* |
| 2333 | * recovered before downdelay expired |
| 2334 | */ |
| 2335 | slave->link = BOND_LINK_UP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | slave->jiffies = jiffies; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2337 | pr_info("%s: link status up again after %d ms for interface %s.\n", |
| 2338 | bond->dev->name, |
| 2339 | (bond->params.downdelay - slave->delay) * |
| 2340 | bond->params.miimon, |
| 2341 | slave->dev->name); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2342 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2344 | |
| 2345 | if (slave->delay <= 0) { |
| 2346 | slave->new_link = BOND_LINK_DOWN; |
| 2347 | commit++; |
| 2348 | continue; |
| 2349 | } |
| 2350 | |
| 2351 | slave->delay--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2354 | case BOND_LINK_DOWN: |
| 2355 | if (!link_state) |
| 2356 | continue; |
| 2357 | |
| 2358 | slave->link = BOND_LINK_BACK; |
| 2359 | slave->delay = bond->params.updelay; |
| 2360 | |
| 2361 | if (slave->delay) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2362 | pr_info("%s: link status up for interface %s, enabling it in %d ms.\n", |
| 2363 | bond->dev->name, slave->dev->name, |
| 2364 | ignore_updelay ? 0 : |
| 2365 | bond->params.updelay * |
| 2366 | bond->params.miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2368 | /*FALLTHRU*/ |
| 2369 | case BOND_LINK_BACK: |
| 2370 | if (!link_state) { |
| 2371 | slave->link = BOND_LINK_DOWN; |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2372 | pr_info("%s: link status down again after %d ms for interface %s.\n", |
| 2373 | bond->dev->name, |
| 2374 | (bond->params.updelay - slave->delay) * |
| 2375 | bond->params.miimon, |
| 2376 | slave->dev->name); |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2377 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2378 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | } |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2380 | |
Jiri Pirko | 41f8910 | 2009-04-24 03:57:29 +0000 | [diff] [blame] | 2381 | if (ignore_updelay) |
| 2382 | slave->delay = 0; |
| 2383 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2384 | if (slave->delay <= 0) { |
| 2385 | slave->new_link = BOND_LINK_UP; |
| 2386 | commit++; |
Jiri Pirko | 41f8910 | 2009-04-24 03:57:29 +0000 | [diff] [blame] | 2387 | ignore_updelay = false; |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2388 | continue; |
| 2389 | } |
| 2390 | |
| 2391 | slave->delay--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | break; |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | return commit; |
| 2397 | } |
| 2398 | |
| 2399 | static void bond_miimon_commit(struct bonding *bond) |
| 2400 | { |
| 2401 | struct slave *slave; |
| 2402 | int i; |
| 2403 | |
| 2404 | bond_for_each_slave(bond, slave, i) { |
| 2405 | switch (slave->new_link) { |
| 2406 | case BOND_LINK_NOCHANGE: |
| 2407 | continue; |
| 2408 | |
| 2409 | case BOND_LINK_UP: |
| 2410 | slave->link = BOND_LINK_UP; |
| 2411 | slave->jiffies = jiffies; |
| 2412 | |
| 2413 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 2414 | /* prevent it from being the active one */ |
| 2415 | slave->state = BOND_STATE_BACKUP; |
| 2416 | } else if (bond->params.mode != BOND_MODE_ACTIVEBACKUP) { |
| 2417 | /* make it immediately active */ |
| 2418 | slave->state = BOND_STATE_ACTIVE; |
| 2419 | } else if (slave != bond->primary_slave) { |
| 2420 | /* prevent it from being the active one */ |
| 2421 | slave->state = BOND_STATE_BACKUP; |
| 2422 | } |
| 2423 | |
Krzysztof Piotr Oledzki | 546add7 | 2010-10-06 14:28:22 -0700 | [diff] [blame] | 2424 | bond_update_speed_duplex(slave); |
| 2425 | |
Krzysztof Piotr Oledzki | 700c2a7 | 2010-10-06 14:25:06 -0700 | [diff] [blame] | 2426 | pr_info("%s: link status definitely up for interface %s, %d Mbps %s duplex.\n", |
| 2427 | bond->dev->name, slave->dev->name, |
| 2428 | slave->speed, slave->duplex ? "full" : "half"); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2429 | |
| 2430 | /* notify ad that the link status has changed */ |
| 2431 | if (bond->params.mode == BOND_MODE_8023AD) |
| 2432 | bond_3ad_handle_link_change(slave, BOND_LINK_UP); |
| 2433 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 2434 | if (bond_is_lb(bond)) |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2435 | bond_alb_handle_link_change(bond, slave, |
| 2436 | BOND_LINK_UP); |
| 2437 | |
| 2438 | if (!bond->curr_active_slave || |
| 2439 | (slave == bond->primary_slave)) |
| 2440 | goto do_failover; |
| 2441 | |
| 2442 | continue; |
| 2443 | |
| 2444 | case BOND_LINK_DOWN: |
Jay Vosburgh | fba4acd | 2008-10-30 17:41:14 -0700 | [diff] [blame] | 2445 | if (slave->link_failure_count < UINT_MAX) |
| 2446 | slave->link_failure_count++; |
| 2447 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2448 | slave->link = BOND_LINK_DOWN; |
| 2449 | |
| 2450 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP || |
| 2451 | bond->params.mode == BOND_MODE_8023AD) |
| 2452 | bond_set_slave_inactive_flags(slave); |
| 2453 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2454 | pr_info("%s: link status definitely down for interface %s, disabling it\n", |
| 2455 | bond->dev->name, slave->dev->name); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2456 | |
| 2457 | if (bond->params.mode == BOND_MODE_8023AD) |
| 2458 | bond_3ad_handle_link_change(slave, |
| 2459 | BOND_LINK_DOWN); |
| 2460 | |
Jiri Pirko | ae63e80 | 2009-05-27 05:42:36 +0000 | [diff] [blame] | 2461 | if (bond_is_lb(bond)) |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2462 | bond_alb_handle_link_change(bond, slave, |
| 2463 | BOND_LINK_DOWN); |
| 2464 | |
| 2465 | if (slave == bond->curr_active_slave) |
| 2466 | goto do_failover; |
| 2467 | |
| 2468 | continue; |
| 2469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | default: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2471 | pr_err("%s: invalid new link %d on slave %s\n", |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2472 | bond->dev->name, slave->new_link, |
| 2473 | slave->dev->name); |
| 2474 | slave->new_link = BOND_LINK_NOCHANGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2476 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2479 | do_failover: |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2480 | ASSERT_RTNL(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2481 | block_netpoll_tx(); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2482 | write_lock_bh(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | bond_select_active_slave(bond); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2484 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2485 | unblock_netpoll_tx(); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2486 | } |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2487 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2488 | bond_set_carrier(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2491 | /* |
| 2492 | * bond_mii_monitor |
| 2493 | * |
| 2494 | * Really a wrapper that splits the mii monitor into two phases: an |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2495 | * inspection, then (if inspection indicates something needs to be done) |
| 2496 | * an acquisition of appropriate locks followed by a commit phase to |
| 2497 | * implement whatever link state changes are indicated. |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2498 | */ |
| 2499 | void bond_mii_monitor(struct work_struct *work) |
| 2500 | { |
| 2501 | struct bonding *bond = container_of(work, struct bonding, |
| 2502 | mii_work.work); |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2503 | |
| 2504 | read_lock(&bond->lock); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2505 | if (bond->kill_timers) |
| 2506 | goto out; |
| 2507 | |
| 2508 | if (bond->slave_cnt == 0) |
| 2509 | goto re_arm; |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 2510 | |
| 2511 | if (bond->send_grat_arp) { |
| 2512 | read_lock(&bond->curr_slave_lock); |
| 2513 | bond_send_gratuitous_arp(bond); |
| 2514 | read_unlock(&bond->curr_slave_lock); |
| 2515 | } |
| 2516 | |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 2517 | if (bond->send_unsol_na) { |
| 2518 | read_lock(&bond->curr_slave_lock); |
| 2519 | bond_send_unsolicited_na(bond); |
| 2520 | read_unlock(&bond->curr_slave_lock); |
| 2521 | } |
| 2522 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2523 | if (bond_miimon_inspect(bond)) { |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2524 | read_unlock(&bond->lock); |
| 2525 | rtnl_lock(); |
| 2526 | read_lock(&bond->lock); |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2527 | |
| 2528 | bond_miimon_commit(bond); |
| 2529 | |
Jay Vosburgh | 5655662 | 2008-01-17 16:25:03 -0800 | [diff] [blame] | 2530 | read_unlock(&bond->lock); |
| 2531 | rtnl_unlock(); /* might sleep, hold no other locks */ |
| 2532 | read_lock(&bond->lock); |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
Jay Vosburgh | f0c76d6 | 2008-07-02 18:21:58 -0700 | [diff] [blame] | 2535 | re_arm: |
| 2536 | if (bond->params.miimon) |
| 2537 | queue_delayed_work(bond->wq, &bond->mii_work, |
| 2538 | msecs_to_jiffies(bond->params.miimon)); |
| 2539 | out: |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2540 | read_unlock(&bond->lock); |
Jay Vosburgh | 0b0eef6 | 2007-10-17 17:37:48 -0700 | [diff] [blame] | 2541 | } |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2542 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2543 | static __be32 bond_glean_dev_ip(struct net_device *dev) |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2544 | { |
| 2545 | struct in_device *idev; |
| 2546 | struct in_ifaddr *ifa; |
Al Viro | a144ea4 | 2006-09-28 18:00:55 -0700 | [diff] [blame] | 2547 | __be32 addr = 0; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2548 | |
| 2549 | if (!dev) |
| 2550 | return 0; |
| 2551 | |
| 2552 | rcu_read_lock(); |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 2553 | idev = __in_dev_get_rcu(dev); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2554 | if (!idev) |
| 2555 | goto out; |
| 2556 | |
| 2557 | ifa = idev->ifa_list; |
| 2558 | if (!ifa) |
| 2559 | goto out; |
| 2560 | |
| 2561 | addr = ifa->ifa_local; |
| 2562 | out: |
| 2563 | rcu_read_unlock(); |
| 2564 | return addr; |
| 2565 | } |
| 2566 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2567 | static int bond_has_this_ip(struct bonding *bond, __be32 ip) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2568 | { |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2569 | struct vlan_entry *vlan; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2570 | |
| 2571 | if (ip == bond->master_ip) |
| 2572 | return 1; |
| 2573 | |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2574 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2575 | if (ip == vlan->vlan_ip) |
| 2576 | return 1; |
| 2577 | } |
| 2578 | |
| 2579 | return 0; |
| 2580 | } |
| 2581 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2582 | /* |
| 2583 | * We go to the (large) trouble of VLAN tagging ARP frames because |
| 2584 | * switches in VLAN mode (especially if ports are configured as |
| 2585 | * "native" to a VLAN) might not pass non-tagged frames. |
| 2586 | */ |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2587 | 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] | 2588 | { |
| 2589 | struct sk_buff *skb; |
| 2590 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2591 | 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] | 2592 | slave_dev->name, dest_ip, src_ip, vlan_id); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2593 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2594 | skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip, |
| 2595 | NULL, slave_dev->dev_addr, NULL); |
| 2596 | |
| 2597 | if (!skb) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2598 | pr_err("ARP packet allocation failed\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2599 | return; |
| 2600 | } |
| 2601 | if (vlan_id) { |
| 2602 | skb = vlan_put_tag(skb, vlan_id); |
| 2603 | if (!skb) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2604 | pr_err("failed to insert VLAN tag\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2605 | return; |
| 2606 | } |
| 2607 | } |
| 2608 | arp_xmit(skb); |
| 2609 | } |
| 2610 | |
| 2611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | static void bond_arp_send_all(struct bonding *bond, struct slave *slave) |
| 2613 | { |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2614 | int i, vlan_id, rv; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2615 | __be32 *targets = bond->params.arp_targets; |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2616 | struct vlan_entry *vlan; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2617 | struct net_device *vlan_dev; |
| 2618 | struct flowi fl; |
| 2619 | struct rtable *rt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | |
Mitch Williams | 6b78056 | 2005-11-09 10:36:19 -0800 | [diff] [blame] | 2621 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
| 2622 | if (!targets[i]) |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 2623 | break; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2624 | pr_debug("basa: target %x\n", targets[i]); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 2625 | if (!bond->vlgrp) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2626 | pr_debug("basa: empty vlan: arp_send\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2627 | bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
| 2628 | bond->master_ip, 0); |
| 2629 | continue; |
| 2630 | } |
| 2631 | |
| 2632 | /* |
| 2633 | * If VLANs are configured, we do a route lookup to |
| 2634 | * determine which VLAN interface would be used, so we |
| 2635 | * can tag the ARP with the proper VLAN tag. |
| 2636 | */ |
| 2637 | memset(&fl, 0, sizeof(fl)); |
| 2638 | fl.fl4_dst = targets[i]; |
| 2639 | fl.fl4_tos = RTO_ONLINK; |
| 2640 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 2641 | rv = ip_route_output_key(dev_net(bond->dev), &rt, &fl); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2642 | if (rv) { |
| 2643 | if (net_ratelimit()) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2644 | pr_warning("%s: no route to arp_ip_target %pI4\n", |
| 2645 | bond->dev->name, &fl.fl4_dst); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2646 | } |
| 2647 | continue; |
| 2648 | } |
| 2649 | |
| 2650 | /* |
| 2651 | * This target is not on a VLAN |
| 2652 | */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2653 | if (rt->dst.dev == bond->dev) { |
Jay Vosburgh | ed4b9f8 | 2005-09-14 14:52:09 -0700 | [diff] [blame] | 2654 | ip_rt_put(rt); |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2655 | pr_debug("basa: rtdev == bond->dev: arp_send\n"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2656 | bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
| 2657 | bond->master_ip, 0); |
| 2658 | continue; |
| 2659 | } |
| 2660 | |
| 2661 | vlan_id = 0; |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 2662 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 2663 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2664 | if (vlan_dev == rt->dst.dev) { |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2665 | vlan_id = vlan->vlan_id; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2666 | pr_debug("basa: vlan match on %s %d\n", |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2667 | vlan_dev->name, vlan_id); |
| 2668 | break; |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | if (vlan_id) { |
Jay Vosburgh | ed4b9f8 | 2005-09-14 14:52:09 -0700 | [diff] [blame] | 2673 | ip_rt_put(rt); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2674 | bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i], |
| 2675 | vlan->vlan_ip, vlan_id); |
| 2676 | continue; |
| 2677 | } |
| 2678 | |
| 2679 | if (net_ratelimit()) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2680 | pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n", |
| 2681 | bond->dev->name, &fl.fl4_dst, |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 2682 | rt->dst.dev ? rt->dst.dev->name : "NULL"); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2683 | } |
Jay Vosburgh | ed4b9f8 | 2005-09-14 14:52:09 -0700 | [diff] [blame] | 2684 | ip_rt_put(rt); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | /* |
| 2689 | * Kick out a gratuitous ARP for an IP on the bonding master plus one |
| 2690 | * for each VLAN above us. |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 2691 | * |
| 2692 | * Caller must hold curr_slave_lock for read or better |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2693 | */ |
| 2694 | static void bond_send_gratuitous_arp(struct bonding *bond) |
| 2695 | { |
| 2696 | struct slave *slave = bond->curr_active_slave; |
| 2697 | struct vlan_entry *vlan; |
| 2698 | struct net_device *vlan_dev; |
| 2699 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2700 | pr_debug("bond_send_grat_arp: bond %s slave %s\n", |
| 2701 | bond->dev->name, slave ? slave->dev->name : "NULL"); |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 2702 | |
| 2703 | if (!slave || !bond->send_grat_arp || |
| 2704 | test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state)) |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2705 | return; |
| 2706 | |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 2707 | bond->send_grat_arp--; |
| 2708 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2709 | if (bond->master_ip) { |
| 2710 | bond_arp_send(slave->dev, ARPOP_REPLY, bond->master_ip, |
Moni Shoua | 1053f62 | 2007-10-09 19:43:42 -0700 | [diff] [blame] | 2711 | bond->master_ip, 0); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2712 | } |
| 2713 | |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 2714 | if (!bond->vlgrp) |
| 2715 | return; |
| 2716 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2717 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 2718 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 2719 | if (vlan->vlan_ip) { |
| 2720 | bond_arp_send(slave->dev, ARPOP_REPLY, vlan->vlan_ip, |
| 2721 | vlan->vlan_ip, vlan->vlan_id); |
| 2722 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | } |
| 2724 | } |
| 2725 | |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2726 | 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] | 2727 | { |
| 2728 | int i; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2729 | __be32 *targets = bond->params.arp_targets; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2730 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2731 | for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2732 | 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] | 2733 | &sip, &tip, i, &targets[i], |
| 2734 | bond_has_this_ip(bond, tip)); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2735 | if (sip == targets[i]) { |
| 2736 | if (bond_has_this_ip(bond, tip)) |
| 2737 | slave->last_arp_rx = jiffies; |
| 2738 | return; |
| 2739 | } |
| 2740 | } |
| 2741 | } |
| 2742 | |
| 2743 | static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev) |
| 2744 | { |
| 2745 | struct arphdr *arp; |
| 2746 | struct slave *slave; |
| 2747 | struct bonding *bond; |
| 2748 | unsigned char *arp_ptr; |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 2749 | __be32 sip, tip; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2750 | |
Andy Gospodarek | 1f3c880 | 2009-12-14 10:48:58 +0000 | [diff] [blame] | 2751 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 2752 | /* |
| 2753 | * When using VLANS and bonding, dev and oriv_dev may be |
| 2754 | * incorrect if the physical interface supports VLAN |
| 2755 | * acceleration. With this change ARP validation now |
| 2756 | * works for hosts only reachable on the VLAN interface. |
| 2757 | */ |
| 2758 | dev = vlan_dev_real_dev(dev); |
| 2759 | orig_dev = dev_get_by_index_rcu(dev_net(skb->dev),skb->skb_iif); |
| 2760 | } |
| 2761 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2762 | if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER)) |
| 2763 | goto out; |
| 2764 | |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 2765 | bond = netdev_priv(dev); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2766 | read_lock(&bond->lock); |
| 2767 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2768 | pr_debug("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2769 | bond->dev->name, skb->dev ? skb->dev->name : "NULL", |
| 2770 | orig_dev ? orig_dev->name : "NULL"); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2771 | |
| 2772 | slave = bond_get_slave_by_dev(bond, orig_dev); |
| 2773 | if (!slave || !slave_do_arp_validate(bond, slave)) |
| 2774 | goto out_unlock; |
| 2775 | |
Neil Horman | b305325 | 2011-01-20 09:02:31 +0000 | [diff] [blame] | 2776 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 2777 | if (!skb) |
| 2778 | goto out_unlock; |
| 2779 | |
Pavel Emelyanov | 988b705 | 2008-03-03 12:20:57 -0800 | [diff] [blame] | 2780 | if (!pskb_may_pull(skb, arp_hdr_len(dev))) |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2781 | goto out_unlock; |
| 2782 | |
Arnaldo Carvalho de Melo | d0a92be | 2007-03-12 20:56:31 -0300 | [diff] [blame] | 2783 | arp = arp_hdr(skb); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2784 | if (arp->ar_hln != dev->addr_len || |
| 2785 | skb->pkt_type == PACKET_OTHERHOST || |
| 2786 | skb->pkt_type == PACKET_LOOPBACK || |
| 2787 | arp->ar_hrd != htons(ARPHRD_ETHER) || |
| 2788 | arp->ar_pro != htons(ETH_P_IP) || |
| 2789 | arp->ar_pln != 4) |
| 2790 | goto out_unlock; |
| 2791 | |
| 2792 | arp_ptr = (unsigned char *)(arp + 1); |
| 2793 | arp_ptr += dev->addr_len; |
| 2794 | memcpy(&sip, arp_ptr, 4); |
| 2795 | arp_ptr += 4 + dev->addr_len; |
| 2796 | memcpy(&tip, arp_ptr, 4); |
| 2797 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 2798 | pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2799 | bond->dev->name, slave->dev->name, slave->state, |
| 2800 | bond->params.arp_validate, slave_do_arp_validate(bond, slave), |
| 2801 | &sip, &tip); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 2802 | |
| 2803 | /* |
| 2804 | * Backup slaves won't see the ARP reply, but do come through |
| 2805 | * here for each ARP probe (so we swap the sip/tip to validate |
| 2806 | * the probe). In a "redundant switch, common router" type of |
| 2807 | * configuration, the ARP probe will (hopefully) travel from |
| 2808 | * the active, through one switch, the router, then the other |
| 2809 | * switch before reaching the backup. |
| 2810 | */ |
| 2811 | if (slave->state == BOND_STATE_ACTIVE) |
| 2812 | bond_validate_arp(bond, slave, sip, tip); |
| 2813 | else |
| 2814 | bond_validate_arp(bond, slave, tip, sip); |
| 2815 | |
| 2816 | out_unlock: |
| 2817 | read_unlock(&bond->lock); |
| 2818 | out: |
| 2819 | dev_kfree_skb(skb); |
| 2820 | return NET_RX_SUCCESS; |
| 2821 | } |
| 2822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | /* |
| 2824 | * this function is called regularly to monitor each slave's link |
| 2825 | * ensuring that traffic is being sent and received when arp monitoring |
| 2826 | * is used in load-balancing mode. if the adapter has been dormant, then an |
| 2827 | * arp is transmitted to generate traffic. see activebackup_arp_monitor for |
| 2828 | * arp monitoring in active backup mode. |
| 2829 | */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2830 | void bond_loadbalance_arp_mon(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | { |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2832 | struct bonding *bond = container_of(work, struct bonding, |
| 2833 | arp_work.work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | struct slave *slave, *oldcurrent; |
| 2835 | int do_failover = 0; |
| 2836 | int delta_in_ticks; |
| 2837 | int i; |
| 2838 | |
| 2839 | read_lock(&bond->lock); |
| 2840 | |
Jay Vosburgh | 5ce0da8 | 2008-05-17 21:10:07 -0700 | [diff] [blame] | 2841 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2843 | if (bond->kill_timers) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2846 | if (bond->slave_cnt == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2847 | goto re_arm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
| 2849 | read_lock(&bond->curr_slave_lock); |
| 2850 | oldcurrent = bond->curr_active_slave; |
| 2851 | read_unlock(&bond->curr_slave_lock); |
| 2852 | |
| 2853 | /* see if any of the previous devices are up now (i.e. they have |
| 2854 | * xmt and rcv traffic). the curr_active_slave does not come into |
| 2855 | * the picture unless it is null. also, slave->jiffies is not needed |
| 2856 | * here because we send an arp on each slave and give a slave as |
| 2857 | * long as it needs to get the tx/rx within the delta. |
| 2858 | * TODO: what about up/down delay in arp mode? it wasn't here before |
| 2859 | * so it can wait |
| 2860 | */ |
| 2861 | bond_for_each_slave(bond, slave, i) { |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2862 | unsigned long trans_start = dev_trans_start(slave->dev); |
| 2863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | if (slave->link != BOND_LINK_UP) { |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2865 | if (time_in_range(jiffies, |
| 2866 | trans_start - delta_in_ticks, |
| 2867 | trans_start + delta_in_ticks) && |
| 2868 | time_in_range(jiffies, |
| 2869 | slave->dev->last_rx - delta_in_ticks, |
| 2870 | slave->dev->last_rx + delta_in_ticks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | |
| 2872 | slave->link = BOND_LINK_UP; |
| 2873 | slave->state = BOND_STATE_ACTIVE; |
| 2874 | |
| 2875 | /* primary_slave has no meaning in round-robin |
| 2876 | * mode. the window of a slave being up and |
| 2877 | * curr_active_slave being null after enslaving |
| 2878 | * is closed. |
| 2879 | */ |
| 2880 | if (!oldcurrent) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2881 | pr_info("%s: link status definitely up for interface %s, ", |
| 2882 | bond->dev->name, |
| 2883 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | do_failover = 1; |
| 2885 | } else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2886 | pr_info("%s: interface %s is now up\n", |
| 2887 | bond->dev->name, |
| 2888 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | } |
| 2890 | } |
| 2891 | } else { |
| 2892 | /* slave->link == BOND_LINK_UP */ |
| 2893 | |
| 2894 | /* not all switches will respond to an arp request |
| 2895 | * when the source ip is 0, so don't take the link down |
| 2896 | * if we don't know our ip yet |
| 2897 | */ |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2898 | if (!time_in_range(jiffies, |
| 2899 | trans_start - delta_in_ticks, |
| 2900 | trans_start + 2 * delta_in_ticks) || |
| 2901 | !time_in_range(jiffies, |
| 2902 | slave->dev->last_rx - delta_in_ticks, |
| 2903 | slave->dev->last_rx + 2 * delta_in_ticks)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | |
| 2905 | slave->link = BOND_LINK_DOWN; |
| 2906 | slave->state = BOND_STATE_BACKUP; |
| 2907 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2908 | if (slave->link_failure_count < UINT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | slave->link_failure_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 2911 | pr_info("%s: interface %s is now down.\n", |
| 2912 | bond->dev->name, |
| 2913 | slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2915 | if (slave == oldcurrent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2916 | do_failover = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | } |
| 2918 | } |
| 2919 | |
| 2920 | /* note: if switch is in round-robin mode, all links |
| 2921 | * must tx arp to ensure all links rx an arp - otherwise |
| 2922 | * links may oscillate or not come up at all; if switch is |
| 2923 | * in something like xor mode, there is nothing we can |
| 2924 | * do - all replies will be rx'ed on same link causing slaves |
| 2925 | * to be unstable during low/no traffic periods |
| 2926 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 2927 | if (IS_UP(slave->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | bond_arp_send_all(bond, slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | if (do_failover) { |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2932 | block_netpoll_tx(); |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2933 | write_lock_bh(&bond->curr_slave_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | |
| 2935 | bond_select_active_slave(bond); |
| 2936 | |
Jay Vosburgh | 059fe7a | 2007-10-17 17:37:49 -0700 | [diff] [blame] | 2937 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 2938 | unblock_netpoll_tx(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | re_arm: |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 2942 | if (bond->params.arp_interval) |
| 2943 | queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | out: |
| 2945 | read_unlock(&bond->lock); |
| 2946 | } |
| 2947 | |
| 2948 | /* |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2949 | * Called to inspect slaves for active-backup mode ARP monitor link state |
| 2950 | * changes. Sets new_link in slaves to specify what action should take |
| 2951 | * place for the slave. Returns 0 if no changes are found, >0 if changes |
| 2952 | * to link states must be committed. |
| 2953 | * |
| 2954 | * Called with bond->lock held for read. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | */ |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2956 | 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] | 2957 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | struct slave *slave; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2959 | int i, commit = 0; |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2960 | unsigned long trans_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | bond_for_each_slave(bond, slave, i) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2963 | slave->new_link = BOND_LINK_NOCHANGE; |
| 2964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | if (slave->link != BOND_LINK_UP) { |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2966 | if (time_in_range(jiffies, |
| 2967 | slave_last_rx(bond, slave) - delta_in_ticks, |
| 2968 | slave_last_rx(bond, slave) + delta_in_ticks)) { |
| 2969 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2970 | slave->new_link = BOND_LINK_UP; |
| 2971 | commit++; |
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 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2974 | continue; |
| 2975 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2976 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2977 | /* |
| 2978 | * Give slaves 2*delta after being enslaved or made |
| 2979 | * active. This avoids bouncing, as the last receive |
| 2980 | * times need a full ARP monitor cycle to be updated. |
| 2981 | */ |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 2982 | if (time_in_range(jiffies, |
| 2983 | slave->jiffies - delta_in_ticks, |
| 2984 | slave->jiffies + 2 * delta_in_ticks)) |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2985 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 2987 | /* |
| 2988 | * Backup slave is down if: |
| 2989 | * - No current_arp_slave AND |
| 2990 | * - more than 3*delta since last receive AND |
| 2991 | * - the bond has an IP address |
| 2992 | * |
| 2993 | * Note: a non-null current_arp_slave indicates |
| 2994 | * the curr_active_slave went down and we are |
| 2995 | * searching for a new one; under this condition |
| 2996 | * we only take the curr_active_slave down - this |
| 2997 | * gives each slave a chance to tx/rx traffic |
| 2998 | * before being taken out |
| 2999 | */ |
| 3000 | if (slave->state == BOND_STATE_BACKUP && |
| 3001 | !bond->current_arp_slave && |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3002 | !time_in_range(jiffies, |
| 3003 | slave_last_rx(bond, slave) - delta_in_ticks, |
| 3004 | slave_last_rx(bond, slave) + 3 * delta_in_ticks)) { |
| 3005 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3006 | slave->new_link = BOND_LINK_DOWN; |
| 3007 | commit++; |
| 3008 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3010 | /* |
| 3011 | * Active slave is down if: |
| 3012 | * - more than 2*delta since transmitting OR |
| 3013 | * - (more than 2*delta since receive AND |
| 3014 | * the bond has an IP address) |
| 3015 | */ |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3016 | trans_start = dev_trans_start(slave->dev); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3017 | if ((slave->state == BOND_STATE_ACTIVE) && |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3018 | (!time_in_range(jiffies, |
| 3019 | trans_start - delta_in_ticks, |
| 3020 | trans_start + 2 * delta_in_ticks) || |
| 3021 | !time_in_range(jiffies, |
| 3022 | slave_last_rx(bond, slave) - delta_in_ticks, |
| 3023 | slave_last_rx(bond, slave) + 2 * delta_in_ticks))) { |
| 3024 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3025 | slave->new_link = BOND_LINK_DOWN; |
| 3026 | commit++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | } |
| 3028 | } |
| 3029 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3030 | return commit; |
| 3031 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3033 | /* |
| 3034 | * Called to commit link state changes noted by inspection step of |
| 3035 | * active-backup mode ARP monitor. |
| 3036 | * |
| 3037 | * Called with RTNL and bond->lock for read. |
| 3038 | */ |
| 3039 | static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks) |
| 3040 | { |
| 3041 | struct slave *slave; |
| 3042 | int i; |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3043 | unsigned long trans_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3045 | bond_for_each_slave(bond, slave, i) { |
| 3046 | switch (slave->new_link) { |
| 3047 | case BOND_LINK_NOCHANGE: |
| 3048 | continue; |
| 3049 | |
| 3050 | case BOND_LINK_UP: |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3051 | trans_start = dev_trans_start(slave->dev); |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3052 | if ((!bond->curr_active_slave && |
Jiri Bohac | cb32f2a | 2010-09-02 05:45:54 +0000 | [diff] [blame] | 3053 | time_in_range(jiffies, |
| 3054 | trans_start - delta_in_ticks, |
| 3055 | trans_start + delta_in_ticks)) || |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3056 | bond->curr_active_slave != slave) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3057 | slave->link = BOND_LINK_UP; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3058 | bond->current_arp_slave = NULL; |
| 3059 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3060 | pr_info("%s: link status definitely up for interface %s.\n", |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3061 | bond->dev->name, slave->dev->name); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3062 | |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3063 | if (!bond->curr_active_slave || |
| 3064 | (slave == bond->primary_slave)) |
| 3065 | goto do_failover; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3066 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3069 | continue; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3070 | |
| 3071 | case BOND_LINK_DOWN: |
| 3072 | if (slave->link_failure_count < UINT_MAX) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | slave->link_failure_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3075 | slave->link = BOND_LINK_DOWN; |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3076 | bond_set_slave_inactive_flags(slave); |
| 3077 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3078 | 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] | 3079 | bond->dev->name, slave->dev->name); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3080 | |
| 3081 | if (slave == bond->curr_active_slave) { |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3082 | bond->current_arp_slave = NULL; |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3083 | goto do_failover; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3084 | } |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3085 | |
| 3086 | continue; |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3087 | |
| 3088 | default: |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3089 | pr_err("%s: impossible: new_link %d on slave %s\n", |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3090 | bond->dev->name, slave->new_link, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | slave->dev->name); |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3092 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3095 | do_failover: |
| 3096 | ASSERT_RTNL(); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 3097 | block_netpoll_tx(); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3098 | write_lock_bh(&bond->curr_slave_lock); |
Jiri Pirko | b9f6025 | 2009-08-31 11:09:38 +0000 | [diff] [blame] | 3099 | bond_select_active_slave(bond); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3100 | write_unlock_bh(&bond->curr_slave_lock); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 3101 | unblock_netpoll_tx(); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
| 3104 | bond_set_carrier(bond); |
| 3105 | } |
| 3106 | |
| 3107 | /* |
| 3108 | * Send ARP probes for active-backup mode ARP monitor. |
| 3109 | * |
| 3110 | * Called with bond->lock held for read. |
| 3111 | */ |
| 3112 | static void bond_ab_arp_probe(struct bonding *bond) |
| 3113 | { |
| 3114 | struct slave *slave; |
| 3115 | int i; |
| 3116 | |
| 3117 | read_lock(&bond->curr_slave_lock); |
| 3118 | |
| 3119 | if (bond->current_arp_slave && bond->curr_active_slave) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3120 | pr_info("PROBE: c_arp %s && cas %s BAD\n", |
| 3121 | bond->current_arp_slave->dev->name, |
| 3122 | bond->curr_active_slave->dev->name); |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3123 | |
| 3124 | if (bond->curr_active_slave) { |
| 3125 | bond_arp_send_all(bond, bond->curr_active_slave); |
| 3126 | read_unlock(&bond->curr_slave_lock); |
| 3127 | return; |
| 3128 | } |
| 3129 | |
| 3130 | read_unlock(&bond->curr_slave_lock); |
| 3131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | /* if we don't have a curr_active_slave, search for the next available |
| 3133 | * backup slave from the current_arp_slave and make it the candidate |
| 3134 | * for becoming the curr_active_slave |
| 3135 | */ |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3136 | |
| 3137 | if (!bond->current_arp_slave) { |
| 3138 | bond->current_arp_slave = bond->first_slave; |
| 3139 | if (!bond->current_arp_slave) |
| 3140 | return; |
| 3141 | } |
| 3142 | |
| 3143 | bond_set_slave_inactive_flags(bond->current_arp_slave); |
| 3144 | |
| 3145 | /* search for next candidate */ |
| 3146 | bond_for_each_slave_from(bond, slave, i, bond->current_arp_slave->next) { |
| 3147 | if (IS_UP(slave->dev)) { |
| 3148 | slave->link = BOND_LINK_BACK; |
| 3149 | bond_set_slave_active_flags(slave); |
| 3150 | bond_arp_send_all(bond, slave); |
| 3151 | slave->jiffies = jiffies; |
| 3152 | bond->current_arp_slave = slave; |
| 3153 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3156 | /* if the link state is up at this point, we |
| 3157 | * mark it down - this can happen if we have |
| 3158 | * simultaneous link failures and |
| 3159 | * reselect_active_interface doesn't make this |
| 3160 | * one the current slave so it is still marked |
| 3161 | * up when it is actually down |
| 3162 | */ |
| 3163 | if (slave->link == BOND_LINK_UP) { |
| 3164 | slave->link = BOND_LINK_DOWN; |
| 3165 | if (slave->link_failure_count < UINT_MAX) |
| 3166 | slave->link_failure_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3168 | bond_set_slave_inactive_flags(slave); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3170 | pr_info("%s: backup interface %s is now down.\n", |
| 3171 | bond->dev->name, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | } |
| 3173 | } |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | void bond_activebackup_arp_mon(struct work_struct *work) |
| 3177 | { |
| 3178 | struct bonding *bond = container_of(work, struct bonding, |
| 3179 | arp_work.work); |
| 3180 | int delta_in_ticks; |
| 3181 | |
| 3182 | read_lock(&bond->lock); |
| 3183 | |
| 3184 | if (bond->kill_timers) |
| 3185 | goto out; |
| 3186 | |
| 3187 | delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval); |
| 3188 | |
| 3189 | if (bond->slave_cnt == 0) |
| 3190 | goto re_arm; |
| 3191 | |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 3192 | if (bond->send_grat_arp) { |
| 3193 | read_lock(&bond->curr_slave_lock); |
| 3194 | bond_send_gratuitous_arp(bond); |
| 3195 | read_unlock(&bond->curr_slave_lock); |
| 3196 | } |
| 3197 | |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 3198 | if (bond->send_unsol_na) { |
| 3199 | read_lock(&bond->curr_slave_lock); |
| 3200 | bond_send_unsolicited_na(bond); |
| 3201 | read_unlock(&bond->curr_slave_lock); |
| 3202 | } |
| 3203 | |
Jay Vosburgh | b2220ca | 2008-05-17 21:10:13 -0700 | [diff] [blame] | 3204 | if (bond_ab_arp_inspect(bond, delta_in_ticks)) { |
| 3205 | read_unlock(&bond->lock); |
| 3206 | rtnl_lock(); |
| 3207 | read_lock(&bond->lock); |
| 3208 | |
| 3209 | bond_ab_arp_commit(bond, delta_in_ticks); |
| 3210 | |
| 3211 | read_unlock(&bond->lock); |
| 3212 | rtnl_unlock(); |
| 3213 | read_lock(&bond->lock); |
| 3214 | } |
| 3215 | |
| 3216 | bond_ab_arp_probe(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | |
| 3218 | re_arm: |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3219 | if (bond->params.arp_interval) |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3220 | queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | out: |
| 3222 | read_unlock(&bond->lock); |
| 3223 | } |
| 3224 | |
| 3225 | /*------------------------------ proc/seq_file-------------------------------*/ |
| 3226 | |
| 3227 | #ifdef CONFIG_PROC_FS |
| 3228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3229 | static void *bond_info_seq_start(struct seq_file *seq, loff_t *pos) |
Eric Dumazet | e4a7b93 | 2010-10-29 01:52:46 +0000 | [diff] [blame] | 3230 | __acquires(RCU) |
Hannes Eder | 1f78d9f | 2009-02-14 11:15:33 +0000 | [diff] [blame] | 3231 | __acquires(&bond->lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | { |
| 3233 | struct bonding *bond = seq->private; |
| 3234 | loff_t off = 0; |
| 3235 | struct slave *slave; |
| 3236 | int i; |
| 3237 | |
| 3238 | /* make sure the bond won't be taken away */ |
Eric Dumazet | e4a7b93 | 2010-10-29 01:52:46 +0000 | [diff] [blame] | 3239 | rcu_read_lock(); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 3240 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3242 | if (*pos == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | return SEQ_START_TOKEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | |
| 3245 | bond_for_each_slave(bond, slave, i) { |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3246 | if (++off == *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | return slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | return NULL; |
| 3251 | } |
| 3252 | |
| 3253 | static void *bond_info_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 3254 | { |
| 3255 | struct bonding *bond = seq->private; |
| 3256 | struct slave *slave = v; |
| 3257 | |
| 3258 | ++*pos; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3259 | if (v == SEQ_START_TOKEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | return bond->first_slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | |
| 3262 | slave = slave->next; |
| 3263 | |
| 3264 | return (slave == bond->first_slave) ? NULL : slave; |
| 3265 | } |
| 3266 | |
| 3267 | static void bond_info_seq_stop(struct seq_file *seq, void *v) |
Hannes Eder | 1f78d9f | 2009-02-14 11:15:33 +0000 | [diff] [blame] | 3268 | __releases(&bond->lock) |
Eric Dumazet | e4a7b93 | 2010-10-29 01:52:46 +0000 | [diff] [blame] | 3269 | __releases(RCU) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | { |
| 3271 | struct bonding *bond = seq->private; |
| 3272 | |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 3273 | read_unlock(&bond->lock); |
Eric Dumazet | e4a7b93 | 2010-10-29 01:52:46 +0000 | [diff] [blame] | 3274 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | static void bond_info_show_master(struct seq_file *seq) |
| 3278 | { |
| 3279 | struct bonding *bond = seq->private; |
| 3280 | struct slave *curr; |
Mitch Williams | 4756b02 | 2005-11-09 10:36:25 -0800 | [diff] [blame] | 3281 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3282 | |
| 3283 | read_lock(&bond->curr_slave_lock); |
| 3284 | curr = bond->curr_active_slave; |
| 3285 | read_unlock(&bond->curr_slave_lock); |
| 3286 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 3287 | seq_printf(seq, "Bonding Mode: %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | bond_mode_name(bond->params.mode)); |
| 3289 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 3290 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP && |
| 3291 | bond->params.fail_over_mac) |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 3292 | seq_printf(seq, " (fail_over_mac %s)", |
| 3293 | fail_over_mac_tbl[bond->params.fail_over_mac].modename); |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 3294 | |
| 3295 | seq_printf(seq, "\n"); |
| 3296 | |
Mitch Williams | c61b75a | 2005-11-09 10:35:13 -0800 | [diff] [blame] | 3297 | if (bond->params.mode == BOND_MODE_XOR || |
| 3298 | bond->params.mode == BOND_MODE_8023AD) { |
| 3299 | seq_printf(seq, "Transmit Hash Policy: %s (%d)\n", |
| 3300 | xmit_hashtype_tbl[bond->params.xmit_policy].modename, |
| 3301 | bond->params.xmit_policy); |
| 3302 | } |
| 3303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | if (USES_PRIMARY(bond->params.mode)) { |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 3305 | seq_printf(seq, "Primary Slave: %s", |
Mitch Williams | 0f418b2 | 2005-11-09 10:35:21 -0800 | [diff] [blame] | 3306 | (bond->primary_slave) ? |
| 3307 | bond->primary_slave->dev->name : "None"); |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 3308 | if (bond->primary_slave) |
| 3309 | seq_printf(seq, " (primary_reselect %s)", |
| 3310 | pri_reselect_tbl[bond->params.primary_reselect].modename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 3312 | seq_printf(seq, "\nCurrently Active Slave: %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | (curr) ? curr->dev->name : "None"); |
| 3314 | } |
| 3315 | |
Jay Vosburgh | ff59c45 | 2006-03-27 13:27:43 -0800 | [diff] [blame] | 3316 | seq_printf(seq, "MII Status: %s\n", netif_carrier_ok(bond->dev) ? |
| 3317 | "up" : "down"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | seq_printf(seq, "MII Polling Interval (ms): %d\n", bond->params.miimon); |
| 3319 | seq_printf(seq, "Up Delay (ms): %d\n", |
| 3320 | bond->params.updelay * bond->params.miimon); |
| 3321 | seq_printf(seq, "Down Delay (ms): %d\n", |
| 3322 | bond->params.downdelay * bond->params.miimon); |
| 3323 | |
Mitch Williams | 4756b02 | 2005-11-09 10:36:25 -0800 | [diff] [blame] | 3324 | |
| 3325 | /* ARP information */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3326 | if (bond->params.arp_interval > 0) { |
| 3327 | int printed = 0; |
Mitch Williams | 4756b02 | 2005-11-09 10:36:25 -0800 | [diff] [blame] | 3328 | seq_printf(seq, "ARP Polling Interval (ms): %d\n", |
| 3329 | bond->params.arp_interval); |
| 3330 | |
| 3331 | seq_printf(seq, "ARP IP target/s (n.n.n.n form):"); |
| 3332 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3333 | for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) { |
Mitch Williams | 4756b02 | 2005-11-09 10:36:25 -0800 | [diff] [blame] | 3334 | if (!bond->params.arp_targets[i]) |
Brian Haley | 5a31bec | 2009-04-13 00:11:30 -0700 | [diff] [blame] | 3335 | break; |
Mitch Williams | 4756b02 | 2005-11-09 10:36:25 -0800 | [diff] [blame] | 3336 | if (printed) |
| 3337 | seq_printf(seq, ","); |
Harvey Harrison | 8cf14e3 | 2008-10-29 22:43:33 -0700 | [diff] [blame] | 3338 | seq_printf(seq, " %pI4", &bond->params.arp_targets[i]); |
Mitch Williams | 4756b02 | 2005-11-09 10:36:25 -0800 | [diff] [blame] | 3339 | printed = 1; |
| 3340 | } |
| 3341 | seq_printf(seq, "\n"); |
| 3342 | } |
| 3343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 3345 | struct ad_info ad_info; |
| 3346 | |
| 3347 | seq_puts(seq, "\n802.3ad info\n"); |
| 3348 | seq_printf(seq, "LACP rate: %s\n", |
| 3349 | (bond->params.lacp_fast) ? "fast" : "slow"); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 3350 | seq_printf(seq, "Aggregator selection policy (ad_select): %s\n", |
| 3351 | ad_select_tbl[bond->params.ad_select].modename); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | |
| 3353 | if (bond_3ad_get_active_agg_info(bond, &ad_info)) { |
| 3354 | seq_printf(seq, "bond %s has no active aggregator\n", |
| 3355 | bond->dev->name); |
| 3356 | } else { |
| 3357 | seq_printf(seq, "Active Aggregator Info:\n"); |
| 3358 | |
| 3359 | seq_printf(seq, "\tAggregator ID: %d\n", |
| 3360 | ad_info.aggregator_id); |
| 3361 | seq_printf(seq, "\tNumber of ports: %d\n", |
| 3362 | ad_info.ports); |
| 3363 | seq_printf(seq, "\tActor Key: %d\n", |
| 3364 | ad_info.actor_key); |
| 3365 | seq_printf(seq, "\tPartner Key: %d\n", |
| 3366 | ad_info.partner_key); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3367 | seq_printf(seq, "\tPartner Mac Address: %pM\n", |
| 3368 | ad_info.partner_system); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | } |
| 3370 | } |
| 3371 | } |
| 3372 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3373 | static void bond_info_show_slave(struct seq_file *seq, |
| 3374 | const struct slave *slave) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | { |
| 3376 | struct bonding *bond = seq->private; |
| 3377 | |
| 3378 | seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); |
| 3379 | seq_printf(seq, "MII Status: %s\n", |
| 3380 | (slave->link == BOND_LINK_UP) ? "up" : "down"); |
Krzysztof Oledzki | dd53df2 | 2010-09-30 06:19:04 +0000 | [diff] [blame] | 3381 | seq_printf(seq, "Speed: %d Mbps\n", slave->speed); |
| 3382 | seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); |
Kenzo Iwami | 65509645 | 2006-09-22 21:53:08 -0700 | [diff] [blame] | 3383 | seq_printf(seq, "Link Failure Count: %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | slave->link_failure_count); |
| 3385 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3386 | seq_printf(seq, "Permanent HW addr: %pM\n", slave->perm_hwaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | |
| 3388 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 3389 | const struct aggregator *agg |
| 3390 | = SLAVE_AD_INFO(slave).port.aggregator; |
| 3391 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3392 | if (agg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | seq_printf(seq, "Aggregator ID: %d\n", |
| 3394 | agg->aggregator_identifier); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3395 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | seq_puts(seq, "Aggregator ID: N/A\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | } |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 3398 | seq_printf(seq, "Slave queue ID: %d\n", slave->queue_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | static int bond_info_seq_show(struct seq_file *seq, void *v) |
| 3402 | { |
| 3403 | if (v == SEQ_START_TOKEN) { |
| 3404 | seq_printf(seq, "%s\n", version); |
| 3405 | bond_info_show_master(seq); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3406 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3407 | bond_info_show_slave(seq, v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | |
| 3409 | return 0; |
| 3410 | } |
| 3411 | |
Jan Engelhardt | 4101dec | 2009-01-14 13:52:18 -0800 | [diff] [blame] | 3412 | static const struct seq_operations bond_info_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | .start = bond_info_seq_start, |
| 3414 | .next = bond_info_seq_next, |
| 3415 | .stop = bond_info_seq_stop, |
| 3416 | .show = bond_info_seq_show, |
| 3417 | }; |
| 3418 | |
| 3419 | static int bond_info_open(struct inode *inode, struct file *file) |
| 3420 | { |
| 3421 | struct seq_file *seq; |
| 3422 | struct proc_dir_entry *proc; |
| 3423 | int res; |
| 3424 | |
| 3425 | res = seq_open(file, &bond_info_seq_ops); |
| 3426 | if (!res) { |
| 3427 | /* recover the pointer buried in proc_dir_entry data */ |
| 3428 | seq = file->private_data; |
| 3429 | proc = PDE(inode); |
| 3430 | seq->private = proc->data; |
| 3431 | } |
| 3432 | |
| 3433 | return res; |
| 3434 | } |
| 3435 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 3436 | static const struct file_operations bond_info_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | .owner = THIS_MODULE, |
| 3438 | .open = bond_info_open, |
| 3439 | .read = seq_read, |
| 3440 | .llseek = seq_lseek, |
| 3441 | .release = seq_release, |
| 3442 | }; |
| 3443 | |
Nicolas de Pesloüan | 38fc002 | 2009-10-13 00:45:06 -0700 | [diff] [blame] | 3444 | static void bond_create_proc_entry(struct bonding *bond) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3445 | { |
| 3446 | struct net_device *bond_dev = bond->dev; |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3447 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3449 | if (bn->proc_dir) { |
Denis V. Lunev | a95609c | 2008-04-29 01:02:29 -0700 | [diff] [blame] | 3450 | bond->proc_entry = proc_create_data(bond_dev->name, |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3451 | S_IRUGO, bn->proc_dir, |
Denis V. Lunev | a95609c | 2008-04-29 01:02:29 -0700 | [diff] [blame] | 3452 | &bond_info_fops, bond); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3453 | if (bond->proc_entry == NULL) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3454 | pr_warning("Warning: Cannot create /proc/net/%s/%s\n", |
| 3455 | DRV_NAME, bond_dev->name); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3456 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3457 | memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | static void bond_remove_proc_entry(struct bonding *bond) |
| 3462 | { |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3463 | struct net_device *bond_dev = bond->dev; |
| 3464 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
| 3465 | |
| 3466 | if (bn->proc_dir && bond->proc_entry) { |
| 3467 | remove_proc_entry(bond->proc_file_name, bn->proc_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | memset(bond->proc_file_name, 0, IFNAMSIZ); |
| 3469 | bond->proc_entry = NULL; |
| 3470 | } |
| 3471 | } |
| 3472 | |
| 3473 | /* Create the bonding directory under /proc/net, if doesn't exist yet. |
| 3474 | * Caller must hold rtnl_lock. |
| 3475 | */ |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 3476 | static void __net_init bond_create_proc_dir(struct bond_net *bn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | { |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3478 | if (!bn->proc_dir) { |
| 3479 | bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net); |
| 3480 | if (!bn->proc_dir) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3481 | pr_warning("Warning: cannot create /proc/net/%s\n", |
| 3482 | DRV_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | } |
| 3484 | } |
| 3485 | |
| 3486 | /* Destroy the bonding directory under /proc/net, if empty. |
| 3487 | * Caller must hold rtnl_lock. |
| 3488 | */ |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 3489 | static void __net_exit bond_destroy_proc_dir(struct bond_net *bn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | { |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3491 | if (bn->proc_dir) { |
| 3492 | remove_proc_entry(DRV_NAME, bn->net->proc_net); |
| 3493 | bn->proc_dir = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | } |
| 3495 | } |
Jiri Pirko | aee64fa | 2009-05-05 06:20:51 +0000 | [diff] [blame] | 3496 | |
| 3497 | #else /* !CONFIG_PROC_FS */ |
| 3498 | |
Nicolas de Pesloüan | 38fc002 | 2009-10-13 00:45:06 -0700 | [diff] [blame] | 3499 | static void bond_create_proc_entry(struct bonding *bond) |
Jiri Pirko | aee64fa | 2009-05-05 06:20:51 +0000 | [diff] [blame] | 3500 | { |
| 3501 | } |
| 3502 | |
| 3503 | static void bond_remove_proc_entry(struct bonding *bond) |
| 3504 | { |
| 3505 | } |
| 3506 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 3507 | static inline void bond_create_proc_dir(struct bond_net *bn) |
Jiri Pirko | aee64fa | 2009-05-05 06:20:51 +0000 | [diff] [blame] | 3508 | { |
| 3509 | } |
| 3510 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 3511 | static inline void bond_destroy_proc_dir(struct bond_net *bn) |
Jiri Pirko | aee64fa | 2009-05-05 06:20:51 +0000 | [diff] [blame] | 3512 | { |
| 3513 | } |
| 3514 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | #endif /* CONFIG_PROC_FS */ |
| 3516 | |
Jiri Pirko | aee64fa | 2009-05-05 06:20:51 +0000 | [diff] [blame] | 3517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | /*-------------------------- netdev event handling --------------------------*/ |
| 3519 | |
| 3520 | /* |
| 3521 | * Change device name |
| 3522 | */ |
| 3523 | static int bond_event_changename(struct bonding *bond) |
| 3524 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | bond_remove_proc_entry(bond); |
| 3526 | bond_create_proc_entry(bond); |
Stephen Hemminger | 7e08384 | 2009-06-12 19:02:46 +0000 | [diff] [blame] | 3527 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 3528 | bond_debug_reregister(bond); |
| 3529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3530 | return NOTIFY_DONE; |
| 3531 | } |
| 3532 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3533 | static int bond_master_netdev_event(unsigned long event, |
| 3534 | struct net_device *bond_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3535 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3536 | struct bonding *event_bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | |
| 3538 | switch (event) { |
| 3539 | case NETDEV_CHANGENAME: |
| 3540 | return bond_event_changename(event_bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | default: |
| 3542 | break; |
| 3543 | } |
| 3544 | |
| 3545 | return NOTIFY_DONE; |
| 3546 | } |
| 3547 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3548 | static int bond_slave_netdev_event(unsigned long event, |
| 3549 | struct net_device *slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | { |
| 3551 | struct net_device *bond_dev = slave_dev->master; |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3552 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | |
| 3554 | switch (event) { |
| 3555 | case NETDEV_UNREGISTER: |
| 3556 | if (bond_dev) { |
Jay Vosburgh | 1284cd3 | 2007-10-15 16:44:27 -0700 | [diff] [blame] | 3557 | if (bond->setup_by_slave) |
| 3558 | bond_release_and_destroy(bond_dev, slave_dev); |
| 3559 | else |
| 3560 | bond_release(bond_dev, slave_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
| 3562 | break; |
| 3563 | case NETDEV_CHANGE: |
Jay Vosburgh | 17d0450 | 2009-03-18 18:38:25 -0700 | [diff] [blame] | 3564 | if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) { |
| 3565 | struct slave *slave; |
| 3566 | |
| 3567 | slave = bond_get_slave_by_dev(bond, slave_dev); |
| 3568 | if (slave) { |
| 3569 | u16 old_speed = slave->speed; |
| 3570 | u16 old_duplex = slave->duplex; |
| 3571 | |
| 3572 | bond_update_speed_duplex(slave); |
| 3573 | |
| 3574 | if (bond_is_lb(bond)) |
| 3575 | break; |
| 3576 | |
| 3577 | if (old_speed != slave->speed) |
| 3578 | bond_3ad_adapter_speed_changed(slave); |
| 3579 | if (old_duplex != slave->duplex) |
| 3580 | bond_3ad_adapter_duplex_changed(slave); |
| 3581 | } |
| 3582 | } |
| 3583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3584 | break; |
| 3585 | case NETDEV_DOWN: |
| 3586 | /* |
| 3587 | * ... Or is it this? |
| 3588 | */ |
| 3589 | break; |
| 3590 | case NETDEV_CHANGEMTU: |
| 3591 | /* |
| 3592 | * TODO: Should slaves be allowed to |
| 3593 | * independently alter their MTU? For |
| 3594 | * an active-backup bond, slaves need |
| 3595 | * not be the same type of device, so |
| 3596 | * MTUs may vary. For other modes, |
| 3597 | * slaves arguably should have the |
| 3598 | * same MTUs. To do this, we'd need to |
| 3599 | * take over the slave's change_mtu |
| 3600 | * function for the duration of their |
| 3601 | * servitude. |
| 3602 | */ |
| 3603 | break; |
| 3604 | case NETDEV_CHANGENAME: |
| 3605 | /* |
| 3606 | * TODO: handle changing the primary's name |
| 3607 | */ |
| 3608 | break; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 3609 | case NETDEV_FEAT_CHANGE: |
| 3610 | bond_compute_features(bond); |
| 3611 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | default: |
| 3613 | break; |
| 3614 | } |
| 3615 | |
| 3616 | return NOTIFY_DONE; |
| 3617 | } |
| 3618 | |
| 3619 | /* |
| 3620 | * bond_netdev_event: handle netdev notifier chain events. |
| 3621 | * |
| 3622 | * This function receives events for the netdev chain. The caller (an |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 3623 | * ioctl handler calling blocking_notifier_call_chain) holds the necessary |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | * locks for us to safely manipulate the slave devices (RTNL lock, |
| 3625 | * dev_probe_lock). |
| 3626 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3627 | static int bond_netdev_event(struct notifier_block *this, |
| 3628 | unsigned long event, void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3629 | { |
| 3630 | struct net_device *event_dev = (struct net_device *)ptr; |
| 3631 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3632 | pr_debug("event_dev: %s, event: %lx\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3633 | event_dev ? event_dev->name : "None", |
| 3634 | event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3635 | |
Jay Vosburgh | 0b680e7 | 2006-09-22 21:54:10 -0700 | [diff] [blame] | 3636 | if (!(event_dev->priv_flags & IFF_BONDING)) |
| 3637 | return NOTIFY_DONE; |
| 3638 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | if (event_dev->flags & IFF_MASTER) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3640 | pr_debug("IFF_MASTER\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | return bond_master_netdev_event(event, event_dev); |
| 3642 | } |
| 3643 | |
| 3644 | if (event_dev->flags & IFF_SLAVE) { |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 3645 | pr_debug("IFF_SLAVE\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | return bond_slave_netdev_event(event, event_dev); |
| 3647 | } |
| 3648 | |
| 3649 | return NOTIFY_DONE; |
| 3650 | } |
| 3651 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3652 | /* |
| 3653 | * bond_inetaddr_event: handle inetaddr notifier chain events. |
| 3654 | * |
| 3655 | * We keep track of device IPs primarily to use as source addresses in |
| 3656 | * ARP monitor probes (rather than spewing out broadcasts all the time). |
| 3657 | * |
| 3658 | * We track one IP for the main device (if it has one), plus one per VLAN. |
| 3659 | */ |
| 3660 | static int bond_inetaddr_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 3661 | { |
| 3662 | struct in_ifaddr *ifa = ptr; |
| 3663 | struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev; |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3664 | 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] | 3665 | struct bonding *bond; |
| 3666 | struct vlan_entry *vlan; |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3667 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 3668 | list_for_each_entry(bond, &bn->dev_list, bond_list) { |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3669 | if (bond->dev == event_dev) { |
| 3670 | switch (event) { |
| 3671 | case NETDEV_UP: |
| 3672 | bond->master_ip = ifa->ifa_local; |
| 3673 | return NOTIFY_OK; |
| 3674 | case NETDEV_DOWN: |
| 3675 | bond->master_ip = bond_glean_dev_ip(bond->dev); |
| 3676 | return NOTIFY_OK; |
| 3677 | default: |
| 3678 | return NOTIFY_DONE; |
| 3679 | } |
| 3680 | } |
| 3681 | |
Pavel Emelyanov | 0883bec | 2008-05-17 21:10:10 -0700 | [diff] [blame] | 3682 | list_for_each_entry(vlan, &bond->vlan_list, vlan_list) { |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 3683 | if (!bond->vlgrp) |
| 3684 | continue; |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 3685 | vlan_dev = vlan_group_get_device(bond->vlgrp, vlan->vlan_id); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3686 | if (vlan_dev == event_dev) { |
| 3687 | switch (event) { |
| 3688 | case NETDEV_UP: |
| 3689 | vlan->vlan_ip = ifa->ifa_local; |
| 3690 | return NOTIFY_OK; |
| 3691 | case NETDEV_DOWN: |
| 3692 | vlan->vlan_ip = |
| 3693 | bond_glean_dev_ip(vlan_dev); |
| 3694 | return NOTIFY_OK; |
| 3695 | default: |
| 3696 | return NOTIFY_DONE; |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | } |
| 3701 | return NOTIFY_DONE; |
| 3702 | } |
| 3703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3704 | static struct notifier_block bond_netdev_notifier = { |
| 3705 | .notifier_call = bond_netdev_event, |
| 3706 | }; |
| 3707 | |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 3708 | static struct notifier_block bond_inetaddr_notifier = { |
| 3709 | .notifier_call = bond_inetaddr_event, |
| 3710 | }; |
| 3711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | /*-------------------------- Packet type handling ---------------------------*/ |
| 3713 | |
| 3714 | /* register to receive lacpdus on a bond */ |
| 3715 | static void bond_register_lacpdu(struct bonding *bond) |
| 3716 | { |
| 3717 | struct packet_type *pk_type = &(BOND_AD_INFO(bond).ad_pkt_type); |
| 3718 | |
| 3719 | /* initialize packet type */ |
| 3720 | pk_type->type = PKT_TYPE_LACPDU; |
| 3721 | pk_type->dev = bond->dev; |
| 3722 | pk_type->func = bond_3ad_lacpdu_recv; |
| 3723 | |
| 3724 | dev_add_pack(pk_type); |
| 3725 | } |
| 3726 | |
| 3727 | /* unregister to receive lacpdus on a bond */ |
| 3728 | static void bond_unregister_lacpdu(struct bonding *bond) |
| 3729 | { |
| 3730 | dev_remove_pack(&(BOND_AD_INFO(bond).ad_pkt_type)); |
| 3731 | } |
| 3732 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3733 | void bond_register_arp(struct bonding *bond) |
| 3734 | { |
| 3735 | struct packet_type *pt = &bond->arp_mon_pt; |
| 3736 | |
Jay Vosburgh | c4f283b | 2007-02-28 17:03:20 -0800 | [diff] [blame] | 3737 | if (pt->type) |
| 3738 | return; |
| 3739 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3740 | pt->type = htons(ETH_P_ARP); |
Jay Vosburgh | e245cb7 | 2007-02-28 17:03:27 -0800 | [diff] [blame] | 3741 | pt->dev = bond->dev; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3742 | pt->func = bond_arp_rcv; |
| 3743 | dev_add_pack(pt); |
| 3744 | } |
| 3745 | |
| 3746 | void bond_unregister_arp(struct bonding *bond) |
| 3747 | { |
Jay Vosburgh | c4f283b | 2007-02-28 17:03:20 -0800 | [diff] [blame] | 3748 | struct packet_type *pt = &bond->arp_mon_pt; |
| 3749 | |
| 3750 | dev_remove_pack(pt); |
| 3751 | pt->type = 0; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3754 | /*---------------------------- Hashing Policies -----------------------------*/ |
| 3755 | |
| 3756 | /* |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3757 | * Hash for the output device based upon layer 2 and layer 3 data. If |
| 3758 | * the packet is not IP mimic bond_xmit_hash_policy_l2() |
| 3759 | */ |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 3760 | 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] | 3761 | { |
| 3762 | struct ethhdr *data = (struct ethhdr *)skb->data; |
| 3763 | struct iphdr *iph = ip_hdr(skb); |
| 3764 | |
Brian Haley | f14c4e4 | 2008-09-02 10:08:08 -0400 | [diff] [blame] | 3765 | if (skb->protocol == htons(ETH_P_IP)) { |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3766 | return ((ntohl(iph->saddr ^ iph->daddr) & 0xffff) ^ |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3767 | (data->h_dest[5] ^ data->h_source[5])) % count; |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3770 | return (data->h_dest[5] ^ data->h_source[5]) % count; |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | /* |
Michael Opdenacker | 59c5159 | 2007-05-09 08:57:56 +0200 | [diff] [blame] | 3774 | * 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] | 3775 | * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is |
| 3776 | * altogether not IP, mimic bond_xmit_hash_policy_l2() |
| 3777 | */ |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 3778 | 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] | 3779 | { |
| 3780 | struct ethhdr *data = (struct ethhdr *)skb->data; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 3781 | struct iphdr *iph = ip_hdr(skb); |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 3782 | __be16 *layer4hdr = (__be16 *)((u32 *)iph + iph->ihl); |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3783 | int layer4_xor = 0; |
| 3784 | |
Brian Haley | f14c4e4 | 2008-09-02 10:08:08 -0400 | [diff] [blame] | 3785 | if (skb->protocol == htons(ETH_P_IP)) { |
| 3786 | if (!(iph->frag_off & htons(IP_MF|IP_OFFSET)) && |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3787 | (iph->protocol == IPPROTO_TCP || |
| 3788 | iph->protocol == IPPROTO_UDP)) { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 3789 | layer4_xor = ntohs((*layer4hdr ^ *(layer4hdr + 1))); |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3790 | } |
| 3791 | return (layer4_xor ^ |
| 3792 | ((ntohl(iph->saddr ^ iph->daddr)) & 0xffff)) % count; |
| 3793 | |
| 3794 | } |
| 3795 | |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3796 | return (data->h_dest[5] ^ data->h_source[5]) % count; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | /* |
| 3800 | * Hash for the output device based upon layer 2 data |
| 3801 | */ |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 3802 | 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] | 3803 | { |
| 3804 | struct ethhdr *data = (struct ethhdr *)skb->data; |
| 3805 | |
Jasper Spaans | d3da683 | 2009-10-23 04:08:46 +0000 | [diff] [blame] | 3806 | return (data->h_dest[5] ^ data->h_source[5]) % count; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 3807 | } |
| 3808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | /*-------------------------- Device entry points ----------------------------*/ |
| 3810 | |
| 3811 | static int bond_open(struct net_device *bond_dev) |
| 3812 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3813 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
| 3815 | bond->kill_timers = 0; |
| 3816 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 3817 | INIT_DELAYED_WORK(&bond->mcast_work, bond_resend_igmp_join_requests_delayed); |
| 3818 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 3819 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3820 | /* bond_alb_initialize must be called before the timer |
| 3821 | * is started. |
| 3822 | */ |
| 3823 | if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) { |
| 3824 | /* something went wrong - fail the open operation */ |
stephen hemminger | b473946 | 2010-01-25 23:34:15 +0000 | [diff] [blame] | 3825 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3828 | INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor); |
| 3829 | queue_delayed_work(bond->wq, &bond->alb_work, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | if (bond->params.miimon) { /* link check interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3833 | INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor); |
| 3834 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | if (bond->params.arp_interval) { /* arp interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3838 | if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) |
| 3839 | INIT_DELAYED_WORK(&bond->arp_work, |
| 3840 | bond_activebackup_arp_mon); |
| 3841 | else |
| 3842 | INIT_DELAYED_WORK(&bond->arp_work, |
| 3843 | bond_loadbalance_arp_mon); |
| 3844 | |
| 3845 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3846 | if (bond->params.arp_validate) |
| 3847 | bond_register_arp(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | if (bond->params.mode == BOND_MODE_8023AD) { |
Adrian Bunk | a40745f | 2007-10-24 18:27:43 +0200 | [diff] [blame] | 3851 | INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler); |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3852 | queue_delayed_work(bond->wq, &bond->ad_work, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | /* register to receive LACPDUs */ |
| 3854 | bond_register_lacpdu(bond); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 3855 | bond_3ad_initiate_agg_selection(bond, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | } |
| 3857 | |
| 3858 | return 0; |
| 3859 | } |
| 3860 | |
| 3861 | static int bond_close(struct net_device *bond_dev) |
| 3862 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3863 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3864 | |
| 3865 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 3866 | /* Unregister the receive of LACPDUs */ |
| 3867 | bond_unregister_lacpdu(bond); |
| 3868 | } |
| 3869 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 3870 | if (bond->params.arp_validate) |
| 3871 | bond_unregister_arp(bond); |
| 3872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | write_lock_bh(&bond->lock); |
| 3874 | |
Jay Vosburgh | b59f9f7 | 2008-06-13 18:12:03 -0700 | [diff] [blame] | 3875 | bond->send_grat_arp = 0; |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 3876 | bond->send_unsol_na = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3877 | |
| 3878 | /* signal timers not to re-arm */ |
| 3879 | bond->kill_timers = 1; |
| 3880 | |
| 3881 | write_unlock_bh(&bond->lock); |
| 3882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | if (bond->params.miimon) { /* link check interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3884 | cancel_delayed_work(&bond->mii_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | if (bond->params.arp_interval) { /* arp interval, in milliseconds. */ |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3888 | cancel_delayed_work(&bond->arp_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | switch (bond->params.mode) { |
| 3892 | case BOND_MODE_8023AD: |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3893 | cancel_delayed_work(&bond->ad_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3894 | break; |
| 3895 | case BOND_MODE_TLB: |
| 3896 | case BOND_MODE_ALB: |
Jay Vosburgh | 1b76b31 | 2007-10-17 17:37:45 -0700 | [diff] [blame] | 3897 | cancel_delayed_work(&bond->alb_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3898 | break; |
| 3899 | default: |
| 3900 | break; |
| 3901 | } |
| 3902 | |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 3903 | if (delayed_work_pending(&bond->mcast_work)) |
| 3904 | cancel_delayed_work(&bond->mcast_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | |
Holger Eitzenberger | 5840205 | 2008-12-09 23:07:13 -0800 | [diff] [blame] | 3906 | if (bond_is_lb(bond)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | /* Must be called only after all |
| 3908 | * slaves have been released |
| 3909 | */ |
| 3910 | bond_alb_deinitialize(bond); |
| 3911 | } |
| 3912 | |
| 3913 | return 0; |
| 3914 | } |
| 3915 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3916 | static struct rtnl_link_stats64 *bond_get_stats(struct net_device *bond_dev, |
| 3917 | struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 3919 | struct bonding *bond = netdev_priv(bond_dev); |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3920 | struct rtnl_link_stats64 temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3921 | struct slave *slave; |
| 3922 | int i; |
| 3923 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3924 | memset(stats, 0, sizeof(*stats)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3925 | |
| 3926 | read_lock_bh(&bond->lock); |
| 3927 | |
| 3928 | bond_for_each_slave(bond, slave, i) { |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 3929 | const struct rtnl_link_stats64 *sstats = |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3930 | dev_get_stats(slave->dev, &temp); |
Stephen Hemminger | eeda3fd | 2008-11-19 21:40:23 -0800 | [diff] [blame] | 3931 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3932 | stats->rx_packets += sstats->rx_packets; |
| 3933 | stats->rx_bytes += sstats->rx_bytes; |
| 3934 | stats->rx_errors += sstats->rx_errors; |
| 3935 | stats->rx_dropped += sstats->rx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3937 | stats->tx_packets += sstats->tx_packets; |
| 3938 | stats->tx_bytes += sstats->tx_bytes; |
| 3939 | stats->tx_errors += sstats->tx_errors; |
| 3940 | stats->tx_dropped += sstats->tx_dropped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3942 | stats->multicast += sstats->multicast; |
| 3943 | stats->collisions += sstats->collisions; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3945 | stats->rx_length_errors += sstats->rx_length_errors; |
| 3946 | stats->rx_over_errors += sstats->rx_over_errors; |
| 3947 | stats->rx_crc_errors += sstats->rx_crc_errors; |
| 3948 | stats->rx_frame_errors += sstats->rx_frame_errors; |
| 3949 | stats->rx_fifo_errors += sstats->rx_fifo_errors; |
| 3950 | stats->rx_missed_errors += sstats->rx_missed_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 3952 | stats->tx_aborted_errors += sstats->tx_aborted_errors; |
| 3953 | stats->tx_carrier_errors += sstats->tx_carrier_errors; |
| 3954 | stats->tx_fifo_errors += sstats->tx_fifo_errors; |
| 3955 | stats->tx_heartbeat_errors += sstats->tx_heartbeat_errors; |
| 3956 | stats->tx_window_errors += sstats->tx_window_errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | read_unlock_bh(&bond->lock); |
| 3960 | |
| 3961 | return stats; |
| 3962 | } |
| 3963 | |
| 3964 | static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd) |
| 3965 | { |
| 3966 | struct net_device *slave_dev = NULL; |
| 3967 | struct ifbond k_binfo; |
| 3968 | struct ifbond __user *u_binfo = NULL; |
| 3969 | struct ifslave k_sinfo; |
| 3970 | struct ifslave __user *u_sinfo = NULL; |
| 3971 | struct mii_ioctl_data *mii = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | int res = 0; |
| 3973 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 3974 | 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] | 3975 | |
| 3976 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | case SIOCGMIIPHY: |
| 3978 | mii = if_mii(ifr); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3979 | if (!mii) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3980 | return -EINVAL; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3982 | mii->phy_id = 0; |
| 3983 | /* Fall Through */ |
| 3984 | case SIOCGMIIREG: |
| 3985 | /* |
| 3986 | * We do this again just in case we were called by SIOCGMIIREG |
| 3987 | * instead of SIOCGMIIPHY. |
| 3988 | */ |
| 3989 | mii = if_mii(ifr); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3990 | if (!mii) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | return -EINVAL; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3993 | |
| 3994 | if (mii->reg_num == 1) { |
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 | mii->val_out = 0; |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 3997 | read_lock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | read_lock(&bond->curr_slave_lock); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 3999 | if (netif_carrier_ok(bond->dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | mii->val_out = BMSR_LSTATUS; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4002 | read_unlock(&bond->curr_slave_lock); |
Jay Vosburgh | 6603a6f | 2007-10-17 17:37:50 -0700 | [diff] [blame] | 4003 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | } |
| 4005 | |
| 4006 | return 0; |
| 4007 | case BOND_INFO_QUERY_OLD: |
| 4008 | case SIOCBONDINFOQUERY: |
| 4009 | u_binfo = (struct ifbond __user *)ifr->ifr_data; |
| 4010 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4011 | if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | |
| 4014 | res = bond_info_query(bond_dev, &k_binfo); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4015 | if (res == 0 && |
| 4016 | copy_to_user(u_binfo, &k_binfo, sizeof(ifbond))) |
| 4017 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | |
| 4019 | return res; |
| 4020 | case BOND_SLAVE_INFO_QUERY_OLD: |
| 4021 | case SIOCBONDSLAVEINFOQUERY: |
| 4022 | u_sinfo = (struct ifslave __user *)ifr->ifr_data; |
| 4023 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4024 | if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | |
| 4027 | res = bond_slave_info_query(bond_dev, &k_sinfo); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4028 | if (res == 0 && |
| 4029 | copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave))) |
| 4030 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4031 | |
| 4032 | return res; |
| 4033 | default: |
| 4034 | /* Go on */ |
| 4035 | break; |
| 4036 | } |
| 4037 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4038 | if (!capable(CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 4041 | 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] | 4042 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4043 | pr_debug("slave_dev=%p:\n", slave_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4045 | if (!slave_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | res = -ENODEV; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4047 | else { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4048 | pr_debug("slave_dev->name=%s:\n", slave_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | switch (cmd) { |
| 4050 | case BOND_ENSLAVE_OLD: |
| 4051 | case SIOCBONDENSLAVE: |
| 4052 | res = bond_enslave(bond_dev, slave_dev); |
| 4053 | break; |
| 4054 | case BOND_RELEASE_OLD: |
| 4055 | case SIOCBONDRELEASE: |
| 4056 | res = bond_release(bond_dev, slave_dev); |
| 4057 | break; |
| 4058 | case BOND_SETHWADDR_OLD: |
| 4059 | case SIOCBONDSETHWADDR: |
| 4060 | res = bond_sethwaddr(bond_dev, slave_dev); |
| 4061 | break; |
| 4062 | case BOND_CHANGE_ACTIVE_OLD: |
| 4063 | case SIOCBONDCHANGEACTIVE: |
| 4064 | res = bond_ioctl_change_active(bond_dev, slave_dev); |
| 4065 | break; |
| 4066 | default: |
| 4067 | res = -EOPNOTSUPP; |
| 4068 | } |
| 4069 | |
| 4070 | dev_put(slave_dev); |
| 4071 | } |
| 4072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4073 | return res; |
| 4074 | } |
| 4075 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4076 | static bool bond_addr_in_mc_list(unsigned char *addr, |
| 4077 | struct netdev_hw_addr_list *list, |
| 4078 | int addrlen) |
| 4079 | { |
| 4080 | struct netdev_hw_addr *ha; |
| 4081 | |
| 4082 | netdev_hw_addr_list_for_each(ha, list) |
| 4083 | if (!memcmp(ha->addr, addr, addrlen)) |
| 4084 | return true; |
| 4085 | |
| 4086 | return false; |
| 4087 | } |
| 4088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4089 | static void bond_set_multicast_list(struct net_device *bond_dev) |
| 4090 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4091 | struct bonding *bond = netdev_priv(bond_dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4092 | struct netdev_hw_addr *ha; |
| 4093 | bool found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | /* |
| 4096 | * Do promisc before checking multicast_mode |
| 4097 | */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4098 | if ((bond_dev->flags & IFF_PROMISC) && !(bond->flags & IFF_PROMISC)) |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 4099 | /* |
| 4100 | * FIXME: Need to handle the error when one of the multi-slaves |
| 4101 | * encounters error. |
| 4102 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | bond_set_promiscuity(bond, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4105 | |
| 4106 | if (!(bond_dev->flags & IFF_PROMISC) && (bond->flags & IFF_PROMISC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | bond_set_promiscuity(bond, -1); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4109 | |
| 4110 | /* set allmulti flag to slaves */ |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4111 | if ((bond_dev->flags & IFF_ALLMULTI) && !(bond->flags & IFF_ALLMULTI)) |
Wang Chen | 7e1a1ac | 2008-07-14 20:51:36 -0700 | [diff] [blame] | 4112 | /* |
| 4113 | * FIXME: Need to handle the error when one of the multi-slaves |
| 4114 | * encounters error. |
| 4115 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | bond_set_allmulti(bond, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4118 | |
| 4119 | if (!(bond_dev->flags & IFF_ALLMULTI) && (bond->flags & IFF_ALLMULTI)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | bond_set_allmulti(bond, -1); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | |
Jay Vosburgh | 80ee5ad | 2008-01-29 18:07:44 -0800 | [diff] [blame] | 4123 | read_lock(&bond->lock); |
| 4124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | bond->flags = bond_dev->flags; |
| 4126 | |
| 4127 | /* looking for addresses to add to slaves' mc list */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4128 | netdev_for_each_mc_addr(ha, bond_dev) { |
| 4129 | found = bond_addr_in_mc_list(ha->addr, &bond->mc_list, |
| 4130 | bond_dev->addr_len); |
| 4131 | if (!found) |
| 4132 | bond_mc_add(bond, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | /* looking for addresses to delete from slaves' list */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4136 | netdev_hw_addr_list_for_each(ha, &bond->mc_list) { |
| 4137 | found = bond_addr_in_mc_list(ha->addr, &bond_dev->mc, |
| 4138 | bond_dev->addr_len); |
| 4139 | if (!found) |
| 4140 | bond_mc_del(bond, ha->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | } |
| 4142 | |
| 4143 | /* save master's multicast list */ |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4144 | __hw_addr_flush(&bond->mc_list); |
| 4145 | __hw_addr_add_multiple(&bond->mc_list, &bond_dev->mc, |
| 4146 | bond_dev->addr_len, NETDEV_HW_ADDR_T_MULTICAST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | |
Jay Vosburgh | 80ee5ad | 2008-01-29 18:07:44 -0800 | [diff] [blame] | 4148 | read_unlock(&bond->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4151 | static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms) |
| 4152 | { |
| 4153 | struct bonding *bond = netdev_priv(dev); |
| 4154 | struct slave *slave = bond->first_slave; |
| 4155 | |
| 4156 | if (slave) { |
| 4157 | const struct net_device_ops *slave_ops |
| 4158 | = slave->dev->netdev_ops; |
| 4159 | if (slave_ops->ndo_neigh_setup) |
Patrick McHardy | 72e2240 | 2009-03-05 01:57:44 -0800 | [diff] [blame] | 4160 | return slave_ops->ndo_neigh_setup(slave->dev, parms); |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4161 | } |
| 4162 | return 0; |
| 4163 | } |
| 4164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | /* |
| 4166 | * Change the MTU of all of a master's slaves to match the master |
| 4167 | */ |
| 4168 | static int bond_change_mtu(struct net_device *bond_dev, int new_mtu) |
| 4169 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4170 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | struct slave *slave, *stop_at; |
| 4172 | int res = 0; |
| 4173 | int i; |
| 4174 | |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 4175 | pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4176 | (bond_dev ? bond_dev->name : "None"), new_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | |
| 4178 | /* Can't hold bond->lock with bh disabled here since |
| 4179 | * some base drivers panic. On the other hand we can't |
| 4180 | * hold bond->lock without bh disabled because we'll |
| 4181 | * deadlock. The only solution is to rely on the fact |
| 4182 | * that we're under rtnl_lock here, and the slaves |
| 4183 | * list won't change. This doesn't solve the problem |
| 4184 | * of setting the slave's MTU while it is |
| 4185 | * transmitting, but the assumption is that the base |
| 4186 | * driver can handle that. |
| 4187 | * |
| 4188 | * TODO: figure out a way to safely iterate the slaves |
| 4189 | * list, but without holding a lock around the actual |
| 4190 | * call to the base driver. |
| 4191 | */ |
| 4192 | |
| 4193 | bond_for_each_slave(bond, slave, i) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4194 | pr_debug("s %p s->p %p c_m %p\n", |
| 4195 | slave, |
| 4196 | slave->prev, |
| 4197 | slave->dev->netdev_ops->ndo_change_mtu); |
Mitch Williams | e944ef7 | 2005-11-09 10:36:50 -0800 | [diff] [blame] | 4198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4199 | res = dev_set_mtu(slave->dev, new_mtu); |
| 4200 | |
| 4201 | if (res) { |
| 4202 | /* If we failed to set the slave's mtu to the new value |
| 4203 | * we must abort the operation even in ACTIVE_BACKUP |
| 4204 | * mode, because if we allow the backup slaves to have |
| 4205 | * different mtu values than the active slave we'll |
| 4206 | * need to change their mtu when doing a failover. That |
| 4207 | * means changing their mtu from timer context, which |
| 4208 | * is probably not a good idea. |
| 4209 | */ |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 4210 | pr_debug("err %d %s\n", res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | goto unwind; |
| 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | bond_dev->mtu = new_mtu; |
| 4216 | |
| 4217 | return 0; |
| 4218 | |
| 4219 | unwind: |
| 4220 | /* unwind from head to the slave that failed */ |
| 4221 | stop_at = slave; |
| 4222 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { |
| 4223 | int tmp_res; |
| 4224 | |
| 4225 | tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu); |
| 4226 | if (tmp_res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4227 | pr_debug("unwind err %d dev %s\n", |
| 4228 | tmp_res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | return res; |
| 4233 | } |
| 4234 | |
| 4235 | /* |
| 4236 | * Change HW address |
| 4237 | * |
| 4238 | * Note that many devices must be down to change the HW address, and |
| 4239 | * downing the master releases all slaves. We can make bonds full of |
| 4240 | * bonding devices to test this, however. |
| 4241 | */ |
| 4242 | static int bond_set_mac_address(struct net_device *bond_dev, void *addr) |
| 4243 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4244 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | struct sockaddr *sa = addr, tmp_sa; |
| 4246 | struct slave *slave, *stop_at; |
| 4247 | int res = 0; |
| 4248 | int i; |
| 4249 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4250 | if (bond->params.mode == BOND_MODE_ALB) |
| 4251 | return bond_alb_set_mac_address(bond_dev, addr); |
| 4252 | |
| 4253 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4254 | pr_debug("bond=%p, name=%s\n", |
| 4255 | bond, bond_dev ? bond_dev->name : "None"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4256 | |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 4257 | /* |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 4258 | * If fail_over_mac is set to active, do nothing and return |
| 4259 | * success. Returning an error causes ifenslave to fail. |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 4260 | */ |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 4261 | if (bond->params.fail_over_mac == BOND_FOM_ACTIVE) |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 4262 | return 0; |
Moni Shoua | 2ab8285 | 2007-10-09 19:43:39 -0700 | [diff] [blame] | 4263 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4264 | if (!is_valid_ether_addr(sa->sa_data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | return -EADDRNOTAVAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4266 | |
| 4267 | /* Can't hold bond->lock with bh disabled here since |
| 4268 | * some base drivers panic. On the other hand we can't |
| 4269 | * hold bond->lock without bh disabled because we'll |
| 4270 | * deadlock. The only solution is to rely on the fact |
| 4271 | * that we're under rtnl_lock here, and the slaves |
| 4272 | * list won't change. This doesn't solve the problem |
| 4273 | * of setting the slave's hw address while it is |
| 4274 | * transmitting, but the assumption is that the base |
| 4275 | * driver can handle that. |
| 4276 | * |
| 4277 | * TODO: figure out a way to safely iterate the slaves |
| 4278 | * list, but without holding a lock around the actual |
| 4279 | * call to the base driver. |
| 4280 | */ |
| 4281 | |
| 4282 | bond_for_each_slave(bond, slave, i) { |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4283 | const struct net_device_ops *slave_ops = slave->dev->netdev_ops; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 4284 | pr_debug("slave %p %s\n", slave, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4285 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4286 | if (slave_ops->ndo_set_mac_address == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | res = -EOPNOTSUPP; |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 4288 | pr_debug("EOPNOTSUPP %s\n", slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4289 | goto unwind; |
| 4290 | } |
| 4291 | |
| 4292 | res = dev_set_mac_address(slave->dev, addr); |
| 4293 | if (res) { |
| 4294 | /* TODO: consider downing the slave |
| 4295 | * and retry ? |
| 4296 | * User should expect communications |
| 4297 | * breakage anyway until ARP finish |
| 4298 | * updating, so... |
| 4299 | */ |
Holger Eitzenberger | 5a03cdb | 2008-12-09 23:09:22 -0800 | [diff] [blame] | 4300 | pr_debug("err %d %s\n", res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4301 | goto unwind; |
| 4302 | } |
| 4303 | } |
| 4304 | |
| 4305 | /* success */ |
| 4306 | memcpy(bond_dev->dev_addr, sa->sa_data, bond_dev->addr_len); |
| 4307 | return 0; |
| 4308 | |
| 4309 | unwind: |
| 4310 | memcpy(tmp_sa.sa_data, bond_dev->dev_addr, bond_dev->addr_len); |
| 4311 | tmp_sa.sa_family = bond_dev->type; |
| 4312 | |
| 4313 | /* unwind from head to the slave that failed */ |
| 4314 | stop_at = slave; |
| 4315 | bond_for_each_slave_from_to(bond, slave, i, bond->first_slave, stop_at) { |
| 4316 | int tmp_res; |
| 4317 | |
| 4318 | tmp_res = dev_set_mac_address(slave->dev, &tmp_sa); |
| 4319 | if (tmp_res) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4320 | pr_debug("unwind err %d dev %s\n", |
| 4321 | tmp_res, slave->dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | return res; |
| 4326 | } |
| 4327 | |
| 4328 | static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev) |
| 4329 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4330 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | struct slave *slave, *start_at; |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 4332 | int i, slave_no, res = 1; |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 4333 | struct iphdr *iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | |
| 4335 | read_lock(&bond->lock); |
| 4336 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4337 | if (!BOND_IS_OK(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4338 | goto out; |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 4339 | /* |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 4340 | * Start with the curr_active_slave that joined the bond as the |
| 4341 | * default for sending IGMP traffic. For failover purposes one |
| 4342 | * needs to maintain some consistency for the interface that will |
| 4343 | * send the join/membership reports. The curr_active_slave found |
| 4344 | * will send all of this type of traffic. |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 4345 | */ |
Eric Dumazet | 00ae702 | 2010-03-30 23:08:37 +0000 | [diff] [blame] | 4346 | if ((iph->protocol == IPPROTO_IGMP) && |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 4347 | (skb->protocol == htons(ETH_P_IP))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4348 | |
Andy Gospodarek | a2fd940 | 2010-03-25 14:49:05 +0000 | [diff] [blame] | 4349 | read_lock(&bond->curr_slave_lock); |
| 4350 | slave = bond->curr_active_slave; |
| 4351 | read_unlock(&bond->curr_slave_lock); |
| 4352 | |
| 4353 | if (!slave) |
| 4354 | goto out; |
| 4355 | } else { |
| 4356 | /* |
| 4357 | * Concurrent TX may collide on rr_tx_counter; we accept |
| 4358 | * that as being rare enough not to justify using an |
| 4359 | * atomic op here. |
| 4360 | */ |
| 4361 | slave_no = bond->rr_tx_counter++ % bond->slave_cnt; |
| 4362 | |
| 4363 | bond_for_each_slave(bond, slave, i) { |
| 4364 | slave_no--; |
| 4365 | if (slave_no < 0) |
| 4366 | break; |
| 4367 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | } |
| 4369 | |
Jay Vosburgh | cf5f904 | 2007-10-17 17:37:47 -0700 | [diff] [blame] | 4370 | start_at = slave; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4371 | bond_for_each_slave_from(bond, slave, i, start_at) { |
| 4372 | if (IS_UP(slave->dev) && |
| 4373 | (slave->link == BOND_LINK_UP) && |
| 4374 | (slave->state == BOND_STATE_ACTIVE)) { |
| 4375 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | break; |
| 4377 | } |
| 4378 | } |
| 4379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | out: |
| 4381 | if (res) { |
| 4382 | /* no suitable interface, frame not sent */ |
| 4383 | dev_kfree_skb(skb); |
| 4384 | } |
| 4385 | read_unlock(&bond->lock); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4386 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
John W. Linville | 075897c | 2005-09-28 17:50:53 -0400 | [diff] [blame] | 4389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4390 | /* |
| 4391 | * in active-backup mode, we know that bond->curr_active_slave is always valid if |
| 4392 | * the bond has a usable interface. |
| 4393 | */ |
| 4394 | static int bond_xmit_activebackup(struct sk_buff *skb, struct net_device *bond_dev) |
| 4395 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4396 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4397 | int res = 1; |
| 4398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4399 | read_lock(&bond->lock); |
| 4400 | read_lock(&bond->curr_slave_lock); |
| 4401 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4402 | if (!BOND_IS_OK(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | |
John W. Linville | 075897c | 2005-09-28 17:50:53 -0400 | [diff] [blame] | 4405 | if (!bond->curr_active_slave) |
| 4406 | goto out; |
| 4407 | |
John W. Linville | 075897c | 2005-09-28 17:50:53 -0400 | [diff] [blame] | 4408 | res = bond_dev_queue_xmit(bond, skb, bond->curr_active_slave->dev); |
| 4409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4410 | out: |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4411 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | /* no suitable interface, frame not sent */ |
| 4413 | dev_kfree_skb(skb); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4415 | read_unlock(&bond->curr_slave_lock); |
| 4416 | read_unlock(&bond->lock); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4417 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | /* |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4421 | * In bond_xmit_xor() , we determine the output device by using a pre- |
| 4422 | * determined xmit_hash_policy(), If the selected device is not enabled, |
| 4423 | * find the next active slave. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4424 | */ |
| 4425 | static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev) |
| 4426 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4427 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | struct slave *slave, *start_at; |
| 4429 | int slave_no; |
| 4430 | int i; |
| 4431 | int res = 1; |
| 4432 | |
| 4433 | read_lock(&bond->lock); |
| 4434 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4435 | if (!BOND_IS_OK(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | |
Jasper Spaans | a361c83 | 2009-10-23 04:09:24 +0000 | [diff] [blame] | 4438 | slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | |
| 4440 | bond_for_each_slave(bond, slave, i) { |
| 4441 | slave_no--; |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4442 | if (slave_no < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4443 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4444 | } |
| 4445 | |
| 4446 | start_at = slave; |
| 4447 | |
| 4448 | bond_for_each_slave_from(bond, slave, i, start_at) { |
| 4449 | if (IS_UP(slave->dev) && |
| 4450 | (slave->link == BOND_LINK_UP) && |
| 4451 | (slave->state == BOND_STATE_ACTIVE)) { |
| 4452 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
| 4453 | break; |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | out: |
| 4458 | if (res) { |
| 4459 | /* no suitable interface, frame not sent */ |
| 4460 | dev_kfree_skb(skb); |
| 4461 | } |
| 4462 | read_unlock(&bond->lock); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4463 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | /* |
| 4467 | * in broadcast mode, we send everything to all usable interfaces. |
| 4468 | */ |
| 4469 | static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev) |
| 4470 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4471 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | struct slave *slave, *start_at; |
| 4473 | struct net_device *tx_dev = NULL; |
| 4474 | int i; |
| 4475 | int res = 1; |
| 4476 | |
| 4477 | read_lock(&bond->lock); |
| 4478 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4479 | if (!BOND_IS_OK(bond)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4480 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4481 | |
| 4482 | read_lock(&bond->curr_slave_lock); |
| 4483 | start_at = bond->curr_active_slave; |
| 4484 | read_unlock(&bond->curr_slave_lock); |
| 4485 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4486 | if (!start_at) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4487 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | |
| 4489 | bond_for_each_slave_from(bond, slave, i, start_at) { |
| 4490 | if (IS_UP(slave->dev) && |
| 4491 | (slave->link == BOND_LINK_UP) && |
| 4492 | (slave->state == BOND_STATE_ACTIVE)) { |
| 4493 | if (tx_dev) { |
| 4494 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
| 4495 | if (!skb2) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4496 | pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n", |
Mitch Williams | 4e0952c | 2005-11-09 10:34:57 -0800 | [diff] [blame] | 4497 | bond_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4498 | continue; |
| 4499 | } |
| 4500 | |
| 4501 | res = bond_dev_queue_xmit(bond, skb2, tx_dev); |
| 4502 | if (res) { |
| 4503 | dev_kfree_skb(skb2); |
| 4504 | continue; |
| 4505 | } |
| 4506 | } |
| 4507 | tx_dev = slave->dev; |
| 4508 | } |
| 4509 | } |
| 4510 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4511 | if (tx_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | res = bond_dev_queue_xmit(bond, skb, tx_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | |
| 4514 | out: |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4515 | if (res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | /* no suitable interface, frame not sent */ |
| 4517 | dev_kfree_skb(skb); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4518 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | /* frame sent to all suitable interfaces */ |
| 4520 | read_unlock(&bond->lock); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 4521 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | } |
| 4523 | |
| 4524 | /*------------------------- Device initialization ---------------------------*/ |
| 4525 | |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 4526 | static void bond_set_xmit_hash_policy(struct bonding *bond) |
| 4527 | { |
| 4528 | switch (bond->params.xmit_policy) { |
| 4529 | case BOND_XMIT_POLICY_LAYER23: |
| 4530 | bond->xmit_hash_policy = bond_xmit_hash_policy_l23; |
| 4531 | break; |
| 4532 | case BOND_XMIT_POLICY_LAYER34: |
| 4533 | bond->xmit_hash_policy = bond_xmit_hash_policy_l34; |
| 4534 | break; |
| 4535 | case BOND_XMIT_POLICY_LAYER2: |
| 4536 | default: |
| 4537 | bond->xmit_hash_policy = bond_xmit_hash_policy_l2; |
| 4538 | break; |
| 4539 | } |
| 4540 | } |
| 4541 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4542 | /* |
| 4543 | * Lookup the slave that corresponds to a qid |
| 4544 | */ |
| 4545 | static inline int bond_slave_override(struct bonding *bond, |
| 4546 | struct sk_buff *skb) |
| 4547 | { |
| 4548 | int i, res = 1; |
| 4549 | struct slave *slave = NULL; |
| 4550 | struct slave *check_slave; |
| 4551 | |
| 4552 | read_lock(&bond->lock); |
| 4553 | |
| 4554 | if (!BOND_IS_OK(bond) || !skb->queue_mapping) |
| 4555 | goto out; |
| 4556 | |
| 4557 | /* Find out if any slaves have the same mapping as this skb. */ |
| 4558 | bond_for_each_slave(bond, check_slave, i) { |
| 4559 | if (check_slave->queue_id == skb->queue_mapping) { |
| 4560 | slave = check_slave; |
| 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | /* If the slave isn't UP, use default transmit policy. */ |
| 4566 | if (slave && slave->queue_id && IS_UP(slave->dev) && |
| 4567 | (slave->link == BOND_LINK_UP)) { |
| 4568 | res = bond_dev_queue_xmit(bond, skb, slave->dev); |
| 4569 | } |
| 4570 | |
| 4571 | out: |
| 4572 | read_unlock(&bond->lock); |
| 4573 | return res; |
| 4574 | } |
| 4575 | |
| 4576 | static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 4577 | { |
| 4578 | /* |
| 4579 | * This helper function exists to help dev_pick_tx get the correct |
| 4580 | * destination queue. Using a helper function skips the a call to |
| 4581 | * skb_tx_hash and will put the skbs in the queue we expect on their |
| 4582 | * way down to the bonding driver. |
| 4583 | */ |
| 4584 | return skb->queue_mapping; |
| 4585 | } |
| 4586 | |
Stephen Hemminger | 424efe9 | 2009-08-31 19:50:51 +0000 | [diff] [blame] | 4587 | 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] | 4588 | { |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4589 | struct bonding *bond = netdev_priv(dev); |
| 4590 | |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 4591 | /* |
| 4592 | * If we risk deadlock from transmitting this in the |
| 4593 | * netpoll path, tell netpoll to queue the frame for later tx |
| 4594 | */ |
| 4595 | if (is_netpoll_tx_blocked(dev)) |
| 4596 | return NETDEV_TX_BUSY; |
| 4597 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4598 | if (TX_QUEUE_OVERRIDE(bond->params.mode)) { |
| 4599 | if (!bond_slave_override(bond, skb)) |
| 4600 | return NETDEV_TX_OK; |
| 4601 | } |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4602 | |
| 4603 | switch (bond->params.mode) { |
| 4604 | case BOND_MODE_ROUNDROBIN: |
| 4605 | return bond_xmit_roundrobin(skb, dev); |
| 4606 | case BOND_MODE_ACTIVEBACKUP: |
| 4607 | return bond_xmit_activebackup(skb, dev); |
| 4608 | case BOND_MODE_XOR: |
| 4609 | return bond_xmit_xor(skb, dev); |
| 4610 | case BOND_MODE_BROADCAST: |
| 4611 | return bond_xmit_broadcast(skb, dev); |
| 4612 | case BOND_MODE_8023AD: |
| 4613 | return bond_3ad_xmit_xor(skb, dev); |
| 4614 | case BOND_MODE_ALB: |
| 4615 | case BOND_MODE_TLB: |
| 4616 | return bond_alb_xmit(skb, dev); |
| 4617 | default: |
| 4618 | /* Should never happen, mode already checked */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4619 | pr_err("%s: Error: Unknown bonding mode %d\n", |
| 4620 | dev->name, bond->params.mode); |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4621 | WARN_ON_ONCE(1); |
| 4622 | dev_kfree_skb(skb); |
| 4623 | return NETDEV_TX_OK; |
| 4624 | } |
| 4625 | } |
| 4626 | |
| 4627 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | /* |
| 4629 | * set bond mode specific net device operations |
| 4630 | */ |
Mitch Williams | a77b532 | 2005-11-09 10:35:51 -0800 | [diff] [blame] | 4631 | void bond_set_mode_ops(struct bonding *bond, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4632 | { |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4633 | struct net_device *bond_dev = bond->dev; |
| 4634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | switch (mode) { |
| 4636 | case BOND_MODE_ROUNDROBIN: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4637 | break; |
| 4638 | case BOND_MODE_ACTIVEBACKUP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4639 | break; |
| 4640 | case BOND_MODE_XOR: |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 4641 | bond_set_xmit_hash_policy(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | break; |
| 4643 | case BOND_MODE_BROADCAST: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4644 | break; |
| 4645 | case BOND_MODE_8023AD: |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 4646 | bond_set_master_3ad_flags(bond); |
Jay Vosburgh | 6f6652b | 2007-12-06 23:40:34 -0800 | [diff] [blame] | 4647 | bond_set_xmit_hash_policy(bond); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4648 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4649 | case BOND_MODE_ALB: |
Jay Vosburgh | 8f903c7 | 2006-02-21 16:36:44 -0800 | [diff] [blame] | 4650 | bond_set_master_alb_flags(bond); |
| 4651 | /* FALLTHRU */ |
| 4652 | case BOND_MODE_TLB: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4653 | break; |
| 4654 | default: |
| 4655 | /* Should never happen, mode already checked */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4656 | pr_err("%s: Error: Unknown bonding mode %d\n", |
| 4657 | bond_dev->name, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4658 | break; |
| 4659 | } |
| 4660 | } |
| 4661 | |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 4662 | static void bond_ethtool_get_drvinfo(struct net_device *bond_dev, |
| 4663 | struct ethtool_drvinfo *drvinfo) |
| 4664 | { |
| 4665 | strncpy(drvinfo->driver, DRV_NAME, 32); |
| 4666 | strncpy(drvinfo->version, DRV_VERSION, 32); |
| 4667 | snprintf(drvinfo->fw_version, 32, "%d", BOND_ABI_VERSION); |
| 4668 | } |
| 4669 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 4670 | static const struct ethtool_ops bond_ethtool_ops = { |
Jay Vosburgh | 217df67 | 2005-09-26 16:11:50 -0700 | [diff] [blame] | 4671 | .get_drvinfo = bond_ethtool_get_drvinfo, |
Stephen Hemminger | fa53eba | 2008-09-13 21:17:09 -0400 | [diff] [blame] | 4672 | .get_link = ethtool_op_get_link, |
| 4673 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 4674 | .get_sg = ethtool_op_get_sg, |
| 4675 | .get_tso = ethtool_op_get_tso, |
| 4676 | .get_ufo = ethtool_op_get_ufo, |
| 4677 | .get_flags = ethtool_op_get_flags, |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 4678 | }; |
| 4679 | |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4680 | static const struct net_device_ops bond_netdev_ops = { |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4681 | .ndo_init = bond_init, |
Stephen Hemminger | 9e71626 | 2009-06-12 19:02:47 +0000 | [diff] [blame] | 4682 | .ndo_uninit = bond_uninit, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4683 | .ndo_open = bond_open, |
| 4684 | .ndo_stop = bond_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4685 | .ndo_start_xmit = bond_start_xmit, |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4686 | .ndo_select_queue = bond_select_queue, |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 4687 | .ndo_get_stats64 = bond_get_stats, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4688 | .ndo_do_ioctl = bond_do_ioctl, |
| 4689 | .ndo_set_multicast_list = bond_set_multicast_list, |
| 4690 | .ndo_change_mtu = bond_change_mtu, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4691 | .ndo_set_mac_address = bond_set_mac_address, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4692 | .ndo_neigh_setup = bond_neigh_setup, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4693 | .ndo_vlan_rx_register = bond_vlan_rx_register, |
| 4694 | .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid, |
| 4695 | .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 4696 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Amerigo Wang | 8a8efa2 | 2011-02-17 23:43:32 +0000 | [diff] [blame^] | 4697 | .ndo_netpoll_setup = bond_netpoll_setup, |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 4698 | .ndo_netpoll_cleanup = bond_netpoll_cleanup, |
| 4699 | .ndo_poll_controller = bond_poll_controller, |
| 4700 | #endif |
Jiri Pirko | 9232ecc | 2011-02-13 09:33:01 +0000 | [diff] [blame] | 4701 | .ndo_add_slave = bond_enslave, |
| 4702 | .ndo_del_slave = bond_release, |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4703 | }; |
| 4704 | |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 4705 | static void bond_destructor(struct net_device *bond_dev) |
| 4706 | { |
| 4707 | struct bonding *bond = netdev_priv(bond_dev); |
| 4708 | if (bond->wq) |
| 4709 | destroy_workqueue(bond->wq); |
| 4710 | free_netdev(bond_dev); |
| 4711 | } |
| 4712 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4713 | static void bond_setup(struct net_device *bond_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4714 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4715 | struct bonding *bond = netdev_priv(bond_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4717 | /* initialize rwlocks */ |
| 4718 | rwlock_init(&bond->lock); |
| 4719 | rwlock_init(&bond->curr_slave_lock); |
| 4720 | |
Stephen Hemminger | d2991f7 | 2009-06-12 19:02:44 +0000 | [diff] [blame] | 4721 | bond->params = bonding_defaults; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | |
| 4723 | /* Initialize pointers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4724 | bond->dev = bond_dev; |
| 4725 | INIT_LIST_HEAD(&bond->vlan_list); |
| 4726 | |
| 4727 | /* Initialize the device entry points */ |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4728 | ether_setup(bond_dev); |
Stephen Hemminger | eb7cc59 | 2008-11-19 21:56:05 -0800 | [diff] [blame] | 4729 | bond_dev->netdev_ops = &bond_netdev_ops; |
Arthur Kepner | 8531c5f | 2005-08-23 01:34:53 -0400 | [diff] [blame] | 4730 | bond_dev->ethtool_ops = &bond_ethtool_ops; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4731 | bond_set_mode_ops(bond, bond->params.mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4732 | |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 4733 | bond_dev->destructor = bond_destructor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4734 | |
| 4735 | /* Initialize the device options */ |
| 4736 | bond_dev->tx_queue_len = 0; |
| 4737 | bond_dev->flags |= IFF_MASTER|IFF_MULTICAST; |
Jay Vosburgh | 0b680e7 | 2006-09-22 21:54:10 -0700 | [diff] [blame] | 4738 | bond_dev->priv_flags |= IFF_BONDING; |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 4739 | bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE; |
| 4740 | |
Jay Vosburgh | 6cf3f41 | 2008-11-03 18:16:50 -0800 | [diff] [blame] | 4741 | if (bond->params.arp_interval) |
| 4742 | bond_dev->priv_flags |= IFF_MASTER_ARPMON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4743 | |
| 4744 | /* At first, we block adding VLANs. That's the only way to |
| 4745 | * prevent problems that occur when adding VLANs over an |
| 4746 | * empty bond. The block will be removed once non-challenged |
| 4747 | * slaves are enslaved. |
| 4748 | */ |
| 4749 | bond_dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 4750 | |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 4751 | /* don't acquire bond device's netif_tx_lock when |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4752 | * transmitting */ |
| 4753 | bond_dev->features |= NETIF_F_LLTX; |
| 4754 | |
| 4755 | /* By default, we declare the bond to be fully |
| 4756 | * VLAN hardware accelerated capable. Special |
| 4757 | * care is taken in the various xmit functions |
| 4758 | * when there are slaves that are not hw accel |
| 4759 | * capable |
| 4760 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4761 | bond_dev->features |= (NETIF_F_HW_VLAN_TX | |
| 4762 | NETIF_F_HW_VLAN_RX | |
| 4763 | NETIF_F_HW_VLAN_FILTER); |
| 4764 | |
Eric Dumazet | e6599c2 | 2010-09-17 09:25:07 +0000 | [diff] [blame] | 4765 | /* By default, we enable GRO on bonding devices. |
| 4766 | * Actual support requires lowlevel drivers are GRO ready. |
| 4767 | */ |
| 4768 | bond_dev->features |= NETIF_F_GRO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
Jay Vosburgh | fdaea7a | 2007-12-06 23:40:35 -0800 | [diff] [blame] | 4771 | static void bond_work_cancel_all(struct bonding *bond) |
| 4772 | { |
| 4773 | write_lock_bh(&bond->lock); |
| 4774 | bond->kill_timers = 1; |
| 4775 | write_unlock_bh(&bond->lock); |
| 4776 | |
| 4777 | if (bond->params.miimon && delayed_work_pending(&bond->mii_work)) |
| 4778 | cancel_delayed_work(&bond->mii_work); |
| 4779 | |
| 4780 | if (bond->params.arp_interval && delayed_work_pending(&bond->arp_work)) |
| 4781 | cancel_delayed_work(&bond->arp_work); |
| 4782 | |
| 4783 | if (bond->params.mode == BOND_MODE_ALB && |
| 4784 | delayed_work_pending(&bond->alb_work)) |
| 4785 | cancel_delayed_work(&bond->alb_work); |
| 4786 | |
| 4787 | if (bond->params.mode == BOND_MODE_8023AD && |
| 4788 | delayed_work_pending(&bond->ad_work)) |
| 4789 | cancel_delayed_work(&bond->ad_work); |
Flavio Leitner | 5a37e8c | 2010-10-05 14:23:57 +0000 | [diff] [blame] | 4790 | |
| 4791 | if (delayed_work_pending(&bond->mcast_work)) |
| 4792 | cancel_delayed_work(&bond->mcast_work); |
Jay Vosburgh | fdaea7a | 2007-12-06 23:40:35 -0800 | [diff] [blame] | 4793 | } |
| 4794 | |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 4795 | /* |
| 4796 | * Destroy a bonding device. |
| 4797 | * Must be under rtnl_lock when this function is called. |
| 4798 | */ |
| 4799 | static void bond_uninit(struct net_device *bond_dev) |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4800 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4801 | struct bonding *bond = netdev_priv(bond_dev); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 4802 | struct vlan_entry *vlan, *tmp; |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4803 | |
WANG Cong | f6dc31a | 2010-05-06 00:48:51 -0700 | [diff] [blame] | 4804 | bond_netpoll_cleanup(bond_dev); |
| 4805 | |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 4806 | /* Release the bonded slaves */ |
| 4807 | bond_release_all(bond_dev); |
| 4808 | |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4809 | list_del(&bond->bond_list); |
| 4810 | |
| 4811 | bond_work_cancel_all(bond); |
| 4812 | |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4813 | bond_remove_proc_entry(bond); |
Eric W. Biederman | c67dfb2 | 2009-10-29 14:18:24 +0000 | [diff] [blame] | 4814 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 4815 | bond_debug_unregister(bond); |
| 4816 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 4817 | __hw_addr_flush(&bond->mc_list); |
Jay Vosburgh | f35188f | 2010-07-21 12:14:47 +0000 | [diff] [blame] | 4818 | |
| 4819 | list_for_each_entry_safe(vlan, tmp, &bond->vlan_list, vlan_list) { |
| 4820 | list_del(&vlan->vlan_list); |
| 4821 | kfree(vlan); |
| 4822 | } |
Jay Vosburgh | a434e43 | 2008-10-30 17:41:15 -0700 | [diff] [blame] | 4823 | } |
| 4824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | /*------------------------- Module initialization ---------------------------*/ |
| 4826 | |
| 4827 | /* |
| 4828 | * Convert string input module parms. Accept either the |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4829 | * number of the mode or its string name. A bit complicated because |
| 4830 | * some mode names are substrings of other names, and calls from sysfs |
| 4831 | * may have whitespace in the name (trailing newlines, for example). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4832 | */ |
Holger Eitzenberger | 325dcf7 | 2008-12-09 23:10:17 -0800 | [diff] [blame] | 4833 | 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] | 4834 | { |
Hannes Eder | 54b8732 | 2009-02-14 11:15:49 +0000 | [diff] [blame] | 4835 | int modeint = -1, i, rv; |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4836 | char *p, modestr[BOND_MAX_MODENAME_LEN + 1] = { 0, }; |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4837 | |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4838 | for (p = (char *)buf; *p; p++) |
| 4839 | if (!(isdigit(*p) || isspace(*p))) |
| 4840 | break; |
| 4841 | |
| 4842 | if (*p) |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4843 | rv = sscanf(buf, "%20s", modestr); |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4844 | else |
Hannes Eder | 54b8732 | 2009-02-14 11:15:49 +0000 | [diff] [blame] | 4845 | rv = sscanf(buf, "%d", &modeint); |
Jay Vosburgh | a42e534 | 2008-01-29 18:07:43 -0800 | [diff] [blame] | 4846 | |
| 4847 | if (!rv) |
| 4848 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4849 | |
| 4850 | for (i = 0; tbl[i].modename; i++) { |
Hannes Eder | 54b8732 | 2009-02-14 11:15:49 +0000 | [diff] [blame] | 4851 | if (modeint == tbl[i].mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | return tbl[i].mode; |
Jay Vosburgh | ece95f7 | 2008-01-17 16:25:01 -0800 | [diff] [blame] | 4853 | if (strcmp(modestr, tbl[i].modename) == 0) |
| 4854 | return tbl[i].mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | return -1; |
| 4858 | } |
| 4859 | |
| 4860 | static int bond_check_params(struct bond_params *params) |
| 4861 | { |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 4862 | int arp_validate_value, fail_over_mac_value, primary_reselect_value; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 4863 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4864 | /* |
| 4865 | * Convert string parameters. |
| 4866 | */ |
| 4867 | if (mode) { |
| 4868 | bond_mode = bond_parse_parm(mode, bond_mode_tbl); |
| 4869 | if (bond_mode == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4870 | pr_err("Error: Invalid bonding mode \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | mode == NULL ? "NULL" : mode); |
| 4872 | return -EINVAL; |
| 4873 | } |
| 4874 | } |
| 4875 | |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4876 | if (xmit_hash_policy) { |
| 4877 | if ((bond_mode != BOND_MODE_XOR) && |
| 4878 | (bond_mode != BOND_MODE_8023AD)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4879 | pr_info("xmit_hash_policy param is irrelevant in mode %s\n", |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4880 | bond_mode_name(bond_mode)); |
| 4881 | } else { |
| 4882 | xmit_hashtype = bond_parse_parm(xmit_hash_policy, |
| 4883 | xmit_hashtype_tbl); |
| 4884 | if (xmit_hashtype == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4885 | pr_err("Error: Invalid xmit_hash_policy \"%s\"\n", |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 4886 | xmit_hash_policy == NULL ? "NULL" : |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 4887 | xmit_hash_policy); |
| 4888 | return -EINVAL; |
| 4889 | } |
| 4890 | } |
| 4891 | } |
| 4892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4893 | if (lacp_rate) { |
| 4894 | if (bond_mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4895 | pr_info("lacp_rate param is irrelevant in mode %s\n", |
| 4896 | bond_mode_name(bond_mode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } else { |
| 4898 | lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl); |
| 4899 | if (lacp_fast == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4900 | pr_err("Error: Invalid lacp rate \"%s\"\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4901 | lacp_rate == NULL ? "NULL" : lacp_rate); |
| 4902 | return -EINVAL; |
| 4903 | } |
| 4904 | } |
| 4905 | } |
| 4906 | |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 4907 | if (ad_select) { |
| 4908 | params->ad_select = bond_parse_parm(ad_select, ad_select_tbl); |
| 4909 | if (params->ad_select == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4910 | pr_err("Error: Invalid ad_select \"%s\"\n", |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 4911 | ad_select == NULL ? "NULL" : ad_select); |
| 4912 | return -EINVAL; |
| 4913 | } |
| 4914 | |
| 4915 | if (bond_mode != BOND_MODE_8023AD) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4916 | pr_warning("ad_select param only affects 802.3ad mode\n"); |
Jay Vosburgh | fd989c8 | 2008-11-04 17:51:16 -0800 | [diff] [blame] | 4917 | } |
| 4918 | } else { |
| 4919 | params->ad_select = BOND_AD_STABLE; |
| 4920 | } |
| 4921 | |
Nicolas de Pesloüan | f584130 | 2009-08-28 13:18:34 +0000 | [diff] [blame] | 4922 | if (max_bonds < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4923 | pr_warning("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n", |
| 4924 | max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4925 | max_bonds = BOND_DEFAULT_MAX_BONDS; |
| 4926 | } |
| 4927 | |
| 4928 | if (miimon < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4929 | pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n", |
| 4930 | miimon, INT_MAX, BOND_LINK_MON_INTERV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4931 | miimon = BOND_LINK_MON_INTERV; |
| 4932 | } |
| 4933 | |
| 4934 | if (updelay < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4935 | pr_warning("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n", |
| 4936 | updelay, INT_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | updelay = 0; |
| 4938 | } |
| 4939 | |
| 4940 | if (downdelay < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4941 | pr_warning("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n", |
| 4942 | downdelay, INT_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | downdelay = 0; |
| 4944 | } |
| 4945 | |
| 4946 | if ((use_carrier != 0) && (use_carrier != 1)) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4947 | pr_warning("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n", |
| 4948 | use_carrier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4949 | use_carrier = 1; |
| 4950 | } |
| 4951 | |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 4952 | if (num_grat_arp < 0 || num_grat_arp > 255) { |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 4953 | pr_warning("Warning: num_grat_arp (%d) not in range 0-255 so it was reset to 1\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4954 | num_grat_arp); |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 4955 | num_grat_arp = 1; |
| 4956 | } |
| 4957 | |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 4958 | if (num_unsol_na < 0 || num_unsol_na > 255) { |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 4959 | pr_warning("Warning: num_unsol_na (%d) not in range 0-255 so it was reset to 1\n", |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4960 | num_unsol_na); |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 4961 | num_unsol_na = 1; |
| 4962 | } |
| 4963 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | /* reset values for 802.3ad */ |
| 4965 | if (bond_mode == BOND_MODE_8023AD) { |
| 4966 | if (!miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4967 | 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] | 4968 | pr_warning("Forcing miimon to 100msec\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4969 | miimon = 100; |
| 4970 | } |
| 4971 | } |
| 4972 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 4973 | if (tx_queues < 1 || tx_queues > 255) { |
| 4974 | pr_warning("Warning: tx_queues (%d) should be between " |
| 4975 | "1 and 255, resetting to %d\n", |
| 4976 | tx_queues, BOND_DEFAULT_TX_QUEUES); |
| 4977 | tx_queues = BOND_DEFAULT_TX_QUEUES; |
| 4978 | } |
| 4979 | |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 4980 | if ((all_slaves_active != 0) && (all_slaves_active != 1)) { |
| 4981 | pr_warning("Warning: all_slaves_active module parameter (%d), " |
| 4982 | "not of valid value (0/1), so it was set to " |
| 4983 | "0\n", all_slaves_active); |
| 4984 | all_slaves_active = 0; |
| 4985 | } |
| 4986 | |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 4987 | if (resend_igmp < 0 || resend_igmp > 255) { |
| 4988 | pr_warning("Warning: resend_igmp (%d) should be between " |
| 4989 | "0 and 255, resetting to %d\n", |
| 4990 | resend_igmp, BOND_DEFAULT_RESEND_IGMP); |
| 4991 | resend_igmp = BOND_DEFAULT_RESEND_IGMP; |
| 4992 | } |
| 4993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | /* reset values for TLB/ALB */ |
| 4995 | if ((bond_mode == BOND_MODE_TLB) || |
| 4996 | (bond_mode == BOND_MODE_ALB)) { |
| 4997 | if (!miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 4998 | 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] | 4999 | pr_warning("Forcing miimon to 100msec\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5000 | miimon = 100; |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | if (bond_mode == BOND_MODE_ALB) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5005 | 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", |
| 5006 | updelay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | if (!miimon) { |
| 5010 | if (updelay || downdelay) { |
| 5011 | /* just warn the user the up/down delay will have |
| 5012 | * no effect since miimon is zero... |
| 5013 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5014 | 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", |
| 5015 | updelay, downdelay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | } |
| 5017 | } else { |
| 5018 | /* don't allow arp monitoring */ |
| 5019 | if (arp_interval) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5020 | pr_warning("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n", |
| 5021 | miimon, arp_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5022 | arp_interval = 0; |
| 5023 | } |
| 5024 | |
| 5025 | if ((updelay % miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5026 | pr_warning("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
| 5027 | updelay, miimon, |
| 5028 | (updelay / miimon) * miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | updelay /= miimon; |
| 5032 | |
| 5033 | if ((downdelay % miimon) != 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5034 | pr_warning("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n", |
| 5035 | downdelay, miimon, |
| 5036 | (downdelay / miimon) * miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | downdelay /= miimon; |
| 5040 | } |
| 5041 | |
| 5042 | if (arp_interval < 0) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5043 | pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n", |
| 5044 | arp_interval, INT_MAX, BOND_LINK_ARP_INTERV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5045 | arp_interval = BOND_LINK_ARP_INTERV; |
| 5046 | } |
| 5047 | |
| 5048 | for (arp_ip_count = 0; |
| 5049 | (arp_ip_count < BOND_MAX_ARP_TARGETS) && arp_ip_target[arp_ip_count]; |
| 5050 | arp_ip_count++) { |
| 5051 | /* not complete check, but should be good enough to |
| 5052 | catch mistakes */ |
| 5053 | if (!isdigit(arp_ip_target[arp_ip_count][0])) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5054 | pr_warning("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n", |
| 5055 | arp_ip_target[arp_ip_count]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5056 | arp_interval = 0; |
| 5057 | } else { |
Al Viro | d3bb52b | 2007-08-22 20:06:58 -0400 | [diff] [blame] | 5058 | __be32 ip = in_aton(arp_ip_target[arp_ip_count]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | arp_target[arp_ip_count] = ip; |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | if (arp_interval && !arp_ip_count) { |
| 5064 | /* don't allow arping if no arp_ip_target given... */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5065 | pr_warning("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n", |
| 5066 | arp_interval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | arp_interval = 0; |
| 5068 | } |
| 5069 | |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 5070 | if (arp_validate) { |
| 5071 | if (bond_mode != BOND_MODE_ACTIVEBACKUP) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5072 | pr_err("arp_validate only supported in active-backup mode\n"); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 5073 | return -EINVAL; |
| 5074 | } |
| 5075 | if (!arp_interval) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5076 | pr_err("arp_validate requires arp_interval\n"); |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 5077 | return -EINVAL; |
| 5078 | } |
| 5079 | |
| 5080 | arp_validate_value = bond_parse_parm(arp_validate, |
| 5081 | arp_validate_tbl); |
| 5082 | if (arp_validate_value == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5083 | pr_err("Error: invalid arp_validate \"%s\"\n", |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 5084 | arp_validate == NULL ? "NULL" : arp_validate); |
| 5085 | return -EINVAL; |
| 5086 | } |
| 5087 | } else |
| 5088 | arp_validate_value = 0; |
| 5089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | if (miimon) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5091 | pr_info("MII link monitoring set to %d ms\n", miimon); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | } else if (arp_interval) { |
| 5093 | int i; |
| 5094 | |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5095 | pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):", |
| 5096 | arp_interval, |
| 5097 | arp_validate_tbl[arp_validate_value].modename, |
| 5098 | arp_ip_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | |
| 5100 | for (i = 0; i < arp_ip_count; i++) |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 5101 | pr_info(" %s", arp_ip_target[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5102 | |
Jiri Pirko | e5e2a8f | 2009-08-13 04:11:52 +0000 | [diff] [blame] | 5103 | pr_info("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 5105 | } else if (max_bonds) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5106 | /* miimon and arp_interval not set, we need one so things |
| 5107 | * work as expected, see bonding.txt for details |
| 5108 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5109 | 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] | 5110 | } |
| 5111 | |
| 5112 | if (primary && !USES_PRIMARY(bond_mode)) { |
| 5113 | /* currently, using a primary only makes sense |
| 5114 | * in active backup, TLB or ALB modes |
| 5115 | */ |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5116 | pr_warning("Warning: %s primary device specified but has no effect in %s mode\n", |
| 5117 | primary, bond_mode_name(bond_mode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5118 | primary = NULL; |
| 5119 | } |
| 5120 | |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 5121 | if (primary && primary_reselect) { |
| 5122 | primary_reselect_value = bond_parse_parm(primary_reselect, |
| 5123 | pri_reselect_tbl); |
| 5124 | if (primary_reselect_value == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5125 | pr_err("Error: Invalid primary_reselect \"%s\"\n", |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 5126 | primary_reselect == |
| 5127 | NULL ? "NULL" : primary_reselect); |
| 5128 | return -EINVAL; |
| 5129 | } |
| 5130 | } else { |
| 5131 | primary_reselect_value = BOND_PRI_RESELECT_ALWAYS; |
| 5132 | } |
| 5133 | |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 5134 | if (fail_over_mac) { |
| 5135 | fail_over_mac_value = bond_parse_parm(fail_over_mac, |
| 5136 | fail_over_mac_tbl); |
| 5137 | if (fail_over_mac_value == -1) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5138 | pr_err("Error: invalid fail_over_mac \"%s\"\n", |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 5139 | arp_validate == NULL ? "NULL" : arp_validate); |
| 5140 | return -EINVAL; |
| 5141 | } |
| 5142 | |
| 5143 | if (bond_mode != BOND_MODE_ACTIVEBACKUP) |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5144 | pr_warning("Warning: fail_over_mac only affects active-backup mode.\n"); |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 5145 | } else { |
| 5146 | fail_over_mac_value = BOND_FOM_NONE; |
| 5147 | } |
Jay Vosburgh | dd957c5 | 2007-10-09 19:57:24 -0700 | [diff] [blame] | 5148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | /* fill params struct with the proper values */ |
| 5150 | params->mode = bond_mode; |
Jay Vosburgh | 169a3e6 | 2005-06-26 17:54:11 -0400 | [diff] [blame] | 5151 | params->xmit_policy = xmit_hashtype; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | params->miimon = miimon; |
Moni Shoua | 7893b24 | 2008-05-17 21:10:12 -0700 | [diff] [blame] | 5153 | params->num_grat_arp = num_grat_arp; |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 5154 | params->num_unsol_na = num_unsol_na; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | params->arp_interval = arp_interval; |
Jay Vosburgh | f5b2b96 | 2006-09-22 21:54:53 -0700 | [diff] [blame] | 5156 | params->arp_validate = arp_validate_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5157 | params->updelay = updelay; |
| 5158 | params->downdelay = downdelay; |
| 5159 | params->use_carrier = use_carrier; |
| 5160 | params->lacp_fast = lacp_fast; |
| 5161 | params->primary[0] = 0; |
Jiri Pirko | a549952 | 2009-09-25 03:28:09 +0000 | [diff] [blame] | 5162 | params->primary_reselect = primary_reselect_value; |
Jay Vosburgh | 3915c1e8 | 2008-05-17 21:10:14 -0700 | [diff] [blame] | 5163 | params->fail_over_mac = fail_over_mac_value; |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 5164 | params->tx_queues = tx_queues; |
Andy Gospodarek | ebd8e49 | 2010-06-02 08:39:21 +0000 | [diff] [blame] | 5165 | params->all_slaves_active = all_slaves_active; |
Flavio Leitner | c2952c3 | 2010-10-05 14:23:59 +0000 | [diff] [blame] | 5166 | params->resend_igmp = resend_igmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5167 | |
| 5168 | if (primary) { |
| 5169 | strncpy(params->primary, primary, IFNAMSIZ); |
| 5170 | params->primary[IFNAMSIZ - 1] = 0; |
| 5171 | } |
| 5172 | |
| 5173 | memcpy(params->arp_targets, arp_target, sizeof(arp_target)); |
| 5174 | |
| 5175 | return 0; |
| 5176 | } |
| 5177 | |
Peter Zijlstra | 0daa2303 | 2006-11-08 19:51:01 -0800 | [diff] [blame] | 5178 | static struct lock_class_key bonding_netdev_xmit_lock_key; |
David S. Miller | cf508b1 | 2008-07-22 14:16:42 -0700 | [diff] [blame] | 5179 | static struct lock_class_key bonding_netdev_addr_lock_key; |
Peter Zijlstra | 0daa2303 | 2006-11-08 19:51:01 -0800 | [diff] [blame] | 5180 | |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 5181 | static void bond_set_lockdep_class_one(struct net_device *dev, |
| 5182 | struct netdev_queue *txq, |
| 5183 | void *_unused) |
David S. Miller | c773e84 | 2008-07-08 23:13:53 -0700 | [diff] [blame] | 5184 | { |
| 5185 | lockdep_set_class(&txq->_xmit_lock, |
| 5186 | &bonding_netdev_xmit_lock_key); |
| 5187 | } |
| 5188 | |
| 5189 | static void bond_set_lockdep_class(struct net_device *dev) |
| 5190 | { |
David S. Miller | cf508b1 | 2008-07-22 14:16:42 -0700 | [diff] [blame] | 5191 | lockdep_set_class(&dev->addr_list_lock, |
| 5192 | &bonding_netdev_addr_lock_key); |
David S. Miller | e8a0464 | 2008-07-17 00:34:19 -0700 | [diff] [blame] | 5193 | 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] | 5194 | } |
| 5195 | |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 5196 | /* |
| 5197 | * Called from registration process |
| 5198 | */ |
| 5199 | static int bond_init(struct net_device *bond_dev) |
| 5200 | { |
| 5201 | struct bonding *bond = netdev_priv(bond_dev); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5202 | struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 5203 | |
| 5204 | pr_debug("Begin bond_init for %s\n", bond_dev->name); |
| 5205 | |
| 5206 | bond->wq = create_singlethread_workqueue(bond_dev->name); |
| 5207 | if (!bond->wq) |
| 5208 | return -ENOMEM; |
| 5209 | |
| 5210 | bond_set_lockdep_class(bond_dev); |
| 5211 | |
| 5212 | netif_carrier_off(bond_dev); |
| 5213 | |
| 5214 | bond_create_proc_entry(bond); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5215 | list_add_tail(&bond->bond_list, &bn->dev_list); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 5216 | |
Eric W. Biederman | 6151b3d | 2009-10-29 14:18:22 +0000 | [diff] [blame] | 5217 | bond_prepare_sysfs_group(bond); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5218 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 5219 | bond_debug_register(bond); |
| 5220 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5221 | __hw_addr_init(&bond->mc_list); |
Stephen Hemminger | 181470f | 2009-06-12 19:02:52 +0000 | [diff] [blame] | 5222 | return 0; |
| 5223 | } |
| 5224 | |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5225 | static int bond_validate(struct nlattr *tb[], struct nlattr *data[]) |
| 5226 | { |
| 5227 | if (tb[IFLA_ADDRESS]) { |
| 5228 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) |
| 5229 | return -EINVAL; |
| 5230 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) |
| 5231 | return -EADDRNOTAVAIL; |
| 5232 | } |
| 5233 | return 0; |
| 5234 | } |
| 5235 | |
| 5236 | static struct rtnl_link_ops bond_link_ops __read_mostly = { |
| 5237 | .kind = "bond", |
Eric W. Biederman | 6639104 | 2009-10-29 23:58:54 +0000 | [diff] [blame] | 5238 | .priv_size = sizeof(struct bonding), |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5239 | .setup = bond_setup, |
| 5240 | .validate = bond_validate, |
| 5241 | }; |
| 5242 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5243 | /* Create a new bond based on the specified name and bonding parameters. |
Jay Vosburgh | e4b91c4 | 2007-01-19 18:15:31 -0800 | [diff] [blame] | 5244 | * If name is NULL, obtain a suitable "bond%d" name for us. |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5245 | * Caller must NOT hold rtnl_lock; we need to release it here before we |
| 5246 | * set up our sysfs entries. |
| 5247 | */ |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5248 | int bond_create(struct net *net, const char *name) |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5249 | { |
| 5250 | struct net_device *bond_dev; |
| 5251 | int res; |
| 5252 | |
| 5253 | rtnl_lock(); |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 5254 | |
Andy Gospodarek | bb1d912 | 2010-06-02 08:40:18 +0000 | [diff] [blame] | 5255 | bond_dev = alloc_netdev_mq(sizeof(struct bonding), name ? name : "", |
| 5256 | bond_setup, tx_queues); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5257 | if (!bond_dev) { |
Joe Perches | a4aee5c | 2009-12-13 20:06:07 -0800 | [diff] [blame] | 5258 | pr_err("%s: eek! can't alloc netdev!\n", name); |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 5259 | rtnl_unlock(); |
| 5260 | return -ENOMEM; |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5263 | dev_net_set(bond_dev, net); |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5264 | bond_dev->rtnl_link_ops = &bond_link_ops; |
| 5265 | |
Jay Vosburgh | e4b91c4 | 2007-01-19 18:15:31 -0800 | [diff] [blame] | 5266 | if (!name) { |
| 5267 | res = dev_alloc_name(bond_dev, "bond%d"); |
| 5268 | if (res < 0) |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 5269 | goto out; |
Neil Horman | 27e6f06 | 2010-10-05 03:39:21 +0000 | [diff] [blame] | 5270 | } else { |
| 5271 | /* |
| 5272 | * If we're given a name to register |
| 5273 | * we need to ensure that its not already |
| 5274 | * registered |
| 5275 | */ |
| 5276 | res = -EEXIST; |
| 5277 | if (__dev_get_by_name(net, name) != NULL) |
| 5278 | goto out; |
Jay Vosburgh | e4b91c4 | 2007-01-19 18:15:31 -0800 | [diff] [blame] | 5279 | } |
| 5280 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5281 | res = register_netdevice(bond_dev); |
Peter Zijlstra | 0daa2303 | 2006-11-08 19:51:01 -0800 | [diff] [blame] | 5282 | |
Eric W. Biederman | 30c15ba | 2009-10-29 14:18:23 +0000 | [diff] [blame] | 5283 | out: |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5284 | rtnl_unlock(); |
Amerigo Wang | 9e2e61f | 2010-03-31 21:30:52 +0000 | [diff] [blame] | 5285 | if (res < 0) |
| 5286 | bond_destructor(bond_dev); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5287 | return res; |
| 5288 | } |
| 5289 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 5290 | static int __net_init bond_net_init(struct net *net) |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5291 | { |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5292 | struct bond_net *bn = net_generic(net, bond_net_id); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5293 | |
| 5294 | bn->net = net; |
| 5295 | INIT_LIST_HEAD(&bn->dev_list); |
| 5296 | |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5297 | bond_create_proc_dir(bn); |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5298 | |
| 5299 | return 0; |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5300 | } |
| 5301 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 5302 | static void __net_exit bond_net_exit(struct net *net) |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5303 | { |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5304 | struct bond_net *bn = net_generic(net, bond_net_id); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5305 | |
| 5306 | bond_destroy_proc_dir(bn); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | static struct pernet_operations bond_net_ops = { |
| 5310 | .init = bond_net_init, |
| 5311 | .exit = bond_net_exit, |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5312 | .id = &bond_net_id, |
| 5313 | .size = sizeof(struct bond_net), |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5314 | }; |
| 5315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5316 | static int __init bonding_init(void) |
| 5317 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5318 | int i; |
| 5319 | int res; |
| 5320 | |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 5321 | pr_info("%s", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5323 | res = bond_check_params(&bonding_defaults); |
Stephen Hemminger | 3d632c3 | 2009-06-12 19:02:48 +0000 | [diff] [blame] | 5324 | if (res) |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5325 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5326 | |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5327 | res = register_pernet_subsys(&bond_net_ops); |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5328 | if (res) |
| 5329 | goto out; |
Jay Vosburgh | 027ea04 | 2008-01-17 16:25:02 -0800 | [diff] [blame] | 5330 | |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5331 | res = rtnl_link_register(&bond_link_ops); |
| 5332 | if (res) |
Eric W. Biederman | 6639104 | 2009-10-29 23:58:54 +0000 | [diff] [blame] | 5333 | goto err_link; |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5334 | |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 5335 | bond_create_debugfs(); |
| 5336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5337 | for (i = 0; i < max_bonds; i++) { |
Eric W. Biederman | ec87fd3 | 2009-10-29 14:18:26 +0000 | [diff] [blame] | 5338 | res = bond_create(&init_net, NULL); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5339 | if (res) |
| 5340 | goto err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | } |
| 5342 | |
Mitch Williams | b76cdba | 2005-11-09 10:36:41 -0800 | [diff] [blame] | 5343 | res = bond_create_sysfs(); |
| 5344 | if (res) |
| 5345 | goto err; |
| 5346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | register_netdevice_notifier(&bond_netdev_notifier); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 5348 | register_inetaddr_notifier(&bond_inetaddr_notifier); |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 5349 | bond_register_ipv6_notifier(); |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5350 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5351 | return res; |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5352 | err: |
| 5353 | rtnl_link_unregister(&bond_link_ops); |
Eric W. Biederman | 6639104 | 2009-10-29 23:58:54 +0000 | [diff] [blame] | 5354 | err_link: |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5355 | unregister_pernet_subsys(&bond_net_ops); |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5356 | goto out; |
Mitch Williams | dfe6039 | 2005-11-09 10:36:04 -0800 | [diff] [blame] | 5357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | static void __exit bonding_exit(void) |
| 5361 | { |
| 5362 | unregister_netdevice_notifier(&bond_netdev_notifier); |
Jay Vosburgh | c3ade5c | 2005-06-26 17:52:20 -0400 | [diff] [blame] | 5363 | unregister_inetaddr_notifier(&bond_inetaddr_notifier); |
Brian Haley | 305d552 | 2008-11-04 17:51:14 -0800 | [diff] [blame] | 5364 | bond_unregister_ipv6_notifier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5365 | |
Pavel Emelyanov | ae68c39 | 2008-05-02 17:49:39 -0700 | [diff] [blame] | 5366 | bond_destroy_sysfs(); |
Taku Izumi | f073c7c | 2010-12-09 15:17:13 +0000 | [diff] [blame] | 5367 | bond_destroy_debugfs(); |
Pavel Emelyanov | ae68c39 | 2008-05-02 17:49:39 -0700 | [diff] [blame] | 5368 | |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5369 | rtnl_link_unregister(&bond_link_ops); |
Eric W. Biederman | 1544974 | 2009-11-29 15:46:04 +0000 | [diff] [blame] | 5370 | unregister_pernet_subsys(&bond_net_ops); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 5371 | |
| 5372 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Neil Horman | fb4fa76 | 2010-12-06 09:05:50 +0000 | [diff] [blame] | 5373 | /* |
| 5374 | * Make sure we don't have an imbalance on our netpoll blocking |
| 5375 | */ |
| 5376 | WARN_ON(atomic_read(&netpoll_block_tx)); |
Neil Horman | e843fa5 | 2010-10-13 16:01:50 +0000 | [diff] [blame] | 5377 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | module_init(bonding_init); |
| 5381 | module_exit(bonding_exit); |
| 5382 | MODULE_LICENSE("GPL"); |
| 5383 | MODULE_VERSION(DRV_VERSION); |
| 5384 | MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION); |
| 5385 | MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others"); |
Eric W. Biederman | 88ead97 | 2009-10-29 14:18:25 +0000 | [diff] [blame] | 5386 | MODULE_ALIAS_RTNL_LINK("bond"); |