Debian Codegraph @

agent/mibgroup/mibII/setSerialNo.c

raw
1 /**
2 * This file implements the snmpSetSerialNo TestAndIncr counter
3 */
4 #include <net-snmp/net-snmp-config.h>
5 #include <net-snmp/net-snmp-features.h>
6 #include <net-snmp/net-snmp-includes.h>
7 #include <net-snmp/agent/net-snmp-agent-includes.h>
8
9 netsnmp_feature_require(watcher_spinlock);
10
11
12 #include "setSerialNo.h"
13
14 /*
15 * A watched spinlock can be fully implemented by the spinlock helper,
16 * but we still need a suitable variable to hold the value.
17 */
18 static int setserialno;
19
20 /*
21 * TestAndIncr values should persist across agent restarts,
22 * so we need config handling routines to load and save the
23 * current value (incrementing this whenever it's loaded).
24 */
25 static void
26 setserial_parse_config( const char *token, char *cptr )
27 {
28 setserialno = atoi(cptr);
29 setserialno++;
30 DEBUGMSGTL(("snmpSetSerialNo",
31 "Re-setting SnmpSetSerialNo to %d\n", setserialno));
32 }
33 static int
34 setserial_store_config( int a, int b, void *c, void *d )
35 {
36 char line[SNMP_MAXBUF_SMALL];
37 snprintf(line, SNMP_MAXBUF_SMALL, "setserialno %d", setserialno);
38 snmpd_store_config( line );
39 return 0;
40 }
41
42 void
43 init_setSerialNo(void)
44 {
45 static const oid set_serial_oid[] = { 1, 3, 6, 1, 6, 3, 1, 1, 6, 1 };
46 int mode;
47
48 /*
49 * If we can't retain the TestAndIncr value across an agent restart,
50 * then it should be initialised to a pseudo-random value. So set it
51 * as such, before registering the config handlers to override this.
52 */
53 setserialno = netsnmp_random();
54 DEBUGMSGTL(("snmpSetSerialNo",
55 "Initalizing SnmpSetSerialNo to %d\n", setserialno));
56 snmpd_register_config_handler("setserialno", setserial_parse_config,
57 NULL, "integer");
58 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
59 setserial_store_config, NULL);
60
61 /*
62 * Register 'setserialno' as a watched spinlock object
63 */
64 #ifndef NETSNMP_NO_WRITE_SUPPORT
65 mode = HANDLER_CAN_RWRITE;
66 #else /* !NETSNMP_NO_WRITE_SUPPORT */
67 mode = HANDLER_CAN_RONLY;
68 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
69 netsnmp_register_watched_spinlock(
70 netsnmp_create_handler_registration("snmpSetSerialNo", NULL,
71 set_serial_oid, OID_LENGTH(set_serial_oid),
72 mode), &setserialno);
73 DEBUGMSGTL(("scalar_int", "Done initalizing example scalar int\n"));
74 }
75