Moving lldp cmd parsing to be above the is_sfp check to take precedence

Needed to increase buffer size for this to send app.js

The logical port status is what is returned in the array, for
non-sequential systems we need to map through physToLog rather
than just subtracting 1

physToLog is 1 based! not 0; also fixing up typecasts

Reimplementing using an array of objects to represent ports.
The previous approach of a bitmask of logical ports, was just too
simple on devices such as the SWGT024_V2_0_MANAGED which has
gaps in the port assignments.
This commit is contained in:
Rob Emery committed 2026-10-10 09:51:33 +01:00
1 parent 9b2bd7f1b8
commit dda873a633
5 files changed
+53 -35

No files matched your search

+8 -8
View File
@@ -914,6 +914,14 @@ void parse_port(void)
print_string("\nName set to: \""); print_string("\nName set to: \"");
print_string_x(port_names[phy_settings.port]); print_string_x(port_names[phy_settings.port]);
print_string("\"\n"); print_string("\"\n");
} else if (cmd_compare(2, "lldp")) {
if (cmd_compare(3, "block")){
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;
} else {
print_string ("Unknown port <port> lldp [block|permit] command\n");
}
} else if (machine.is_sfp[phy_settings.port]) { } else if (machine.is_sfp[phy_settings.port]) {
print_string(" is SFP no PHY information available.\n"); print_string(" is SFP no PHY information available.\n");
} else if (cmd_compare(2, "10m")) { } else if (cmd_compare(2, "10m")) {
@@ -967,14 +975,6 @@ void parse_port(void)
else else
phy_settings.duplex = PHY_DUPLEX_HALF; phy_settings.duplex = PHY_DUPLEX_HALF;
phy_set_duplex(); phy_set_duplex();
} else if (cmd_compare(2, "lldp")) {
if (cmd_compare(3, "block")){
lldp_logical_port_status &= ~(1 << phy_settings.port);
} else if (cmd_compare(3, "permit")) {
lldp_logical_port_status |= 1 << phy_settings.port;
} else {
print_string ("Unknown port <port> lldp [block|permit] command\n");
}
} else { } else {
cmd_error("Unknown port command\n"); cmd_error("Unknown port command\n");
} }
+8 -18
View File
@@ -1843,36 +1843,26 @@ function lldpLoad(){
return getJSON("/lldp.json").then(function(s){ return getJSON("/lldp.json").then(function(s){
$("lldp_en").checked=s.on; $("lldp_en").checked=s.on;
var tb=$("lldp_table").tBodies[0];tb.innerHTML=""; var tb=$("lldp_table").tBodies[0];tb.innerHTML="";
if(tb.rows.length!==S.n){ byPort(s.portStatus).forEach(function(p){
tb.innerHTML=""; var tr=tb.insertRow();
for(var i=0;i<S.n;i++)(function(i){ tr.insertCell().textContent=p.portNum;
var tr=tb.insertRow(); tr.insertCell().textContent=p.name;
tr.insertCell();
tr.insertCell();
tr.insertCell();
})(i);
}
S.ports.forEach(function(p){
var r=tb.rows[p.portNum-1];
if(!r)return;
r.cells[0].textContent=p.portNum+(p.isSFP?" (SFP)":"");
r.cells[1].textContent=p.name||"";
var sw=h("label",{class:"switch"},[ var sw=h("label",{class:"switch"},[
h("input",{type:"checkbox",onchange:function(){ h("input",{type:"checkbox",onchange:function(){
postCmd("port "+p.portNum+" lldp "+(this.checked?"permit":"block")) postCmd("port "+p.portNum+" lldp "+(this.checked?"permit":"block"))
.then(function(){setTimeout(lldpLoad,300)}).catch(function(){}); .then(function(){setTimeout(lldpLoad,300)}).catch(function(){});
}}),h("i")]); }}),h("i")]);
sw.firstChild.checked=s.port_status[p.portNum-1]; sw.firstChild.checked=p.enabled;
r.cells[2].appendChild(sw); tr.insertCell().appendChild(sw);
}); });
}).catch(function(e){console.log("ERROR!"); console.log(e)}); });
} }
$("lldp_en").addEventListener("change",function(){ $("lldp_en").addEventListener("change",function(){
var el=this; var el=this;
postCmd("lldp "+(el.checked?"on":"off")).catch(function(){el.checked=!el.checked}); postCmd("lldp "+(el.checked?"on":"off")).catch(function(){el.checked=!el.checked});
}); });
tabHooks.lldp={enter:needPorts(lldpLoad)}; tabHooks.lldp={enter:lldpLoad};
function eeeFlags(bits){ function eeeFlags(bits){
var b=parseInt(bits,2); var b=parseInt(bits,2);
+23 -7
View File
@@ -743,14 +743,30 @@ void send_lldp(void)
slen += strtox(outbuf + slen, "{\"on\":"); slen += strtox(outbuf + slen, "{\"on\":");
bool_to_html(lldp_enabled); bool_to_html(lldp_enabled);
slen += strtox(outbuf + slen, ",\"port_status\":["); slen += strtox(outbuf + slen, ",\"portStatus\":[");
for (uint8_t port = machine.min_port; port <= machine.max_port; port++) { for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
bool_to_html((1 << port) & lldp_logical_port_status); slen += strtox(outbuf + slen, "{\"portNum\":");
slen += strtox(outbuf + slen, ","); itoa_html(machine.log_to_phys_port[i]);
}
slen--; //overwrite the last comma slen += strtox(outbuf + slen, ",\"logPort\":");
slen += strtox(outbuf + slen, "]}"); itoa_html(i);
slen += strtox(outbuf + slen, ",\"name\":\"");
for (uint8_t j = 0; j < PORT_NAME_SIZE && port_names[i][j]; j++) {
json_char_to_html(port_names[i][j]);
}
slen += strtox(outbuf + slen, "\"");
slen += strtox(outbuf + slen, ",\"enabled\":\"");
bool_to_html(1 & (lldp_logical_port_status >> i));
slen += strtox(outbuf + slen, "\"}");
if (i < machine.max_port)
char_to_html(',');
else
char_to_html(']');
}
char_to_html('}');
} }
void send_eee(void) void send_eee(void)
+13 -1
View File
@@ -459,7 +459,19 @@ void send_lldp(int s)
char *header = "HTTP/1.1 200 OK\r\n" char *header = "HTTP/1.1 200 OK\r\n"
"Content-Type: application/json; charset=UTF-8\r\n\r\n"; "Content-Type: application/json; charset=UTF-8\r\n\r\n";
char *body = "{\"on\": 1,\"port_status\":[1,1,0,1,1,1,1,0,0]}"; //portNum represents physical ports
char *body = "{\"on\": 1,\"portStatus\":[\
{\"portNum\":1,\"logPort\":1,\"name\":\"PC\",\"enabled\":1},\
{\"portNum\":2,\"logPort\":2,\"name\":\"\",\"enabled\":1},\
{\"portNum\":3,\"logPort\":3,\"name\":\"\",\"enabled\":1},\
{\"portNum\":4,\"logPort\":4,\"name\":\"\",\"enabled\":0},\
{\"portNum\":5,\"logPort\":5,\"name\":\"\",\"enabled\":1},\
{\"portNum\":6,\"logPort\":6,\"name\":\"TV\",\"enabled\":1},\
{\"portNum\":7,\"logPort\":7,\"name\":\"\",\"enabled\":0},\
{\"portNum\":8,\"logPort\":8,\"name\":\"Router\",\"enabled\":1},\
{\"portNum\":9,\"logPort\":9,\"name\":\"\",\"enabled\":1},\
{\"portNum\":10,\"logPort\":10,\"name\":\"Uplink\",\"enabled\":1}\
]}";
write(s, header, strlen(header)); write(s, header, strlen(header));
write(s, body, strlen(body)); write(s, body, strlen(body));
+1 -1
View File
@@ -3,7 +3,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#define BUFFER_SIZE 131072 #define BUFFER_SIZE 262144
struct Server { struct Server {
int domain; int domain;