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