]> git.pld-linux.org Git - packages/net-snmp.git/blame - net-snmp-loadave-writable.patch
- release 5
[packages/net-snmp.git] / net-snmp-loadave-writable.patch
CommitLineData
18fb53ea
ER
1This patch makes "load X Y Z" snmpsettable via snmpset,
2
3it behaves the same as sysName.0, once written in snmpd.conf, it becames
4readonly.
5
6Signed-off-by: Elan Ruusamäe <glen@delfi.ee>
7Upstream-Tracker: https://sourceforge.net/tracker/?func=detail&aid=2931446&group_id=12694&atid=312694
8
9--- net-snmp/agent/mibgroup/ucd-snmp/loadave.c 2010/07/29 14:58:47 19264
10+++ net-snmp/agent/mibgroup/ucd-snmp/loadave.c 2010/08/11 22:07:58 19294
11@@ -128,7 +128,19 @@
12 #include "util_funcs/header_simple_table.h"
13 #include "kernel.h"
14
15-double maxload[3];
16+static double maxload[3];
17+static int laConfigSet = 0;
18+
19+static int
20+loadave_store_config(int a, int b, void *c, void *d)
21+{
22+ char line[SNMP_MAXBUF_SMALL];
23+ if (laConfigSet > 0) {
24+ snprintf(line, SNMP_MAXBUF_SMALL, "pload %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
25+ snmpd_store_config(line);
26+ }
27+ return SNMPERR_SUCCESS;
28+}
29
30 void
31 init_loadave(void)
32@@ -145,7 +157,7 @@
33 var_extensible_loadave, 1, {ERRORNAME}},
34 {LOADAVE, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
849c236b 35 var_extensible_loadave, 1, {LOADAVE}},
18fb53ea
ER
36- {LOADMAXVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
37+ {LOADMAXVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE,
849c236b 38 var_extensible_loadave, 1, {LOADMAXVAL}},
18fb53ea 39 {LOADAVEINT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
849c236b 40 var_extensible_loadave, 1, {LOADAVEINT}},
18fb53ea
ER
41@@ -172,9 +184,22 @@
42 REGISTER_MIB("ucd-snmp/loadave", extensible_loadave_variables,
43 variable2, loadave_variables_oid);
44
45+ laConfigSet = 0;
46+
47 snmpd_register_config_handler("load", loadave_parse_config,
48 loadave_free_config,
49 "max1 [max5] [max15]");
50+
51+ snmpd_register_config_handler("pload",
52+ loadave_parse_config, NULL, NULL);
53+
54+
55+ /*
56+ * we need to be called back later
57+ */
58+ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
59+ loadave_store_config, NULL);
60+
61 }
62
63 void
64@@ -182,6 +207,25 @@
65 {
66 int i;
67
68+ if (strcmp(token, "pload") == 0) {
69+ if (laConfigSet < 0) {
70+ snmp_log(LOG_WARNING,
71+ "ignoring attempted override of read-only load\n");
72+ return;
73+ } else {
74+ laConfigSet++;
75+ }
76+ } else {
77+ if (laConfigSet > 0) {
78+ snmp_log(LOG_WARNING,
79+ "ignoring attempted override of read-only load\n");
80+ /*
81+ * Fall through and copy in this value.
82+ */
83+ }
84+ laConfigSet = -1;
85+ }
86+
87 for (i = 0; i <= 2; i++) {
88 if (cptr != NULL)
89 maxload[i] = atof(cptr);
90@@ -307,6 +351,71 @@
91 return 0;
92 }
93
94+static int
95+write_laConfig(int action,
96+ u_char * var_val,
97+ u_char var_val_type,
98+ size_t var_val_len,
99+ u_char * statP, oid * name, size_t name_len)
100+{
101+ static double laConfig = 0;
102+
103+ switch (action) {
104+ case RESERVE1: /* Check values for acceptability */
105+ if (var_val_type != ASN_OCTET_STR) {
106+ DEBUGMSGTL(("ucd-snmp/loadave",
107+ "write to laConfig not ASN_OCTET_STR\n"));
108+ return SNMP_ERR_WRONGTYPE;
109+ }
110+ if (var_val_len > 8 || var_val_len <= 0) {
111+ DEBUGMSGTL(("ucd-snmp/loadave",
112+ "write to laConfig: bad length\n"));
113+ return SNMP_ERR_WRONGLENGTH;
114+ }
115+
116+ if (laConfigSet < 0) {
117+ /*
118+ * The object is set in a read-only configuration file.
119+ */
120+ return SNMP_ERR_NOTWRITABLE;
121+ }
122+ break;
123+
124+ case RESERVE2: /* Allocate memory and similar resources */
125+ {
126+ u_char buf[8];
127+ int old_errno = errno;
128+ double val;
129+ char *endp;
130+
131+ strncpy(buf, var_val, var_val_len);
132+ buf[var_val_len] = '\0';
133+ val = strtod(buf, &endp);
134+
135+ if (errno == ERANGE || *endp != '\0' || val < 0 || val > 65536.00) {
136+ errno = old_errno;
137+ DEBUGMSGTL(("ucd-snmp/loadave",
138+ "write to laConfig: invalid value\n"));
139+ return SNMP_ERR_WRONGVALUE;
140+ }
141+
142+ errno = old_errno;
143+
144+ laConfig = val;
145+ }
146+ break;
147+
148+ case COMMIT:
149+ {
150+ int idx = name[name_len - 1] - 1;
151+ maxload[idx] = laConfig;
152+ laConfigSet = 1;
153+ }
154+ }
155+
156+ return SNMP_ERR_NOERROR;
157+}
158+
159 u_char *
160 var_extensible_loadave(struct variable * vp,
161 oid * name,
162@@ -326,6 +435,10 @@
163 case MIBINDEX:
164 long_ret = name[*length - 1];
165 return ((u_char *) (&long_ret));
166+ case LOADMAXVAL:
167+ /* setup write method, but don't return yet */
168+ *write_method = write_laConfig;
169+ break;
170 case ERRORNAME:
171 sprintf(errmsg, "Load-%d", ((name[*length - 1] == 1) ? 1 :
172 ((name[*length - 1] == 2) ? 5 : 15)));
This page took 0.096495 seconds and 4 git commands to generate.