mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-11-01 18:04:12 +08:00
lldp: send the port name as the port description
A port named in the CLI or the web UI (port <n> name ...) now carries that name in a Port Description TLV, so a neighbour sees "Uplink" next to "Port 9". The tail of the frame is built per port, since the TLV length differs from port to port; ports without a name send no TLV.
This commit is contained in:
1 parent
9a61e471ea
commit
3dd60f6b13
2 files changed
+26
-6
No files matched your search
+24
-6
@@ -63,6 +63,7 @@ struct lldp_pkt {
|
||||
static void lldp_send_ports(uint16_t ttl, uint16_t ports) __reentrant
|
||||
{
|
||||
__xdata uint8_t *p;
|
||||
__xdata uint8_t *tail;
|
||||
uint8_t port_position;
|
||||
|
||||
lldp_set_addresses();
|
||||
@@ -120,6 +121,17 @@ static void lldp_send_ports(uint16_t ttl, uint16_t ports) __reentrant
|
||||
*p++ = 0; //OID length
|
||||
}
|
||||
|
||||
tail = p;
|
||||
|
||||
for (uint8_t port = MACHINE_MIN_PORT; port <= MACHINE_MAX_PORT; port++) {
|
||||
|
||||
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);
|
||||
|
||||
p = tail;
|
||||
p += lldp_portdesc(p, port);
|
||||
|
||||
// End of LLDPDU TLV
|
||||
*p++ = 0x00; //padding
|
||||
*p++ = 0x00; //padding
|
||||
@@ -140,12 +152,6 @@ static void lldp_send_ports(uint16_t ttl, uint16_t ports) __reentrant
|
||||
*/
|
||||
uip_len = MAC_ADDR_LEN + MAC_ADDR_LEN + sizeof(struct rtl_tag) + LLDP_ETHERTYPE_LENGTH + (p - LLDP_O->payload);
|
||||
|
||||
for (uint8_t port = MACHINE_MIN_PORT; port <= MACHINE_MAX_PORT; port++) {
|
||||
|
||||
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);
|
||||
|
||||
tcpip_output();
|
||||
}
|
||||
}
|
||||
@@ -205,3 +211,15 @@ uint8_t lldp_sysdesc(__xdata uint8_t *p) __banked
|
||||
memcpyc(p, VERSION_SW, version_length);
|
||||
return machine_name_length + 1 + version_length + 2;
|
||||
}
|
||||
|
||||
uint8_t lldp_portdesc(__xdata uint8_t *p, uint8_t port) __banked
|
||||
{
|
||||
uint8_t name_length = strlen_x(port_names[port]);
|
||||
|
||||
if (!name_length)
|
||||
return 0;
|
||||
*p++ = LLDP_TYPE(LLDP_PORT_DESC_TLV_TYPE);
|
||||
*p++ = name_length;
|
||||
memcpy(p, port_names[port], name_length);
|
||||
return name_length + 2;
|
||||
}
|
||||
@@ -24,6 +24,7 @@
|
||||
#define LLDP_CHASSIS_ID_TLV_LENGTH 7
|
||||
#define LLDP_CHASSIS_ID_TLV_SUBTYPE 4
|
||||
|
||||
#define LLDP_PORT_DESC_TLV_TYPE 4
|
||||
#define LLDP_SYSNAME_TLV_TYPE 5
|
||||
#define LLDP_SYSDESC_TLV_TYPE 6
|
||||
|
||||
@@ -47,5 +48,6 @@ void lldp_set_addresses(void) __banked;
|
||||
void lldp_set_rtl_wrapper(void) __banked;
|
||||
uint8_t lldp_sysname(__xdata uint8_t *p) __banked;
|
||||
uint8_t lldp_sysdesc(__xdata uint8_t *p) __banked;
|
||||
uint8_t lldp_portdesc(__xdata uint8_t *p, uint8_t port) __banked;
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user