diff --git a/cmd_parser.c b/cmd_parser.c index 9c52e1f9..8262463b 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_port_status &= ~(1 << phy_settings.port); + lldp_physical_port_status &= ~(1 << phy_settings.port); } else if (cmd_compare(3, "permit")) { - lldp_port_status |= 1 << phy_settings.port; + lldp_physical_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 9bbafcc9..d9c9a1e8 100644 --- a/html/app.js +++ b/html/app.js @@ -3,7 +3,7 @@ var LANG={ en:{ nav_dash:"Dashboard",nav_ports:"Ports",nav_stp:"Spanning tree",nav_stats:"Statistics", nav_vlan:"VLANs",nav_l2:"MAC table",nav_mirror:"Mirroring",nav_isolate:"Isolation",nav_lag:"LAG",nav_eee:"EEE", -nav_bw:"Bandwidth",nav_system:"System",nav_fw:"Firmware", +nav_bw:"Bandwidth",nav_system:"System",nav_fw:"Firmware",nav_lldp:"LLDP", hdr_dirty:"unsaved changes",hdr_dirty_t:"Running config differs from startup config", hdr_save:"Save to flash",hdr_save_t:"Persist running configuration to flash", th_auto:"System",th_auto_sel:"System (Selenized)",sy_display:"Display",sy_theme:"Theme",sy_display_note:"Stored in this browser only.",th_light:"Light",th_dark:"Dark", @@ -40,6 +40,7 @@ stp_en_q:"Enable spanning tree?", stp_en_d:"Ports start blocked and take up to twice the forward delay to reach forwarding; edge ports recover immediately.", stp_dis_q:"Disable spanning tree?",stp_dis_d:"All ports go straight to forwarding; loop protection is lost.", stp_cost_err:"Path cost must be 0-200000000", +lldp_enabled: "LLDP Enabled",lldp_title:"Service Status",lldp_portname:"Name",lldp_enable:"Send Frames", st_title:"Port statistics",st_h:"totals since boot",st_txg:"TX good",st_txb:"TX bad",st_rxg:"RX good", st_rxb:"RX bad",st_details:"Details",st_counters:"MIB counters",st_nonzero:"non-zero only", st_autoref:"auto-refresh",st_counter:"Counter",st_value:"Value",st_fail:"failed to load counters", @@ -77,7 +78,7 @@ sc_title:"Storm control",sc_h:"per port and traffic type, empty = off",sc_bcast: sc_ucast:"Unknown unicast",sc_umcast:"Unknown multicast",sc_err:"Storm limit must be 1-1048575 pps or 1-10000000 kbit/s", sc_note:"Frames of a type above its limit are dropped where they enter the switch.", sy_network:"Network",sy_dhcp:"Use DHCP",sy_dhcp_t:"Request address via DHCP",sy_services:"Services", -sy_igmp:"IGMP snooping",sy_sysip:"server IP",sy_server:"Server",sy_port:"Port",sy_lldp:"LLDP", +sy_igmp:"IGMP snooping",sy_sysip:"server IP",sy_server:"Server",sy_port:"Port", sy_sesstmo:"Session timeout (s)",sy_sesstmo_err:"Session timeout must be 1-65535 s", sy_services_note:"Service state reflects the startup config; runtime state is not readable.", sy_password:"Admin password",sy_newpw:"New password",sy_repeat:"Repeat",sy_pwapply:"Change password", @@ -788,6 +789,7 @@ var CONF_CMDS=[ /^ingress(\s+\d{1,2}[tua])+$/,/^ingress\s+[tua]$/, /^port\s+\d{1,2}\s+(10m|100m|1g|2g5|5g|10g|auto|on|off)(\s+(half|full))?$/, /^port\s+\d{1,2}\s+name\s+\S+$/, + /^port\s+\d{1,2}\s+lldp\s+(permit|block)+$/, /^eee\s+(on|off)(\s+\d{1,2})?(\s+(100m|1g|2g5))?$/, /^mirror(\s+\d{1,2})(\s+\d{1,2}[tr]?)+$/,/^mirror\s+off$/, /^lag\s+[1-4](\s+\d{1,2})+$/,/^lag\s+[1-4]\s+d$/,/^laghash\s+[1-4](\s+\w+)+$/, @@ -798,7 +800,7 @@ var CONF_CMDS=[ /^stp\s+(port\s+\d{1,2}|lag\s+[1-4])\s+cost\s+\d{1,9}$/,/^stp\s+(port\s+\d{1,2}|lag\s+[1-4])\s+prio\s+\d{1,3}$/, /^stp\s+(port\s+\d{1,2}|lag\s+[1-4])\s+guard\s+(none|bpdu|root)$/,/^stp\s+(port\s+\d{1,2}|lag\s+[1-4])\s+filter\s+(on|off)$/, /^stp\s+(port\s+\d{1,2}|lag\s+[1-4])\s+p2p\s+(auto|on|off)$/, - /^igmp\s+(on|off)$/,/^mtu\s+\d{1,2}\s+\d+$/, + /^igmp\s+(on|off)$/,/^mtu\s+\d{1,2}\s+\d+$/,/^lldp\s+(on|off)$/, /^bw\s+(in|out)\s+\d{1,2}\s+\S+$/, /^storm\s+\d{1,2}\s+(bcast|mcast|ucast|umcast)\s+(off|\d{1,8}\s+(pps|kbps))$/, ]; @@ -860,6 +862,7 @@ var TABS=[ {id:"mirror",icon:"M12 3v18M7 8l-4 4 4 4M17 8l4 4-4 4"}, {id:"isolate",icon:"M4 4h6v6H4zM14 14h6v6h-6zM14 4h6v6h-6zM4 14h6v6H4z"}, {id:"lag", icon:"M7 8a4 4 0 100 8h3M17 8a4 4 0 110 8h-3M9 12h6"}, + {id:"lldp", icon:"M7 12h6"}, {id:"eee", icon:"M13 2L4 14h6l-1 8 9-12h-6z"}, {id:"bw", icon:"M4 18a8 8 0 0116 0M12 18l4-6"}, {id:"system",icon:"M12 8a4 4 0 100 8 4 4 0 000-8zM4 12h2M18 12h2M12 4v2M12 18v2M6 6l1.5 1.5M16.5 16.5L18 18M18 6l-1.5 1.5M7.5 16.5L6 18"}, @@ -1835,6 +1838,44 @@ function lagApply(g){ } tabHooks.lag={enter:function(){needPorts(function(){buildLag();lagLoad().catch(function(){})})}}; + +function lldpLoad(){ + return getJSON("/lldp.json").then(function(s){ + $("lldp_en").checked=s.on; + var tb=$("lldp_table").tBodies[0];tb.innerHTML=""; + if(tb.rows.length!==S.n){ + tb.innerHTML=""; + for(var i=0;i +
+

LLDP

+ +
+ +
Port NumberNameSend Frames
+
+
+

Port isolation

A frame entering a port may only leave through the ports ticked in its row.

@@ -386,8 +397,6 @@ button.danger{background:var(--bad);color:#fff;border-color:transparent}

Services

-
diff --git a/httpd/httpd.c b/httpd/httpd.c index 770eaa39..aec2eaf1 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -1034,6 +1034,8 @@ void httpd_appcall(void) send_lag(); } else if (is_word(q, "/stp.json")) { send_stp(); + } else if (is_word(q, "/lldp.json")) { + send_lldp(); } else if (is_word(q, "/vlanlist")) { send_vlanlist(); } else if (is_word(q, "/config")) { diff --git a/httpd/page_impl.c b/httpd/page_impl.c index fe5ccced..f9c55b83 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -49,6 +49,9 @@ 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 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"; __code const uint8_t * __code const HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n"; @@ -619,7 +622,6 @@ static void bridge_to_html(void) byte_to_html(pi_mac[i]); } - void send_stp(void) { uint8_t i, j, st, dsg; @@ -734,6 +736,22 @@ void send_stp(void) slen += strtox(outbuf + slen, "]}"); } +void send_lldp(void) +{ + dbg_string("send_lldp called\n"); + slen = strtox(outbuf, HTTP_RESPONCE_JSON); + + slen += strtox(outbuf + slen, "{\"on\":"); + bool_to_html(lldp_enabled); + 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); + slen += strtox(outbuf + slen, ","); + } + + slen += strtox(outbuf + slen, "]}"); +} diff --git a/httpd/page_impl.h b/httpd/page_impl.h index d6690dc6..fd51c8c6 100644 --- a/httpd/page_impl.h +++ b/httpd/page_impl.h @@ -23,6 +23,7 @@ void send_config(void); void send_cmd_log(void); void send_lag(void); void send_stp(void); +void send_lldp(void); void send_vlanlist(void); /* Convert only the lower nibble to ascii HEX char. diff --git a/rtl837x_common.h b/rtl837x_common.h index 8fa68477..74425fbc 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_port_status; +extern __xdata uint16_t lldp_physical_port_status; extern __xdata bool stp_enabled; diff --git a/rtl837x_lldp.c b/rtl837x_lldp.c index 57f27150..3e484cbe 100644 --- a/rtl837x_lldp.c +++ b/rtl837x_lldp.c @@ -14,7 +14,7 @@ extern __xdata bool lldp_enabled; extern __code const struct machine machine; __xdata uint8_t lldp_seconds; -__xdata uint16_t lldp_port_status = 0xffff; +__xdata uint16_t lldp_physical_port_status = 0xffff; void lldp_init(void) __banked { @@ -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_port_status) { + if ((1 << machine.log_to_phys_port[port]) & lldp_physical_port_status) { LLDP_O->payload[port_position] = '0' + machine.log_to_phys_port[port]; - LLDP_O->rtl_tag.pmask = HTONS((uint16_t)1 << port); + LLDP_O->rtl_tag.pmask = HTONS((uint16_t)1 << machine.log_to_phys_port[port]); tcpip_output(); } diff --git a/tools/httpd_sim.c b/tools/httpd_sim.c index 76c088c3..efa367c6 100644 --- a/tools/httpd_sim.c +++ b/tools/httpd_sim.c @@ -454,6 +454,16 @@ void send_mtu(int s) json_object_put(mtus); } +void send_lldp(int s) +{ + char *header = "HTTP/1.1 200 OK\r\n" + "Content-Type: application/json; charset=UTF-8\r\n\r\n"; + + char *body = "{\"on\": true, \"port_status\":[true,true,false,true,true,true,true,false,false]}"; + + write(s, header, strlen(header)); + write(s, body, strlen(body)); +} void send_cmd_log(int s) { @@ -468,7 +478,6 @@ void send_cmd_log(int s) } } - void send_config(int s) { char *header = "HTTP/1.1 200 OK\r\n" @@ -701,6 +710,13 @@ void launch(struct Server *server) else send_vlan(new_socket, vlan); goto done; + } else if (!strncmp(&buffer[4], "/lldp.json", 10)) { + printf("LLDP request"); + if (!authenticated) + send_unauthorized(new_socket); + else + send_lldp(new_socket); + goto done; } else if (!strncmp(&buffer[4], "/cmd_log", 8)) { printf("Request cmd_log\n"); if (!authenticated)