diff --git a/src/confd/src/infix-services.c b/src/confd/src/infix-services.c index b9a66b04b..6b124f1d8 100644 --- a/src/confd/src/infix-services.c +++ b/src/confd/src/infix-services.c @@ -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; @@ -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) @@ -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, "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, @@ -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, @@ -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, @@ -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, @@ -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; @@ -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 */ @@ -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; @@ -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; diff --git a/src/confd/yang/confd.inc b/src/confd/yang/confd.inc index 4f87d649b..93a67cdb8 100644 --- a/src/confd/yang/confd.inc +++ b/src/confd/yang/confd.inc @@ -29,7 +29,7 @@ MODULES=( "infix-if-type@2024-10-13.yang" "infix-routing@2024-11-27.yang" "ieee802-dot1ab-lldp@2022-03-15.yang" - "infix-lldp@2023-08-23.yang" + "infix-lldp@2025-01-08.yang" "infix-dhcp-client@2024-09-20.yang" "infix-meta@2024-10-18.yang" "infix-system@2024-11-27.yang" diff --git a/src/confd/yang/infix-lldp.yang b/src/confd/yang/infix-lldp.yang index ba560b640..665cf5266 100644 --- a/src/confd/yang/infix-lldp.yang +++ b/src/confd/yang/infix-lldp.yang @@ -9,7 +9,11 @@ module infix-lldp { organization "KernelKit"; contact "kernelkit@googlegroups.com"; - description "Infix augments and deviations to ieee-dot1ab-lldp."; + description "This module extends and modifies the ieee802-dot1ab-lldp YANG model to add specific configuration options."; + + revision 2025-01-08 { + description "Added support for configuring the regular transmit interval."; + } revision 2023-08-23 { description "Initial revision."; @@ -21,11 +25,20 @@ module infix-lldp { */ augment "/lldp:lldp" { - description "Augment of ieee802-dot1ab-lldp with a global enabled flag."; + description "Extension of the ieee802-dot1ab-lldp model to include a global enable flag and regular transmit interval configuration."; + leaf enabled { type boolean; description "Globally enable or disable IEEE 802.1ab LLDP agent."; } + + leaf tx-interval { + type uint16 { + range "1..3600"; + } + default "30"; + description "Specifies the regular interval (in seconds) for LLDP message transmissions."; + } } deviation "/lldp:lldp/lldp:message-fast-tx" { diff --git a/src/confd/yang/infix-lldp@2023-08-23.yang b/src/confd/yang/infix-lldp@2025-01-08.yang similarity index 100% rename from src/confd/yang/infix-lldp@2023-08-23.yang rename to src/confd/yang/infix-lldp@2025-01-08.yang