Skip to content

Commit

Permalink
confd: Enable configuring LLDP tx interval
Browse files Browse the repository at this point in the history
This change introduces the configuration of the tx-interval parameter
for the LLDP service, allowing control over the frequency of LLDP hello
messages. By reducing the tx-interval, the waiting time for LLDP
packets during tests is significantly shortened. This improvement
eliminates the need to toggle the interface down and up to force the
emission of LLDP packets.
  • Loading branch information
axkar committed Jan 10, 2025
1 parent ac0acfe commit 7de414b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
51 changes: 40 additions & 11 deletions src/confd/src/infix-services.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ static sr_data_t *get(sr_session_ctx_t *session, sr_event_t event, const char *x
return cfg;
}

static int put(sr_data_t *cfg, struct lyd_node *srv)
static int put(sr_data_t *cfg)
{
sr_release_data(cfg);
return SR_ERR_OK;
}

static int svc_change(sr_session_ctx_t *session, sr_event_t event, const char *xpath,
static int svc_enadis_change(sr_session_ctx_t *session, sr_event_t event, const char *xpath,
const char *name, const char *svc)
{
struct lyd_node *srv = NULL;
Expand All @@ -148,7 +148,7 @@ static int svc_change(sr_session_ctx_t *session, sr_event_t event, const char *x
if (ena)
systemf("initctl -nbq touch %s", svc); /* in case already enabled */

return put(cfg, srv);
return put(cfg);
}

static void svc_enadis(int ena, svc type, const char *svc)
Expand Down Expand Up @@ -299,13 +299,41 @@ static int mdns_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m
svc_enadis(ena, none, "avahi");
mdns_cname(session);

return put(cfg, srv);
return put(cfg);
}

static int is_service_running(const char *service) {
return systemf("initctl status %s | grep -q running", service) == 0;
}

static int lldp_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
const char *xpath, sr_event_t event, unsigned request_id, void *_confd)
{
return svc_change(session, event, xpath, "lldp", "lldpd");
struct lyd_node *srv = NULL;
sr_data_t *cfg;
int lldp_enabled;

cfg = get(session, event, xpath, &srv, "lldp", NULL);
if (!cfg)
return SR_ERR_OK;

lldp_enabled = lydx_is_enabled(srv, "enabled");

if (lldp_enabled != is_service_running("lldpd")) {
if (systemf("initctl -nbq %s lldpd", lldp_enabled ? "enable" : "disable"))
ERROR("Failed %s lldpd", lldp_enabled ? "enabling" : "disabling");

if (lldp_enabled)
systemf("initctl -nbq touch lldpd");
}

if (lldp_enabled) {
const char *tx_interval = lydx_get_cattr(srv, "message-tx-interval");
if (tx_interval && *tx_interval && systemf("sudo lldpcli configure lldp tx-interval %s", tx_interval))
ERROR("Failed configuring LLDP tx-interval %s", tx_interval);
}

return put(cfg);
}

static int ttyd_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
Expand All @@ -320,7 +348,7 @@ static int ttyd_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m

svc_enadis(lydx_is_enabled(srv, "enabled"), ttyd, NULL);

return put(cfg, srv);
return put(cfg);
}

static int netbrowse_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
Expand All @@ -336,7 +364,7 @@ static int netbrowse_change(sr_session_ctx_t *session, uint32_t sub_id, const ch
svc_enadis(lydx_is_enabled(srv, "enabled"), netbrowse, NULL);
mdns_cname(session);

return put(cfg, srv);
return put(cfg);
}

static int restconf_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
Expand All @@ -351,7 +379,7 @@ static int restconf_change(sr_session_ctx_t *session, uint32_t sub_id, const cha

svc_enadis(lydx_is_enabled(srv, "enabled"), restconf, NULL);

return put(cfg, srv);
return put(cfg);
}

static int ssh_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
Expand All @@ -364,7 +392,7 @@ static int ssh_change(sr_session_ctx_t *session, uint32_t sub_id, const char *mo

switch (event) {
case SR_EV_DONE:
return svc_change(session, event, xpath, "ssh", "sshd");
return svc_enadis_change(session, event, xpath, "ssh", "sshd");
case SR_EV_ENABLED:
case SR_EV_CHANGE:
break;
Expand Down Expand Up @@ -447,7 +475,7 @@ static int web_change(sr_session_ctx_t *session, uint32_t sub_id, const char *mo
svc_enadis(ena, web, "nginx");
mdns_cname(session);

return put(cfg, srv);
return put(cfg);
}

/* Store SSH public/private keys */
Expand All @@ -474,7 +502,7 @@ static int change_keystore_cb(sr_session_ctx_t *session, uint32_t sub_id, const
ERROR("Failed to remove old SSH hostkeys: %d", errno);
}
rename(SSH_HOSTKEYS_NEXT, SSH_HOSTKEYS);
svc_change(session, event, "/infix-services:ssh", "ssh", "sshd");
svc_enadis_change(session, event, "/infix-services:ssh", "ssh", "sshd");
}
return SR_ERR_OK;

Expand Down Expand Up @@ -515,6 +543,7 @@ static int change_keystore_cb(sr_session_ctx_t *session, uint32_t sub_id, const

return rc;
}

int infix_services_init(struct confd *confd)
{
int rc;
Expand Down
2 changes: 1 addition & 1 deletion src/confd/yang/confd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MODULES=(
"[email protected]"
"[email protected]"
"[email protected]"
"infix-lldp@2023-08-23.yang"
"infix-lldp@2025-01-08.yang"
"[email protected]"
"[email protected]"
"[email protected]"
Expand Down
7 changes: 4 additions & 3 deletions src/confd/yang/infix-lldp.yang
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module infix-lldp {
contact "[email protected]";
description "Infix augments and deviations to ieee-dot1ab-lldp.";

revision 2025-01-08 {
description "Switched to the standard 'message-tx-interval' for regular LLDP transmit interval configuration.";
}

revision 2023-08-23 {
description "Initial revision.";
reference "internal";
Expand All @@ -34,9 +38,6 @@ module infix-lldp {
deviation "/lldp:lldp/lldp:message-tx-hold-multiplier" {
deviate not-supported;
}
deviation "/lldp:lldp/lldp:message-tx-interval" {
deviate not-supported;
}
deviation "/lldp:lldp/lldp:notification-interval" {
deviate not-supported;
}
Expand Down
File renamed without changes.

0 comments on commit 7de414b

Please sign in to comment.