iPXE
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.

Macros

#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)
 FILE_SECBOOT (PERMITTED)
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.

Macro Definition Documentation

◆ ENOTSUP_PROTOCOL

#define ENOTSUP_PROTOCOL   __einfo_error ( EINFO_ENOTSUP_PROTOCOL )

Definition at line 42 of file stp.c.

Referenced by stp_rx().

◆ EINFO_ENOTSUP_PROTOCOL

#define EINFO_ENOTSUP_PROTOCOL
Value:
"Non-STP packet received" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition errno.h:181
#define EINFO_ENOTSUP
Definition errno.h:591

Definition at line 43 of file stp.c.

43#define EINFO_ENOTSUP_PROTOCOL \
44 __einfo_uniqify ( EINFO_ENOTSUP, 0x02, \
45 "Non-STP packet received" )

◆ ENOTSUP_VERSION

#define ENOTSUP_VERSION   __einfo_error ( EINFO_ENOTSUP_VERSION )

Definition at line 46 of file stp.c.

Referenced by stp_rx(), and tls_new_server_hello().

◆ EINFO_ENOTSUP_VERSION

#define EINFO_ENOTSUP_VERSION
Value:
"Legacy STP packet received" )

Definition at line 47 of file stp.c.

47#define EINFO_ENOTSUP_VERSION \
48 __einfo_uniqify ( EINFO_ENOTSUP, 0x03, \
49 "Legacy STP packet received" )

◆ ENOTSUP_TYPE

#define ENOTSUP_TYPE   __einfo_error ( EINFO_ENOTSUP_TYPE )

Definition at line 50 of file stp.c.

Referenced by cms_parse_content_type(), and stp_rx().

◆ EINFO_ENOTSUP_TYPE

#define EINFO_ENOTSUP_TYPE
Value:
"Non-RSTP packet received" )

Definition at line 51 of file stp.c.

51#define EINFO_ENOTSUP_TYPE \
52 __einfo_uniqify ( EINFO_ENOTSUP, 0x04, \
53 "Non-RSTP packet received" )

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ stp_rx()

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 64 of file stp.c.

