diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index 708b49f5..620b3e76 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -134,6 +134,12 @@ process_incoming_packet(clicon_handle h, if ((cbret = cbuf_new()) != NULL){ if ((xc = xml_child_i(xret,0))!=NULL){ xa=NULL; + /* Copy message-id attribute from incoming to reply. + * RFC 6241: + * If additional attributes are present in an element, a NETCONF + * peer MUST return them unmodified in the element. This + * includes any "xmlns" attributes. + */ while ((xa = xml_child_each(xrpc, xa, CX_ATTR)) != NULL){ if ((xa2 = xml_dup(xa)) ==NULL) goto done; diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index 83484335..80eebfe2 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -964,12 +964,26 @@ netconf_rpc_dispatch(clicon_handle h, int retval = -1; cxobj *xe; yang_spec *yspec = NULL; + char *username; + cxobj *xa; /* Check incoming RPC against system / netconf RPC:s */ if ((yspec = clicon_netconf_yang(h)) == NULL){ clicon_err(OE_YANG, ENOENT, "No netconf yang spec"); goto done; } + /* Tag username on all incoming requests in case they are forwarded as internal messages + * This may be unecesary since not all are forwarded. + * It may even be wrong if something else is done with the incoming message? + */ + if ((username = clicon_username_get(h)) != NULL){ + if ((xa = xml_new("username", xn, NULL)) == NULL) + goto done; + xml_type_set(xa, CX_ATTR); + if (xml_value_set(xa, username) < 0) + goto done; + } + xe = NULL; while ((xe = xml_child_each(xn, xe, CX_ELMNT)) != NULL) { if (strcmp(xml_name(xe), "get-config") == 0){ @@ -1047,5 +1061,8 @@ netconf_rpc_dispatch(clicon_handle h, } retval = 0; done: + /* Username attribute added at top - otherwise it is returned to sender */ + if ((xa = xml_find(xn, "username")) != NULL) + xml_purge(xa); return retval; }