diff --git a/package/skeleton-init-finit/skeleton/etc/finit.d/available/lldpd.conf b/package/skeleton-init-finit/skeleton/etc/finit.d/available/lldpd.conf index ccb202f7d..d057d1ff1 100644 --- a/package/skeleton-init-finit/skeleton/etc/finit.d/available/lldpd.conf +++ b/package/skeleton-init-finit/skeleton/etc/finit.d/available/lldpd.conf @@ -1 +1,2 @@ -service [2345] env:-/etc/default/lldpd lldpd -d $LLDPD_ARGS -- LLDP daemon (IEEE 802.1ab) +service env:-/etc/default/lldpd \ + [2345] lldpd -d $LLDPD_ARGS -- LLDP daemon (IEEE 802.1ab) diff --git a/src/confd/src/infix-services.c b/src/confd/src/infix-services.c index b9a66b04b..2c7ab8a1f 100644 --- a/src/confd/src/infix-services.c +++ b/src/confd/src/infix-services.c @@ -21,6 +21,9 @@ #define SSH_HOSTKEYS "/etc/ssh/hostkeys" #define SSH_HOSTKEYS_NEXT SSH_HOSTKEYS"+" + +#define LLDP_CONFIG "/etc/lldpd.d/confd.conf" +#define LLDP_CONFIG_NEXT LLDP_CONFIG"+" #define FOREACH_SVC(SVC) \ SVC(none) \ @@ -125,7 +128,7 @@ 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; @@ -148,7 +151,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 +302,71 @@ 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 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 *node = NULL; + sr_data_t *cfg; + struct lyd_node *subnode; + + switch (event) { + case SR_EV_ENABLED: + case SR_EV_CHANGE: + if (sr_get_data(session, xpath, 0, 0, 0, &cfg) || !cfg) + break; + + node = cfg->tree; + if (lydx_is_enabled(node, "enabled")){ + const char *tx_interval = lydx_get_cattr(node, "message-tx-interval"); + FILE *fp = fopen(LLDP_CONFIG_NEXT, "w"); + if (!fp) { + ERRNO("Failed to open %s for writing", LLDP_CONFIG_NEXT); + break; + } + fprintf(fp, "configure lldp tx-interval %s\n", tx_interval); + + LY_LIST_FOR(lyd_child(node), subnode) { + if (!strcmp(subnode->schema->name, "port")) { + const char *port_name = lydx_get_cattr(subnode, "name"); + const char *admin_status = lydx_get_cattr(subnode, "admin-status"); + + if (strcmp(admin_status, "tx-and-rx") == 0) + admin_status = "rx-and-tx"; + + fprintf(fp, "configure ports %s lldp status %s\n", port_name, admin_status); + } + } + fclose(fp); + } + + return put(cfg); + + case SR_EV_DONE: + if (fexist(LLDP_CONFIG_NEXT)){ + if (erase(LLDP_CONFIG)) + ERRNO("Failed to remove old %s", LLDP_CONFIG); + + rename(LLDP_CONFIG_NEXT, LLDP_CONFIG); + } + else + if (erase(LLDP_CONFIG)) + ERRNO("Failed to remove old %s", LLDP_CONFIG); + + svc_change(session, event, xpath, "lldp", "lldpd"); + break; + + case SR_EV_ABORT: + erase(LLDP_CONFIG_NEXT); + break; + + default: + break; + } + + return SR_ERR_OK; } static int ttyd_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module, @@ -320,7 +381,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 +397,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 +412,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, @@ -447,7 +508,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 */ @@ -463,16 +524,13 @@ static int change_keystore_cb(sr_session_ctx_t *session, uint32_t sub_id, const case SR_EV_ENABLED: break; case SR_EV_ABORT: - /* Remove */ - if(fexist(SSH_HOSTKEYS_NEXT)) - rmrf(SSH_HOSTKEYS_NEXT); + rmrf(SSH_HOSTKEYS_NEXT); return SR_ERR_OK; case SR_EV_DONE: if(fexist(SSH_HOSTKEYS_NEXT)) { - if(fexist(SSH_HOSTKEYS)) - if(rmrf(SSH_HOSTKEYS)) { - ERROR("Failed to remove old SSH hostkeys: %d", errno); - } + if(rmrf(SSH_HOSTKEYS)) { + ERRNO("Failed to remove old SSH hostkeys: %d", errno); + } rename(SSH_HOSTKEYS_NEXT, SSH_HOSTKEYS); svc_change(session, event, "/infix-services:ssh", "ssh", "sshd"); } @@ -515,6 +573,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..2de0a7287 100644 --- a/src/confd/yang/infix-lldp.yang +++ b/src/confd/yang/infix-lldp.yang @@ -11,6 +11,10 @@ module infix-lldp { contact "kernelkit@googlegroups.com"; description "Infix augments and deviations to ieee-dot1ab-lldp."; + revision 2025-01-08 { + description "Enable std. /lldp:lldp/message-tx-interval"; + } + revision 2023-08-23 { description "Initial revision."; reference "internal"; @@ -34,15 +38,9 @@ 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; } - deviation "/lldp:lldp/lldp:port" { - deviate not-supported; - } deviation "/lldp:lldp/lldp:reinit-delay" { deviate not-supported; } @@ -52,4 +50,56 @@ module infix-lldp { deviation "/lldp:lldp/lldp:tx-fast-init" { deviate not-supported; } + + + deviation "/lldp:lldp/lldp:port/lldp:notification-enable" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:tlvs-tx-enable" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:management-address-tx-port" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:port-id-subtype" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:port-id" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:port-desc" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:tx-statistics" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:rx-statistics" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:remote-systems-data" { + deviate not-supported; + } + + + deviation "/lldp:lldp/lldp:port/lldp:message-fast-tx" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:message-tx-hold-multiplier" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:message-tx-interval" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:notification-interval" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:reinit-delay" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:tx-credit-max" { + deviate not-supported; + } + deviation "/lldp:lldp/lldp:port/lldp:tx-fast-init" { + deviate not-supported; + } } 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