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