Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confd: Enable config for lldp tx interval #882

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
89 changes: 74 additions & 15 deletions src/confd/src/infix-services.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
axkar marked this conversation as resolved.
Show resolved Hide resolved
}
}
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);
axkar marked this conversation as resolved.
Show resolved Hide resolved
break;

default:
break;
}

return SR_ERR_OK;
}

static int ttyd_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 */
Expand All @@ -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");
}
Expand Down Expand Up @@ -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;
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
62 changes: 56 additions & 6 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 "Enable std. /lldp:lldp/message-tx-interval";
}

revision 2023-08-23 {
description "Initial revision.";
reference "internal";
Expand All @@ -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;
}
Expand All @@ -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;
}
}
File renamed without changes.