iPXE
Functions | Variables
eth_slow.c File Reference

Ethernet slow protocols. More...

#include <stdlib.h>
#include <string.h>
#include <byteswap.h>
#include <errno.h>
#include <ipxe/timer.h>
#include <ipxe/iobuf.h>
#include <ipxe/netdevice.h>
#include <ipxe/if_ether.h>
#include <ipxe/ethernet.h>
#include <ipxe/eth_slow.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static const char * eth_slow_lacp_tlv_name (uint8_t type)
 Name LACP TLV type.
static const char * eth_slow_marker_tlv_name (uint8_t type)
 Name marker TLV type.
static const char * eth_slow_lacp_state_name (uint8_t state)
 Name LACP state.
static void eth_slow_lacp_dump (struct io_buffer *iobuf, struct net_device *netdev, const char *label)
 Dump LACP packet.
static int eth_slow_lacp_rx (struct io_buffer *iobuf, struct net_device *netdev)
 Process incoming LACP packet.
static void eth_slow_marker_dump (struct io_buffer *iobuf, struct net_device *netdev, const char *label)
 Dump marker packet.
static int eth_slow_marker_rx (struct io_buffer *iobuf, struct net_device *netdev)
 Process incoming marker packet.
static int eth_slow_rx (struct io_buffer *iobuf, struct net_device *netdev, const void *ll_dest __unused, const void *ll_source __unused, unsigned int flags __unused)
 Process incoming slow packet.

Variables

struct net_protocol
eth_slow_protocol 
__net_protocol
 Slow protocol.
static const uint8_t eth_slow_address [ETH_ALEN]
 Slow protocols multicast address.

Detailed Description

Ethernet slow protocols.

We implement a very simple passive LACP entity, that pretends that each port is the only port on an individual system. We avoid the need for timeout logic (and retaining local state about our partner) by requesting the same timeout period (1s or 30s) as our partner requests, and then simply responding to every packet the partner sends us.

Definition in file eth_slow.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static const char* eth_slow_lacp_tlv_name ( uint8_t  type) [inline, static]

Name LACP TLV type.

Parameters:
typeLACP TLV type
Return values:
nameName of LACP TLV type

Definition at line 62 of file eth_slow.c.

References ETH_SLOW_TLV_LACP_ACTOR, ETH_SLOW_TLV_LACP_COLLECTOR, ETH_SLOW_TLV_LACP_PARTNER, and ETH_SLOW_TLV_TERMINATOR.

                                        {
        switch ( type ) {
        case ETH_SLOW_TLV_TERMINATOR:           return "terminator";
        case ETH_SLOW_TLV_LACP_ACTOR:           return "actor";
        case ETH_SLOW_TLV_LACP_PARTNER:         return "partner";
        case ETH_SLOW_TLV_LACP_COLLECTOR:       return "collector";
        default:                                return "<invalid>";
        }
}
static const char* eth_slow_marker_tlv_name ( uint8_t  type) [inline, static]

Name marker TLV type.

Parameters:
typeMarker TLV type
Return values:
nameName of marker TLV type

Definition at line 79 of file eth_slow.c.

References ETH_SLOW_TLV_MARKER_REQUEST, ETH_SLOW_TLV_MARKER_RESPONSE, and ETH_SLOW_TLV_TERMINATOR.

Referenced by eth_slow_marker_dump().

                                          {
        switch ( type ) {
        case ETH_SLOW_TLV_TERMINATOR:           return "terminator";
        case ETH_SLOW_TLV_MARKER_REQUEST:       return "request";
        case ETH_SLOW_TLV_MARKER_RESPONSE:      return "response";
        default:                                return "<invalid>";
        }
}
static const char* eth_slow_lacp_state_name ( uint8_t  state) [static]

Name LACP state.

Parameters:
stateLACP state
Return values:
nameLACP state name

Definition at line 94 of file eth_slow.c.

Referenced by eth_slow_lacp_dump().

                                                               {
        static char state_chars[] = "AFGSCDLX";
        unsigned int i;

        for ( i = 0 ; i < 8 ; i++ ) {
                state_chars[i] |= 0x20;
                if ( state & ( 1 << i ) )
                        state_chars[i] &= ~0x20;
        }
        return state_chars;
}
static void eth_slow_lacp_dump ( struct io_buffer iobuf,
struct net_device netdev,
const char *  label 
) [static]

