Translated all files to ENG (#5)

Reviewed-on: #5
Co-authored-by: Finn <fwaggoner@nmfpgt.de>
Co-committed-by: Finn <fwaggoner@nmfpgt.de>
This commit was merged in pull request #5.
This commit is contained in:
2026-07-12 01:45:38 +01:00
committed by Koda
parent fb542777ca
commit 59274da4e5
14 changed files with 317 additions and 307 deletions
+28 -29
View File
@@ -1,33 +1,33 @@
/*
* openuf - lldp.c
*
* LLDP completo: envío de frames propios + lectura de vecinos.
* Complete LLDP: sending of own frames + reading of neighbors.
*
* ── Construcción del frame ────────────────────────────────────────
* ── Frame construction ─────────────────────────────────────────────
*
* Los TLVs LLDP tienen cabecera de 2 bytes:
* bit 15..9 → tipo (7 bits)
* bit 8..0 → longitud (9 bits, max 511 bytes)
* LLDP TLVs have a 2-byte header:
* bit 15..9 → type (7 bits)
* bit 8..0 → length (9 bits, max 511 bytes)
*
* uint16_t header_be = (type << 9) | (len & 0x1ff)
*
* Ejemplo: Chassis ID TLV (type=1), 7 bytes de valor:
* Example: Chassis ID TLV (type=1), 7 bytes of value:
* header = (1 << 9) | 7 = 0x0207
* → bytes: 0x02 0x07 [subtype=4] [MAC 6 bytes]
*
* ── Envío con AF_PACKET ───────────────────────────────────────────
* ── Sending with AF_PACKET ────────────────────────────────────────
*
* 1. socket(AF_PACKET, SOCK_RAW, htons(0x88cc))
* 2. ioctl(SIOCGIFINDEX) → ifindex
* 3. Construir frame completo en buffer
* 4. sendto() con sockaddr_ll
* 3. Build the complete frame in a buffer
* 4. sendto() with sockaddr_ll
*
* Sin CAP_NET_RAW (no root) → socket() devuelve EPERM.
* Lo ignoramos silenciosamente (LLDP es opcional).
* Without CAP_NET_RAW (not root) → socket() returns EPERM.
* This is silently ignored (LLDP is optional).
*
* ── Lectura de vecinos con lldpctl ───────────────────────────────
* ── Reading neighbors with lldpctl ───────────────────────────────
*
* lldpctl -f json retorna:
* lldpctl -f json returns:
* {
* "lldp": {
* "interface": [
@@ -66,12 +66,12 @@
#include "lldp.h"
/* ─── Constantes ────────────────────────────────────────────────── */
/* ─── Constants ────────────────────────────────────────────────── */
static const uint8_t LLDP_DST[6] = {0x01,0x80,0xc2,0x00,0x00,0x0e};
#define LLDP_ETHERTYPE 0x88cc
#define CAP_WLAN_AP 0x0040
/* ─── Escribir TLV en buffer ────────────────────────────────────── */
/* ─── Write TLV to buffer ────────────────────────────────────── */
static int tlv_write(uint8_t *buf, int pos, int maxlen,
int type, const uint8_t *val, int vlen)
{
@@ -90,7 +90,7 @@ static int tlv_str(uint8_t *buf, int pos, int maxlen,
(const uint8_t*)str, (int)strlen(str));
}
/* ─── Parsear MAC "aa:bb:cc:dd:ee:ff" → bytes ──────────────────── */
/* ─── Parse MAC "aa:bb:cc:dd:ee:ff" → bytes ──────────────────── */
static void parse_mac(const char *s, uint8_t out[6])
{
unsigned int b[6]={0};
@@ -109,7 +109,7 @@ int lldp_send_frame(const char *ifname,
{
/* Socket raw — requiere root */
int fd = socket(AF_PACKET, SOCK_RAW, htons(LLDP_ETHERTYPE));
if (fd < 0) return -1; /* EPERM sin root → silencioso */
if (fd < 0) return -1; /* EPERM without root → silent */
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
@@ -162,9 +162,9 @@ int lldp_send_frame(const char *ifname,
0x00, (uint8_t)(CAP_WLAN_AP >> 8),
0x00, (uint8_t)(CAP_WLAN_AP & 0xff)
};
/* Corregir: CAP_WLAN_AP = 0x0040, un solo byte basta */
/* Fix: CAP_WLAN_AP = 0x0040, a single byte is enough */
v[1] = 0x00; v[0] = 0x00;
/* bit 6 de los 16 bits de capabilities */
/* bit 6 of the 16 capability bits */
uint16_t cap = CAP_WLAN_AP;
v[0] = (cap >> 8) & 0xff; v[1] = cap & 0xff;
v[2] = v[0]; v[3] = v[1]; /* enabled = same */
@@ -197,16 +197,15 @@ bool lldp_available(void)
}
/* ═══════════════════════════════════════════════════════════════════
lldp_read_neighbors — parsea JSON de lldpctl
lldp_read_neighbors — parses JSON from lldpctl
═══════════════════════════════════════════════════════════════════
Navega: root → "lldp" → "interface" (array) → cada vecino.
Por cada vecino extrae: chassis.id, chassis.name, chassis.descr,
port.id, port.descr, y el nombre de la interfaz local.
El resultado se incluye en lldp_table[] del payload inform.
El controlador lo usa para dibujar las líneas de conexión en
la topología visual (qué switch/puerto conecta a este AP).
Navigate: root → "lldp" → "interface" (array) → each neighbor.
For each neighbor, extract: chassis.id, chassis.name, chassis.descr,
port.id, port.descr, and the name of the local interface.
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)
{
@@ -230,7 +229,7 @@ struct json_object *lldp_read_neighbors(void)
struct json_object *root = json_tokener_parse(buf);
if (!root) return result;
/* Navegar: root.lldp.interface[] */
/* Browse: root.lldp.interface[] */
struct json_object *lldp_o, *iface_arr;
if (!json_object_object_get_ex(root, "lldp", &lldp_o)) goto done;
if (!json_object_object_get_ex(lldp_o, "interface", &iface_arr)) goto done;
@@ -241,7 +240,7 @@ struct json_object *lldp_read_neighbors(void)
struct json_object *iface = json_object_array_get_idx(iface_arr, i);
if (!iface) continue;
/* Puerto local */
/* Local port */
struct json_object *tmp_o;
const char *local_port = "";
if (json_object_object_get_ex(iface, "name", &tmp_o))