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