aggr_lacp.c revision 898426033d8c1e142f65a89420550381abf52f94
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* IEEE 802.3ad Link Aggregation - LACP & Marker Protocol processing.
*/
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#include <sys/isa_defs.h>
#include <sys/aggr_impl.h>
static struct ether_addr etherzeroaddr = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*
* Slow_Protocol_Multicast address, as per IEEE 802.3ad spec.
*/
static struct ether_addr slow_multicast_addr = {
0x01, 0x80, 0xc2, 0x00, 0x00, 0x02
};
#ifdef DEBUG
/* LACP state machine debugging support */
static uint32_t aggr_lacp_debug = 0;
#else
#define AGGR_LACP_DBG(x) {}
#endif /* DEBUG */
#define NSECS_PER_SEC 1000000000ll
/* used by lacp_misconfig_walker() */
typedef struct lacp_misconfig_check_state_s {
static const char *lacp_receive_str[] = LACP_RECEIVE_STATE_STRINGS;
static const char *lacp_periodic_str[] = LACP_PERIODIC_STRINGS;
static const char *lacp_mux_str[] = LACP_MUX_STRINGS;
/*
* Maintains a list of all ports in ATTACHED state. This information
* is used to detect misconfiguration.
*/
typedef struct lacp_sel_ports {
/* Note: sp_partner_system must be 2-byte aligned */
struct ether_addr sp_partner_system;
struct lacp_sel_ports *sp_next;
static kmutex_t lacp_sel_lock;
static void periodic_timer_pop_locked(aggr_port_t *);
static void periodic_timer_pop(void *);
static void lacp_xmit_sm(aggr_port_t *);
static void lacp_periodic_sm(aggr_port_t *);
static void lacp_on(aggr_port_t *);
static void lacp_off(aggr_port_t *);
static void start_wait_while_timer(aggr_port_t *);
static void stop_wait_while_timer(aggr_port_t *);
static void lacp_reset_port(aggr_port_t *);
static void stop_current_while_timer(aggr_port_t *);
static void current_while_timer_pop(void *);
static void update_default_selected(aggr_port_t *);
static void lacp_sel_ports_del(aggr_port_t *);
void
aggr_lacp_init(void)
{
}
void
aggr_lacp_fini(void)
{
}
/*
* Set the port LACP state to SELECTED. Returns B_FALSE if the operation
* could not be performed due to a memory allocation error, B_TRUE otherwise.
*/
static boolean_t
{
if (!lacp_sel_ports_add(portp))
return (B_FALSE);
return (B_TRUE);
}
/*
* Set the port LACP state to UNSELECTED.
*/
static void
{
}
/*
* Initialize group specific LACP state and parameters.
*/
void
{
}
/*
* Complete LACP info initialization at port creation time.
*/
void
{
/* actor port # */
AGGR_LACP_DBG(("aggr_lacp_init_port(%s): "
pl->ActorPortNumber));
AGGR_LACP_DBG(("aggr_lacp_init_port(%s) "
"ActorAdminPortKey = 0x%x, ActorAdminPortKey = 0x%x\n",
/* Actor admin. port state */
/*
* Partner Administrative Information
* (All initialized to zero except for the following)
* Fast Timeouts.
*/
/*
* State machine information.
*/
/*
* Timer information.
*/
}
/*
* Port initialization when we need to
* reset like in the above routine.
* Do NOT modify things like link status.
*/
static void
{
/* reset operational port state */
/*
* State machine information.
*/
/*
* Timer information.
*/
}
static void
{
return;
(uchar_t *)&slow_multicast_addr);
}
static void
{
return;
(uchar_t *)&slow_multicast_addr);
}
static void
{
}
}
static void
{
}
}
/*
* When the timer pops, we arrive here to
* clear out LACPDU count as well as transmit an
* LACPDU. We then set the periodic state and let
* the periodic state machine restart the timer.
*/
static void
{
/* current timestamp */
/*
* Set Periodic State machine state based on the
* value of the Partner Operation Port State timeout
* bit.
*/
} else {
}
}
static void
periodic_timer_pop(void *data)
{
if (portp->lp_closing)
return;
}
/*
* Invoked from:
* - startup upon aggregation
* - when the periodic timer pops
* - when the periodic timer value is changed
* - when the port is attached or detached
* - when LACP mode is changed.
*/
static void
{
/* LACP_OFF state not in specification so check here. */
/* Stop timer whether it is running or not */
AGGR_LACP_DBG(("lacp_periodic_sm(%s):NO LACP "
return;
}
/* Stop timer whether it is running or not */
AGGR_LACP_DBG(("lacp_periodic_sm(%s):STOP %s--->%s\n",
return;
}
/*
* Startup with FAST_PERIODIC_TIME if no previous LACPDU
* has been received. Then after we timeout, then it is
* possible to go to SLOW_PERIODIC_TIME.
*/
/*
* If we receive a bit indicating we are going to
* fast periodic from slow periodic, stop the timer
* and let the periodic_timer_pop routine deal
* with reseting the periodic state and transmitting
* a LACPDU.
*/
}
/* Rearm timer with value provided by partner */
}
/*
* This routine transmits an LACPDU if lacp_enabled
* is TRUE and if NTT is set.
*/
static void
{
const mac_txinfo_t *mtp;
/* LACP_OFF state not in specification so check here. */
return;
/*
* Do nothing if LACP has been turned off or if the
* periodic state machine is not enabled.
*/
return;
}
/*
* If we have sent 5 Slow packets in the last second, avoid
* sending any more here. No more than three LACPDUs may be transmitted
* in any Fast_Periodic_Time interval.
*/
/*
* Grab the current time value and see if
* more than 1 second has passed. If so,
* reset the timestamp and clear the count.
*/
if (elapsed > NSECS_PER_SEC) {
} else {
return;
}
}
return;
/*
* Store the transmit info pointer locally in case it changes between
* loading mt_fn and mt_arg.
*/
}
/*
* Initialize the ethernet header of a LACP packet sent from the specified
* port.
*/
static void
{
}
static void
{
/*
* Actor Information
*/
/*
* Partner Information
*/
/* Collector Information */
/* Termination Information */
}
/*
* lacp_mux_sm - LACP mux state machine
* This state machine is invoked from:
* - startup upon aggregation
* - from the Selection logic
* - when the wait_while_timer pops
* - when the aggregation MAC address is changed
* - when receiving DL_NOTE_LINK_UP/DOWN
* - when receiving DL_NOTE_AGGR_AVAIL/UNAVAIL
* - when LACP mode is changed.
* - when a DL_NOTE_SPEED is received
*/
static void
{
/* LACP_OFF state not in specification so check here. */
AGGR_LACP_DBG(("trunk link: (%s): "
"Collector_Distributor Disabled.\n",
portp->lp_devname));
}
return;
}
/* determine next state, or return if state unchanged */
case LACP_DETACHED:
break;
}
break;
}
return;
case LACP_WAITING:
break;
}
break;
}
return;
case LACP_ATTACHED:
break;
}
break;
}
return;
break;
}
return;
}
AGGR_LACP_DBG(("lacp_mux_sm(%s):%s--->%s\n",
/* perform actions on entering a new state */
case LACP_DETACHED:
AGGR_LACP_DBG(("trunk link: (%s): "
"Collector_Distributor Disabled.\n",
portp->lp_devname));
}
/* Turn OFF Collector_Distributor */
break;
case LACP_WAITING:
break;
case LACP_ATTACHED:
AGGR_LACP_DBG(("trunk link: (%s): "
"Collector_Distributor Disabled.\n",
portp->lp_devname));
}
/* Turn OFF Collector_Distributor */
/*
* We had already received an updated sync from
* the partner. Attempt to transition to
* collecting/distributing now.
*/
goto again;
}
break;
AGGR_LACP_DBG(("trunk link: (%s): "
"Collector_Distributor Enabled.\n",
portp->lp_devname));
}
/* Turn Collector_Distributor back ON */
break;
}
/*
* If we updated the state of the NTT variable, then
* initiate a LACPDU transmission.
*/
if (NTT_updated) {
}
} /* lacp_mux_sm */
static void
{
const mac_txinfo_t *mtp;
AGGR_LACP_DBG(("trunk link: (%s): MARKER PDU received:\n",
portp->lp_devname));
/* LACP_OFF state not in specification so check here. */
goto bail;
goto bail;
AGGR_LACP_DBG(("trunk link (%s): Malformed MARKER PDU: "
"version = %d does not match s/w version %d\n",
goto bail;
}
/* We do not yet send out MARKER info PDUs */
AGGR_LACP_DBG(("trunk link (%s): MARKER RESPONSE PDU: "
" MARKER TLV = %d - We don't send out info type!\n",
goto bail;
}
AGGR_LACP_DBG(("trunk link (%s): Malformed MARKER PDU: "
markerp->tlv_marker));
goto bail;
}
AGGR_LACP_DBG(("trunk link (%s): Malformed MARKER PDU: "
markerp->marker_len));
goto bail;
}
AGGR_LACP_DBG(("trunk link (%s): MARKER PDU: "
" MARKER Port %d not equal to Partner port %d\n",
goto bail;
}
AGGR_LACP_DBG(("trunk link (%s): MARKER PDU: "
" MARKER MAC not equal to Partner MAC\n",
portp->lp_devname));
goto bail;
}
/*
* Turn into Marker Response PDU
* and return mblk to sending system
*/
/* reuse the space that was used by received ethernet header */
/*
* Store the transmit info pointer locally in case it changes between
* loading mt_fn and mt_arg.
*/
return;
bail:
}
/*
* Update the LACP mode (off, active, or passive) of the specified group.
*/
void
{
return;
(mode == AGGR_LACP_ACTIVE);
if (old_mode == AGGR_LACP_OFF) {
/* OFF -> {PASSIVE,ACTIVE} */
/* turn OFF Collector_Distributor */
} else if (mode == AGGR_LACP_OFF) {
/* {PASSIVE,ACTIVE} -> OFF */
if (!grp->lg_closing) {
/* Turn ON Collector_Distributor */
}
} else {
/* PASSIVE->ACTIVE or ACTIVE->PASSIVE */
/* kick off state machines */
}
if (grp->lg_closing)
break;
}
}
/*
* Update the LACP timer (short or long) of the specified group.
*/
void
{
return;
(timer == AGGR_LACP_TIMER_SHORT);
}
}
/*
* Sets the initial LACP mode (off, active, passive) and LACP timer
* (short, long) of the specified group.
*/
void
{
(mode == AGGR_LACP_ACTIVE);
(timer == AGGR_LACP_TIMER_SHORT);
/* Turn ON Collector_Distributor */
} else { /* LACP_ACTIVE/PASSIVE */
}
}
}
/*
* Verify that the Partner MAC and Key recorded by the specified
* port are not found in other ports that are not part of our
* aggregation. Returns B_TRUE if such a port is found, B_FALSE
* otherwise.
*/
static boolean_t
{
/* skip entries of the group of the port being checked */
continue;
/*
* The Partner port information is already in use
* by ports in another aggregation so disable this
* port.
*/
"%x:%x:%x:%x:%x:%x",
"MAC %s and key %d in use on aggregation "
cport->sp_devname);
break;
}
}
}
/*
* Remove the specified port from the list of selected ports.
*/
static void
{
MAXNAMELEN + 1) == 0) {
break;
}
}
return;
}
}
/*
* Add the specified port to the list of selected ports. Returns B_FALSE
* if the operation could not be performed due to an memory allocation
* error.
*/
static boolean_t
{
/* check if port is already in the list */
MAXNAMELEN + 1) == 0) {
return (B_TRUE);
}
}
/* create and initialize new entry */
return (B_FALSE);
}
return (B_TRUE);
}
/*
* lacp_selection_logic - LACP selection logic
* Sets the selected variable on a per port basis
* and sets Ready when all waiting ports are ready
* to go online.
*
* parameters:
* - portp - instance this applies to.
*
* invoked:
* - when initialization is needed
* - when UNSELECTED is set from the lacp_receive_sm() in LACP_CURRENT state
* - When the lacp_receive_sm goes to the LACP_DEFAULTED state
* - every time the wait_while_timer pops
*/
static void
{
int ports_waiting;
/* LACP_OFF state not in specification so check here. */
return;
}
AGGR_LACP_DBG(("lacp_selection_logic:(%s): "
"selected %d-->%d (begin=%d, lacp_enabled = %d, "
return;
}
/*
* If LACP is not enabled then selected is never set.
*/
AGGR_LACP_DBG(("lacp_selection_logic:(%s): selected %d-->%d\n",
return;
}
/*
* Check if the Partner MAC or Key are zero. If so, we have
* not received any LACP info or it has expired and the
* receive machine is in the LACP_DEFAULTED state.
*/
(pl->PartnerOperKey == 0)) {
ðerzeroaddr) != 0 &&
break;
}
/*
* If all ports have no key or aggregation address,
* then clear the negotiated Partner MAC and key.
*/
/* Clear the aggregation Partner MAC and key */
}
return;
}
/*
* Insure that at least one port in the aggregation
* matches the Partner aggregation MAC and key. If not,
* then clear the aggregation MAC and key. Later we will
* set the Partner aggregation MAC and key to that of the
* current port's Partner MAC and key.
*/
break;
}
/* Clear the aggregation Partner MAC and key */
}
}
/*
* If our Actor MAC is found in the Partner MAC
* on this port then we have a loopback misconfiguration.
*/
portp->lp_devname);
return;
}
/*
* If our Partner MAC and Key are found on any other
* ports that are not in our aggregation, we have
* a misconfiguration.
*/
if (lacp_misconfig_check(portp)) {
return;
}
/*
* If the Aggregation Partner MAC and Key have not been
* set, then this is either the first port or the aggregation
* MAC and key have been reset. In either case we must set
* the values of the Partner MAC and key.
*/
/* Set aggregation Partner MAC and key */
/*
* If we reset Partner aggregation MAC, then restart
* selection_logic on ports that match new MAC address.
*/
if (reset_mac) {
continue;
}
}
/*
* The Partner port information does not match
* that of the other ports in the aggregation
* so disable this port.
*/
" key (%d) incompatible with Aggregation Partner "
"MAC or key (%d)\n",
return;
}
/* If we get to here, automatically set selected */
AGGR_LACP_DBG(("lacp_selection_logic:(%s): "
if (!lacp_port_select(portp))
return;
}
/*
* From this point onward we have selected the port
* and are simply checking if the Ready flag should
* be set.
*/
/*
* If at least two ports are waiting to aggregate
* and ready_n is set on all ports waiting to aggregate
* then set READY for the aggregation.
*/
ports_waiting = 0;
/*
* If all ports in the aggregation have received compatible
* partner information and they match up correctly with the
* switch, there is no need to wait for all the
* wait_while_timers to pop.
*/
/* Add up ports uninitialized or waiting */
return;
}
}
}
AGGR_LACP_DBG(("lacp_selection_logic:(%s): "
} else {
AGGR_LACP_DBG(("lacp_selection_logic:(%s): Ready %d-->%d\n",
}
}
/*
* wait_while_timer_pop - When the timer pops, we arrive here to
* set ready_n and trigger the selection logic.
*/
static void
wait_while_timer_pop(void *data)
{
if (portp->lp_closing)
return;
AGGR_LACP_DBG(("trunk link:(%s): wait_while_timer pop \n",
portp->lp_devname));
}
static void
{
drv_usectohz(1000000 *
}
}
static void
{
}
}
/*
* Invoked when a port has been attached to a group.
* Complete the processing that couldn't be finished from lacp_on()
* because the port was not started. We know that the link is full
* duplex and ON, otherwise it wouldn't be attached.
*/
void
{
AGGR_LACP_DBG(("aggr_lacp_port_attached: port %s\n",
portp->lp_devname));
/* Turn ON Collector_Distributor */
return;
}
/* Turn OFF Collector_Distributor */
} else {
/* Enable Multicast Slow Protocol address */
/* periodic_sm is started up from the receive machine */
}
}
/*
* Invoked when a port has been detached from a group. Turn off
* LACP processing if it was enabled.
*/
void
{
AGGR_LACP_DBG(("aggr_lacp_port_detached: port %s\n",
portp->lp_devname));
return;
/* Disable Slow Protocol PDUs */
}
/*
* Invoked after the outbound port selection policy has been changed.
*/
void
{
/* suspend transmission for CollectorMaxDelay time */
}
/*
* Enable Slow Protocol LACP and Marker PDUs.
*/
static void
{
/*
* Reset the state machines and Partner operational
* information. Careful to not reset things like
* our link state.
*/
return;
/* Enable Multicast Slow Protocol address */
/* periodic_sm is started up from the receive machine */
} /* lacp_on */
/* Disable Slow Protocol LACP and Marker PDUs */
static void
{
/*
* Disable Slow Protocol Timers. We must temporarely release
* the group and port locks in order to avod deadlocks. Make
* sure that the port nor the group are closing after re-acquiring
* their locks.
*/
}
/* Turn OFF Collector_Distributor */
/* Disable Multicast Slow Protocol address */
}
static boolean_t
{
/*
* 43.4.12 - "a Receive machine shall not validate
* the Version Number, TLV_type, or Reserved fields in received
* LACPDUs."
* ... "a Receive machine may validate the Actor_Information_Length,
* Partner_Information_Length, Collector_Information_Length,
* or Terminator_Length fields."
*/
AGGR_LACP_DBG(("trunk link (%s): Malformed LACPDU: "
lacp->terminator_len));
return (B_FALSE);
}
return (B_TRUE);
}
static void
{
if (time > 0) {
} else {
}
}
}
static void
{
}
}
static void
current_while_timer_pop(void *data)
{
if (portp->lp_closing)
return;
AGGR_LACP_DBG(("trunk link:(%s): current_while_timer "
}
/*
* record_Default - Simply copies over administrative values
* to the partner operational values, and sets our state to indicate we
* are using defaulted values.
*/
static void
{
}
/* Returns B_TRUE on sync value changing */
static boolean_t
{
/*
* Partner Information
*/
/* All state info except for Synchronization */
/* Defaulted set to FALSE */
/*
* 43.4.9 - (Partner_Port, Partner_Port_Priority, Partner_system,
* Partner_System_Priority, Partner_Key, and
* Partner_State.Aggregation) are compared to the
* corresponding operations paramters values for
* the Actor. If these are equal, or if this is
* an individual link, we are synchronized.
*/
pl->ActorPortPriority) &&
} else {
}
AGGR_LACP_DBG(("record_PDU:(%s): partner sync "
return (B_TRUE);
} else {
return (B_FALSE);
}
}
/*
* update_selected - If any of the Partner parameters has
* changed from a previous value, then
* unselect the link from the aggregator.
*/
static boolean_t
{
(pl->PartnerOperSysPriority !=
AGGR_LACP_DBG(("update_selected:(%s): "
return (B_TRUE);
} else {
return (B_FALSE);
}
}
/*
* update_default_selected - If any of the operational Partner parameters
* is different than that of the administrative values
* then unselect the link from the aggregator.
*/
static void
{
AGGR_LACP_DBG(("update_default_selected:(%s): "
}
}
/*
* update_NTT - If any of the Partner values in the received LACPDU
* are different than that of the Actor operational
* values then set NTT to true.
*/
static void
{
(pl->ActorPortPriority !=
AGGR_LACP_DBG(("update_NTT:(%s): NTT %d-->%d\n",
}
}
/*
* lacp_receive_sm - LACP receive state machine
*
* parameters:
* - portp - instance this applies to.
* - lacp - pointer in the case of a received LACPDU.
* This value is NULL if there is no LACPDU.
*
* invoked:
* - when initialization is needed
* - upon reception of an LACPDU. This is the common case.
* - every time the current_while_timer pops
*/
static void
{
/* LACP_OFF state not in specification so check here. */
return;
/* figure next state */
}
}
AGGR_LACP_DBG(("lacp_receive_sm(%s):%s--->%s\n",
}
case LACP_INITIALIZE:
break;
case LACP_PORT_DISABLED:
/*
* Stop current_while_timer in case
* we got here from link down
*/
/* We goto LACP_DISABLED state */
break;
/*
* FALL THROUGH TO LACP_EXPIRED CASE:
* We have no way of knowing if we get into
* lacp_receive_sm() from a current_while_timer
* expiring as it has never been kicked off yet!
*/
} else {
/* We stay in LACP_PORT_DISABLED state */
break;
}
/* LACP_PORT_DISABLED -> LACP_EXPIRED */
/* FALLTHROUGH */
case LACP_EXPIRED:
/*
* Arrives here from LACP_PORT_DISABLED state as well as
* as well as current_while_timer expiring.
*/
break;
case LACP_DISABLED:
/*
* This is the normal state for recv_sm when LACP_OFF
* is set or the NIC is in half duplex mode.
*/
break;
case LACP_DEFAULTED:
/*
* Current_while_timer expired a second time.
*/
break;
case LACP_CURRENT:
/*
* Reception of LACPDU
*/
if (!lacp) /* no LACPDU so current_while_timer popped */
break;
AGGR_LACP_DBG(("lacp_receive_sm: (%s): LACPDU received:\n",
portp->lp_devname));
/*
* Validate Actor_Information_Length,
* Partner_Information_Length, Collector_Information_Length,
* and Terminator_Length fields.
*/
AGGR_LACP_DBG(("lacp_receive_sm (%s): "
"Invalid LACPDU received\n",
portp->lp_devname));
break;
}
if (selected_updated) {
} else if (sync_updated) {
}
/*
* If the periodic timer value bit has been modified
* or the partner activity bit has been changed then
* we need to respectively:
* - restart the timer with the proper timeout value.
*/
save_activity)) {
}
/* Check if we need to transmit an LACPDU */
break;
}
}
static void
{
}
static void
{
AGGR_LACP_DBG(("AGGR_SET_COLL_DIST_TYPE: (%s) %s\n",
if (!enable) {
/*
* Turn OFF Collector_Distributor.
*/
return;
}
/*
* Turn ON Collector_Distributor.
*/
/* Port is compatible and can be aggregated */
}
}
/*
* Process a received Marker or LACPDU.
*/
void
{
return;
}
case LACP_SUBTYPE:
AGGR_LACP_DBG(("aggr_lacp_rx:(%s): LACPDU received.\n",
portp->lp_devname));
break;
}
break;
case MARKER_SUBTYPE:
AGGR_LACP_DBG(("aggr_lacp_rx:(%s): Marker Packet received.\n",
portp->lp_devname));
break;
default:
AGGR_LACP_DBG(("aggr_lacp_rx: (%s): "
"Unknown Slow Protocol type %d\n",
break;
}
}