Commit b9e83a64 authored by Alessandro Rubini's avatar Alessandro Rubini

snmp library: rename the fake Pstats to Scalar

I want to keep this scalar thing in place as a minimal working thing.
However, to rename an object I need to redo everything from scratch.
No comment on the quality of this all.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 54c5ad69
...@@ -12,7 +12,7 @@ CFLAGS = -fPIC $$($(NET_SNMP_CONFIG) --cflags) ...@@ -12,7 +12,7 @@ CFLAGS = -fPIC $$($(NET_SNMP_CONFIG) --cflags)
LDFLAGS = -shared $$($(NET_SNMP_CONFIG) --ldflags) LDFLAGS = -shared $$($(NET_SNMP_CONFIG) --ldflags)
SHLIB = wrsSnmp.so SHLIB = wrsSnmp.so
SOURCES = init.c wrsPstats.c SOURCES = init.c wrsScalar.c
OBJECTS = $(SOURCES:.c=.o) OBJECTS = $(SOURCES:.c=.o)
all: $(SHLIB) all: $(SHLIB)
......
...@@ -10,5 +10,7 @@ And then this "intuitive" command: ...@@ -10,5 +10,7 @@ And then this "intuitive" command:
$BUILD_DIR/netsnmp-5.6.1.1/local/mib2c \ $BUILD_DIR/netsnmp-5.6.1.1/local/mib2c \
-I $BUILD_DIR//netsnmp-5.6.1.1/local \ -I $BUILD_DIR//netsnmp-5.6.1.1/local \
-c mib2c.scalar.conf \ -c mib2c.scalar.conf \
wrsPstats wrsScalar
Clearly, if you rename the item, the code must be completely rewritten.
...@@ -28,18 +28,18 @@ wrSwitchMIB MODULE-IDENTITY ...@@ -28,18 +28,18 @@ wrSwitchMIB MODULE-IDENTITY
-- Define typical mib nodes -- Define typical mib nodes
-- we'll prefix everything in this mib with wrs (White Rabbit Switch) -- we'll prefix everything in this mib with wrs (White Rabbit Switch)
wrsPstats OBJECT IDENTIFIER ::= { wrSwitchMIB 1 } wrsScalar OBJECT IDENTIFIER ::= { wrSwitchMIB 1 }
wrsPpsi OBJECT IDENTIFIER ::= { wrSwitchMIB 2 } wrsPstats OBJECT IDENTIFIER ::= { wrSwitchMIB 2 }
wrsPpsi OBJECT IDENTIFIER ::= { wrSwitchMIB 3 }
-- define 1 stupid object for a start -- define one stupid object for a start
wrsPstatsOne OBJECT-TYPE wrsScalarOne OBJECT-TYPE
SYNTAX Integer32 SYNTAX Integer32
MAX-ACCESS read-write MAX-ACCESS read-write
STATUS current STATUS current
DESCRIPTION DESCRIPTION
"Just an integer" "Just an integer"
DEFVAL { 666 } ::= { wrsScalar 1 }
::= { wrsPstats 1 }
END END
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include <net-snmp/agent/net-snmp-agent-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h>
/* The sub-init functions */ /* The sub-init functions */
#include "wrsPstats.h" #include "wrsScalar.h"
void void
init_wrsSnmp(void) init_wrsSnmp(void)
{ {
init_wrsPstats(); init_wrsScalar();
} }
...@@ -6,29 +6,26 @@ ...@@ -6,29 +6,26 @@
#include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h> #include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h>
#include "wrsPstats.h" #include "wrsScalar.h"
#include <stdint.h> /** Initializes the wrsScalar module */
static uint32_t fakeStatValue;
/** Initializes the wrsPstats module */
void void
init_wrsPstats(void) init_wrsScalar(void)
{ {
const oid wrsPstatsOne_oid[] = const oid wrsScalarOne_oid[] =
{ 1, 3, 6, 1, 4, 1, 96, 100, 1, 1 }; { 1, 3, 6, 1, 4, 1, 96, 100, 1, 1 };
DEBUGMSGTL(("wrsPstats", "Initializing\n")); DEBUGMSGTL(("wrsScalar", "Initializing\n"));
netsnmp_register_scalar(netsnmp_create_handler_registration netsnmp_register_scalar(netsnmp_create_handler_registration
("wrsPstatsOne", handle_wrsPstatsOne, ("wrsScalarOne", handle_wrsScalarOne,
wrsPstatsOne_oid, wrsScalarOne_oid,
OID_LENGTH(wrsPstatsOne_oid), OID_LENGTH(wrsScalarOne_oid),
HANDLER_CAN_RWRITE)); HANDLER_CAN_RWRITE));
} }
int int
handle_wrsPstatsOne(netsnmp_mib_handler *handler, handle_wrsScalarOne(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo, netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo, netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) netsnmp_request_info *requests)
...@@ -47,10 +44,13 @@ handle_wrsPstatsOne(netsnmp_mib_handler *handler, ...@@ -47,10 +44,13 @@ handle_wrsPstatsOne(netsnmp_mib_handler *handler,
switch (reqinfo->mode) { switch (reqinfo->mode) {
case MODE_GET: case MODE_GET:
fakeStatValue++;
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER, snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
&fakeStatValue, /*
sizeof(fakeStatValue)); * XXX: a pointer to the scalar's data
*/ ,
/*
* XXX: the length of the data in bytes
*/ );
break; break;
/* /*
...@@ -70,26 +70,64 @@ handle_wrsPstatsOne(netsnmp_mib_handler *handler, ...@@ -70,26 +70,64 @@ handle_wrsPstatsOne(netsnmp_mib_handler *handler,
break; break;
case MODE_SET_RESERVE2: case MODE_SET_RESERVE2:
/*
* XXX malloc "undo" storage buffer
*/
if ( /* XXX if malloc, or whatever, failed: */ ) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
break;
case MODE_SET_FREE: case MODE_SET_FREE:
/*
* XXX: free resources allocated in RESERVE1 and/or
* RESERVE2. Something failed somewhere, and the states
* below won't be called.
*/
break; break;
case MODE_SET_ACTION: case MODE_SET_ACTION:
/* FIXME: set... */ /*
* XXX: perform the value change here
*/
if ( /* XXX: error? */ ) {
netsnmp_set_request_error(reqinfo, requests, /* some error */
);
}
break; break;
case MODE_SET_COMMIT: case MODE_SET_COMMIT:
/* FIXME: commit */ /*
* XXX: delete temporary storage
*/
if ( /* XXX: error? */ ) {
/*
* try _really_really_ hard to never get to this point
*/
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_COMMITFAILED);
}
break; break;
case MODE_SET_UNDO: case MODE_SET_UNDO:
/* FIXME: undo */ /*
* XXX: UNDO and return to previous value for the object
*/
if ( /* XXX: error? */ ) {
/*
* try _really_really_ hard to never get to this point
*/
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_UNDOFAILED);
}
break; break;
default: default:
/* /*
* we should never get here, so this is a really bad error * we should never get here, so this is a really bad error
*/ */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_wrsPstatsOne\n", snmp_log(LOG_ERR, "unknown mode (%d) in handle_wrsScalarOne\n",
reqinfo->mode); reqinfo->mode);
return SNMP_ERR_GENERR; return SNMP_ERR_GENERR;
} }
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
* Note: this file originally auto-generated by mib2c using * Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 17798 2009-10-27 06:44:54Z magfr $ * : mib2c.scalar.conf 17798 2009-10-27 06:44:54Z magfr $
*/ */
#ifndef WRSPSTATS_H #ifndef WRSSCALAR_H
#define WRSPSTATS_H #define WRSSCALAR_H
/* /*
* function declarations * function declarations
*/ */
void init_wrsPstats(void); void init_wrsScalar(void);
Netsnmp_Node_Handler handle_wrsPstatsOne; Netsnmp_Node_Handler handle_wrsScalarOne;
#endif /* WRSPSTATS_H */ #endif /* WRSSCALAR_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment