Debian Codegraph @

agent/mibgroup/disman/event/mteTriggerDeltaTable.c

raw
1 /*
2 * DisMan Event MIB:
3 * Implementation of the mteTriggerDeltaTable 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/mteTriggerDeltaTable.h"
15
16 netsnmp_feature_require(table_tdata);
17 #ifndef NETSNMP_NO_WRITE_SUPPORT
18 netsnmp_feature_require(check_vb_oid);
19 netsnmp_feature_require(check_vb_truthvalue);
20 #endif /* NETSNMP_NO_WRITE_SUPPORT */
21
22 /** Initializes the mteTriggerDeltaTable module */
23 void
24 init_mteTriggerDeltaTable(void)
25 {
26 static oid mteTDeltaTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 2, 3 };
27 size_t mteTDeltaTable_oid_len = OID_LENGTH(mteTDeltaTable_oid);
28 netsnmp_handler_registration *reg;
29 netsnmp_table_registration_info *table_info;
30 int rc;
31
32 /*
33 * Ensure the (combined) table container is available...
34 */
35 init_trigger_table_data();
36
37 /*
38 * ... then set up the MIB interface to the mteTriggerDeltaTable slice
39 */
40 #ifndef NETSNMP_NO_WRITE_SUPPORT
41 reg = netsnmp_create_handler_registration("mteTriggerDeltaTable",
42 mteTriggerDeltaTable_handler,
43 mteTDeltaTable_oid,
44 mteTDeltaTable_oid_len,
45 HANDLER_CAN_RWRITE);
46 #else /* !NETSNMP_NO_WRITE_SUPPORT */
47 reg = netsnmp_create_handler_registration("mteTriggerDeltaTable",
48 mteTriggerDeltaTable_handler,
49 mteTDeltaTable_oid,
50 mteTDeltaTable_oid_len,
51 HANDLER_CAN_RONLY);
52 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
53
54 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
55 netsnmp_table_helper_add_indexes(table_info,
56 ASN_OCTET_STR, /* index: mteOwner */
57 /* index: mteTriggerName */
58 ASN_PRIV_IMPLIED_OCTET_STR,
59 0);
60
61 table_info->min_column = COLUMN_MTETRIGGERDELTADISCONTINUITYID;
62 table_info->max_column = COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE;
63
64 /* Register this using the (common) trigger_table_data container */
65 rc = netsnmp_tdata_register(reg, trigger_table_data, table_info);
66 if (rc != SNMPERR_SUCCESS) {
67 snmp_log(LOG_ERR, "%s: netsnmp_tdata_register() returned %d\n",
68 __func__, rc);
69 return;
70 }
71 netsnmp_handler_owns_table_info(reg->handler->next);
72 DEBUGMSGTL(("disman:event:init", "Trigger Delta Table\n"));
73 }
74
75
76 /** handles requests for the mteTriggerDeltaTable table */
77 int
78 mteTriggerDeltaTable_handler(netsnmp_mib_handler *handler,
79 netsnmp_handler_registration *reginfo,
80 netsnmp_agent_request_info *reqinfo,
81 netsnmp_request_info *requests)
82 {
83
84 netsnmp_request_info *request;
85 netsnmp_table_request_info *tinfo;
86 struct mteTrigger *entry;
87 int ret;
88
89 DEBUGMSGTL(("disman:event:mib", "Delta Table handler (%d)\n",
90 reqinfo->mode));
91
92 switch (reqinfo->mode) {
93 /*
94 * Read-support (also covers GetNext requests)
95 */
96 case MODE_GET:
97 for (request = requests; request; request = request->next) {
98 if (request->processed)
99 continue;
100
101 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
102 tinfo = netsnmp_extract_table_info(request);
103
104 /*
105 * The mteTriggerBooleanTable should only contains entries for
106 * rows where the mteTriggerSampleType is 'deltaValue(2)'
107 * So skip entries where this isn't the case.
108 */
109 if (!entry || !(entry->flags & MTE_TRIGGER_FLAG_DELTA )) {
110 netsnmp_request_set_error(request, SNMP_NOSUCHINSTANCE);
111 continue;
112 }
113
114 switch (tinfo->colnum) {
115 case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
116 snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
117 (u_char *) entry->mteDeltaDiscontID,
118 entry->mteDeltaDiscontID_len*sizeof(oid));
119 break;
120 case COLUMN_MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
121 ret = (entry->flags & MTE_TRIGGER_FLAG_DWILD ) ?
122 TV_TRUE : TV_FALSE;
123 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER, ret);
124 break;
125 case COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE:
126 snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
127 entry->mteDeltaDiscontIDType);
128 break;
129 }
130 }
131 break;
132
133 #ifndef NETSNMP_NO_WRITE_SUPPORT
134 /*
135 * Write-support
136 */
137 case MODE_SET_RESERVE1:
138 for (request = requests; request; request = request->next) {
139 if (request->processed)
140 continue;
141
142 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
143 tinfo = netsnmp_extract_table_info(request);
144
145 /*
146 * Since the mteTriggerDeltaTable only contains entries for
147 * rows where mteTriggerSampleType is 'deltaValue(2)',
148 * strictly speaking we should reject assignments where
149 * this isn't the case.
150 * But SET requests that include an assignment of
151 * 'deltaValue(2)' at the same time are valid, so would
152 * need to be accepted. Unfortunately, this assignment
153 * is only applied in the COMMIT pass, so it's difficult
154 * to detect whether this holds or not.
155 *
156 * Let's fudge things for now, by processing
157 * assignments even if this value isn't set.
158 */
159 switch (tinfo->colnum) {
160 case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
161 ret = netsnmp_check_vb_oid(request->requestvb);
162 if (ret != SNMP_ERR_NOERROR) {
163 netsnmp_set_request_error(reqinfo, request, ret);
164 return SNMP_ERR_NOERROR;
165 }
166 break;
167 case COLUMN_MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
168 ret = netsnmp_check_vb_truthvalue(request->requestvb);
169 if (ret != SNMP_ERR_NOERROR) {
170 netsnmp_set_request_error(reqinfo, request, ret);
171 return SNMP_ERR_NOERROR;
172 }
173 break;
174 case COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE:
175 ret = netsnmp_check_vb_int_range(request->requestvb,
176 MTE_DELTAD_TTICKS,
177 MTE_DELTAD_DATETIME);
178 if (ret != SNMP_ERR_NOERROR) {
179 netsnmp_set_request_error(reqinfo, request, ret);
180 return SNMP_ERR_NOERROR;
181 }
182 break;
183 default:
184 netsnmp_set_request_error(reqinfo, request,
185 SNMP_ERR_NOTWRITABLE);
186 return SNMP_ERR_NOERROR;
187 }
188
189 /*
190 * The Event MIB is somewhat ambiguous as to whether the
191 * various trigger table entries can be modified once the
192 * main mteTriggerTable entry has been marked 'active'.
193 * But it's clear from discussion on the DisMan mailing
194 * list is that the intention is not.
195 *
196 * So check for whether this row is already active,
197 * and reject *all* SET requests if it is.
198 */
199 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
200 if (entry &&
201 entry->flags & MTE_TRIGGER_FLAG_ACTIVE ) {
202 netsnmp_set_request_error(reqinfo, request,
203 SNMP_ERR_INCONSISTENTVALUE);
204 return SNMP_ERR_NOERROR;
205 }
206 }
207 break;
208
209 case MODE_SET_RESERVE2:
210 case MODE_SET_FREE:
211 case MODE_SET_UNDO:
212 break;
213
214 case MODE_SET_ACTION:
215 for (request = requests; request; request = request->next) {
216 if (request->processed)
217 continue;
218
219 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
220 if (!entry) {
221 /*
222 * New rows must be created via the RowStatus column
223 * (in the main mteTriggerTable)
224 */
225 netsnmp_set_request_error(reqinfo, request,
226 SNMP_ERR_NOCREATION);
227 /* or inconsistentName? */
228 return SNMP_ERR_NOERROR;
229 }
230 }
231 break;
232
233 case MODE_SET_COMMIT:
234 /*
235 * All these assignments are "unfailable", so it's
236 * (reasonably) safe to apply them in the Commit phase
237 */
238 for (request = requests; request; request = request->next) {
239 if (request->processed)
240 continue;
241
242 entry = (struct mteTrigger *) netsnmp_tdata_extract_entry(request);
243 tinfo = netsnmp_extract_table_info(request);
244
245 switch (tinfo->colnum) {
246 case COLUMN_MTETRIGGERDELTADISCONTINUITYID:
247 if ( snmp_oid_compare(
248 request->requestvb->val.objid,
249 request->requestvb->val_len/sizeof(oid),
250 _sysUpTime_instance, _sysUpTime_inst_len) != 0 ) {
251 memset(entry->mteDeltaDiscontID, 0,
252 sizeof(entry->mteDeltaDiscontID));
253 memcpy(entry->mteDeltaDiscontID,
254 request->requestvb->val.string,
255 request->requestvb->val_len);
256 entry->mteDeltaDiscontID_len =
257 request->requestvb->val_len/sizeof(oid);
258 entry->flags &= ~MTE_TRIGGER_FLAG_SYSUPT;
259 }
260 break;
261 case COLUMN_MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
262 if (*request->requestvb->val.integer == TV_TRUE)
263 entry->flags |= MTE_TRIGGER_FLAG_DWILD;
264 else
265 entry->flags &= ~MTE_TRIGGER_FLAG_DWILD;
266 break;
267 case COLUMN_MTETRIGGERDELTADISCONTINUITYIDTYPE:
268 entry->mteDeltaDiscontIDType = *request->requestvb->val.integer;
269 break;
270 }
271 }
272 break;
273 #endif /* !NETSNMP_NO_WRITE_SUPPORT */
274 }
275 return SNMP_ERR_NOERROR;
276 }