aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding/bond_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/bonding/bond_main.c')
-rw-r--r--drivers/net/bonding/bond_main.c978
1 files changed, 453 insertions, 525 deletions
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 40fb5eefc72e..0075514bf32f 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -31,6 +31,8 @@
31 * 31 *
32 */ 32 */
33 33
34#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35
34#include <linux/kernel.h> 36#include <linux/kernel.h>
35#include <linux/module.h> 37#include <linux/module.h>
36#include <linux/types.h> 38#include <linux/types.h>
@@ -75,6 +77,7 @@
75#include <linux/jiffies.h> 77#include <linux/jiffies.h>
76#include <net/route.h> 78#include <net/route.h>
77#include <net/net_namespace.h> 79#include <net/net_namespace.h>
80#include <net/netns/generic.h>
78#include "bonding.h" 81#include "bonding.h"
79#include "bond_3ad.h" 82#include "bond_3ad.h"
80#include "bond_alb.h" 83#include "bond_alb.h"
@@ -94,6 +97,7 @@ static int downdelay;
94static int use_carrier = 1; 97static int use_carrier = 1;
95static char *mode; 98static char *mode;
96static char *primary; 99static char *primary;
100static char *primary_reselect;
97static char *lacp_rate; 101static char *lacp_rate;
98static char *ad_select; 102static char *ad_select;
99static char *xmit_hash_policy; 103static char *xmit_hash_policy;
@@ -126,6 +130,14 @@ MODULE_PARM_DESC(mode, "Mode of operation : 0 for balance-rr, "
126 "6 for balance-alb"); 130 "6 for balance-alb");
127module_param(primary, charp, 0); 131module_param(primary, charp, 0);
128MODULE_PARM_DESC(primary, "Primary network device to use"); 132MODULE_PARM_DESC(primary, "Primary network device to use");
133module_param(primary_reselect, charp, 0);
134MODULE_PARM_DESC(primary_reselect, "Reselect primary slave "
135 "once it comes up; "
136 "0 for always (default), "
137 "1 for only if speed of primary is "
138 "better, "
139 "2 for only on active slave "
140 "failure");
129module_param(lacp_rate, charp, 0); 141module_param(lacp_rate, charp, 0);
130MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner " 142MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner "
131 "(slow/fast)"); 143 "(slow/fast)");
@@ -148,11 +160,7 @@ MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to the
148static const char * const version = 160static const char * const version =
149 DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"; 161 DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n";
150 162
151LIST_HEAD(bond_dev_list); 163int bond_net_id __read_mostly;
152
153#ifdef CONFIG_PROC_FS
154static struct proc_dir_entry *bond_proc_dir;
155#endif
156 164
157static __be32 arp_target[BOND_MAX_ARP_TARGETS]; 165static __be32 arp_target[BOND_MAX_ARP_TARGETS];
158static int arp_ip_count; 166static int arp_ip_count;
@@ -200,6 +208,13 @@ const struct bond_parm_tbl fail_over_mac_tbl[] = {
200{ NULL, -1}, 208{ NULL, -1},
201}; 209};
202 210
211const struct bond_parm_tbl pri_reselect_tbl[] = {
212{ "always", BOND_PRI_RESELECT_ALWAYS},
213{ "better", BOND_PRI_RESELECT_BETTER},
214{ "failure", BOND_PRI_RESELECT_FAILURE},
215{ NULL, -1},
216};
217
203struct bond_parm_tbl ad_select_tbl[] = { 218struct bond_parm_tbl ad_select_tbl[] = {
204{ "stable", BOND_AD_STABLE}, 219{ "stable", BOND_AD_STABLE},
205{ "bandwidth", BOND_AD_BANDWIDTH}, 220{ "bandwidth", BOND_AD_BANDWIDTH},
@@ -211,7 +226,7 @@ struct bond_parm_tbl ad_select_tbl[] = {
211 226
212static void bond_send_gratuitous_arp(struct bonding *bond); 227static void bond_send_gratuitous_arp(struct bonding *bond);
213static int bond_init(struct net_device *bond_dev); 228static int bond_init(struct net_device *bond_dev);
214static void bond_deinit(struct net_device *bond_dev); 229static void bond_uninit(struct net_device *bond_dev);
215 230
216/*---------------------------- General routines -----------------------------*/ 231/*---------------------------- General routines -----------------------------*/
217 232
@@ -247,7 +262,7 @@ static int bond_add_vlan(struct bonding *bond, unsigned short vlan_id)
247 struct vlan_entry *vlan; 262 struct vlan_entry *vlan;
248 263
249 pr_debug("bond: %s, vlan id %d\n", 264 pr_debug("bond: %s, vlan id %d\n",
250 (bond ? bond->dev->name : "None"), vlan_id); 265 (bond ? bond->dev->name : "None"), vlan_id);
251 266
252 vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL); 267 vlan = kzalloc(sizeof(struct vlan_entry), GFP_KERNEL);
253 if (!vlan) 268 if (!vlan)
@@ -290,8 +305,8 @@ static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
290 if (bond_is_lb(bond)) 305 if (bond_is_lb(bond))
291 bond_alb_clear_vlan(bond, vlan_id); 306 bond_alb_clear_vlan(bond, vlan_id);
292 307
293 pr_debug("removed VLAN ID %d from bond %s\n", vlan_id, 308 pr_debug("removed VLAN ID %d from bond %s\n",
294 bond->dev->name); 309 vlan_id, bond->dev->name);
295 310
296 kfree(vlan); 311 kfree(vlan);
297 312
@@ -310,8 +325,8 @@ static int bond_del_vlan(struct bonding *bond, unsigned short vlan_id)
310 } 325 }
311 } 326 }
312 327
313 pr_debug("couldn't find VLAN ID %d in bond %s\n", vlan_id, 328 pr_debug("couldn't find VLAN ID %d in bond %s\n",
314 bond->dev->name); 329 vlan_id, bond->dev->name);
315 330
316out: 331out:
317 write_unlock_bh(&bond->lock); 332 write_unlock_bh(&bond->lock);
@@ -335,7 +350,7 @@ static int bond_has_challenged_slaves(struct bonding *bond)
335 bond_for_each_slave(bond, slave, i) { 350 bond_for_each_slave(bond, slave, i) {
336 if (slave->dev->features & NETIF_F_VLAN_CHALLENGED) { 351 if (slave->dev->features & NETIF_F_VLAN_CHALLENGED) {
337 pr_debug("found VLAN challenged slave - %s\n", 352 pr_debug("found VLAN challenged slave - %s\n",
338 slave->dev->name); 353 slave->dev->name);
339 return 1; 354 return 1;
340 } 355 }
341 } 356 }
@@ -486,8 +501,7 @@ static void bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid)
486 501
487 res = bond_add_vlan(bond, vid); 502 res = bond_add_vlan(bond, vid);
488 if (res) { 503 if (res) {
489 pr_err(DRV_NAME 504 pr_err("%s: Error: Failed to add vlan id %d\n",
490 ": %s: Error: Failed to add vlan id %d\n",
491 bond_dev->name, vid); 505 bond_dev->name, vid);
492 } 506 }
493} 507}
@@ -521,8 +535,7 @@ static void bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)
521 535
522 res = bond_del_vlan(bond, vid); 536 res = bond_del_vlan(bond, vid);
523 if (res) { 537 if (res) {
524 pr_err(DRV_NAME 538 pr_err("%s: Error: Failed to remove vlan id %d\n",
525 ": %s: Error: Failed to remove vlan id %d\n",
526 bond_dev->name, vid); 539 bond_dev->name, vid);
527 } 540 }
528} 541}
@@ -1040,8 +1053,7 @@ static void bond_do_fail_over_mac(struct bonding *bond,
1040 1053
1041 rv = dev_set_mac_address(new_active->dev, &saddr); 1054 rv = dev_set_mac_address(new_active->dev, &saddr);
1042 if (rv) { 1055 if (rv) {
1043 pr_err(DRV_NAME 1056 pr_err("%s: Error %d setting MAC of slave %s\n",
1044 ": %s: Error %d setting MAC of slave %s\n",
1045 bond->dev->name, -rv, new_active->dev->name); 1057 bond->dev->name, -rv, new_active->dev->name);
1046 goto out; 1058 goto out;
1047 } 1059 }
@@ -1054,22 +1066,39 @@ static void bond_do_fail_over_mac(struct bonding *bond,
1054 1066
1055 rv = dev_set_mac_address(old_active->dev, &saddr); 1067 rv = dev_set_mac_address(old_active->dev, &saddr);
1056 if (rv) 1068 if (rv)
1057 pr_err(DRV_NAME 1069 pr_err("%s: Error %d setting MAC of slave %s\n",
1058 ": %s: Error %d setting MAC of slave %s\n",
1059 bond->dev->name, -rv, new_active->dev->name); 1070 bond->dev->name, -rv, new_active->dev->name);
1060out: 1071out:
1061 read_lock(&bond->lock); 1072 read_lock(&bond->lock);
1062 write_lock_bh(&bond->curr_slave_lock); 1073 write_lock_bh(&bond->curr_slave_lock);
1063 break; 1074 break;
1064 default: 1075 default:
1065 pr_err(DRV_NAME 1076 pr_err("%s: bond_do_fail_over_mac impossible: bad policy %d\n",
1066 ": %s: bond_do_fail_over_mac impossible: bad policy %d\n",
1067 bond->dev->name, bond->params.fail_over_mac); 1077 bond->dev->name, bond->params.fail_over_mac);
1068 break; 1078 break;
1069 } 1079 }
1070 1080
1071} 1081}
1072 1082
1083static bool bond_should_change_active(struct bonding *bond)
1084{
1085 struct slave *prim = bond->primary_slave;
1086 struct slave *curr = bond->curr_active_slave;
1087
1088 if (!prim || !curr || curr->link != BOND_LINK_UP)
1089 return true;
1090 if (bond->force_primary) {
1091 bond->force_primary = false;
1092 return true;
1093 }
1094 if (bond->params.primary_reselect == BOND_PRI_RESELECT_BETTER &&
1095 (prim->speed < curr->speed ||
1096 (prim->speed == curr->speed && prim->duplex <= curr->duplex)))
1097 return false;
1098 if (bond->params.primary_reselect == BOND_PRI_RESELECT_FAILURE)
1099 return false;
1100 return true;
1101}
1073 1102
1074/** 1103/**
1075 * find_best_interface - select the best available slave to be the active one 1104 * find_best_interface - select the best available slave to be the active one
@@ -1084,7 +1113,7 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
1084 int mintime = bond->params.updelay; 1113 int mintime = bond->params.updelay;
1085 int i; 1114 int i;
1086 1115
1087 new_active = old_active = bond->curr_active_slave; 1116 new_active = bond->curr_active_slave;
1088 1117
1089 if (!new_active) { /* there were no active slaves left */ 1118 if (!new_active) { /* there were no active slaves left */
1090 if (bond->slave_cnt > 0) /* found one slave */ 1119 if (bond->slave_cnt > 0) /* found one slave */
@@ -1094,7 +1123,8 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
1094 } 1123 }
1095 1124
1096 if ((bond->primary_slave) && 1125 if ((bond->primary_slave) &&
1097 bond->primary_slave->link == BOND_LINK_UP) { 1126 bond->primary_slave->link == BOND_LINK_UP &&
1127 bond_should_change_active(bond)) {
1098 new_active = bond->primary_slave; 1128 new_active = bond->primary_slave;
1099 } 1129 }
1100 1130
@@ -1145,11 +1175,9 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1145 1175
1146 if (new_active->link == BOND_LINK_BACK) { 1176 if (new_active->link == BOND_LINK_BACK) {
1147 if (USES_PRIMARY(bond->params.mode)) { 1177 if (USES_PRIMARY(bond->params.mode)) {
1148 pr_info(DRV_NAME 1178 pr_info("%s: making interface %s the new active one %d ms earlier.\n",
1149 ": %s: making interface %s the new " 1179 bond->dev->name, new_active->dev->name,
1150 "active one %d ms earlier.\n", 1180 (bond->params.updelay - new_active->delay) * bond->params.miimon);
1151 bond->dev->name, new_active->dev->name,
1152 (bond->params.updelay - new_active->delay) * bond->params.miimon);
1153 } 1181 }
1154 1182
1155 new_active->delay = 0; 1183 new_active->delay = 0;
@@ -1162,10 +1190,8 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1162 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP); 1190 bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
1163 } else { 1191 } else {
1164 if (USES_PRIMARY(bond->params.mode)) { 1192 if (USES_PRIMARY(bond->params.mode)) {
1165 pr_info(DRV_NAME 1193 pr_info("%s: making interface %s the new active one.\n",
1166 ": %s: making interface %s the new " 1194 bond->dev->name, new_active->dev->name);
1167 "active one.\n",
1168 bond->dev->name, new_active->dev->name);
1169 } 1195 }
1170 } 1196 }
1171 } 1197 }
@@ -1209,6 +1235,11 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1209 write_lock_bh(&bond->curr_slave_lock); 1235 write_lock_bh(&bond->curr_slave_lock);
1210 } 1236 }
1211 } 1237 }
1238
1239 /* resend IGMP joins since all were sent on curr_active_slave */
1240 if (bond->params.mode == BOND_MODE_ROUNDROBIN) {
1241 bond_resend_igmp_join_requests(bond);
1242 }
1212} 1243}
1213 1244
1214/** 1245/**
@@ -1235,13 +1266,11 @@ void bond_select_active_slave(struct bonding *bond)
1235 return; 1266 return;
1236 1267
1237 if (netif_carrier_ok(bond->dev)) { 1268 if (netif_carrier_ok(bond->dev)) {
1238 pr_info(DRV_NAME 1269 pr_info("%s: first active interface up!\n",
1239 ": %s: first active interface up!\n", 1270 bond->dev->name);
1240 bond->dev->name);
1241 } else { 1271 } else {
1242 pr_info(DRV_NAME ": %s: " 1272 pr_info("%s: now running without any active interface !\n",
1243 "now running without any active interface !\n", 1273 bond->dev->name);
1244 bond->dev->name);
1245 } 1274 }
1246 } 1275 }
1247} 1276}
@@ -1390,16 +1419,14 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1390 1419
1391 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL && 1420 if (!bond->params.use_carrier && slave_dev->ethtool_ops == NULL &&
1392 slave_ops->ndo_do_ioctl == NULL) { 1421 slave_ops->ndo_do_ioctl == NULL) {
1393 pr_warning(DRV_NAME 1422 pr_warning("%s: Warning: no link monitoring support for %s\n",
1394 ": %s: Warning: no link monitoring support for %s\n", 1423 bond_dev->name, slave_dev->name);
1395 bond_dev->name, slave_dev->name);
1396 } 1424 }
1397 1425
1398 /* bond must be initialized by bond_open() before enslaving */ 1426 /* bond must be initialized by bond_open() before enslaving */
1399 if (!(bond_dev->flags & IFF_UP)) { 1427 if (!(bond_dev->flags & IFF_UP)) {
1400 pr_warning(DRV_NAME 1428 pr_warning("%s: master_dev is not up in bond_enslave\n",
1401 " %s: master_dev is not up in bond_enslave\n", 1429 bond_dev->name);
1402 bond_dev->name);
1403 } 1430 }
1404 1431
1405 /* already enslaved */ 1432 /* already enslaved */
@@ -1413,19 +1440,13 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1413 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) { 1440 if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
1414 pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name); 1441 pr_debug("%s: NETIF_F_VLAN_CHALLENGED\n", slave_dev->name);
1415 if (!list_empty(&bond->vlan_list)) { 1442 if (!list_empty(&bond->vlan_list)) {
1416 pr_err(DRV_NAME 1443 pr_err("%s: Error: cannot enslave VLAN challenged slave %s on VLAN enabled bond %s\n",
1417 ": %s: Error: cannot enslave VLAN " 1444 bond_dev->name, slave_dev->name, bond_dev->name);
1418 "challenged slave %s on VLAN enabled "
1419 "bond %s\n", bond_dev->name, slave_dev->name,
1420 bond_dev->name);
1421 return -EPERM; 1445 return -EPERM;
1422 } else { 1446 } else {
1423 pr_warning(DRV_NAME 1447 pr_warning("%s: Warning: enslaved VLAN challenged slave %s. Adding VLANs will be blocked as long as %s is part of bond %s\n",
1424 ": %s: Warning: enslaved VLAN challenged " 1448 bond_dev->name, slave_dev->name,
1425 "slave %s. Adding VLANs will be blocked as " 1449 slave_dev->name, bond_dev->name);
1426 "long as %s is part of bond %s\n",
1427 bond_dev->name, slave_dev->name, slave_dev->name,
1428 bond_dev->name);
1429 bond_dev->features |= NETIF_F_VLAN_CHALLENGED; 1450 bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
1430 } 1451 }
1431 } else { 1452 } else {
@@ -1445,8 +1466,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1445 * enslaving it; the old ifenslave will not. 1466 * enslaving it; the old ifenslave will not.
1446 */ 1467 */
1447 if ((slave_dev->flags & IFF_UP)) { 1468 if ((slave_dev->flags & IFF_UP)) {
1448 pr_err(DRV_NAME ": %s is up. " 1469 pr_err("%s is up. This may be due to an out of date ifenslave.\n",
1449 "This may be due to an out of date ifenslave.\n",
1450 slave_dev->name); 1470 slave_dev->name);
1451 res = -EPERM; 1471 res = -EPERM;
1452 goto err_undo_flags; 1472 goto err_undo_flags;
@@ -1462,7 +1482,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1462 if (bond->slave_cnt == 0) { 1482 if (bond->slave_cnt == 0) {
1463 if (bond_dev->type != slave_dev->type) { 1483 if (bond_dev->type != slave_dev->type) {
1464 pr_debug("%s: change device type from %d to %d\n", 1484 pr_debug("%s: change device type from %d to %d\n",
1465 bond_dev->name, bond_dev->type, slave_dev->type); 1485 bond_dev->name,
1486 bond_dev->type, slave_dev->type);
1466 1487
1467 netdev_bonding_change(bond_dev, NETDEV_BONDING_OLDTYPE); 1488 netdev_bonding_change(bond_dev, NETDEV_BONDING_OLDTYPE);
1468 1489
@@ -1474,28 +1495,21 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1474 netdev_bonding_change(bond_dev, NETDEV_BONDING_NEWTYPE); 1495 netdev_bonding_change(bond_dev, NETDEV_BONDING_NEWTYPE);
1475 } 1496 }
1476 } else if (bond_dev->type != slave_dev->type) { 1497 } else if (bond_dev->type != slave_dev->type) {
1477 pr_err(DRV_NAME ": %s ether type (%d) is different " 1498 pr_err("%s ether type (%d) is different from other slaves (%d), can not enslave it.\n",
1478 "from other slaves (%d), can not enslave it.\n", 1499 slave_dev->name,
1479 slave_dev->name, 1500 slave_dev->type, bond_dev->type);
1480 slave_dev->type, bond_dev->type); 1501 res = -EINVAL;
1481 res = -EINVAL; 1502 goto err_undo_flags;
1482 goto err_undo_flags;
1483 } 1503 }
1484 1504
1485 if (slave_ops->ndo_set_mac_address == NULL) { 1505 if (slave_ops->ndo_set_mac_address == NULL) {
1486 if (bond->slave_cnt == 0) { 1506 if (bond->slave_cnt == 0) {
1487 pr_warning(DRV_NAME 1507 pr_warning("%s: Warning: The first slave device specified does not support setting the MAC address. Setting fail_over_mac to active.",
1488 ": %s: Warning: The first slave device " 1508 bond_dev->name);
1489 "specified does not support setting the MAC "
1490 "address. Setting fail_over_mac to active.",
1491 bond_dev->name);
1492 bond->params.fail_over_mac = BOND_FOM_ACTIVE; 1509 bond->params.fail_over_mac = BOND_FOM_ACTIVE;
1493 } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) { 1510 } else if (bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
1494 pr_err(DRV_NAME 1511 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",
1495 ": %s: Error: The slave device specified " 1512 bond_dev->name);
1496 "does not support setting the MAC address, "
1497 "but fail_over_mac is not set to active.\n"
1498 , bond_dev->name);
1499 res = -EOPNOTSUPP; 1513 res = -EOPNOTSUPP;
1500 goto err_undo_flags; 1514 goto err_undo_flags;
1501 } 1515 }
@@ -1622,22 +1636,12 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1622 * supported); thus, we don't need to change 1636 * supported); thus, we don't need to change
1623 * the messages for netif_carrier. 1637 * the messages for netif_carrier.
1624 */ 1638 */
1625 pr_warning(DRV_NAME 1639 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",
1626 ": %s: Warning: MII and ETHTOOL support not "
1627 "available for interface %s, and "
1628 "arp_interval/arp_ip_target module parameters "
1629 "not specified, thus bonding will not detect "
1630 "link failures! see bonding.txt for details.\n",
1631 bond_dev->name, slave_dev->name); 1640 bond_dev->name, slave_dev->name);
1632 } else if (link_reporting == -1) { 1641 } else if (link_reporting == -1) {
1633 /* unable get link status using mii/ethtool */ 1642 /* unable get link status using mii/ethtool */
1634 pr_warning(DRV_NAME 1643 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",
1635 ": %s: Warning: can't get link status from " 1644 bond_dev->name, slave_dev->name);
1636 "interface %s; the network driver associated "
1637 "with this interface does not support MII or "
1638 "ETHTOOL link status reporting, thus miimon "
1639 "has no effect on this interface.\n",
1640 bond_dev->name, slave_dev->name);
1641 } 1645 }
1642 } 1646 }
1643 1647
@@ -1645,41 +1649,36 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1645 if (!bond->params.miimon || 1649 if (!bond->params.miimon ||
1646 (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) { 1650 (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS)) {
1647 if (bond->params.updelay) { 1651 if (bond->params.updelay) {
1648 pr_debug("Initial state of slave_dev is " 1652 pr_debug("Initial state of slave_dev is BOND_LINK_BACK\n");
1649 "BOND_LINK_BACK\n");
1650 new_slave->link = BOND_LINK_BACK; 1653 new_slave->link = BOND_LINK_BACK;
1651 new_slave->delay = bond->params.updelay; 1654 new_slave->delay = bond->params.updelay;
1652 } else { 1655 } else {
1653 pr_debug("Initial state of slave_dev is " 1656 pr_debug("Initial state of slave_dev is BOND_LINK_UP\n");
1654 "BOND_LINK_UP\n");
1655 new_slave->link = BOND_LINK_UP; 1657 new_slave->link = BOND_LINK_UP;
1656 } 1658 }
1657 new_slave->jiffies = jiffies; 1659 new_slave->jiffies = jiffies;
1658 } else { 1660 } else {
1659 pr_debug("Initial state of slave_dev is " 1661 pr_debug("Initial state of slave_dev is BOND_LINK_DOWN\n");
1660 "BOND_LINK_DOWN\n");
1661 new_slave->link = BOND_LINK_DOWN; 1662 new_slave->link = BOND_LINK_DOWN;
1662 } 1663 }
1663 1664
1664 if (bond_update_speed_duplex(new_slave) && 1665 if (bond_update_speed_duplex(new_slave) &&
1665 (new_slave->link != BOND_LINK_DOWN)) { 1666 (new_slave->link != BOND_LINK_DOWN)) {
1666 pr_warning(DRV_NAME 1667 pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n",
1667 ": %s: Warning: failed to get speed and duplex from %s, " 1668 bond_dev->name, new_slave->dev->name);
1668 "assumed to be 100Mb/sec and Full.\n",
1669 bond_dev->name, new_slave->dev->name);
1670 1669
1671 if (bond->params.mode == BOND_MODE_8023AD) { 1670 if (bond->params.mode == BOND_MODE_8023AD) {
1672 pr_warning(DRV_NAME 1671 pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n",
1673 ": %s: Warning: Operation of 802.3ad mode requires ETHTOOL " 1672 bond_dev->name);
1674 "support in base driver for proper aggregator "
1675 "selection.\n", bond_dev->name);
1676 } 1673 }
1677 } 1674 }
1678 1675
1679 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) { 1676 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) {
1680 /* if there is a primary slave, remember it */ 1677 /* if there is a primary slave, remember it */
1681 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) 1678 if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
1682 bond->primary_slave = new_slave; 1679 bond->primary_slave = new_slave;
1680 bond->force_primary = true;
1681 }
1683 } 1682 }
1684 1683
1685 write_lock_bh(&bond->curr_slave_lock); 1684 write_lock_bh(&bond->curr_slave_lock);
@@ -1742,11 +1741,10 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1742 if (res) 1741 if (res)
1743 goto err_close; 1742 goto err_close;
1744 1743
1745 pr_info(DRV_NAME 1744 pr_info("%s: enslaving %s as a%s interface with a%s link.\n",
1746 ": %s: enslaving %s as a%s interface with a%s link.\n", 1745 bond_dev->name, slave_dev->name,
1747 bond_dev->name, slave_dev->name, 1746 new_slave->state == BOND_STATE_ACTIVE ? "n active" : " backup",
1748 new_slave->state == BOND_STATE_ACTIVE ? "n active" : " backup", 1747 new_slave->link != BOND_LINK_DOWN ? "n up" : " down");
1749 new_slave->link != BOND_LINK_DOWN ? "n up" : " down");
1750 1748
1751 /* enslave is successful */ 1749 /* enslave is successful */
1752 return 0; 1750 return 0;
@@ -1798,8 +1796,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1798 /* slave is not a slave or master is not master of this slave */ 1796 /* slave is not a slave or master is not master of this slave */
1799 if (!(slave_dev->flags & IFF_SLAVE) || 1797 if (!(slave_dev->flags & IFF_SLAVE) ||
1800 (slave_dev->master != bond_dev)) { 1798 (slave_dev->master != bond_dev)) {
1801 pr_err(DRV_NAME 1799 pr_err("%s: Error: cannot release %s.\n",
1802 ": %s: Error: cannot release %s.\n",
1803 bond_dev->name, slave_dev->name); 1800 bond_dev->name, slave_dev->name);
1804 return -EINVAL; 1801 return -EINVAL;
1805 } 1802 }
@@ -1809,24 +1806,19 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1809 slave = bond_get_slave_by_dev(bond, slave_dev); 1806 slave = bond_get_slave_by_dev(bond, slave_dev);
1810 if (!slave) { 1807 if (!slave) {
1811 /* not a slave of this bond */ 1808 /* not a slave of this bond */
1812 pr_info(DRV_NAME 1809 pr_info("%s: %s not enslaved\n",
1813 ": %s: %s not enslaved\n", 1810 bond_dev->name, slave_dev->name);
1814 bond_dev->name, slave_dev->name);
1815 write_unlock_bh(&bond->lock); 1811 write_unlock_bh(&bond->lock);
1816 return -EINVAL; 1812 return -EINVAL;
1817 } 1813 }
1818 1814
1819 if (!bond->params.fail_over_mac) { 1815 if (!bond->params.fail_over_mac) {
1820 if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) 1816 if (!compare_ether_addr(bond_dev->dev_addr, slave->perm_hwaddr) &&
1821 && bond->slave_cnt > 1) 1817 bond->slave_cnt > 1)
1822 pr_warning(DRV_NAME 1818 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",
1823 ": %s: Warning: the permanent HWaddr of %s - " 1819 bond_dev->name, slave_dev->name,
1824 "%pM - is still in use by %s. " 1820 slave->perm_hwaddr,
1825 "Set the HWaddr of %s to a different address " 1821 bond_dev->name, slave_dev->name);
1826 "to avoid conflicts.\n",
1827 bond_dev->name, slave_dev->name,
1828 slave->perm_hwaddr,
1829 bond_dev->name, slave_dev->name);
1830 } 1822 }
1831 1823
1832 /* Inform AD package of unbinding of slave. */ 1824 /* Inform AD package of unbinding of slave. */
@@ -1837,12 +1829,10 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1837 bond_3ad_unbind_slave(slave); 1829 bond_3ad_unbind_slave(slave);
1838 } 1830 }
1839 1831
1840 pr_info(DRV_NAME 1832 pr_info("%s: releasing %s interface %s\n",
1841 ": %s: releasing %s interface %s\n", 1833 bond_dev->name,
1842 bond_dev->name, 1834 (slave->state == BOND_STATE_ACTIVE) ? "active" : "backup",
1843 (slave->state == BOND_STATE_ACTIVE) 1835 slave_dev->name);
1844 ? "active" : "backup",
1845 slave_dev->name);
1846 1836
1847 oldcurrent = bond->curr_active_slave; 1837 oldcurrent = bond->curr_active_slave;
1848 1838
@@ -1899,21 +1889,15 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1899 if (list_empty(&bond->vlan_list)) { 1889 if (list_empty(&bond->vlan_list)) {
1900 bond_dev->features |= NETIF_F_VLAN_CHALLENGED; 1890 bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
1901 } else { 1891 } else {
1902 pr_warning(DRV_NAME 1892 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
1903 ": %s: Warning: clearing HW address of %s while it " 1893 bond_dev->name, bond_dev->name);
1904 "still has VLANs.\n", 1894 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
1905 bond_dev->name, bond_dev->name); 1895 bond_dev->name);
1906 pr_warning(DRV_NAME
1907 ": %s: When re-adding slaves, make sure the bond's "
1908 "HW address matches its VLANs'.\n",
1909 bond_dev->name);
1910 } 1896 }
1911 } else if ((bond_dev->features & NETIF_F_VLAN_CHALLENGED) && 1897 } else if ((bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
1912 !bond_has_challenged_slaves(bond)) { 1898 !bond_has_challenged_slaves(bond)) {
1913 pr_info(DRV_NAME 1899 pr_info("%s: last VLAN challenged slave %s left bond %s. VLAN blocking is removed\n",
1914 ": %s: last VLAN challenged slave %s " 1900 bond_dev->name, slave_dev->name, bond_dev->name);
1915 "left bond %s. VLAN blocking is removed\n",
1916 bond_dev->name, slave_dev->name, bond_dev->name);
1917 bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED; 1901 bond_dev->features &= ~NETIF_F_VLAN_CHALLENGED;
1918 } 1902 }
1919 1903
@@ -1965,25 +1949,6 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
1965} 1949}
1966 1950
1967/* 1951/*
1968* Destroy a bonding device.
1969* Must be under rtnl_lock when this function is called.
1970*/
1971static void bond_uninit(struct net_device *bond_dev)
1972{
1973 struct bonding *bond = netdev_priv(bond_dev);
1974
1975 bond_deinit(bond_dev);
1976 bond_destroy_sysfs_entry(bond);
1977
1978 if (bond->wq)
1979 destroy_workqueue(bond->wq);
1980
1981 netif_addr_lock_bh(bond_dev);
1982 bond_mc_list_destroy(bond);
1983 netif_addr_unlock_bh(bond_dev);
1984}
1985
1986/*
1987* First release a slave and than destroy the bond if no more slaves are left. 1952* First release a slave and than destroy the bond if no more slaves are left.
1988* Must be under rtnl_lock when this function is called. 1953* Must be under rtnl_lock when this function is called.
1989*/ 1954*/
@@ -1995,8 +1960,8 @@ int bond_release_and_destroy(struct net_device *bond_dev,
1995 1960
1996 ret = bond_release(bond_dev, slave_dev); 1961 ret = bond_release(bond_dev, slave_dev);
1997 if ((ret == 0) && (bond->slave_cnt == 0)) { 1962 if ((ret == 0) && (bond->slave_cnt == 0)) {
1998 pr_info(DRV_NAME ": %s: destroying bond %s.\n", 1963 pr_info("%s: destroying bond %s.\n",
1999 bond_dev->name, bond_dev->name); 1964 bond_dev->name, bond_dev->name);
2000 unregister_netdevice(bond_dev); 1965 unregister_netdevice(bond_dev);
2001 } 1966 }
2002 return ret; 1967 return ret;
@@ -2100,19 +2065,13 @@ static int bond_release_all(struct net_device *bond_dev)
2100 if (list_empty(&bond->vlan_list)) 2065 if (list_empty(&bond->vlan_list))
2101 bond_dev->features |= NETIF_F_VLAN_CHALLENGED; 2066 bond_dev->features |= NETIF_F_VLAN_CHALLENGED;
2102 else { 2067 else {
2103 pr_warning(DRV_NAME 2068 pr_warning("%s: Warning: clearing HW address of %s while it still has VLANs.\n",
2104 ": %s: Warning: clearing HW address of %s while it " 2069 bond_dev->name, bond_dev->name);
2105 "still has VLANs.\n", 2070 pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
2106 bond_dev->name, bond_dev->name); 2071 bond_dev->name);
2107 pr_warning(DRV_NAME
2108 ": %s: When re-adding slaves, make sure the bond's "
2109 "HW address matches its VLANs'.\n",
2110 bond_dev->name);
2111 } 2072 }
2112 2073
2113 pr_info(DRV_NAME 2074 pr_info("%s: released all slaves\n", bond_dev->name);
2114 ": %s: released all slaves\n",
2115 bond_dev->name);
2116 2075
2117out: 2076out:
2118 write_unlock_bh(&bond->lock); 2077 write_unlock_bh(&bond->lock);
@@ -2238,16 +2197,14 @@ static int bond_miimon_inspect(struct bonding *bond)
2238 slave->link = BOND_LINK_FAIL; 2197 slave->link = BOND_LINK_FAIL;
2239 slave->delay = bond->params.downdelay; 2198 slave->delay = bond->params.downdelay;
2240 if (slave->delay) { 2199 if (slave->delay) {
2241 pr_info(DRV_NAME 2200 pr_info("%s: link status down for %sinterface %s, disabling it in %d ms.\n",
2242 ": %s: link status down for %s" 2201 bond->dev->name,
2243 "interface %s, disabling it in %d ms.\n", 2202 (bond->params.mode ==
2244 bond->dev->name, 2203 BOND_MODE_ACTIVEBACKUP) ?
2245 (bond->params.mode == 2204 ((slave->state == BOND_STATE_ACTIVE) ?
2246 BOND_MODE_ACTIVEBACKUP) ? 2205 "active " : "backup ") : "",
2247 ((slave->state == BOND_STATE_ACTIVE) ? 2206 slave->dev->name,
2248 "active " : "backup ") : "", 2207 bond->params.downdelay * bond->params.miimon);
2249 slave->dev->name,
2250 bond->params.downdelay * bond->params.miimon);
2251 } 2208 }
2252 /*FALLTHRU*/ 2209 /*FALLTHRU*/
2253 case BOND_LINK_FAIL: 2210 case BOND_LINK_FAIL:
@@ -2257,13 +2214,11 @@ static int bond_miimon_inspect(struct bonding *bond)
2257 */ 2214 */
2258 slave->link = BOND_LINK_UP; 2215 slave->link = BOND_LINK_UP;
2259 slave->jiffies = jiffies; 2216 slave->jiffies = jiffies;
2260 pr_info(DRV_NAME 2217 pr_info("%s: link status up again after %d ms for interface %s.\n",
2261 ": %s: link status up again after %d " 2218 bond->dev->name,
2262 "ms for interface %s.\n", 2219 (bond->params.downdelay - slave->delay) *
2263 bond->dev->name, 2220 bond->params.miimon,
2264 (bond->params.downdelay - slave->delay) * 2221 slave->dev->name);
2265 bond->params.miimon,
2266 slave->dev->name);
2267 continue; 2222 continue;
2268 } 2223 }
2269 2224
@@ -2284,25 +2239,21 @@ static int bond_miimon_inspect(struct bonding *bond)
2284 slave->delay = bond->params.updelay; 2239 slave->delay = bond->params.updelay;
2285 2240
2286 if (slave->delay) { 2241 if (slave->delay) {
2287 pr_info(DRV_NAME 2242 pr_info("%s: link status up for interface %s, enabling it in %d ms.\n",
2288 ": %s: link status up for " 2243 bond->dev->name, slave->dev->name,
2289 "interface %s, enabling it in %d ms.\n", 2244 ignore_updelay ? 0 :
2290 bond->dev->name, slave->dev->name, 2245 bond->params.updelay *
2291 ignore_updelay ? 0 : 2246 bond->params.miimon);
2292 bond->params.updelay *
2293 bond->params.miimon);
2294 } 2247 }
2295 /*FALLTHRU*/ 2248 /*FALLTHRU*/
2296 case BOND_LINK_BACK: 2249 case BOND_LINK_BACK:
2297 if (!link_state) { 2250 if (!link_state) {
2298 slave->link = BOND_LINK_DOWN; 2251 slave->link = BOND_LINK_DOWN;
2299 pr_info(DRV_NAME 2252 pr_info("%s: link status down again after %d ms for interface %s.\n",
2300 ": %s: link status down again after %d " 2253 bond->dev->name,
2301 "ms for interface %s.\n", 2254 (bond->params.updelay - slave->delay) *
2302 bond->dev->name, 2255 bond->params.miimon,
2303 (bond->params.updelay - slave->delay) * 2256 slave->dev->name);
2304 bond->params.miimon,
2305 slave->dev->name);
2306 2257
2307 continue; 2258 continue;
2308 } 2259 }
@@ -2350,10 +2301,8 @@ static void bond_miimon_commit(struct bonding *bond)
2350 slave->state = BOND_STATE_BACKUP; 2301 slave->state = BOND_STATE_BACKUP;
2351 } 2302 }
2352 2303
2353 pr_info(DRV_NAME 2304 pr_info("%s: link status definitely up for interface %s.\n",
2354 ": %s: link status definitely " 2305 bond->dev->name, slave->dev->name);
2355 "up for interface %s.\n",
2356 bond->dev->name, slave->dev->name);
2357 2306
2358 /* notify ad that the link status has changed */ 2307 /* notify ad that the link status has changed */
2359 if (bond->params.mode == BOND_MODE_8023AD) 2308 if (bond->params.mode == BOND_MODE_8023AD)
@@ -2379,10 +2328,8 @@ static void bond_miimon_commit(struct bonding *bond)
2379 bond->params.mode == BOND_MODE_8023AD) 2328 bond->params.mode == BOND_MODE_8023AD)
2380 bond_set_slave_inactive_flags(slave); 2329 bond_set_slave_inactive_flags(slave);
2381 2330
2382 pr_info(DRV_NAME 2331 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2383 ": %s: link status definitely down for " 2332 bond->dev->name, slave->dev->name);
2384 "interface %s, disabling it\n",
2385 bond->dev->name, slave->dev->name);
2386 2333
2387 if (bond->params.mode == BOND_MODE_8023AD) 2334 if (bond->params.mode == BOND_MODE_8023AD)
2388 bond_3ad_handle_link_change(slave, 2335 bond_3ad_handle_link_change(slave,
@@ -2398,8 +2345,7 @@ static void bond_miimon_commit(struct bonding *bond)
2398 continue; 2345 continue;
2399 2346
2400 default: 2347 default:
2401 pr_err(DRV_NAME 2348 pr_err("%s: invalid new link %d on slave %s\n",
2402 ": %s: invalid new link %d on slave %s\n",
2403 bond->dev->name, slave->new_link, 2349 bond->dev->name, slave->new_link,
2404 slave->dev->name); 2350 slave->dev->name);
2405 slave->new_link = BOND_LINK_NOCHANGE; 2351 slave->new_link = BOND_LINK_NOCHANGE;
@@ -2518,19 +2464,19 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_
2518 struct sk_buff *skb; 2464 struct sk_buff *skb;
2519 2465
2520 pr_debug("arp %d on slave %s: dst %x src %x vid %d\n", arp_op, 2466 pr_debug("arp %d on slave %s: dst %x src %x vid %d\n", arp_op,
2521 slave_dev->name, dest_ip, src_ip, vlan_id); 2467 slave_dev->name, dest_ip, src_ip, vlan_id);
2522 2468
2523 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip, 2469 skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
2524 NULL, slave_dev->dev_addr, NULL); 2470 NULL, slave_dev->dev_addr, NULL);
2525 2471
2526 if (!skb) { 2472 if (!skb) {
2527 pr_err(DRV_NAME ": ARP packet allocation failed\n"); 2473 pr_err("ARP packet allocation failed\n");
2528 return; 2474 return;
2529 } 2475 }
2530 if (vlan_id) { 2476 if (vlan_id) {
2531 skb = vlan_put_tag(skb, vlan_id); 2477 skb = vlan_put_tag(skb, vlan_id);
2532 if (!skb) { 2478 if (!skb) {
2533 pr_err(DRV_NAME ": failed to insert VLAN tag\n"); 2479 pr_err("failed to insert VLAN tag\n");
2534 return; 2480 return;
2535 } 2481 }
2536 } 2482 }
@@ -2567,12 +2513,11 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2567 fl.fl4_dst = targets[i]; 2513 fl.fl4_dst = targets[i];
2568 fl.fl4_tos = RTO_ONLINK; 2514 fl.fl4_tos = RTO_ONLINK;
2569 2515
2570 rv = ip_route_output_key(&init_net, &rt, &fl); 2516 rv = ip_route_output_key(dev_net(bond->dev), &rt, &fl);
2571 if (rv) { 2517 if (rv) {
2572 if (net_ratelimit()) { 2518 if (net_ratelimit()) {
2573 pr_warning(DRV_NAME 2519 pr_warning("%s: no route to arp_ip_target %pI4\n",
2574 ": %s: no route to arp_ip_target %pI4\n", 2520 bond->dev->name, &fl.fl4_dst);
2575 bond->dev->name, &fl.fl4_dst);
2576 } 2521 }
2577 continue; 2522 continue;
2578 } 2523 }
@@ -2607,10 +2552,9 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2607 } 2552 }
2608 2553
2609 if (net_ratelimit()) { 2554 if (net_ratelimit()) {
2610 pr_warning(DRV_NAME 2555 pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
2611 ": %s: no path to arp_ip_target %pI4 via rt.dev %s\n", 2556 bond->dev->name, &fl.fl4_dst,
2612 bond->dev->name, &fl.fl4_dst, 2557 rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
2613 rt->u.dst.dev ? rt->u.dst.dev->name : "NULL");
2614 } 2558 }
2615 ip_rt_put(rt); 2559 ip_rt_put(rt);
2616 } 2560 }
@@ -2628,8 +2572,8 @@ static void bond_send_gratuitous_arp(struct bonding *bond)
2628 struct vlan_entry *vlan; 2572 struct vlan_entry *vlan;
2629 struct net_device *vlan_dev; 2573 struct net_device *vlan_dev;
2630 2574
2631 pr_debug("bond_send_grat_arp: bond %s slave %s\n", bond->dev->name, 2575 pr_debug("bond_send_grat_arp: bond %s slave %s\n",
2632 slave ? slave->dev->name : "NULL"); 2576 bond->dev->name, slave ? slave->dev->name : "NULL");
2633 2577
2634 if (!slave || !bond->send_grat_arp || 2578 if (!slave || !bond->send_grat_arp ||
2635 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state)) 2579 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
@@ -2658,7 +2602,8 @@ static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32
2658 2602
2659 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) { 2603 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && targets[i]; i++) {
2660 pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n", 2604 pr_debug("bva: sip %pI4 tip %pI4 t[%d] %pI4 bhti(tip) %d\n",
2661 &sip, &tip, i, &targets[i], bond_has_this_ip(bond, tip)); 2605 &sip, &tip, i, &targets[i],
2606 bond_has_this_ip(bond, tip));
2662 if (sip == targets[i]) { 2607 if (sip == targets[i]) {
2663 if (bond_has_this_ip(bond, tip)) 2608 if (bond_has_this_ip(bond, tip))
2664 slave->last_arp_rx = jiffies; 2609 slave->last_arp_rx = jiffies;
@@ -2675,8 +2620,16 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
2675 unsigned char *arp_ptr; 2620 unsigned char *arp_ptr;
2676 __be32 sip, tip; 2621 __be32 sip, tip;
2677 2622
2678 if (dev_net(dev) != &init_net) 2623 if (dev->priv_flags & IFF_802_1Q_VLAN) {
2679 goto out; 2624 /*
2625 * When using VLANS and bonding, dev and oriv_dev may be
2626 * incorrect if the physical interface supports VLAN
2627 * acceleration. With this change ARP validation now
2628 * works for hosts only reachable on the VLAN interface.
2629 */
2630 dev = vlan_dev_real_dev(dev);
2631 orig_dev = dev_get_by_index_rcu(dev_net(skb->dev),skb->skb_iif);
2632 }
2680 2633
2681 if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER)) 2634 if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER))
2682 goto out; 2635 goto out;
@@ -2685,8 +2638,8 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
2685 read_lock(&bond->lock); 2638 read_lock(&bond->lock);
2686 2639
2687 pr_debug("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n", 2640 pr_debug("bond_arp_rcv: bond %s skb->dev %s orig_dev %s\n",
2688 bond->dev->name, skb->dev ? skb->dev->name : "NULL", 2641 bond->dev->name, skb->dev ? skb->dev->name : "NULL",
2689 orig_dev ? orig_dev->name : "NULL"); 2642 orig_dev ? orig_dev->name : "NULL");
2690 2643
2691 slave = bond_get_slave_by_dev(bond, orig_dev); 2644 slave = bond_get_slave_by_dev(bond, orig_dev);
2692 if (!slave || !slave_do_arp_validate(bond, slave)) 2645 if (!slave || !slave_do_arp_validate(bond, slave))
@@ -2711,9 +2664,9 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
2711 memcpy(&tip, arp_ptr, 4); 2664 memcpy(&tip, arp_ptr, 4);
2712 2665
2713 pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n", 2666 pr_debug("bond_arp_rcv: %s %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2714 bond->dev->name, slave->dev->name, slave->state, 2667 bond->dev->name, slave->dev->name, slave->state,
2715 bond->params.arp_validate, slave_do_arp_validate(bond, slave), 2668 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2716 &sip, &tip); 2669 &sip, &tip);
2717 2670
2718 /* 2671 /*
2719 * Backup slaves won't see the ARP reply, but do come through 2672 * Backup slaves won't see the ARP reply, but do come through
@@ -2787,17 +2740,14 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
2787 * is closed. 2740 * is closed.
2788 */ 2741 */
2789 if (!oldcurrent) { 2742 if (!oldcurrent) {
2790 pr_info(DRV_NAME 2743 pr_info("%s: link status definitely up for interface %s, ",
2791 ": %s: link status definitely " 2744 bond->dev->name,
2792 "up for interface %s, ", 2745 slave->dev->name);
2793 bond->dev->name,
2794 slave->dev->name);
2795 do_failover = 1; 2746 do_failover = 1;
2796 } else { 2747 } else {
2797 pr_info(DRV_NAME 2748 pr_info("%s: interface %s is now up\n",
2798 ": %s: interface %s is now up\n", 2749 bond->dev->name,
2799 bond->dev->name, 2750 slave->dev->name);
2800 slave->dev->name);
2801 } 2751 }
2802 } 2752 }
2803 } else { 2753 } else {
@@ -2816,10 +2766,9 @@ void bond_loadbalance_arp_mon(struct work_struct *work)
2816 if (slave->link_failure_count < UINT_MAX) 2766 if (slave->link_failure_count < UINT_MAX)
2817 slave->link_failure_count++; 2767 slave->link_failure_count++;
2818 2768
2819 pr_info(DRV_NAME 2769 pr_info("%s: interface %s is now down.\n",
2820 ": %s: interface %s is now down.\n", 2770 bond->dev->name,
2821 bond->dev->name, 2771 slave->dev->name);
2822 slave->dev->name);
2823 2772
2824 if (slave == oldcurrent) 2773 if (slave == oldcurrent)
2825 do_failover = 1; 2774 do_failover = 1;
@@ -2952,9 +2901,7 @@ static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
2952 slave->link = BOND_LINK_UP; 2901 slave->link = BOND_LINK_UP;
2953 bond->current_arp_slave = NULL; 2902 bond->current_arp_slave = NULL;
2954 2903
2955 pr_info(DRV_NAME 2904 pr_info("%s: link status definitely up for interface %s.\n",
2956 ": %s: link status definitely "
2957 "up for interface %s.\n",
2958 bond->dev->name, slave->dev->name); 2905 bond->dev->name, slave->dev->name);
2959 2906
2960 if (!bond->curr_active_slave || 2907 if (!bond->curr_active_slave ||
@@ -2972,9 +2919,7 @@ static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
2972 slave->link = BOND_LINK_DOWN; 2919 slave->link = BOND_LINK_DOWN;
2973 bond_set_slave_inactive_flags(slave); 2920 bond_set_slave_inactive_flags(slave);
2974 2921
2975 pr_info(DRV_NAME 2922 pr_info("%s: link status definitely down for interface %s, disabling it\n",
2976 ": %s: link status definitely down for "
2977 "interface %s, disabling it\n",
2978 bond->dev->name, slave->dev->name); 2923 bond->dev->name, slave->dev->name);
2979 2924
2980 if (slave == bond->curr_active_slave) { 2925 if (slave == bond->curr_active_slave) {
@@ -2985,8 +2930,7 @@ static void bond_ab_arp_commit(struct bonding *bond, int delta_in_ticks)
2985 continue; 2930 continue;
2986 2931
2987 default: 2932 default:
2988 pr_err(DRV_NAME 2933 pr_err("%s: impossible: new_link %d on slave %s\n",
2989 ": %s: impossible: new_link %d on slave %s\n",
2990 bond->dev->name, slave->new_link, 2934 bond->dev->name, slave->new_link,
2991 slave->dev->name); 2935 slave->dev->name);
2992 continue; 2936 continue;
@@ -3015,9 +2959,9 @@ static void bond_ab_arp_probe(struct bonding *bond)
3015 read_lock(&bond->curr_slave_lock); 2959 read_lock(&bond->curr_slave_lock);
3016 2960
3017 if (bond->current_arp_slave && bond->curr_active_slave) 2961 if (bond->current_arp_slave && bond->curr_active_slave)
3018 pr_info(DRV_NAME "PROBE: c_arp %s && cas %s BAD\n", 2962 pr_info("PROBE: c_arp %s && cas %s BAD\n",
3019 bond->current_arp_slave->dev->name, 2963 bond->current_arp_slave->dev->name,
3020 bond->curr_active_slave->dev->name); 2964 bond->curr_active_slave->dev->name);
3021 2965
3022 if (bond->curr_active_slave) { 2966 if (bond->curr_active_slave) {
3023 bond_arp_send_all(bond, bond->curr_active_slave); 2967 bond_arp_send_all(bond, bond->curr_active_slave);
@@ -3065,9 +3009,8 @@ static void bond_ab_arp_probe(struct bonding *bond)
3065 3009
3066 bond_set_slave_inactive_flags(slave); 3010 bond_set_slave_inactive_flags(slave);
3067 3011
3068 pr_info(DRV_NAME 3012 pr_info("%s: backup interface %s is now down.\n",
3069 ": %s: backup interface %s is now down.\n", 3013 bond->dev->name, slave->dev->name);
3070 bond->dev->name, slave->dev->name);
3071 } 3014 }
3072 } 3015 }
3073} 3016}
@@ -3201,11 +3144,14 @@ static void bond_info_show_master(struct seq_file *seq)
3201 } 3144 }
3202 3145
3203 if (USES_PRIMARY(bond->params.mode)) { 3146 if (USES_PRIMARY(bond->params.mode)) {
3204 seq_printf(seq, "Primary Slave: %s\n", 3147 seq_printf(seq, "Primary Slave: %s",
3205 (bond->primary_slave) ? 3148 (bond->primary_slave) ?
3206 bond->primary_slave->dev->name : "None"); 3149 bond->primary_slave->dev->name : "None");
3150 if (bond->primary_slave)
3151 seq_printf(seq, " (primary_reselect %s)",
3152 pri_reselect_tbl[bond->params.primary_reselect].modename);
3207 3153
3208 seq_printf(seq, "Currently Active Slave: %s\n", 3154 seq_printf(seq, "\nCurrently Active Slave: %s\n",
3209 (curr) ? curr->dev->name : "None"); 3155 (curr) ? curr->dev->name : "None");
3210 } 3156 }
3211 3157
@@ -3334,29 +3280,30 @@ static const struct file_operations bond_info_fops = {
3334 .release = seq_release, 3280 .release = seq_release,
3335}; 3281};
3336 3282
3337static int bond_create_proc_entry(struct bonding *bond) 3283static void bond_create_proc_entry(struct bonding *bond)
3338{ 3284{
3339 struct net_device *bond_dev = bond->dev; 3285 struct net_device *bond_dev = bond->dev;
3286 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
3340 3287
3341 if (bond_proc_dir) { 3288 if (bn->proc_dir) {
3342 bond->proc_entry = proc_create_data(bond_dev->name, 3289 bond->proc_entry = proc_create_data(bond_dev->name,
3343 S_IRUGO, bond_proc_dir, 3290 S_IRUGO, bn->proc_dir,
3344 &bond_info_fops, bond); 3291 &bond_info_fops, bond);
3345 if (bond->proc_entry == NULL) 3292 if (bond->proc_entry == NULL)
3346 pr_warning(DRV_NAME 3293 pr_warning("Warning: Cannot create /proc/net/%s/%s\n",
3347 ": Warning: Cannot create /proc/net/%s/%s\n", 3294 DRV_NAME, bond_dev->name);
3348 DRV_NAME, bond_dev->name);
3349 else 3295 else
3350 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ); 3296 memcpy(bond->proc_file_name, bond_dev->name, IFNAMSIZ);
3351 } 3297 }
3352
3353 return 0;
3354} 3298}
3355 3299
3356static void bond_remove_proc_entry(struct bonding *bond) 3300static void bond_remove_proc_entry(struct bonding *bond)
3357{ 3301{
3358 if (bond_proc_dir && bond->proc_entry) { 3302 struct net_device *bond_dev = bond->dev;
3359 remove_proc_entry(bond->proc_file_name, bond_proc_dir); 3303 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
3304
3305 if (bn->proc_dir && bond->proc_entry) {
3306 remove_proc_entry(bond->proc_file_name, bn->proc_dir);
3360 memset(bond->proc_file_name, 0, IFNAMSIZ); 3307 memset(bond->proc_file_name, 0, IFNAMSIZ);
3361 bond->proc_entry = NULL; 3308 bond->proc_entry = NULL;
3362 } 3309 }
@@ -3365,31 +3312,30 @@ static void bond_remove_proc_entry(struct bonding *bond)
3365/* Create the bonding directory under /proc/net, if doesn't exist yet. 3312/* Create the bonding directory under /proc/net, if doesn't exist yet.
3366 * Caller must hold rtnl_lock. 3313 * Caller must hold rtnl_lock.
3367 */ 3314 */
3368static void bond_create_proc_dir(void) 3315static void __net_init bond_create_proc_dir(struct bond_net *bn)
3369{ 3316{
3370 if (!bond_proc_dir) { 3317 if (!bn->proc_dir) {
3371 bond_proc_dir = proc_mkdir(DRV_NAME, init_net.proc_net); 3318 bn->proc_dir = proc_mkdir(DRV_NAME, bn->net->proc_net);
3372 if (!bond_proc_dir) 3319 if (!bn->proc_dir)
3373 pr_warning(DRV_NAME 3320 pr_warning("Warning: cannot create /proc/net/%s\n",
3374 ": Warning: cannot create /proc/net/%s\n", 3321 DRV_NAME);
3375 DRV_NAME);
3376 } 3322 }
3377} 3323}
3378 3324
3379/* Destroy the bonding directory under /proc/net, if empty. 3325/* Destroy the bonding directory under /proc/net, if empty.
3380 * Caller must hold rtnl_lock. 3326 * Caller must hold rtnl_lock.
3381 */ 3327 */
3382static void bond_destroy_proc_dir(void) 3328static void __net_exit bond_destroy_proc_dir(struct bond_net *bn)
3383{ 3329{
3384 if (bond_proc_dir) { 3330 if (bn->proc_dir) {
3385 remove_proc_entry(DRV_NAME, init_net.proc_net); 3331 remove_proc_entry(DRV_NAME, bn->net->proc_net);
3386 bond_proc_dir = NULL; 3332 bn->proc_dir = NULL;
3387 } 3333 }
3388} 3334}
3389 3335
3390#else /* !CONFIG_PROC_FS */ 3336#else /* !CONFIG_PROC_FS */
3391 3337
3392static int bond_create_proc_entry(struct bonding *bond) 3338static void bond_create_proc_entry(struct bonding *bond)
3393{ 3339{
3394} 3340}
3395 3341
@@ -3397,11 +3343,11 @@ static void bond_remove_proc_entry(struct bonding *bond)
3397{ 3343{
3398} 3344}
3399 3345
3400static void bond_create_proc_dir(void) 3346static inline void bond_create_proc_dir(struct bond_net *bn)
3401{ 3347{
3402} 3348}
3403 3349
3404static void bond_destroy_proc_dir(void) 3350static inline void bond_destroy_proc_dir(struct bond_net *bn)
3405{ 3351{
3406} 3352}
3407 3353
@@ -3418,9 +3364,6 @@ static int bond_event_changename(struct bonding *bond)
3418 bond_remove_proc_entry(bond); 3364 bond_remove_proc_entry(bond);
3419 bond_create_proc_entry(bond); 3365 bond_create_proc_entry(bond);
3420 3366
3421 bond_destroy_sysfs_entry(bond);
3422 bond_create_sysfs_entry(bond);
3423
3424 return NOTIFY_DONE; 3367 return NOTIFY_DONE;
3425} 3368}
3426 3369
@@ -3432,9 +3375,6 @@ static int bond_master_netdev_event(unsigned long event,
3432 switch (event) { 3375 switch (event) {
3433 case NETDEV_CHANGENAME: 3376 case NETDEV_CHANGENAME:
3434 return bond_event_changename(event_bond); 3377 return bond_event_changename(event_bond);
3435 case NETDEV_UNREGISTER:
3436 bond_release_all(event_bond->dev);
3437 break;
3438 default: 3378 default:
3439 break; 3379 break;
3440 } 3380 }
@@ -3526,12 +3466,9 @@ static int bond_netdev_event(struct notifier_block *this,
3526{ 3466{
3527 struct net_device *event_dev = (struct net_device *)ptr; 3467 struct net_device *event_dev = (struct net_device *)ptr;
3528 3468
3529 if (dev_net(event_dev) != &init_net)
3530 return NOTIFY_DONE;
3531
3532 pr_debug("event_dev: %s, event: %lx\n", 3469 pr_debug("event_dev: %s, event: %lx\n",
3533 (event_dev ? event_dev->name : "None"), 3470 event_dev ? event_dev->name : "None",
3534 event); 3471 event);
3535 3472
3536 if (!(event_dev->priv_flags & IFF_BONDING)) 3473 if (!(event_dev->priv_flags & IFF_BONDING))
3537 return NOTIFY_DONE; 3474 return NOTIFY_DONE;
@@ -3561,13 +3498,11 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
3561{ 3498{
3562 struct in_ifaddr *ifa = ptr; 3499 struct in_ifaddr *ifa = ptr;
3563 struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev; 3500 struct net_device *vlan_dev, *event_dev = ifa->ifa_dev->dev;
3501 struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id);
3564 struct bonding *bond; 3502 struct bonding *bond;
3565 struct vlan_entry *vlan; 3503 struct vlan_entry *vlan;
3566 3504
3567 if (dev_net(ifa->ifa_dev->dev) != &init_net) 3505 list_for_each_entry(bond, &bn->dev_list, bond_list) {
3568 return NOTIFY_DONE;
3569
3570 list_for_each_entry(bond, &bond_dev_list, bond_list) {
3571 if (bond->dev == event_dev) { 3506 if (bond->dev == event_dev) {
3572 switch (event) { 3507 switch (event) {
3573 case NETDEV_UP: 3508 case NETDEV_UP:
@@ -3657,8 +3592,7 @@ void bond_unregister_arp(struct bonding *bond)
3657 * Hash for the output device based upon layer 2 and layer 3 data. If 3592 * Hash for the output device based upon layer 2 and layer 3 data. If
3658 * the packet is not IP mimic bond_xmit_hash_policy_l2() 3593 * the packet is not IP mimic bond_xmit_hash_policy_l2()
3659 */ 3594 */
3660static int bond_xmit_hash_policy_l23(struct sk_buff *skb, 3595static int bond_xmit_hash_policy_l23(struct sk_buff *skb, int count)
3661 struct net_device *bond_dev, int count)
3662{ 3596{
3663 struct ethhdr *data = (struct ethhdr *)skb->data; 3597 struct ethhdr *data = (struct ethhdr *)skb->data;
3664 struct iphdr *iph = ip_hdr(skb); 3598 struct iphdr *iph = ip_hdr(skb);
@@ -3676,8 +3610,7 @@ static int bond_xmit_hash_policy_l23(struct sk_buff *skb,
3676 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is 3610 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3677 * altogether not IP, mimic bond_xmit_hash_policy_l2() 3611 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3678 */ 3612 */
3679static int bond_xmit_hash_policy_l34(struct sk_buff *skb, 3613static int bond_xmit_hash_policy_l34(struct sk_buff *skb, int count)
3680 struct net_device *bond_dev, int count)
3681{ 3614{
3682 struct ethhdr *data = (struct ethhdr *)skb->data; 3615 struct ethhdr *data = (struct ethhdr *)skb->data;
3683 struct iphdr *iph = ip_hdr(skb); 3616 struct iphdr *iph = ip_hdr(skb);
@@ -3701,8 +3634,7 @@ static int bond_xmit_hash_policy_l34(struct sk_buff *skb,
3701/* 3634/*
3702 * Hash for the output device based upon layer 2 data 3635 * Hash for the output device based upon layer 2 data
3703 */ 3636 */
3704static int bond_xmit_hash_policy_l2(struct sk_buff *skb, 3637static int bond_xmit_hash_policy_l2(struct sk_buff *skb, int count)
3705 struct net_device *bond_dev, int count)
3706{ 3638{
3707 struct ethhdr *data = (struct ethhdr *)skb->data; 3639 struct ethhdr *data = (struct ethhdr *)skb->data;
3708 3640
@@ -3723,7 +3655,7 @@ static int bond_open(struct net_device *bond_dev)
3723 */ 3655 */
3724 if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) { 3656 if (bond_alb_initialize(bond, (bond->params.mode == BOND_MODE_ALB))) {
3725 /* something went wrong - fail the open operation */ 3657 /* something went wrong - fail the open operation */
3726 return -1; 3658 return -ENOMEM;
3727 } 3659 }
3728 3660
3729 INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor); 3661 INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
@@ -3815,7 +3747,7 @@ static int bond_close(struct net_device *bond_dev)
3815static struct net_device_stats *bond_get_stats(struct net_device *bond_dev) 3747static struct net_device_stats *bond_get_stats(struct net_device *bond_dev)
3816{ 3748{
3817 struct bonding *bond = netdev_priv(bond_dev); 3749 struct bonding *bond = netdev_priv(bond_dev);
3818 struct net_device_stats *stats = &bond->stats; 3750 struct net_device_stats *stats = &bond_dev->stats;
3819 struct net_device_stats local_stats; 3751 struct net_device_stats local_stats;
3820 struct slave *slave; 3752 struct slave *slave;
3821 int i; 3753 int i;
@@ -3871,8 +3803,7 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
3871 struct mii_ioctl_data *mii = NULL; 3803 struct mii_ioctl_data *mii = NULL;
3872 int res = 0; 3804 int res = 0;
3873 3805
3874 pr_debug("bond_ioctl: master=%s, cmd=%d\n", 3806 pr_debug("bond_ioctl: master=%s, cmd=%d\n", bond_dev->name, cmd);
3875 bond_dev->name, cmd);
3876 3807
3877 switch (cmd) { 3808 switch (cmd) {
3878 case SIOCGMIIPHY: 3809 case SIOCGMIIPHY:
@@ -3939,14 +3870,14 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
3939 if (!capable(CAP_NET_ADMIN)) 3870 if (!capable(CAP_NET_ADMIN))
3940 return -EPERM; 3871 return -EPERM;
3941 3872
3942 slave_dev = dev_get_by_name(&init_net, ifr->ifr_slave); 3873 slave_dev = dev_get_by_name(dev_net(bond_dev), ifr->ifr_slave);
3943 3874
3944 pr_debug("slave_dev=%p: \n", slave_dev); 3875 pr_debug("slave_dev=%p:\n", slave_dev);
3945 3876
3946 if (!slave_dev) 3877 if (!slave_dev)
3947 res = -ENODEV; 3878 res = -ENODEV;
3948 else { 3879 else {
3949 pr_debug("slave_dev->name=%s: \n", slave_dev->name); 3880 pr_debug("slave_dev->name=%s:\n", slave_dev->name);
3950 switch (cmd) { 3881 switch (cmd) {
3951 case BOND_ENSLAVE_OLD: 3882 case BOND_ENSLAVE_OLD:
3952 case SIOCBONDENSLAVE: 3883 case SIOCBONDENSLAVE:
@@ -4055,7 +3986,7 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
4055 int i; 3986 int i;
4056 3987
4057 pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond, 3988 pr_debug("bond=%p, name=%s, new_mtu=%d\n", bond,
4058 (bond_dev ? bond_dev->name : "None"), new_mtu); 3989 (bond_dev ? bond_dev->name : "None"), new_mtu);
4059 3990
4060 /* Can't hold bond->lock with bh disabled here since 3991 /* Can't hold bond->lock with bh disabled here since
4061 * some base drivers panic. On the other hand we can't 3992 * some base drivers panic. On the other hand we can't
@@ -4073,8 +4004,10 @@ static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
4073 */ 4004 */
4074 4005
4075 bond_for_each_slave(bond, slave, i) { 4006 bond_for_each_slave(bond, slave, i) {
4076 pr_debug("s %p s->p %p c_m %p\n", slave, 4007 pr_debug("s %p s->p %p c_m %p\n",
4077 slave->prev, slave->dev->netdev_ops->ndo_change_mtu); 4008 slave,
4009 slave->prev,
4010 slave->dev->netdev_ops->ndo_change_mtu);
4078 4011
4079 res = dev_set_mtu(slave->dev, new_mtu); 4012 res = dev_set_mtu(slave->dev, new_mtu);
4080 4013
@@ -4104,8 +4037,8 @@ unwind:
4104 4037
4105 tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu); 4038 tmp_res = dev_set_mtu(slave->dev, bond_dev->mtu);
4106 if (tmp_res) { 4039 if (tmp_res) {
4107 pr_debug("unwind err %d dev %s\n", tmp_res, 4040 pr_debug("unwind err %d dev %s\n",
4108 slave->dev->name); 4041 tmp_res, slave->dev->name);
4109 } 4042 }
4110 } 4043 }
4111 4044
@@ -4131,7 +4064,8 @@ static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
4131 return bond_alb_set_mac_address(bond_dev, addr); 4064 return bond_alb_set_mac_address(bond_dev, addr);
4132 4065
4133 4066
4134 pr_debug("bond=%p, name=%s\n", bond, (bond_dev ? bond_dev->name : "None")); 4067 pr_debug("bond=%p, name=%s\n",
4068 bond, bond_dev ? bond_dev->name : "None");
4135 4069
4136 /* 4070 /*
4137 * If fail_over_mac is set to active, do nothing and return 4071 * If fail_over_mac is set to active, do nothing and return
@@ -4196,8 +4130,8 @@ unwind:
4196 4130
4197 tmp_res = dev_set_mac_address(slave->dev, &tmp_sa); 4131 tmp_res = dev_set_mac_address(slave->dev, &tmp_sa);
4198 if (tmp_res) { 4132 if (tmp_res) {
4199 pr_debug("unwind err %d dev %s\n", tmp_res, 4133 pr_debug("unwind err %d dev %s\n",
4200 slave->dev->name); 4134 tmp_res, slave->dev->name);
4201 } 4135 }
4202 } 4136 }
4203 4137
@@ -4209,22 +4143,41 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev
4209 struct bonding *bond = netdev_priv(bond_dev); 4143 struct bonding *bond = netdev_priv(bond_dev);
4210 struct slave *slave, *start_at; 4144 struct slave *slave, *start_at;
4211 int i, slave_no, res = 1; 4145 int i, slave_no, res = 1;
4146 struct iphdr *iph = ip_hdr(skb);
4212 4147
4213 read_lock(&bond->lock); 4148 read_lock(&bond->lock);
4214 4149
4215 if (!BOND_IS_OK(bond)) 4150 if (!BOND_IS_OK(bond))
4216 goto out; 4151 goto out;
4217
4218 /* 4152 /*
4219 * Concurrent TX may collide on rr_tx_counter; we accept that 4153 * Start with the curr_active_slave that joined the bond as the
4220 * as being rare enough not to justify using an atomic op here 4154 * default for sending IGMP traffic. For failover purposes one
4155 * needs to maintain some consistency for the interface that will
4156 * send the join/membership reports. The curr_active_slave found
4157 * will send all of this type of traffic.
4221 */ 4158 */
4222 slave_no = bond->rr_tx_counter++ % bond->slave_cnt; 4159 if ((iph->protocol == IPPROTO_IGMP) &&
4160 (skb->protocol == htons(ETH_P_IP))) {
4223 4161
4224 bond_for_each_slave(bond, slave, i) { 4162 read_lock(&bond->curr_slave_lock);
4225 slave_no--; 4163 slave = bond->curr_active_slave;
4226 if (slave_no < 0) 4164 read_unlock(&bond->curr_slave_lock);
4227 break; 4165
4166 if (!slave)
4167 goto out;
4168 } else {
4169 /*
4170 * Concurrent TX may collide on rr_tx_counter; we accept
4171 * that as being rare enough not to justify using an
4172 * atomic op here.
4173 */
4174 slave_no = bond->rr_tx_counter++ % bond->slave_cnt;
4175
4176 bond_for_each_slave(bond, slave, i) {
4177 slave_no--;
4178 if (slave_no < 0)
4179 break;
4180 }
4228 } 4181 }
4229 4182
4230 start_at = slave; 4183 start_at = slave;
@@ -4295,7 +4248,7 @@ static int bond_xmit_xor(struct sk_buff *skb, struct net_device *bond_dev)
4295 if (!BOND_IS_OK(bond)) 4248 if (!BOND_IS_OK(bond))
4296 goto out; 4249 goto out;
4297 4250
4298 slave_no = bond->xmit_hash_policy(skb, bond_dev, bond->slave_cnt); 4251 slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt);
4299 4252
4300 bond_for_each_slave(bond, slave, i) { 4253 bond_for_each_slave(bond, slave, i) {
4301 slave_no--; 4254 slave_no--;
@@ -4353,9 +4306,7 @@ static int bond_xmit_broadcast(struct sk_buff *skb, struct net_device *bond_dev)
4353 if (tx_dev) { 4306 if (tx_dev) {
4354 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); 4307 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
4355 if (!skb2) { 4308 if (!skb2) {
4356 pr_err(DRV_NAME 4309 pr_err("%s: Error: bond_xmit_broadcast(): skb_clone() failed\n",
4357 ": %s: Error: bond_xmit_broadcast(): "
4358 "skb_clone() failed\n",
4359 bond_dev->name); 4310 bond_dev->name);
4360 continue; 4311 continue;
4361 } 4312 }
@@ -4421,8 +4372,8 @@ static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
4421 return bond_alb_xmit(skb, dev); 4372 return bond_alb_xmit(skb, dev);
4422 default: 4373 default:
4423 /* Should never happen, mode already checked */ 4374 /* Should never happen, mode already checked */
4424 pr_err(DRV_NAME ": %s: Error: Unknown bonding mode %d\n", 4375 pr_err("%s: Error: Unknown bonding mode %d\n",
4425 dev->name, bond->params.mode); 4376 dev->name, bond->params.mode);
4426 WARN_ON_ONCE(1); 4377 WARN_ON_ONCE(1);
4427 dev_kfree_skb(skb); 4378 dev_kfree_skb(skb);
4428 return NETDEV_TX_OK; 4379 return NETDEV_TX_OK;
@@ -4458,10 +4409,8 @@ void bond_set_mode_ops(struct bonding *bond, int mode)
4458 break; 4409 break;
4459 default: 4410 default:
4460 /* Should never happen, mode already checked */ 4411 /* Should never happen, mode already checked */
4461 pr_err(DRV_NAME 4412 pr_err("%s: Error: Unknown bonding mode %d\n",
4462 ": %s: Error: Unknown bonding mode %d\n", 4413 bond_dev->name, mode);
4463 bond_dev->name,
4464 mode);
4465 break; 4414 break;
4466 } 4415 }
4467} 4416}
@@ -4501,6 +4450,14 @@ static const struct net_device_ops bond_netdev_ops = {
4501 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, 4450 .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
4502}; 4451};
4503 4452
4453static void bond_destructor(struct net_device *bond_dev)
4454{
4455 struct bonding *bond = netdev_priv(bond_dev);
4456 if (bond->wq)
4457 destroy_workqueue(bond->wq);
4458 free_netdev(bond_dev);
4459}
4460
4504static void bond_setup(struct net_device *bond_dev) 4461static void bond_setup(struct net_device *bond_dev)
4505{ 4462{
4506 struct bonding *bond = netdev_priv(bond_dev); 4463 struct bonding *bond = netdev_priv(bond_dev);
@@ -4521,7 +4478,7 @@ static void bond_setup(struct net_device *bond_dev)
4521 bond_dev->ethtool_ops = &bond_ethtool_ops; 4478 bond_dev->ethtool_ops = &bond_ethtool_ops;
4522 bond_set_mode_ops(bond, bond->params.mode); 4479 bond_set_mode_ops(bond, bond->params.mode);
4523 4480
4524 bond_dev->destructor = free_netdev; 4481 bond_dev->destructor = bond_destructor;
4525 4482
4526 /* Initialize the device options */ 4483 /* Initialize the device options */
4527 bond_dev->tx_queue_len = 0; 4484 bond_dev->tx_queue_len = 0;
@@ -4576,37 +4533,26 @@ static void bond_work_cancel_all(struct bonding *bond)
4576 cancel_delayed_work(&bond->ad_work); 4533 cancel_delayed_work(&bond->ad_work);
4577} 4534}
4578 4535
4579/* De-initialize device specific data. 4536/*
4580 * Caller must hold rtnl_lock. 4537* Destroy a bonding device.
4581 */ 4538* Must be under rtnl_lock when this function is called.
4582static void bond_deinit(struct net_device *bond_dev) 4539*/
4540static void bond_uninit(struct net_device *bond_dev)
4583{ 4541{
4584 struct bonding *bond = netdev_priv(bond_dev); 4542 struct bonding *bond = netdev_priv(bond_dev);
4585 4543
4544 /* Release the bonded slaves */
4545 bond_release_all(bond_dev);
4546
4586 list_del(&bond->bond_list); 4547 list_del(&bond->bond_list);
4587 4548
4588 bond_work_cancel_all(bond); 4549 bond_work_cancel_all(bond);
4589 4550
4590 bond_remove_proc_entry(bond); 4551 bond_remove_proc_entry(bond);
4591}
4592 4552
4593/* Unregister and free all bond devices. 4553 netif_addr_lock_bh(bond_dev);
4594 * Caller must hold rtnl_lock. 4554 bond_mc_list_destroy(bond);
4595 */ 4555 netif_addr_unlock_bh(bond_dev);
4596static void bond_free_all(void)
4597{
4598 struct bonding *bond, *nxt;
4599
4600 list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list) {
4601 struct net_device *bond_dev = bond->dev;
4602
4603 bond_work_cancel_all(bond);
4604 /* Release the bonded slaves */
4605 bond_release_all(bond_dev);
4606 unregister_netdevice(bond_dev);
4607 }
4608
4609 bond_destroy_proc_dir();
4610} 4556}
4611 4557
4612/*------------------------- Module initialization ---------------------------*/ 4558/*------------------------- Module initialization ---------------------------*/
@@ -4646,7 +4592,7 @@ int bond_parse_parm(const char *buf, const struct bond_parm_tbl *tbl)
4646 4592
4647static int bond_check_params(struct bond_params *params) 4593static int bond_check_params(struct bond_params *params)
4648{ 4594{
4649 int arp_validate_value, fail_over_mac_value; 4595 int arp_validate_value, fail_over_mac_value, primary_reselect_value;
4650 4596
4651 /* 4597 /*
4652 * Convert string parameters. 4598 * Convert string parameters.
@@ -4654,8 +4600,7 @@ static int bond_check_params(struct bond_params *params)
4654 if (mode) { 4600 if (mode) {
4655 bond_mode = bond_parse_parm(mode, bond_mode_tbl); 4601 bond_mode = bond_parse_parm(mode, bond_mode_tbl);
4656 if (bond_mode == -1) { 4602 if (bond_mode == -1) {
4657 pr_err(DRV_NAME 4603 pr_err("Error: Invalid bonding mode \"%s\"\n",
4658 ": Error: Invalid bonding mode \"%s\"\n",
4659 mode == NULL ? "NULL" : mode); 4604 mode == NULL ? "NULL" : mode);
4660 return -EINVAL; 4605 return -EINVAL;
4661 } 4606 }
@@ -4664,15 +4609,13 @@ static int bond_check_params(struct bond_params *params)
4664 if (xmit_hash_policy) { 4609 if (xmit_hash_policy) {
4665 if ((bond_mode != BOND_MODE_XOR) && 4610 if ((bond_mode != BOND_MODE_XOR) &&
4666 (bond_mode != BOND_MODE_8023AD)) { 4611 (bond_mode != BOND_MODE_8023AD)) {
4667 pr_info(DRV_NAME 4612 pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
4668 ": xor_mode param is irrelevant in mode %s\n",
4669 bond_mode_name(bond_mode)); 4613 bond_mode_name(bond_mode));
4670 } else { 4614 } else {
4671 xmit_hashtype = bond_parse_parm(xmit_hash_policy, 4615 xmit_hashtype = bond_parse_parm(xmit_hash_policy,
4672 xmit_hashtype_tbl); 4616 xmit_hashtype_tbl);
4673 if (xmit_hashtype == -1) { 4617 if (xmit_hashtype == -1) {
4674 pr_err(DRV_NAME 4618 pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
4675 ": Error: Invalid xmit_hash_policy \"%s\"\n",
4676 xmit_hash_policy == NULL ? "NULL" : 4619 xmit_hash_policy == NULL ? "NULL" :
4677 xmit_hash_policy); 4620 xmit_hash_policy);
4678 return -EINVAL; 4621 return -EINVAL;
@@ -4682,14 +4625,12 @@ static int bond_check_params(struct bond_params *params)
4682 4625
4683 if (lacp_rate) { 4626 if (lacp_rate) {
4684 if (bond_mode != BOND_MODE_8023AD) { 4627 if (bond_mode != BOND_MODE_8023AD) {
4685 pr_info(DRV_NAME 4628 pr_info("lacp_rate param is irrelevant in mode %s\n",
4686 ": lacp_rate param is irrelevant in mode %s\n", 4629 bond_mode_name(bond_mode));
4687 bond_mode_name(bond_mode));
4688 } else { 4630 } else {
4689 lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl); 4631 lacp_fast = bond_parse_parm(lacp_rate, bond_lacp_tbl);
4690 if (lacp_fast == -1) { 4632 if (lacp_fast == -1) {
4691 pr_err(DRV_NAME 4633 pr_err("Error: Invalid lacp rate \"%s\"\n",
4692 ": Error: Invalid lacp rate \"%s\"\n",
4693 lacp_rate == NULL ? "NULL" : lacp_rate); 4634 lacp_rate == NULL ? "NULL" : lacp_rate);
4694 return -EINVAL; 4635 return -EINVAL;
4695 } 4636 }
@@ -4699,82 +4640,64 @@ static int bond_check_params(struct bond_params *params)
4699 if (ad_select) { 4640 if (ad_select) {
4700 params->ad_select = bond_parse_parm(ad_select, ad_select_tbl); 4641 params->ad_select = bond_parse_parm(ad_select, ad_select_tbl);
4701 if (params->ad_select == -1) { 4642 if (params->ad_select == -1) {
4702 pr_err(DRV_NAME 4643 pr_err("Error: Invalid ad_select \"%s\"\n",
4703 ": Error: Invalid ad_select \"%s\"\n",
4704 ad_select == NULL ? "NULL" : ad_select); 4644 ad_select == NULL ? "NULL" : ad_select);
4705 return -EINVAL; 4645 return -EINVAL;
4706 } 4646 }
4707 4647
4708 if (bond_mode != BOND_MODE_8023AD) { 4648 if (bond_mode != BOND_MODE_8023AD) {
4709 pr_warning(DRV_NAME 4649 pr_warning("ad_select param only affects 802.3ad mode\n");
4710 ": ad_select param only affects 802.3ad mode\n");
4711 } 4650 }
4712 } else { 4651 } else {
4713 params->ad_select = BOND_AD_STABLE; 4652 params->ad_select = BOND_AD_STABLE;
4714 } 4653 }
4715 4654
4716 if (max_bonds < 0) { 4655 if (max_bonds < 0) {
4717 pr_warning(DRV_NAME 4656 pr_warning("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
4718 ": Warning: max_bonds (%d) not in range %d-%d, so it " 4657 max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
4719 "was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
4720 max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
4721 max_bonds = BOND_DEFAULT_MAX_BONDS; 4658 max_bonds = BOND_DEFAULT_MAX_BONDS;
4722 } 4659 }
4723 4660
4724 if (miimon < 0) { 4661 if (miimon < 0) {
4725 pr_warning(DRV_NAME 4662 pr_warning("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to %d\n",
4726 ": Warning: miimon module parameter (%d), " 4663 miimon, INT_MAX, BOND_LINK_MON_INTERV);
4727 "not in range 0-%d, so it was reset to %d\n",
4728 miimon, INT_MAX, BOND_LINK_MON_INTERV);
4729 miimon = BOND_LINK_MON_INTERV; 4664 miimon = BOND_LINK_MON_INTERV;
4730 } 4665 }
4731 4666
4732 if (updelay < 0) { 4667 if (updelay < 0) {
4733 pr_warning(DRV_NAME 4668 pr_warning("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4734 ": Warning: updelay module parameter (%d), " 4669 updelay, INT_MAX);
4735 "not in range 0-%d, so it was reset to 0\n",
4736 updelay, INT_MAX);
4737 updelay = 0; 4670 updelay = 0;
4738 } 4671 }
4739 4672
4740 if (downdelay < 0) { 4673 if (downdelay < 0) {
4741 pr_warning(DRV_NAME 4674 pr_warning("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
4742 ": Warning: downdelay module parameter (%d), " 4675 downdelay, INT_MAX);
4743 "not in range 0-%d, so it was reset to 0\n",
4744 downdelay, INT_MAX);
4745 downdelay = 0; 4676 downdelay = 0;
4746 } 4677 }
4747 4678
4748 if ((use_carrier != 0) && (use_carrier != 1)) { 4679 if ((use_carrier != 0) && (use_carrier != 1)) {
4749 pr_warning(DRV_NAME 4680 pr_warning("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n",
4750 ": Warning: use_carrier module parameter (%d), " 4681 use_carrier);
4751 "not of valid value (0/1), so it was set to 1\n",
4752 use_carrier);
4753 use_carrier = 1; 4682 use_carrier = 1;
4754 } 4683 }
4755 4684
4756 if (num_grat_arp < 0 || num_grat_arp > 255) { 4685 if (num_grat_arp < 0 || num_grat_arp > 255) {
4757 pr_warning(DRV_NAME 4686 pr_warning("Warning: num_grat_arp (%d) not in range 0-255 so it was reset to 1 \n",
4758 ": Warning: num_grat_arp (%d) not in range 0-255 so it " 4687 num_grat_arp);
4759 "was reset to 1 \n", num_grat_arp);
4760 num_grat_arp = 1; 4688 num_grat_arp = 1;
4761 } 4689 }
4762 4690
4763 if (num_unsol_na < 0 || num_unsol_na > 255) { 4691 if (num_unsol_na < 0 || num_unsol_na > 255) {
4764 pr_warning(DRV_NAME 4692 pr_warning("Warning: num_unsol_na (%d) not in range 0-255 so it was reset to 1 \n",
4765 ": Warning: num_unsol_na (%d) not in range 0-255 so it " 4693 num_unsol_na);
4766 "was reset to 1 \n", num_unsol_na);
4767 num_unsol_na = 1; 4694 num_unsol_na = 1;
4768 } 4695 }
4769 4696
4770 /* reset values for 802.3ad */ 4697 /* reset values for 802.3ad */
4771 if (bond_mode == BOND_MODE_8023AD) { 4698 if (bond_mode == BOND_MODE_8023AD) {
4772 if (!miimon) { 4699 if (!miimon) {
4773 pr_warning(DRV_NAME 4700 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");
4774 ": Warning: miimon must be specified, "
4775 "otherwise bonding will not detect link "
4776 "failure, speed and duplex which are "
4777 "essential for 802.3ad operation\n");
4778 pr_warning("Forcing miimon to 100msec\n"); 4701 pr_warning("Forcing miimon to 100msec\n");
4779 miimon = 100; 4702 miimon = 100;
4780 } 4703 }
@@ -4784,24 +4707,15 @@ static int bond_check_params(struct bond_params *params)
4784 if ((bond_mode == BOND_MODE_TLB) || 4707 if ((bond_mode == BOND_MODE_TLB) ||
4785 (bond_mode == BOND_MODE_ALB)) { 4708 (bond_mode == BOND_MODE_ALB)) {
4786 if (!miimon) { 4709 if (!miimon) {
4787 pr_warning(DRV_NAME 4710 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");
4788 ": Warning: miimon must be specified, "
4789 "otherwise bonding will not detect link "
4790 "failure and link speed which are essential "
4791 "for TLB/ALB load balancing\n");
4792 pr_warning("Forcing miimon to 100msec\n"); 4711 pr_warning("Forcing miimon to 100msec\n");
4793 miimon = 100; 4712 miimon = 100;
4794 } 4713 }
4795 } 4714 }
4796 4715
4797 if (bond_mode == BOND_MODE_ALB) { 4716 if (bond_mode == BOND_MODE_ALB) {
4798 pr_notice(DRV_NAME 4717 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",
4799 ": In ALB mode you might experience client " 4718 updelay);
4800 "disconnections upon reconnection of a link if the "
4801 "bonding module updelay parameter (%d msec) is "
4802 "incompatible with the forwarding delay time of the "
4803 "switch\n",
4804 updelay);
4805 } 4719 }
4806 4720
4807 if (!miimon) { 4721 if (!miimon) {
@@ -4809,49 +4723,37 @@ static int bond_check_params(struct bond_params *params)
4809 /* just warn the user the up/down delay will have 4723 /* just warn the user the up/down delay will have
4810 * no effect since miimon is zero... 4724 * no effect since miimon is zero...
4811 */ 4725 */
4812 pr_warning(DRV_NAME 4726 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",
4813 ": Warning: miimon module parameter not set " 4727 updelay, downdelay);
4814 "and updelay (%d) or downdelay (%d) module "
4815 "parameter is set; updelay and downdelay have "
4816 "no effect unless miimon is set\n",
4817 updelay, downdelay);
4818 } 4728 }
4819 } else { 4729 } else {
4820 /* don't allow arp monitoring */ 4730 /* don't allow arp monitoring */
4821 if (arp_interval) { 4731 if (arp_interval) {
4822 pr_warning(DRV_NAME 4732 pr_warning("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n",
4823 ": Warning: miimon (%d) and arp_interval (%d) " 4733 miimon, arp_interval);
4824 "can't be used simultaneously, disabling ARP "
4825 "monitoring\n",
4826 miimon, arp_interval);
4827 arp_interval = 0; 4734 arp_interval = 0;
4828 } 4735 }
4829 4736
4830 if ((updelay % miimon) != 0) { 4737 if ((updelay % miimon) != 0) {
4831 pr_warning(DRV_NAME 4738 pr_warning("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
4832 ": Warning: updelay (%d) is not a multiple " 4739 updelay, miimon,
4833 "of miimon (%d), updelay rounded to %d ms\n", 4740 (updelay / miimon) * miimon);
4834 updelay, miimon, (updelay / miimon) * miimon);
4835 } 4741 }
4836 4742
4837 updelay /= miimon; 4743 updelay /= miimon;
4838 4744
4839 if ((downdelay % miimon) != 0) { 4745 if ((downdelay % miimon) != 0) {
4840 pr_warning(DRV_NAME 4746 pr_warning("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n",
4841 ": Warning: downdelay (%d) is not a multiple " 4747 downdelay, miimon,
4842 "of miimon (%d), downdelay rounded to %d ms\n", 4748 (downdelay / miimon) * miimon);
4843 downdelay, miimon,
4844 (downdelay / miimon) * miimon);
4845 } 4749 }
4846 4750
4847 downdelay /= miimon; 4751 downdelay /= miimon;
4848 } 4752 }
4849 4753
4850 if (arp_interval < 0) { 4754 if (arp_interval < 0) {
4851 pr_warning(DRV_NAME 4755 pr_warning("Warning: arp_interval module parameter (%d) , not in range 0-%d, so it was reset to %d\n",
4852 ": Warning: arp_interval module parameter (%d) " 4756 arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
4853 ", not in range 0-%d, so it was reset to %d\n",
4854 arp_interval, INT_MAX, BOND_LINK_ARP_INTERV);
4855 arp_interval = BOND_LINK_ARP_INTERV; 4757 arp_interval = BOND_LINK_ARP_INTERV;
4856 } 4758 }
4857 4759
@@ -4861,10 +4763,8 @@ static int bond_check_params(struct bond_params *params)
4861 /* not complete check, but should be good enough to 4763 /* not complete check, but should be good enough to
4862 catch mistakes */ 4764 catch mistakes */
4863 if (!isdigit(arp_ip_target[arp_ip_count][0])) { 4765 if (!isdigit(arp_ip_target[arp_ip_count][0])) {
4864 pr_warning(DRV_NAME 4766 pr_warning("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n",
4865 ": Warning: bad arp_ip_target module parameter " 4767 arp_ip_target[arp_ip_count]);
4866 "(%s), ARP monitoring will not be performed\n",
4867 arp_ip_target[arp_ip_count]);
4868 arp_interval = 0; 4768 arp_interval = 0;
4869 } else { 4769 } else {
4870 __be32 ip = in_aton(arp_ip_target[arp_ip_count]); 4770 __be32 ip = in_aton(arp_ip_target[arp_ip_count]);
@@ -4874,31 +4774,25 @@ static int bond_check_params(struct bond_params *params)
4874 4774
4875 if (arp_interval && !arp_ip_count) { 4775 if (arp_interval && !arp_ip_count) {
4876 /* don't allow arping if no arp_ip_target given... */ 4776 /* don't allow arping if no arp_ip_target given... */
4877 pr_warning(DRV_NAME 4777 pr_warning("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n",
4878 ": Warning: arp_interval module parameter (%d) " 4778 arp_interval);
4879 "specified without providing an arp_ip_target "
4880 "parameter, arp_interval was reset to 0\n",
4881 arp_interval);
4882 arp_interval = 0; 4779 arp_interval = 0;
4883 } 4780 }
4884 4781
4885 if (arp_validate) { 4782 if (arp_validate) {
4886 if (bond_mode != BOND_MODE_ACTIVEBACKUP) { 4783 if (bond_mode != BOND_MODE_ACTIVEBACKUP) {
4887 pr_err(DRV_NAME 4784 pr_err("arp_validate only supported in active-backup mode\n");
4888 ": arp_validate only supported in active-backup mode\n");
4889 return -EINVAL; 4785 return -EINVAL;
4890 } 4786 }
4891 if (!arp_interval) { 4787 if (!arp_interval) {
4892 pr_err(DRV_NAME 4788 pr_err("arp_validate requires arp_interval\n");
4893 ": arp_validate requires arp_interval\n");
4894 return -EINVAL; 4789 return -EINVAL;
4895 } 4790 }
4896 4791
4897 arp_validate_value = bond_parse_parm(arp_validate, 4792 arp_validate_value = bond_parse_parm(arp_validate,
4898 arp_validate_tbl); 4793 arp_validate_tbl);
4899 if (arp_validate_value == -1) { 4794 if (arp_validate_value == -1) {
4900 pr_err(DRV_NAME 4795 pr_err("Error: invalid arp_validate \"%s\"\n",
4901 ": Error: invalid arp_validate \"%s\"\n",
4902 arp_validate == NULL ? "NULL" : arp_validate); 4796 arp_validate == NULL ? "NULL" : arp_validate);
4903 return -EINVAL; 4797 return -EINVAL;
4904 } 4798 }
@@ -4906,17 +4800,14 @@ static int bond_check_params(struct bond_params *params)
4906 arp_validate_value = 0; 4800 arp_validate_value = 0;
4907 4801
4908 if (miimon) { 4802 if (miimon) {
4909 pr_info(DRV_NAME 4803 pr_info("MII link monitoring set to %d ms\n", miimon);
4910 ": MII link monitoring set to %d ms\n",
4911 miimon);
4912 } else if (arp_interval) { 4804 } else if (arp_interval) {
4913 int i; 4805 int i;
4914 4806
4915 pr_info(DRV_NAME ": ARP monitoring set to %d ms," 4807 pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
4916 " validate %s, with %d target(s):", 4808 arp_interval,
4917 arp_interval, 4809 arp_validate_tbl[arp_validate_value].modename,
4918 arp_validate_tbl[arp_validate_value].modename, 4810 arp_ip_count);
4919 arp_ip_count);
4920 4811
4921 for (i = 0; i < arp_ip_count; i++) 4812 for (i = 0; i < arp_ip_count; i++)
4922 pr_info(" %s", arp_ip_target[i]); 4813 pr_info(" %s", arp_ip_target[i]);
@@ -4927,38 +4818,42 @@ static int bond_check_params(struct bond_params *params)
4927 /* miimon and arp_interval not set, we need one so things 4818 /* miimon and arp_interval not set, we need one so things
4928 * work as expected, see bonding.txt for details 4819 * work as expected, see bonding.txt for details
4929 */ 4820 */
4930 pr_warning(DRV_NAME 4821 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");
4931 ": Warning: either miimon or arp_interval and "
4932 "arp_ip_target module parameters must be specified, "
4933 "otherwise bonding will not detect link failures! see "
4934 "bonding.txt for details.\n");
4935 } 4822 }
4936 4823
4937 if (primary && !USES_PRIMARY(bond_mode)) { 4824 if (primary && !USES_PRIMARY(bond_mode)) {
4938 /* currently, using a primary only makes sense 4825 /* currently, using a primary only makes sense
4939 * in active backup, TLB or ALB modes 4826 * in active backup, TLB or ALB modes
4940 */ 4827 */
4941 pr_warning(DRV_NAME 4828 pr_warning("Warning: %s primary device specified but has no effect in %s mode\n",
4942 ": Warning: %s primary device specified but has no " 4829 primary, bond_mode_name(bond_mode));
4943 "effect in %s mode\n",
4944 primary, bond_mode_name(bond_mode));
4945 primary = NULL; 4830 primary = NULL;
4946 } 4831 }
4947 4832
4833 if (primary && primary_reselect) {
4834 primary_reselect_value = bond_parse_parm(primary_reselect,
4835 pri_reselect_tbl);
4836 if (primary_reselect_value == -1) {
4837 pr_err("Error: Invalid primary_reselect \"%s\"\n",
4838 primary_reselect ==
4839 NULL ? "NULL" : primary_reselect);
4840 return -EINVAL;
4841 }
4842 } else {
4843 primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
4844 }
4845
4948 if (fail_over_mac) { 4846 if (fail_over_mac) {
4949 fail_over_mac_value = bond_parse_parm(fail_over_mac, 4847 fail_over_mac_value = bond_parse_parm(fail_over_mac,
4950 fail_over_mac_tbl); 4848 fail_over_mac_tbl);
4951 if (fail_over_mac_value == -1) { 4849 if (fail_over_mac_value == -1) {
4952 pr_err(DRV_NAME 4850 pr_err("Error: invalid fail_over_mac \"%s\"\n",
4953 ": Error: invalid fail_over_mac \"%s\"\n",
4954 arp_validate == NULL ? "NULL" : arp_validate); 4851 arp_validate == NULL ? "NULL" : arp_validate);
4955 return -EINVAL; 4852 return -EINVAL;
4956 } 4853 }
4957 4854
4958 if (bond_mode != BOND_MODE_ACTIVEBACKUP) 4855 if (bond_mode != BOND_MODE_ACTIVEBACKUP)
4959 pr_warning(DRV_NAME 4856 pr_warning("Warning: fail_over_mac only affects active-backup mode.\n");
4960 ": Warning: fail_over_mac only affects "
4961 "active-backup mode.\n");
4962 } else { 4857 } else {
4963 fail_over_mac_value = BOND_FOM_NONE; 4858 fail_over_mac_value = BOND_FOM_NONE;
4964 } 4859 }
@@ -4976,6 +4871,7 @@ static int bond_check_params(struct bond_params *params)
4976 params->use_carrier = use_carrier; 4871 params->use_carrier = use_carrier;
4977 params->lacp_fast = lacp_fast; 4872 params->lacp_fast = lacp_fast;
4978 params->primary[0] = 0; 4873 params->primary[0] = 0;
4874 params->primary_reselect = primary_reselect_value;
4979 params->fail_over_mac = fail_over_mac_value; 4875 params->fail_over_mac = fail_over_mac_value;
4980 4876
4981 if (primary) { 4877 if (primary) {
@@ -5012,6 +4908,7 @@ static void bond_set_lockdep_class(struct net_device *dev)
5012static int bond_init(struct net_device *bond_dev) 4908static int bond_init(struct net_device *bond_dev)
5013{ 4909{
5014 struct bonding *bond = netdev_priv(bond_dev); 4910 struct bonding *bond = netdev_priv(bond_dev);
4911 struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
5015 4912
5016 pr_debug("Begin bond_init for %s\n", bond_dev->name); 4913 pr_debug("Begin bond_init for %s\n", bond_dev->name);
5017 4914
@@ -5024,68 +4921,94 @@ static int bond_init(struct net_device *bond_dev)
5024 netif_carrier_off(bond_dev); 4921 netif_carrier_off(bond_dev);
5025 4922
5026 bond_create_proc_entry(bond); 4923 bond_create_proc_entry(bond);
5027 list_add_tail(&bond->bond_list, &bond_dev_list); 4924 list_add_tail(&bond->bond_list, &bn->dev_list);
5028 4925
4926 bond_prepare_sysfs_group(bond);
4927 return 0;
4928}
4929
4930static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
4931{
4932 if (tb[IFLA_ADDRESS]) {
4933 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
4934 return -EINVAL;
4935 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
4936 return -EADDRNOTAVAIL;
4937 }
5029 return 0; 4938 return 0;
5030} 4939}
5031 4940
4941static struct rtnl_link_ops bond_link_ops __read_mostly = {
4942 .kind = "bond",
4943 .priv_size = sizeof(struct bonding),
4944 .setup = bond_setup,
4945 .validate = bond_validate,
4946};
4947
5032/* Create a new bond based on the specified name and bonding parameters. 4948/* Create a new bond based on the specified name and bonding parameters.
5033 * If name is NULL, obtain a suitable "bond%d" name for us. 4949 * If name is NULL, obtain a suitable "bond%d" name for us.
5034 * Caller must NOT hold rtnl_lock; we need to release it here before we 4950 * Caller must NOT hold rtnl_lock; we need to release it here before we
5035 * set up our sysfs entries. 4951 * set up our sysfs entries.
5036 */ 4952 */
5037int bond_create(const char *name) 4953int bond_create(struct net *net, const char *name)
5038{ 4954{
5039 struct net_device *bond_dev; 4955 struct net_device *bond_dev;
5040 int res; 4956 int res;
5041 4957
5042 rtnl_lock(); 4958 rtnl_lock();
5043 /* Check to see if the bond already exists. */
5044 /* FIXME: pass netns from caller */
5045 if (name && __dev_get_by_name(&init_net, name)) {
5046 pr_err(DRV_NAME ": cannot add bond %s; already exists\n",
5047 name);
5048 res = -EEXIST;
5049 goto out_rtnl;
5050 }
5051 4959
5052 bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "", 4960 bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "",
5053 bond_setup); 4961 bond_setup);
5054 if (!bond_dev) { 4962 if (!bond_dev) {
5055 pr_err(DRV_NAME ": %s: eek! can't alloc netdev!\n", 4963 pr_err("%s: eek! can't alloc netdev!\n", name);
5056 name); 4964 rtnl_unlock();
5057 res = -ENOMEM; 4965 return -ENOMEM;
5058 goto out_rtnl;
5059 } 4966 }
5060 4967
4968 dev_net_set(bond_dev, net);
4969 bond_dev->rtnl_link_ops = &bond_link_ops;
4970
5061 if (!name) { 4971 if (!name) {
5062 res = dev_alloc_name(bond_dev, "bond%d"); 4972 res = dev_alloc_name(bond_dev, "bond%d");
5063 if (res < 0) 4973 if (res < 0)
5064 goto out_netdev; 4974 goto out;
5065 } 4975 }
5066 4976
5067 res = register_netdevice(bond_dev); 4977 res = register_netdevice(bond_dev);
5068 if (res < 0)
5069 goto out_bond;
5070 4978
5071 res = bond_create_sysfs_entry(netdev_priv(bond_dev)); 4979out:
4980 rtnl_unlock();
5072 if (res < 0) 4981 if (res < 0)
5073 goto out_unreg; 4982 bond_destructor(bond_dev);
4983 return res;
4984}
5074 4985
5075 rtnl_unlock(); 4986static int __net_init bond_net_init(struct net *net)
4987{
4988 struct bond_net *bn = net_generic(net, bond_net_id);
4989
4990 bn->net = net;
4991 INIT_LIST_HEAD(&bn->dev_list);
4992
4993 bond_create_proc_dir(bn);
4994
5076 return 0; 4995 return 0;
4996}
5077 4997
5078out_unreg: 4998static void __net_exit bond_net_exit(struct net *net)
5079 unregister_netdevice(bond_dev); 4999{
5080out_bond: 5000 struct bond_net *bn = net_generic(net, bond_net_id);
5081 bond_deinit(bond_dev); 5001
5082out_netdev: 5002 bond_destroy_proc_dir(bn);
5083 free_netdev(bond_dev);
5084out_rtnl:
5085 rtnl_unlock();
5086 return res;
5087} 5003}
5088 5004
5005static struct pernet_operations bond_net_ops = {
5006 .init = bond_net_init,
5007 .exit = bond_net_exit,
5008 .id = &bond_net_id,
5009 .size = sizeof(struct bond_net),
5010};
5011
5089static int __init bonding_init(void) 5012static int __init bonding_init(void)
5090{ 5013{
5091 int i; 5014 int i;
@@ -5097,10 +5020,16 @@ static int __init bonding_init(void)
5097 if (res) 5020 if (res)
5098 goto out; 5021 goto out;
5099 5022
5100 bond_create_proc_dir(); 5023 res = register_pernet_subsys(&bond_net_ops);
5024 if (res)
5025 goto out;
5026
5027 res = rtnl_link_register(&bond_link_ops);
5028 if (res)
5029 goto err_link;
5101 5030
5102 for (i = 0; i < max_bonds; i++) { 5031 for (i = 0; i < max_bonds; i++) {
5103 res = bond_create(NULL); 5032 res = bond_create(&init_net, NULL);
5104 if (res) 5033 if (res)
5105 goto err; 5034 goto err;
5106 } 5035 }
@@ -5112,14 +5041,13 @@ static int __init bonding_init(void)
5112 register_netdevice_notifier(&bond_netdev_notifier); 5041 register_netdevice_notifier(&bond_netdev_notifier);
5113 register_inetaddr_notifier(&bond_inetaddr_notifier); 5042 register_inetaddr_notifier(&bond_inetaddr_notifier);
5114 bond_register_ipv6_notifier(); 5043 bond_register_ipv6_notifier();
5115
5116 goto out;
5117err:
5118 rtnl_lock();
5119 bond_free_all();
5120 rtnl_unlock();
5121out: 5044out:
5122 return res; 5045 return res;
5046err:
5047 rtnl_link_unregister(&bond_link_ops);
5048err_link:
5049 unregister_pernet_subsys(&bond_net_ops);
5050 goto out;
5123 5051
5124} 5052}
5125 5053
@@ -5131,9 +5059,8 @@ static void __exit bonding_exit(void)
5131 5059
5132 bond_destroy_sysfs(); 5060 bond_destroy_sysfs();
5133 5061
5134 rtnl_lock(); 5062 rtnl_link_unregister(&bond_link_ops);
5135 bond_free_all(); 5063 unregister_pernet_subsys(&bond_net_ops);
5136 rtnl_unlock();
5137} 5064}
5138 5065
5139module_init(bonding_init); 5066module_init(bonding_init);
@@ -5142,3 +5069,4 @@ MODULE_LICENSE("GPL");
5142MODULE_VERSION(DRV_VERSION); 5069MODULE_VERSION(DRV_VERSION);
5143MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION); 5070MODULE_DESCRIPTION(DRV_DESCRIPTION ", v" DRV_VERSION);
5144MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others"); 5071MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");
5072MODULE_ALIAS_RTNL_LINK("bond");