From 9b2bd7f1b82efc113471ead52a861af973d0dff5 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Thu, 1 Oct 2026 11:37:13 +0100 Subject: [PATCH] The tick rate has been changed now so we'll have to approximate timing with ticks Fixing up the log_to_phys_port assignment 2000 is about every 10 seconds, so scaling up to once every 30ish Removing the attempt to block lldp frames, This does not work however the hard work has been done for us in the #514 so we can borrow that work later on --- cmd_parser.c | 4 ++-- html/app.js | 4 +--- httpd/page_impl.c | 4 ++-- rtl837x_common.h | 2 +- rtl837x_lldp.c | 16 ++++++++-------- rtl837x_lldp.h | 2 +- rtlplayground.c | 4 ---- test/env_tables.c | 2 +- 8 files changed, 16 insertions(+), 22 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index 8262463b..3cb7724c 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -969,9 +969,9 @@ void parse_port(void) phy_set_duplex(); } else if (cmd_compare(2, "lldp")) { if (cmd_compare(3, "block")){ - lldp_physical_port_status &= ~(1 << phy_settings.port); + lldp_logical_port_status &= ~(1 << phy_settings.port); } else if (cmd_compare(3, "permit")) { - lldp_physical_port_status |= 1 << phy_settings.port; + lldp_logical_port_status |= 1 << phy_settings.port; } else { print_string ("Unknown port lldp [block|permit] command\n"); } diff --git a/html/app.js b/html/app.js index 3da29b5a..00af6434 100644 --- a/html/app.js +++ b/html/app.js @@ -1872,10 +1872,8 @@ $("lldp_en").addEventListener("change",function(){ var el=this; postCmd("lldp "+(el.checked?"on":"off")).catch(function(){el.checked=!el.checked}); }); - tabHooks.lldp={enter:needPorts(lldpLoad)}; - function eeeFlags(bits){ var b=parseInt(bits,2); return["100M","1G","2.5G"].map(function(s,i){ @@ -2036,7 +2034,7 @@ function sysLoad(){ cfgReload(); } function cfgParseKnown(txt){ - var igmp=false,lldp=false,syslog=false; + var igmp=false,syslog=false; txt.split(/\r?\n/).forEach(function(l){ l=l.trim(); if(/^igmp on$/.test(l))igmp=true; diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 0d054be9..9a818dcf 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -49,7 +49,7 @@ extern __xdata char sfp_module_model[2][17]; extern __xdata char sfp_module_serial[2][17]; extern __xdata uint8_t sfp_options[2]; -extern __xdata uint16_t lldp_physical_port_status; +extern __xdata uint16_t lldp_logical_port_status; extern __xdata bool lldp_enabled; __code const uint8_t * __code const HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n"; @@ -746,7 +746,7 @@ void send_lldp(void) slen += strtox(outbuf + slen, ",\"port_status\":["); for (uint8_t port = machine.min_port; port <= machine.max_port; port++) { - bool_to_html((1 << machine.log_to_phys_port[port]) & lldp_physical_port_status); + bool_to_html((1 << port) & lldp_logical_port_status); slen += strtox(outbuf + slen, ","); } slen--; //overwrite the last comma diff --git a/rtl837x_common.h b/rtl837x_common.h index 74425fbc..a36d41fc 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -131,7 +131,7 @@ struct flash_region_t { }; extern __xdata char port_names[9][PORT_NAME_SIZE]; -extern __xdata uint16_t lldp_physical_port_status; +extern __xdata uint16_t lldp_logical_port_status; extern __xdata bool stp_enabled; diff --git a/rtl837x_lldp.c b/rtl837x_lldp.c index 3e484cbe..84208433 100644 --- a/rtl837x_lldp.c +++ b/rtl837x_lldp.c @@ -13,22 +13,22 @@ extern __xdata bool lldp_enabled; extern __code const struct machine machine; -__xdata uint8_t lldp_seconds; -__xdata uint16_t lldp_physical_port_status = 0xffff; +__xdata uint16_t lldp_ticks; +__xdata uint16_t lldp_logical_port_status = 0xffff; void lldp_init(void) __banked { - lldp_seconds = 0; + lldp_ticks = 0; } void lldp_tick(void) __banked { - lldp_seconds++; + lldp_ticks++; - if (lldp_seconds < LLDP_TX_INTERVAL_SEC) + if (lldp_ticks < LLDP_TX_INTERVAL_TICKS) return; - lldp_seconds = 0; + lldp_ticks = 0; if(lldp_enabled == 1) lldp_send(); @@ -110,9 +110,9 @@ void lldp_send(void) __banked __reentrant for (uint8_t port = machine.min_port; port <= machine.max_port; port++) { - if ((1 << machine.log_to_phys_port[port]) & lldp_physical_port_status) { + if ((1 << port) & lldp_logical_port_status) { LLDP_O->payload[port_position] = '0' + machine.log_to_phys_port[port]; - LLDP_O->rtl_tag.pmask = HTONS((uint16_t)1 << machine.log_to_phys_port[port]); + LLDP_O->rtl_tag.pmask = HTONS((uint16_t)1 << port); tcpip_output(); } diff --git a/rtl837x_lldp.h b/rtl837x_lldp.h index b441d8c4..298775c6 100644 --- a/rtl837x_lldp.h +++ b/rtl837x_lldp.h @@ -8,7 +8,7 @@ #define LLDP_ETHERTYPE_LENGTH 2 #define LLDP_MAX_FRAME 256 #define MAC_ADDR_LEN 6 -#define LLDP_TX_INTERVAL_SEC 30 +#define LLDP_TX_INTERVAL_TICKS 6000 #define LLDP_PORT_ID_TLV_TYPE 2 #define LLDP_PORT_ID_TLV_LENGTH 0x02 diff --git a/rtlplayground.c b/rtlplayground.c index 4fb22009..43ff83f0 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -1068,10 +1068,6 @@ void handle_rx(void) if (uip_len) { tcpip_output(); } - } else if (lldp_enabled && uip_buf[0] == 0x01 && uip_buf[1] == 0x80 && uip_buf[2] == 0xc2 - && uip_buf[3] == 0x00 && uip_buf[4] == 0x00 && uip_buf[5] == 0x0e && uip_buf[12] == 0x88 - && uip_buf[13] == 0xcc) { //LLDP Mac + EtherType check - // LLDP packets shouldn't be passed elsewhere } else if (ETH_IN->ether_type == HTONS(0x0806)) { // ARP uip_arp_arpin(); if (uip_len) { diff --git a/test/env_tables.c b/test/env_tables.c index 3b246948..41694b72 100644 --- a/test/env_tables.c +++ b/test/env_tables.c @@ -85,7 +85,7 @@ struct flash_region_t flash_region; struct syslog_state syslog_state; bool stp_enabled; bool lldp_enabled; -uint16_t lldp_physical_port_status; +uint16_t lldp_logical_port_status; uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;