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

SNMP编程

开发平台:

Unix_Linux

  1. /*
  2.  *  Interface MIB architecture support
  3.  *
  4.  * $Id: route_common.c,v 1.3 2004/08/28 06:16:35 rstory Exp $
  5.  */
  6. #include <net-snmp/net-snmp-config.h>
  7. #include <net-snmp/net-snmp-includes.h>
  8. #include "mibII/mibII_common.h"
  9. #include <net-snmp/agent/net-snmp-agent-includes.h>
  10. #include <net-snmp/data_access/route.h>
  11. /**---------------------------------------------------------------------*/
  12. /*
  13.  * local static prototypes
  14.  */
  15. static void _access_route_entry_release(netsnmp_route_entry * entry, void *unused);
  16. /**---------------------------------------------------------------------*/
  17. /*
  18.  * external per-architecture functions prototypes
  19.  *
  20.  * These shouldn't be called by the general public, so they aren't in
  21.  * the header file.
  22.  */
  23. extern int netsnmp_access_route_container_arch_load(netsnmp_container* container,
  24.                                                     u_int load_flags);
  25. /**---------------------------------------------------------------------*/
  26. /*
  27.  * container functions
  28.  */
  29. /**
  30.  * @retval NULL  error
  31.  * @retval !NULL pointer to container
  32.  */
  33. netsnmp_container*
  34. netsnmp_access_route_container_load(netsnmp_container* container, u_int load_flags)
  35. {
  36.     int rc;
  37.     DEBUGMSGTL(("access:route:container", "loadn"));
  38.     if (NULL == container)
  39.         container = netsnmp_container_find("access:_route:table_container");
  40.     if (NULL == container) {
  41.         snmp_log(LOG_ERR, "no container specified/found for access_routen");
  42.         return NULL;
  43.     }
  44.     rc =  netsnmp_access_route_container_arch_load(container, load_flags);
  45.     if (0 != rc) {
  46.         netsnmp_access_route_container_free(container, NETSNMP_ACCESS_ROUTE_FREE_NOFLAGS);
  47.         container = NULL;
  48.     }
  49.     return container;
  50. }
  51. void
  52. netsnmp_access_route_container_free(netsnmp_container *container, u_int free_flags)
  53. {
  54.     DEBUGMSGTL(("access:route:container", "freen"));
  55.     if (NULL == container) {
  56.         snmp_log(LOG_ERR, "invalid container for netsnmp_access_route_freen");
  57.         return;
  58.     }
  59.     if(! (free_flags & NETSNMP_ACCESS_ROUTE_FREE_DONT_CLEAR)) {
  60.         /*
  61.          * free all items.
  62.          */
  63.         CONTAINER_CLEAR(container,
  64.                         (netsnmp_container_obj_func*)_access_route_entry_release,
  65.                         NULL);
  66.     }
  67.     if(! (free_flags & NETSNMP_ACCESS_ROUTE_FREE_KEEP_CONTAINER))
  68.         CONTAINER_FREE(container);
  69. }
  70. /**---------------------------------------------------------------------*/
  71. /*
  72.  * ifentry functions
  73.  */
  74. /** create route entry
  75.  *
  76.  * @note:
  77.  *  if you create a route for entry into a container of your own, you
  78.  *  must set ns_rt_index to a unique index for your container.
  79.  */
  80. netsnmp_route_entry *
  81. netsnmp_access_route_entry_create(void)
  82. {
  83.     netsnmp_route_entry *entry = SNMP_MALLOC_TYPEDEF(netsnmp_route_entry);
  84.     if(NULL == entry) {
  85.         snmp_log(LOG_ERR, "could not allocate route entryn");
  86.         return NULL;
  87.     }
  88.     entry->oid_index.oids = &entry->ns_rt_index;
  89.     entry->oid_index.len = 1;
  90.     entry->rt_metric1 = -1;
  91.     entry->rt_metric2 = -1;
  92.     entry->rt_metric3 = -1;
  93.     entry->rt_metric4 = -1;
  94.     entry->rt_metric5 = -1;
  95.     /** entry->row_status? */
  96.     return entry;
  97. }
  98. /**
  99.  */
  100. void
  101. netsnmp_access_route_entry_free(netsnmp_route_entry * entry)
  102. {
  103.     if (NULL == entry)
  104.         return;
  105. #ifdef USING_IP_FORWARD_MIB_INETCIDRROUTETABLE_INETCIDRROUTETABLE_MODULE
  106.     if ((NULL != entry->rt_policy) && !(entry->flags & NETSNMP_ROUTE_ENTRY_POLICY_STATIC))
  107.         free(entry->rt_policy);
  108. #endif
  109. #ifdef USING_IP_FORWARD_MIB_IPCIDRROUTETABLE_IPCIDRROUTETABLE_MODULE
  110.     if (NULL != entry->rt_info)
  111.         free(entry->rt_info);
  112. #endif
  113.     free(entry);
  114. }
  115. /**---------------------------------------------------------------------*/
  116. /*
  117.  * Utility routines
  118.  */
  119. /**
  120.  */
  121. void
  122. _access_route_entry_release(netsnmp_route_entry * entry, void *context)
  123. {
  124.     netsnmp_access_route_entry_free(entry);
  125. }