YANG namespace sanity check

YANG shared fix for empty revisions
This commit is contained in:
Olof hagsand 2024-06-29 10:26:25 +02:00
parent 9a553bdcaa
commit c53877eb78
2 changed files with 19 additions and 2 deletions

View file

@ -855,6 +855,8 @@ yang_lib2yspec(clixon_handle h,
int retval = -1;
cxobj *xi;
char *name;
char *ns;
char *ns2;
char *revision;
cvec *nsc = NULL;
cxobj **vec = NULL;
@ -870,6 +872,7 @@ yang_lib2yspec(clixon_handle h,
xi = vec[i];
if ((name = xml_find_body(xi, "name")) == NULL)
continue;
ns = xml_find_body(xi, "namespace");
revision = xml_find_body(xi, "revision");
if ((ymod = yang_find(yspec, Y_MODULE, name)) != NULL ||
(ymod = yang_find(yspec, Y_SUBMODULE, name)) != NULL){
@ -887,6 +890,17 @@ yang_lib2yspec(clixon_handle h,
}
if (yang_parse_module(h, name, revision, yspec, NULL) == NULL)
goto fail;
/* Sanity check: if given namespace differs from namespace in file */
if (ns != NULL) {
if ((ymod = yang_find(yspec, Y_MODULE, name)) != NULL) {
if ((ns2 = yang_find_mynamespace(ymod)) != NULL){
if (strcmp(ns, ns2) != 0){
clixon_err(OE_YANG, 0, "Module:%s namespace mismatch %s vs %s", name, ns, ns2);
goto fail;
}
}
}
}
}
#ifdef YANG_SCHEMA_MOUNT_YANG_LIB_FORCE
/* Force add ietf-yang-library@2019-01-04 on all mount-points

View file

@ -865,7 +865,7 @@ yang_schema_cmp_kludge(clixon_handle h,
}
}
revision2 = xml_find_body(x2, "revision");
if (clicon_strcmp(revision1, revision2) != 0){
if (revision1 && revision2 && clicon_strcmp(revision1, revision2) != 0){
clixon_debug(CLIXON_DBG_YANG, "revision mismatch %s %s\n", revision1, revision2);
goto noteq;
}
@ -899,7 +899,7 @@ yang_schema_cmp_kludge(clixon_handle h,
}
}
revision1 = xml_find_body(x1, "revision");
if (clicon_strcmp(revision1, revision2) != 0){
if (revision1 && revision2 && clicon_strcmp(revision1, revision2) != 0){
clixon_debug(CLIXON_DBG_YANG, "revision mismatch %s %s\n", revision1, revision2);
goto noteq;
}
@ -1037,11 +1037,14 @@ yang_schema_yanglib_parse_mount(clixon_handle h,
/* Parse it and set mount-point */
if ((yspec = yspec_new()) == NULL)
goto done;
clixon_debug(CLIXON_DBG_YANG, "new yang-spec: %p", yspec);
if ((ret = yang_lib2yspec(h, xyanglib, yspec)) < 0)
goto done;
if (ret == 0)
goto anydata;
}
else
clixon_debug(CLIXON_DBG_YANG, "shared yang-spec: %p", yspec);
if (xml_yang_mount_set(h, xt, yspec) < 0)
goto done;
if (shared)