Skip to content

Commit

Permalink
Fixed: [NACM paths don't work for mounted YANG models](clicon/clixon-…
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Nov 15, 2023
1 parent 2e6d916 commit aaab8a4
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Developers may need to change their code

### Corrected Bugs

* Fixed: [NACM paths don't work for mounted YANG models](https://github.com/clicon/clixon-controller/issues/62)
* Fixed: [cl:creator attribute must be persistent](https://github.com/clicon/clixon-controller/issues/54)
* Fixed: [Does clixon cli support autocompletion for leafrefs pointed to another module?](https://github.com/clicon/clixon/issues/455)
* Fixed: [commit diff sometimes includes namespace in output](https://github.com/clicon/clixon-controller/issues/44)
Expand Down
1 change: 1 addition & 0 deletions lib/clixon/clixon_yang_schema_mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int yang_mount_get(yang_stmt *yu, char *xpath, yang_stmt **yspec);
int yang_mount_set(yang_stmt *yu, char *xpath, yang_stmt *yspec);
int xml_yang_mount_get(clicon_handle h, cxobj *x, validate_level *vl, yang_stmt **yspec);
int xml_yang_mount_set(clicon_handle h, cxobj *x, yang_stmt *yspec);
int yang_mount_get_yspec_any(yang_stmt *y, yang_stmt **yspec);
int xml_yang_mount_freeall(cvec *cvv);
int yang_schema_mount_statedata(clicon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
int yang_schema_mount_statistics(clicon_handle h, cxobj *xt, int modules, cbuf *cb);
Expand Down
21 changes: 17 additions & 4 deletions lib/src/clixon_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ api_path2xpath_cvv(cvec *api_path,
char *name = NULL;
cvec *cvk = NULL; /* vector of index keys */
yang_stmt *y = NULL;
yang_stmt *y1;
yang_stmt *ymod = NULL;
char *val;
cg_var *cvi;
Expand Down Expand Up @@ -807,12 +808,11 @@ api_path2xpath_cvv(cvec *api_path,
cprintf(xpath, "%s:", xprefix);
cprintf(xpath, "%s", name);
}

/* If x/y is mountpoint, pass mount yspec to children */
if ((ret = yang_schema_mount_point(y)) < 0)
goto done;
if (ret == 1){
yang_stmt *y1 = NULL;
y1 = NULL;
if (xml_nsctx_yangspec(yspec, &nsc) < 0)
goto done;
/* cf xml_bind_yang0_opt/xml_yang_mount_get */
Expand Down Expand Up @@ -976,6 +976,7 @@ api_path2xml_vec(char **vec,
int vi;
cxobj *x = NULL;
yang_stmt *y = NULL;
yang_stmt *y1;
yang_stmt *ymod;
yang_stmt *ykey;
char *namespace = NULL;
Expand Down Expand Up @@ -1155,7 +1156,7 @@ api_path2xml_vec(char **vec,
if ((ret = yang_schema_mount_point(y)) < 0)
goto done;
if (ret == 1){
yang_stmt *y1 = NULL;
y1 = NULL;
if (xml_nsctx_yangspec(ys_spec(y), &nsc) < 0)
goto done;
if (xml2xpath(x, nsc, 0, 1, &xpath) < 0) // XXX should be canonical
Expand Down Expand Up @@ -1472,6 +1473,7 @@ api_path_resolve(clixon_path *cplist,
/*! Resolve instance-id prefix:names to yang statements
*
* @param[in] cplist Lisp of clixon-path
* @param[in] path Instance-id path original
* @param[in] yt Yang statement of top symbol (can be yang-spec if top-level)
* @retval 1 OK
* @retval 0 Fail error in xerr
Expand Down Expand Up @@ -1499,7 +1501,8 @@ instance_id_resolve(clixon_path *cplist,
cg_var *cva;
yang_stmt *yspec;
char *kname;

int ret;

yspec = ys_spec(yt);
if ((cp = cplist) != NULL){
do {
Expand All @@ -1513,6 +1516,16 @@ instance_id_resolve(clixon_path *cplist,
goto fail;
}
}
if ((ret = yang_schema_mount_point(yt)) < 0)
goto done;
if (ret == 1){
if (yang_mount_get_yspec_any(yt, &yspec) == 1){
if ((yt = yang_find_module_by_prefix_yspec(yspec, cp->cp_prefix)) == NULL){
clicon_err(OE_YANG, ENOENT, "Prefix \"%s\" does not correspond to any existing module", cp->cp_prefix);
goto fail;
}
}
}
if ((yc = yang_find_datanode(yt, cp->cp_id)) == NULL){
clicon_err(OE_YANG, ENOENT, "Node %s used in path has no corresponding yang node",
cp->cp_id);
Expand Down
34 changes: 31 additions & 3 deletions lib/src/clixon_yang_schema_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ yang_mount_get(yang_stmt *y,
char *xpath,
yang_stmt **yspec)
{
cvec *cvv = NULL;
cg_var *cv;
cvec *cvv;
cg_var *cv;

clicon_debug(CLIXON_DBG_DEFAULT, "%s %s %p", __FUNCTION__, xpath, y);
/* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */
Expand Down Expand Up @@ -328,6 +328,34 @@ xml_yang_mount_set(clicon_handle h,
return retval;
}

/*! Get any yspec of a mount-point, special function
*
* Get (the first) mounted yspec.
* A more generic way would be to call plugin_mount to get the yanglib and from that get the
* yspec. But there is clixon code that cant call the plugin since h is not available
* @param[in] y Yang container/list containing unknown node
* @param[out] yspec YANG stmt spec
* @retval 1 yspec found and set
* @retval 0 Not found
*/
int
yang_mount_get_yspec_any(yang_stmt *y,
yang_stmt **yspec)
{
cvec *cvv;
cg_var *cv;
void *p;

/* Special value in yang unknown node for mount-points: mapping from xpath->mounted yspec */
if ((cvv = yang_cvec_get(y)) != NULL &&
(cv = cvec_i(cvv, 0)) != NULL &&
(p = cv_void_get(cv)) != NULL){
*yspec = p;
return 1;
}
return 0;
}

/*! Free all yspec yang-mounts
*
* @param[in] cvv Cligen-variable vector containing xpath -> yspec mapping
Expand Down Expand Up @@ -663,7 +691,7 @@ yang_schema_yanglib_parse_mount(clicon_handle h,
goto done;
}

/*! Check if XML nod is mount-point and return matching YANG child
/*! Check if XML node is mount-point and return matching YANG child
*
* @param[in] h Clixon handle
* @param[in] x1 XML node
Expand Down
Loading

0 comments on commit aaab8a4

Please sign in to comment.