Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 580431 Details for
Bug 803585
agentx counter64 snmpget problem
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
subagent for reproducer
subagent.c (text/plain), 9.26 KB, created by
Jan Safranek
on 2012-04-26 10:56:48 UTC
(
hide
)
Description:
subagent for reproducer
Filename:
MIME Type:
Creator:
Jan Safranek
Created:
2012-04-26 10:56:48 UTC
Size:
9.26 KB
patch
obsolete
>/* > * Template MIB group implementation - example.c > * > */ > >/* > * include important headers > */ >#include <net-snmp/net-snmp-config.h> >#if HAVE_STDLIB_H >#include <stdlib.h> >#endif >#if HAVE_STRING_H >#include <string.h> >#else >#include <strings.h> >#endif > >/* > * needed by util_funcs.h > */ >#if TIME_WITH_SYS_TIME ># ifdef WIN32 ># include <sys/timeb.h> ># else ># include <sys/time.h> ># endif ># include <time.h> >#else ># if HAVE_SYS_TIME_H ># include <sys/time.h> ># else ># include <time.h> ># endif >#endif > >#if HAVE_WINSOCK_H >#include <winsock.h> >#endif >#if HAVE_NETINET_IN_H >#include <netinet/in.h> >#endif > >#include <net-snmp/net-snmp-includes.h> >#include <net-snmp/agent/net-snmp-agent-includes.h> > >/* > * include our .h file > */ >#include "subagent.h" > >#include <limits.h> > >#define EXAMPLESTRING 1 >#define EXAMPLEINT1 2 >#define EXAMPLEINT2 3 >#define EXAMPLEINT3 4 >#define EXAMPLEINT4 5 > /* > * Certain objects can be set via configuration file directives. > * These variables hold the values for such objects, as they need to > * be accessible to both the config handlers, and the callback routine. > */ >#define EXAMPLE_STR_LEN 300 >#define EXAMPLE_STR_DEFAULT "life the universe and everything" > > /********************* > * > * Initialisation & common implementation functions > * > *********************/ > > /* > * This array structure defines a representation of the > * MIB being implemented. > * > * The type of the array is 'struct variableN', where N is > * large enough to contain the longest OID sub-component > * being loaded. This will normally be the maximum value > * of the fifth field in each line. In this case, the second > * and third entries are both of size 2, so we're using > * 'struct variable2' > * > * The supported values for N are listed in <agent/var_struct.h> > * If the value you need is not listed there, simply use the > * next largest that is. > * > * The format of each line is as follows > * (using the first entry as an example): > * 1: EXAMPLESTRING: > * The magic number defined in the example header file. > * This is passed to the callback routine and is used > * to determine which object is being queried. > * 2: ASN_OCTET_STR: > * The type of the object. > * Valid types are listed in <snmp_impl.h> > * 3: RONLY (or RWRITE): > * Whether this object can be SET or not. > * 4: var_example: > * The callback routine, used when the object is queried. > * This will usually be the same for all objects in a module > * and is typically defined later in this file. > * 5: 1: > * The length of the OID sub-component (the next field) > * 6: {1}: > * The OID sub-components of this entry. > * In other words, the bits of the full OID that differ > * between the various entries of this array. > * This value is appended to the common prefix (defined later) > * to obtain the full OID of each entry. > */ >struct variable2 example_variables[] = { > {EXAMPLESTRING, ASN_OCTET_STR, RONLY, var_example, 1, {1}}, > {EXAMPLEINT1, ASN_COUNTER64, RONLY, var_example, 1, {2}}, > {EXAMPLEINT2, ASN_COUNTER64, RONLY, var_example, 1, {3}}, > {EXAMPLEINT3, ASN_COUNTER64, RONLY, var_example, 1, {4}}, > {EXAMPLEINT4, ASN_COUNTER64, RONLY, var_example, 1, {5}}, > >}; > > /* > * This array defines the OID of the top of the mib tree that we're > * registering underneath. > * Note that this needs to be the correct size for the OID being > * registered, so that the length of the OID can be calculated. > * The format given here is the simplest way to achieve this. > */ >oid example_variables_oid[] = { 1, 3, 6, 1, 4, 1, 2021, 1, 1 }; > > > > /* > * This function is called at the time the agent starts up > * to do any initializations that might be required. > * > * In theory it is optional and can be omitted if no > * initialization is needed. In practise, every module > * will need to register itself (or the objects being > * implemented will not appear in the MIB tree), and this > * registration is typically done here. > * > * If this function is added or removed, you must re-run > * the configure script, to detect this change. > */ >void >init_subagent(void) >{ > /* > * Register ourselves with the agent to handle our mib tree. > * The arguments are: > * descr: A short description of the mib group being loaded. > * var: The variable structure to load. > * (the name of the variable structure defined above) > * vartype: The type of this variable structure > * theoid: The OID pointer this MIB is being registered underneath. > */ > register_mib_priority("subagent", (struct variable *) example_variables, sizeof(struct variable2), sizeof(example_variables)/sizeof(struct variable2), example_variables_oid, > sizeof(example_variables_oid)/sizeof(oid), 120); >// REGISTER_MIB("example", example_variables, variable2, example_variables_oid); >} > > /********************* > * > * System specific implementation functions > * > *********************/ > > /* > * Define the callback function used in the example_variables structure. > * This is called whenever an incoming request refers to an object > * within this sub-tree. > * > * Four of the parameters are used to pass information in. > * These are: > * vp The entry from the 'example_variables' array for the > * object being queried. > * name The OID from the request. > * length The length of this OID. > * exact A flag to indicate whether this is an 'exact' request > * (GET/SET) or an 'inexact' one (GETNEXT/GETBULK). > * > * Four of the parameters are used to pass information back out. > * These are: > * name The OID being returned. > * length The length of this OID. > * var_len The length of the answer being returned. > * write_method A pointer to the SET function for this object. > * > * Note that name & length serve a dual purpose in both roles. > */ > >u_char * >var_example(struct variable *vp, > oid * name, > size_t * length, > int exact, size_t * var_len, WriteMethod ** write_method) >{ > /* > * The result returned from this function needs to be a pointer to > * static data (so that it can be accessed from outside). > * Define suitable variables for any type of data we may return. > */ > static char string[200]; > static int i; > static long l; > static U64 counter; > > /* > * Before returning an answer, we need to check that the request > * refers to a valid instance of this object. The utility routine > * 'header_generic' can be used to do this for scalar objects. > * > * This routine 'header_simple_table' does the same thing for "simple" > * tables. (See the AGENT.txt file for the definition of a simple table). > * > * Both these utility routines also set up default values for the > * return arguments (assuming the check succeeded). > * The name and length are set suitably for the current object, > * var_len assumes that the result is an integer of some form, > * and write_method assumes that the object cannot be set. > * > * If these assumptions are correct, this callback routine simply > * needs to return a pointer to the appropriate value (using 'long_ret'). > * Otherwise, 'var_len' and/or 'write_method' should be set suitably. > */ > DEBUGMSGTL(("example", "var_example entered\n")); > if (header_generic(vp, name, length, exact, var_len, write_method) == > MATCH_FAILED) > return NULL; > > switch (vp->magic) { > case EXAMPLESTRING: > sprintf(string, "Hello world, i=%d, l=%d", sizeof(i), sizeof(l)); > *var_len = strlen(string); > return (u_char *) string; > > case EXAMPLEINT1: > counter.low=0; > counter.high=1; > *var_len = sizeof(U64); > return (u_char *) & counter; > case EXAMPLEINT2: > counter.low=1; > counter.high=1; > *var_len = sizeof(U64); > return (u_char *) & counter; > case EXAMPLEINT3: > counter.low=2; > counter.high=1; > *var_len = sizeof(U64); > return (u_char *) & counter; > case EXAMPLEINT4: > counter.low=3; > counter.high=1; > *var_len = sizeof(U64); > return (u_char *) & counter; > > default: > /* > * This will only be triggered if there's a problem with > * the coding of the module. SNMP requests that reference > * a non-existant OID will be directed elsewhere. > * If this branch is reached, log an error, so that > * the problem can be investigated. > */ > printf("Intentionally exiting subagent to test AgentX\n"); > exit(0); > > DEBUGMSGTL(("snmpd", "unknown sub-id %d in examples/var_example\n", > vp->magic)); > } > /* > * If we fall through to here, fail by returning NULL. > * This is essentially a continuation of the 'default' case above. > */ > return NULL; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 803585
: 580431