From a2aa9043c07ea77545b899a354c12546a4e6e3e8 Mon Sep 17 00:00:00 2001 From: Jeremie Leska Date: Wed, 13 Aug 2025 17:04:08 +0200 Subject: [PATCH] main BUGFIX fix empty rpc-reply When an RPC output has a container and the RPC callback returns nothing, the np2srv_rpc_cb does not add the 'ok' empty leaf. The rpc-reply is empty. The client receives an error when it reads the RPC response with nc_recv_reply, because it expects either 'ok' or 'data'. Look at the content of the reply and add the 'ok' leaf if no child with the default flag is found. Fixes: 3936132d91d6 ("server UPDATE call NC RPC directly, not using sysrepo") Link: https://datatracker.ietf.org/doc/html/rfc7950#section-7.14.4 Link: https://datatracker.ietf.org/doc/html/rfc6241#section-4.4 --- src/main.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 9e36a2f7..de014062 100644 --- a/src/main.c +++ b/src/main.c @@ -401,9 +401,24 @@ np2srv_rpc_cb(struct lyd_node *rpc, struct nc_session *ncs) /* error reply */ reply = np_reply_err_sr(user_sess->sess, LYD_NAME(rpc)); } else if (output) { - /* data reply */ - reply = np_reply_success(rpc, output->tree); - output->tree = NULL; + struct lyd_node *child = NULL; + int has_non_default = 0; + + LY_LIST_FOR(lyd_child(output->tree), child) { + if (!(child->flags & LYD_DEFAULT)) { + has_non_default = 1; + break; + } + } + + if (has_non_default) { + /* data reply */ + reply = np_reply_success(rpc, output->tree); + output->tree = NULL; + } else { + /* OK reply */ + reply = np_reply_success(rpc, NULL); + } } else { /* OK reply */ reply = np_reply_success(rpc, NULL);