Debian Codegraph @

agent/mibgroup/disman/event/mteTriggerThresholdTable.c

raw
1 /*
2 * DisMan Event MIB:
3 * Implementation of the mteTriggerThresholdTable MIB interface
4 * See 'mteTrigger.c' for active behaviour of this table.
5 *
6 * (based on mib2c.table_data.conf output)
7 */
8
9 #include <net-snmp/net-snmp-config.h>
10 #include <net-snmp/net-snmp-features.h>
11 #include <net-snmp/net-snmp-includes.h>
12 #include <net-snmp/agent/net-snmp-agent-includes.h>
13 #include "disman/event/mteTrigger.h"
14 #include "disman/event/mteTriggerThresholdTable.h"
15
16 netsnmp_feature_require(table_tdata);
17 #ifndef NETSNMP_NO_WRITE_SUPPORT
18 netsnmp_feature_require(check_vb_type_and_max_size);
19 #endif /* NETSNMP_NO_WRITE_SUPPORT */
20
21 static netsnmp_table_registration_info *table_info;
22
23 /** Initializes the mteTriggerThresholdTable module */
24 void
25 init_mteTriggerThresholdTable(void)
26 {
27 static oid mteTThreshTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 6 };
28 size_t mteTThreshTable_oid_len = OID_LENGTH(mteTThreshTable_oid);
29 netsnmp_handler_registration *reg;
30
31 /*
32 * Ensure the (combined) table container is available...
33 */
34 init_trigger_table_data();
35
36 /*
37 * ... then set up the MIB interface to the mteTriggerThresholdTable slice
38 */
39 #ifndef NETSNMP_NO_WRITE_SUPPORT
40 reg = netsnmp_create_handler_registration("mteTriggerThresholdTable",
41 mteTriggerThresholdTable_handler,
42 mteTThreshTable_oid,
43 mteTThreshTable_oid_len,
44 HANDLER_CAN_RWRITE);
45 #else /* !NETSNMP_NO_WRITE_SUPPORT */
46 reg = netsnmp_create_handler_registration("mteTriggerThresholdTable",
47 mteTriggerThresholdTable_handler,
48 mteTThreshTable_oid,
49 mteTThreshTable_oid_len,
50 HANDLER_CAN_RONLY);
51 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
52
53 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
54 netsnmp_table_helper_add_indexes(table_info,
55 ASN_OCTET_STR, /* index: mteOwner */
56 /* index: mteTriggerName */
57 ASN_PRIV_IMPLIED_OCTET_STR,
58 0);
59
60 table_info->min_column = COLUMN_MTETRIGGERTHRESHOLDSTARTUP;
61 table_info->max_column = COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT;
62
63 /* Register this using the (common) trigger_table_data container */
64 netsnmp_tdata_register(reg, trigger_table_data, table_info);
65 DEBUGMSGTL(("disman:event:init", "Trigger Threshold Table\n"));
66 }
67
68 void
69 shutdown_mteTriggerThresholdTable(void)
70 {
71 if (table_info) {
72 netsnmp_table_registration_info_free(table_info);
73 table_info = NULL;
74 }
75 }
76
77
78 /** handles requests for the mteTriggerThresholdTable table */
79 int
80 mteTriggerThresholdTable_handler(netsnmp_mib_handler *handler,
81 netsnmp_handler_registration *reginfo,
82 netsnmp_agent_request_info *reqinfo,
83 netsnmp_request_info *requests)
84 {
85
86 netsnmp_request_info *request;
87 netsnmp_table_request_info *tinfo;
88 struct mteTrigger *entry;
89 int ret;
90
91 DEBUGMSGTL(("disman:event:mib", "Threshold Table handler (%d)\n",
92 reqinfo->mode));
93
94 switch (reqinfo->mode) {
95 /*
96 * Read-support (also covers GetNext requests)
97 */
98 case MODE_GET:
99 for (request = requests; request; request = request->next) {
100 if (request->processed)
101 continue;
102
103 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
104 tinfo = netsnmp_extract_table_info(request);
105
106 /*
107 * The mteTriggerThresholdTable should only contains entries for
108 * rows where the mteTriggerTest 'threshold(2)' bit is set.
109 * So skip entries where this isn't the case.
110 */
111 if (!entry || !(entry->mteTriggerTest & MTE_TRIGGER_THRESHOLD )) {
112 netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
113 continue;
114 }
115
116 switch (tinfo->colnum) {
117 case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
118 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
119 entry->mteTThStartup);
120 break;
121 case COLUMN_MTETRIGGERTHRESHOLDRISING:
122 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
123 entry->mteTThRiseValue);
124 break;
125 case COLUMN_MTETRIGGERTHRESHOLDFALLING:
126 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
127 entry->mteTThFallValue);
128 break;
129 case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
130 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
131 entry->mteTThDRiseValue);
132 break;
133 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
134 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
135 entry->mteTThDFallValue);
136 break;
137 case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
138 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
139 (u_char *) entry->mteTThObjOwner,
140 strlen(entry->mteTThObjOwner));
141 break;
142 case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
143 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
144 (u_char *) entry->mteTThObjects,
145 strlen(entry->mteTThObjects));
146 break;
147 case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
148 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
149 (u_char *) entry->mteTThRiseOwner,
150 strlen(entry->mteTThRiseOwner));
151 break;
152 case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
153 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
154 (u_char *) entry->mteTThRiseEvent,
155 strlen(entry->mteTThRiseEvent));
156 break;
157 case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
158 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
159 (u_char *) entry->mteTThFallOwner,
160 strlen(entry->mteTThFallOwner));
161 break;
162 case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
163 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
164 (u_char *) entry->mteTThFallEvent,
165 strlen(entry->mteTThFallEvent));
166 break;
167 case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
168 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
169 (u_char *) entry->mteTThDRiseOwner,
170 strlen(entry->mteTThDRiseOwner));
171 break;
172 case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
173 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
174 (u_char *) entry->mteTThDRiseEvent,
175 strlen(entry->mteTThDRiseEvent));
176 break;
177 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
178 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
179 (u_char *) entry->mteTThDFallOwner,
180 strlen(entry->mteTThDFallOwner));
181 break;
182 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
183 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
184 (u_char *) entry->mteTThDFallEvent,
185 strlen(entry->mteTThDFallEvent));
186 break;
187 }
188 }
189 break;
190
191 #ifndef NETSNMP_NO_WRITE_SUPPORT
192 /*
193 * Write-support
194 */
195 case MODE_SET_RESERVE1:
196 for (request = requests; request; request = request->next) {
197 if (request->processed)
198 continue;
199
200 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
201 tinfo = netsnmp_extract_table_info(request);
202
203 /*
204 * Since the mteTriggerThresholdTable only contains entries for
205 * rows where the mteTriggerTest 'threshold(2)' bit is set,
206 * strictly speaking we should reject assignments where
207 * this isn't the case.
208 * But SET requests that include an assignment of the
209 * 'threshold(2)' bit at the same time are valid, so would
210 * need to be accepted. Unfortunately, this assignment
211 * is only applied in the COMMIT pass, so it's difficult
212 * to detect whether this holds or not.
213 *
214 * Let's fudge things for now, by processing assignments
215 * even if the 'threshold(2)' bit isn't set.
216 */
217 switch (tinfo->colnum) {
218 case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
219 ret = netsnmp_check_vb_int_range(request->requestvb,
220 MTE_THRESH_START_RISE,
221 MTE_THRESH_START_RISEFALL );
222 if (ret != SNMP_ERR_NOERROR) {
223 netsnmp_set_request_error(reqinfo, request, ret);
224 return SNMP_ERR_NOERROR;
225 }
226 break;
227 case COLUMN_MTETRIGGERTHRESHOLDRISING:
228 case COLUMN_MTETRIGGERTHRESHOLDFALLING:
229 case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
230 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
231 ret = netsnmp_check_vb_int(request->requestvb);
232 if (ret != SNMP_ERR_NOERROR) {
233 netsnmp_set_request_error(reqinfo, request, ret);
234 return SNMP_ERR_NOERROR;
235 }
236 break;
237 case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
238 case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
239 case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
240 case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
241 case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
242 case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
243 case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
244 case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
245 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
246 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
247 ret = netsnmp_check_vb_type_and_max_size(
248 request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN);
249 if (ret != SNMP_ERR_NOERROR) {
250 netsnmp_set_request_error(reqinfo, request, ret);
251 return SNMP_ERR_NOERROR;
252 }
253 break;
254 default:
255 netsnmp_set_request_error(reqinfo, request,
256 SNMP_ERR_NOTWRITABLE);
257 return SNMP_ERR_NOERROR;
258 }
259
260 /*
261 * The Event MIB is somewhat ambiguous as to whether the
262 * various trigger table entries can be modified once the
263 * main mteTriggerTable entry has been marked 'active'.
264 * But it's clear from discussion on the DisMan mailing
265 * list is that the intention is not.
266 *
267 * So check for whether this row is already active,
268 * and reject *all* SET requests if it is.
269 */
270 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
271 if (entry &&
272 entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) {
273 netsnmp_set_request_error(reqinfo, request,
274 SNMP_ERR_INCONSISTENTVALUE);
275 return SNMP_ERR_NOERROR;
276 }
277 }
278 break;
279
280 case MODE_SET_RESERVE2:
281 case MODE_SET_FREE:
282 case MODE_SET_UNDO:
283 break;
284
285 case MODE_SET_ACTION:
286 for (request = requests; request; request = request->next) {
287 if (request->processed)
288 continue;
289
290 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
291 if (!entry) {
292 /*
293 * New rows must be created via the RowStatus column
294 * (in the main mteTriggerTable)
295 */
296 netsnmp_set_request_error(reqinfo, request,
297 SNMP_ERR_NOCREATION);
298 /* or inconsistentName? */
299 return SNMP_ERR_NOERROR;
300 }
301 }
302 break;
303
304 case MODE_SET_COMMIT:
305 /*
306 * All these assignments are "unfailable", so it's
307 * (reasonably) safe to apply them in the Commit phase
308 */
309 for (request = requests; request; request = request->next) {
310 if (request->processed)
311 continue;
312
313 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
314 tinfo = netsnmp_extract_table_info(request);
315
316 switch (tinfo->colnum) {
317 case COLUMN_MTETRIGGERTHRESHOLDSTARTUP:
318 entry->mteTThStartup = *request->requestvb->val.integer;
319 break;
320 case COLUMN_MTETRIGGERTHRESHOLDRISING:
321 entry->mteTThRiseValue = *request->requestvb->val.integer;
322 break;
323 case COLUMN_MTETRIGGERTHRESHOLDFALLING:
324 entry->mteTThFallValue = *request->requestvb->val.integer;
325 break;
326 case COLUMN_MTETRIGGERTHRESHOLDDELTARISING:
327 entry->mteTThDRiseValue = *request->requestvb->val.integer;
328 break;
329 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLING:
330 entry->mteTThDFallValue = *request->requestvb->val.integer;
331 break;
332 case COLUMN_MTETRIGGERTHRESHOLDOBJECTSOWNER:
333 memset(entry->mteTThObjOwner, 0, sizeof(entry->mteTThObjOwner));
334 memcpy(entry->mteTThObjOwner, request->requestvb->val.string,
335 request->requestvb->val_len);
336 break;
337 case COLUMN_MTETRIGGERTHRESHOLDOBJECTS:
338 memset(entry->mteTThObjects, 0, sizeof(entry->mteTThObjects));
339 memcpy(entry->mteTThObjects, request->requestvb->val.string,
340 request->requestvb->val_len);
341 break;
342 case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
343 memset(entry->mteTThRiseOwner, 0, sizeof(entry->mteTThRiseOwner));
344 memcpy(entry->mteTThRiseOwner, request->requestvb->val.string,
345 request->requestvb->val_len);
346 break;
347 case COLUMN_MTETRIGGERTHRESHOLDRISINGEVENT:
348 memset(entry->mteTThRiseEvent, 0, sizeof(entry->mteTThRiseEvent));
349 memcpy(entry->mteTThRiseEvent, request->requestvb->val.string,
350 request->requestvb->val_len);
351 break;
352 case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
353 memset(entry->mteTThFallOwner, 0, sizeof(entry->mteTThFallOwner));
354 memcpy(entry->mteTThFallOwner, request->requestvb->val.string,
355 request->requestvb->val_len);
356 break;
357 case COLUMN_MTETRIGGERTHRESHOLDFALLINGEVENT:
358 memset(entry->mteTThFallEvent, 0, sizeof(entry->mteTThFallEvent));
359 memcpy(entry->mteTThFallEvent, request->requestvb->val.string,
360 request->requestvb->val_len);
361 break;
362 case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
363 memset(entry->mteTThDRiseOwner, 0, sizeof(entry->mteTThDRiseOwner));
364 memcpy(entry->mteTThDRiseOwner, request->requestvb->val.string,
365 request->requestvb->val_len);
366 break;
367 case COLUMN_MTETRIGGERTHRESHOLDDELTARISINGEVENT:
368 memset(entry->mteTThDRiseEvent, 0, sizeof(entry->mteTThDRiseEvent));
369 memcpy(entry->mteTThDRiseEvent, request->requestvb->val.string,
370 request->requestvb->val_len);
371 break;
372 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
373 memset(entry->mteTThDFallOwner, 0, sizeof(entry->mteTThDFallOwner));
374 memcpy(entry->mteTThDFallOwner, request->requestvb->val.string,
375 request->requestvb->val_len);
376 break;
377 case COLUMN_MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
378 memset(entry->mteTThDFallEvent, 0, sizeof(entry->mteTThDFallEvent));
379 memcpy(entry->mteTThDFallEvent, request->requestvb->val.string,
380 request->requestvb->val_len);
381 break;
382 }
383 }
384 break;
385 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
386
387 }
388 return SNMP_ERR_NOERROR;
389 }