Commit 9228a7ff authored by Alessandro Rubini's avatar Alessandro Rubini

snmp library: first trivial code base, not even building

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 481c69d3
SNMP_BUILD := $(wildcard $(WRS_OUTPUT_DIR)/build/buildroot-2*)
SNMP_BUILD := $(wildcard $(SNMP_BUILD)/output/build/netsnmp-*)
NET_SNMP_CONFIG = $(SNMP_BUILD)/net-snmp-config
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
# defer running "net-snmp-config --cflags" so it is visible in make output
CFLAGS = -fPIC $$($(NET_SNMP_CONFIG) --cflags)
LDFLAGS = -shared $$($(NET_SNMP_CONFIG) --ldflags)
SHLIB = wrsSnmp.so
SOURCES = wrsPstats.c
OBJECTS = $(SOURCES:.c=.o)
all: $(SHLIB)
$(SHLIB): $(OBJECTS)
$(CC) $(LDFLAGS) $^ -o $@
clean:
rm -f $(SHLIB) $(OBJECTS)
install:
install -d $(WR_INSTALL_ROOT)/lib
install *.so $(WR_INSTALL_ROOT)/lib
The initial version of wrsPstats.c and wrsPstats.h is generated by running
export BUILD_DIR="$WRS_OUTPUT_DIR/build/buildroot-2011.11/output/build"
export MIBDIRS=$BUILD_DIR/netsnmp-5.6.1.1/mibs
And then this "intuitive" command:
export MIBS=./WR-SWITCH-MIB.txt
$BUILD_DIR/netsnmp-5.6.1.1/local/mib2c \
-I $BUILD_DIR//netsnmp-5.6.1.1/local \
-c mib2c.scalar.conf \
wrsPstats
WR-SWITCH-MIB DEFINITIONS ::= BEGIN
-- This is blatantly copied from NET-SNMP-TUTORIAL-MIB.txt and adapted
-- URL: http://www.net-snmp.org/tutorial/tutorial-5/
-- toolkit/mib_module/NET-SNMP-TUTORIAL-MIB.txt
-- Bugs and swearing by Alessandro Rubini
-- IMPORTS: Include definitions from other mibs here
IMPORTS
OBJECT-TYPE, Integer32,
MODULE-IDENTITY,enterprises FROM SNMPv2-SMI
MODULE-COMPLIANCE, OBJECT-GROUP FROM SNMPv2-CONF;
CERN OBJECT IDENTIFIER ::= { enterprises 96 }
-- A brief description and update information about this mib.
-- (I follow the CamelCase to be sure I don't mysype. Who knows the rules...
wrSwitchMIB MODULE-IDENTITY
LAST-UPDATED "201406181915Z" -- 18 june 2014, 19:15 (why saying again?)
ORGANIZATION "CERN"
CONTACT-INFO "postal: BE-CO-HT, CERN, Geneva
email: ht-drivers@cern.ch
"
DESCRIPTION "White Rabbit Switch internal details
"
::= { CERN 100 }
-- Define typical mib nodes
-- we'll prefix everything in this mib with wrs (White Rabbit Switch)
wrsPstats OBJECT IDENTIFIER ::= { wrSwitchMIB 1 }
wrsPpsi OBJECT IDENTIFIER ::= { wrSwitchMIB 2 }
-- define 1 stupid object for a start
wrsPstatsOne OBJECT-TYPE
SYNTAX Integer32
MAX-ACCESS read-write
STATUS current
DESCRIPTION
"Just an integer"
DEFVAL { 666 }
::= { wrsPstats 1 }
END
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 17798 2009-10-27 06:44:54Z magfr $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "wrsPstats.h"
/** Initializes the wrsPstats module */
void
init_wrsPstats(void)
{
const oid wrsPstatsOne_oid[] =
{ 1, 3, 6, 1, 4, 1, 96, 100, 1, 1 };
DEBUGMSGTL(("wrsPstats", "Initializing\n"));
netsnmp_register_scalar(netsnmp_create_handler_registration
("wrsPstatsOne", handle_wrsPstatsOne,
wrsPstatsOne_oid,
OID_LENGTH(wrsPstatsOne_oid),
HANDLER_CAN_RWRITE));
}
int
handle_wrsPstatsOne(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/*
* We are never called for a GETNEXT if it's registered as a
* "instance", as it's "magically" handled for us.
*/
/*
* a instance handler also only hands us one request at a time, so
* we don't need to loop over a list of requests; we'll only get one.
*/
switch (reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
/*
* XXX: a pointer to the scalar's data
*/ ,
/*
* XXX: the length of the data in bytes
*/ );
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
* http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/*
* or you could use netsnmp_check_vb_type_and_size instead
*/
ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
if (ret != SNMP_ERR_NOERROR) {
netsnmp_set_request_error(reqinfo, requests, ret);
}
break;
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:
/*
* XXX: free resources allocated in RESERVE1 and/or
* RESERVE2. Something failed somewhere, and the states
* below won't be called.
*/
break;
case MODE_SET_ACTION:
/*
* XXX: perform the value change here
*/
if ( /* XXX: error? */ ) {
netsnmp_set_request_error(reqinfo, requests, /* some error */
);
}
break;
case MODE_SET_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;
case MODE_SET_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;
default:
/*
* we should never get here, so this is a really bad error
*/
snmp_log(LOG_ERR, "unknown mode (%d) in handle_wrsPstatsOne\n",
reqinfo->mode);
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 17798 2009-10-27 06:44:54Z magfr $
*/
#ifndef WRSPSTATS_H
#define WRSPSTATS_H
/*
* function declarations
*/
void init_wrsPstats(void);
Netsnmp_Node_Handler handle_wrsPstatsOne;
#endif /* WRSPSTATS_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