Dump LACP packet.

Parameters:
iobufI/O buffer
netdevNetwork device
label"RX" or "TX"

Definition at line 113 of file eth_slow.c.

References eth_slow_lacp::actor, eth_slow_lacp::collector, io_buffer::data, DBGC, DBGC2_HDA, eth_ntoa(), eth_slow_lacp_state_name(), iob_len(), eth_slow_lacp_entity_tlv::key, eth_slow_packet::lacp, lacp, eth_slow_lacp_collector_tlv::max_delay, net_device::name, ntohs, eth_slow_lacp::partner, eth_slow_lacp_entity_tlv::port, eth_slow_lacp_entity_tlv::port_priority, eth_slow_lacp_entity_tlv::state, eth_slow_lacp_entity_tlv::system, and eth_slow_lacp_entity_tlv::system_priority.

Referenced by eth_slow_lacp_rx().

                                                     {
        union eth_slow_packet *eth_slow = iobuf->data;
        struct eth_slow_lacp *lacp = &eth_slow->lacp;

        DBGC ( netdev,
               "SLOW %s %s LACP actor (%04x,%s,%04x,%02x,%04x) [%s]\n",
               netdev->name, label, ntohs ( lacp->actor.system_priority ),
               eth_ntoa ( lacp->actor.system ),
               ntohs ( lacp->actor.key ),
               ntohs ( lacp->actor.port_priority ),
               ntohs ( lacp->actor.port ),
               eth_slow_lacp_state_name ( lacp->actor.state ) );
        DBGC ( netdev,
               "SLOW %s %s LACP partner (%04x,%s,%04x,%02x,%04x) [%s]\n",
               netdev->name, label, ntohs ( lacp->partner.system_priority ),
               eth_ntoa ( lacp->partner.system ),
               ntohs ( lacp->partner.key ),
               ntohs ( lacp->partner.port_priority ),
               ntohs ( lacp->partner.port ),
               eth_slow_lacp_state_name ( lacp->partner.state ) );
        DBGC ( netdev, "SLOW %s %s LACP collector %04x (%d us)\n",
               netdev->name, label, ntohs ( lacp->collector.max_delay ),
               ( ntohs ( lacp->collector.max_delay ) * 10 ) );
        DBGC2_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
}
static int eth_slow_lacp_rx ( struct io_buffer iobuf,
struct net_device netdev 
) [static]

Process incoming LACP packet.

Parameters:
iobufI/O buffer
netdevNetwork device
Return values:
rcReturn status code

Definition at line 148 of file eth_slow.c.

References eth_slow_lacp::actor, eth_slow_lacp::collector, io_buffer::data, DBGC, eth_slow_address, eth_slow_lacp_dump(), ETH_SLOW_LACP_VERSION, ETH_SLOW_TLV_LACP_ACTOR, ETH_SLOW_TLV_LACP_ACTOR_LEN, ETH_SLOW_TLV_LACP_COLLECTOR, ETH_SLOW_TLV_LACP_COLLECTOR_LEN, ETH_SLOW_TLV_LACP_PARTNER, ETH_SLOW_TLV_LACP_PARTNER_LEN, eth_slow_lacp::header, htons, eth_slow_lacp_entity_tlv::key, eth_slow_packet::lacp, lacp, LACP_INTERVAL_FAST, LACP_INTERVAL_SLOW, LACP_PORT_PRIORITY_MAX, LACP_STATE_AGGREGATABLE, LACP_STATE_COLLECTING, LACP_STATE_DISTRIBUTING, LACP_STATE_FAST, LACP_STATE_IN_SYNC, LACP_SYSTEM_PRIORITY_MAX, eth_slow_tlv_header::length, net_device::ll_addr, memcpy(), memset(), net_device::name, net_tx(), netdev_link_block(), netdev_link_blocked(), netdev_link_unblock(), eth_slow_lacp::partner, eth_slow_lacp_entity_tlv::port, eth_slow_lacp_entity_tlv::port_priority, eth_slow_lacp_entity_tlv::reserved, eth_slow_lacp::reserved, eth_slow_lacp_entity_tlv::state, eth_slow_lacp_entity_tlv::system, eth_slow_lacp_entity_tlv::system_priority, eth_slow_lacp::terminator, TICKS_PER_SEC, eth_slow_lacp_entity_tlv::tlv, eth_slow_lacp_collector_tlv::tlv, eth_slow_tlv_header::type, and eth_slow_header::version.

