From 88d81f36c5bebfa5487a711cb38ba41fb575734e Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 27 Aug 2024 16:15:50 +0200 Subject: [PATCH] confd: fix missing yang:operation when deleting syslog actions The srx_get_changes() API, introduced in 18b5922, does not provide the user with a delete yang:operation when the entire YANG tree is deleted. Refactor syslog actions to use the srx_get_diff() API instead. Signed-off-by: Joachim Wiberg --- src/confd/src/ietf-syslog.c | 14 ++++++++------ src/libsrx/src/srx_val.c | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/confd/src/ietf-syslog.c b/src/confd/src/ietf-syslog.c index 33d2d5b8..9e335bfb 100644 --- a/src/confd/src/ietf-syslog.c +++ b/src/confd/src/ietf-syslog.c @@ -207,16 +207,17 @@ static const char *getnm(struct lyd_node *node, char *xpath, size_t len) static int file_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module, const char *xpath, sr_event_t event, unsigned request_id, void *priv) { - struct lyd_node *files, *file; + struct lyd_node *files, *file, *tree; int err; if (SR_EV_DONE != event) return SR_ERR_OK; - err = srx_get_changes(session, XPATH_FILE_, &files); + err = srx_get_diff(session, &tree); if (err) return SR_ERR_OK; + files = lydx_get_descendant(tree, "syslog", "actions", "file", "log-file", NULL); LYX_LIST_FOR_EACH(files, file, "log-file") { struct lyd_node *node = lydx_get_child(file, "name"); enum lydx_op op = lydx_get_op(node); @@ -230,7 +231,7 @@ static int file_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m action(session, name, path, NULL); } - srx_free_changes(files); + srx_free_changes(tree); systemf("initctl -nbq touch sysklogd"); return SR_ERR_OK; @@ -239,16 +240,17 @@ static int file_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m static int remote_change(sr_session_ctx_t *session, uint32_t sub_id, const char *module, const char *xpath, sr_event_t event, unsigned request_id, void *priv) { - struct lyd_node *remotes, *remote; + struct lyd_node *remotes, *remote, *tree; int err; if (SR_EV_DONE != event) return SR_ERR_OK; - err = srx_get_changes(session, XPATH_REMOTE_, &remotes); + err = srx_get_diff(session, &tree); if (err) return SR_ERR_OK; + remotes = lydx_get_descendant(tree, "syslog", "actions", "remote", "destination", NULL); LYX_LIST_FOR_EACH(remotes, remote, "destination") { struct lyd_node *node = lydx_get_child(remote, "name"); enum lydx_op op = lydx_get_op(node); @@ -268,7 +270,7 @@ static int remote_change(sr_session_ctx_t *session, uint32_t sub_id, const char } } - srx_free_changes(remotes); + srx_free_changes(tree); systemf("initctl -nbq touch sysklogd"); return SR_ERR_OK; diff --git a/src/libsrx/src/srx_val.c b/src/libsrx/src/srx_val.c index 1542f045..e77b0635 100644 --- a/src/libsrx/src/srx_val.c +++ b/src/libsrx/src/srx_val.c @@ -43,6 +43,10 @@ static char *token(char *ptr) * it depends. * * When done, call srx_free_changes(treep); + * + * WARNING: this tree does not return any yang:operation for a subtree + * when deleting the entire yang tree (factory reset)! For + * that use-case, only srx_get_diff() works. */ int srx_get_changes(sr_session_ctx_t *session, const char *path, struct lyd_node **treep) {