[Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)
* Applies to all c/h/y/l/sh files and .editorconfig
This commit is contained in:
parent
a9d1ab006c
commit
d84c529ff1
376 changed files with 38147 additions and 38133 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -45,13 +45,13 @@ extern "C" {
|
|||
* Prototypes
|
||||
*/
|
||||
int clixon_snmp_table_handler(netsnmp_mib_handler *handler,
|
||||
netsnmp_handler_registration *nhreg,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests);
|
||||
netsnmp_handler_registration *nhreg,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests);
|
||||
int clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
|
||||
netsnmp_handler_registration *nhreg,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests);
|
||||
netsnmp_handler_registration *nhreg,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests);
|
||||
|
||||
#endif /* _SNMP_HANDLER_H_ */
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -74,7 +74,7 @@ struct clixon_snmp_handle {
|
|||
char *sh_default; /* MIB default value leaf only */
|
||||
cvec *sh_cvk_orig; /* Index/Key variable values (original) */
|
||||
netsnmp_table_registration_info *sh_table_info; /* To mimic table-handler in libnetsnmp code
|
||||
* save only to free properly */
|
||||
* save only to free properly */
|
||||
};
|
||||
typedef struct clixon_snmp_handle clixon_snmp_handle;
|
||||
|
||||
|
|
@ -93,11 +93,11 @@ void *snmp_handle_clone(void *arg);
|
|||
void snmp_handle_free(void *arg);
|
||||
int type_yang2asn1(yang_stmt *ys, int *asn1_type, int extended);
|
||||
int type_snmp2xml(yang_stmt *ys,
|
||||
int *asn1type,
|
||||
netsnmp_variable_list *requestvb,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests,
|
||||
char **valstr);
|
||||
int *asn1type,
|
||||
netsnmp_variable_list *requestvb,
|
||||
netsnmp_agent_request_info *reqinfo,
|
||||
netsnmp_request_info *requests,
|
||||
char **valstr);
|
||||
int type_xml2snmp_pre(char *xmlstr, yang_stmt *ys, char **snmpstr);
|
||||
int type_xml2snmp(char *snmpstr, int *asn1type, u_char **snmpval, size_t *snmplen, char **reason);
|
||||
int snmp_yang2xpath(yang_stmt *ys, cvec *keyvec, char **xpath);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ static void
|
|||
clixon_snmp_sig_term(int arg)
|
||||
{
|
||||
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
__PROGRAM__, __FUNCTION__, getpid(), arg);
|
||||
__PROGRAM__, __FUNCTION__, getpid(), arg);
|
||||
/* This should ensure no more accepts or incoming packets are processed because next time eventloop
|
||||
* is entered, it will terminate.
|
||||
* However there may be a case of sockets closing rather abruptly for clients
|
||||
|
|
@ -114,25 +114,25 @@ snmp_terminate(clicon_handle h)
|
|||
shutdown_agent();
|
||||
clixon_snmp_api_agent_cleanup();
|
||||
if (clicon_ptr_get(h, "snmp-rowstatus-tree", (void**)&x) == 0 && x){
|
||||
xml_free(x);
|
||||
x = NULL;
|
||||
xml_free(x);
|
||||
x = NULL;
|
||||
}
|
||||
clicon_rpc_close_session(h);
|
||||
if ((yspec = clicon_dbspec_yang(h)) != NULL)
|
||||
ys_free(yspec);
|
||||
ys_free(yspec);
|
||||
if ((yspec = clicon_config_yang(h)) != NULL)
|
||||
ys_free(yspec);
|
||||
ys_free(yspec);
|
||||
if ((nsctx = clicon_nsctx_global_get(h)) != NULL)
|
||||
cvec_free(nsctx);
|
||||
cvec_free(nsctx);
|
||||
if ((x = clicon_conf_xml(h)) != NULL)
|
||||
xml_free(x);
|
||||
xml_free(x);
|
||||
xpath_optimize_exit();
|
||||
clixon_event_exit();
|
||||
clicon_handle_exit(h);
|
||||
clixon_err_exit();
|
||||
clicon_log_exit();
|
||||
if (pidfile)
|
||||
unlink(pidfile);
|
||||
unlink(pidfile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ snmp_terminate(clicon_handle h)
|
|||
*/
|
||||
static int
|
||||
clixon_snmp_fdset_register(clicon_handle h,
|
||||
int regfd)
|
||||
int regfd)
|
||||
{
|
||||
int retval = -1;
|
||||
int numfds = 0;
|
||||
|
|
@ -160,23 +160,23 @@ clixon_snmp_fdset_register(clicon_handle h,
|
|||
|
||||
FD_ZERO(&readfds);
|
||||
if ((nr = snmp_sess_select_info(NULL, &numfds, &readfds, &timeout, &block)) < 0){
|
||||
clicon_err(OE_XML, errno, "snmp_select_error");
|
||||
goto done;
|
||||
clicon_err(OE_XML, errno, "snmp_select_error");
|
||||
goto done;
|
||||
}
|
||||
/* eg 4, 6, 8 */
|
||||
for (s=0; s<numfds; s++){
|
||||
if (FD_ISSET(s, &readfds)){
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, s);
|
||||
if (regfd){
|
||||
if (clixon_event_reg_fd(s, clixon_snmp_input_cb, h, "snmp socket") < 0)
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0)
|
||||
goto done;
|
||||
close(s);
|
||||
}
|
||||
}
|
||||
if (FD_ISSET(s, &readfds)){
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, s);
|
||||
if (regfd){
|
||||
if (clixon_event_reg_fd(s, clixon_snmp_input_cb, h, "snmp socket") < 0)
|
||||
goto done;
|
||||
}
|
||||
else{
|
||||
if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0)
|
||||
goto done;
|
||||
close(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -191,7 +191,7 @@ clixon_snmp_fdset_register(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
clixon_snmp_input_cb(int s,
|
||||
void *arg)
|
||||
void *arg)
|
||||
{
|
||||
int retval = -1;
|
||||
fd_set readfds;
|
||||
|
|
@ -203,28 +203,28 @@ clixon_snmp_input_cb(int s,
|
|||
FD_SET(s, &readfds);
|
||||
(void)snmp_read(&readfds);
|
||||
if (clixon_event_poll(s) < 0){
|
||||
if (errno == EBADF){
|
||||
clicon_err_reset();
|
||||
/* Close the active socket */
|
||||
if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0)
|
||||
goto done;
|
||||
close(s);
|
||||
/* and then the others */
|
||||
if (clixon_snmp_fdset_register(h, 0) < 0)
|
||||
goto done;
|
||||
if ((ret = snmp_close_sessions()) != 1){
|
||||
clicon_err(OE_SNMP, ret, "snmp_close_sessions");
|
||||
goto done;
|
||||
}
|
||||
/* Signal normal exit to upper layers (=event handling)
|
||||
* One can signal error and return -1, but it is nicer with an orderly exit
|
||||
*/
|
||||
clixon_exit_set(1);
|
||||
}
|
||||
else {
|
||||
clicon_err(OE_UNIX, errno, "poll");
|
||||
goto done;
|
||||
}
|
||||
if (errno == EBADF){
|
||||
clicon_err_reset();
|
||||
/* Close the active socket */
|
||||
if (clixon_event_unreg_fd(s, clixon_snmp_input_cb) < 0)
|
||||
goto done;
|
||||
close(s);
|
||||
/* and then the others */
|
||||
if (clixon_snmp_fdset_register(h, 0) < 0)
|
||||
goto done;
|
||||
if ((ret = snmp_close_sessions()) != 1){
|
||||
clicon_err(OE_SNMP, ret, "snmp_close_sessions");
|
||||
goto done;
|
||||
}
|
||||
/* Signal normal exit to upper layers (=event handling)
|
||||
* One can signal error and return -1, but it is nicer with an orderly exit
|
||||
*/
|
||||
clixon_exit_set(1);
|
||||
}
|
||||
else {
|
||||
clicon_err(OE_UNIX, errno, "poll");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -238,16 +238,16 @@ clixon_snmp_input_cb(int s,
|
|||
*/
|
||||
static int
|
||||
clixon_snmp_init_subagent(clicon_handle h,
|
||||
int logdst)
|
||||
int logdst)
|
||||
{
|
||||
int retval = -1;
|
||||
char *sockpath = NULL;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
if (logdst == CLICON_LOG_SYSLOG)
|
||||
snmp_enable_calllog();
|
||||
snmp_enable_calllog();
|
||||
else
|
||||
snmp_enable_stderrlog();
|
||||
snmp_enable_stderrlog();
|
||||
/* 0 if master, 1 if client */
|
||||
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
|
||||
/* don't load config and don't load/save persistent file */
|
||||
|
|
@ -258,11 +258,11 @@ clixon_snmp_init_subagent(clicon_handle h,
|
|||
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DISABLE_PERSISTENT_SAVE, 1);
|
||||
|
||||
if (clicon_debug_get())
|
||||
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1);
|
||||
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_VERBOSE, 1);
|
||||
|
||||
if ((sockpath = clicon_option_str(h, "CLICON_SNMP_AGENT_SOCK")) == NULL){
|
||||
clicon_err(OE_XML, 0, "CLICON_SNMP_AGENT_SOCK not set");
|
||||
goto done;
|
||||
clicon_err(OE_XML, 0, "CLICON_SNMP_AGENT_SOCK not set");
|
||||
goto done;
|
||||
}
|
||||
/* XXX: This should be configurable. */
|
||||
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, sockpath);
|
||||
|
|
@ -274,25 +274,25 @@ clixon_snmp_init_subagent(clicon_handle h,
|
|||
init_snmp(__PROGRAM__);
|
||||
|
||||
if (!clixon_snmp_api_agent_check()){
|
||||
clicon_err(OE_DAEMON, 0, "Connection to SNMP agent failed");
|
||||
goto done;
|
||||
clicon_err(OE_DAEMON, 0, "Connection to SNMP agent failed");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
if (set_signal(SIGTERM, clixon_snmp_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGINT, clixon_snmp_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "Setting SIGPIPE signal");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "Setting SIGPIPE signal");
|
||||
goto done;
|
||||
}
|
||||
/* Workaround for netsnmps API use of fdset:s instead of sockets */
|
||||
if (clixon_snmp_fdset_register(h, 1) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
|
@ -307,15 +307,15 @@ usage(clicon_handle h,
|
|||
char *argv0)
|
||||
{
|
||||
fprintf(stderr, "usage:%s\n"
|
||||
"where options are\n"
|
||||
"where options are\n"
|
||||
"\t-h\t\tHelp\n"
|
||||
"\t-D <level>\tDebug level (>1 for extensive libnetsnmp debug)\n"
|
||||
"\t-f <file>\tConfiguration file (mandatory)\n"
|
||||
"\t-l (e|o|s|f<file>) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n"
|
||||
"\t-z\t\tKill other %s daemon and exit\n"
|
||||
"\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
|
||||
argv0, argv0
|
||||
);
|
||||
"\t-D <level>\tDebug level (>1 for extensive libnetsnmp debug)\n"
|
||||
"\t-f <file>\tConfiguration file (mandatory)\n"
|
||||
"\t-l (e|o|s|f<file>) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n"
|
||||
"\t-z\t\tKill other %s daemon and exit\n"
|
||||
"\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
|
||||
argv0, argv0
|
||||
);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
@ -344,40 +344,40 @@ main(int argc,
|
|||
|
||||
/* Create handle */
|
||||
if ((h = clicon_handle_init()) == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
||||
/* Set username to clixon handle. Use in all communication to backend */
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_username_set(h, pw->pw_name) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
while ((c = getopt(argc, argv, SNMP_OPTS)) != -1)
|
||||
switch (c) {
|
||||
case 'h' : /* help */
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'D' : /* debug */
|
||||
if (sscanf(optarg, "%d", &dbg) != 1)
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'f': /* override config file */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv[0]);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case 'h' : /* help */
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'D' : /* debug */
|
||||
if (sscanf(optarg, "%d", &dbg) != 1)
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
case 'f': /* override config file */
|
||||
if (!strlen(optarg))
|
||||
usage(h, argv[0]);
|
||||
clicon_option_str_set(h, "CLICON_CONFIGFILE", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv[0]);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
|
|
@ -386,48 +386,48 @@ main(int argc,
|
|||
clicon_debug_init(dbg, NULL);
|
||||
/* This is netsnmplib debugging which is quite extensive + only if compiled w debug */
|
||||
if (dbg > 1)
|
||||
snmp_set_do_debugging(1);
|
||||
snmp_set_do_debugging(1);
|
||||
/*
|
||||
* Register error category and error/log callbacks for netsnmp special error handling
|
||||
*/
|
||||
if (clixon_err_cat_reg(OE_SNMP, /* category */
|
||||
h, /* handle (can be NULL) */
|
||||
clixon_snmp_err_cb /* log fn */
|
||||
) < 0)
|
||||
goto done;
|
||||
h, /* handle (can be NULL) */
|
||||
clixon_snmp_err_cb /* log fn */
|
||||
) < 0)
|
||||
goto done;
|
||||
|
||||
yang_init(h);
|
||||
|
||||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Now rest of options */
|
||||
optind = 1;
|
||||
opterr = 0;
|
||||
while ((c = getopt(argc, argv, SNMP_OPTS)) != -1)
|
||||
switch (c) {
|
||||
case 'h' : /* help */
|
||||
case 'D' : /* debug */
|
||||
case 'f': /* config file */
|
||||
case 'l': /* log */
|
||||
break; /* see above */
|
||||
case 'o':{ /* Configuration option */
|
||||
char *val;
|
||||
if ((val = index(optarg, '=')) == NULL)
|
||||
usage(h, argv0);
|
||||
*val++ = '\0';
|
||||
if (clicon_option_add(h, optarg, val) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
case 'z': /* Zap other process */
|
||||
zap++;
|
||||
break;
|
||||
default:
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
switch (c) {
|
||||
case 'h' : /* help */
|
||||
case 'D' : /* debug */
|
||||
case 'f': /* config file */
|
||||
case 'l': /* log */
|
||||
break; /* see above */
|
||||
case 'o':{ /* Configuration option */
|
||||
char *val;
|
||||
if ((val = index(optarg, '=')) == NULL)
|
||||
usage(h, argv0);
|
||||
*val++ = '\0';
|
||||
if (clicon_option_add(h, optarg, val) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
case 'z': /* Zap other process */
|
||||
zap++;
|
||||
break;
|
||||
default:
|
||||
usage(h, argv[0]);
|
||||
break;
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
|
|
@ -436,27 +436,27 @@ main(int argc,
|
|||
|
||||
/* Check pid-file, if zap kill the old daemon, else return here */
|
||||
if ((pidfile = clicon_snmp_pidfile(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "pidfile not set");
|
||||
goto done;
|
||||
clicon_err(OE_FATAL, 0, "pidfile not set");
|
||||
goto done;
|
||||
}
|
||||
if (pidfile_get(pidfile, &pid) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (zap){
|
||||
if (pid && pidfile_zapold(pid) < 0)
|
||||
return -1;
|
||||
if (lstat(pidfile, &st) == 0)
|
||||
unlink(pidfile);
|
||||
snmp_terminate(h);
|
||||
exit(0); /* OK */
|
||||
if (pid && pidfile_zapold(pid) < 0)
|
||||
return -1;
|
||||
if (lstat(pidfile, &st) == 0)
|
||||
unlink(pidfile);
|
||||
snmp_terminate(h);
|
||||
exit(0); /* OK */
|
||||
}
|
||||
else if (pid){
|
||||
clicon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)",
|
||||
pid, argv0);
|
||||
return -1; /* goto done deletes pidfile */
|
||||
clicon_err(OE_DAEMON, 0, "Clixon_snmp daemon already running with pid %d\n(Try killing it with %s -z)",
|
||||
pid, argv0);
|
||||
return -1; /* goto done deletes pidfile */
|
||||
}
|
||||
/* Here there is either no old process or we have killed it,.. */
|
||||
if (lstat(pidfile, &st) == 0)
|
||||
unlink(pidfile);
|
||||
unlink(pidfile);
|
||||
|
||||
/* Init cligen buffers */
|
||||
cligen_buflen = clicon_option_int(h, "CLICON_CLI_BUF_START");
|
||||
|
|
@ -464,7 +464,7 @@ main(int argc,
|
|||
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
|
||||
|
||||
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
|
||||
clicon_log_string_limit_set(sz);
|
||||
clicon_log_string_limit_set(sz);
|
||||
|
||||
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
|
||||
xml_nsctx_namespace_netconf_default(h);
|
||||
|
|
@ -473,49 +473,49 @@ main(int argc,
|
|||
* Otherwise it is loaded in netconf_module_load below
|
||||
*/
|
||||
if (netconf_module_features(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Create top-level yang spec and store as option */
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
/* Load Yang modules
|
||||
* 1. Load a yang module as a specific absolute filename */
|
||||
if ((str = clicon_yang_main_file(h)) != NULL){
|
||||
if (yang_spec_parse_file(h, str, yspec) < 0)
|
||||
goto done;
|
||||
if (yang_spec_parse_file(h, str, yspec) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* 2. Load a (single) main module */
|
||||
if ((str = clicon_yang_module_main(h)) != NULL){
|
||||
if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
|
||||
yspec) < 0)
|
||||
goto done;
|
||||
if (yang_spec_parse_module(h, str, clicon_yang_module_revision(h),
|
||||
yspec) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* 3. Load all modules in a directory */
|
||||
if ((str = clicon_yang_main_dir(h)) != NULL){
|
||||
if (yang_spec_load_dir(h, str, yspec) < 0)
|
||||
goto done;
|
||||
if (yang_spec_load_dir(h, str, yspec) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Load clixon lib yang module */
|
||||
if (yang_spec_parse_module(h, "clixon-lib", NULL, yspec) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Load yang module library, RFC7895 */
|
||||
if (yang_modules_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Add netconf yang spec, used by netconf client and as internal protocol */
|
||||
if (netconf_module_load(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Here all modules are loaded
|
||||
* Compute and set canonical namespace context
|
||||
*/
|
||||
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
if (dbg)
|
||||
clicon_option_dump(h, dbg);
|
||||
clicon_option_dump(h, dbg);
|
||||
|
||||
/* Get session id from backend hello */
|
||||
clicon_session_id_set(h, getpid());
|
||||
|
|
@ -526,23 +526,23 @@ main(int argc,
|
|||
* each message sent to the backend.
|
||||
*/
|
||||
if (clicon_hello_req(h, &id) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
clicon_session_id_set(h, id);
|
||||
|
||||
/* Init snmp as subagent */
|
||||
if (clixon_snmp_init_subagent(h, logdst) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Init and traverse mib-translated yangs and register callbacks */
|
||||
if (clixon_snmp_traverse_mibyangs(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Write pid-file */
|
||||
if (pidfile_write(pidfile) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* main event loop */
|
||||
if (clixon_event_loop(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
snmp_terminate(h);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
|
||||
* smiv2:defval "42"; (not always)
|
||||
* 2. container, list
|
||||
* smiv2:oid "1.3.6.1.4.1.8072.2.1";
|
||||
* smiv2:oid "1.3.6.1.4.1.8072.2.1";
|
||||
* 3. module level
|
||||
* smiv2:alias "netSnmpExamples" {
|
||||
* smiv2:oid "1.3.6.1.4.1.8072.2";
|
||||
|
|
@ -96,10 +96,10 @@
|
|||
*/
|
||||
static int
|
||||
mibyang_leaf_register(clicon_handle h,
|
||||
yang_stmt *ys,
|
||||
cvec *cvk_val,
|
||||
oid *oidk,
|
||||
size_t oidklen)
|
||||
yang_stmt *ys,
|
||||
cvec *cvk_val,
|
||||
oid *oidk,
|
||||
size_t oidklen)
|
||||
{
|
||||
int retval = -1;
|
||||
netsnmp_handler_registration *nhreg = NULL;
|
||||
|
|
@ -115,40 +115,40 @@ mibyang_leaf_register(clicon_handle h,
|
|||
cbuf *cboid = NULL;
|
||||
|
||||
if ((cboid = cbuf_new()) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = yangext_oid_get(ys, oid1, &oid1len, NULL)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto ok;
|
||||
goto ok;
|
||||
if (oid_append(oid1, &oid1len, oidk, oidklen) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Check if already registered */
|
||||
if (clixon_snmp_api_oid_find(oid1, oid1len) == 1)
|
||||
goto ok;
|
||||
goto ok;
|
||||
if (yang_extension_value(ys, "max-access", IETF_YANG_SMIV2_NS, NULL, &modes_str) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Only for sanity check of types initially to fail early */
|
||||
if (type_yang2asn1(ys, NULL, 0) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
/* Get modes (access) read-only, read-write, not-accessible, accessible-for-notify
|
||||
*/
|
||||
if (modes_str == NULL)
|
||||
goto ok;
|
||||
goto ok;
|
||||
modes = snmp_access_str2int(modes_str);
|
||||
|
||||
/* SMI default value, How is this different from yang defaults?
|
||||
*/
|
||||
if (yang_extension_value(ys, "defval", IETF_YANG_SMIV2_NS, NULL, &default_str) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
|
||||
name = yang_argument_get(ys);
|
||||
/* Stateless function, just returns ptr */
|
||||
if ((handler = netsnmp_create_handler(name, clixon_snmp_scalar_handler)) == NULL){
|
||||
clicon_err(OE_XML, errno, "netsnmp_create_handler");
|
||||
goto done;
|
||||
clicon_err(OE_XML, errno, "netsnmp_create_handler");
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Userdata to pass around in netsmp callbacks
|
||||
|
|
@ -165,17 +165,17 @@ mibyang_leaf_register(clicon_handle h,
|
|||
sh->sh_oidlen = oid1len;
|
||||
sh->sh_default = default_str;
|
||||
if (cvk_val &&
|
||||
(sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
(sh->sh_cvk_orig = cvec_dup(cvk_val)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "cvec_dup");
|
||||
goto done;
|
||||
}
|
||||
/* Stateless function, just returns ptr */
|
||||
if ((nhreg = netsnmp_handler_registration_create(name, handler,
|
||||
oid1, oid1len,
|
||||
modes)) == NULL){
|
||||
clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
|
||||
netsnmp_handler_free(handler);
|
||||
goto done;
|
||||
oid1, oid1len,
|
||||
modes)) == NULL){
|
||||
clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
|
||||
netsnmp_handler_free(handler);
|
||||
goto done;
|
||||
}
|
||||
/* Register our application data and how to free it */
|
||||
handler->myvoid = (void*)sh;
|
||||
|
|
@ -186,9 +186,9 @@ mibyang_leaf_register(clicon_handle h,
|
|||
* XXX: nhreg->agent_data
|
||||
*/
|
||||
if ((ret = netsnmp_register_instance(nhreg)) != SNMPERR_SUCCESS){
|
||||
/* Note MIB_ errors, not regular SNMPERR_ */
|
||||
clicon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance");
|
||||
goto done;
|
||||
/* Note MIB_ errors, not regular SNMPERR_ */
|
||||
clicon_err(OE_SNMP, ret-CLIXON_ERR_SNMP_MIB, "netsnmp_register_instance");
|
||||
goto done;
|
||||
}
|
||||
oid_cbuf(cboid, oid1, oid1len);
|
||||
clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, cbuf_get(cboid));
|
||||
|
|
@ -196,7 +196,7 @@ mibyang_leaf_register(clicon_handle h,
|
|||
retval = 0;
|
||||
done:
|
||||
if (cboid)
|
||||
cbuf_free(cboid);
|
||||
cbuf_free(cboid);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -218,12 +218,12 @@ mibyang_leaf_register(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
mibyang_table_register(clicon_handle h,
|
||||
yang_stmt *ylist,
|
||||
oid *oid1,
|
||||
size_t oid1len,
|
||||
oid *oid2,
|
||||
size_t oid2len,
|
||||
char *oidstr)
|
||||
yang_stmt *ylist,
|
||||
oid *oid1,
|
||||
size_t oid1len,
|
||||
oid *oid2,
|
||||
size_t oid2len,
|
||||
char *oidstr)
|
||||
{
|
||||
int retval = -1;
|
||||
netsnmp_handler_registration *nhreg;
|
||||
|
|
@ -240,9 +240,9 @@ mibyang_table_register(clicon_handle h,
|
|||
char *name;
|
||||
|
||||
if ((ys = yang_parent_get(ylist)) == NULL ||
|
||||
yang_keyword_get(ys) != Y_CONTAINER){
|
||||
clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
|
||||
goto done;
|
||||
yang_keyword_get(ys) != Y_CONTAINER){
|
||||
clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
|
||||
goto done;
|
||||
}
|
||||
/* Note: This is wrong for augmented nodes where name is the original list, not the
|
||||
* augmented. For example, for IFMIB you get ifTable twice where you should get ifTable for
|
||||
|
|
@ -266,15 +266,15 @@ mibyang_table_register(clicon_handle h,
|
|||
sh->sh_oid2len = oid2len;
|
||||
|
||||
if ((handler = netsnmp_create_handler(name, clixon_snmp_table_handler)) == NULL){
|
||||
clicon_err(OE_XML, errno, "netsnmp_create_handler");
|
||||
goto done;
|
||||
clicon_err(OE_XML, errno, "netsnmp_create_handler");
|
||||
goto done;
|
||||
}
|
||||
if ((nhreg = netsnmp_handler_registration_create(name, handler,
|
||||
oid1, oid1len,
|
||||
HANDLER_CAN_RWRITE)) == NULL){
|
||||
clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
|
||||
netsnmp_handler_free(handler);
|
||||
goto done;
|
||||
oid1, oid1len,
|
||||
HANDLER_CAN_RWRITE)) == NULL){
|
||||
clicon_err(OE_XML, errno, "netsnmp_handler_registration_create");
|
||||
netsnmp_handler_free(handler);
|
||||
goto done;
|
||||
}
|
||||
/* Register our application data and how to free it */
|
||||
handler->myvoid =(void*)sh;
|
||||
|
|
@ -283,35 +283,35 @@ mibyang_table_register(clicon_handle h,
|
|||
|
||||
/* See netsnmp_register_table_data_set */
|
||||
if ((table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF");
|
||||
goto done;
|
||||
clicon_err(OE_UNIX, errno, "SNMP_MALLOC_TYPEDEF");
|
||||
goto done;
|
||||
}
|
||||
/* Keys, go through keys */
|
||||
if ((cvk = yang_cvec_get(ylist)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No keys");
|
||||
goto done;
|
||||
clicon_err(OE_YANG, 0, "No keys");
|
||||
goto done;
|
||||
}
|
||||
cvi = NULL;
|
||||
/* Iterate over individual keys */
|
||||
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
|
||||
keyname = cv_string_get(cvi);
|
||||
if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){
|
||||
clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
|
||||
yang_argument_get(ylist), keyname);
|
||||
goto done;
|
||||
}
|
||||
if (type_yang2asn1(yleaf, &asn1type, 0) < 0)
|
||||
// goto done;
|
||||
goto ok; // XXX skip
|
||||
if (snmp_varlist_add_variable(&table_info->indexes,
|
||||
NULL, // oid name
|
||||
0, // oid len
|
||||
asn1type,
|
||||
NULL, // value
|
||||
0) == NULL){
|
||||
clicon_err(OE_XML, errno, "snmp_varlist_add_variable");
|
||||
goto done;
|
||||
}
|
||||
keyname = cv_string_get(cvi);
|
||||
if ((yleaf = yang_find(ylist, Y_LEAF, keyname)) == NULL){
|
||||
clicon_err(OE_XML, 0, "List statement \"%s\" has no key leaf \"%s\"",
|
||||
yang_argument_get(ylist), keyname);
|
||||
goto done;
|
||||
}
|
||||
if (type_yang2asn1(yleaf, &asn1type, 0) < 0)
|
||||
// goto done;
|
||||
goto ok; // XXX skip
|
||||
if (snmp_varlist_add_variable(&table_info->indexes,
|
||||
NULL, // oid name
|
||||
0, // oid len
|
||||
asn1type,
|
||||
NULL, // value
|
||||
0) == NULL){
|
||||
clicon_err(OE_XML, errno, "snmp_varlist_add_variable");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
table_info->min_column = 1;
|
||||
|
||||
|
|
@ -319,12 +319,12 @@ mibyang_table_register(clicon_handle h,
|
|||
yleaf = NULL;
|
||||
table_info->max_column = 0;
|
||||
while ((yleaf = yn_each(ylist, yleaf)) != NULL) {
|
||||
if (yang_keyword_get(yleaf) == Y_LEAF)
|
||||
table_info->max_column++;
|
||||
if (yang_keyword_get(yleaf) == Y_LEAF)
|
||||
table_info->max_column++;
|
||||
}
|
||||
if ((ret = netsnmp_register_table(nhreg, table_info)) != SNMPERR_SUCCESS){
|
||||
clicon_err(OE_SNMP, ret, "netsnmp_register_table");
|
||||
goto done;
|
||||
clicon_err(OE_SNMP, ret, "netsnmp_register_table");
|
||||
goto done;
|
||||
}
|
||||
sh->sh_table_info = table_info; /* Keep to free at exit */
|
||||
clicon_debug(1, "%s register: %s %s", __FUNCTION__, name, oidstr);
|
||||
|
|
@ -351,7 +351,7 @@ mibyang_table_register(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
mibyang_list_register(clicon_handle h,
|
||||
yang_stmt *ylist)
|
||||
yang_stmt *ylist)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yc;
|
||||
|
|
@ -363,23 +363,23 @@ mibyang_list_register(clicon_handle h,
|
|||
int ret;
|
||||
|
||||
if ((yc = yang_parent_get(ylist)) == NULL ||
|
||||
yang_keyword_get(yc) != Y_CONTAINER){
|
||||
clicon_err(OE_YANG, EINVAL, "ylist parent is not container");
|
||||
goto done;
|
||||
yang_keyword_get(yc) != Y_CONTAINER){
|
||||
clicon_err(OE_YANG, EINVAL, "ylist parent is not container");
|
||||
goto done;
|
||||
}
|
||||
if ((ret = yangext_oid_get(ylist, oid2, &oid2len, NULL)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto ok;
|
||||
goto ok;
|
||||
if ((ret = yangext_oid_get(yc, oid1, &oid1len, &oidstr)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto ok;
|
||||
goto ok;
|
||||
if (mibyang_table_register(h, ylist,
|
||||
oid1, oid1len,
|
||||
oid2, oid2len,
|
||||
oidstr) < 0)
|
||||
goto done;
|
||||
oid1, oid1len,
|
||||
oid2, oid2len,
|
||||
oidstr) < 0)
|
||||
goto done;
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -406,7 +406,7 @@ mibyang_list_register(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
mibyang_augment_register(clicon_handle h,
|
||||
yang_stmt *yaug)
|
||||
yang_stmt *yaug)
|
||||
{
|
||||
int retval = -1;
|
||||
char *schema_nodeid;
|
||||
|
|
@ -420,25 +420,25 @@ mibyang_augment_register(clicon_handle h,
|
|||
char *ri;
|
||||
|
||||
if ((ret = yangext_oid_get(yaug, oid2, &oid2len, &oidstr)) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
goto ok;
|
||||
goto ok;
|
||||
/* Decrement oid of list object (oid2) to container object (oid1) */
|
||||
memcpy(oid1, oid2, sizeof(oid2));
|
||||
oid1len = oid2len - 1;
|
||||
oid1[oid1len] = 0;
|
||||
if ((ri = rindex(oidstr, '.')) != NULL)
|
||||
*ri = '\0';
|
||||
*ri = '\0';
|
||||
schema_nodeid = yang_argument_get(yaug);
|
||||
if (yang_abs_schema_nodeid(yaug, schema_nodeid, &ylist) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
if (yang_keyword_get(ylist) != Y_LIST)
|
||||
goto ok; /* skip */
|
||||
goto ok; /* skip */
|
||||
if (mibyang_table_register(h, ylist,
|
||||
oid1, oid1len,
|
||||
oid2, oid2len,
|
||||
oidstr) < 0)
|
||||
goto done;
|
||||
oid1, oid1len,
|
||||
oid2, oid2len,
|
||||
oidstr) < 0)
|
||||
goto done;
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -459,7 +459,7 @@ mibyang_augment_register(clicon_handle h,
|
|||
*/
|
||||
int
|
||||
mibyang_table_poll(clicon_handle h,
|
||||
yang_stmt *ylist)
|
||||
yang_stmt *ylist)
|
||||
{
|
||||
int retval = -1;
|
||||
cvec *nsc = NULL;
|
||||
|
|
@ -479,9 +479,9 @@ mibyang_table_poll(clicon_handle h,
|
|||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
if ((ys = yang_parent_get(ylist)) == NULL ||
|
||||
yang_keyword_get(ys) != Y_CONTAINER){
|
||||
clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
|
||||
goto done;
|
||||
yang_keyword_get(ys) != Y_CONTAINER){
|
||||
clicon_err(OE_YANG, EINVAL, "ylist parent is not list");
|
||||
goto done;
|
||||
}
|
||||
if (xml_nsctx_yang(ys, &nsc) < 0)
|
||||
goto done;
|
||||
|
|
@ -494,30 +494,30 @@ mibyang_table_poll(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) {
|
||||
/* Make a clone of key-list, but replace names with values */
|
||||
if ((cvk_name = yang_cvec_get(ylist)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No keys");
|
||||
goto done;
|
||||
}
|
||||
xrow = NULL;
|
||||
while ((xrow = xml_child_each(xtable, xrow, CX_ELMNT)) != NULL) {
|
||||
if ((ret = snmp_xmlkey2val_oid(xrow, cvk_name, &cvk_val, oidk, &oidklen)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
continue; /* skip row, not all indexes */
|
||||
xcol = NULL;
|
||||
while ((xcol = xml_child_each(xrow, xcol, CX_ELMNT)) != NULL) {
|
||||
if ((y = xml_spec(xcol)) == NULL)
|
||||
continue;
|
||||
if (mibyang_leaf_register(h, y, cvk_val, oidk, oidklen) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
/* Make a clone of key-list, but replace names with values */
|
||||
if ((cvk_name = yang_cvec_get(ylist)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No keys");
|
||||
goto done;
|
||||
}
|
||||
xrow = NULL;
|
||||
while ((xrow = xml_child_each(xtable, xrow, CX_ELMNT)) != NULL) {
|
||||
if ((ret = snmp_xmlkey2val_oid(xrow, cvk_name, &cvk_val, oidk, &oidklen)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
continue; /* skip row, not all indexes */
|
||||
xcol = NULL;
|
||||
while ((xcol = xml_child_each(xrow, xcol, CX_ELMNT)) != NULL) {
|
||||
if ((y = xml_spec(xcol)) == NULL)
|
||||
continue;
|
||||
if (mibyang_leaf_register(h, y, cvk_val, oidk, oidklen) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (xpath)
|
||||
free(xpath);
|
||||
free(xpath);
|
||||
if (cvk_val)
|
||||
cvec_free(cvk_val);
|
||||
if (xt)
|
||||
|
|
@ -537,7 +537,7 @@ mibyang_table_poll(clicon_handle h,
|
|||
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
|
||||
* smiv2:defval "42"; (not always)
|
||||
* 2. container, list
|
||||
* smiv2:oid "1.3.6.1.4.1.8072.2.1";
|
||||
* smiv2:oid "1.3.6.1.4.1.8072.2.1";
|
||||
* 3. module level
|
||||
* smiv2:alias "netSnmpExamples" {
|
||||
* smiv2:oid "1.3.6.1.4.1.8072.2";
|
||||
|
|
@ -550,51 +550,51 @@ mibyang_table_poll(clicon_handle h,
|
|||
*/
|
||||
static int
|
||||
mibyang_traverse(clicon_handle h,
|
||||
yang_stmt *yn)
|
||||
yang_stmt *yn)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *ys = NULL;
|
||||
yang_stmt *yp;
|
||||
int ret;
|
||||
|
||||
|
||||
clicon_debug(1, "%s %s", __FUNCTION__, yang_argument_get(yn));
|
||||
switch(yang_keyword_get(yn)){
|
||||
case Y_AUGMENT:
|
||||
if (mibyang_augment_register(h, yn) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
break;
|
||||
if (mibyang_augment_register(h, yn) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
break;
|
||||
case Y_LEAF:
|
||||
if (mibyang_leaf_register(h, yn, NULL, NULL, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
if (mibyang_leaf_register(h, yn, NULL, NULL, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case Y_CONTAINER: /* See list case */
|
||||
break;
|
||||
break;
|
||||
case Y_LIST: /* If parent is container -> identify as table */
|
||||
yp = yang_parent_get(yn);
|
||||
if (yang_keyword_get(yp) == Y_CONTAINER){
|
||||
yp = yang_parent_get(yn);
|
||||
if (yang_keyword_get(yp) == Y_CONTAINER){
|
||||
|
||||
/* Register table entry handler itself (not column/row leafs) */
|
||||
if (mibyang_list_register(h, yn) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
break;
|
||||
/* Register table entry handler itself (not column/row leafs) */
|
||||
if (mibyang_list_register(h, yn) < 0)
|
||||
goto done;
|
||||
goto ok;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
/* Traverse data nodes in tree (module is special case */
|
||||
ys = NULL;
|
||||
while ((ys = yn_each(yn, ys)) != NULL) {
|
||||
/* augment special case of table */
|
||||
if (!yang_schemanode(ys) && yang_keyword_get(ys) != Y_AUGMENT)
|
||||
continue;
|
||||
if ((ret = mibyang_traverse(h, ys)) < 0)
|
||||
goto done;
|
||||
if (ret > 0){
|
||||
retval = ret;
|
||||
goto done;
|
||||
}
|
||||
/* augment special case of table */
|
||||
if (!yang_schemanode(ys) && yang_keyword_get(ys) != Y_AUGMENT)
|
||||
continue;
|
||||
if ((ret = mibyang_traverse(h, ys)) < 0)
|
||||
goto done;
|
||||
if (ret > 0){
|
||||
retval = ret;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
ok:
|
||||
retval = 0;
|
||||
|
|
@ -618,32 +618,32 @@ clixon_snmp_traverse_mibyangs(clicon_handle h)
|
|||
yang_stmt *ymod;
|
||||
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
goto done;
|
||||
}
|
||||
/* Loop over clixon configuration file to find all CLICON_SNMP_MIB, and
|
||||
* then loop over all those MIBs to register OIDs with netsnmp
|
||||
*/
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
|
||||
continue;
|
||||
if ((modname = xml_body(x)) == NULL)
|
||||
continue;
|
||||
clicon_debug(1, "%s %s: \"%s\"", __FUNCTION__, xml_name(x), modname);
|
||||
/* Note, here we assume the Yang is loaded by some other mechanism and
|
||||
* error if it not found.
|
||||
* Alternatively, that YANG could be loaded.
|
||||
* Problem is, if clixon_snmp has not loaded it, has backend done it?
|
||||
* What happens if backend has not loaded it?
|
||||
*/
|
||||
if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname);
|
||||
goto done;
|
||||
}
|
||||
/* Recursively traverse the mib-yang to find extensions */
|
||||
if (mibyang_traverse(h, ymod) < 0)
|
||||
goto done;
|
||||
if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
|
||||
continue;
|
||||
if ((modname = xml_body(x)) == NULL)
|
||||
continue;
|
||||
clicon_debug(1, "%s %s: \"%s\"", __FUNCTION__, xml_name(x), modname);
|
||||
/* Note, here we assume the Yang is loaded by some other mechanism and
|
||||
* error if it not found.
|
||||
* Alternatively, that YANG could be loaded.
|
||||
* Problem is, if clixon_snmp has not loaded it, has backend done it?
|
||||
* What happens if backend has not loaded it?
|
||||
*/
|
||||
if ((ymod = yang_find(yspec, Y_MODULE, modname)) == NULL){
|
||||
clicon_err(OE_YANG, 0, "Mib-translated-yang %s not loaded", modname);
|
||||
goto done;
|
||||
}
|
||||
/* Recursively traverse the mib-yang to find extensions */
|
||||
if (mibyang_traverse(h, ymod) < 0)
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue