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