* New "general-purpose" datastore upgrade callback added which i called once on startup, intended for lo
w-level general upgrades and as a complement to module-specific upgrade. * Called on startup after initial XML parsing, but before module-specific upgrades * Enabled by definign the `.ca_datastore_upgrade` * [General-purpose upgrade documentation](https://clixon-docs.readthedocs.io/en/latest/backend.html#ge neral-purpose) * JSON parse error messages change from ` on line x: syntax error,..` to `json_parse: line x: syntax err or` * Unknown-element error message is more descriptive, eg from `namespace is: urn:example:clixon` to: `Fai led to find YANG spec of XML node: x with parent: xp in namespace urn:example:clixon`. * C-API parse and validation API more capable * `xml_spec_populate` family of functions extended with three-value return values * -1: error, 0: parse OK, 1: parse and YANG binding OK. * `xml_parse` and `json_parse` API changes * Three value returns: -1: error, 0: parse OK, 1: parse and YANG binding OK. * Extended `xml_parse_file2` and `xml_parse_string2` extended API functions with all options available. * New concept called `yang_bind` that defines how XML symbols are bound to YANG after parsing * Existing API same except `xml_parse_file` `endtag` argument moved to `xml_parse_file2` * C-API: Added instrumentation: `xml_size` and `xml_stats_get`. * Fixed: Enabling modstate (CLICON_XMLDB_MODSTATE), changing a revision on a yang, and restarting made the backend daemon exit at start (thanks Matt) * Also: ensure to load `ietf-yang-library.yang ` if CLICON_XMLDB_MODSTATE is set
This commit is contained in:
parent
d665992f7c
commit
9fa5e216c4
80 changed files with 2204 additions and 755 deletions
|
|
@ -3,6 +3,7 @@
|
|||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2019 Olof Hagsand
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -34,6 +35,7 @@
|
|||
* JSON support functions.
|
||||
* JSON syntax is according to:
|
||||
* http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf
|
||||
* RFC 7951 JSON Encoding of Data Modeled with YANG
|
||||
*/
|
||||
#ifndef _CLIXON_JSON_H
|
||||
#define _CLIXON_JSON_H
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2017-2020 Olof Hagsand
|
||||
Copyright (C) 2017-2019 Olof Hagsand
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -85,13 +86,13 @@ int api_path2xml(char *api_path, yang_stmt *yspec, cxobj *xtop,
|
|||
cxobj **xpathp, yang_stmt **ypathp, cxobj **xerr);
|
||||
int xml2api_path_1(cxobj *x, cbuf *cb);
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
int clixon_xml_find_api_path(cxobj *xcur, yang_stmt *yt, cxobj ***vec, size_t *veclen, char *format,
|
||||
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format,
|
||||
...) __attribute__ ((format (printf, 5, 6)));;
|
||||
int clixon_xml_find_instance_id(cxobj *xcur, yang_stmt *yt, cxobj ***vec, size_t *veclen, char *format,
|
||||
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format,
|
||||
...) __attribute__ ((format (printf, 5, 6)));;
|
||||
#else
|
||||
int clixon_xml_find_api_path(cxobj *xcur, yang_stmt *yt, cxobj ***vec, size_t *veclen, char *format,o ...);
|
||||
int clixon_xml_find_instance_id(cxobj *xcur, yang_stmt *yt, cxobj ***vec, size_t *veclen, char *format, ...);
|
||||
int clixon_xml_find_api_path(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format, ...);
|
||||
int clixon_xml_find_instance_id(cxobj *xt, yang_stmt *yt, cxobj ***xvec, size_t *xlen, char *format, ...);
|
||||
#endif
|
||||
|
||||
#endif /* _CLIXON_PATH_H_ */
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -148,8 +149,8 @@ typedef int (plgstatedata_t)(clicon_handle h, cvec *nsc, char *xpath, cxobj *xto
|
|||
|
||||
typedef void *transaction_data;
|
||||
|
||||
/* Transaction callbacks */
|
||||
typedef int (trans_cb_t)(clicon_handle h, transaction_data td);
|
||||
/* Transaction callback */
|
||||
typedef int (trans_cb_t)(clicon_handle h, transaction_data td);
|
||||
|
||||
/*! Hook to override default prompt with explicit function
|
||||
* Format prompt before each getline
|
||||
|
|
@ -159,6 +160,19 @@ typedef int (trans_cb_t)(clicon_handle h, transaction_data td);
|
|||
*/
|
||||
typedef char *(cli_prompthook_t)(clicon_handle, char *mode);
|
||||
|
||||
/*! General-purpose datastore upgrade callback called once on startupo
|
||||
*
|
||||
* Gets called on startup after initial XML parsing, but before module-specific upgrades
|
||||
* and before validation.
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] db Name of datastore, eg "running", "startup" or "tmp"
|
||||
* @param[in] xt XML tree. Upgrade this "in place"
|
||||
* @param[in] msd Info on datastore module-state, if any
|
||||
* @retval -1 Error
|
||||
* @retval 0 OK
|
||||
*/
|
||||
typedef int (datastore_upgrade_t)(clicon_handle h, char *db, cxobj *xt, modstate_diff_t *msd);
|
||||
|
||||
/*! Startup status for use in startup-callback
|
||||
* Note that for STARTUP_ERR and _INVALID, running runs in failsafe mode
|
||||
* and startup contains the erroneous or invalid database.
|
||||
|
|
@ -205,9 +219,9 @@ struct clixon_plugin_api{
|
|||
trans_cb_t *cb_trans_commit; /* Transaction commit */
|
||||
trans_cb_t *cb_trans_revert; /* Transaction revert */
|
||||
trans_cb_t *cb_trans_end; /* Transaction completed */
|
||||
trans_cb_t *cb_trans_abort; /* Transaction aborted */
|
||||
trans_cb_t *cb_trans_abort; /* Transaction aborted */
|
||||
datastore_upgrade_t *cb_datastore_upgrade; /* General-purpose datastore upgrade */
|
||||
} cau_backend;
|
||||
|
||||
} u;
|
||||
};
|
||||
/* Access fields */
|
||||
|
|
@ -224,6 +238,7 @@ struct clixon_plugin_api{
|
|||
#define ca_trans_revert u.cau_backend.cb_trans_revert
|
||||
#define ca_trans_end u.cau_backend.cb_trans_end
|
||||
#define ca_trans_abort u.cau_backend.cb_trans_abort
|
||||
#define ca_datastore_upgrade u.cau_backend.cb_datastore_upgrade
|
||||
|
||||
/*
|
||||
* Macros
|
||||
|
|
@ -271,6 +286,8 @@ int clixon_plugin_auth(clicon_handle h, void *arg);
|
|||
|
||||
int clixon_plugin_extension(clicon_handle h, yang_stmt *yext, yang_stmt *ys);
|
||||
|
||||
int clixon_plugin_datastore_upgrade(clicon_handle h, char *db, cxobj *xt, modstate_diff_t *msd);
|
||||
|
||||
/* rpc callback API */
|
||||
int rpc_callback_register(clicon_handle h, clicon_rpc_cb cb, void *arg, char *namespace, char *name);
|
||||
int rpc_callback_delete_all(clicon_handle h);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -36,7 +37,7 @@
|
|||
#ifndef _CLIXON_STRING_H_
|
||||
#define _CLIXON_STRING_H_
|
||||
|
||||
/* Struct used to map between int and strings. Typically used to map between
|
||||
/*! Struct used to map between int and strings. Typically used to map between
|
||||
* values and their names. Note NULL terminated
|
||||
* Example:
|
||||
* @code
|
||||
|
|
@ -55,6 +56,14 @@ struct map_str2int{
|
|||
};
|
||||
typedef struct map_str2int map_str2int;
|
||||
|
||||
/*! Struct used to map between two strings.
|
||||
*/
|
||||
struct map_str2str{
|
||||
char *ms_s0;
|
||||
char *ms_s1;
|
||||
};
|
||||
typedef struct map_str2str map_str2str;
|
||||
|
||||
/*! A malloc version that aligns on 4 bytes. To avoid warning from valgrind */
|
||||
#define align4(s) (((s)/4)*4 + 4)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2017-2020 Olof Hagsand
|
||||
Copyright (C) 2017-2019 Olof Hagsand
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -77,10 +78,19 @@ enum insert_type{ /* edit-config insert */
|
|||
INS_AFTER,
|
||||
};
|
||||
|
||||
/* XML object types */
|
||||
enum cxobj_type {CX_ERROR=-1,
|
||||
CX_ELMNT,
|
||||
CX_ATTR,
|
||||
CX_BODY};
|
||||
|
||||
/* How to bind yang to XML top-level when parsing */
|
||||
enum yang_bind{
|
||||
YB_NONE, /* Dont try to do Yang binding */
|
||||
YB_PARENT, /* Get yang binding from parents yang */
|
||||
YB_TOP, /* Get yang binding from top-level modules */
|
||||
};
|
||||
|
||||
#define CX_ANY CX_ERROR /* catch all and error is same */
|
||||
|
||||
typedef struct xml cxobj; /* struct defined in clicon_xml.c */
|
||||
|
|
@ -107,6 +117,8 @@ typedef int (xml_applyfn_t)(cxobj *x, void *arg);
|
|||
* Prototypes
|
||||
*/
|
||||
char *xml_type2str(enum cxobj_type type);
|
||||
int xml_stats_get(uint64_t *nr);
|
||||
size_t xml_size(cxobj *xt, size_t *szp);
|
||||
char *xml_name(cxobj *xn);
|
||||
int xml_name_set(cxobj *xn, char *name);
|
||||
char *xml_prefix(cxobj *xn);
|
||||
|
|
@ -115,7 +127,6 @@ char *nscache_get(cxobj *x, char *prefix);
|
|||
int nscache_get_prefix(cxobj *x, char *namespace, char **prefix);
|
||||
cvec *nscache_get_all(cxobj *x);
|
||||
int nscache_set(cxobj *x, char *prefix, char *namespace);
|
||||
|
||||
int nscache_clear(cxobj *x);
|
||||
int nscache_replace(cxobj *x, cvec *ns);
|
||||
|
||||
|
|
@ -181,8 +192,11 @@ int xml_free(cxobj *xn);
|
|||
int xml_print(FILE *f, cxobj *xn);
|
||||
int clicon_xml2file(FILE *f, cxobj *xn, int level, int prettyprint);
|
||||
int clicon_xml2cbuf(cbuf *xf, cxobj *xn, int level, int prettyprint, int32_t depth);
|
||||
int xml_parse_file(int fd, char *endtag, yang_stmt *yspec, cxobj **xt);
|
||||
int xml_parse_file(int fd, yang_stmt *yspec, cxobj **xt);
|
||||
int xml_parse_file2(int fd, enum yang_bind bind, yang_stmt *yspec, char *endtag, cxobj **xt, cxobj **xerr);
|
||||
int xml_parse_string(const char *str, yang_stmt *yspec, cxobj **xml_top);
|
||||
int xml_parse_string2(const char *str, enum yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr);
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
int xml_parse_va(cxobj **xt, yang_stmt *yspec, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -56,11 +57,17 @@ int xml_diff(yang_stmt *yspec, cxobj *x0, cxobj *x1,
|
|||
cxobj ***changed_x0, cxobj ***changed_x1, size_t *changedlen);
|
||||
int xml_tree_prune_flagged_sub(cxobj *xt, int flag, int test, int *upmark);
|
||||
int xml_tree_prune_flagged(cxobj *xt, int flag, int test);
|
||||
int xml_namespace_change(cxobj *x, char *namespace, char *prefix);
|
||||
int xml_default(cxobj *x, void *arg);
|
||||
int xml_sanity(cxobj *x, void *arg);
|
||||
int xml_non_config_data(cxobj *xt, void *arg);
|
||||
int xml_spec_populate_rpc_input(clicon_handle h, cxobj *x, yang_stmt *yspec);
|
||||
int xml_spec_populate(cxobj *x, void *arg);
|
||||
int xml_spec_populate_rpc(cxobj *xrpc, yang_stmt *yspec, cxobj **xerr);
|
||||
int xml_spec_populate_rpc_reply(cxobj *xrpc, char *name, yang_stmt *yspec, cxobj **xerr);
|
||||
int xml_spec_populate0(cxobj *xt, yang_stmt *yspec, cxobj **xerr);
|
||||
int xml_spec_populate0_parent(cxobj *xt, cxobj **xerr);
|
||||
int xml_spec_populate(cxobj *xt, yang_stmt *yspec, cxobj **xerr);
|
||||
int xml_spec_populate_parent(cxobj *xt, cxobj **xerr);
|
||||
|
||||
int xml2xpath(cxobj *x, char **xpath);
|
||||
int assign_namespaces(cxobj *x0, cxobj *x1, cxobj *x1p);
|
||||
int xml_merge(cxobj *x0, cxobj *x1, yang_stmt *yspec, char **reason);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
int xml_child_spec(cxobj *x, cxobj *xp, yang_stmt *yspec, yang_stmt **yp);
|
||||
int xml_cmp(cxobj *x1, cxobj *x2, int same, int skip1);
|
||||
int xml_sort(cxobj *x0, void *arg);
|
||||
int xml_insert(cxobj *xp, cxobj *xc, enum insert_type ins, char *key_val, cvec *nsckey);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
*
|
||||
***** BEGIN LICENSE BLOCK *****
|
||||
|
||||
Copyright (C) 2009-2020 Olof Hagsand
|
||||
Copyright (C) 2009-2019 Olof Hagsand
|
||||
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
|
||||
|
||||
This file is part of CLIXON.
|
||||
|
||||
|
|
@ -51,8 +52,10 @@
|
|||
* This is in state of flux so it needs to be contained and easily changed.
|
||||
*/
|
||||
typedef struct {
|
||||
cxobj *md_del; /* yang module state deletes */
|
||||
cxobj *md_mod; /* yang module state modifications */
|
||||
int md_status; /* 0 if no module-state in a datastore, 1 if there is */
|
||||
char *md_set_id; /* server-specific identifier */
|
||||
cxobj *md_del; /* yang module state deletes */
|
||||
cxobj *md_mod; /* yang module state modifications */
|
||||
} modstate_diff_t;
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue