Fix LLDP String
This commit is contained in:
1 parent
db81260d7f
commit
e8ee53aeff
3 files changed
+48
-17
No files matched your search
+2
-1
@@ -909,7 +909,8 @@ static char *build_payload(const openuf_state_t *st,
|
|||||||
json_object_object_add(root, "sta_table", sta_table);
|
json_object_object_add(root, "sta_table", sta_table);
|
||||||
|
|
||||||
/* ── LLDP neighbors for visual topology ─────────────────────── */
|
/* ── LLDP neighbors for visual topology ─────────────────────── */
|
||||||
json_object_object_add(root, "lldp_table", lldp_read_neighbors());
|
json_object_object_add(root, "lldp_table", lldp_read_neighbors(m));
|
||||||
|
/*json_object_object_add(root, "lldp_table", lldp_read_neighbors());*/
|
||||||
|
|
||||||
/* Global counters */
|
/* Global counters */
|
||||||
json_object_object_add(root, "bytes_r", json_object_new_int(0));
|
json_object_object_add(root, "bytes_r", json_object_new_int(0));
|
||||||
|
|||||||
+42
-14
@@ -65,6 +65,7 @@
|
|||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
|
|
||||||
#include "lldp.h"
|
#include "lldp.h"
|
||||||
|
#include "ufmodel.h"
|
||||||
|
|
||||||
/* ─── Constants ────────────────────────────────────────────────── */
|
/* ─── Constants ────────────────────────────────────────────────── */
|
||||||
static const uint8_t LLDP_DST[6] = {0x01,0x80,0xc2,0x00,0x00,0x0e};
|
static const uint8_t LLDP_DST[6] = {0x01,0x80,0xc2,0x00,0x00,0x0e};
|
||||||
@@ -201,13 +202,13 @@ bool lldp_available(void)
|
|||||||
═══════════════════════════════════════════════════════════════════
|
═══════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
Navigate: root → "lldp" → "interface" (array) → each neighbor.
|
Navigate: root → "lldp" → "interface" (array) → each neighbor.
|
||||||
For each neighbor, extract: chassis.id, chassis.name, chassis.descr,
|
For each neighbor, extract: chassis.id (+ subtype), chassis.name,
|
||||||
port.id, port.descr, and the name of the local interface.
|
chassis.descr, port.id (+ subtype), port.descr, and the name of the
|
||||||
|
local interface — resolved against our own port_table to get the
|
||||||
|
local_port_idx the controller needs for the topology tree.
|
||||||
The result is included in lldp_table[] of the inform payload.
|
The result is included in lldp_table[] of the inform payload.
|
||||||
The controller uses it to draw the connection lines in
|
|
||||||
the visual topology (which switch/port this AP connects to).
|
|
||||||
*/
|
*/
|
||||||
struct json_object *lldp_read_neighbors(void)
|
struct json_object *lldp_read_neighbors(const uf_model_t *m)
|
||||||
{
|
{
|
||||||
struct json_object *result = json_object_new_array();
|
struct json_object *result = json_object_new_array();
|
||||||
if (!lldp_available()) return result;
|
if (!lldp_available()) return result;
|
||||||
@@ -247,7 +248,7 @@ struct json_object *lldp_read_neighbors(void)
|
|||||||
local_port = json_object_get_string(tmp_o);
|
local_port = json_object_get_string(tmp_o);
|
||||||
|
|
||||||
/* Chassis */
|
/* Chassis */
|
||||||
const char *chassis_id="", *sys_name="", *sys_desc="";
|
const char *chassis_id="", *chassis_id_subtype="", *sys_name="", *sys_desc="";
|
||||||
struct json_object *chassis;
|
struct json_object *chassis;
|
||||||
if (json_object_object_get_ex(iface, "chassis", &chassis)) {
|
if (json_object_object_get_ex(iface, "chassis", &chassis)) {
|
||||||
struct json_object *cid, *cname, *cdescr;
|
struct json_object *cid, *cname, *cdescr;
|
||||||
@@ -255,6 +256,8 @@ struct json_object *lldp_read_neighbors(void)
|
|||||||
struct json_object *cv;
|
struct json_object *cv;
|
||||||
if (json_object_object_get_ex(cid, "value", &cv))
|
if (json_object_object_get_ex(cid, "value", &cv))
|
||||||
chassis_id = json_object_get_string(cv);
|
chassis_id = json_object_get_string(cv);
|
||||||
|
if (json_object_object_get_ex(cid, "type", &cv))
|
||||||
|
chassis_id_subtype = json_object_get_string(cv);
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(chassis, "name", &cname)) {
|
if (json_object_object_get_ex(chassis, "name", &cname)) {
|
||||||
struct json_object *cv;
|
struct json_object *cv;
|
||||||
@@ -269,7 +272,7 @@ struct json_object *lldp_read_neighbors(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Port */
|
/* Port */
|
||||||
const char *port_id="", *port_desc="";
|
const char *port_id="", *port_id_subtype="", *port_desc="";
|
||||||
struct json_object *port;
|
struct json_object *port;
|
||||||
if (json_object_object_get_ex(iface, "port", &port)) {
|
if (json_object_object_get_ex(iface, "port", &port)) {
|
||||||
struct json_object *pid, *pdesc;
|
struct json_object *pid, *pdesc;
|
||||||
@@ -277,6 +280,8 @@ struct json_object *lldp_read_neighbors(void)
|
|||||||
struct json_object *pv;
|
struct json_object *pv;
|
||||||
if (json_object_object_get_ex(pid, "value", &pv))
|
if (json_object_object_get_ex(pid, "value", &pv))
|
||||||
port_id = json_object_get_string(pv);
|
port_id = json_object_get_string(pv);
|
||||||
|
if (json_object_object_get_ex(pid, "type", &pv))
|
||||||
|
port_id_subtype = json_object_get_string(pv);
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(port, "descr", &pdesc)) {
|
if (json_object_object_get_ex(port, "descr", &pdesc)) {
|
||||||
struct json_object *pv;
|
struct json_object *pv;
|
||||||
@@ -285,14 +290,37 @@ struct json_object *lldp_read_neighbors(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* local_port ist ein ifname ("eth0"), der Controller braucht aber
|
||||||
|
* den port_idx aus unserer eigenen port_table zur Zuordnung. */
|
||||||
|
int local_port_idx = -1;
|
||||||
|
for (int j = 0; m && j < m->port_table_len; j++) {
|
||||||
|
if (strcmp(m->port_table[j].ifname, local_port) == 0) {
|
||||||
|
local_port_idx = m->port_table[j].port_idx;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct json_object *e = json_object_new_object();
|
struct json_object *e = json_object_new_object();
|
||||||
json_object_object_add(e, "local_port", json_object_new_string(local_port));
|
json_object_object_add(e, "local_port_idx",
|
||||||
json_object_object_add(e, "chassis_id", json_object_new_string(chassis_id));
|
json_object_new_int(local_port_idx));
|
||||||
json_object_object_add(e, "port_id", json_object_new_string(port_id));
|
json_object_object_add(e, "local_port_name",
|
||||||
json_object_object_add(e, "sys_name", json_object_new_string(sys_name));
|
json_object_new_string(local_port));
|
||||||
json_object_object_add(e, "sys_desc", json_object_new_string(sys_desc));
|
json_object_object_add(e, "chassis_id",
|
||||||
json_object_object_add(e, "port_desc", json_object_new_string(port_desc));
|
json_object_new_string(chassis_id));
|
||||||
json_object_object_add(e, "port_table", json_object_new_array());
|
json_object_object_add(e, "chassis_id_subtype",
|
||||||
|
json_object_new_string(chassis_id_subtype));
|
||||||
|
json_object_object_add(e, "port_id",
|
||||||
|
json_object_new_string(port_id));
|
||||||
|
json_object_object_add(e, "port_id_subtype",
|
||||||
|
json_object_new_string(port_id_subtype));
|
||||||
|
json_object_object_add(e, "port_descr",
|
||||||
|
json_object_new_string(port_desc));
|
||||||
|
json_object_object_add(e, "sys_name",
|
||||||
|
json_object_new_string(sys_name));
|
||||||
|
json_object_object_add(e, "sys_desc",
|
||||||
|
json_object_new_string(sys_desc));
|
||||||
|
json_object_object_add(e, "is_wired",
|
||||||
|
json_object_new_boolean(true));
|
||||||
json_object_array_add(result, e);
|
json_object_array_add(result, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -1,5 +1,6 @@
|
|||||||
#ifndef OPENUF_LLDP_H
|
#ifndef OPENUF_LLDP_H
|
||||||
#define OPENUF_LLDP_H
|
#define OPENUF_LLDP_H
|
||||||
|
#include "ufmodel.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* openuf - lldp.h
|
* openuf - lldp.h
|
||||||
@@ -63,8 +64,9 @@ int lldp_send_frame(const char *ifname,
|
|||||||
|
|
||||||
/* Reads LLDP neighbors from lldpctl and returns a JSON array lldp_table.
|
/* Reads LLDP neighbors from lldpctl and returns a JSON array lldp_table.
|
||||||
* If lldpctl is not present, returns an empty array (does not fail).
|
* If lldpctl is not present, returns an empty array (does not fail).
|
||||||
* Caller frees it with json_object_put(). */
|
* Caller frees it with json_object_put().
|
||||||
struct json_object *lldp_read_neighbors(void);
|
struct json_object *lldp_read_neighbors(void);*/
|
||||||
|
struct json_object *lldp_read_neighbors(const uf_model_t *m);
|
||||||
|
|
||||||
/* true if lldpctl is installed */
|
/* true if lldpctl is installed */
|
||||||
bool lldp_available(void);
|
bool lldp_available(void);
|
||||||
|
|||||||
Reference in new issue
Block a user