traceRouteResultsTable.c
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:14k
源码类别:

SNMP编程

开发平台:

Unix_Linux

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