From 43bfc8294220cc81995eb52665e307fbac8ef832 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 28 Sep 2024 18:04:04 +0200 Subject: [PATCH] Break out init of orig-ptr to yang_start() to be made after options --- apps/backend/backend_main.c | 1 + apps/cli/cli_main.c | 2 ++ apps/netconf/netconf_main.c | 1 + apps/restconf/restconf_main_native.c | 1 + apps/snmp/snmp_main.c | 2 +- lib/clixon/clixon_yang.h | 1 + lib/src/clixon_client.c | 1 + lib/src/clixon_yang.c | 18 ++++++++++++++++-- 8 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 3b1ff5bb..d743943f 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -829,6 +829,7 @@ main(int argc, if (nacm_load_external(h) < 0) goto done; } + yang_start(h); /* Create top-level data yangs */ if ((yspec = yspec_new(h, YANG_DATA_TOP)) == NULL) goto done; diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index ebb0cad4..1afc88c0 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -842,8 +842,10 @@ main(int argc, /* In case ietf-yang-metadata is loaded by application, handle annotation extension */ if (yang_metadata_init(h) < 0) goto done; + yang_start(h); /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ xml_nsctx_namespace_netconf_default(h); + /* Create top-level and store as option */ if ((yspec = yspec_new(h, YANG_DATA_TOP)) == NULL) goto done; diff --git a/apps/netconf/netconf_main.c b/apps/netconf/netconf_main.c index 8106a16c..4d27a07b 100644 --- a/apps/netconf/netconf_main.c +++ b/apps/netconf/netconf_main.c @@ -866,6 +866,7 @@ main(int argc, /* Initialize plugin module by creating a handle holding plugin and callback lists */ if (clixon_plugin_module_init(h) < 0) goto done; + yang_start(h); /* In case ietf-yang-metadata is loaded by application, handle annotation extension */ if (yang_metadata_init(h) < 0) goto done; diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index 6583ea39..ded27bd2 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -1353,6 +1353,7 @@ main(int argc, /* Initialize plugin module by creating a handle holding plugin and callback lists */ if (clixon_plugin_module_init(h) < 0) goto done; + yang_start(h); /* Call start function in all plugins before we go interactive */ if (clixon_plugin_start_all(h) < 0) goto done; diff --git a/apps/snmp/snmp_main.c b/apps/snmp/snmp_main.c index a401044e..ded93c99 100644 --- a/apps/snmp/snmp_main.c +++ b/apps/snmp/snmp_main.c @@ -511,7 +511,7 @@ main(int argc, /* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */ xml_nsctx_namespace_netconf_default(h); - + yang_start(h); /* Add (hardcoded) netconf features in case ietf-netconf loaded here * Otherwise it is loaded in netconf_module_load below */ diff --git a/lib/clixon/clixon_yang.h b/lib/clixon/clixon_yang.h index d73e709f..7d3e43ae 100644 --- a/lib/clixon/clixon_yang.h +++ b/lib/clixon/clixon_yang.h @@ -347,6 +347,7 @@ void *yang_action_cb_get(yang_stmt *ys); int yang_action_cb_add(yang_stmt *ys, void *rc); int ys_populate_feature(clixon_handle h, yang_stmt *ys); int yang_init(clixon_handle h); +int yang_start(clixon_handle h); int yang_exit(clixon_handle h); #endif /* _CLIXON_YANG_H_ */ diff --git a/lib/src/clixon_client.c b/lib/src/clixon_client.c index 8de6777d..0fe687a8 100644 --- a/lib/src/clixon_client.c +++ b/lib/src/clixon_client.c @@ -132,6 +132,7 @@ clixon_client_init(const char *config_file) /* Find, read and parse configfile */ if (clicon_options_main(h) < 0) return NULL; + yang_start(h); return h; } diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 5ed11abd..b11bf2de 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -4456,7 +4456,7 @@ yang_action_cb_add(yang_stmt *ys, return 0; } -/*! Init yang code +/*! Init yang code. Called before any yang code, before options * * Add two external tables for YANGs * @param[in] h Clixon handle @@ -4470,7 +4470,6 @@ yang_init(clixon_handle h) map_ptr2ptr *mp; yang_stmt *ymounts; - _yang_use_orig = clicon_option_bool(h, "CLICON_YANG_USE_ORIGINAL"); if ((mp = calloc(1, sizeof(*mp))) == NULL){ clixon_err(OE_UNIX, errno, "calloc"); goto done; @@ -4492,6 +4491,21 @@ yang_init(clixon_handle h) return retval; } +/*! Start yang code. Called after yang options loaded + * + * Called after YANG config and -o options and plugins init + * But before YANG data loaded + * Set local CLICON_YANG_USE_ORIGINAL variable + * @param[in] h Clixon handle + * @retval 0 OK + */ +int +yang_start(clixon_handle h) +{ + _yang_use_orig = clicon_option_bool(h, "CLICON_YANG_USE_ORIGINAL"); + return 0; +} + /*! Exit yang code * * @param[in] h Clixon handle