67 {
68 struct stp_bpdu *stp;
69 unsigned int hello;
70 int rc;
71
72 /* Sanity check */
73 if ( iob_len ( iobuf ) < sizeof ( *stp ) ) {
74 DBGC ( netdev, "STP %s received underlength packet (%zd "
75 "bytes):\n", netdev->name, iob_len ( iobuf ) );
76 DBGC_HDA ( netdev, 0, iobuf->data, iob_len ( iobuf ) );
77 rc = -EINVAL;
78 goto done;
79 }
80 stp = iobuf->data;
81
82 /* Ignore non-RSTP packets */
83 if ( stp->protocol != htons ( STP_PROTOCOL ) ) {
84 DBGC ( netdev, "STP %s ignoring non-STP packet (protocol "
85 "%#04x)\n", netdev->name, ntohs ( stp->protocol ) );
87 goto done;
88 }
89 if ( stp->version < STP_VERSION_RSTP ) {
90 DBGC ( netdev, "STP %s received legacy STP packet (version "
91 "%#02x)\n", netdev->name, stp->version );
93 goto done;
94 }
95 if ( stp->type != STP_TYPE_RSTP ) {
96 DBGC ( netdev, "STP %s received non-RSTP packet (type %#02x)\n",
97 netdev->name, stp->type );
99 goto done;
100 }
101
102 /* Dump information */
103 DBGC2 ( netdev, "STP %s %s port %#04x flags %#02x hello %d delay %d\n",
104 netdev->name, eth_ntoa ( stp->sender.mac ), ntohs ( stp->port ),
105 stp->flags, ntohs ( stp->hello ), ntohs ( stp->delay ) );
106
107 /* Check if port is forwarding */
108 if ( ! ( stp->flags & STP_FL_FORWARDING ) ) {
109 /* Port is not forwarding: block link for two hello times */
110 DBGC ( netdev, "STP %s %s port %#04x flags %#02x is not "
111 "forwarding\n",
112 netdev->name, eth_ntoa ( stp->sender.mac ),
113 ntohs ( stp->port ), stp->flags );
114 hello = ( ntohs ( stp->hello ) * ( TICKS_PER_SEC / 256 ) );
115 netdev_link_block ( netdev, ( hello * 2 ) );
116 rc = -ENETUNREACH;
117 goto done;
118 }
119
120 /* Success */
121 if ( netdev_link_blocked ( netdev ) ) {
122 DBGC ( netdev, "STP %s %s port %#04x flags %#02x is "
123 "forwarding\n",
124 netdev->name, eth_ntoa ( stp->sender.mac ),
125 ntohs ( stp->port ), stp->flags );
126 }
128 rc = 0;
129
130 done:
131 free_iob ( iobuf );
132 return rc;
133}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
struct bofm_section_header done
Definition bofm_test.c:46
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition ethernet.c:176
static struct net_device * netdev
Definition gdbudp.c:53
#define DBGC2(...)
Definition compiler.h:522
#define DBGC(...)
Definition compiler.h:505
#define DBGC_HDA(...)
Definition compiler.h:506
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENETUNREACH
Network unreachable.
Definition errno.h:489
#define htons(value)
Definition byteswap.h:136
#define ntohs(value)
Definition byteswap.h:137
#define TICKS_PER_SEC
Number of ticks per second.
Definition timer.h:16
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
void netdev_link_block(struct net_device *netdev, unsigned long timeout)
Mark network device link as being blocked.
Definition netdevice.c:248
void netdev_link_unblock(struct net_device *netdev)
Mark network device link as being unblocked.
Definition netdevice.c:263
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition netdevice.h:651
#define ENOTSUP_VERSION
Definition stp.c:46
#define ENOTSUP_PROTOCOL
Definition stp.c:42
#define ENOTSUP_TYPE
Definition stp.c:50
#define STP_FL_FORWARDING
Port is forwarding.
Definition stp.h:75
uint16_t hello
Hello time.
Definition stp.h:27
#define STP_VERSION_RSTP
Rapid Spanning Tree protocol version.
Definition stp.h:69
#define STP_PROTOCOL
Spanning Tree protocol ID.
Definition stp.h:66
#define STP_TYPE_RSTP
Rapid Spanning Tree bridge PDU type.
Definition stp.h:72
void * data
Start of data.
Definition iobuf.h:53
A Spanning Tree bridge protocol data unit.
Definition stp.h:32
uint8_t type
Message type.
Definition stp.h:44
uint16_t protocol
Protocol ID.
Definition stp.h:40
struct stp_switch sender
Sender switch.
Definition stp.h:52
uint8_t flags
Flags.
Definition stp.h:46
uint16_t hello
Hello time.
Definition stp.h:60
uint16_t delay
Forward delay.
Definition stp.h:62
uint8_t version
Protocol version.
Definition stp.h:42
uint16_t port
Port.
Definition stp.h:54
uint8_t mac[ETH_ALEN]
MAC address.
Definition stp.h:28

References __unused, io_buffer::data, DBGC, DBGC2, DBGC_HDA, stp_bpdu::delay, done, EINVAL, ENETUNREACH, ENOTSUP_PROTOCOL, ENOTSUP_TYPE, ENOTSUP_VERSION, eth_ntoa(), flags, stp_bpdu::flags, free_iob(), hello, stp_bpdu::hello, htons, iob_len(), stp_switch::mac, netdev, 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.

◆ stp_ntoa()

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 143 of file stp.c.

143 {
144 return "<STP>";
145}

References __unused.

Variable Documentation

◆ __net_protocol

struct net_protocol stp_protocol __net_protocol
Initial value:
= {
.name = "STP",
.net_proto = htons ( ETH_P_STP ),
.rx = stp_rx,
.ntoa = stp_ntoa,
}
static const char * stp_ntoa(const void *net_addr __unused)
Transcribe STP address.
Definition stp.c:143
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.
Definition stp.c:64
#define ETH_P_STP
"Protocol" value for STP
Definition stp.h:21

STP network protocol.

AoE protocol.

Definition at line 148 of file stp.c.

148 {
149 .name = "STP",
150 .net_proto = htons ( ETH_P_STP ),
151 .rx = stp_rx,
152 .ntoa = stp_ntoa,
153};