From 677536dd7433a814936427908d5adda45a33bff0 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Tue, 13 Oct 2026 03:24:55 +0200 Subject: [PATCH 1/3] lldp: send the port id as an interface name The Port ID TLV carried a single digit with the locally assigned subtype, so a neighbour listed us as port "3". Send "Port 3" with the interface name subtype instead, the form the port keeps in the CLI and the web UI. --- rtl837x_lldp.c | 2 ++ rtl837x_lldp.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rtl837x_lldp.c b/rtl837x_lldp.c index 84208433..3eb644ea 100644 --- a/rtl837x_lldp.c +++ b/rtl837x_lldp.c @@ -76,6 +76,8 @@ void lldp_send(void) __banked __reentrant *p++ = LLDP_TYPE(LLDP_PORT_ID_TLV_TYPE); *p++ = LLDP_PORT_ID_TLV_LENGTH; *p++ = LLDP_PORT_ID_TLV_SUBTYPE; + memcpyc(p, LLDP_PORT_ID_PREFIX, LLDP_PORT_ID_PREFIX_LENGTH); + p += LLDP_PORT_ID_PREFIX_LENGTH; port_position = (p-LLDP_O->payload); *p++ = '0'; // filled in per port below diff --git a/rtl837x_lldp.h b/rtl837x_lldp.h index 298775c6..4a48e121 100644 --- a/rtl837x_lldp.h +++ b/rtl837x_lldp.h @@ -11,8 +11,10 @@ #define LLDP_TX_INTERVAL_TICKS 6000 #define LLDP_PORT_ID_TLV_TYPE 2 -#define LLDP_PORT_ID_TLV_LENGTH 0x02 -#define LLDP_PORT_ID_TLV_SUBTYPE 0x07 +#define LLDP_PORT_ID_PREFIX "Port " +#define LLDP_PORT_ID_PREFIX_LENGTH 5 +#define LLDP_PORT_ID_TLV_LENGTH (1 + LLDP_PORT_ID_PREFIX_LENGTH + 1) +#define LLDP_PORT_ID_TLV_SUBTYPE 0x05 #define LLDP_TTL_TLV_TYPE 3 #define LLDP_TTL_TLV_LENGTH 2 From 0e2d9407659ddcb2e07e843afab386e28daeaea3 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Tue, 13 Oct 2026 03:25:53 +0200 Subject: [PATCH 2/3] lldp: advertise system capabilities and the management address Neighbours could not tell a bridge from a host and had no address to reach us on. Add the System Capabilities TLV (bridge, enabled) and a Management Address TLV with the IPv4 address, left out while the address is still 0.0.0.0. Size the payload buffer for the frame it can now hold: 64 bytes did not cover a 23 character hostname next to the longer model names. --- rtl837x_lldp.c | 26 +++++++++++++++++++++++++- rtl837x_lldp.h | 12 ++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/rtl837x_lldp.c b/rtl837x_lldp.c index 3eb644ea..590e15b2 100644 --- a/rtl837x_lldp.c +++ b/rtl837x_lldp.c @@ -42,7 +42,7 @@ struct lldp_pkt { struct rtl_tag rtl_tag; uint16_t ether_type; - uint8_t payload[64]; + uint8_t payload[LLDP_MAX_PAYLOAD]; }; #define LLDP_O ((__xdata struct lldp_pkt *)&uip_buf[RTL_FRAME_DESC_SIZE]) @@ -90,6 +90,30 @@ void lldp_send(void) __banked __reentrant p += lldp_sysname(p); p += lldp_sysdesc(p); + //System Capabilities: supported, enabled + *p++ = LLDP_TYPE(LLDP_CAPABILITIES_TLV_TYPE); + *p++ = LLDP_CAPABILITIES_TLV_LENGTH; + *p++ = LLDP_CAPABILITY_BRIDGE >> 8; + *p++ = LLDP_CAPABILITY_BRIDGE & 0xff; + *p++ = LLDP_CAPABILITY_BRIDGE >> 8; + *p++ = LLDP_CAPABILITY_BRIDGE & 0xff; + + //Management Address: IPv4 + if (uip_hostaddr[0] | uip_hostaddr[1]) { + *p++ = LLDP_TYPE(LLDP_MGMT_ADDR_TLV_TYPE); + *p++ = LLDP_MGMT_ADDR_TLV_LENGTH; + *p++ = LLDP_MGMT_ADDR_STR_LENGTH; + *p++ = LLDP_MGMT_ADDR_SUBTYPE_IPV4; + memcpy(p, (__xdata uint8_t *)uip_hostaddr, sizeof(uip_ipaddr_t)); + p += sizeof(uip_ipaddr_t); + *p++ = LLDP_MGMT_IF_NUMBERING_UNKNOWN; + *p++ = 0; //interface number + *p++ = 0; + *p++ = 0; + *p++ = 0; + *p++ = 0; //OID length + } + // End of LLDPDU TLV *p++ = 0x00; //padding *p++ = 0x00; //padding diff --git a/rtl837x_lldp.h b/rtl837x_lldp.h index 4a48e121..8adc4a6f 100644 --- a/rtl837x_lldp.h +++ b/rtl837x_lldp.h @@ -27,6 +27,18 @@ #define LLDP_SYSNAME_TLV_TYPE 5 #define LLDP_SYSDESC_TLV_TYPE 6 +#define LLDP_CAPABILITIES_TLV_TYPE 7 +#define LLDP_CAPABILITIES_TLV_LENGTH 4 +#define LLDP_CAPABILITY_BRIDGE 0x0004 + +#define LLDP_MGMT_ADDR_TLV_TYPE 8 +#define LLDP_MGMT_ADDR_TLV_LENGTH 12 +#define LLDP_MGMT_ADDR_STR_LENGTH 5 +#define LLDP_MGMT_ADDR_SUBTYPE_IPV4 1 +#define LLDP_MGMT_IF_NUMBERING_UNKNOWN 1 + +#define LLDP_MAX_PAYLOAD 128 + void lldp_init(void) __banked; void lldp_tick(void) __banked; void lldp_send(void) __banked; From 12b85025e35c230e14584096f316df65badf63cc Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Tue, 13 Oct 2026 03:32:44 +0200 Subject: [PATCH 3/3] lldp: announce shutdown with a TTL of 0 lldp off and port lldp block went silent and left the neighbour holding our entry until its TTL ran out, 120 s later. Send one LLDPDU with a TTL of 0 on the ports that stop, the shutdown form 802.1AB defines for this, before the transmit mask changes. --- cmd_parser.c | 4 ++++ rtl837x_lldp.c | 18 ++++++++++++++---- rtl837x_lldp.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index e16fa108..85180cbd 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -920,6 +920,8 @@ void parse_port(void) print_string("\"\n"); } else if (cmd_compare(2, "lldp")) { if (cmd_compare(3, "block")){ + if (lldp_enabled) + lldp_shutdown((uint16_t)1 << phy_settings.port); lldp_logical_port_status &= ~((uint16_t)1 << phy_settings.port); } else if (cmd_compare(3, "permit")) { lldp_logical_port_status |= (uint16_t)1 << phy_settings.port; @@ -2046,6 +2048,8 @@ void cmd_parser(void) __banked lldp_enabled = 1; } else { print_string("LLDP disabled\n"); + if (lldp_enabled) + lldp_shutdown(lldp_logical_port_status); lldp_enabled = 0; } } diff --git a/rtl837x_lldp.c b/rtl837x_lldp.c index 590e15b2..5f31d7f4 100644 --- a/rtl837x_lldp.c +++ b/rtl837x_lldp.c @@ -54,7 +54,7 @@ struct lldp_pkt { // the length at any point #define LLDP_TYPE(value) (value << 1) -void lldp_send(void) __banked __reentrant +static void lldp_send_ports(uint16_t ttl, uint16_t ports) __reentrant { __xdata uint8_t *p; uint8_t port_position; @@ -84,8 +84,8 @@ void lldp_send(void) __banked __reentrant //TTL *p++ = LLDP_TYPE(LLDP_TTL_TLV_TYPE); *p++ = LLDP_TTL_TLV_LENGTH; - *p++ = 0x00; //padding - *p++ = LLDP_TTL_TTL_SECONDS; + *p++ = ttl >> 8; + *p++ = ttl & 0xff; p += lldp_sysname(p); p += lldp_sysdesc(p); @@ -136,7 +136,7 @@ void lldp_send(void) __banked __reentrant for (uint8_t port = machine.min_port; port <= machine.max_port; port++) { - if ((1 << port) & lldp_logical_port_status) { + if ((1 << port) & ports) { LLDP_O->payload[port_position] = '0' + machine.log_to_phys_port[port]; LLDP_O->rtl_tag.pmask = HTONS((uint16_t)1 << port); @@ -145,6 +145,16 @@ void lldp_send(void) __banked __reentrant } } +void lldp_send(void) __banked __reentrant +{ + lldp_send_ports(LLDP_TTL_TTL_SECONDS, lldp_logical_port_status); +} + +void lldp_shutdown(uint16_t ports) __banked __reentrant +{ + lldp_send_ports(0, ports); +} + void lldp_set_addresses(void) __banked { // LLDP destination multicast addr: 01:80:c2:00:00:0e memcpyc(LLDP_O->dst.addr, "\x01\x80\xc2\x00\x00\x0e", MAC_ADDR_LEN); diff --git a/rtl837x_lldp.h b/rtl837x_lldp.h index 8adc4a6f..1b3e4abe 100644 --- a/rtl837x_lldp.h +++ b/rtl837x_lldp.h @@ -42,6 +42,7 @@ void lldp_init(void) __banked; void lldp_tick(void) __banked; void lldp_send(void) __banked; +void lldp_shutdown(uint16_t ports) __banked; void lldp_set_addresses(void) __banked; void lldp_set_rtl_wrapper(void) __banked; uint8_t lldp_sysname(__xdata uint8_t *p) __banked;