Referenced by eth_slow_rx().

                                                          {
        union eth_slow_packet *eth_slow = iobuf->data;
        struct eth_slow_lacp *lacp = &eth_slow->lacp;
        unsigned int interval;

        eth_slow_lacp_dump ( iobuf, netdev, "RX" );

        /* If partner is not in sync, collecting, and distributing,
         * then block the link until after the next expected LACP
         * packet.
         */
        if ( ~lacp->actor.state & ( LACP_STATE_IN_SYNC |
                                    LACP_STATE_COLLECTING |
                                    LACP_STATE_DISTRIBUTING ) ) {
                DBGC ( netdev, "SLOW %s LACP partner is down\n", netdev->name );
                interval = ( ( lacp->actor.state & LACP_STATE_FAST ) ?
                             ( ( LACP_INTERVAL_FAST + 1 ) * TICKS_PER_SEC ) :
                             ( ( LACP_INTERVAL_SLOW + 1 ) * TICKS_PER_SEC ) );
                netdev_link_block ( netdev, interval );
        } else {
                if ( netdev_link_blocked ( netdev ) ) {
                        DBGC ( netdev, "SLOW %s LACP partner is up\n",
                               netdev->name );
                }
                netdev_link_unblock ( netdev );
        }

        /* Build response */
        memset ( lacp->reserved, 0, sizeof ( lacp->reserved ) );
        memset ( &lacp->terminator, 0, sizeof ( lacp->terminator ) );
        memset ( &lacp->collector, 0, sizeof ( lacp->collector ) );
        lacp->collector.tlv.type = ETH_SLOW_TLV_LACP_COLLECTOR;
        lacp->collector.tlv.length = ETH_SLOW_TLV_LACP_COLLECTOR_LEN;
        memcpy ( &lacp->partner, &lacp->actor, sizeof ( lacp->partner ) );
        lacp->partner.tlv.type = ETH_SLOW_TLV_LACP_PARTNER;
        lacp->partner.tlv.length = ETH_SLOW_TLV_LACP_PARTNER_LEN;
        memset ( &lacp->partner.reserved, 0,
                 sizeof ( lacp->partner.reserved ) );
        memset ( &lacp->actor, 0, sizeof ( lacp->actor ) );
        lacp->actor.tlv.type = ETH_SLOW_TLV_LACP_ACTOR;
        lacp->actor.tlv.length = ETH_SLOW_TLV_LACP_ACTOR_LEN;
        lacp->actor.system_priority = htons ( LACP_SYSTEM_PRIORITY_MAX );
        memcpy ( lacp->actor.system, netdev->ll_addr,
                 sizeof ( lacp->actor.system ) );
        lacp->actor.key = htons ( 1 );
        lacp->actor.port_priority = htons ( LACP_PORT_PRIORITY_MAX );
        lacp->actor.port = htons ( 1 );
        lacp->actor.state = ( LACP_STATE_AGGREGATABLE |
                              LACP_STATE_IN_SYNC |
                              LACP_STATE_COLLECTING |
                              LACP_STATE_DISTRIBUTING |
                              ( lacp->partner.state & LACP_STATE_FAST ) );
        lacp->header.version = ETH_SLOW_LACP_VERSION;

        /* Send response */
        eth_slow_lacp_dump ( iobuf, netdev, "TX" );
        return net_tx ( iobuf, netdev, &eth_slow_protocol, eth_slow_address,
                        netdev->ll_addr );
}
static void eth_slow_marker_dump ( struct io_buffer iobuf,
struct net_device netdev,
const char *  label 
) [static]

Dump marker packet.

Parameters:
iobufI/O buffer
netdevNetwork device
label"RX" or "TX"

Definition at line 216 of file eth_slow.c.

References io_buffer::data, DBGC, DBGC2_HDA, eth_ntoa(), eth_slow_marker_tlv_name(), iob_len(), eth_slow_marker::marker, marker, eth_slow_packet::marker, net_device::name, ntohl, ntohs, eth_slow_marker_tlv::port, eth_slow_marker_tlv::system, eth_slow_marker_tlv::tlv, eth_slow_tlv_header::type, and eth_slow_marker_tlv::xact.

