1 #ifdef BUILD_SNMP_SNMP_MIB
4 * SNMPv1 MIB group implementation - snmp.c
8 #include <net-snmp/net-snmp-config.h>
16 #include <netinet/in.h>
23 #include <net-snmp/net-snmp-includes.h>
24 #include <net-snmp/agent/net-snmp-agent-includes.h>
26 #include "util_funcs.h"
29 #ifdef BUILD_SNMP_SYSOR_MIB
30 #include "sysORTable.h"
31 #endif /* BUILD_SNMP_SYSOR_MIB */
33 /*********************
35 * Kernel & interface information,
36 * and internal forward declarations
38 *********************/
40 extern int snmp_enableauthentraps;
41 extern int snmp_enableauthentrapsset;
42 int old_snmp_enableauthentraps;
44 /*********************
46 * Initialisation & common implementation functions
48 *********************/
51 * define the structure we're going to ask the agent to register our
54 struct variable1 snmp_variables[] = {
55 {SNMPINPKTS, ASN_COUNTER, RONLY, var_snmp, 1, {1}},
56 {SNMPOUTPKTS, ASN_COUNTER, RONLY, var_snmp, 1, {2}},
57 {SNMPINBADVERSIONS, ASN_COUNTER, RONLY, var_snmp, 1, {3}},
58 {SNMPINBADCOMMUNITYNAMES, ASN_COUNTER, RONLY, var_snmp, 1, {4}},
59 {SNMPINBADCOMMUNITYUSES, ASN_COUNTER, RONLY, var_snmp, 1, {5}},
60 {SNMPINASNPARSEERRORS, ASN_COUNTER, RONLY, var_snmp, 1, {6}},
61 {SNMPINTOOBIGS, ASN_COUNTER, RONLY, var_snmp, 1, {8}},
62 {SNMPINNOSUCHNAMES, ASN_COUNTER, RONLY, var_snmp, 1, {9}},
63 {SNMPINBADVALUES, ASN_COUNTER, RONLY, var_snmp, 1, {10}},
64 {SNMPINREADONLYS, ASN_COUNTER, RONLY, var_snmp, 1, {11}},
65 {SNMPINGENERRS, ASN_COUNTER, RONLY, var_snmp, 1, {12}},
66 {SNMPINTOTALREQVARS, ASN_COUNTER, RONLY, var_snmp, 1, {13}},
67 {SNMPINTOTALSETVARS, ASN_COUNTER, RONLY, var_snmp, 1, {14}},
68 {SNMPINGETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {15}},
69 {SNMPINGETNEXTS, ASN_COUNTER, RONLY, var_snmp, 1, {16}},
70 {SNMPINSETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {17}},
71 {SNMPINGETRESPONSES, ASN_COUNTER, RONLY, var_snmp, 1, {18}},
72 {SNMPINTRAPS, ASN_COUNTER, RONLY, var_snmp, 1, {19}},
73 {SNMPOUTTOOBIGS, ASN_COUNTER, RONLY, var_snmp, 1, {20}},
74 {SNMPOUTNOSUCHNAMES, ASN_COUNTER, RONLY, var_snmp, 1, {21}},
75 {SNMPOUTBADVALUES, ASN_COUNTER, RONLY, var_snmp, 1, {22}},
76 {SNMPOUTGENERRS, ASN_COUNTER, RONLY, var_snmp, 1, {24}},
77 {SNMPOUTGETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {25}},
78 {SNMPOUTGETNEXTS, ASN_COUNTER, RONLY, var_snmp, 1, {26}},
79 {SNMPOUTSETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {27}},
80 {SNMPOUTGETRESPONSES, ASN_COUNTER, RONLY, var_snmp, 1, {28}},
81 {SNMPOUTTRAPS, ASN_COUNTER, RONLY, var_snmp, 1, {29}},
82 {SNMPENABLEAUTHENTRAPS, ASN_INTEGER, RWRITE, var_snmp, 1, {30}},
83 {SNMPSILENTDROPS, ASN_COUNTER, RONLY, var_snmp, 1, {31}},
84 {SNMPPROXYDROPS, ASN_COUNTER, RONLY, var_snmp, 1, {32}}
88 * Define the OID pointer to the top of the mib tree that we're
89 * registering underneath
91 oid snmp_variables_oid[] = { SNMP_OID_MIB2, 11 };
92 #ifdef USING_MIBII_SYSTEM_MIB_MODULE
93 extern oid system_module_oid[];
94 extern int system_module_oid_len;
95 extern int system_module_count;
99 snmp_enableauthentraps_store(int a, int b, void *c, void *d)
101 char line[SNMP_MAXBUF_SMALL];
103 if (snmp_enableauthentrapsset > 0) {
104 snprintf(line, SNMP_MAXBUF_SMALL, "pauthtrapenable %d",
105 snmp_enableauthentraps);
106 snmpd_store_config(line);
115 * register ourselves with the agent to handle our mib tree
117 REGISTER_MIB("mibII/snmp", snmp_variables, variable1,
120 #ifdef BUILD_SNMP_SYSOR_MIB
121 #ifdef USING_MIBII_SYSTEM_MIB_MODULE
122 if (++system_module_count == 3)
123 REGISTER_SYSOR_TABLE(system_module_oid, system_module_oid_len,
124 "The MIB module for SNMPv2 entities");
126 #endif /* BUILD_SNMP_SYSOR_MIB */
127 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
128 snmp_enableauthentraps_store, NULL);
134 * vp IN - pointer to variable entry that points here
135 * name IN/OUT - IN/name requested, OUT/name found
136 * length IN/OUT - length of IN/OUT oid's
137 * exact IN - TRUE if an exact match was requested
138 * var_len OUT - length of variable or 0 if function returned
143 /*********************
145 * System specific implementation functions
148 *********************/
152 var_snmp(struct variable *vp,
155 int exact, size_t * var_len, WriteMethod ** write_method)
157 static long long_ret;
159 *write_method = 0; /* assume it isnt writable for the time being */
160 *var_len = sizeof(long_ret); /* assume an integer and change later if not */
162 if (header_generic(vp, name, length, exact, var_len, write_method)
167 * this is where we do the value assignments for the mib results.
169 if (vp->magic == SNMPENABLEAUTHENTRAPS) {
170 *write_method = write_snmp;
171 long_return = snmp_enableauthentraps;
172 return (u_char *) & long_return;
173 } else if ((vp->magic >= 1)
175 (STAT_SNMP_STATS_END - STAT_SNMP_STATS_START + 1))) {
177 snmp_get_statistic(vp->magic + STAT_SNMP_STATS_START - 1);
178 return (unsigned char *) &long_ret;
184 * only for snmpEnableAuthenTraps:
188 write_snmp(int action,
191 size_t var_val_len, u_char * statP, oid * name, size_t name_len)
196 case RESERVE1: /* Check values for acceptability */
197 if (var_val_type != ASN_INTEGER) {
198 DEBUGMSGTL(("mibII/snmp_mib", "%x not integer type",
200 return SNMP_ERR_WRONGTYPE;
203 intval = *((long *) var_val);
204 if (intval != 1 && intval != 2) {
205 DEBUGMSGTL(("mibII/snmp_mib", "not valid %x\n", intval));
206 return SNMP_ERR_WRONGVALUE;
208 if (snmp_enableauthentrapsset < 0) {
210 * The object is set in a read-only configuration file.
212 return SNMP_ERR_NOTWRITABLE;
216 case RESERVE2: /* Allocate memory and similar resources */
219 * Using static variables, so nothing needs to be done
223 case ACTION: /* Perform the SET action (if reversible) */
226 * Save the old value, in case of UNDO
228 intval = *((long *) var_val);
229 old_snmp_enableauthentraps = snmp_enableauthentraps;
230 snmp_enableauthentraps = intval;
233 case UNDO: /* Reverse the SET action and free resources */
235 snmp_enableauthentraps = old_snmp_enableauthentraps;
239 snmp_enableauthentrapsset = 1;
240 snmp_save_persistent(netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE));
241 (void) snmp_call_callbacks(SNMP_CALLBACK_LIBRARY,
242 SNMP_CALLBACK_STORE_DATA, NULL);
243 snmp_clean_persistent(netsnmp_ds_get_string
244 (NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE));
247 case FREE: /* Free any resources allocated */
250 return SNMP_ERR_NOERROR;
253 /*********************
255 * Internal implementation functions
257 *********************/
264 #endif /* BUILD_SNMP_SNMP_MIB */