Skip to content

Commit

Permalink
Refactored YANG min/max validation code, created new clixon_validate_…
Browse files Browse the repository at this point in the history
…minmax.[ch]

Added new recursive minmax check for non-presence containers
This makes validation checks stricter, including check of incoming RPCs
Renamed xml_yang_check_list_unique_minmax() to xml_yang_minmax_recurse()
Fixed again: [YANG min-elements within non-presence container does not work](#355)
  • Loading branch information
olofhagsand committed Sep 1, 2022
1 parent c8bf718 commit 2eb9c6c
Show file tree
Hide file tree
Showing 17 changed files with 867 additions and 614 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ Expected: September 2022
* idle-timeout for periodic call-homes.
* An example util client is `clixon_restconf_callhome_client.c` used in test cases

### API changes on existing protocol/config features

Users may have to change how they access the system

* Constraints on number of elements have been made stricter (ie unique, min/max-elements)
* Usecases that passed previously may now return error
* This includes:
* Check of incoming RPCs
* Check of non-presence containers

### Corrected Bugs

* Fixed: [YANG ordering fails for nested choice and action](https://github.com/clicon/clixon/issues/356)
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/backend_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ from_client_edit_config(clicon_handle h,
}
/* Limited validation of incoming payload
*/
if ((ret = xml_yang_check_list_unique_minmax(xc, &xret)) < 0)
if ((ret = xml_yang_minmax_recurse(xc, &xret)) < 0)
goto done;
/* xmldb_put (difflist handling) requires list keys */
if (ret==1 && (ret = xml_yang_validate_list_key_only(xc, &xret)) < 0)
Expand Down
1 change: 1 addition & 0 deletions lib/clixon/clixon.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extern "C" {
#include <clixon/clixon_xml_map.h>
#include <clixon/clixon_xml_bind.h>
#include <clixon/clixon_xml_io.h>
#include <clixon/clixon_validate_minmax.h>
#include <clixon/clixon_validate.h>
#include <clixon/clixon_datastore.h>
#include <clixon/clixon_xpath_ctx.h>
Expand Down
3 changes: 1 addition & 2 deletions lib/clixon/clixon_validate.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
***** END LICENSE BLOCK *****
*
* XML code
* Check YANG validation
*/

#ifndef _CLIXON_VALIDATE_H_
Expand All @@ -45,7 +45,6 @@
*/
int xml_yang_validate_rpc(clicon_handle h, cxobj *xrpc, cxobj **xret);
int xml_yang_validate_rpc_reply(clicon_handle h, cxobj *xrpc, cxobj **xret);
int xml_yang_check_list_unique_minmax(cxobj *xt, cxobj **xret);
int xml_yang_validate_add(clicon_handle h, cxobj *xt, cxobj **xret);
int xml_yang_validate_list_key_only(cxobj *xt, cxobj **xret);
int xml_yang_validate_all(clicon_handle h, cxobj *xt, cxobj **xret);
Expand Down
48 changes: 48 additions & 0 deletions lib/clixon/clixon_validate_minmax.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020-2022 Olof Hagsand and Rubicon Communications, LLC (Netgate)
This file is part of CLIXON.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 3 or later (the "GPL"),
in which case the provisions of the GPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of the GPL, and not to allow others to
use your version of this file under the terms of Apache License version 2,
indicate your decision by deleting the provisions above and replace them with
the notice and other provisions required by the GPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the Apache License version 2 or the GPL.
***** END LICENSE BLOCK *****
*
* Check YANG validation for min/max-elements and unique
*/

#ifndef _CLIXON_VALIDATE_MINMAX_H_
#define _CLIXON_VALIDATE_MINMAX_H_

/*
* Prototypes
*/
int xml_yang_minmax_recurse(cxobj *xt, cxobj **xret);

#endif /* _CLIXON_VALIDATE_MINMAX_H_ */
1 change: 0 additions & 1 deletion lib/clixon/clixon_xml.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ cxobj *xml_child_i_type(cxobj *xn, int i, enum cxobj_type type);
cxobj *xml_child_i_set(cxobj *xt, int i, cxobj *xc);
int xml_child_order(cxobj *xn, cxobj *xc);
cxobj *xml_child_each(cxobj *xparent, cxobj *xprev, enum cxobj_type type);

int xml_child_insert_pos(cxobj *x, cxobj *xc, int i);
int xml_childvec_set(cxobj *x, int len);
cxobj **xml_childvec_get(cxobj *x);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_err.c clixon_event.c \
clixon_yang.c clixon_yang_type.c clixon_yang_module.c \
clixon_yang_parse_lib.c clixon_yang_sub_parse.c \
clixon_yang_cardinality.c clixon_xml_changelog.c clixon_xml_nsctx.c \
clixon_path.c clixon_validate.c \
clixon_path.c clixon_validate.c clixon_validate_minmax.c \
clixon_hash.c clixon_options.c clixon_data.c clixon_plugin.c \
clixon_proto.c clixon_proto_client.c \
clixon_xpath.c clixon_xpath_ctx.c clixon_xpath_eval.c clixon_xpath_function.c \
Expand Down
5 changes: 4 additions & 1 deletion lib/src/clixon_datastore_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,10 @@ xmldb_get0_clear(clicon_handle h,
/* Remove global defaults and empty non-presence containers */
if (xml_defaults_nopresence(x, 1) < 0)
goto done;
/* clear flags: mark and change */
/* Clear XML tree of defaults */
if (xml_tree_prune_flagged(x, XML_FLAG_TRANSIENT, 1) < 0)
goto done;
/* clear mark and change */
xml_apply0(x, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
(void*)(XML_FLAG_MARK|XML_FLAG_ADD|XML_FLAG_CHANGE));
ok:
Expand Down
Loading

0 comments on commit 2eb9c6c

Please sign in to comment.