Referenced by eth_slow_marker_rx().

                                                       {
        union eth_slow_packet *eth_slow = iobuf->data;
        struct eth_slow_marker *marker = &eth_slow->marker;

        DBGC ( netdev, "SLOW %s %s marker %s port %04x system %s xact %08x\n",
               netdev->name, label,
               eth_slow_marker_tlv_name ( marker->marker.tlv.type ),
               ntohs ( marker->marker.port ),
               eth_ntoa ( marker->marker.system ),
               ntohl ( marker->marker.xact ) );
        DBGC2_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
}
static int eth_slow_marker_rx ( struct io_buffer iobuf,
struct net_device netdev 
) [static]

Process incoming marker packet.

Parameters:
iobufI/O buffer
netdevNetwork device
Return values:
rcReturn status code

Definition at line 238 of file eth_slow.c.

References io_buffer::data, EINVAL, eth_slow_address, eth_slow_marker_dump(), ETH_SLOW_TLV_MARKER_REQUEST, ETH_SLOW_TLV_MARKER_RESPONSE, free_iob(), net_device::ll_addr, eth_slow_marker::marker, marker, eth_slow_packet::marker, net_tx(), eth_slow_marker_tlv::tlv, and eth_slow_tlv_header::type.

Referenced by eth_slow_rx().

                                                            {
        union eth_slow_packet *eth_slow = iobuf->data;
        struct eth_slow_marker *marker = &eth_slow->marker;

        eth_slow_marker_dump ( iobuf, netdev, "RX" );

        if ( marker->marker.tlv.type == ETH_SLOW_TLV_MARKER_REQUEST ) {
                /* Send marker response */
                marker->marker.tlv.type = ETH_SLOW_TLV_MARKER_RESPONSE;
                eth_slow_marker_dump ( iobuf, netdev, "TX" );
                return net_tx ( iobuf, netdev, &eth_slow_protocol,
                                eth_slow_address, netdev->ll_addr );
        } else {
                /* Discard all other marker packets */
                free_iob ( iobuf );
                return -EINVAL;
        }
}
static int eth_slow_rx ( struct io_buffer iobuf,
struct net_device netdev,
const void *ll_dest  __unused,
const void *ll_source  __unused,
unsigned int flags  __unused 
) [static]

Process incoming slow packet.

Parameters:
iobufI/O buffer
netdevNetwork device
ll_destLink-layer destination address
ll_sourceLink-layer source address
flagsPacket flags
Return values:
rcReturn status code

Definition at line 268 of file eth_slow.c.

References io_buffer::data, DBGC, EINVAL, eth_slow_lacp_rx(), eth_slow_marker_rx(), ETH_SLOW_SUBTYPE_LACP, ETH_SLOW_SUBTYPE_MARKER, free_iob(), eth_slow_packet::header, iob_len(), net_device::name, and eth_slow_header::subtype.

                                                       {
        union eth_slow_packet *eth_slow = iobuf->data;

        /* Sanity checks */
        if ( iob_len ( iobuf ) < sizeof ( *eth_slow ) ) {
                free_iob ( iobuf );
                return -EINVAL;
        }

        /* Handle according to subtype */
        switch ( eth_slow->header.subtype ) {
        case ETH_SLOW_SUBTYPE_LACP:
                return eth_slow_lacp_rx ( iobuf, netdev );
        case ETH_SLOW_SUBTYPE_MARKER:
                return eth_slow_marker_rx ( iobuf, netdev );
        default:
                DBGC ( netdev, "SLOW %s RX unknown subtype %02x\n",
                       netdev->name, eth_slow->header.subtype );
                free_iob ( iobuf );
                return -EINVAL;
        }
}

Variable Documentation

struct net_protocol eth_slow_protocol __net_protocol
Initial value:
 {
        .name = "Slow",
        .net_proto = htons ( ETH_P_SLOW ),
        .rx = eth_slow_rx,
}

Slow protocol.

AoE protocol.

Definition at line 49 of file eth_slow.c.

Initial value:
        { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x02 }

Slow protocols multicast address.

Definition at line 52 of file eth_slow.c.

Referenced by eth_slow_lacp_rx(), and eth_slow_marker_rx().