When an 802.3ad (LACP) bonding interface has no slaves in the collecting/distributing state, the bonding master may still report carrier as up. In this situation, no slave is actually able to transmit or receive traffic. As a result, upper-layer daemons consider the interface operational while traffic is effectively blackholed. Fix this by asserting carrier only when at least 'min_links' slaves are in the collecting/distributing state (or collecting only if the coupled_control default behavior is disabled). Fixes: 655f8919d549 ("bonding: add min links parameter to 802.3ad") Signed-off-by: Louis Scalbert --- drivers/net/bonding/bond_3ad.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index af7f74cfdc08..6d3613755d45 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -745,6 +745,22 @@ static void __set_agg_ports_ready(struct aggregator *aggregator, int val) } } +static int __agg_valid_ports(struct aggregator *agg) +{ + struct port *port; + int valid = 0; + + for (port = agg->lag_ports; port; + port = port->next_port_in_aggregator) { + if (port->actor_oper_port_state & LACP_STATE_COLLECTING && + (!port->slave->bond->params.coupled_control || + port->actor_oper_port_state & LACP_STATE_DISTRIBUTING)) + valid++; + } + + return valid; +} + static int __agg_active_ports(struct aggregator *agg) { struct port *port; @@ -2120,6 +2136,7 @@ static void ad_enable_collecting_distributing(struct port *port, port->actor_port_number, port->aggregator->aggregator_identifier); __enable_port(port); + bond_3ad_set_carrier(port->slave->bond); /* Slave array needs update */ *update_slave_arr = true; /* Should notify peers if possible */ @@ -2141,6 +2158,7 @@ static void ad_disable_collecting_distributing(struct port *port, port->actor_port_number, port->aggregator->aggregator_identifier); __disable_port(port); + bond_3ad_set_carrier(port->slave->bond); /* Slave array needs an update */ *update_slave_arr = true; } @@ -2819,8 +2837,10 @@ int bond_3ad_set_carrier(struct bonding *bond) } active = __get_active_agg(&(SLAVE_AD_INFO(first_slave)->aggregator)); if (active) { - /* are enough slaves available to consider link up? */ - if (__agg_active_ports(active) < bond->params.min_links) { + /* are enough slaves in collecting (and distributing) state to consider + * link up? + */ + if (__agg_valid_ports(active) < bond->params.min_links) { if (netif_carrier_ok(bond->dev)) { netif_carrier_off(bond->dev); goto out; -- 2.39.2 When the bonding interface has carrier down due to the absence of valid slaves and a slave transitions from down to up, the bonding interface briefly goes carrier up, then down again, and finally up once LACP negotiates collecting and distributing on the port. The interface should not transition to carrier up until LACP negotiation is complete. This happens because the actor and partner port states remain in collecting (and distributing) when the port goes down. When the port comes back up, it temporarily remains in this state until LACP renegotiation occurs. Previously this was mostly cosmetic, but since the bonding carrier state now depends on the LACP negotiation state, it causes the interface to flap. Fix this by unsetting the SELECTED flag when a port goes down so that the mux state machine transitions through ATTACHED and DETACHED, which clears the actor collecting and distributing flags. Do not attempt to set the SELECTED flag if the port is still disabled. Fixes: 655f8919d549 ("bonding: add min links parameter to 802.3ad") Signed-off-by: Louis Scalbert --- drivers/net/bonding/bond_3ad.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 6d3613755d45..1771e406224c 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -1570,6 +1570,12 @@ static void ad_port_selection_logic(struct port *port, bool *update_slave_arr) struct slave *slave; int found = 0; + /* Disabled ports cannot be SELECTED. + * Do not attempt to set the SELECTED flag if the port is still disabled. + */ + if (!port->is_enabled) + return; + /* if the port is already Selected, do nothing */ if (port->sm_vars & AD_PORT_SELECTED) return; @@ -2794,6 +2800,7 @@ void bond_3ad_handle_link_change(struct slave *slave, char link) /* link has failed */ port->is_enabled = false; ad_update_actor_keys(port, true); + port->sm_vars &= ~AD_PORT_SELECTED; } agg = __get_first_agg(port); ad_agg_selection_logic(agg, &dummy); -- 2.39.2 The previous commit introduced a side effect caused by clearing the SELECTED flag on disabled ports. After all ports in an aggregator go down, if only a subset of ports comes back up, those ports can no longer renegotiate LACP unless all aggregator ports come back up. 1. All aggregator ports go down - The SELECTED flag is cleared on all of them. 2. One port comes back up - Its SELECTED flag is set again. - It enters the WAITING state and gets its READY_N flag. - The remaining ports stay UNSELECTED. Because of that, they cannot enter the WAITING state and therefore never get READY_N. - __agg_ports_are_ready() returns 0 because it finds a port without READY_N. - As a result, __set_agg_ports_ready() keeps the READY flag cleared on all ports. - The port that came back up is therefore not marked READY and cannot transition to ATTACHED. - LACP negotiation becomes stuck, and the port cannot be used. 3. All aggregator ports come back up - They all regain SELECTED and READY_N. - __agg_ports_are_ready() now returns 1. - __set_agg_ports_ready() sets READY on all ports. - They can then transition to ATTACHED. - Negotiation resumes and the aggregator becomes operational again. Consider only ports currently in the WAITING mux state for READY_N in order to avoid __agg_ports_are_ready() to return 0 because of a disabled port. That matches 802.3ad, which states: "The Selection Logic asserts Ready TRUE when the values of Ready_N for all ports that are waiting to attach to a given Aggregator are TRUE.". Fixes: 655f8919d549 ("bonding: add min links parameter to 802.3ad") Signed-off-by: Louis Scalbert --- drivers/net/bonding/bond_3ad.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c index 1771e406224c..86657de7143d 100644 --- a/drivers/net/bonding/bond_3ad.c +++ b/drivers/net/bonding/bond_3ad.c @@ -700,7 +700,8 @@ static void __update_ntt(struct lacpdu *lacpdu, struct port *port) } /** - * __agg_ports_are_ready - check if all ports in an aggregator are ready + * __agg_ports_are_ready - check if all ports in an aggregator that are in + * the WAITING state are ready * @aggregator: the aggregator we're looking at * */ @@ -716,6 +717,8 @@ static int __agg_ports_are_ready(struct aggregator *aggregator) for (port = aggregator->lag_ports; port; port = port->next_port_in_aggregator) { + if (port->sm_mux_state != AD_MUX_WAITING) + continue; if (!(port->sm_vars & AD_PORT_READY_N)) { retval = 0; break; -- 2.39.2