From d29b7e574cc67c330e9a19347097723178963ed6 Mon Sep 17 00:00:00 2001 From: Colin Baumgarten Date: Thu, 25 Apr 2024 10:22:08 +0200 Subject: [PATCH] xml_merge1(): Allow merging trees with nodes below mountpoints xml_merge1() fails right now when merging trees which have data below mountpoints with an error message like this: XML node %s/%s has no corresponding yang specification (Invalid XML or wrong Yang spec? This is because xml_merge1() does not handle mountpoints. Adjust it accordingly. Note that this was encountered when generating the state of a a yang module that has both state and config below a mountpoint. In that case netconf_trymerge() will be called to merge state and config and will trigger the problem in xml_merge1(). --- lib/src/clixon_xml_map.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/src/clixon_xml_map.c b/lib/src/clixon_xml_map.c index f87ee720..f651c2e9 100644 --- a/lib/src/clixon_xml_map.c +++ b/lib/src/clixon_xml_map.c @@ -1310,6 +1310,22 @@ xml_merge1(cxobj *x0, /* the target */ x1cname = xml_name(x1c); /* Get yang spec of the child */ if ((yc = yang_find_datanode(y0, x1cname)) == NULL){ + /* + * Actually the CLICON_YANG_SCHEMA_MOUNT option should be checked below + * to be consistent with what is done e.g. in + * clixon_datastore_write.c::text_modify() when yang_find_datanode() + * returns NULL. + * However the clixon_handle needed to check this option is not + * available here. + * So check for the YANG_FLAG_MOUNTPOINT flag on y0 as an alternative. + * It will only have been set if CLICON_YANG_SCHEMA_MOUNT is enabled + * and it will be set for exactly those cases where the xml_spec() + * call is needed. + */ + if (yang_flag_get(y0, YANG_FLAG_MOUNTPOINT)) + yc = xml_spec(x1c); + } + if (yc == NULL) { if (reason){ if ((cbr = cbuf_new()) == NULL){ clixon_err(OE_XML, errno, "cbuf_new");