aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/bonding
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/bonding')
-rw-r--r--drivers/net/bonding/bond_3ad.c294
-rw-r--r--drivers/net/bonding/bond_alb.c43
-rw-r--r--drivers/net/bonding/bond_ipv6.c19
-rw-r--r--drivers/net/bonding/bond_main.c978
-rw-r--r--drivers/net/bonding/bond_sysfs.c418
-rw-r--r--drivers/net/bonding/bonding.h36
6 files changed, 848 insertions, 940 deletions
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index c3fa31c9f2a7..822f586d72af 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -20,6 +20,8 @@
20 * 20 *
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/skbuff.h> 25#include <linux/skbuff.h>
24#include <linux/if_ether.h> 26#include <linux/if_ether.h>
25#include <linux/netdevice.h> 27#include <linux/netdevice.h>
@@ -352,7 +354,8 @@ static u16 __get_link_speed(struct port *port)
352 } 354 }
353 } 355 }
354 356
355 pr_debug("Port %d Received link speed %d update from adapter\n", port->actor_port_number, speed); 357 pr_debug("Port %d Received link speed %d update from adapter\n",
358 port->actor_port_number, speed);
356 return speed; 359 return speed;
357} 360}
358 361
@@ -378,12 +381,14 @@ static u8 __get_duplex(struct port *port)
378 switch (slave->duplex) { 381 switch (slave->duplex) {
379 case DUPLEX_FULL: 382 case DUPLEX_FULL:
380 retval=0x1; 383 retval=0x1;
381 pr_debug("Port %d Received status full duplex update from adapter\n", port->actor_port_number); 384 pr_debug("Port %d Received status full duplex update from adapter\n",
385 port->actor_port_number);
382 break; 386 break;
383 case DUPLEX_HALF: 387 case DUPLEX_HALF:
384 default: 388 default:
385 retval=0x0; 389 retval=0x0;
386 pr_debug("Port %d Received status NOT full duplex update from adapter\n", port->actor_port_number); 390 pr_debug("Port %d Received status NOT full duplex update from adapter\n",
391 port->actor_port_number);
387 break; 392 break;
388 } 393 }
389 } 394 }
@@ -446,6 +451,48 @@ static u16 __ad_timer_to_ticks(u16 timer_type, u16 par)
446///////////////////////////////////////////////////////////////////////////////// 451/////////////////////////////////////////////////////////////////////////////////
447 452
448/** 453/**
454 * __choose_matched - update a port's matched variable from a received lacpdu
455 * @lacpdu: the lacpdu we've received
456 * @port: the port we're looking at
457 *
458 * Update the value of the matched variable, using parameter values from a
459 * newly received lacpdu. Parameter values for the partner carried in the
460 * received PDU are compared with the corresponding operational parameter
461 * values for the actor. Matched is set to TRUE if all of these parameters
462 * match and the PDU parameter partner_state.aggregation has the same value as
463 * actor_oper_port_state.aggregation and lacp will actively maintain the link
464 * in the aggregation. Matched is also set to TRUE if the value of
465 * actor_state.aggregation in the received PDU is set to FALSE, i.e., indicates
466 * an individual link and lacp will actively maintain the link. Otherwise,
467 * matched is set to FALSE. LACP is considered to be actively maintaining the
468 * link if either the PDU's actor_state.lacp_activity variable is TRUE or both
469 * the actor's actor_oper_port_state.lacp_activity and the PDU's
470 * partner_state.lacp_activity variables are TRUE.
471 *
472 * Note: the AD_PORT_MATCHED "variable" is not specified by 802.3ad; it is
473 * used here to implement the language from 802.3ad 43.4.9 that requires
474 * recordPDU to "match" the LACPDU parameters to the stored values.
475 */
476static void __choose_matched(struct lacpdu *lacpdu, struct port *port)
477{
478 // check if all parameters are alike
479 if (((ntohs(lacpdu->partner_port) == port->actor_port_number) &&
480 (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) &&
481 !MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) &&
482 (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) &&
483 (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) &&
484 ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) ||
485 // or this is individual link(aggregation == FALSE)
486 ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0)
487 ) {
488 // update the state machine Matched variable
489 port->sm_vars |= AD_PORT_MATCHED;
490 } else {
491 port->sm_vars &= ~AD_PORT_MATCHED;
492 }
493}
494
495/**
449 * __record_pdu - record parameters from a received lacpdu 496 * __record_pdu - record parameters from a received lacpdu
450 * @lacpdu: the lacpdu we've received 497 * @lacpdu: the lacpdu we've received
451 * @port: the port we're looking at 498 * @port: the port we're looking at
@@ -459,6 +506,7 @@ static void __record_pdu(struct lacpdu *lacpdu, struct port *port)
459 if (lacpdu && port) { 506 if (lacpdu && port) {
460 struct port_params *partner = &port->partner_oper; 507 struct port_params *partner = &port->partner_oper;
461 508
509 __choose_matched(lacpdu, port);
462 // record the new parameter values for the partner operational 510 // record the new parameter values for the partner operational
463 partner->port_number = ntohs(lacpdu->actor_port); 511 partner->port_number = ntohs(lacpdu->actor_port);
464 partner->port_priority = ntohs(lacpdu->actor_port_priority); 512 partner->port_priority = ntohs(lacpdu->actor_port_priority);
@@ -518,12 +566,12 @@ static void __update_selected(struct lacpdu *lacpdu, struct port *port)
518 const struct port_params *partner = &port->partner_oper; 566 const struct port_params *partner = &port->partner_oper;
519 567
520 // check if any parameter is different 568 // check if any parameter is different
521 if (ntohs(lacpdu->actor_port) != partner->port_number 569 if (ntohs(lacpdu->actor_port) != partner->port_number ||
522 || ntohs(lacpdu->actor_port_priority) != partner->port_priority 570 ntohs(lacpdu->actor_port_priority) != partner->port_priority ||
523 || MAC_ADDRESS_COMPARE(&lacpdu->actor_system, &partner->system) 571 MAC_ADDRESS_COMPARE(&lacpdu->actor_system, &partner->system) ||
524 || ntohs(lacpdu->actor_system_priority) != partner->system_priority 572 ntohs(lacpdu->actor_system_priority) != partner->system_priority ||
525 || ntohs(lacpdu->actor_key) != partner->key 573 ntohs(lacpdu->actor_key) != partner->key ||
526 || (lacpdu->actor_state & AD_STATE_AGGREGATION) != (partner->port_state & AD_STATE_AGGREGATION)) { 574 (lacpdu->actor_state & AD_STATE_AGGREGATION) != (partner->port_state & AD_STATE_AGGREGATION)) {
527 // update the state machine Selected variable 575 // update the state machine Selected variable
528 port->sm_vars &= ~AD_PORT_SELECTED; 576 port->sm_vars &= ~AD_PORT_SELECTED;
529 } 577 }
@@ -549,12 +597,12 @@ static void __update_default_selected(struct port *port)
549 const struct port_params *oper = &port->partner_oper; 597 const struct port_params *oper = &port->partner_oper;
550 598
551 // check if any parameter is different 599 // check if any parameter is different
552 if (admin->port_number != oper->port_number 600 if (admin->port_number != oper->port_number ||
553 || admin->port_priority != oper->port_priority 601 admin->port_priority != oper->port_priority ||
554 || MAC_ADDRESS_COMPARE(&admin->system, &oper->system) 602 MAC_ADDRESS_COMPARE(&admin->system, &oper->system) ||
555 || admin->system_priority != oper->system_priority 603 admin->system_priority != oper->system_priority ||
556 || admin->key != oper->key 604 admin->key != oper->key ||
557 || (admin->port_state & AD_STATE_AGGREGATION) 605 (admin->port_state & AD_STATE_AGGREGATION)
558 != (oper->port_state & AD_STATE_AGGREGATION)) { 606 != (oper->port_state & AD_STATE_AGGREGATION)) {
559 // update the state machine Selected variable 607 // update the state machine Selected variable
560 port->sm_vars &= ~AD_PORT_SELECTED; 608 port->sm_vars &= ~AD_PORT_SELECTED;
@@ -563,47 +611,6 @@ static void __update_default_selected(struct port *port)
563} 611}
564 612
565/** 613/**
566 * __choose_matched - update a port's matched variable from a received lacpdu
567 * @lacpdu: the lacpdu we've received
568 * @port: the port we're looking at
569 *
570 * Update the value of the matched variable, using parameter values from a
571 * newly received lacpdu. Parameter values for the partner carried in the
572 * received PDU are compared with the corresponding operational parameter
573 * values for the actor. Matched is set to TRUE if all of these parameters
574 * match and the PDU parameter partner_state.aggregation has the same value as
575 * actor_oper_port_state.aggregation and lacp will actively maintain the link
576 * in the aggregation. Matched is also set to TRUE if the value of
577 * actor_state.aggregation in the received PDU is set to FALSE, i.e., indicates
578 * an individual link and lacp will actively maintain the link. Otherwise,
579 * matched is set to FALSE. LACP is considered to be actively maintaining the
580 * link if either the PDU's actor_state.lacp_activity variable is TRUE or both
581 * the actor's actor_oper_port_state.lacp_activity and the PDU's
582 * partner_state.lacp_activity variables are TRUE.
583 */
584static void __choose_matched(struct lacpdu *lacpdu, struct port *port)
585{
586 // validate lacpdu and port
587 if (lacpdu && port) {
588 // check if all parameters are alike
589 if (((ntohs(lacpdu->partner_port) == port->actor_port_number) &&
590 (ntohs(lacpdu->partner_port_priority) == port->actor_port_priority) &&
591 !MAC_ADDRESS_COMPARE(&(lacpdu->partner_system), &(port->actor_system)) &&
592 (ntohs(lacpdu->partner_system_priority) == port->actor_system_priority) &&
593 (ntohs(lacpdu->partner_key) == port->actor_oper_port_key) &&
594 ((lacpdu->partner_state & AD_STATE_AGGREGATION) == (port->actor_oper_port_state & AD_STATE_AGGREGATION))) ||
595 // or this is individual link(aggregation == FALSE)
596 ((lacpdu->actor_state & AD_STATE_AGGREGATION) == 0)
597 ) {
598 // update the state machine Matched variable
599 port->sm_vars |= AD_PORT_MATCHED;
600 } else {
601 port->sm_vars &= ~AD_PORT_MATCHED;
602 }
603 }
604}
605
606/**
607 * __update_ntt - update a port's ntt variable from a received lacpdu 614 * __update_ntt - update a port's ntt variable from a received lacpdu
608 * @lacpdu: the lacpdu we've received 615 * @lacpdu: the lacpdu we've received
609 * @port: the port we're looking at 616 * @port: the port we're looking at
@@ -978,7 +985,9 @@ static void ad_mux_machine(struct port *port)
978 985
979 // check if the state machine was changed 986 // check if the state machine was changed
980 if (port->sm_mux_state != last_state) { 987 if (port->sm_mux_state != last_state) {
981 pr_debug("Mux Machine: Port=%d, Last State=%d, Curr State=%d\n", port->actor_port_number, last_state, port->sm_mux_state); 988 pr_debug("Mux Machine: Port=%d, Last State=%d, Curr State=%d\n",
989 port->actor_port_number, last_state,
990 port->sm_mux_state);
982 switch (port->sm_mux_state) { 991 switch (port->sm_mux_state) {
983 case AD_MUX_DETACHED: 992 case AD_MUX_DETACHED:
984 __detach_bond_from_agg(port); 993 __detach_bond_from_agg(port);
@@ -1077,7 +1086,9 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
1077 1086
1078 // check if the State machine was changed or new lacpdu arrived 1087 // check if the State machine was changed or new lacpdu arrived
1079 if ((port->sm_rx_state != last_state) || (lacpdu)) { 1088 if ((port->sm_rx_state != last_state) || (lacpdu)) {
1080 pr_debug("Rx Machine: Port=%d, Last State=%d, Curr State=%d\n", port->actor_port_number, last_state, port->sm_rx_state); 1089 pr_debug("Rx Machine: Port=%d, Last State=%d, Curr State=%d\n",
1090 port->actor_port_number, last_state,
1091 port->sm_rx_state);
1081 switch (port->sm_rx_state) { 1092 switch (port->sm_rx_state) {
1082 case AD_RX_INITIALIZE: 1093 case AD_RX_INITIALIZE:
1083 if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_BITS)) { 1094 if (!(port->actor_oper_port_key & AD_DUPLEX_KEY_BITS)) {
@@ -1124,9 +1135,8 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
1124 // detect loopback situation 1135 // detect loopback situation
1125 if (!MAC_ADDRESS_COMPARE(&(lacpdu->actor_system), &(port->actor_system))) { 1136 if (!MAC_ADDRESS_COMPARE(&(lacpdu->actor_system), &(port->actor_system))) {
1126 // INFO_RECEIVED_LOOPBACK_FRAMES 1137 // INFO_RECEIVED_LOOPBACK_FRAMES
1127 pr_err(DRV_NAME ": %s: An illegal loopback occurred on " 1138 pr_err("%s: An illegal loopback occurred on adapter (%s).\n"
1128 "adapter (%s). Check the configuration to verify that all " 1139 "Check the configuration to verify that all adapters are connected to 802.3ad compliant switch ports\n",
1129 "Adapters are connected to 802.3ad compliant switch ports\n",
1130 port->slave->dev->master->name, port->slave->dev->name); 1140 port->slave->dev->master->name, port->slave->dev->name);
1131 __release_rx_machine_lock(port); 1141 __release_rx_machine_lock(port);
1132 return; 1142 return;
@@ -1134,7 +1144,6 @@ static void ad_rx_machine(struct lacpdu *lacpdu, struct port *port)
1134 __update_selected(lacpdu, port); 1144 __update_selected(lacpdu, port);
1135 __update_ntt(lacpdu, port); 1145 __update_ntt(lacpdu, port);
1136 __record_pdu(lacpdu, port); 1146 __record_pdu(lacpdu, port);
1137 __choose_matched(lacpdu, port);
1138 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT)); 1147 port->sm_rx_timer_counter = __ad_timer_to_ticks(AD_CURRENT_WHILE_TIMER, (u16)(port->actor_oper_port_state & AD_STATE_LACP_TIMEOUT));
1139 port->actor_oper_port_state &= ~AD_STATE_EXPIRED; 1148 port->actor_oper_port_state &= ~AD_STATE_EXPIRED;
1140 // verify that if the aggregator is enabled, the port is enabled too. 1149 // verify that if the aggregator is enabled, the port is enabled too.
@@ -1165,7 +1174,8 @@ static void ad_tx_machine(struct port *port)
1165 __update_lacpdu_from_port(port); 1174 __update_lacpdu_from_port(port);
1166 1175
1167 if (ad_lacpdu_send(port) >= 0) { 1176 if (ad_lacpdu_send(port) >= 0) {
1168 pr_debug("Sent LACPDU on port %d\n", port->actor_port_number); 1177 pr_debug("Sent LACPDU on port %d\n",
1178 port->actor_port_number);
1169 1179
1170 /* mark ntt as false, so it will not be sent again until 1180 /* mark ntt as false, so it will not be sent again until
1171 demanded */ 1181 demanded */
@@ -1240,7 +1250,9 @@ static void ad_periodic_machine(struct port *port)
1240 1250
1241 // check if the state machine was changed 1251 // check if the state machine was changed
1242 if (port->sm_periodic_state != last_state) { 1252 if (port->sm_periodic_state != last_state) {
1243 pr_debug("Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n", port->actor_port_number, last_state, port->sm_periodic_state); 1253 pr_debug("Periodic Machine: Port=%d, Last State=%d, Curr State=%d\n",
1254 port->actor_port_number, last_state,
1255 port->sm_periodic_state);
1244 switch (port->sm_periodic_state) { 1256 switch (port->sm_periodic_state) {
1245 case AD_NO_PERIODIC: 1257 case AD_NO_PERIODIC:
1246 port->sm_periodic_timer_counter = 0; // zero timer 1258 port->sm_periodic_timer_counter = 0; // zero timer
@@ -1297,7 +1309,9 @@ static void ad_port_selection_logic(struct port *port)
1297 port->next_port_in_aggregator=NULL; 1309 port->next_port_in_aggregator=NULL;
1298 port->actor_port_aggregator_identifier=0; 1310 port->actor_port_aggregator_identifier=0;
1299 1311
1300 pr_debug("Port %d left LAG %d\n", port->actor_port_number, temp_aggregator->aggregator_identifier); 1312 pr_debug("Port %d left LAG %d\n",
1313 port->actor_port_number,
1314 temp_aggregator->aggregator_identifier);
1301 // if the aggregator is empty, clear its parameters, and set it ready to be attached 1315 // if the aggregator is empty, clear its parameters, and set it ready to be attached
1302 if (!temp_aggregator->lag_ports) { 1316 if (!temp_aggregator->lag_ports) {
1303 ad_clear_agg(temp_aggregator); 1317 ad_clear_agg(temp_aggregator);
@@ -1306,9 +1320,7 @@ static void ad_port_selection_logic(struct port *port)
1306 } 1320 }
1307 } 1321 }
1308 if (!curr_port) { // meaning: the port was related to an aggregator but was not on the aggregator port list 1322 if (!curr_port) { // meaning: the port was related to an aggregator but was not on the aggregator port list
1309 pr_warning(DRV_NAME ": %s: Warning: Port %d (on %s) " 1323 pr_warning("%s: Warning: Port %d (on %s) was related to aggregator %d but was not on its port list\n",
1310 "was related to aggregator %d but was not "
1311 "on its port list\n",
1312 port->slave->dev->master->name, 1324 port->slave->dev->master->name,
1313 port->actor_port_number, 1325 port->actor_port_number,
1314 port->slave->dev->name, 1326 port->slave->dev->name,
@@ -1342,7 +1354,9 @@ static void ad_port_selection_logic(struct port *port)
1342 port->next_port_in_aggregator=aggregator->lag_ports; 1354 port->next_port_in_aggregator=aggregator->lag_ports;
1343 port->aggregator->num_of_ports++; 1355 port->aggregator->num_of_ports++;
1344 aggregator->lag_ports=port; 1356 aggregator->lag_ports=port;
1345 pr_debug("Port %d joined LAG %d(existing LAG)\n", port->actor_port_number, port->aggregator->aggregator_identifier); 1357 pr_debug("Port %d joined LAG %d(existing LAG)\n",
1358 port->actor_port_number,
1359 port->aggregator->aggregator_identifier);
1346 1360
1347 // mark this port as selected 1361 // mark this port as selected
1348 port->sm_vars |= AD_PORT_SELECTED; 1362 port->sm_vars |= AD_PORT_SELECTED;
@@ -1379,10 +1393,11 @@ static void ad_port_selection_logic(struct port *port)
1379 // mark this port as selected 1393 // mark this port as selected
1380 port->sm_vars |= AD_PORT_SELECTED; 1394 port->sm_vars |= AD_PORT_SELECTED;
1381 1395
1382 pr_debug("Port %d joined LAG %d(new LAG)\n", port->actor_port_number, port->aggregator->aggregator_identifier); 1396 pr_debug("Port %d joined LAG %d(new LAG)\n",
1397 port->actor_port_number,
1398 port->aggregator->aggregator_identifier);
1383 } else { 1399 } else {
1384 pr_err(DRV_NAME ": %s: Port %d (on %s) did not find " 1400 pr_err("%s: Port %d (on %s) did not find a suitable aggregator\n",
1385 "a suitable aggregator\n",
1386 port->slave->dev->master->name, 1401 port->slave->dev->master->name,
1387 port->actor_port_number, port->slave->dev->name); 1402 port->actor_port_number, port->slave->dev->name);
1388 } 1403 }
@@ -1459,8 +1474,7 @@ static struct aggregator *ad_agg_selection_test(struct aggregator *best,
1459 break; 1474 break;
1460 1475
1461 default: 1476 default:
1462 pr_warning(DRV_NAME 1477 pr_warning("%s: Impossible agg select mode %d\n",
1463 ": %s: Impossible agg select mode %d\n",
1464 curr->slave->dev->master->name, 1478 curr->slave->dev->master->name,
1465 __get_agg_selection_mode(curr->lag_ports)); 1479 __get_agg_selection_mode(curr->lag_ports));
1466 break; 1480 break;
@@ -1545,40 +1559,38 @@ static void ad_agg_selection_logic(struct aggregator *agg)
1545 // if there is new best aggregator, activate it 1559 // if there is new best aggregator, activate it
1546 if (best) { 1560 if (best) {
1547 pr_debug("best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", 1561 pr_debug("best Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
1548 best->aggregator_identifier, best->num_of_ports, 1562 best->aggregator_identifier, best->num_of_ports,
1549 best->actor_oper_aggregator_key, 1563 best->actor_oper_aggregator_key,
1550 best->partner_oper_aggregator_key, 1564 best->partner_oper_aggregator_key,
1551 best->is_individual, best->is_active); 1565 best->is_individual, best->is_active);
1552 pr_debug("best ports %p slave %p %s\n", 1566 pr_debug("best ports %p slave %p %s\n",
1553 best->lag_ports, best->slave, 1567 best->lag_ports, best->slave,
1554 best->slave ? best->slave->dev->name : "NULL"); 1568 best->slave ? best->slave->dev->name : "NULL");
1555 1569
1556 for (agg = __get_first_agg(best->lag_ports); agg; 1570 for (agg = __get_first_agg(best->lag_ports); agg;
1557 agg = __get_next_agg(agg)) { 1571 agg = __get_next_agg(agg)) {
1558 1572
1559 pr_debug("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", 1573 pr_debug("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
1560 agg->aggregator_identifier, agg->num_of_ports, 1574 agg->aggregator_identifier, agg->num_of_ports,
1561 agg->actor_oper_aggregator_key, 1575 agg->actor_oper_aggregator_key,
1562 agg->partner_oper_aggregator_key, 1576 agg->partner_oper_aggregator_key,
1563 agg->is_individual, agg->is_active); 1577 agg->is_individual, agg->is_active);
1564 } 1578 }
1565 1579
1566 // check if any partner replys 1580 // check if any partner replys
1567 if (best->is_individual) { 1581 if (best->is_individual) {
1568 pr_warning(DRV_NAME ": %s: Warning: No 802.3ad" 1582 pr_warning("%s: Warning: No 802.3ad response from the link partner for any adapters in the bond\n",
1569 " response from the link partner for any" 1583 best->slave ? best->slave->dev->master->name : "NULL");
1570 " adapters in the bond\n",
1571 best->slave->dev->master->name);
1572 } 1584 }
1573 1585
1574 best->is_active = 1; 1586 best->is_active = 1;
1575 pr_debug("LAG %d chosen as the active LAG\n", 1587 pr_debug("LAG %d chosen as the active LAG\n",
1576 best->aggregator_identifier); 1588 best->aggregator_identifier);
1577 pr_debug("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n", 1589 pr_debug("Agg=%d; P=%d; a k=%d; p k=%d; Ind=%d; Act=%d\n",
1578 best->aggregator_identifier, best->num_of_ports, 1590 best->aggregator_identifier, best->num_of_ports,
1579 best->actor_oper_aggregator_key, 1591 best->actor_oper_aggregator_key,
1580 best->partner_oper_aggregator_key, 1592 best->partner_oper_aggregator_key,
1581 best->is_individual, best->is_active); 1593 best->is_individual, best->is_active);
1582 1594
1583 // disable the ports that were related to the former active_aggregator 1595 // disable the ports that were related to the former active_aggregator
1584 if (active) { 1596 if (active) {
@@ -1632,7 +1644,8 @@ static void ad_clear_agg(struct aggregator *aggregator)
1632 aggregator->lag_ports = NULL; 1644 aggregator->lag_ports = NULL;
1633 aggregator->is_active = 0; 1645 aggregator->is_active = 0;
1634 aggregator->num_of_ports = 0; 1646 aggregator->num_of_ports = 0;
1635 pr_debug("LAG %d was cleared\n", aggregator->aggregator_identifier); 1647 pr_debug("LAG %d was cleared\n",
1648 aggregator->aggregator_identifier);
1636 } 1649 }
1637} 1650}
1638 1651
@@ -1727,7 +1740,9 @@ static void ad_initialize_port(struct port *port, int lacp_fast)
1727static void ad_enable_collecting_distributing(struct port *port) 1740static void ad_enable_collecting_distributing(struct port *port)
1728{ 1741{
1729 if (port->aggregator->is_active) { 1742 if (port->aggregator->is_active) {
1730 pr_debug("Enabling port %d(LAG %d)\n", port->actor_port_number, port->aggregator->aggregator_identifier); 1743 pr_debug("Enabling port %d(LAG %d)\n",
1744 port->actor_port_number,
1745 port->aggregator->aggregator_identifier);
1731 __enable_port(port); 1746 __enable_port(port);
1732 } 1747 }
1733} 1748}
@@ -1740,7 +1755,9 @@ static void ad_enable_collecting_distributing(struct port *port)
1740static void ad_disable_collecting_distributing(struct port *port) 1755static void ad_disable_collecting_distributing(struct port *port)
1741{ 1756{
1742 if (port->aggregator && MAC_ADDRESS_COMPARE(&(port->aggregator->partner_system), &(null_mac_addr))) { 1757 if (port->aggregator && MAC_ADDRESS_COMPARE(&(port->aggregator->partner_system), &(null_mac_addr))) {
1743 pr_debug("Disabling port %d(LAG %d)\n", port->actor_port_number, port->aggregator->aggregator_identifier); 1758 pr_debug("Disabling port %d(LAG %d)\n",
1759 port->actor_port_number,
1760 port->aggregator->aggregator_identifier);
1744 __disable_port(port); 1761 __disable_port(port);
1745 } 1762 }
1746} 1763}
@@ -1778,7 +1795,8 @@ static void ad_marker_info_send(struct port *port)
1778 1795
1779 // send the marker information 1796 // send the marker information
1780 if (ad_marker_send(port, &marker) >= 0) { 1797 if (ad_marker_send(port, &marker) >= 0) {
1781 pr_debug("Sent Marker Information on port %d\n", port->actor_port_number); 1798 pr_debug("Sent Marker Information on port %d\n",
1799 port->actor_port_number);
1782 } 1800 }
1783} 1801}
1784#endif 1802#endif
@@ -1802,7 +1820,8 @@ static void ad_marker_info_received(struct bond_marker *marker_info,
1802 // send the marker response 1820 // send the marker response
1803 1821
1804 if (ad_marker_send(port, &marker) >= 0) { 1822 if (ad_marker_send(port, &marker) >= 0) {
1805 pr_debug("Sent Marker Response on port %d\n", port->actor_port_number); 1823 pr_debug("Sent Marker Response on port %d\n",
1824 port->actor_port_number);
1806 } 1825 }
1807} 1826}
1808 1827
@@ -1888,8 +1907,7 @@ int bond_3ad_bind_slave(struct slave *slave)
1888 struct aggregator *aggregator; 1907 struct aggregator *aggregator;
1889 1908
1890 if (bond == NULL) { 1909 if (bond == NULL) {
1891 pr_err(DRV_NAME ": %s: The slave %s is not attached to " 1910 pr_err("%s: The slave %s is not attached to its bond\n",
1892 "its bond\n",
1893 slave->dev->master->name, slave->dev->name); 1911 slave->dev->master->name, slave->dev->name);
1894 return -1; 1912 return -1;
1895 } 1913 }
@@ -1956,7 +1974,7 @@ void bond_3ad_unbind_slave(struct slave *slave)
1956 struct port *port, *prev_port, *temp_port; 1974 struct port *port, *prev_port, *temp_port;
1957 struct aggregator *aggregator, *new_aggregator, *temp_aggregator; 1975 struct aggregator *aggregator, *new_aggregator, *temp_aggregator;
1958 int select_new_active_agg = 0; 1976 int select_new_active_agg = 0;
1959 1977
1960 // find the aggregator related to this slave 1978 // find the aggregator related to this slave
1961 aggregator = &(SLAVE_AD_INFO(slave).aggregator); 1979 aggregator = &(SLAVE_AD_INFO(slave).aggregator);
1962 1980
@@ -1965,13 +1983,13 @@ void bond_3ad_unbind_slave(struct slave *slave)
1965 1983
1966 // if slave is null, the whole port is not initialized 1984 // if slave is null, the whole port is not initialized
1967 if (!port->slave) { 1985 if (!port->slave) {
1968 pr_warning(DRV_NAME ": Warning: %s: Trying to " 1986 pr_warning("Warning: %s: Trying to unbind an uninitialized port on %s\n",
1969 "unbind an uninitialized port on %s\n",
1970 slave->dev->master->name, slave->dev->name); 1987 slave->dev->master->name, slave->dev->name);
1971 return; 1988 return;
1972 } 1989 }
1973 1990
1974 pr_debug("Unbinding Link Aggregation Group %d\n", aggregator->aggregator_identifier); 1991 pr_debug("Unbinding Link Aggregation Group %d\n",
1992 aggregator->aggregator_identifier);
1975 1993
1976 /* Tell the partner that this port is not suitable for aggregation */ 1994 /* Tell the partner that this port is not suitable for aggregation */
1977 port->actor_oper_port_state &= ~AD_STATE_AGGREGATION; 1995 port->actor_oper_port_state &= ~AD_STATE_AGGREGATION;
@@ -1995,10 +2013,12 @@ void bond_3ad_unbind_slave(struct slave *slave)
1995 // if new aggregator found, copy the aggregator's parameters 2013 // if new aggregator found, copy the aggregator's parameters
1996 // and connect the related lag_ports to the new aggregator 2014 // and connect the related lag_ports to the new aggregator
1997 if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) { 2015 if ((new_aggregator) && ((!new_aggregator->lag_ports) || ((new_aggregator->lag_ports == port) && !new_aggregator->lag_ports->next_port_in_aggregator))) {
1998 pr_debug("Some port(s) related to LAG %d - replaceing with LAG %d\n", aggregator->aggregator_identifier, new_aggregator->aggregator_identifier); 2016 pr_debug("Some port(s) related to LAG %d - replaceing with LAG %d\n",
2017 aggregator->aggregator_identifier,
2018 new_aggregator->aggregator_identifier);
1999 2019
2000 if ((new_aggregator->lag_ports == port) && new_aggregator->is_active) { 2020 if ((new_aggregator->lag_ports == port) && new_aggregator->is_active) {
2001 pr_info(DRV_NAME ": %s: Removing an active aggregator\n", 2021 pr_info("%s: Removing an active aggregator\n",
2002 aggregator->slave->dev->master->name); 2022 aggregator->slave->dev->master->name);
2003 // select new active aggregator 2023 // select new active aggregator
2004 select_new_active_agg = 1; 2024 select_new_active_agg = 1;
@@ -2024,13 +2044,12 @@ void bond_3ad_unbind_slave(struct slave *slave)
2024 2044
2025 // clear the aggregator 2045 // clear the aggregator
2026 ad_clear_agg(aggregator); 2046 ad_clear_agg(aggregator);
2027 2047
2028 if (select_new_active_agg) { 2048 if (select_new_active_agg) {
2029 ad_agg_selection_logic(__get_first_agg(port)); 2049 ad_agg_selection_logic(__get_first_agg(port));
2030 } 2050 }
2031 } else { 2051 } else {
2032 pr_warning(DRV_NAME ": %s: Warning: unbinding aggregator, " 2052 pr_warning("%s: Warning: unbinding aggregator, and could not find a new aggregator for its ports\n",
2033 "and could not find a new aggregator for its ports\n",
2034 slave->dev->master->name); 2053 slave->dev->master->name);
2035 } 2054 }
2036 } else { // in case that the only port related to this aggregator is the one we want to remove 2055 } else { // in case that the only port related to this aggregator is the one we want to remove
@@ -2038,7 +2057,7 @@ void bond_3ad_unbind_slave(struct slave *slave)
2038 // clear the aggregator 2057 // clear the aggregator
2039 ad_clear_agg(aggregator); 2058 ad_clear_agg(aggregator);
2040 if (select_new_active_agg) { 2059 if (select_new_active_agg) {
2041 pr_info(DRV_NAME ": %s: Removing an active aggregator\n", 2060 pr_info("%s: Removing an active aggregator\n",
2042 slave->dev->master->name); 2061 slave->dev->master->name);
2043 // select new active aggregator 2062 // select new active aggregator
2044 ad_agg_selection_logic(__get_first_agg(port)); 2063 ad_agg_selection_logic(__get_first_agg(port));
@@ -2065,7 +2084,7 @@ void bond_3ad_unbind_slave(struct slave *slave)
2065 // clear the aggregator 2084 // clear the aggregator
2066 ad_clear_agg(temp_aggregator); 2085 ad_clear_agg(temp_aggregator);
2067 if (select_new_active_agg) { 2086 if (select_new_active_agg) {
2068 pr_info(DRV_NAME ": %s: Removing an active aggregator\n", 2087 pr_info("%s: Removing an active aggregator\n",
2069 slave->dev->master->name); 2088 slave->dev->master->name);
2070 // select new active aggregator 2089 // select new active aggregator
2071 ad_agg_selection_logic(__get_first_agg(port)); 2090 ad_agg_selection_logic(__get_first_agg(port));
@@ -2075,7 +2094,7 @@ void bond_3ad_unbind_slave(struct slave *slave)
2075 } 2094 }
2076 } 2095 }
2077 } 2096 }
2078 port->slave=NULL; 2097 port->slave=NULL;
2079} 2098}
2080 2099
2081/** 2100/**
@@ -2114,8 +2133,8 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2114 // select the active aggregator for the bond 2133 // select the active aggregator for the bond
2115 if ((port = __get_first_port(bond))) { 2134 if ((port = __get_first_port(bond))) {
2116 if (!port->slave) { 2135 if (!port->slave) {
2117 pr_warning(DRV_NAME ": %s: Warning: bond's first port is " 2136 pr_warning("%s: Warning: bond's first port is uninitialized\n",
2118 "uninitialized\n", bond->dev->name); 2137 bond->dev->name);
2119 goto re_arm; 2138 goto re_arm;
2120 } 2139 }
2121 2140
@@ -2128,8 +2147,8 @@ void bond_3ad_state_machine_handler(struct work_struct *work)
2128 // for each port run the state machines 2147 // for each port run the state machines
2129 for (port = __get_first_port(bond); port; port = __get_next_port(port)) { 2148 for (port = __get_first_port(bond); port; port = __get_next_port(port)) {
2130 if (!port->slave) { 2149 if (!port->slave) {
2131 pr_warning(DRV_NAME ": %s: Warning: Found an uninitialized " 2150 pr_warning("%s: Warning: Found an uninitialized port\n",
2132 "port\n", bond->dev->name); 2151 bond->dev->name);
2133 goto re_arm; 2152 goto re_arm;
2134 } 2153 }
2135 2154
@@ -2170,15 +2189,15 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
2170 port = &(SLAVE_AD_INFO(slave).port); 2189 port = &(SLAVE_AD_INFO(slave).port);
2171 2190
2172 if (!port->slave) { 2191 if (!port->slave) {
2173 pr_warning(DRV_NAME ": %s: Warning: port of slave %s " 2192 pr_warning("%s: Warning: port of slave %s is uninitialized\n",
2174 "is uninitialized\n",
2175 slave->dev->name, slave->dev->master->name); 2193 slave->dev->name, slave->dev->master->name);
2176 return; 2194 return;
2177 } 2195 }
2178 2196
2179 switch (lacpdu->subtype) { 2197 switch (lacpdu->subtype) {
2180 case AD_TYPE_LACPDU: 2198 case AD_TYPE_LACPDU:
2181 pr_debug("Received LACPDU on port %d\n", port->actor_port_number); 2199 pr_debug("Received LACPDU on port %d\n",
2200 port->actor_port_number);
2182 ad_rx_machine(lacpdu, port); 2201 ad_rx_machine(lacpdu, port);
2183 break; 2202 break;
2184 2203
@@ -2187,17 +2206,20 @@ static void bond_3ad_rx_indication(struct lacpdu *lacpdu, struct slave *slave, u
2187 2206
2188 switch (((struct bond_marker *)lacpdu)->tlv_type) { 2207 switch (((struct bond_marker *)lacpdu)->tlv_type) {
2189 case AD_MARKER_INFORMATION_SUBTYPE: 2208 case AD_MARKER_INFORMATION_SUBTYPE:
2190 pr_debug("Received Marker Information on port %d\n", port->actor_port_number); 2209 pr_debug("Received Marker Information on port %d\n",
2210 port->actor_port_number);
2191 ad_marker_info_received((struct bond_marker *)lacpdu, port); 2211 ad_marker_info_received((struct bond_marker *)lacpdu, port);
2192 break; 2212 break;
2193 2213
2194 case AD_MARKER_RESPONSE_SUBTYPE: 2214 case AD_MARKER_RESPONSE_SUBTYPE:
2195 pr_debug("Received Marker Response on port %d\n", port->actor_port_number); 2215 pr_debug("Received Marker Response on port %d\n",
2216 port->actor_port_number);
2196 ad_marker_response_received((struct bond_marker *)lacpdu, port); 2217 ad_marker_response_received((struct bond_marker *)lacpdu, port);
2197 break; 2218 break;
2198 2219
2199 default: 2220 default:
2200 pr_debug("Received an unknown Marker subtype on slot %d\n", port->actor_port_number); 2221 pr_debug("Received an unknown Marker subtype on slot %d\n",
2222 port->actor_port_number);
2201 } 2223 }
2202 } 2224 }
2203 } 2225 }
@@ -2217,8 +2239,7 @@ void bond_3ad_adapter_speed_changed(struct slave *slave)
2217 2239
2218 // if slave is null, the whole port is not initialized 2240 // if slave is null, the whole port is not initialized
2219 if (!port->slave) { 2241 if (!port->slave) {
2220 pr_warning(DRV_NAME ": Warning: %s: speed " 2242 pr_warning("Warning: %s: speed changed for uninitialized port on %s\n",
2221 "changed for uninitialized port on %s\n",
2222 slave->dev->master->name, slave->dev->name); 2243 slave->dev->master->name, slave->dev->name);
2223 return; 2244 return;
2224 } 2245 }
@@ -2245,8 +2266,7 @@ void bond_3ad_adapter_duplex_changed(struct slave *slave)
2245 2266
2246 // if slave is null, the whole port is not initialized 2267 // if slave is null, the whole port is not initialized
2247 if (!port->slave) { 2268 if (!port->slave) {
2248 pr_warning(DRV_NAME ": %s: Warning: duplex changed " 2269 pr_warning("%s: Warning: duplex changed for uninitialized port on %s\n",
2249 "for uninitialized port on %s\n",
2250 slave->dev->master->name, slave->dev->name); 2270 slave->dev->master->name, slave->dev->name);
2251 return; 2271 return;
2252 } 2272 }
@@ -2274,8 +2294,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
2274 2294
2275 // if slave is null, the whole port is not initialized 2295 // if slave is null, the whole port is not initialized
2276 if (!port->slave) { 2296 if (!port->slave) {
2277 pr_warning(DRV_NAME ": Warning: %s: link status changed for " 2297 pr_warning("Warning: %s: link status changed for uninitialized port on %s\n",
2278 "uninitialized port on %s\n",
2279 slave->dev->master->name, slave->dev->name); 2298 slave->dev->master->name, slave->dev->name);
2280 return; 2299 return;
2281 } 2300 }
@@ -2301,7 +2320,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link)
2301} 2320}
2302 2321
2303/* 2322/*
2304 * set link state for bonding master: if we have an active 2323 * set link state for bonding master: if we have an active
2305 * aggregator, we're up, if not, we're down. Presumes that we cannot 2324 * aggregator, we're up, if not, we're down. Presumes that we cannot
2306 * have an active aggregator if there are no slaves with link up. 2325 * have an active aggregator if there are no slaves with link up.
2307 * 2326 *
@@ -2380,8 +2399,8 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2380 } 2399 }
2381 2400
2382 if (bond_3ad_get_active_agg_info(bond, &ad_info)) { 2401 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
2383 pr_debug(DRV_NAME ": %s: Error: " 2402 pr_debug("%s: Error: bond_3ad_get_active_agg_info failed\n",
2384 "bond_3ad_get_active_agg_info failed\n", dev->name); 2403 dev->name);
2385 goto out; 2404 goto out;
2386 } 2405 }
2387 2406
@@ -2390,12 +2409,11 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2390 2409
2391 if (slaves_in_agg == 0) { 2410 if (slaves_in_agg == 0) {
2392 /*the aggregator is empty*/ 2411 /*the aggregator is empty*/
2393 pr_debug(DRV_NAME ": %s: Error: active aggregator is empty\n", 2412 pr_debug("%s: Error: active aggregator is empty\n", dev->name);
2394 dev->name);
2395 goto out; 2413 goto out;
2396 } 2414 }
2397 2415
2398 slave_agg_no = bond->xmit_hash_policy(skb, dev, slaves_in_agg); 2416 slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg);
2399 2417
2400 bond_for_each_slave(bond, slave, i) { 2418 bond_for_each_slave(bond, slave, i) {
2401 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator; 2419 struct aggregator *agg = SLAVE_AD_INFO(slave).port.aggregator;
@@ -2409,8 +2427,8 @@ int bond_3ad_xmit_xor(struct sk_buff *skb, struct net_device *dev)
2409 } 2427 }
2410 2428
2411 if (slave_agg_no >= 0) { 2429 if (slave_agg_no >= 0) {
2412 pr_err(DRV_NAME ": %s: Error: Couldn't find a slave to tx on " 2430 pr_err("%s: Error: Couldn't find a slave to tx on for aggregator ID %d\n",
2413 "for aggregator ID %d\n", dev->name, agg_id); 2431 dev->name, agg_id);
2414 goto out; 2432 goto out;
2415 } 2433 }
2416 2434
@@ -2445,9 +2463,6 @@ int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct pac
2445 struct slave *slave = NULL; 2463 struct slave *slave = NULL;
2446 int ret = NET_RX_DROP; 2464 int ret = NET_RX_DROP;
2447 2465
2448 if (dev_net(dev) != &init_net)
2449 goto out;
2450
2451 if (!(dev->flags & IFF_MASTER)) 2466 if (!(dev->flags & IFF_MASTER))
2452 goto out; 2467 goto out;
2453 2468
@@ -2468,4 +2483,3 @@ out:
2468 2483
2469 return ret; 2484 return ret;
2470} 2485}
2471
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index 9b5936f072dc..40fdc41446cc 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -20,6 +20,8 @@
20 * 20 *
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/skbuff.h> 25#include <linux/skbuff.h>
24#include <linux/netdevice.h> 26#include <linux/netdevice.h>
25#include <linux/etherdevice.h> 27#include <linux/etherdevice.h>
@@ -201,8 +203,7 @@ static int tlb_initialize(struct bonding *bond)
201 203
202 new_hashtbl = kzalloc(size, GFP_KERNEL); 204 new_hashtbl = kzalloc(size, GFP_KERNEL);
203 if (!new_hashtbl) { 205 if (!new_hashtbl) {
204 pr_err(DRV_NAME 206 pr_err("%s: Error: Failed to allocate TLB hash table\n",
205 ": %s: Error: Failed to allocate TLB hash table\n",
206 bond->dev->name); 207 bond->dev->name);
207 return -1; 208 return -1;
208 } 209 }
@@ -355,9 +356,6 @@ static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct
355 struct arp_pkt *arp = (struct arp_pkt *)skb->data; 356 struct arp_pkt *arp = (struct arp_pkt *)skb->data;
356 int res = NET_RX_DROP; 357 int res = NET_RX_DROP;
357 358
358 if (dev_net(bond_dev) != &init_net)
359 goto out;
360
361 while (bond_dev->priv_flags & IFF_802_1Q_VLAN) 359 while (bond_dev->priv_flags & IFF_802_1Q_VLAN)
362 bond_dev = vlan_dev_real_dev(bond_dev); 360 bond_dev = vlan_dev_real_dev(bond_dev);
363 361
@@ -517,8 +515,7 @@ static void rlb_update_client(struct rlb_client_info *client_info)
517 client_info->slave->dev->dev_addr, 515 client_info->slave->dev->dev_addr,
518 client_info->mac_dst); 516 client_info->mac_dst);
519 if (!skb) { 517 if (!skb) {
520 pr_err(DRV_NAME 518 pr_err("%s: Error: failed to create an ARP packet\n",
521 ": %s: Error: failed to create an ARP packet\n",
522 client_info->slave->dev->master->name); 519 client_info->slave->dev->master->name);
523 continue; 520 continue;
524 } 521 }
@@ -528,8 +525,7 @@ static void rlb_update_client(struct rlb_client_info *client_info)
528 if (client_info->tag) { 525 if (client_info->tag) {
529 skb = vlan_put_tag(skb, client_info->vlan_id); 526 skb = vlan_put_tag(skb, client_info->vlan_id);
530 if (!skb) { 527 if (!skb) {
531 pr_err(DRV_NAME 528 pr_err("%s: Error: failed to insert VLAN tag\n",
532 ": %s: Error: failed to insert VLAN tag\n",
533 client_info->slave->dev->master->name); 529 client_info->slave->dev->master->name);
534 continue; 530 continue;
535 } 531 }
@@ -559,7 +555,7 @@ static void rlb_update_rx_clients(struct bonding *bond)
559 } 555 }
560 } 556 }
561 557
562 /* do not update the entries again untill this counter is zero so that 558 /* do not update the entries again until this counter is zero so that
563 * not to confuse the clients. 559 * not to confuse the clients.
564 */ 560 */
565 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY; 561 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
@@ -612,9 +608,7 @@ static void rlb_req_update_subnet_clients(struct bonding *bond, __be32 src_ip)
612 client_info = &(bond_info->rx_hashtbl[hash_index]); 608 client_info = &(bond_info->rx_hashtbl[hash_index]);
613 609
614 if (!client_info->slave) { 610 if (!client_info->slave) {
615 pr_err(DRV_NAME 611 pr_err("%s: Error: found a client with no channel in the client's hash table\n",
616 ": %s: Error: found a client with no channel in "
617 "the client's hash table\n",
618 bond->dev->name); 612 bond->dev->name);
619 continue; 613 continue;
620 } 614 }
@@ -809,8 +803,7 @@ static int rlb_initialize(struct bonding *bond)
809 803
810 new_hashtbl = kmalloc(size, GFP_KERNEL); 804 new_hashtbl = kmalloc(size, GFP_KERNEL);
811 if (!new_hashtbl) { 805 if (!new_hashtbl) {
812 pr_err(DRV_NAME 806 pr_err("%s: Error: Failed to allocate RLB hash table\n",
813 ": %s: Error: Failed to allocate RLB hash table\n",
814 bond->dev->name); 807 bond->dev->name);
815 return -1; 808 return -1;
816 } 809 }
@@ -931,8 +924,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
931 924
932 skb = vlan_put_tag(skb, vlan->vlan_id); 925 skb = vlan_put_tag(skb, vlan->vlan_id);
933 if (!skb) { 926 if (!skb) {
934 pr_err(DRV_NAME 927 pr_err("%s: Error: failed to insert VLAN tag\n",
935 ": %s: Error: failed to insert VLAN tag\n",
936 bond->dev->name); 928 bond->dev->name);
937 continue; 929 continue;
938 } 930 }
@@ -961,11 +953,8 @@ static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], int hw)
961 memcpy(s_addr.sa_data, addr, dev->addr_len); 953 memcpy(s_addr.sa_data, addr, dev->addr_len);
962 s_addr.sa_family = dev->type; 954 s_addr.sa_family = dev->type;
963 if (dev_set_mac_address(dev, &s_addr)) { 955 if (dev_set_mac_address(dev, &s_addr)) {
964 pr_err(DRV_NAME 956 pr_err("%s: Error: dev_set_mac_address of dev %s failed!\n"
965 ": %s: Error: dev_set_mac_address of dev %s failed! ALB " 957 "ALB mode requires that the base driver support setting the hw address also when the network device's interface is open\n",
966 "mode requires that the base driver support setting "
967 "the hw address also when the network device's "
968 "interface is open\n",
969 dev->master->name, dev->name); 958 dev->master->name, dev->name);
970 return -EOPNOTSUPP; 959 return -EOPNOTSUPP;
971 } 960 }
@@ -1172,18 +1161,12 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
1172 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr, 1161 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
1173 bond->alb_info.rlb_enabled); 1162 bond->alb_info.rlb_enabled);
1174 1163
1175 pr_warning(DRV_NAME 1164 pr_warning("%s: Warning: the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
1176 ": %s: Warning: the hw address of slave %s is "
1177 "in use by the bond; giving it the hw address "
1178 "of %s\n",
1179 bond->dev->name, slave->dev->name, 1165 bond->dev->name, slave->dev->name,
1180 free_mac_slave->dev->name); 1166 free_mac_slave->dev->name);
1181 1167
1182 } else if (has_bond_addr) { 1168 } else if (has_bond_addr) {
1183 pr_err(DRV_NAME 1169 pr_err("%s: Error: the hw address of slave %s is in use by the bond; couldn't find a slave with a free hw address to give it (this should not have happened)\n",
1184 ": %s: Error: the hw address of slave %s is in use by the "
1185 "bond; couldn't find a slave with a free hw address to "
1186 "give it (this should not have happened)\n",
1187 bond->dev->name, slave->dev->name); 1170 bond->dev->name, slave->dev->name);
1188 return -EFAULT; 1171 return -EFAULT;
1189 } 1172 }
diff --git a/drivers/net/bonding/bond_ipv6.c b/drivers/net/bonding/bond_ipv6.c
index 83921abae12d..6dd64cf3cb76 100644
--- a/drivers/net/bonding/bond_ipv6.c
+++ b/drivers/net/bonding/bond_ipv6.c
@@ -20,11 +20,14 @@
20 * 20 *
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
23#include <linux/types.h> 25#include <linux/types.h>
24#include <linux/if_vlan.h> 26#include <linux/if_vlan.h>
25#include <net/ipv6.h> 27#include <net/ipv6.h>
26#include <net/ndisc.h> 28#include <net/ndisc.h>
27#include <net/addrconf.h> 29#include <net/addrconf.h>
30#include <net/netns/generic.h>
28#include "bonding.h" 31#include "bonding.h"
29 32
30/* 33/*
@@ -73,20 +76,20 @@ static void bond_na_send(struct net_device *slave_dev,
73 addrconf_addr_solict_mult(daddr, &mcaddr); 76 addrconf_addr_solict_mult(daddr, &mcaddr);
74 77
75 pr_debug("ipv6 na on slave %s: dest %pI6, src %pI6\n", 78 pr_debug("ipv6 na on slave %s: dest %pI6, src %pI6\n",
76 slave_dev->name, &mcaddr, daddr); 79 slave_dev->name, &mcaddr, daddr);
77 80
78 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr, 81 skb = ndisc_build_skb(slave_dev, &mcaddr, daddr, &icmp6h, daddr,
79 ND_OPT_TARGET_LL_ADDR); 82 ND_OPT_TARGET_LL_ADDR);
80 83
81 if (!skb) { 84 if (!skb) {
82 pr_err(DRV_NAME ": NA packet allocation failed\n"); 85 pr_err("NA packet allocation failed\n");
83 return; 86 return;
84 } 87 }
85 88
86 if (vlan_id) { 89 if (vlan_id) {
87 skb = vlan_put_tag(skb, vlan_id); 90 skb = vlan_put_tag(skb, vlan_id);
88 if (!skb) { 91 if (!skb) {
89 pr_err(DRV_NAME ": failed to insert VLAN tag\n"); 92 pr_err("failed to insert VLAN tag\n");
90 return; 93 return;
91 } 94 }
92 } 95 }
@@ -108,8 +111,8 @@ void bond_send_unsolicited_na(struct bonding *bond)
108 struct inet6_dev *idev; 111 struct inet6_dev *idev;
109 int is_router; 112 int is_router;
110 113
111 pr_debug("bond_send_unsol_na: bond %s slave %s\n", bond->dev->name, 114 pr_debug("%s: bond %s slave %s\n", bond->dev->name,
112 slave ? slave->dev->name : "NULL"); 115 __func__, slave ? slave->dev->name : "NULL");
113 116
114 if (!slave || !bond->send_unsol_na || 117 if (!slave || !bond->send_unsol_na ||
115 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state)) 118 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
@@ -152,11 +155,9 @@ static int bond_inet6addr_event(struct notifier_block *this,
152 struct net_device *vlan_dev, *event_dev = ifa->idev->dev; 155 struct net_device *vlan_dev, *event_dev = ifa->idev->dev;
153 struct bonding *bond; 156 struct bonding *bond;
154 struct vlan_entry *vlan; 157 struct vlan_entry *vlan;
158 struct bond_net *bn = net_generic(dev_net(event_dev), bond_net_id);
155 159
156 if (dev_net(event_dev) != &init_net) 160 list_for_each_entry(bond, &bn->dev_list, bond_list) {
157 return NOTIFY_DONE;
158
159 list_for_each_entry(bond, &bond_dev_list, bond_list) {
160 if (bond->dev == event_dev) { 161 if (bond->dev == event_dev) {
161 switch (event) { 162 switch (event) {
162 case NETDEV_UP: 163 case NETDEV_UP:
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");
diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index 8762a27a2a18..b8bec086daa1 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -19,6 +19,9 @@
19 * file called LICENSE. 19 * file called LICENSE.
20 * 20 *
21 */ 21 */
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
22#include <linux/kernel.h> 25#include <linux/kernel.h>
23#include <linux/module.h> 26#include <linux/module.h>
24#include <linux/device.h> 27#include <linux/device.h>
@@ -36,6 +39,8 @@
36#include <linux/rtnetlink.h> 39#include <linux/rtnetlink.h>
37#include <linux/etherdevice.h> 40#include <linux/etherdevice.h>
38#include <net/net_namespace.h> 41#include <net/net_namespace.h>
42#include <net/netns/generic.h>
43#include <linux/nsproxy.h>
39 44
40#include "bonding.h" 45#include "bonding.h"
41 46
@@ -46,14 +51,18 @@
46 * "show" function for the bond_masters attribute. 51 * "show" function for the bond_masters attribute.
47 * The class parameter is ignored. 52 * The class parameter is ignored.
48 */ 53 */
49static ssize_t bonding_show_bonds(struct class *cls, char *buf) 54static ssize_t bonding_show_bonds(struct class *cls,
55 struct class_attribute *attr,
56 char *buf)
50{ 57{
58 struct net *net = current->nsproxy->net_ns;
59 struct bond_net *bn = net_generic(net, bond_net_id);
51 int res = 0; 60 int res = 0;
52 struct bonding *bond; 61 struct bonding *bond;
53 62
54 rtnl_lock(); 63 rtnl_lock();
55 64
56 list_for_each_entry(bond, &bond_dev_list, bond_list) { 65 list_for_each_entry(bond, &bn->dev_list, bond_list) {
57 if (res > (PAGE_SIZE - IFNAMSIZ)) { 66 if (res > (PAGE_SIZE - IFNAMSIZ)) {
58 /* not enough space for another interface name */ 67 /* not enough space for another interface name */
59 if ((PAGE_SIZE - res) > 10) 68 if ((PAGE_SIZE - res) > 10)
@@ -70,11 +79,12 @@ static ssize_t bonding_show_bonds(struct class *cls, char *buf)
70 return res; 79 return res;
71} 80}
72 81
73static struct net_device *bond_get_by_name(const char *ifname) 82static struct net_device *bond_get_by_name(struct net *net, const char *ifname)
74{ 83{
84 struct bond_net *bn = net_generic(net, bond_net_id);
75 struct bonding *bond; 85 struct bonding *bond;
76 86
77 list_for_each_entry(bond, &bond_dev_list, bond_list) { 87 list_for_each_entry(bond, &bn->dev_list, bond_list) {
78 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0) 88 if (strncmp(bond->dev->name, ifname, IFNAMSIZ) == 0)
79 return bond->dev; 89 return bond->dev;
80 } 90 }
@@ -90,8 +100,10 @@ static struct net_device *bond_get_by_name(const char *ifname)
90 */ 100 */
91 101
92static ssize_t bonding_store_bonds(struct class *cls, 102static ssize_t bonding_store_bonds(struct class *cls,
103 struct class_attribute *attr,
93 const char *buffer, size_t count) 104 const char *buffer, size_t count)
94{ 105{
106 struct net *net = current->nsproxy->net_ns;
95 char command[IFNAMSIZ + 1] = {0, }; 107 char command[IFNAMSIZ + 1] = {0, };
96 char *ifname; 108 char *ifname;
97 int rv, res = count; 109 int rv, res = count;
@@ -103,25 +115,22 @@ static ssize_t bonding_store_bonds(struct class *cls,
103 goto err_no_cmd; 115 goto err_no_cmd;
104 116
105 if (command[0] == '+') { 117 if (command[0] == '+') {
106 pr_info(DRV_NAME 118 pr_info("%s is being created...\n", ifname);
107 ": %s is being created...\n", ifname); 119 rv = bond_create(net, ifname);
108 rv = bond_create(ifname);
109 if (rv) { 120 if (rv) {
110 pr_info(DRV_NAME ": Bond creation failed.\n"); 121 pr_info("Bond creation failed.\n");
111 res = rv; 122 res = rv;
112 } 123 }
113 } else if (command[0] == '-') { 124 } else if (command[0] == '-') {
114 struct net_device *bond_dev; 125 struct net_device *bond_dev;
115 126
116 rtnl_lock(); 127 rtnl_lock();
117 bond_dev = bond_get_by_name(ifname); 128 bond_dev = bond_get_by_name(net, ifname);
118 if (bond_dev) { 129 if (bond_dev) {
119 pr_info(DRV_NAME ": %s is being deleted...\n", 130 pr_info("%s is being deleted...\n", ifname);
120 ifname);
121 unregister_netdevice(bond_dev); 131 unregister_netdevice(bond_dev);
122 } else { 132 } else {
123 pr_err(DRV_NAME ": unable to delete non-existent %s\n", 133 pr_err("unable to delete non-existent %s\n", ifname);
124 ifname);
125 res = -ENODEV; 134 res = -ENODEV;
126 } 135 }
127 rtnl_unlock(); 136 rtnl_unlock();
@@ -134,8 +143,7 @@ static ssize_t bonding_store_bonds(struct class *cls,
134 return res; 143 return res;
135 144
136err_no_cmd: 145err_no_cmd:
137 pr_err(DRV_NAME ": no command found in bonding_masters." 146 pr_err("no command found in bonding_masters. Use +ifname or -ifname.\n");
138 " Use +ifname or -ifname.\n");
139 return -EPERM; 147 return -EPERM;
140} 148}
141 149
@@ -219,8 +227,8 @@ static ssize_t bonding_store_slaves(struct device *d,
219 227
220 /* Quick sanity check -- is the bond interface up? */ 228 /* Quick sanity check -- is the bond interface up? */
221 if (!(bond->dev->flags & IFF_UP)) { 229 if (!(bond->dev->flags & IFF_UP)) {
222 pr_warning(DRV_NAME ": %s: doing slave updates when " 230 pr_warning("%s: doing slave updates when interface is down.\n",
223 "interface is down.\n", bond->dev->name); 231 bond->dev->name);
224 } 232 }
225 233
226 /* Note: We can't hold bond->lock here, as bond_create grabs it. */ 234 /* Note: We can't hold bond->lock here, as bond_create grabs it. */
@@ -239,20 +247,16 @@ static ssize_t bonding_store_slaves(struct device *d,
239 /* Got a slave name in ifname. Is it already in the list? */ 247 /* Got a slave name in ifname. Is it already in the list? */
240 found = 0; 248 found = 0;
241 249
242 /* FIXME: get netns from sysfs object */ 250 dev = __dev_get_by_name(dev_net(bond->dev), ifname);
243 dev = __dev_get_by_name(&init_net, ifname);
244 if (!dev) { 251 if (!dev) {
245 pr_info(DRV_NAME 252 pr_info("%s: Interface %s does not exist!\n",
246 ": %s: Interface %s does not exist!\n", 253 bond->dev->name, ifname);
247 bond->dev->name, ifname);
248 ret = -ENODEV; 254 ret = -ENODEV;
249 goto out; 255 goto out;
250 } 256 }
251 257
252 if (dev->flags & IFF_UP) { 258 if (dev->flags & IFF_UP) {
253 pr_err(DRV_NAME 259 pr_err("%s: Error: Unable to enslave %s because it is already up.\n",
254 ": %s: Error: Unable to enslave %s "
255 "because it is already up.\n",
256 bond->dev->name, dev->name); 260 bond->dev->name, dev->name);
257 ret = -EPERM; 261 ret = -EPERM;
258 goto out; 262 goto out;
@@ -261,8 +265,7 @@ static ssize_t bonding_store_slaves(struct device *d,
261 read_lock(&bond->lock); 265 read_lock(&bond->lock);
262 bond_for_each_slave(bond, slave, i) 266 bond_for_each_slave(bond, slave, i)
263 if (slave->dev == dev) { 267 if (slave->dev == dev) {
264 pr_err(DRV_NAME 268 pr_err("%s: Interface %s is already enslaved!\n",
265 ": %s: Interface %s is already enslaved!\n",
266 bond->dev->name, ifname); 269 bond->dev->name, ifname);
267 ret = -EPERM; 270 ret = -EPERM;
268 read_unlock(&bond->lock); 271 read_unlock(&bond->lock);
@@ -270,8 +273,7 @@ static ssize_t bonding_store_slaves(struct device *d,
270 } 273 }
271 read_unlock(&bond->lock); 274 read_unlock(&bond->lock);
272 275
273 pr_info(DRV_NAME ": %s: Adding slave %s.\n", 276 pr_info("%s: Adding slave %s.\n", bond->dev->name, ifname);
274 bond->dev->name, ifname);
275 277
276 /* If this is the first slave, then we need to set 278 /* If this is the first slave, then we need to set
277 the master's hardware address to be the same as the 279 the master's hardware address to be the same as the
@@ -308,7 +310,7 @@ static ssize_t bonding_store_slaves(struct device *d,
308 break; 310 break;
309 } 311 }
310 if (dev) { 312 if (dev) {
311 pr_info(DRV_NAME ": %s: Removing slave %s\n", 313 pr_info("%s: Removing slave %s\n",
312 bond->dev->name, dev->name); 314 bond->dev->name, dev->name);
313 res = bond_release(bond->dev, dev); 315 res = bond_release(bond->dev, dev);
314 if (res) { 316 if (res) {
@@ -318,16 +320,16 @@ static ssize_t bonding_store_slaves(struct device *d,
318 /* set the slave MTU to the default */ 320 /* set the slave MTU to the default */
319 dev_set_mtu(dev, original_mtu); 321 dev_set_mtu(dev, original_mtu);
320 } else { 322 } else {
321 pr_err(DRV_NAME ": unable to remove non-existent" 323 pr_err("unable to remove non-existent slave %s for bond %s.\n",
322 " slave %s for bond %s.\n", 324 ifname, bond->dev->name);
323 ifname, bond->dev->name);
324 ret = -ENODEV; 325 ret = -ENODEV;
325 } 326 }
326 goto out; 327 goto out;
327 } 328 }
328 329
329err_no_cmd: 330err_no_cmd:
330 pr_err(DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name); 331 pr_err("no command found in slaves file for bond %s. Use +ifname or -ifname.\n",
332 bond->dev->name);
331 ret = -EPERM; 333 ret = -EPERM;
332 334
333out: 335out:
@@ -360,18 +362,16 @@ static ssize_t bonding_store_mode(struct device *d,
360 struct bonding *bond = to_bond(d); 362 struct bonding *bond = to_bond(d);
361 363
362 if (bond->dev->flags & IFF_UP) { 364 if (bond->dev->flags & IFF_UP) {
363 pr_err(DRV_NAME ": unable to update mode of %s" 365 pr_err("unable to update mode of %s because interface is up.\n",
364 " because interface is up.\n", bond->dev->name); 366 bond->dev->name);
365 ret = -EPERM; 367 ret = -EPERM;
366 goto out; 368 goto out;
367 } 369 }
368 370
369 new_value = bond_parse_parm(buf, bond_mode_tbl); 371 new_value = bond_parse_parm(buf, bond_mode_tbl);
370 if (new_value < 0) { 372 if (new_value < 0) {
371 pr_err(DRV_NAME 373 pr_err("%s: Ignoring invalid mode value %.*s.\n",
372 ": %s: Ignoring invalid mode value %.*s.\n", 374 bond->dev->name, (int)strlen(buf) - 1, buf);
373 bond->dev->name,
374 (int)strlen(buf) - 1, buf);
375 ret = -EINVAL; 375 ret = -EINVAL;
376 goto out; 376 goto out;
377 } else { 377 } else {
@@ -383,8 +383,8 @@ static ssize_t bonding_store_mode(struct device *d,
383 383
384 bond->params.mode = new_value; 384 bond->params.mode = new_value;
385 bond_set_mode_ops(bond, bond->params.mode); 385 bond_set_mode_ops(bond, bond->params.mode);
386 pr_info(DRV_NAME ": %s: setting mode to %s (%d).\n", 386 pr_info("%s: setting mode to %s (%d).\n",
387 bond->dev->name, bond_mode_tbl[new_value].modename, 387 bond->dev->name, bond_mode_tbl[new_value].modename,
388 new_value); 388 new_value);
389 } 389 }
390out: 390out:
@@ -416,8 +416,7 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
416 struct bonding *bond = to_bond(d); 416 struct bonding *bond = to_bond(d);
417 417
418 if (bond->dev->flags & IFF_UP) { 418 if (bond->dev->flags & IFF_UP) {
419 pr_err(DRV_NAME 419 pr_err("%s: Interface is up. Unable to update xmit policy.\n",
420 "%s: Interface is up. Unable to update xmit policy.\n",
421 bond->dev->name); 420 bond->dev->name);
422 ret = -EPERM; 421 ret = -EPERM;
423 goto out; 422 goto out;
@@ -425,8 +424,7 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
425 424
426 new_value = bond_parse_parm(buf, xmit_hashtype_tbl); 425 new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
427 if (new_value < 0) { 426 if (new_value < 0) {
428 pr_err(DRV_NAME 427 pr_err("%s: Ignoring invalid xmit hash policy value %.*s.\n",
429 ": %s: Ignoring invalid xmit hash policy value %.*s.\n",
430 bond->dev->name, 428 bond->dev->name,
431 (int)strlen(buf) - 1, buf); 429 (int)strlen(buf) - 1, buf);
432 ret = -EINVAL; 430 ret = -EINVAL;
@@ -434,7 +432,7 @@ static ssize_t bonding_store_xmit_hash(struct device *d,
434 } else { 432 } else {
435 bond->params.xmit_policy = new_value; 433 bond->params.xmit_policy = new_value;
436 bond_set_mode_ops(bond, bond->params.mode); 434 bond_set_mode_ops(bond, bond->params.mode);
437 pr_info(DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n", 435 pr_info("%s: setting xmit hash policy to %s (%d).\n",
438 bond->dev->name, 436 bond->dev->name,
439 xmit_hashtype_tbl[new_value].modename, new_value); 437 xmit_hashtype_tbl[new_value].modename, new_value);
440 } 438 }
@@ -467,20 +465,18 @@ static ssize_t bonding_store_arp_validate(struct device *d,
467 465
468 new_value = bond_parse_parm(buf, arp_validate_tbl); 466 new_value = bond_parse_parm(buf, arp_validate_tbl);
469 if (new_value < 0) { 467 if (new_value < 0) {
470 pr_err(DRV_NAME 468 pr_err("%s: Ignoring invalid arp_validate value %s\n",
471 ": %s: Ignoring invalid arp_validate value %s\n",
472 bond->dev->name, buf); 469 bond->dev->name, buf);
473 return -EINVAL; 470 return -EINVAL;
474 } 471 }
475 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) { 472 if (new_value && (bond->params.mode != BOND_MODE_ACTIVEBACKUP)) {
476 pr_err(DRV_NAME 473 pr_err("%s: arp_validate only supported in active-backup mode.\n",
477 ": %s: arp_validate only supported in active-backup mode.\n",
478 bond->dev->name); 474 bond->dev->name);
479 return -EINVAL; 475 return -EINVAL;
480 } 476 }
481 pr_info(DRV_NAME ": %s: setting arp_validate to %s (%d).\n", 477 pr_info("%s: setting arp_validate to %s (%d).\n",
482 bond->dev->name, arp_validate_tbl[new_value].modename, 478 bond->dev->name, arp_validate_tbl[new_value].modename,
483 new_value); 479 new_value);
484 480
485 if (!bond->params.arp_validate && new_value) 481 if (!bond->params.arp_validate && new_value)
486 bond_register_arp(bond); 482 bond_register_arp(bond);
@@ -518,24 +514,22 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
518 struct bonding *bond = to_bond(d); 514 struct bonding *bond = to_bond(d);
519 515
520 if (bond->slave_cnt != 0) { 516 if (bond->slave_cnt != 0) {
521 pr_err(DRV_NAME 517 pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
522 ": %s: Can't alter fail_over_mac with slaves in bond.\n",
523 bond->dev->name); 518 bond->dev->name);
524 return -EPERM; 519 return -EPERM;
525 } 520 }
526 521
527 new_value = bond_parse_parm(buf, fail_over_mac_tbl); 522 new_value = bond_parse_parm(buf, fail_over_mac_tbl);
528 if (new_value < 0) { 523 if (new_value < 0) {
529 pr_err(DRV_NAME 524 pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
530 ": %s: Ignoring invalid fail_over_mac value %s.\n",
531 bond->dev->name, buf); 525 bond->dev->name, buf);
532 return -EINVAL; 526 return -EINVAL;
533 } 527 }
534 528
535 bond->params.fail_over_mac = new_value; 529 bond->params.fail_over_mac = new_value;
536 pr_info(DRV_NAME ": %s: Setting fail_over_mac to %s (%d).\n", 530 pr_info("%s: Setting fail_over_mac to %s (%d).\n",
537 bond->dev->name, fail_over_mac_tbl[new_value].modename, 531 bond->dev->name, fail_over_mac_tbl[new_value].modename,
538 new_value); 532 new_value);
539 533
540 return count; 534 return count;
541} 535}
@@ -566,31 +560,26 @@ static ssize_t bonding_store_arp_interval(struct device *d,
566 struct bonding *bond = to_bond(d); 560 struct bonding *bond = to_bond(d);
567 561
568 if (sscanf(buf, "%d", &new_value) != 1) { 562 if (sscanf(buf, "%d", &new_value) != 1) {
569 pr_err(DRV_NAME 563 pr_err("%s: no arp_interval value specified.\n",
570 ": %s: no arp_interval value specified.\n",
571 bond->dev->name); 564 bond->dev->name);
572 ret = -EINVAL; 565 ret = -EINVAL;
573 goto out; 566 goto out;
574 } 567 }
575 if (new_value < 0) { 568 if (new_value < 0) {
576 pr_err(DRV_NAME 569 pr_err("%s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
577 ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
578 bond->dev->name, new_value, INT_MAX); 570 bond->dev->name, new_value, INT_MAX);
579 ret = -EINVAL; 571 ret = -EINVAL;
580 goto out; 572 goto out;
581 } 573 }
582 574
583 pr_info(DRV_NAME 575 pr_info("%s: Setting ARP monitoring interval to %d.\n",
584 ": %s: Setting ARP monitoring interval to %d.\n", 576 bond->dev->name, new_value);
585 bond->dev->name, new_value);
586 bond->params.arp_interval = new_value; 577 bond->params.arp_interval = new_value;
587 if (bond->params.arp_interval) 578 if (bond->params.arp_interval)
588 bond->dev->priv_flags |= IFF_MASTER_ARPMON; 579 bond->dev->priv_flags |= IFF_MASTER_ARPMON;
589 if (bond->params.miimon) { 580 if (bond->params.miimon) {
590 pr_info(DRV_NAME 581 pr_info("%s: ARP monitoring cannot be used with MII monitoring. %s Disabling MII monitoring.\n",
591 ": %s: ARP monitoring cannot be used with MII monitoring. " 582 bond->dev->name, bond->dev->name);
592 "%s Disabling MII monitoring.\n",
593 bond->dev->name, bond->dev->name);
594 bond->params.miimon = 0; 583 bond->params.miimon = 0;
595 if (delayed_work_pending(&bond->mii_work)) { 584 if (delayed_work_pending(&bond->mii_work)) {
596 cancel_delayed_work(&bond->mii_work); 585 cancel_delayed_work(&bond->mii_work);
@@ -598,10 +587,8 @@ static ssize_t bonding_store_arp_interval(struct device *d,
598 } 587 }
599 } 588 }
600 if (!bond->params.arp_targets[0]) { 589 if (!bond->params.arp_targets[0]) {
601 pr_info(DRV_NAME 590 pr_info("%s: ARP monitoring has been set up, but no ARP targets have been specified.\n",
602 ": %s: ARP monitoring has been set up, " 591 bond->dev->name);
603 "but no ARP targets have been specified.\n",
604 bond->dev->name);
605 } 592 }
606 if (bond->dev->flags & IFF_UP) { 593 if (bond->dev->flags & IFF_UP) {
607 /* If the interface is up, we may need to fire off 594 /* If the interface is up, we may need to fire off
@@ -661,8 +648,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
661 /* look for adds */ 648 /* look for adds */
662 if (buf[0] == '+') { 649 if (buf[0] == '+') {
663 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { 650 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
664 pr_err(DRV_NAME 651 pr_err("%s: invalid ARP target %pI4 specified for addition\n",
665 ": %s: invalid ARP target %pI4 specified for addition\n",
666 bond->dev->name, &newtarget); 652 bond->dev->name, &newtarget);
667 ret = -EINVAL; 653 ret = -EINVAL;
668 goto out; 654 goto out;
@@ -670,23 +656,20 @@ static ssize_t bonding_store_arp_targets(struct device *d,
670 /* look for an empty slot to put the target in, and check for dupes */ 656 /* look for an empty slot to put the target in, and check for dupes */
671 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { 657 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
672 if (targets[i] == newtarget) { /* duplicate */ 658 if (targets[i] == newtarget) { /* duplicate */
673 pr_err(DRV_NAME 659 pr_err("%s: ARP target %pI4 is already present\n",
674 ": %s: ARP target %pI4 is already present\n",
675 bond->dev->name, &newtarget); 660 bond->dev->name, &newtarget);
676 ret = -EINVAL; 661 ret = -EINVAL;
677 goto out; 662 goto out;
678 } 663 }
679 if (targets[i] == 0) { 664 if (targets[i] == 0) {
680 pr_info(DRV_NAME 665 pr_info("%s: adding ARP target %pI4.\n",
681 ": %s: adding ARP target %pI4.\n", 666 bond->dev->name, &newtarget);
682 bond->dev->name, &newtarget);
683 done = 1; 667 done = 1;
684 targets[i] = newtarget; 668 targets[i] = newtarget;
685 } 669 }
686 } 670 }
687 if (!done) { 671 if (!done) {
688 pr_err(DRV_NAME 672 pr_err("%s: ARP target table is full!\n",
689 ": %s: ARP target table is full!\n",
690 bond->dev->name); 673 bond->dev->name);
691 ret = -EINVAL; 674 ret = -EINVAL;
692 goto out; 675 goto out;
@@ -694,8 +677,7 @@ static ssize_t bonding_store_arp_targets(struct device *d,
694 677
695 } else if (buf[0] == '-') { 678 } else if (buf[0] == '-') {
696 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) { 679 if ((newtarget == 0) || (newtarget == htonl(INADDR_BROADCAST))) {
697 pr_err(DRV_NAME 680 pr_err("%s: invalid ARP target %pI4 specified for removal\n",
698 ": %s: invalid ARP target %pI4 specified for removal\n",
699 bond->dev->name, &newtarget); 681 bond->dev->name, &newtarget);
700 ret = -EINVAL; 682 ret = -EINVAL;
701 goto out; 683 goto out;
@@ -704,9 +686,8 @@ static ssize_t bonding_store_arp_targets(struct device *d,
704 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) { 686 for (i = 0; (i < BOND_MAX_ARP_TARGETS) && !done; i++) {
705 if (targets[i] == newtarget) { 687 if (targets[i] == newtarget) {
706 int j; 688 int j;
707 pr_info(DRV_NAME 689 pr_info("%s: removing ARP target %pI4.\n",
708 ": %s: removing ARP target %pI4.\n", 690 bond->dev->name, &newtarget);
709 bond->dev->name, &newtarget);
710 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++) 691 for (j = i; (j < (BOND_MAX_ARP_TARGETS-1)) && targets[j+1]; j++)
711 targets[j] = targets[j+1]; 692 targets[j] = targets[j+1];
712 693
@@ -715,16 +696,14 @@ static ssize_t bonding_store_arp_targets(struct device *d,
715 } 696 }
716 } 697 }
717 if (!done) { 698 if (!done) {
718 pr_info(DRV_NAME 699 pr_info("%s: unable to remove nonexistent ARP target %pI4.\n",
719 ": %s: unable to remove nonexistent ARP target %pI4.\n", 700 bond->dev->name, &newtarget);
720 bond->dev->name, &newtarget);
721 ret = -EINVAL; 701 ret = -EINVAL;
722 goto out; 702 goto out;
723 } 703 }
724 } else { 704 } else {
725 pr_err(DRV_NAME ": no command found in arp_ip_targets file" 705 pr_err("no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
726 " for bond %s. Use +<addr> or -<addr>.\n", 706 bond->dev->name);
727 bond->dev->name);
728 ret = -EPERM; 707 ret = -EPERM;
729 goto out; 708 goto out;
730 } 709 }
@@ -756,41 +735,34 @@ static ssize_t bonding_store_downdelay(struct device *d,
756 struct bonding *bond = to_bond(d); 735 struct bonding *bond = to_bond(d);
757 736
758 if (!(bond->params.miimon)) { 737 if (!(bond->params.miimon)) {
759 pr_err(DRV_NAME 738 pr_err("%s: Unable to set down delay as MII monitoring is disabled\n",
760 ": %s: Unable to set down delay as MII monitoring is disabled\n",
761 bond->dev->name); 739 bond->dev->name);
762 ret = -EPERM; 740 ret = -EPERM;
763 goto out; 741 goto out;
764 } 742 }
765 743
766 if (sscanf(buf, "%d", &new_value) != 1) { 744 if (sscanf(buf, "%d", &new_value) != 1) {
767 pr_err(DRV_NAME 745 pr_err("%s: no down delay value specified.\n", bond->dev->name);
768 ": %s: no down delay value specified.\n",
769 bond->dev->name);
770 ret = -EINVAL; 746 ret = -EINVAL;
771 goto out; 747 goto out;
772 } 748 }
773 if (new_value < 0) { 749 if (new_value < 0) {
774 pr_err(DRV_NAME 750 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
775 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
776 bond->dev->name, new_value, 1, INT_MAX); 751 bond->dev->name, new_value, 1, INT_MAX);
777 ret = -EINVAL; 752 ret = -EINVAL;
778 goto out; 753 goto out;
779 } else { 754 } else {
780 if ((new_value % bond->params.miimon) != 0) { 755 if ((new_value % bond->params.miimon) != 0) {
781 pr_warning(DRV_NAME 756 pr_warning("%s: Warning: down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n",
782 ": %s: Warning: down delay (%d) is not a "
783 "multiple of miimon (%d), delay rounded "
784 "to %d ms\n",
785 bond->dev->name, new_value, 757 bond->dev->name, new_value,
786 bond->params.miimon, 758 bond->params.miimon,
787 (new_value / bond->params.miimon) * 759 (new_value / bond->params.miimon) *
788 bond->params.miimon); 760 bond->params.miimon);
789 } 761 }
790 bond->params.downdelay = new_value / bond->params.miimon; 762 bond->params.downdelay = new_value / bond->params.miimon;
791 pr_info(DRV_NAME ": %s: Setting down delay to %d.\n", 763 pr_info("%s: Setting down delay to %d.\n",
792 bond->dev->name, 764 bond->dev->name,
793 bond->params.downdelay * bond->params.miimon); 765 bond->params.downdelay * bond->params.miimon);
794 766
795 } 767 }
796 768
@@ -818,41 +790,35 @@ static ssize_t bonding_store_updelay(struct device *d,
818 struct bonding *bond = to_bond(d); 790 struct bonding *bond = to_bond(d);
819 791
820 if (!(bond->params.miimon)) { 792 if (!(bond->params.miimon)) {
821 pr_err(DRV_NAME 793 pr_err("%s: Unable to set up delay as MII monitoring is disabled\n",
822 ": %s: Unable to set up delay as MII monitoring is disabled\n",
823 bond->dev->name); 794 bond->dev->name);
824 ret = -EPERM; 795 ret = -EPERM;
825 goto out; 796 goto out;
826 } 797 }
827 798
828 if (sscanf(buf, "%d", &new_value) != 1) { 799 if (sscanf(buf, "%d", &new_value) != 1) {
829 pr_err(DRV_NAME 800 pr_err("%s: no up delay value specified.\n",
830 ": %s: no up delay value specified.\n",
831 bond->dev->name); 801 bond->dev->name);
832 ret = -EINVAL; 802 ret = -EINVAL;
833 goto out; 803 goto out;
834 } 804 }
835 if (new_value < 0) { 805 if (new_value < 0) {
836 pr_err(DRV_NAME 806 pr_err("%s: Invalid down delay value %d not in range %d-%d; rejected.\n",
837 ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
838 bond->dev->name, new_value, 1, INT_MAX); 807 bond->dev->name, new_value, 1, INT_MAX);
839 ret = -EINVAL; 808 ret = -EINVAL;
840 goto out; 809 goto out;
841 } else { 810 } else {
842 if ((new_value % bond->params.miimon) != 0) { 811 if ((new_value % bond->params.miimon) != 0) {
843 pr_warning(DRV_NAME 812 pr_warning("%s: Warning: up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
844 ": %s: Warning: up delay (%d) is not a "
845 "multiple of miimon (%d), updelay rounded "
846 "to %d ms\n",
847 bond->dev->name, new_value, 813 bond->dev->name, new_value,
848 bond->params.miimon, 814 bond->params.miimon,
849 (new_value / bond->params.miimon) * 815 (new_value / bond->params.miimon) *
850 bond->params.miimon); 816 bond->params.miimon);
851 } 817 }
852 bond->params.updelay = new_value / bond->params.miimon; 818 bond->params.updelay = new_value / bond->params.miimon;
853 pr_info(DRV_NAME ": %s: Setting up delay to %d.\n", 819 pr_info("%s: Setting up delay to %d.\n",
854 bond->dev->name, bond->params.updelay * bond->params.miimon); 820 bond->dev->name,
855 821 bond->params.updelay * bond->params.miimon);
856 } 822 }
857 823
858out: 824out:
@@ -884,16 +850,14 @@ static ssize_t bonding_store_lacp(struct device *d,
884 struct bonding *bond = to_bond(d); 850 struct bonding *bond = to_bond(d);
885 851
886 if (bond->dev->flags & IFF_UP) { 852 if (bond->dev->flags & IFF_UP) {
887 pr_err(DRV_NAME 853 pr_err("%s: Unable to update LACP rate because interface is up.\n",
888 ": %s: Unable to update LACP rate because interface is up.\n",
889 bond->dev->name); 854 bond->dev->name);
890 ret = -EPERM; 855 ret = -EPERM;
891 goto out; 856 goto out;
892 } 857 }
893 858
894 if (bond->params.mode != BOND_MODE_8023AD) { 859 if (bond->params.mode != BOND_MODE_8023AD) {
895 pr_err(DRV_NAME 860 pr_err("%s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
896 ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
897 bond->dev->name); 861 bond->dev->name);
898 ret = -EPERM; 862 ret = -EPERM;
899 goto out; 863 goto out;
@@ -903,12 +867,11 @@ static ssize_t bonding_store_lacp(struct device *d,
903 867
904 if ((new_value == 1) || (new_value == 0)) { 868 if ((new_value == 1) || (new_value == 0)) {
905 bond->params.lacp_fast = new_value; 869 bond->params.lacp_fast = new_value;
906 pr_info(DRV_NAME ": %s: Setting LACP rate to %s (%d).\n", 870 pr_info("%s: Setting LACP rate to %s (%d).\n",
907 bond->dev->name, bond_lacp_tbl[new_value].modename, 871 bond->dev->name, bond_lacp_tbl[new_value].modename,
908 new_value); 872 new_value);
909 } else { 873 } else {
910 pr_err(DRV_NAME 874 pr_err("%s: Ignoring invalid LACP rate value %.*s.\n",
911 ": %s: Ignoring invalid LACP rate value %.*s.\n",
912 bond->dev->name, (int)strlen(buf) - 1, buf); 875 bond->dev->name, (int)strlen(buf) - 1, buf);
913 ret = -EINVAL; 876 ret = -EINVAL;
914 } 877 }
@@ -938,9 +901,8 @@ static ssize_t bonding_store_ad_select(struct device *d,
938 struct bonding *bond = to_bond(d); 901 struct bonding *bond = to_bond(d);
939 902
940 if (bond->dev->flags & IFF_UP) { 903 if (bond->dev->flags & IFF_UP) {
941 pr_err(DRV_NAME 904 pr_err("%s: Unable to update ad_select because interface is up.\n",
942 ": %s: Unable to update ad_select because interface " 905 bond->dev->name);
943 "is up.\n", bond->dev->name);
944 ret = -EPERM; 906 ret = -EPERM;
945 goto out; 907 goto out;
946 } 908 }
@@ -949,13 +911,11 @@ static ssize_t bonding_store_ad_select(struct device *d,
949 911
950 if (new_value != -1) { 912 if (new_value != -1) {
951 bond->params.ad_select = new_value; 913 bond->params.ad_select = new_value;
952 pr_info(DRV_NAME 914 pr_info("%s: Setting ad_select to %s (%d).\n",
953 ": %s: Setting ad_select to %s (%d).\n", 915 bond->dev->name, ad_select_tbl[new_value].modename,
954 bond->dev->name, ad_select_tbl[new_value].modename, 916 new_value);
955 new_value);
956 } else { 917 } else {
957 pr_err(DRV_NAME 918 pr_err("%s: Ignoring invalid ad_select value %.*s.\n",
958 ": %s: Ignoring invalid ad_select value %.*s.\n",
959 bond->dev->name, (int)strlen(buf) - 1, buf); 919 bond->dev->name, (int)strlen(buf) - 1, buf);
960 ret = -EINVAL; 920 ret = -EINVAL;
961 } 921 }
@@ -985,15 +945,13 @@ static ssize_t bonding_store_n_grat_arp(struct device *d,
985 struct bonding *bond = to_bond(d); 945 struct bonding *bond = to_bond(d);
986 946
987 if (sscanf(buf, "%d", &new_value) != 1) { 947 if (sscanf(buf, "%d", &new_value) != 1) {
988 pr_err(DRV_NAME 948 pr_err("%s: no num_grat_arp value specified.\n",
989 ": %s: no num_grat_arp value specified.\n",
990 bond->dev->name); 949 bond->dev->name);
991 ret = -EINVAL; 950 ret = -EINVAL;
992 goto out; 951 goto out;
993 } 952 }
994 if (new_value < 0 || new_value > 255) { 953 if (new_value < 0 || new_value > 255) {
995 pr_err(DRV_NAME 954 pr_err("%s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n",
996 ": %s: Invalid num_grat_arp value %d not in range 0-255; rejected.\n",
997 bond->dev->name, new_value); 955 bond->dev->name, new_value);
998 ret = -EINVAL; 956 ret = -EINVAL;
999 goto out; 957 goto out;
@@ -1026,16 +984,14 @@ static ssize_t bonding_store_n_unsol_na(struct device *d,
1026 struct bonding *bond = to_bond(d); 984 struct bonding *bond = to_bond(d);
1027 985
1028 if (sscanf(buf, "%d", &new_value) != 1) { 986 if (sscanf(buf, "%d", &new_value) != 1) {
1029 pr_err(DRV_NAME 987 pr_err("%s: no num_unsol_na value specified.\n",
1030 ": %s: no num_unsol_na value specified.\n",
1031 bond->dev->name); 988 bond->dev->name);
1032 ret = -EINVAL; 989 ret = -EINVAL;
1033 goto out; 990 goto out;
1034 } 991 }
1035 992
1036 if (new_value < 0 || new_value > 255) { 993 if (new_value < 0 || new_value > 255) {
1037 pr_err(DRV_NAME 994 pr_err("%s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n",
1038 ": %s: Invalid num_unsol_na value %d not in range 0-255; rejected.\n",
1039 bond->dev->name, new_value); 995 bond->dev->name, new_value);
1040 ret = -EINVAL; 996 ret = -EINVAL;
1041 goto out; 997 goto out;
@@ -1070,40 +1026,31 @@ static ssize_t bonding_store_miimon(struct device *d,
1070 struct bonding *bond = to_bond(d); 1026 struct bonding *bond = to_bond(d);
1071 1027
1072 if (sscanf(buf, "%d", &new_value) != 1) { 1028 if (sscanf(buf, "%d", &new_value) != 1) {
1073 pr_err(DRV_NAME 1029 pr_err("%s: no miimon value specified.\n",
1074 ": %s: no miimon value specified.\n",
1075 bond->dev->name); 1030 bond->dev->name);
1076 ret = -EINVAL; 1031 ret = -EINVAL;
1077 goto out; 1032 goto out;
1078 } 1033 }
1079 if (new_value < 0) { 1034 if (new_value < 0) {
1080 pr_err(DRV_NAME 1035 pr_err("%s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1081 ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
1082 bond->dev->name, new_value, 1, INT_MAX); 1036 bond->dev->name, new_value, 1, INT_MAX);
1083 ret = -EINVAL; 1037 ret = -EINVAL;
1084 goto out; 1038 goto out;
1085 } else { 1039 } else {
1086 pr_info(DRV_NAME 1040 pr_info("%s: Setting MII monitoring interval to %d.\n",
1087 ": %s: Setting MII monitoring interval to %d.\n", 1041 bond->dev->name, new_value);
1088 bond->dev->name, new_value);
1089 bond->params.miimon = new_value; 1042 bond->params.miimon = new_value;
1090 if (bond->params.updelay) 1043 if (bond->params.updelay)
1091 pr_info(DRV_NAME 1044 pr_info("%s: Note: Updating updelay (to %d) since it is a multiple of the miimon value.\n",
1092 ": %s: Note: Updating updelay (to %d) " 1045 bond->dev->name,
1093 "since it is a multiple of the miimon value.\n", 1046 bond->params.updelay * bond->params.miimon);
1094 bond->dev->name,
1095 bond->params.updelay * bond->params.miimon);
1096 if (bond->params.downdelay) 1047 if (bond->params.downdelay)
1097 pr_info(DRV_NAME 1048 pr_info("%s: Note: Updating downdelay (to %d) since it is a multiple of the miimon value.\n",
1098 ": %s: Note: Updating downdelay (to %d) " 1049 bond->dev->name,
1099 "since it is a multiple of the miimon value.\n", 1050 bond->params.downdelay * bond->params.miimon);
1100 bond->dev->name,
1101 bond->params.downdelay * bond->params.miimon);
1102 if (bond->params.arp_interval) { 1051 if (bond->params.arp_interval) {
1103 pr_info(DRV_NAME 1052 pr_info("%s: MII monitoring cannot be used with ARP monitoring. Disabling ARP monitoring...\n",
1104 ": %s: MII monitoring cannot be used with " 1053 bond->dev->name);
1105 "ARP monitoring. Disabling ARP monitoring...\n",
1106 bond->dev->name);
1107 bond->params.arp_interval = 0; 1054 bond->params.arp_interval = 0;
1108 bond->dev->priv_flags &= ~IFF_MASTER_ARPMON; 1055 bond->dev->priv_flags &= ~IFF_MASTER_ARPMON;
1109 if (bond->params.arp_validate) { 1056 if (bond->params.arp_validate) {
@@ -1171,17 +1118,15 @@ static ssize_t bonding_store_primary(struct device *d,
1171 write_lock_bh(&bond->curr_slave_lock); 1118 write_lock_bh(&bond->curr_slave_lock);
1172 1119
1173 if (!USES_PRIMARY(bond->params.mode)) { 1120 if (!USES_PRIMARY(bond->params.mode)) {
1174 pr_info(DRV_NAME 1121 pr_info("%s: Unable to set primary slave; %s is in mode %d\n",
1175 ": %s: Unable to set primary slave; %s is in mode %d\n", 1122 bond->dev->name, bond->dev->name, bond->params.mode);
1176 bond->dev->name, bond->dev->name, bond->params.mode);
1177 } else { 1123 } else {
1178 bond_for_each_slave(bond, slave, i) { 1124 bond_for_each_slave(bond, slave, i) {
1179 if (strnicmp 1125 if (strnicmp
1180 (slave->dev->name, buf, 1126 (slave->dev->name, buf,
1181 strlen(slave->dev->name)) == 0) { 1127 strlen(slave->dev->name)) == 0) {
1182 pr_info(DRV_NAME 1128 pr_info("%s: Setting %s as primary slave.\n",
1183 ": %s: Setting %s as primary slave.\n", 1129 bond->dev->name, slave->dev->name);
1184 bond->dev->name, slave->dev->name);
1185 bond->primary_slave = slave; 1130 bond->primary_slave = slave;
1186 strcpy(bond->params.primary, slave->dev->name); 1131 strcpy(bond->params.primary, slave->dev->name);
1187 bond_select_active_slave(bond); 1132 bond_select_active_slave(bond);
@@ -1192,15 +1137,13 @@ static ssize_t bonding_store_primary(struct device *d,
1192 /* if we got here, then we didn't match the name of any slave */ 1137 /* if we got here, then we didn't match the name of any slave */
1193 1138
1194 if (strlen(buf) == 0 || buf[0] == '\n') { 1139 if (strlen(buf) == 0 || buf[0] == '\n') {
1195 pr_info(DRV_NAME 1140 pr_info("%s: Setting primary slave to None.\n",
1196 ": %s: Setting primary slave to None.\n", 1141 bond->dev->name);
1197 bond->dev->name);
1198 bond->primary_slave = NULL; 1142 bond->primary_slave = NULL;
1199 bond_select_active_slave(bond); 1143 bond_select_active_slave(bond);
1200 } else { 1144 } else {
1201 pr_info(DRV_NAME 1145 pr_info("%s: Unable to set %.*s as primary slave as it is not a slave.\n",
1202 ": %s: Unable to set %.*s as primary slave as it is not a slave.\n", 1146 bond->dev->name, (int)strlen(buf) - 1, buf);
1203 bond->dev->name, (int)strlen(buf) - 1, buf);
1204 } 1147 }
1205 } 1148 }
1206out: 1149out:
@@ -1214,6 +1157,57 @@ static DEVICE_ATTR(primary, S_IRUGO | S_IWUSR,
1214 bonding_show_primary, bonding_store_primary); 1157 bonding_show_primary, bonding_store_primary);
1215 1158
1216/* 1159/*
1160 * Show and set the primary_reselect flag.
1161 */
1162static ssize_t bonding_show_primary_reselect(struct device *d,
1163 struct device_attribute *attr,
1164 char *buf)
1165{
1166 struct bonding *bond = to_bond(d);
1167
1168 return sprintf(buf, "%s %d\n",
1169 pri_reselect_tbl[bond->params.primary_reselect].modename,
1170 bond->params.primary_reselect);
1171}
1172
1173static ssize_t bonding_store_primary_reselect(struct device *d,
1174 struct device_attribute *attr,
1175 const char *buf, size_t count)
1176{
1177 int new_value, ret = count;
1178 struct bonding *bond = to_bond(d);
1179
1180 if (!rtnl_trylock())
1181 return restart_syscall();
1182
1183 new_value = bond_parse_parm(buf, pri_reselect_tbl);
1184 if (new_value < 0) {
1185 pr_err("%s: Ignoring invalid primary_reselect value %.*s.\n",
1186 bond->dev->name,
1187 (int) strlen(buf) - 1, buf);
1188 ret = -EINVAL;
1189 goto out;
1190 }
1191
1192 bond->params.primary_reselect = new_value;
1193 pr_info("%s: setting primary_reselect to %s (%d).\n",
1194 bond->dev->name, pri_reselect_tbl[new_value].modename,
1195 new_value);
1196
1197 read_lock(&bond->lock);
1198 write_lock_bh(&bond->curr_slave_lock);
1199 bond_select_active_slave(bond);
1200 write_unlock_bh(&bond->curr_slave_lock);
1201 read_unlock(&bond->lock);
1202out:
1203 rtnl_unlock();
1204 return ret;
1205}
1206static DEVICE_ATTR(primary_reselect, S_IRUGO | S_IWUSR,
1207 bonding_show_primary_reselect,
1208 bonding_store_primary_reselect);
1209
1210/*
1217 * Show and set the use_carrier flag. 1211 * Show and set the use_carrier flag.
1218 */ 1212 */
1219static ssize_t bonding_show_carrier(struct device *d, 1213static ssize_t bonding_show_carrier(struct device *d,
@@ -1234,20 +1228,18 @@ static ssize_t bonding_store_carrier(struct device *d,
1234 1228
1235 1229
1236 if (sscanf(buf, "%d", &new_value) != 1) { 1230 if (sscanf(buf, "%d", &new_value) != 1) {
1237 pr_err(DRV_NAME 1231 pr_err("%s: no use_carrier value specified.\n",
1238 ": %s: no use_carrier value specified.\n",
1239 bond->dev->name); 1232 bond->dev->name);
1240 ret = -EINVAL; 1233 ret = -EINVAL;
1241 goto out; 1234 goto out;
1242 } 1235 }
1243 if ((new_value == 0) || (new_value == 1)) { 1236 if ((new_value == 0) || (new_value == 1)) {
1244 bond->params.use_carrier = new_value; 1237 bond->params.use_carrier = new_value;
1245 pr_info(DRV_NAME ": %s: Setting use_carrier to %d.\n", 1238 pr_info("%s: Setting use_carrier to %d.\n",
1246 bond->dev->name, new_value); 1239 bond->dev->name, new_value);
1247 } else { 1240 } else {
1248 pr_info(DRV_NAME 1241 pr_info("%s: Ignoring invalid use_carrier value %d.\n",
1249 ": %s: Ignoring invalid use_carrier value %d.\n", 1242 bond->dev->name, new_value);
1250 bond->dev->name, new_value);
1251 } 1243 }
1252out: 1244out:
1253 return count; 1245 return count;
@@ -1292,8 +1284,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
1292 write_lock_bh(&bond->curr_slave_lock); 1284 write_lock_bh(&bond->curr_slave_lock);
1293 1285
1294 if (!USES_PRIMARY(bond->params.mode)) 1286 if (!USES_PRIMARY(bond->params.mode))
1295 pr_info(DRV_NAME ": %s: Unable to change active slave;" 1287 pr_info("%s: Unable to change active slave; %s is in mode %d\n",
1296 " %s is in mode %d\n",
1297 bond->dev->name, bond->dev->name, bond->params.mode); 1288 bond->dev->name, bond->dev->name, bond->params.mode);
1298 else { 1289 else {
1299 bond_for_each_slave(bond, slave, i) { 1290 bond_for_each_slave(bond, slave, i) {
@@ -1304,9 +1295,9 @@ static ssize_t bonding_store_active_slave(struct device *d,
1304 new_active = slave; 1295 new_active = slave;
1305 if (new_active == old_active) { 1296 if (new_active == old_active) {
1306 /* do nothing */ 1297 /* do nothing */
1307 pr_info(DRV_NAME 1298 pr_info("%s: %s is already the current active slave.\n",
1308 ": %s: %s is already the current active slave.\n", 1299 bond->dev->name,
1309 bond->dev->name, slave->dev->name); 1300 slave->dev->name);
1310 goto out; 1301 goto out;
1311 } 1302 }
1312 else { 1303 else {
@@ -1314,16 +1305,15 @@ static ssize_t bonding_store_active_slave(struct device *d,
1314 (old_active) && 1305 (old_active) &&
1315 (new_active->link == BOND_LINK_UP) && 1306 (new_active->link == BOND_LINK_UP) &&
1316 IS_UP(new_active->dev)) { 1307 IS_UP(new_active->dev)) {
1317 pr_info(DRV_NAME 1308 pr_info("%s: Setting %s as active slave.\n",
1318 ": %s: Setting %s as active slave.\n", 1309 bond->dev->name,
1319 bond->dev->name, slave->dev->name); 1310 slave->dev->name);
1320 bond_change_active_slave(bond, new_active); 1311 bond_change_active_slave(bond, new_active);
1321 } 1312 }
1322 else { 1313 else {
1323 pr_info(DRV_NAME 1314 pr_info("%s: Could not set %s as active slave; either %s is down or the link is down.\n",
1324 ": %s: Could not set %s as active slave; " 1315 bond->dev->name,
1325 "either %s is down or the link is down.\n", 1316 slave->dev->name,
1326 bond->dev->name, slave->dev->name,
1327 slave->dev->name); 1317 slave->dev->name);
1328 } 1318 }
1329 goto out; 1319 goto out;
@@ -1334,14 +1324,12 @@ static ssize_t bonding_store_active_slave(struct device *d,
1334 /* if we got here, then we didn't match the name of any slave */ 1324 /* if we got here, then we didn't match the name of any slave */
1335 1325
1336 if (strlen(buf) == 0 || buf[0] == '\n') { 1326 if (strlen(buf) == 0 || buf[0] == '\n') {
1337 pr_info(DRV_NAME 1327 pr_info("%s: Setting active slave to None.\n",
1338 ": %s: Setting active slave to None.\n",
1339 bond->dev->name); 1328 bond->dev->name);
1340 bond->primary_slave = NULL; 1329 bond->primary_slave = NULL;
1341 bond_select_active_slave(bond); 1330 bond_select_active_slave(bond);
1342 } else { 1331 } else {
1343 pr_info(DRV_NAME ": %s: Unable to set %.*s" 1332 pr_info("%s: Unable to set %.*s as active slave as it is not a slave.\n",
1344 " as active slave as it is not a slave.\n",
1345 bond->dev->name, (int)strlen(buf) - 1, buf); 1333 bond->dev->name, (int)strlen(buf) - 1, buf);
1346 } 1334 }
1347 } 1335 }
@@ -1502,6 +1490,7 @@ static struct attribute *per_bond_attrs[] = {
1502 &dev_attr_num_unsol_na.attr, 1490 &dev_attr_num_unsol_na.attr,
1503 &dev_attr_miimon.attr, 1491 &dev_attr_miimon.attr,
1504 &dev_attr_primary.attr, 1492 &dev_attr_primary.attr,
1493 &dev_attr_primary_reselect.attr,
1505 &dev_attr_use_carrier.attr, 1494 &dev_attr_use_carrier.attr,
1506 &dev_attr_active_slave.attr, 1495 &dev_attr_active_slave.attr,
1507 &dev_attr_mii_status.attr, 1496 &dev_attr_mii_status.attr,
@@ -1542,8 +1531,7 @@ int bond_create_sysfs(void)
1542 /* Is someone being kinky and naming a device bonding_master? */ 1531 /* Is someone being kinky and naming a device bonding_master? */
1543 if (__dev_get_by_name(&init_net, 1532 if (__dev_get_by_name(&init_net,
1544 class_attr_bonding_masters.attr.name)) 1533 class_attr_bonding_masters.attr.name))
1545 pr_err("network device named %s already " 1534 pr_err("network device named %s already exists in sysfs",
1546 "exists in sysfs",
1547 class_attr_bonding_masters.attr.name); 1535 class_attr_bonding_masters.attr.name);
1548 ret = 0; 1536 ret = 0;
1549 } 1537 }
@@ -1564,24 +1552,8 @@ void bond_destroy_sysfs(void)
1564 * Initialize sysfs for each bond. This sets up and registers 1552 * Initialize sysfs for each bond. This sets up and registers
1565 * the 'bondctl' directory for each individual bond under /sys/class/net. 1553 * the 'bondctl' directory for each individual bond under /sys/class/net.
1566 */ 1554 */
1567int bond_create_sysfs_entry(struct bonding *bond) 1555void bond_prepare_sysfs_group(struct bonding *bond)
1568{
1569 struct net_device *dev = bond->dev;
1570 int err;
1571
1572 err = sysfs_create_group(&(dev->dev.kobj), &bonding_group);
1573 if (err)
1574 pr_emerg("eek! didn't create group!\n");
1575
1576 return err;
1577}
1578/*
1579 * Remove sysfs entries for each bond.
1580 */
1581void bond_destroy_sysfs_entry(struct bonding *bond)
1582{ 1556{
1583 struct net_device *dev = bond->dev; 1557 bond->dev->sysfs_groups[0] = &bonding_group;
1584
1585 sysfs_remove_group(&(dev->dev.kobj), &bonding_group);
1586} 1558}
1587 1559
diff --git a/drivers/net/bonding/bonding.h b/drivers/net/bonding/bonding.h
index 68247714466f..257a7a4dfce9 100644
--- a/drivers/net/bonding/bonding.h
+++ b/drivers/net/bonding/bonding.h
@@ -23,15 +23,13 @@
23#include "bond_3ad.h" 23#include "bond_3ad.h"
24#include "bond_alb.h" 24#include "bond_alb.h"
25 25
26#define DRV_VERSION "3.5.0" 26#define DRV_VERSION "3.6.0"
27#define DRV_RELDATE "November 4, 2008" 27#define DRV_RELDATE "September 26, 2009"
28#define DRV_NAME "bonding" 28#define DRV_NAME "bonding"
29#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver" 29#define DRV_DESCRIPTION "Ethernet Channel Bonding Driver"
30 30
31#define BOND_MAX_ARP_TARGETS 16 31#define BOND_MAX_ARP_TARGETS 16
32 32
33extern struct list_head bond_dev_list;
34
35#define IS_UP(dev) \ 33#define IS_UP(dev) \
36 ((((dev)->flags & IFF_UP) == IFF_UP) && \ 34 ((((dev)->flags & IFF_UP) == IFF_UP) && \
37 netif_running(dev) && \ 35 netif_running(dev) && \
@@ -131,6 +129,7 @@ struct bond_params {
131 int lacp_fast; 129 int lacp_fast;
132 int ad_select; 130 int ad_select;
133 char primary[IFNAMSIZ]; 131 char primary[IFNAMSIZ];
132 int primary_reselect;
134 __be32 arp_targets[BOND_MAX_ARP_TARGETS]; 133 __be32 arp_targets[BOND_MAX_ARP_TARGETS];
135}; 134};
136 135
@@ -190,6 +189,7 @@ struct bonding {
190 struct slave *curr_active_slave; 189 struct slave *curr_active_slave;
191 struct slave *current_arp_slave; 190 struct slave *current_arp_slave;
192 struct slave *primary_slave; 191 struct slave *primary_slave;
192 bool force_primary;
193 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */ 193 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
194 rwlock_t lock; 194 rwlock_t lock;
195 rwlock_t curr_slave_lock; 195 rwlock_t curr_slave_lock;
@@ -197,14 +197,13 @@ struct bonding {
197 s8 send_grat_arp; 197 s8 send_grat_arp;
198 s8 send_unsol_na; 198 s8 send_unsol_na;
199 s8 setup_by_slave; 199 s8 setup_by_slave;
200 struct net_device_stats stats;
201#ifdef CONFIG_PROC_FS 200#ifdef CONFIG_PROC_FS
202 struct proc_dir_entry *proc_entry; 201 struct proc_dir_entry *proc_entry;
203 char proc_file_name[IFNAMSIZ]; 202 char proc_file_name[IFNAMSIZ];
204#endif /* CONFIG_PROC_FS */ 203#endif /* CONFIG_PROC_FS */
205 struct list_head bond_list; 204 struct list_head bond_list;
206 struct dev_mc_list *mc_list; 205 struct dev_mc_list *mc_list;
207 int (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int); 206 int (*xmit_hash_policy)(struct sk_buff *, int);
208 __be32 master_ip; 207 __be32 master_ip;
209 u16 flags; 208 u16 flags;
210 u16 rr_tx_counter; 209 u16 rr_tx_counter;
@@ -254,10 +253,14 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
254 253
255static inline bool bond_is_lb(const struct bonding *bond) 254static inline bool bond_is_lb(const struct bonding *bond)
256{ 255{
257 return bond->params.mode == BOND_MODE_TLB 256 return (bond->params.mode == BOND_MODE_TLB ||
258 || bond->params.mode == BOND_MODE_ALB; 257 bond->params.mode == BOND_MODE_ALB);
259} 258}
260 259
260#define BOND_PRI_RESELECT_ALWAYS 0
261#define BOND_PRI_RESELECT_BETTER 1
262#define BOND_PRI_RESELECT_FAILURE 2
263
261#define BOND_FOM_NONE 0 264#define BOND_FOM_NONE 0
262#define BOND_FOM_ACTIVE 1 265#define BOND_FOM_ACTIVE 1
263#define BOND_FOM_FOLLOW 2 266#define BOND_FOM_FOLLOW 2
@@ -321,12 +324,11 @@ static inline void bond_unset_master_alb_flags(struct bonding *bond)
321 324
322struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr); 325struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
323int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev); 326int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
324int bond_create(const char *name); 327int bond_create(struct net *net, const char *name);
325int bond_release_and_destroy(struct net_device *bond_dev, struct net_device *slave_dev); 328int bond_release_and_destroy(struct net_device *bond_dev, struct net_device *slave_dev);
326int bond_create_sysfs(void); 329int bond_create_sysfs(void);
327void bond_destroy_sysfs(void); 330void bond_destroy_sysfs(void);
328void bond_destroy_sysfs_entry(struct bonding *bond); 331void bond_prepare_sysfs_group(struct bonding *bond);
329int bond_create_sysfs_entry(struct bonding *bond);
330int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave); 332int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave);
331void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave); 333void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave);
332int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev); 334int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
@@ -341,13 +343,22 @@ void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
341void bond_register_arp(struct bonding *); 343void bond_register_arp(struct bonding *);
342void bond_unregister_arp(struct bonding *); 344void bond_unregister_arp(struct bonding *);
343 345
346struct bond_net {
347 struct net * net; /* Associated network namespace */
348 struct list_head dev_list;
349#ifdef CONFIG_PROC_FS
350 struct proc_dir_entry * proc_dir;
351#endif
352};
353
344/* exported from bond_main.c */ 354/* exported from bond_main.c */
345extern struct list_head bond_dev_list; 355extern int bond_net_id;
346extern const struct bond_parm_tbl bond_lacp_tbl[]; 356extern const struct bond_parm_tbl bond_lacp_tbl[];
347extern const struct bond_parm_tbl bond_mode_tbl[]; 357extern const struct bond_parm_tbl bond_mode_tbl[];
348extern const struct bond_parm_tbl xmit_hashtype_tbl[]; 358extern const struct bond_parm_tbl xmit_hashtype_tbl[];
349extern const struct bond_parm_tbl arp_validate_tbl[]; 359extern const struct bond_parm_tbl arp_validate_tbl[];
350extern const struct bond_parm_tbl fail_over_mac_tbl[]; 360extern const struct bond_parm_tbl fail_over_mac_tbl[];
361extern const struct bond_parm_tbl pri_reselect_tbl[];
351extern struct bond_parm_tbl ad_select_tbl[]; 362extern struct bond_parm_tbl ad_select_tbl[];
352 363
353#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) 364#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
@@ -370,4 +381,3 @@ static inline void bond_unregister_ipv6_notifier(void)
370#endif 381#endif
371 382
372#endif /* _LINUX_BONDING_H */ 383#endif /* _LINUX_BONDING_H */
373