iPXE
Defines | Functions | Variables
stp.c File Reference

Spanning Tree Protocol (STP) More...

#include <errno.h>
#include <byteswap.h>
#include <ipxe/netdevice.h>
#include <ipxe/ethernet.h>
#include <ipxe/iobuf.h>
#include <ipxe/timer.h>
#include <ipxe/stp.h>

Go to the source code of this file.

Defines

#define ENOTSUP_PROTOCOL   __einfo_error ( EINFO_ENOTSUP_PROTOCOL )
#define EINFO_ENOTSUP_PROTOCOL
#define ENOTSUP_VERSION   __einfo_error ( EINFO_ENOTSUP_VERSION )
#define EINFO_ENOTSUP_VERSION
#define ENOTSUP_TYPE   __einfo_error ( EINFO_ENOTSUP_TYPE )
#define EINFO_ENOTSUP_TYPE

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int stp_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 STP packets.
static const char * stp_ntoa (const void *net_addr __unused)
 Transcribe STP address.

Variables

struct net_protocol stp_protocol __net_protocol
 STP network protocol.

Detailed Description

Spanning Tree Protocol (STP)

Definition in file stp.c.


Define Documentation

Definition at line 41 of file stp.c.

Referenced by stp_rx().

Value:
__einfo_uniqify ( EINFO_ENOTSUP, 0x02,                  \
                          "Non-STP packet received" )

Definition at line 42 of file stp.c.

Definition at line 45 of file stp.c.

Referenced by stp_rx().

Value:
__einfo_uniqify ( EINFO_ENOTSUP, 0x03,                  \
                          "Legacy STP packet received" )

Definition at line 46 of file stp.c.

Definition at line 49 of file stp.c.

Referenced by stp_rx().

Value:
__einfo_uniqify ( EINFO_ENOTSUP, 0x04,                  \
                          "Non-RSTP packet received" )

Definition at line 50 of file stp.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int stp_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 STP packets.

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

Definition at line 63 of file stp.c.

References io_buffer::data, DBGC, DBGC2, DBGC_HDA, stp_bpdu::delay, done, EINVAL, ENETUNREACH, ENOTSUP_PROTOCOL, ENOTSUP_TYPE, ENOTSUP_VERSION, eth_ntoa(), stp_bpdu::flags, free_iob(), stp_bpdu::hello, hello, htons, iob_len(), stp_switch::mac, net_device::name, netdev_link_block(), netdev_link_blocked(), netdev_link_unblock(), ntohs, stp_bpdu::port, stp_bpdu::protocol, rc, stp_bpdu::sender, STP_FL_FORWARDING, STP_PROTOCOL, STP_TYPE_RSTP, STP_VERSION_RSTP, TICKS_PER_SEC, stp_bpdu::type, and stp_bpdu::version.

                                                  {
        struct stp_bpdu *stp;
        unsigned int hello;
        int rc;

        /* Sanity check */
        if ( iob_len ( iobuf ) < sizeof ( *stp ) ) {
                DBGC ( netdev, "STP %s received underlength packet (%zd "
                       "bytes):\n", netdev->name, iob_len ( iobuf ) );
                DBGC_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
                rc = -EINVAL;
                goto done;
        }
        stp = iobuf->data;

        /* Ignore non-RSTP packets */
        if ( stp->protocol != htons ( STP_PROTOCOL ) ) {
                DBGC ( netdev, "STP %s ignoring non-STP packet (protocol "
                       "%#04x)\n", netdev->name, ntohs ( stp->protocol ) );
                rc = -ENOTSUP_PROTOCOL;
                goto done;
        }
        if ( stp->version < STP_VERSION_RSTP ) {
                DBGC ( netdev, "STP %s received legacy STP packet (version "
                       "%#02x)\n", netdev->name, stp->version );
                rc = -ENOTSUP_VERSION;
                goto done;
        }
        if ( stp->type != STP_TYPE_RSTP ) {
                DBGC ( netdev, "STP %s received non-RSTP packet (type %#02x)\n",
                       netdev->name, stp->type );
                rc = -ENOTSUP_TYPE;
                goto done;
        }

        /* Dump information */
        DBGC2 ( netdev, "STP %s %s port %#04x flags %#02x hello %d delay %d\n",
                netdev->name, eth_ntoa ( stp->sender.mac ), ntohs ( stp->port ),
                stp->flags, ntohs ( stp->hello ), ntohs ( stp->delay ) );

        /* Check if port is forwarding */
        if ( ! ( stp->flags & STP_FL_FORWARDING ) ) {
                /* Port is not forwarding: block link for two hello times */
                DBGC ( netdev, "STP %s %s port %#04x flags %#02x is not "
                       "forwarding\n",
                       netdev->name, eth_ntoa ( stp->sender.mac ),
                       ntohs ( stp->port ), stp->flags );
                hello = ( ntohs ( stp->hello ) * ( TICKS_PER_SEC / 256 ) );
                netdev_link_block ( netdev, ( hello * 2 ) );
                rc = -ENETUNREACH;
                goto done;
        }

        /* Success */
        if ( netdev_link_blocked ( netdev ) ) {
                DBGC ( netdev, "STP %s %s port %#04x flags %#02x is "
                       "forwarding\n",
                       netdev->name, eth_ntoa ( stp->sender.mac ),
                       ntohs ( stp->port ), stp->flags );
        }
        netdev_link_unblock ( netdev );
        rc = 0;

 done:
        free_iob ( iobuf );
        return rc;
}
static const char* stp_ntoa ( const void *net_addr  __unused) [static]

Transcribe STP address.

Parameters:
net_addrSTP address
Return values:
string"<STP>"

This operation is meaningless for the STP protocol.

Definition at line 142 of file stp.c.

                                                               {
        return "<STP>";
}

Variable Documentation

struct net_protocol stp_protocol __net_protocol
Initial value:
 {
        .name = "STP",
        .net_proto = htons ( ETH_P_STP ),
        .rx = stp_rx,
        .ntoa = stp_ntoa,
}

STP network protocol.

AoE protocol.

Definition at line 147 of file stp.c.