Debian Codegraph @

agent/mibgroup/disman/traceroute/traceRouteResultsTable.c

raw
1 /*
2 *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches.
3 *
4 *All right reserved
5 *
6 *File Name:traceRouteResultsTable.c
7 *File Description:Rows of traceRouteResultsTable MIB read.
8 *
9 *Current Version:1.0
10 *Author:ChenJing
11 *Date:2004.8.20
12 */
13
14 /*
15 * Note: this file originally auto-generated by mib2c using
16 * : mib2c.create-dataset.conf,v 5.3 2002/12/05 00:29:45 hardaker Exp $
17 */
18
19
20 #include <net-snmp/net-snmp-config.h>
21 #include <net-snmp/net-snmp-features.h>
22
23 #ifdef HAVE_STDLIB_H
24 #include <stdlib.h>
25 #endif
26 #ifdef HAVE_STRING_H
27 #include <string.h>
28 #else
29 #include <strings.h>
30 #endif
31 #ifdef HAVE_LIMITS_H
32 #include <limits.h>
33 #endif
34
35 #include <net-snmp/net-snmp-config.h>
36 #include <net-snmp/net-snmp-includes.h>
37 #include <net-snmp/agent/net-snmp-agent-includes.h>
38
39 #include "traceRouteResultsTable.h"
40 #include "traceRouteCtlTable.h"
41 #include "traceRouteProbeHistoryTable.h"
42 #include "traceRouteHopsTable.h"
43 #include "header_complex.h"
44
45 netsnmp_feature_require(table_dataset);
46
47 /*
48 *traceRouteResultsTable_variables_oid:
49 *
50 */
51 oid traceRouteResultsTable_variables_oid[] =
52 { 1, 3, 6, 1, 2, 1, 81, 1, 3 };
53
54 struct variable2 traceRouteResultsTable_variables[] = {
55 {COLUMN_TRACEROUTERESULTSOPERSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
56 var_traceRouteResultsTable, 2, {1, 1}},
57 {COLUMN_TRACEROUTERESULTSCURHOPCOUNT, ASN_GAUGE, NETSNMP_OLDAPI_RONLY,
58 var_traceRouteResultsTable, 2, {1, 2}},
59 {COLUMN_TRACEROUTERESULTSCURPROBECOUNT, ASN_GAUGE, NETSNMP_OLDAPI_RONLY,
60 var_traceRouteResultsTable, 2, {1, 3}},
61 {COLUMN_TRACEROUTERESULTSIPTGTADDRTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
62 var_traceRouteResultsTable, 2, {1, 4}},
63 {COLUMN_TRACEROUTERESULTSIPTGTADDR, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
64 var_traceRouteResultsTable, 2, {1, 5}},
65 {COLUMN_TRACEROUTERESULTSTESTATTEMPTS, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY,
66 var_traceRouteResultsTable, 2, {1, 6}},
67 {COLUMN_TRACEROUTERESULTSTESTSUCCESSES, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY,
68 var_traceRouteResultsTable, 2, {1, 7}},
69 {COLUMN_TRACEROUTERESULTSLASTGOODPATH, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
70 var_traceRouteResultsTable, 2, {1, 8}}
71 };
72
73
74 void
75 traceRouteResultsTable_inadd(struct traceRouteResultsTable_data *thedata);
76
77 void
78 traceRouteResultsTable_cleaner(struct header_complex_index *thestuff)
79 {
80 struct header_complex_index *hciptr, *nhciptr;
81 struct traceRouteResultsTable_data *StorageDel;
82
83 DEBUGMSGTL(("traceRouteResultsTable", "cleanerout "));
84 for (hciptr = thestuff; hciptr; hciptr = nhciptr) {
85 nhciptr = hciptr->next;
86 StorageDel =
87 header_complex_extract_entry(&traceRouteResultsTableStorage,
88 hciptr);
89 if (StorageDel != NULL) {
90 free(StorageDel->traceRouteCtlOwnerIndex);
91 free(StorageDel->traceRouteCtlTestName);
92 free(StorageDel->traceRouteResultsIpTgtAddr);
93 free(StorageDel->traceRouteResultsLastGoodPath);
94 free(StorageDel);
95 }
96 DEBUGMSGTL(("traceRouteResultsTable", "cleaner "));
97 }
98 }
99
100 void
101 init_traceRouteResultsTable(void)
102 {
103
104 DEBUGMSGTL(("traceRouteResultsTable", "initializing... "));
105
106
107 /*
108 * register ourselves with the agent to handle our mib tree
109 */
110 REGISTER_MIB("traceRouteResultsTable",
111 traceRouteResultsTable_variables, variable2,
112 traceRouteResultsTable_variables_oid);
113
114
115 /*
116 * register our config handler(s) to deal with registrations
117 */
118 snmpd_register_config_handler("traceRouteResultsTable",
119 parse_traceRouteResultsTable, NULL,
120 NULL);
121
122 /*
123 * we need to be called back later to store our data
124 */
125 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
126 store_traceRouteResultsTable, NULL);
127
128 DEBUGMSGTL(("traceRouteResultsTable", "done.\n"));
129 }
130
131 /*
132 * parse_mteObjectsTable():
133 * parses .conf file entries needed to configure the mib.
134 */
135
136 void
137 parse_traceRouteResultsTable(const char *token, char *line)
138 {
139 size_t tmpint;
140 struct traceRouteResultsTable_data *StorageTmp =
141 SNMP_MALLOC_STRUCT(traceRouteResultsTable_data);
142
143 DEBUGMSGTL(("traceRouteResultsTable", "parsing config... "));
144
145
146 if (StorageTmp == NULL) {
147 config_perror("malloc failure");
148 return;
149 }
150
151 line =
152 read_config_read_data(ASN_OCTET_STR, line,
153 &StorageTmp->traceRouteCtlOwnerIndex,
154 &StorageTmp->traceRouteCtlOwnerIndexLen);
155 if (StorageTmp->traceRouteCtlOwnerIndex == NULL) {
156 config_perror("invalid specification for traceRouteCtlOwnerIndex");
157 free(StorageTmp);
158 return;
159 }
160
161 line =
162 read_config_read_data(ASN_OCTET_STR, line,
163 &StorageTmp->traceRouteCtlTestName,
164 &StorageTmp->traceRouteCtlTestNameLen);
165 if (StorageTmp->traceRouteCtlTestName == NULL) {
166 config_perror("invalid specification for traceRouteCtlTestName");
167 free(StorageTmp);
168 return;
169 }
170
171 line =
172 read_config_read_data(ASN_INTEGER, line,
173 &StorageTmp->traceRouteResultsOperStatus,
174 &tmpint);
175 line =
176 read_config_read_data(ASN_GAUGE, line,
177 &StorageTmp->traceRouteResultsCurHopCount,
178 &tmpint);
179 line =
180 read_config_read_data(ASN_GAUGE, line,
181 &StorageTmp->traceRouteResultsCurProbeCount,
182 &tmpint);
183 line =
184 read_config_read_data(ASN_INTEGER, line,
185 &StorageTmp->traceRouteResultsIpTgtAddrType,
186 &tmpint);
187 line =
188 read_config_read_data(ASN_OCTET_STR, line,
189 &StorageTmp->traceRouteResultsIpTgtAddr,
190 &StorageTmp->traceRouteResultsIpTgtAddrLen);
191 if (StorageTmp->traceRouteResultsIpTgtAddr == NULL) {
192 config_perror
193 ("invalid specification for traceRouteResultsIpTgtAddr");
194 free(StorageTmp);
195 return;
196 }
197
198 line =
199 read_config_read_data(ASN_UNSIGNED, line,
200 &StorageTmp->traceRouteResultsTestAttempts,
201 &tmpint);
202 line =
203 read_config_read_data(ASN_UNSIGNED, line,
204 &StorageTmp->traceRouteResultsTestSuccesses,
205 &tmpint);
206 line =
207 read_config_read_data(ASN_OCTET_STR, line,
208 &StorageTmp->traceRouteResultsLastGoodPath,
209 &StorageTmp->
210 traceRouteResultsLastGoodPathLen);
211 if (StorageTmp->traceRouteResultsLastGoodPath == NULL) {
212 config_perror
213 ("invalid specification for traceRouteResultsLastGoodPath!");
214 free(StorageTmp);
215 return;
216 }
217
218
219 traceRouteResultsTable_inadd(StorageTmp);
220
221 /* traceRouteResultsTable_cleaner(traceRouteResultsTableStorage); */
222
223 DEBUGMSGTL(("traceRouteResultsTable", "done.\n"));
224 }
225
226
227
228
229
230 /*
231 * store_traceRouteResultsTable():
232 * stores .conf file entries needed to configure the mib.
233 */
234
235 int
236 store_traceRouteResultsTable(int majorID, int minorID, void *serverarg,
237 void *clientarg)
238 {
239 char line[SNMP_MAXBUF];
240 char *cptr = NULL;
241 size_t tmpint;
242 struct traceRouteResultsTable_data *StorageTmp = NULL;
243 struct header_complex_index *hcindex = NULL;
244
245
246 DEBUGMSGTL(("traceRouteResultsTable", "storing data... "));
247
248
249 for (hcindex = traceRouteResultsTableStorage; hcindex != NULL;
250 hcindex = hcindex->next) {
251 StorageTmp = (struct traceRouteResultsTable_data *) hcindex->data;
252
253 if (StorageTmp->storageType != ST_READONLY) {
254 memset(line, 0, sizeof(line));
255 strcat(line, "traceRouteResultsTable ");
256 cptr = line + strlen(line);
257
258 cptr =
259 read_config_store_data(ASN_OCTET_STR, cptr,
260 &StorageTmp->
261 traceRouteCtlOwnerIndex,
262 &StorageTmp->
263 traceRouteCtlOwnerIndexLen);
264 cptr =
265 read_config_store_data(ASN_OCTET_STR, cptr,
266 &StorageTmp->traceRouteCtlTestName,
267 &StorageTmp->
268 traceRouteCtlTestNameLen);
269 cptr =
270 read_config_store_data(ASN_INTEGER, cptr,
271 &StorageTmp->
272 traceRouteResultsOperStatus,
273 &tmpint);
274 cptr =
275 read_config_store_data(ASN_GAUGE, cptr,
276 &StorageTmp->
277 traceRouteResultsCurHopCount,
278 &tmpint);
279 cptr =
280 read_config_store_data(ASN_GAUGE, cptr,
281 &StorageTmp->
282 traceRouteResultsCurProbeCount,
283 &tmpint);
284 cptr =
285 read_config_store_data(ASN_INTEGER, cptr,
286 &StorageTmp->
287 traceRouteResultsIpTgtAddrType,
288 &tmpint);
289 cptr =
290 read_config_store_data(ASN_OCTET_STR, cptr,
291 &StorageTmp->
292 traceRouteResultsIpTgtAddr,
293 &StorageTmp->
294 traceRouteResultsIpTgtAddrLen);
295
296 cptr =
297 read_config_store_data(ASN_UNSIGNED, cptr,
298 &StorageTmp->
299 traceRouteResultsTestAttempts,
300 &tmpint);
301 cptr =
302 read_config_store_data(ASN_UNSIGNED, cptr,
303 &StorageTmp->
304 traceRouteResultsTestSuccesses,
305 &tmpint);
306 cptr =
307 read_config_store_data(ASN_OCTET_STR, cptr,
308 &StorageTmp->
309 traceRouteResultsLastGoodPath,
310 &StorageTmp->
311 traceRouteResultsLastGoodPathLen);
312
313 snmpd_store_config(line);
314 }
315 }
316 DEBUGMSGTL(("traceRouteResultsTable", "done.\n"));
317 return SNMPERR_SUCCESS;
318 }
319
320 void
321 traceRouteResultsTable_inadd(struct traceRouteResultsTable_data *thedata)
322 {
323 netsnmp_variable_list *vars_list = NULL;
324
325 snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) thedata->traceRouteCtlOwnerIndex, thedata->traceRouteCtlOwnerIndexLen); /* traceRouteCtlOwnerIndex */
326 snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) thedata->traceRouteCtlTestName, thedata->traceRouteCtlTestNameLen); /* traceRouteCtlTestName */
327
328 DEBUGMSGTL(("traceRouteResultsTable", "adding data... "));
329 /*
330 * add the index variables to the varbind list, which is
331 * used by header_complex to index the data
332 */
333
334 header_complex_add_data(&traceRouteResultsTableStorage, vars_list,
335 thedata);
336 DEBUGMSGTL(("traceRouteResultsTable", "registered an entry\n"));
337
338
339 DEBUGMSGTL(("traceRouteResultsTable", "done.\n"));
340 }
341
342
343 /*
344 * var_traceRouteResultsTable():
345 * Handle this table separately from the scalar value case.
346 * The workings of this are basically the same as for var_traceRouteResultsTable above.
347 */
348 unsigned char *
349 var_traceRouteResultsTable(struct variable *vp,
350 oid * name,
351 size_t *length,
352 int exact,
353 size_t *var_len, WriteMethod ** write_method)
354 {
355
356
357 struct traceRouteResultsTable_data *StorageTmp = NULL;
358
359 *write_method = NULL;
360
361 /*
362 * this assumes you have registered all your data properly
363 */
364 if ((StorageTmp =
365 header_complex(traceRouteResultsTableStorage, vp, name, length,
366 exact, var_len, write_method)) == NULL) {
367 return NULL;
368 }
369
370 /*
371 * this is where we do the value assignments for the mib results.
372 */
373
374 switch (vp->magic) {
375
376 case COLUMN_TRACEROUTERESULTSOPERSTATUS:
377 *var_len = sizeof(StorageTmp->traceRouteResultsOperStatus);
378 return (u_char *) & StorageTmp->traceRouteResultsOperStatus;
379
380 case COLUMN_TRACEROUTERESULTSCURHOPCOUNT:
381 *var_len = sizeof(StorageTmp->traceRouteResultsCurHopCount);
382 return (u_char *) & StorageTmp->traceRouteResultsCurHopCount;
383
384 case COLUMN_TRACEROUTERESULTSCURPROBECOUNT:
385 *var_len = sizeof(StorageTmp->traceRouteResultsCurProbeCount);
386 return (u_char *) & StorageTmp->traceRouteResultsCurProbeCount;
387
388 case COLUMN_TRACEROUTERESULTSIPTGTADDRTYPE:
389 *var_len = sizeof(StorageTmp->traceRouteResultsIpTgtAddrType);
390 return (u_char *) & StorageTmp->traceRouteResultsIpTgtAddrType;
391
392 case COLUMN_TRACEROUTERESULTSIPTGTADDR:
393 *var_len = (StorageTmp->traceRouteResultsIpTgtAddrLen);
394 return (u_char *) StorageTmp->traceRouteResultsIpTgtAddr;
395
396 case COLUMN_TRACEROUTERESULTSTESTATTEMPTS:
397 *var_len = sizeof(StorageTmp->traceRouteResultsTestAttempts);
398 return (u_char *) & StorageTmp->traceRouteResultsTestAttempts;
399
400 case COLUMN_TRACEROUTERESULTSTESTSUCCESSES:
401 *var_len = sizeof(StorageTmp->traceRouteResultsTestSuccesses);
402 return (u_char *) & StorageTmp->traceRouteResultsTestSuccesses;
403
404 case COLUMN_TRACEROUTERESULTSLASTGOODPATH:
405 *var_len = (StorageTmp->traceRouteResultsLastGoodPathLen);
406 return (u_char *) StorageTmp->traceRouteResultsLastGoodPath;
407
408 default:
409 ERROR_MSG("");
410 }
411
412 return NULL;
413 }