Skip to content

Commit

Permalink
YANG namespace sanity check
Browse files Browse the repository at this point in the history
YANG shared fix for empty revisions
  • Loading branch information
olofhagsand committed Jun 29, 2024
1 parent 9a553bd commit c53877e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/src/clixon_yang_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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){
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/src/clixon_yang_schema_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c53877e

Please sign in to comment.