SNMP frontend

Fixed table/scalar collision issue
Made the CS variable change said to be in previous commit
This commit is contained in:
Olof hagsand 2022-05-05 23:03:18 +02:00
parent 214b7cc0c7
commit 4e0d9dd987
4 changed files with 111 additions and 58 deletions

View file

@ -394,11 +394,6 @@ main(int argc,
if (clicon_nsctx_global_set(h, nsctx_global) < 0) if (clicon_nsctx_global_set(h, nsctx_global) < 0)
goto done; goto done;
#if 0
/* Call start function is all plugins before we go interactive */
if (clixon_plugin_start_all(h) < 0)
goto done;
#endif
/* Get session id from backend hello */ /* Get session id from backend hello */
clicon_session_id_set(h, getpid()); clicon_session_id_set(h, getpid());

View file

@ -292,6 +292,7 @@ my_test_instance_handler(netsnmp_mib_handler *handler,
return SNMP_ERR_NOERROR; return SNMP_ERR_NOERROR;
} }
#endif #endif
/*! Parse smiv2 extensions for YANG leaf /*! Parse smiv2 extensions for YANG leaf
@ -318,8 +319,6 @@ mib_yang_leaf(clicon_handle h,
char *origtype=NULL; /* original type */ char *origtype=NULL; /* original type */
char *name; char *name;
clicon_debug(1, "%s %s", __FUNCTION__, oidstr);
if (yang_extension_value(ys, "oid", IETF_YANG_SMIV2_NS, NULL, &oidstr) < 0) if (yang_extension_value(ys, "oid", IETF_YANG_SMIV2_NS, NULL, &oidstr) < 0)
goto done; goto done;
if (oidstr == NULL) if (oidstr == NULL)
@ -347,10 +346,12 @@ mib_yang_leaf(clicon_handle h,
goto done; goto done;
// restype = yrestype?yang_argument_get(yrestype):NULL; // restype = yrestype?yang_argument_get(yrestype):NULL;
name = yang_argument_get(ys); name = yang_argument_get(ys);
if ((handler = netsnmp_create_handler(name, my_test_instance_handler)) == NULL){ if ((handler = netsnmp_create_handler(name, my_test_instance_handler)) == NULL){
clicon_err(OE_SNMP, errno, "netsnmp_create_handler"); clicon_err(OE_SNMP, errno, "netsnmp_create_handler");
goto done; goto done;
} }
// handler->myvoid = h; // handler->myvoid = h;
handler->myvoid =(void*)99; handler->myvoid =(void*)99;
if ((nh = netsnmp_handler_registration_create(name, if ((nh = netsnmp_handler_registration_create(name,
@ -362,12 +363,13 @@ mib_yang_leaf(clicon_handle h,
netsnmp_handler_free(handler); netsnmp_handler_free(handler);
goto done; goto done;
} }
clicon_debug(1, "%s %p", __FUNCTION__, nh);
if ((ret = netsnmp_register_instance(nh)) < 0){ if ((ret = netsnmp_register_instance(nh)) < 0){
/* XXX Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ /* XXX Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */
clicon_err(OE_SNMP, ret, "netsnmp_register_instance"); clicon_err(OE_SNMP, ret, "netsnmp_register_instance");
goto done; goto done;
} }
clicon_debug(1, "%s %s registered", __FUNCTION__, oidstr);
ok: ok:
retval = 0; retval = 0;
done: done:
@ -386,27 +388,65 @@ mib_yang_leaf(clicon_handle h,
* @see yang_extension_value * @see yang_extension_value
* @see ys_populate_unknown * @see ys_populate_unknown
*/ */
/*! Traverse mib-yang tree, identify scalars and tables, register OID and callbacks
*
* The tree is traversed depth-first, which at least guarantees that a parent is
* traversed before a child.
* Extensions are grouped in some categories, the one I have seen are, example:
* 1. leaf
* smiv2:max-access "read-write";
* 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";
* 3. module level
* smiv2:alias "netSnmpExamples" {
* smiv2:oid "1.3.6.1.4.1.8072.2";
* @param[in] h Clixon handle
* @param[in] yn yang node
* @retval -1 Error, aborted at first error encounter
* @retval 0 OK, all nodes traversed
*/
static int static int
mib_yang_extension(yang_stmt *ys, mib_traverse(clicon_handle h,
void *arg) yang_stmt *yn)
{ {
int retval = -1; int retval = -1;
clicon_handle h = (clicon_handle)arg; yang_stmt *ys = NULL;
yang_stmt *yp;
int ret;
switch(yang_keyword_get(ys)){ switch(yang_keyword_get(yn)){
case Y_LEAF: case Y_LEAF:
if (mib_yang_leaf(h, ys) < 0) if (mib_yang_leaf(h, yn) < 0)
goto done; goto done;
break; break;
case Y_CONTAINER: // XXX case Y_CONTAINER: // XXX
break; break;
case Y_LIST: // XXX case Y_LIST: // XXX
yp = yang_parent_get(yn);
if (yang_keyword_get(yp) == Y_CONTAINER){
/* XXX ad-hoc method to find table? now skip */
goto ok;
}
break; break;
default: default:
break; break;
} }
ys = NULL;
while ((ys = yn_each(yn, ys)) != NULL) {
if ((ret = mib_traverse(h, ys)) < 0)
goto done;
if (ret > 0){
retval = ret;
goto done;
}
}
ok:
retval = 0; retval = 0;
done: done:
return retval; return retval;
} }
@ -420,8 +460,6 @@ clixon_snmp_mib_yangs(clicon_handle h)
yang_stmt *ymod; yang_stmt *ymod;
/* XXX Hardcoded, replace this with generic MIB */ /* XXX Hardcoded, replace this with generic MIB */
init_testtable(); // XXX
if ((yspec = clicon_dbspec_yang(h)) == NULL){ if ((yspec = clicon_dbspec_yang(h)) == NULL){
clicon_err(OE_FATAL, 0, "No DB_SPEC"); clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done; goto done;
@ -444,9 +482,10 @@ clixon_snmp_mib_yangs(clicon_handle h)
goto done; goto done;
} }
/* Recursively traverse the mib-yang to find extensions */ /* Recursively traverse the mib-yang to find extensions */
if (yang_apply(ymod, -1, mib_yang_extension, 1, h) < 0) if (mib_traverse(h, ymod) < 0)
goto done; goto done;
} }
init_testtable(); // XXX NOTE Must be AFTER loop ^ for unknown reason
retval = 0; retval = 0;
done: done:
return retval; return retval;

View file

@ -48,6 +48,8 @@ EOF
function testinit(){ function testinit(){
new "test params: -f $cfg" new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
# Kill old backend and start a new one # Kill old backend and start a new one
new "kill old backend" new "kill old backend"
sudo clixon_backend -zf $cfg sudo clixon_backend -zf $cfg
@ -59,16 +61,22 @@ function testinit(){
new "Starting backend" new "Starting backend"
start_backend -s init -f $cfg start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
if [ $CS -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp
new "Starting clixon_snmp" new "Starting clixon_snmp"
start_snmp $cfg & start_snmp $cfg &
fi
# Wait for things to settle new "wait snmp"
sleep 3 wait_snmp
} }
function testexit(){ function testexit(){

View file

@ -41,6 +41,7 @@ cat <<EOF > $cfg
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE> <CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR> <CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK> <CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
</clixon-config> </clixon-config>
EOF EOF
@ -57,6 +58,7 @@ EOF
function testinit(){ function testinit(){
new "test params: -f $cfg" new "test params: -f $cfg"
if [ $BE -ne 0 ]; then
# Kill old backend and start a new one # Kill old backend and start a new one
new "kill old backend" new "kill old backend"
sudo clixon_backend -zf $cfg sudo clixon_backend -zf $cfg
@ -68,20 +70,29 @@ function testinit(){
new "Starting backend" new "Starting backend"
start_backend -s init -f $cfg start_backend -s init -f $cfg
fi
new "wait backend"
wait_backend
if [ $CS -ne 0 ]; then
# Kill old clixon_snmp, if any # Kill old clixon_snmp, if any
new "Terminating any old clixon_snmp processes" new "Terminating any old clixon_snmp processes"
sudo killall -q clixon_snmp sudo killall -q clixon_snmp
new "Starting clixon_snmp" new "Starting clixon_snmp"
start_snmp $cfg & start_snmp $cfg &
fi
# Wait for things to settle new "wait snmp"
sleep 3 wait_snmp
} }
function testexit(){ function testexit()
{
if [ $CS -ne 0 ]; then
stop_snmp stop_snmp
fi
} }
new "SNMP table tests" new "SNMP table tests"