Skip to content

Commit 07e72c4

Browse files
jeremie6windmichalvasko
authored andcommitted
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: 3936132 ("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
1 parent 2549f8f commit 07e72c4

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,24 @@ np2srv_rpc_cb(struct lyd_node *rpc, struct nc_session *ncs)
401401
/* error reply */
402402
reply = np_reply_err_sr(user_sess->sess, LYD_NAME(rpc));
403403
} else if (output) {
404-
/* data reply */
405-
reply = np_reply_success(rpc, output->tree);
406-
output->tree = NULL;
404+
struct lyd_node *child = NULL;
405+
int has_non_default = 0;
406+
407+
LY_LIST_FOR(lyd_child(output->tree), child) {
408+
if (!(child->flags & LYD_DEFAULT)) {
409+
has_non_default = 1;
410+
break;
411+
}
412+
}
413+
414+
if (has_non_default) {
415+
/* data reply */
416+
reply = np_reply_success(rpc, output->tree);
417+
output->tree = NULL;
418+
} else {
419+
/* OK reply */
420+
reply = np_reply_success(rpc, NULL);
421+
}
407422
} else {
408423
/* OK reply */
409424
reply = np_reply_success(rpc, NULL);

0 commit comments

Comments
 (0)