Symbolic and combined debug names in cmd-line of all applications

New debug levels: BACKEND, CLI, NETCONF,RESTCONF, SNMP, STREAM
This commit is contained in:
Olof hagsand 2024-02-02 11:47:01 +01:00
parent 86f251f343
commit 4e3bd6fbdd
39 changed files with 564 additions and 416 deletions

View file

@ -100,7 +100,7 @@ snmp_common_handler(netsnmp_mib_handler *handler,
oid_cbuf(cb, (*shp)->sh_oid, (*shp)->sh_oidlen);
if (oid_eq(requestvb->name, requestvb->name_length,
(*shp)->sh_oid, (*shp)->sh_oidlen) == 0){ /* equal */
clixon_debug(CLIXON_DBG_CLIENT, "\"%s\" %s inclusive:%d %s",
clixon_debug(CLIXON_DBG_SNMP, "\"%s\" %s inclusive:%d %s",
cbuf_get(cb),
snmp_msg_int2str(reqinfo->mode),
request->inclusive, tablehandler?"table":"scalar");
@ -110,7 +110,7 @@ snmp_common_handler(netsnmp_mib_handler *handler,
oid_cbuf(cb, requestvb->name, requestvb->name_length);
cprintf(cb, ")");
// nhreg->rootoid same as shp
clixon_debug(CLIXON_DBG_CLIENT, "\"%s\" %s inclusive:%d %s",
clixon_debug(CLIXON_DBG_SNMP, "\"%s\" %s inclusive:%d %s",
cbuf_get(cb),
snmp_msg_int2str(reqinfo->mode),
request->inclusive, tablehandler?"table":"scalar");
@ -181,7 +181,7 @@ snmp_scalar_return(cxobj *xs,
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
goto done;
if (ret == 0){
clixon_debug(CLIXON_DBG_CLIENT, "%s", reason);
clixon_debug(CLIXON_DBG_SNMP, "%s", reason);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
@ -246,7 +246,7 @@ snmp_scalar_get(clixon_handle h,
cxobj *xcache = NULL;
char *body = NULL;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
/* Prepare backend call by constructing namespace context */
if (xml_nsctx_yang(ys, &nsc) < 0)
goto done;
@ -301,7 +301,7 @@ snmp_scalar_get(clixon_handle h,
if ((ret = type_xml2snmp(xmlstr, &asn1type, &snmpval, &snmplen, &reason)) < 0)
goto done;
if (ret == 0){
clixon_debug(CLIXON_DBG_CLIENT, "%s", reason);
clixon_debug(CLIXON_DBG_SNMP, "%s", reason);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
@ -408,7 +408,7 @@ snmp_scalar_set(clixon_handle h,
int asn1_type;
enum operation_type op = OP_MERGE;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if ((xtop = xml_new(NETCONF_INPUT_CONFIG, NULL, CX_ELMNT)) == NULL)
goto done;
if (snmp_yang2xml(xtop, ys, cvk, &xbot) < 0)
@ -557,7 +557,7 @@ snmp_cache_set(clixon_handle h,
int isrowstatus = 0;
cxobj *xcache = NULL;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if ((yspec = clicon_dbspec_yang(h)) == NULL){
clixon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
@ -601,7 +601,7 @@ snmp_cache_set(clixon_handle h,
goto done;
}
else if (strcmp(valstr, "destroy") == 0){
clixon_debug(CLIXON_DBG_CLIENT, "%d", rowstatus);
clixon_debug(CLIXON_DBG_SNMP, "%d", rowstatus);
/* Don't send delete to backend if notInService(2) */
if (snmp_cache_row_op(h, yang_parent_get(ys), cvk, "delete", rowstatus!=2) < 0)
goto done;
@ -660,7 +660,7 @@ snmp_table_rowstatus_get(clixon_handle h,
cxobj *xr;
char *body;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
/* Prepare backend call by constructing namespace context */
if (xml_nsctx_yang(ys, &nsc) < 0)
goto done;
@ -705,7 +705,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
netsnmp_variable_list *requestvb = request->requestvb;
int ret;
clixon_debug(CLIXON_DBG_CLIENT | CLIXON_DBG_DETAIL, "");
clixon_debug(CLIXON_DBG_SNMP | CLIXON_DBG_DETAIL, "");
if (snmp_common_handler(handler, nhreg, reqinfo, request, 0, &sh) < 0)
goto done;
/* see net-snmp/agent/snmp_agent.h / net-snmp/library/snmp.h */
@ -727,7 +727,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
if (type_yang2asn1(sh->sh_ys, &asn1_type, 0) < 0)
goto done;
if (requestvb->type != asn1_type){
clixon_debug(CLIXON_DBG_CLIENT, "Expected type:%d, got: %d", requestvb->type, asn1_type);
clixon_debug(CLIXON_DBG_SNMP, "Expected type:%d, got: %d", requestvb->type, asn1_type);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok;
@ -774,7 +774,7 @@ clixon_snmp_scalar_handler1(netsnmp_mib_handler *handler,
ok:
retval = SNMP_ERR_NOERROR;
done:
clixon_debug(CLIXON_DBG_CLIENT, "retval:%d", retval);
clixon_debug(CLIXON_DBG_SNMP, "retval:%d", retval);
return retval;
}
@ -798,7 +798,7 @@ clixon_snmp_scalar_handler(netsnmp_mib_handler *handler,
netsnmp_request_info *req;
int ret;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
for (req = requests; req; req = req->next){
ret = clixon_snmp_scalar_handler1(handler, nhreg, reqinfo, req);
if (ret != SNMP_ERR_NOERROR){
@ -1037,7 +1037,7 @@ snmp_table_set(clixon_handle h,
goto done;
requestvb = request->requestvb;
if (requestvb->type != asn1_type){
clixon_debug(CLIXON_DBG_CLIENT, "Expected type:%d, got: %d", requestvb->type, asn1_type);
clixon_debug(CLIXON_DBG_SNMP, "Expected type:%d, got: %d", requestvb->type, asn1_type);
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto ok;
@ -1185,7 +1185,7 @@ snmp_table_getnext(clixon_handle h,
yang_stmt *ynext = NULL;
cbuf *cb = NULL;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){
clixon_err(OE_YANG, EINVAL, "ylist parent is not list");
@ -1247,7 +1247,7 @@ snmp_table_getnext(clixon_handle h,
goto done;
}
oid_cbuf(cb, oidnext, oidnextlen);
clixon_debug(CLIXON_DBG_CLIENT, "next: %s", cbuf_get(cb));
clixon_debug(CLIXON_DBG_SNMP, "next: %s", cbuf_get(cb));
}
retval = found;
done:
@ -1286,11 +1286,11 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
netsnmp_variable_list *requestvb;
int err = 0;
clixon_debug(CLIXON_DBG_CLIENT | CLIXON_DBG_DETAIL, "");
clixon_debug(CLIXON_DBG_SNMP | CLIXON_DBG_DETAIL, "");
if ((ret = snmp_common_handler(handler, nhreg, reqinfo, request, 1, &sh)) < 0)
goto done;
if (sh->sh_ys == NULL){
clixon_debug(CLIXON_DBG_CLIENT, "Error table not registered");
clixon_debug(CLIXON_DBG_SNMP, "Error table not registered");
goto ok;
}
requestvb = request->requestvb;
@ -1308,7 +1308,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
}
clixon_debug(CLIXON_DBG_CLIENT, "Nosuchinstance");
clixon_debug(CLIXON_DBG_SNMP, "Nosuchinstance");
}
break;
case MODE_GETNEXT: // 161
@ -1323,7 +1323,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
}
clixon_debug(CLIXON_DBG_CLIENT, "No such object");
clixon_debug(CLIXON_DBG_SNMP, "No such object");
}
break;
case MODE_SET_RESERVE1: // 0
@ -1345,7 +1345,7 @@ clixon_snmp_table_handler1(netsnmp_mib_handler *handler,
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
}
clixon_debug(CLIXON_DBG_CLIENT, "Nosuchinstance");
clixon_debug(CLIXON_DBG_SNMP, "Nosuchinstance");
}
/*
* There does not seem to be a separate validation action and commit does not
@ -1408,7 +1408,7 @@ clixon_snmp_table_handler(netsnmp_mib_handler *handler,
netsnmp_request_info *req;
int ret;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
for (req = requests; req; req = req->next){
ret = clixon_snmp_table_handler1(handler, nhreg, reqinfo, req);
if (ret != SNMP_ERR_NOERROR){

View file

@ -470,7 +470,7 @@ yangext_oid_get(yang_stmt *yn,
if (yang_extension_value_opt(yref, "smiv2:oid", &exist, &oidstr) < 0)
goto done;
if (exist == 0 || oidstr == NULL){
clixon_debug(CLIXON_DBG_CLIENT, "OID not found as SMIv2 yang extension of %s", yang_argument_get(yref));
clixon_debug(CLIXON_DBG_SNMP, "OID not found as SMIv2 yang extension of %s", yang_argument_get(yref));
goto fail;
}
if (snmp_parse_oid(oidstr, objid, objidlen) == NULL){
@ -649,7 +649,7 @@ type_snmp2xml(yang_stmt *ys,
yang_stmt *yrestype = NULL;
int ret;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if (valstr == NULL){
clixon_err(OE_UNIX, EINVAL, "valstr is NULL");
goto done;
@ -733,7 +733,7 @@ type_snmp2xml(yang_stmt *ys,
}
default:
assert(0); // XXX
clixon_debug(CLIXON_DBG_CLIENT, "%s not supported", cv_type2str(cvtype));
clixon_debug(CLIXON_DBG_SNMP, "%s not supported", cv_type2str(cvtype));
if ((ret = netsnmp_request_set_error(request, SNMP_ERR_WRONGTYPE)) != SNMPERR_SUCCESS){
clixon_err(OE_SNMP, ret, "netsnmp_request_set_error");
goto done;
@ -747,7 +747,7 @@ type_snmp2xml(yang_stmt *ys,
}
retval = 1;
done:
clixon_debug(CLIXON_DBG_CLIENT | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_SNMP | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (origtype)
free(origtype);
if (cv)
@ -794,7 +794,7 @@ type_xml2snmp_pre(char *xmlstr0,
if ((ret = yang_enum2valstr(yrestype, xmlstr0, &str)) < 0)
goto done;
if (ret == 0){
clixon_debug(CLIXON_DBG_CLIENT, "Invalid enum valstr %s", xmlstr0);
clixon_debug(CLIXON_DBG_SNMP, "Invalid enum valstr %s", xmlstr0);
goto fail;
}
}
@ -820,7 +820,7 @@ type_xml2snmp_pre(char *xmlstr0,
if ((ret = parse_dec64(xmlstr0, cv_dec64_n_get(cv), &num, NULL)) < 0)
goto done;
if (ret == 0){
clixon_debug(CLIXON_DBG_CLIENT, "Invalid decimal64 valstr %s", xmlstr0);
clixon_debug(CLIXON_DBG_SNMP, "Invalid decimal64 valstr %s", xmlstr0);
goto fail;
}
cv_dec64_i_set(cv, num);
@ -836,7 +836,7 @@ type_xml2snmp_pre(char *xmlstr0,
}
retval = 1;
done:
clixon_debug(CLIXON_DBG_CLIENT | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_SNMP | CLIXON_DBG_DETAIL, "retval:%d", retval);
if (cb)
cbuf_free(cb);
return retval;
@ -905,7 +905,7 @@ type_xml2snmp(char *snmpstr,
oid oid1[MAX_OID_LEN] = {0,};
size_t sz1 = MAX_OID_LEN;
if (snmp_parse_oid(snmpstr, oid1, &sz1) == NULL){
clixon_debug(CLIXON_DBG_CLIENT, "Failed to parse OID %s", snmpstr);
clixon_debug(CLIXON_DBG_SNMP, "Failed to parse OID %s", snmpstr);
goto fail;
}
*snmplen = sizeof(oid)*sz1;
@ -961,7 +961,7 @@ type_xml2snmp(char *snmpstr,
}
memset(*snmpval, 0, *snmplen + 1);
if ((eaddr = ether_aton(snmpstr)) == NULL){
clixon_debug(CLIXON_DBG_CLIENT, "ether_aton(%s)", snmpstr);
clixon_debug(CLIXON_DBG_SNMP, "ether_aton(%s)", snmpstr);
goto fail;
}
memcpy(*snmpval, eaddr, sizeof(*eaddr));
@ -981,7 +981,7 @@ type_xml2snmp(char *snmpstr,
}
retval = 1;
done:
clixon_debug(CLIXON_DBG_CLIENT | CLIXON_DBG_DETAIL, "retval:%d", retval);
clixon_debug(CLIXON_DBG_SNMP | CLIXON_DBG_DETAIL, "retval:%d", retval);
return retval;
fail:
retval = 0;
@ -1232,7 +1232,7 @@ clixon_snmp_err_cb(void *handle,
{
const char *errstr;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if (suberr < 0){
if (suberr < -CLIXON_ERR_SNMP_MIB){
switch (suberr+CLIXON_ERR_SNMP_MIB){

View file

@ -170,7 +170,7 @@ clixon_snmp_fdset_register(clixon_handle h,
/* eg 4, 6, 8 */
for (s=0; s<numfds; s++){
if (FD_ISSET(s, &readfds)){
clixon_debug(CLIXON_DBG_CLIENT, "%d", s);
clixon_debug(CLIXON_DBG_SNMP, "%d", s);
if (regfd){
if (clixon_event_reg_fd(s, clixon_snmp_input_cb, h, "snmp socket") < 0)
goto done;
@ -205,7 +205,7 @@ clixon_snmp_input_cb(int s,
clixon_handle h = (clixon_handle)arg;
int ret;
clixon_debug(CLIXON_DBG_CLIENT | CLIXON_DBG_DETAIL, "%d", s);
clixon_debug(CLIXON_DBG_SNMP | CLIXON_DBG_DETAIL, "%d", s);
FD_ZERO(&readfds);
FD_SET(s, &readfds);
(void)snmp_read(&readfds);
@ -253,7 +253,7 @@ clixon_snmp_init_subagent(clixon_handle h,
int retval = -1;
char *sockpath = NULL;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if (logdst == CLIXON_LOG_SYSLOG)
snmp_enable_calllog();
else
@ -320,7 +320,7 @@ usage(clixon_handle h,
"where options are\n"
"\t-h\t\tHelp\n"
"\t-V \t\tPrint version and exit\n"
"\t-D <level>\tDebug level (>1 for extensive libnetsnmp debug)\n"
"\t-D <level> \tDebug level (see available levels below)\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-C <format>\tDump configuration options on stdout after loading. Format is xml|json|text\n"
@ -328,6 +328,9 @@ usage(clixon_handle h,
"\t-o \"<option>=<value>\"\tGive configuration option overriding config file (see clixon-config.yang)\n",
argv0, argv0
);
fprintf(stderr, "Debug keys: ");
clixon_debug_key_dump(stderr);
fprintf(stderr, "\n");
exit(0);
}
@ -381,10 +384,16 @@ main(int argc,
cligen_output(stdout, "Clixon version %s\n", CLIXON_VERSION_STRING);
exit(0);
break;
case 'D' : /* debug */
if (sscanf(optarg, "%d", &dbg) != 1)
case 'D' : { /* debug */
int d = 0;
/* Try first symbolic, then numeric match */
if ((d = clixon_debug_str2key(optarg)) < 0 &&
sscanf(optarg, "%d", &d) != 1){
usage(h, argv[0]);
}
dbg |= d;
break;
}
case 'f': /* override config file */
if (!strlen(optarg))
usage(h, argv[0]);
@ -571,7 +580,7 @@ main(int argc,
goto done;
ok:
retval = 0;
done:
done:
snmp_terminate(h);
clixon_log_init(h, __PROGRAM__, LOG_INFO, 0); /* Log on syslog no stderr */
clixon_log(h, LOG_NOTICE, "%s: %u Terminated", __PROGRAM__, getpid());

View file

@ -190,7 +190,7 @@ mibyang_leaf_register(clixon_handle h,
goto done;
}
oid_cbuf(cboid, oid1, oid1len);
clixon_debug(CLIXON_DBG_CLIENT, "register: %s %s", name, cbuf_get(cboid));
clixon_debug(CLIXON_DBG_SNMP, "register: %s %s", name, cbuf_get(cboid));
ok:
retval = 0;
done:
@ -327,7 +327,7 @@ mibyang_table_register(clixon_handle h,
goto done;
}
sh->sh_table_info = table_info; /* Keep to free at exit */
clixon_debug(CLIXON_DBG_CLIENT, "register: %s %s", name, oidstr);
clixon_debug(CLIXON_DBG_SNMP, "register: %s %s", name, oidstr);
ok:
retval = 0;
done:
@ -478,7 +478,7 @@ mibyang_table_poll(clixon_handle h,
oid oidk[MAX_OID_LEN] = {0,};
size_t oidklen = MAX_OID_LEN;
clixon_debug(CLIXON_DBG_CLIENT, "");
clixon_debug(CLIXON_DBG_SNMP, "");
if ((ys = yang_parent_get(ylist)) == NULL ||
yang_keyword_get(ys) != Y_CONTAINER){
clixon_err(OE_YANG, EINVAL, "ylist parent is not list");
@ -559,7 +559,7 @@ mibyang_traverse(clixon_handle h,
int ret;
static oid zero_oid = 0;
clixon_debug(CLIXON_DBG_CLIENT, "%s", yang_argument_get(yn));
clixon_debug(CLIXON_DBG_SNMP, "%s", yang_argument_get(yn));
switch(yang_keyword_get(yn)){
case Y_AUGMENT:
if (mibyang_augment_register(h, yn) < 0)
@ -632,7 +632,7 @@ clixon_snmp_traverse_mibyangs(clixon_handle h)
continue;
if ((modname = xml_body(x)) == NULL)
continue;
clixon_debug(CLIXON_DBG_CLIENT, "%s: \"%s\"", xml_name(x), modname);
clixon_debug(CLIXON_DBG_SNMP, "%s: \"%s\"", 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.