From 352a1f1f64e48c1493b62f80fd5cd9e661cd70ce Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 11 Jun 2023 20:45:26 +0200 Subject: [PATCH] confd: refactor, make lydx_is_enabled() available to all modules Signed-off-by: Joachim Wiberg --- src/confd/src/confd/infix-dhcp.c | 15 ++------------- src/confd/src/lib/lyx.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/confd/src/confd/infix-dhcp.c b/src/confd/src/confd/infix-dhcp.c index f267aec3..25a9ad0c 100644 --- a/src/confd/src/confd/infix-dhcp.c +++ b/src/confd/src/confd/infix-dhcp.c @@ -18,17 +18,6 @@ static const struct srx_module_requirement infix_dhcp_reqs[] = { { NULL } }; -static int is_enabled(struct lyd_node *parent, const char *name) -{ - const char *attr; - - attr = lydx_get_cattr(parent, name); - if (!attr || strcmp(attr, "true")) - return 0; - - return 1; -} - static void add(const char *ifname, const char *client_id) { char *args = NULL; @@ -87,7 +76,7 @@ static int client_change(sr_session_ctx_t *session, uint32_t sub_id, const char goto err_release_data; global = lydx_get_descendant(cfg->tree, "dhcp-client", NULL); - ena = is_enabled(global, "enabled"); + ena = lydx_is_enabled(global, "enabled"); cifs = lydx_get_descendant(cfg->tree, "dhcp-client", "client-if", NULL); difs = lydx_get_descendant(diff, "dhcp-client", "client-if", NULL); @@ -105,7 +94,7 @@ static int client_change(sr_session_ctx_t *session, uint32_t sub_id, const char if (strcmp(ifname, lydx_get_cattr(cif, "if-name"))) continue; - if (!ena || !is_enabled(cif, "enabled")) + if (!ena || !lydx_is_enabled(cif, "enabled")) del(ifname); else add(ifname, lydx_get_cattr(cif, "client-id")); diff --git a/src/confd/src/lib/lyx.h b/src/confd/src/lib/lyx.h index 494a39f2..7d4e91e9 100644 --- a/src/confd/src/lib/lyx.h +++ b/src/confd/src/lib/lyx.h @@ -48,4 +48,15 @@ int lydx_new_path(const struct ly_ctx *ctx, struct lyd_node **parent, int *first char *node, const char *fmt, ...) __attribute__ ((format (printf, 6, 7))); +static inline int lydx_is_enabled(struct lyd_node *parent, const char *name) +{ + const char *attr; + + attr = lydx_get_cattr(parent, name); + if (!attr || strcmp(attr, "true")) + return 0; + + return 1; +} + #endif /* CONFD_LY_EXT_H_ */