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

SNMP编程

开发平台:

Unix_Linux

  1. /*
  2.  * Note: this file originally auto-generated by mib2c using
  3.  *       version : 1.43 $ of : mfd-interface.m2c,v $ 
  4.  *
  5.  * $Id: ipAddressTable_interface.c,v 1.10.2.1 2005/03/29 21:05:25 nba Exp $
  6.  */
  7. /*
  8.  * *********************************************************************
  9.  * *********************************************************************
  10.  * *********************************************************************
  11.  * ***                                                               ***
  12.  * ***  NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE  ***
  13.  * ***                                                               ***
  14.  * ***                                                               ***
  15.  * ***       THIS FILE DOES NOT CONTAIN ANY USER EDITABLE CODE.      ***
  16.  * ***                                                               ***
  17.  * ***                                                               ***
  18.  * ***       THE GENERATED CODE IS INTERNAL IMPLEMENTATION, AND      ***
  19.  * ***                                                               ***
  20.  * ***                                                               ***
  21.  * ***    IS SUBJECT TO CHANGE WITHOUT WARNING IN FUTURE RELEASES.   ***
  22.  * ***                                                               ***
  23.  * ***                                                               ***
  24.  * *********************************************************************
  25.  * *********************************************************************
  26.  * *********************************************************************
  27.  */
  28. /*
  29.  * standard Net-SNMP includes 
  30.  */
  31. #include <net-snmp/net-snmp-config.h>
  32. #include <net-snmp/net-snmp-includes.h>
  33. #include <net-snmp/agent/net-snmp-agent-includes.h>
  34. /*
  35.  * include our parent header 
  36.  */
  37. #include "ipAddressTable.h"
  38. #include <net-snmp/library/container.h>
  39. #include "ipAddressTable_interface.h"
  40. /**********************************************************************
  41.  **********************************************************************
  42.  ***
  43.  *** Table ipAddressTable
  44.  ***
  45.  **********************************************************************
  46.  **********************************************************************/
  47. /*
  48.  * ipAddressTable is subid 34 of ip.
  49.  * Its status is Current.
  50.  * OID: .1.3.6.1.2.1.4.34, length: 8
  51.  */
  52. typedef struct ipAddressTable_interface_ctx_s {
  53.     netsnmp_container *container;
  54.     netsnmp_cache  *cache;      /* optional cache */
  55.     ipAddressTable_registration_ptr user_ctx;
  56.     netsnmp_table_registration_info tbl_info;
  57.     netsnmp_baby_steps_access_methods access_multiplexer;
  58. } ipAddressTable_interface_ctx;
  59. static ipAddressTable_interface_ctx ipAddressTable_if_ctx;
  60. static void     _ipAddressTable_container_init(ipAddressTable_interface_ctx
  61.                                                * if_ctx);
  62. static Netsnmp_Node_Handler _mfd_ipAddressTable_pre_request;
  63. static Netsnmp_Node_Handler _mfd_ipAddressTable_post_request;
  64. static Netsnmp_Node_Handler _mfd_ipAddressTable_object_lookup;
  65. static Netsnmp_Node_Handler _mfd_ipAddressTable_get_values;
  66. static Netsnmp_Node_Handler _mfd_ipAddressTable_check_objects;
  67. static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_setup;
  68. static Netsnmp_Node_Handler _mfd_ipAddressTable_set_values;
  69. static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_cleanup;
  70. static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_values;
  71. static Netsnmp_Node_Handler _mfd_ipAddressTable_commit;
  72. static Netsnmp_Node_Handler _mfd_ipAddressTable_undo_commit;
  73. static Netsnmp_Node_Handler _mfd_ipAddressTable_check_dependencies;
  74. NETSNMP_STATIC_INLINE int
  75.                 _ipAddressTable_undo_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
  76.                                             netsnmp_variable_list * var,
  77.                                             int column);
  78. NETSNMP_STATIC_INLINE int
  79.                 _ipAddressTable_check_indexes(ipAddressTable_rowreq_ctx * rowreq_ctx);
  80. /**
  81.  * @internal
  82.  * Initialize the table ipAddressTable 
  83.  *    (Define its contents and how it's structured)
  84.  */
  85. void
  86. _ipAddressTable_initialize_interface(ipAddressTable_registration_ptr
  87.                                      reg_ptr, u_long flags)
  88. {
  89.     netsnmp_baby_steps_access_methods *access_multiplexer =
  90.         &ipAddressTable_if_ctx.access_multiplexer;
  91.     netsnmp_table_registration_info *tbl_info =
  92.         &ipAddressTable_if_ctx.tbl_info;
  93.     netsnmp_handler_registration *reginfo;
  94.     netsnmp_mib_handler *handler;
  95.     int             mfd_modes = 0;
  96.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_initialize_interface", "calledn"));
  97.     /*************************************************
  98.      *
  99.      * save interface context for ipAddressTable
  100.      */
  101.     /*
  102.      * Setting up the table's definition
  103.      */
  104.     netsnmp_table_helper_add_indexes(tbl_info, ASN_INTEGER,
  105.                                                /** index: ipAddressAddrType */
  106.                                      ASN_OCTET_STR,
  107.                                                  /** index: ipAddressAddr */
  108.                                      0);
  109.     /*
  110.      * Define the minimum and maximum accessible columns.  This
  111.      * optimizes retrival. 
  112.      */
  113.     tbl_info->min_column = IPADDRESSTABLE_MIN_COL;
  114.     tbl_info->max_column = IPADDRESSTABLE_MAX_COL;
  115.     /*
  116.      * save users context
  117.      */
  118.     ipAddressTable_if_ctx.user_ctx = reg_ptr;
  119.     /*
  120.      * call data access initialization code
  121.      */
  122.     ipAddressTable_init_data(reg_ptr);
  123.     /*
  124.      * set up the container
  125.      */
  126.     _ipAddressTable_container_init(&ipAddressTable_if_ctx);
  127.     if (NULL == ipAddressTable_if_ctx.container) {
  128.         snmp_log(LOG_ERR,
  129.                  "could not initialize container for ipAddressTablen");
  130.         return;
  131.     }
  132.     /*
  133.      * access_multiplexer: REQUIRED wrapper for get request handling
  134.      */
  135.     access_multiplexer->object_lookup = _mfd_ipAddressTable_object_lookup;
  136.     access_multiplexer->get_values = _mfd_ipAddressTable_get_values;
  137.     /*
  138.      * no wrappers yet
  139.      */
  140.     access_multiplexer->pre_request = _mfd_ipAddressTable_pre_request;
  141.     access_multiplexer->post_request = _mfd_ipAddressTable_post_request;
  142.     /*
  143.      * REQUIRED wrappers for set request handling
  144.      */
  145.     access_multiplexer->object_syntax_checks =
  146.         _mfd_ipAddressTable_check_objects;
  147.     access_multiplexer->undo_setup = _mfd_ipAddressTable_undo_setup;
  148.     access_multiplexer->undo_cleanup = _mfd_ipAddressTable_undo_cleanup;
  149.     access_multiplexer->set_values = _mfd_ipAddressTable_set_values;
  150.     access_multiplexer->undo_sets = _mfd_ipAddressTable_undo_values;
  151.     /*
  152.      * no wrappers yet
  153.      */
  154.     access_multiplexer->commit = _mfd_ipAddressTable_commit;
  155.     access_multiplexer->undo_commit = _mfd_ipAddressTable_undo_commit;
  156.     /*
  157.      * REQUIRED for tables with dependencies
  158.      */
  159.     access_multiplexer->consistency_checks =
  160.         _mfd_ipAddressTable_check_dependencies;
  161.     /*************************************************
  162.      *
  163.      * Create a registration, save our reg data, register table.
  164.      */
  165.     DEBUGMSGTL(("ipAddressTable:init_ipAddressTable",
  166.                 "Registering ipAddressTable as a mibs-for-dummies table.n"));
  167.     handler =
  168.         netsnmp_baby_steps_access_multiplexer_get(access_multiplexer);
  169.     reginfo =
  170.         netsnmp_handler_registration_create("ipAddressTable", handler,
  171.                                             ipAddressTable_oid,
  172.                                             ipAddressTable_oid_size,
  173.                                             HANDLER_CAN_BABY_STEP |
  174.                                             HANDLER_CAN_RWRITE);
  175.     if (NULL == reginfo) {
  176.         snmp_log(LOG_ERR, "error registering table ipAddressTablen");
  177.         return;
  178.     }
  179.     reginfo->my_reg_void = &ipAddressTable_if_ctx;
  180.     /*************************************************
  181.      *
  182.      * set up baby steps handler, create it and inject it
  183.      */
  184.     if (access_multiplexer->object_lookup)
  185.         mfd_modes |= BABY_STEP_OBJECT_LOOKUP;
  186.     if (access_multiplexer->set_values)
  187.         mfd_modes |= BABY_STEP_SET_VALUES;
  188.     if (access_multiplexer->irreversible_commit)
  189.         mfd_modes |= BABY_STEP_IRREVERSIBLE_COMMIT;
  190.     if (access_multiplexer->object_syntax_checks)
  191.         mfd_modes |= BABY_STEP_CHECK_OBJECT;
  192.     if (access_multiplexer->pre_request)
  193.         mfd_modes |= BABY_STEP_PRE_REQUEST;
  194.     if (access_multiplexer->post_request)
  195.         mfd_modes |= BABY_STEP_POST_REQUEST;
  196.     if (access_multiplexer->undo_setup)
  197.         mfd_modes |= BABY_STEP_UNDO_SETUP;
  198.     if (access_multiplexer->undo_cleanup)
  199.         mfd_modes |= BABY_STEP_UNDO_CLEANUP;
  200.     if (access_multiplexer->undo_sets)
  201.         mfd_modes |= BABY_STEP_UNDO_SETS;
  202.     if (access_multiplexer->row_creation)
  203.         mfd_modes |= BABY_STEP_ROW_CREATE;
  204.     if (access_multiplexer->consistency_checks)
  205.         mfd_modes |= BABY_STEP_CHECK_CONSISTENCY;
  206.     if (access_multiplexer->commit)
  207.         mfd_modes |= BABY_STEP_COMMIT;
  208.     if (access_multiplexer->undo_commit)
  209.         mfd_modes |= BABY_STEP_UNDO_COMMIT;
  210.     handler = netsnmp_baby_steps_handler_get(mfd_modes);
  211.     netsnmp_inject_handler(reginfo, handler);
  212.     /*************************************************
  213.      *
  214.      * inject row_merge helper with prefix rootoid_len + 2 (entry.col)
  215.      */
  216.     handler = netsnmp_get_row_merge_handler(reginfo->rootoid_len + 2);
  217.     netsnmp_inject_handler(reginfo, handler);
  218.     /*************************************************
  219.      *
  220.      * inject container_table helper
  221.      */
  222.     handler =
  223.         netsnmp_container_table_handler_get(tbl_info,
  224.                                             ipAddressTable_if_ctx.
  225.                                             container,
  226.                                             TABLE_CONTAINER_KEY_NETSNMP_INDEX);
  227.     netsnmp_inject_handler(reginfo, handler);
  228.     /*************************************************
  229.      *
  230.      * inject cache helper
  231.      */
  232.     if (NULL != ipAddressTable_if_ctx.cache) {
  233.         handler = netsnmp_cache_handler_get(ipAddressTable_if_ctx.cache);
  234.         netsnmp_inject_handler(reginfo, handler);
  235.     }
  236.     /*
  237.      * register table
  238.      */
  239.     netsnmp_register_table(reginfo, tbl_info);
  240. }                               /* _ipAddressTable_initialize_interface */
  241. void
  242. ipAddressTable_valid_columns_set(netsnmp_column_info *vc)
  243. {
  244.     ipAddressTable_if_ctx.tbl_info.valid_columns = vc;
  245. }                               /* ipAddressTable_valid_columns_set */
  246. /**
  247.  * @internal
  248.  * convert the index component stored in the context to an oid
  249.  */
  250. int
  251. ipAddressTable_index_to_oid(netsnmp_index * oid_idx,
  252.                             ipAddressTable_mib_index * mib_idx)
  253. {
  254.     int             err = SNMP_ERR_NOERROR;
  255.     /*
  256.      * temp storage for parsing indexes
  257.      */
  258.     /*
  259.      * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
  260.      */
  261.     netsnmp_variable_list var_ipAddressAddrType;
  262.     /*
  263.      * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
  264.      */
  265.     netsnmp_variable_list var_ipAddressAddr;
  266.     /*
  267.      * set up varbinds
  268.      */
  269.     memset(&var_ipAddressAddrType, 0x00, sizeof(var_ipAddressAddrType));
  270.     var_ipAddressAddrType.type = ASN_INTEGER;
  271.     memset(&var_ipAddressAddr, 0x00, sizeof(var_ipAddressAddr));
  272.     var_ipAddressAddr.type = ASN_OCTET_STR;
  273.     /*
  274.      * chain temp index varbinds together
  275.      */
  276.     var_ipAddressAddrType.next_variable = &var_ipAddressAddr;
  277.     var_ipAddressAddr.next_variable = NULL;
  278.     DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_index_to_oid",
  279.                 "calledn"));
  280.     /*
  281.      * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h 
  282.      */
  283.     snmp_set_var_value(&var_ipAddressAddrType,
  284.                        (u_char *) & mib_idx->ipAddressAddrType,
  285.                        sizeof(mib_idx->ipAddressAddrType));
  286.     /*
  287.      * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h 
  288.      */
  289.     snmp_set_var_value(&var_ipAddressAddr,
  290.                        (u_char *) & mib_idx->ipAddressAddr,
  291.                        mib_idx->ipAddressAddr_len *
  292.                        sizeof(mib_idx->ipAddressAddr[0]));
  293.     err = build_oid_noalloc(oid_idx->oids, oid_idx->len, &oid_idx->len,
  294.                             NULL, 0, &var_ipAddressAddrType);
  295.     if (err)
  296.         snmp_log(LOG_ERR, "error %d converting index to oidn", err);
  297.     /*
  298.      * parsing may have allocated memory. free it.
  299.      */
  300.     snmp_reset_var_buffers(&var_ipAddressAddrType);
  301.     return err;
  302. }                               /* ipAddressTable_index_to_oid */
  303. /**
  304.  * extract ipAddressTable indexes from a netsnmp_index
  305.  *
  306.  * @retval SNMP_ERR_NOERROR  : no error
  307.  * @retval SNMP_ERR_GENERR   : error
  308.  */
  309. int
  310. ipAddressTable_index_from_oid(netsnmp_index * oid_idx,
  311.                               ipAddressTable_mib_index * mib_idx)
  312. {
  313.     int             err = SNMP_ERR_NOERROR;
  314.     /*
  315.      * temp storage for parsing indexes
  316.      */
  317.     /*
  318.      * ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h
  319.      */
  320.     netsnmp_variable_list var_ipAddressAddrType;
  321.     /*
  322.      * ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h
  323.      */
  324.     netsnmp_variable_list var_ipAddressAddr;
  325.     /*
  326.      * set up varbinds
  327.      */
  328.     memset(&var_ipAddressAddrType, 0x00, sizeof(var_ipAddressAddrType));
  329.     var_ipAddressAddrType.type = ASN_INTEGER;
  330.     memset(&var_ipAddressAddr, 0x00, sizeof(var_ipAddressAddr));
  331.     var_ipAddressAddr.type = ASN_OCTET_STR;
  332.     /*
  333.      * chain temp index varbinds together
  334.      */
  335.     var_ipAddressAddrType.next_variable = &var_ipAddressAddr;
  336.     var_ipAddressAddr.next_variable = NULL;
  337.     DEBUGMSGTL(("verbose:ipAddressTable:ipAddressTable_index_from_oid",
  338.                 "calledn"));
  339.     /*
  340.      * parse the oid into the individual index components
  341.      */
  342.     err = parse_oid_indexes(oid_idx->oids, oid_idx->len,
  343.                             &var_ipAddressAddrType);
  344.     if (err == SNMP_ERR_NOERROR) {
  345.         /*
  346.          * copy out values
  347.          */
  348.         mib_idx->ipAddressAddrType =
  349.             *((u_long *) var_ipAddressAddrType.val.string);
  350.         /*
  351.          * NOTE: val_len is in bytes, ipAddressAddr_len might not be
  352.          */
  353.         if (var_ipAddressAddr.val_len > sizeof(mib_idx->ipAddressAddr))
  354.             err = SNMP_ERR_GENERR;
  355.         else {
  356.             memcpy(mib_idx->ipAddressAddr, var_ipAddressAddr.val.string,
  357.                    var_ipAddressAddr.val_len);
  358.             mib_idx->ipAddressAddr_len =
  359.                 var_ipAddressAddr.val_len /
  360.                 sizeof(mib_idx->ipAddressAddr[0]);
  361.         }
  362.     }
  363.     /*
  364.      * parsing may have allocated memory. free it.
  365.      */
  366.     snmp_reset_var_buffers(&var_ipAddressAddrType);
  367.     return err;
  368. }                               /* ipAddressTable_index_from_oid */
  369. /*
  370.  *********************************************************************
  371.  * @internal
  372.  * allocate resources for a ipAddressTable_rowreq_ctx
  373.  */
  374. ipAddressTable_rowreq_ctx *
  375. ipAddressTable_allocate_rowreq_ctx(ipAddressTable_data * data)
  376. {
  377.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  378.         SNMP_MALLOC_TYPEDEF(ipAddressTable_rowreq_ctx);
  379.     DEBUGMSGTL(("internal:ipAddressTable:ipAddressTable_allocate_rowreq_ctx", "calledn"));
  380.     if (NULL == rowreq_ctx) {
  381.         snmp_log(LOG_ERR, "Couldn't allocate memory for a "
  382.                  "ipAddressTable_rowreq_ctx.n");
  383.     } else {
  384.         if (NULL != data) {
  385.             rowreq_ctx->data = data;
  386.         } else if (NULL ==
  387.                    (rowreq_ctx->data = ipAddressTable_allocate_data())) {
  388.             SNMP_FREE(rowreq_ctx);
  389.             return NULL;
  390.         }
  391.     }
  392.     /*
  393.      * undo context will be allocated when needed (in *_undo_setup)
  394.      */
  395.     rowreq_ctx->oid_idx.oids = rowreq_ctx->oid_tmp;
  396.     rowreq_ctx->ipAddressTable_data_list = NULL;
  397.     rowreq_ctx->ipAddressTable_reg = ipAddressTable_if_ctx.user_ctx;
  398.     return rowreq_ctx;
  399. }                               /* ipAddressTable_allocate_rowreq_ctx */
  400. /*
  401.  * @internal
  402.  * release resources for a ipAddressTable_rowreq_ctx
  403.  */
  404. void
  405. ipAddressTable_release_rowreq_ctx(ipAddressTable_rowreq_ctx * rowreq_ctx)
  406. {
  407.     DEBUGMSGTL(("internal:ipAddressTable:ipAddressTable_release_rowreq_ctx", "calledn"));
  408.     netsnmp_assert(NULL != rowreq_ctx);
  409.     if (rowreq_ctx->data)
  410.         ipAddressTable_release_data(rowreq_ctx->data);
  411.     if (rowreq_ctx->undo)
  412.         ipAddressTable_release_data(rowreq_ctx->undo);
  413.     /*
  414.      * free index oid pointer
  415.      */
  416.     if (rowreq_ctx->oid_idx.oids != rowreq_ctx->oid_tmp)
  417.         free(rowreq_ctx->oid_idx.oids);
  418.     SNMP_FREE(rowreq_ctx);
  419. }                               /* ipAddressTable_release_rowreq_ctx */
  420. /**
  421.  * @internal
  422.  * wrapper
  423.  */
  424. static int
  425. _mfd_ipAddressTable_pre_request(netsnmp_mib_handler *handler,
  426.                                 netsnmp_handler_registration *reginfo,
  427.                                 netsnmp_agent_request_info *agtreq_info,
  428.                                 netsnmp_request_info *requests)
  429. {
  430.     int             rc =
  431.         ipAddressTable_pre_request(ipAddressTable_if_ctx.user_ctx);
  432.     if (MFD_SUCCESS != rc) {
  433.         /*
  434.          * nothing we can do about it but log it
  435.          */
  436.         DEBUGMSGTL(("internal:ipAddressTable", "error %d from "
  437.                     "ipAddressTable_pre_requestn", rc));
  438.         netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
  439.     }
  440.     return SNMP_ERR_NOERROR;
  441. }                               /* _mfd_ipAddressTable_pre_request */
  442. /**
  443.  * @internal
  444.  * wrapper
  445.  */
  446. static int
  447. _mfd_ipAddressTable_post_request(netsnmp_mib_handler *handler,
  448.                                  netsnmp_handler_registration *reginfo,
  449.                                  netsnmp_agent_request_info *agtreq_info,
  450.                                  netsnmp_request_info *requests)
  451. {
  452.     ipAddressTable_rowreq_ctx *rowreq_ctx;
  453.     int             rc =
  454.         ipAddressTable_post_request(ipAddressTable_if_ctx.user_ctx);
  455.     if (MFD_SUCCESS != rc) {
  456.         /*
  457.          * nothing we can do about it but log it
  458.          */
  459.         DEBUGMSGTL(("internal:ipAddressTable", "error %d from "
  460.                     "ipAddressTable_post_requestn", rc));
  461.     }
  462.     /*
  463.      * if it was set, clear row created flag.
  464.      */
  465.     rowreq_ctx = netsnmp_container_table_row_extract(requests);
  466.     if ((NULL != rowreq_ctx)
  467.         && (rowreq_ctx->rowreq_flags & MFD_ROW_CREATED))
  468.         rowreq_ctx->rowreq_flags &= ~MFD_ROW_CREATED;
  469.     return SNMP_ERR_NOERROR;
  470. }                               /* _mfd_ipAddressTable_post_request */
  471. /**
  472.  * @internal
  473.  * wrapper
  474.  */
  475. static int
  476. _mfd_ipAddressTable_object_lookup(netsnmp_mib_handler *handler,
  477.                                   netsnmp_handler_registration *reginfo,
  478.                                   netsnmp_agent_request_info *agtreq_info,
  479.                                   netsnmp_request_info *requests)
  480. {
  481.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  482.         netsnmp_container_table_row_extract(requests);
  483.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_object_lookup", "calledn"));
  484.     /*
  485.      * get our context from mfd
  486.      * ipAddressTable_interface_ctx *if_ctx =
  487.      *             (ipAddressTable_interface_ctx *)reginfo->my_reg_void;
  488.      */
  489.     if (NULL == rowreq_ctx) {
  490. #define NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT 1
  491. #ifndef NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT
  492.         netsnmp_request_set_error(requests, SNMP_ERR_NOCREATION);
  493. #else
  494.         int             rc = MFD_SUCCESS;
  495.         netsnmp_table_request_info *tblreq_info;
  496.         netsnmp_index   oid_idx;
  497.         ipAddressTable_mib_index mib_idx;
  498.         tblreq_info = netsnmp_extract_table_info(requests);
  499.         if (NULL == tblreq_info) {
  500.             snmp_log(LOG_ERR, "request had no table infon");
  501.             return MFD_ERROR;
  502.         }
  503.         /*
  504.          * try to parse oid
  505.          */
  506.         oid_idx.oids = tblreq_info->index_oid;
  507.         oid_idx.len = tblreq_info->index_oid_len;
  508.         rc = ipAddressTable_index_from_oid(&oid_idx, &mib_idx);
  509.         if (MFD_SUCCESS != rc) {
  510.             DEBUGMSGT(("ipAddressTable", "error parsing indexn"));
  511.             netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
  512.         } else {
  513.             /*
  514.              * allocate new context
  515.              */
  516.             rowreq_ctx = ipAddressTable_allocate_rowreq_ctx(NULL);
  517.             if (NULL == rowreq_ctx)
  518.                 return MFD_ERROR;       /* msg already logged */
  519.             memcpy(&rowreq_ctx->tbl_idx, &mib_idx, sizeof(mib_idx));
  520.             /*
  521.              * check indexes
  522.              */
  523.             rc = _ipAddressTable_check_indexes(rowreq_ctx);
  524.             if (MFD_SUCCESS != rc) {
  525.                 netsnmp_assert((rc == SNMP_ERR_NOCREATION) ||
  526.                                (rc == SNMP_ERR_INCONSISTENTNAME));
  527.                 netsnmp_request_set_error_all(requests,
  528.                                               SNMP_VALIDATE_ERR(rc));
  529.                 ipAddressTable_release_rowreq_ctx(rowreq_ctx);
  530.             } else {
  531.                 rowreq_ctx->rowreq_flags |= MFD_ROW_CREATED;
  532.                 netsnmp_container_table_row_insert(requests, rowreq_ctx);
  533.             }
  534.         }
  535. #endif                          /* NETSNMP_IPADDRESSTABLE_CREATE_SUPPORT */
  536.     } else {
  537.         ipAddressTable_row_prep(rowreq_ctx);
  538.     }
  539.     return SNMP_ERR_NOERROR;
  540. }                               /* _mfd_ipAddressTable_object_lookup */
  541. /***********************************************************************
  542.  *
  543.  * GET processing
  544.  *
  545.  ***********************************************************************/
  546. /*
  547.  * @internal
  548.  * Retrieve the value for a particular column
  549.  */
  550. NETSNMP_STATIC_INLINE int
  551. _ipAddressTable_get_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
  552.                            netsnmp_variable_list * var, int column)
  553. {
  554.     int             rc = SNMPERR_SUCCESS;
  555.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_column",
  556.                 "calledn"));
  557.     netsnmp_assert(NULL != rowreq_ctx);
  558.     switch (column) {
  559.         /*
  560.          * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H 
  561.          */
  562.     case COLUMN_IPADDRESSIFINDEX:
  563.         var->val_len = sizeof(long);
  564.         var->type = ASN_INTEGER;
  565.         rc = ipAddressIfIndex_get(rowreq_ctx, (long *) var->val.string);
  566.         break;
  567.         /*
  568.          * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  569.          */
  570.     case COLUMN_IPADDRESSTYPE:
  571.         var->val_len = sizeof(u_long);
  572.         var->type = ASN_INTEGER;
  573.         rc = ipAddressType_get(rowreq_ctx, (u_long *) var->val.string);
  574.         break;
  575.         /*
  576.          * ipAddressPrefix(5)/RowPointer/ASN_OBJECT_ID/oid(oid)//L/A/w/e/r/D/h 
  577.          */
  578.     case COLUMN_IPADDRESSPREFIX:
  579.         var->type = ASN_OBJECT_ID;
  580.         rc = ipAddressPrefix_get(rowreq_ctx, (oid **) & var->val.string,
  581.                                  &var->val_len);
  582.         break;
  583.         /*
  584.          * ipAddressOrigin(6)/IpAddressOriginTC/ASN_INTEGER/long(u_long)//l/A/w/E/r/d/h 
  585.          */
  586.     case COLUMN_IPADDRESSORIGIN:
  587.         var->val_len = sizeof(u_long);
  588.         var->type = ASN_INTEGER;
  589.         rc = ipAddressOrigin_get(rowreq_ctx, (u_long *) var->val.string);
  590.         break;
  591.         /*
  592.          * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  593.          */
  594.     case COLUMN_IPADDRESSSTATUS:
  595.         var->val_len = sizeof(u_long);
  596.         var->type = ASN_INTEGER;
  597.         rc = ipAddressStatus_get(rowreq_ctx, (u_long *) var->val.string);
  598.         break;
  599.         /*
  600.          * ipAddressCreated(8)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h 
  601.          */
  602.     case COLUMN_IPADDRESSCREATED:
  603.         var->val_len = sizeof(u_long);
  604.         var->type = ASN_TIMETICKS;
  605.         rc = ipAddressCreated_get(rowreq_ctx, (u_long *) var->val.string);
  606.         break;
  607.         /*
  608.          * ipAddressLastChanged(9)/TimeStamp/ASN_TIMETICKS/u_long(u_long)//l/A/w/e/r/d/h 
  609.          */
  610.     case COLUMN_IPADDRESSLASTCHANGED:
  611.         var->val_len = sizeof(u_long);
  612.         var->type = ASN_TIMETICKS;
  613.         rc = ipAddressLastChanged_get(rowreq_ctx,
  614.                                       (u_long *) var->val.string);
  615.         break;
  616.         /*
  617.          * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
  618.          */
  619.     case COLUMN_IPADDRESSROWSTATUS:
  620.         var->val_len = sizeof(u_long);
  621.         var->type = ASN_INTEGER;
  622.         rc = ipAddressRowStatus_get(rowreq_ctx,
  623.                                     (u_long *) var->val.string);
  624.         break;
  625.         /*
  626.          * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  627.          */
  628.     case COLUMN_IPADDRESSSTORAGETYPE:
  629.         var->val_len = sizeof(u_long);
  630.         var->type = ASN_INTEGER;
  631.         rc = ipAddressStorageType_get(rowreq_ctx,
  632.                                       (u_long *) var->val.string);
  633.         break;
  634.     default:
  635.         snmp_log(LOG_ERR,
  636.                  "unknown column %d in _ipAddressTable_get_columnn",
  637.                  column);
  638.         break;
  639.     }
  640.     return rc;
  641. }                               /* _ipAddressTable_get_column */
  642. int
  643. _mfd_ipAddressTable_get_values(netsnmp_mib_handler *handler,
  644.                                netsnmp_handler_registration *reginfo,
  645.                                netsnmp_agent_request_info *agtreq_info,
  646.                                netsnmp_request_info *requests)
  647. {
  648.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  649.         netsnmp_container_table_row_extract(requests);
  650.     netsnmp_table_request_info *tri;
  651.     u_char         *old_string;
  652.     void            (*dataFreeHook) (void *);
  653.     int             rc;
  654.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_get_values",
  655.                 "calledn"));
  656.     netsnmp_assert(NULL != rowreq_ctx);
  657.     for (; requests; requests = requests->next) {
  658.         /*
  659.          * save old pointer, so we can free it if replaced
  660.          */
  661.         old_string = requests->requestvb->val.string;
  662.         dataFreeHook = requests->requestvb->dataFreeHook;
  663.         if (NULL == requests->requestvb->val.string) {
  664.             requests->requestvb->val.string = requests->requestvb->buf;
  665.             requests->requestvb->val_len =
  666.                 sizeof(requests->requestvb->buf);
  667.         } else if (requests->requestvb->buf ==
  668.                    requests->requestvb->val.string) {
  669.             if (requests->requestvb->val_len !=
  670.                 sizeof(requests->requestvb->buf))
  671.                 requests->requestvb->val_len =
  672.                     sizeof(requests->requestvb->buf);
  673.         }
  674.         /*
  675.          * get column data
  676.          */
  677.         tri = netsnmp_extract_table_info(requests);
  678.         if (NULL == tri)
  679.             continue;
  680.         rc = _ipAddressTable_get_column(rowreq_ctx, requests->requestvb,
  681.                                         tri->colnum);
  682.         if (rc) {
  683.             if (MFD_SKIP == rc) {
  684.                 requests->requestvb->type = ASN_PRIV_RETRY;
  685.                 rc = SNMP_ERR_NOERROR;
  686.             }
  687.         } else if (NULL == requests->requestvb->val.string) {
  688.             snmp_log(LOG_ERR, "NULL varbind data pointer!n");
  689.             rc = SNMP_ERR_GENERR;
  690.         }
  691.         if (rc)
  692.             netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));
  693.         /*
  694.          * if the buffer wasn't used previously for the old data (i.e. it
  695.          * was allcoated memory)  and the get routine replaced the pointer,
  696.          * we need to free the previous pointer.
  697.          */
  698.         if (old_string && (old_string != requests->requestvb->buf) &&
  699.             (requests->requestvb->val.string != old_string)) {
  700.             if (dataFreeHook)
  701.                 (*dataFreeHook) (old_string);
  702.             else
  703.                 free(old_string);
  704.         }
  705.     }                           /* for results */
  706.     return SNMP_ERR_NOERROR;
  707. }                               /* _mfd_ipAddressTable_get_values */
  708. /***********************************************************************
  709.  *
  710.  * SET processing
  711.  *
  712.  ***********************************************************************/
  713. /*----------------------------------------------------------------------
  714.  *
  715.  * SET: Syntax checks
  716.  *
  717.  *---------------------------------------------------------------------*/
  718. /*
  719.  * @internal
  720.  * Check the syntax for a particular column
  721.  */
  722. NETSNMP_STATIC_INLINE int
  723. _ipAddressTable_check_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
  724.                              netsnmp_variable_list * var, int column)
  725. {
  726.     int             rc = SNMPERR_SUCCESS;
  727.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_column",
  728.                 "calledn"));
  729.     netsnmp_assert(NULL != rowreq_ctx);
  730.     switch (column) {
  731.         /*
  732.          * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H 
  733.          */
  734.     case COLUMN_IPADDRESSIFINDEX:
  735.         rc = netsnmp_check_vb_type(var, ASN_INTEGER);
  736.         if (SNMPERR_SUCCESS == rc) {
  737.             /*
  738.              * check that the value is in the defined range(s); inefficent
  739.              * * but keeps rc value knowledge in libarary where it belongs. 
  740.              */
  741.             if (1 && ((rc = netsnmp_check_vb_int_range(var, 1, 2147483647))
  742.                       != SNMP_ERR_NOERROR)
  743.                 ) {
  744.                 ;               /* rc set in condition */
  745.             }
  746.         }
  747.         if (SNMPERR_SUCCESS == rc) {
  748.             rc = ipAddressIfIndex_check_value(rowreq_ctx,
  749.                                               *((long *) var->val.string));
  750.             if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
  751.                 && (MFD_NOT_VALID_NOW != rc)) {
  752.                 snmp_log(LOG_ERR,
  753.                          "bad rc %d from ipAddressIfIndex_check_valuen",
  754.                          rc);
  755.                 rc = SNMP_ERR_GENERR;
  756.             }
  757.         }
  758.         break;
  759.         /*
  760.          * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  761.          */
  762.     case COLUMN_IPADDRESSTYPE:
  763.         rc = netsnmp_check_vb_type(var, ASN_INTEGER);
  764.         if (SNMPERR_SUCCESS == rc) {
  765.             /*
  766.              * check that the value is one of defined enums 
  767.              */
  768.             if (1 && (*var->val.integer != IPADDRESSTYPE_UNICAST)
  769.                 && (*var->val.integer != IPADDRESSTYPE_ANYCAST)
  770.                 && (*var->val.integer != IPADDRESSTYPE_BROADCAST)
  771.                 ) {
  772.                 rc = SNMP_ERR_WRONGVALUE;
  773.             }
  774.         }
  775.         if (SNMPERR_SUCCESS == rc) {
  776.             rc = ipAddressType_check_value(rowreq_ctx,
  777.                                            *((u_long *) var->val.string));
  778.             if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
  779.                 && (MFD_NOT_VALID_NOW != rc)) {
  780.                 snmp_log(LOG_ERR,
  781.                          "bad rc %d from ipAddressType_check_valuen", rc);
  782.                 rc = SNMP_ERR_GENERR;
  783.             }
  784.         }
  785.         break;
  786.         /*
  787.          * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  788.          */
  789.     case COLUMN_IPADDRESSSTATUS:
  790.         rc = netsnmp_check_vb_type(var, ASN_INTEGER);
  791.         if (SNMPERR_SUCCESS == rc) {
  792.             /*
  793.              * check that the value is one of defined enums 
  794.              */
  795.             if (1 && (*var->val.integer != IPADDRESSSTATUSTC_PREFERRED)
  796.                 && (*var->val.integer != IPADDRESSSTATUSTC_INVALID)
  797.                 && (*var->val.integer != IPADDRESSSTATUSTC_INACCESSIBLE)
  798.                 && (*var->val.integer != IPADDRESSSTATUSTC_UNKNOWN)
  799.                 && (*var->val.integer != IPADDRESSSTATUSTC_TENTATIVE)
  800.                 && (*var->val.integer != IPADDRESSSTATUSTC_DUPLICATE)
  801.                 ) {
  802.                 rc = SNMP_ERR_WRONGVALUE;
  803.             }
  804.         }
  805.         if (SNMPERR_SUCCESS == rc) {
  806.             rc = ipAddressStatus_check_value(rowreq_ctx,
  807.                                              *((u_long *) var->val.
  808.                                                string));
  809.             if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
  810.                 && (MFD_NOT_VALID_NOW != rc)) {
  811.                 snmp_log(LOG_ERR,
  812.                          "bad rc %d from ipAddressStatus_check_valuen",
  813.                          rc);
  814.                 rc = SNMP_ERR_GENERR;
  815.             }
  816.         }
  817.         break;
  818.         /*
  819.          * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
  820.          */
  821.     case COLUMN_IPADDRESSROWSTATUS:
  822.         rc = netsnmp_check_vb_rowstatus_value(var);
  823.         if (SNMPERR_SUCCESS == rc) {
  824.             rc = ipAddressRowStatus_check_value(rowreq_ctx,
  825.                                                 *((u_long *) var->val.
  826.                                                   string));
  827.             if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
  828.                 && (MFD_NOT_VALID_NOW != rc)) {
  829.                 snmp_log(LOG_ERR,
  830.                          "bad rc %d from ipAddressRowStatus_check_valuen",
  831.                          rc);
  832.                 rc = SNMP_ERR_GENERR;
  833.             }
  834.         }
  835.         break;
  836.         /*
  837.          * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  838.          */
  839.     case COLUMN_IPADDRESSSTORAGETYPE:
  840.         rc = netsnmp_check_vb_type(var, ASN_INTEGER);
  841.         if (SNMPERR_SUCCESS == rc) {
  842.             /*
  843.              * check that the value is one of defined enums 
  844.              */
  845.             if (1 && (*var->val.integer != STORAGETYPE_OTHER)
  846.                 && (*var->val.integer != STORAGETYPE_VOLATILE)
  847.                 && (*var->val.integer != STORAGETYPE_NONVOLATILE)
  848.                 && (*var->val.integer != STORAGETYPE_PERMANENT)
  849.                 && (*var->val.integer != STORAGETYPE_READONLY)
  850.                 ) {
  851.                 rc = SNMP_ERR_WRONGVALUE;
  852.             }
  853.         }
  854.         if (SNMPERR_SUCCESS == rc) {
  855.             rc = ipAddressStorageType_check_value(rowreq_ctx,
  856.                                                   *((u_long *) var->val.
  857.                                                     string));
  858.             if ((MFD_SUCCESS != rc) && (MFD_NOT_VALID_EVER != rc)
  859.                 && (MFD_NOT_VALID_NOW != rc)) {
  860.                 snmp_log(LOG_ERR,
  861.                          "bad rc %d from ipAddressStorageType_check_valuen",
  862.                          rc);
  863.                 rc = SNMP_ERR_GENERR;
  864.             }
  865.         }
  866.         break;
  867.     default:   /** We shouldn't get here */
  868.         rc = SNMP_ERR_GENERR;
  869.         snmp_log(LOG_ERR,
  870.                  "unknown column %d in _ipAddressTable_check_columnn",
  871.                  column);
  872.     }
  873.     return rc;
  874. }                               /* _ipAddressTable_check_column */
  875. int
  876. _mfd_ipAddressTable_check_objects(netsnmp_mib_handler *handler,
  877.                                   netsnmp_handler_registration *reginfo,
  878.                                   netsnmp_agent_request_info *agtreq_info,
  879.                                   netsnmp_request_info *requests)
  880. {
  881.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  882.         netsnmp_container_table_row_extract(requests);
  883.     netsnmp_table_request_info *tri;
  884.     int             rc;
  885.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_check_objects", "calledn"));
  886.     netsnmp_assert(NULL != rowreq_ctx);
  887.     for (; requests; requests = requests->next) {
  888.         /*
  889.          * get column number from table request info, and check that column
  890.          */
  891.         tri = netsnmp_extract_table_info(requests);
  892.         if (NULL == tri)
  893.             continue;
  894.         rc = _ipAddressTable_check_column(rowreq_ctx, requests->requestvb,
  895.                                           tri->colnum);
  896.         if (rc) {
  897.             netsnmp_request_set_error(requests, SNMP_VALIDATE_ERR(rc));
  898.             break;
  899.         }
  900.     }                           /* for results */
  901.     return SNMP_ERR_NOERROR;
  902. }                               /* _mfd_ipAddressTable_check_objects */
  903. NETSNMP_STATIC_INLINE int
  904. _ipAddressTable_check_indexes(ipAddressTable_rowreq_ctx * rowreq_ctx)
  905. {
  906.     int             rc;
  907.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_check_indexes",
  908.                 "calledn"));
  909.     netsnmp_assert(NULL != rowreq_ctx);
  910.     /*
  911.      * (INDEX) ipAddressAddrType(1)/InetAddressType/ASN_INTEGER/long(u_long)//l/a/w/E/r/d/h 
  912.      */
  913.     rc = ipAddressAddrType_check_index(rowreq_ctx);
  914.     if (MFD_SUCCESS != rc)
  915.         return SNMP_ERR_NOCREATION;
  916.     /*
  917.      * (INDEX) ipAddressAddr(2)/InetAddress/ASN_OCTET_STR/char(char)//L/a/w/e/R/d/h 
  918.      */
  919.     rc = ipAddressAddr_check_index(rowreq_ctx);
  920.     if (MFD_SUCCESS != rc)
  921.         return SNMP_ERR_NOCREATION;
  922.     /*
  923.      * if individual parts look ok, check them as a whole
  924.      */
  925.     return ipAddressTable_validate_index(rowreq_ctx->ipAddressTable_reg,
  926.                                          rowreq_ctx);
  927. }                               /* _ipAddressTable_check_indexes */
  928. /*----------------------------------------------------------------------
  929.  *
  930.  * SET: check dependencies
  931.  *
  932.  *---------------------------------------------------------------------*/
  933. /*
  934.  * @internal
  935.  * Check dependencies wrapper
  936.  */
  937. static int
  938. _mfd_ipAddressTable_check_dependencies(netsnmp_mib_handler *handler, netsnmp_handler_registration
  939.                                        *reginfo, netsnmp_agent_request_info
  940.                                        *agtreq_info,
  941.                                        netsnmp_request_info *requests)
  942. {
  943.     int             rc;
  944.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  945.         netsnmp_container_table_row_extract(requests);
  946.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_check_dependencies", "calledn"));
  947.     netsnmp_assert(NULL != rowreq_ctx);
  948.     rc = ipAddressTable_check_dependencies(rowreq_ctx);
  949.     if (rc) {
  950.         DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  951.                     "ipAddressTable_check_dependenciesn", rc));
  952.         netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
  953.     }
  954.     return SNMP_ERR_NOERROR;
  955. }                               /* _mfd_ipAddressTable_check_dependencies */
  956. /*----------------------------------------------------------------------
  957.  *
  958.  * SET: Undo setup
  959.  *
  960.  *---------------------------------------------------------------------*/
  961. /*
  962.  * @internal
  963.  * Set the value for a particular column
  964.  */
  965. NETSNMP_STATIC_INLINE int
  966. _ipAddressTable_undo_setup_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
  967.                                   int column)
  968. {
  969.     int             rc = SNMPERR_SUCCESS;
  970.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_undo_setup_column", "calledn"));
  971.     netsnmp_assert(NULL != rowreq_ctx);
  972.     switch (column) {
  973.         /*
  974.          * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H 
  975.          */
  976.     case COLUMN_IPADDRESSIFINDEX:
  977.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSIFINDEX;
  978.         rc = ipAddressIfIndex_undo_setup(rowreq_ctx);
  979.         break;
  980.         /*
  981.          * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  982.          */
  983.     case COLUMN_IPADDRESSTYPE:
  984.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSTYPE;
  985.         rc = ipAddressType_undo_setup(rowreq_ctx);
  986.         break;
  987.         /*
  988.          * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  989.          */
  990.     case COLUMN_IPADDRESSSTATUS:
  991.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSSTATUS;
  992.         rc = ipAddressStatus_undo_setup(rowreq_ctx);
  993.         break;
  994.         /*
  995.          * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
  996.          */
  997.     case COLUMN_IPADDRESSROWSTATUS:
  998.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSROWSTATUS;
  999.         rc = ipAddressRowStatus_undo_setup(rowreq_ctx);
  1000.         break;
  1001.         /*
  1002.          * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1003.          */
  1004.     case COLUMN_IPADDRESSSTORAGETYPE:
  1005.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSSTORAGETYPE;
  1006.         rc = ipAddressStorageType_undo_setup(rowreq_ctx);
  1007.         break;
  1008.     default:
  1009.         snmp_log(LOG_ERR,
  1010.                  "unknown column %d in _ipAddressTable_undo_setup_columnn",
  1011.                  column);
  1012.         break;
  1013.     }
  1014.     return rc;
  1015. }                               /* _ipAddressTable_undo_setup_column */
  1016. /**
  1017.  * @internal
  1018.  * undo setup
  1019.  */
  1020. int
  1021. _mfd_ipAddressTable_undo_setup(netsnmp_mib_handler *handler,
  1022.                                netsnmp_handler_registration *reginfo,
  1023.                                netsnmp_agent_request_info *agtreq_info,
  1024.                                netsnmp_request_info *requests)
  1025. {
  1026.     int             rc;
  1027.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  1028.         netsnmp_container_table_row_extract(requests);
  1029.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_setup",
  1030.                 "calledn"));
  1031.     netsnmp_assert(NULL != rowreq_ctx);
  1032.     /*
  1033.      * allocate undo context
  1034.      */
  1035.     rowreq_ctx->undo = ipAddressTable_allocate_data();
  1036.     if (NULL == rowreq_ctx->undo) {
  1037.         /** msg already logged */
  1038.         netsnmp_request_set_error_all(requests,
  1039.                                       SNMP_ERR_RESOURCEUNAVAILABLE);
  1040.         return SNMP_ERR_NOERROR;
  1041.     }
  1042.     /*
  1043.      * row undo setup
  1044.      */
  1045.     rowreq_ctx->column_set_flags = 0;
  1046.     rc = ipAddressTable_undo_setup(rowreq_ctx);
  1047.     if (MFD_SUCCESS != rc) {
  1048.         DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1049.                     "ipAddressTable_undo_setupn", rc));
  1050.         netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
  1051.     } else {
  1052.         /*
  1053.          * column undo setup
  1054.          */
  1055.         netsnmp_table_request_info *tri;
  1056.         for (; requests; requests = requests->next) {
  1057.             /*
  1058.              * set column data
  1059.              */
  1060.             tri = netsnmp_extract_table_info(requests);
  1061.             if (NULL == tri)
  1062.                 continue;
  1063.             rc = _ipAddressTable_undo_setup_column(rowreq_ctx,
  1064.                                                    tri->colnum);
  1065.             if (MFD_SUCCESS != rc) {
  1066.                 DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1067.                             "ipAddressTable_undo_setup_columnn", rc));
  1068.                 netsnmp_set_request_error(agtreq_info, requests,
  1069.                                           SNMP_VALIDATE_ERR(rc));
  1070.             }
  1071.         }                       /* for results */
  1072.     }
  1073.     return SNMP_ERR_NOERROR;
  1074. }                               /* _mfd_ipAddressTable_undo_setup */
  1075. /**
  1076.  * @internal
  1077.  * undo setup
  1078.  */
  1079. int
  1080. _mfd_ipAddressTable_undo_cleanup(netsnmp_mib_handler *handler,
  1081.                                  netsnmp_handler_registration *reginfo,
  1082.                                  netsnmp_agent_request_info *agtreq_info,
  1083.                                  netsnmp_request_info *requests)
  1084. {
  1085.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  1086.         netsnmp_container_table_row_extract(requests);
  1087.     int             rc;
  1088.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_cleanup",
  1089.                 "calledn"));
  1090.     /*
  1091.      * failed row create in early stages has no rowreq_ctx
  1092.      */
  1093.     if (NULL == rowreq_ctx)
  1094.         return MFD_SUCCESS;
  1095.     /*
  1096.      * call user cleanup
  1097.      */
  1098.     rc = ipAddressTable_undo_cleanup(rowreq_ctx);
  1099.     if (MFD_SUCCESS != rc) {
  1100.         /*
  1101.          * nothing we can do about it but log it
  1102.          */
  1103.         DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1104.                     "ipAddressTable_undo_cleanupn", rc));
  1105.     }
  1106.     /*
  1107.      * release undo context, if needed
  1108.      */
  1109.     if (rowreq_ctx->undo) {
  1110.         ipAddressTable_release_data(rowreq_ctx->undo);
  1111.         rowreq_ctx->undo = NULL;
  1112.     }
  1113.     /*
  1114.      * clear set flags
  1115.      */
  1116.     rowreq_ctx->column_set_flags = 0;
  1117.     return SNMP_ERR_NOERROR;
  1118. }                               /* _mfd_ipAddressTable_undo_cleanup */
  1119. /*----------------------------------------------------------------------
  1120.  *
  1121.  * SET: Set values
  1122.  *
  1123.  *---------------------------------------------------------------------*/
  1124. /*
  1125.  * @internal
  1126.  * Set the value for a particular column
  1127.  */
  1128. NETSNMP_STATIC_INLINE int
  1129. _ipAddressTable_set_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
  1130.                            netsnmp_variable_list * var, int column)
  1131. {
  1132.     int             rc = SNMPERR_SUCCESS;
  1133.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_set_column",
  1134.                 "calledn"));
  1135.     netsnmp_assert(NULL != rowreq_ctx);
  1136.     switch (column) {
  1137.         /*
  1138.          * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H 
  1139.          */
  1140.     case COLUMN_IPADDRESSIFINDEX:
  1141.         if (var->val_len != sizeof(long)) {
  1142.             rc = SNMP_ERR_WRONGLENGTH;
  1143.             snmp_log(LOG_ERR,
  1144.                      "varbind size of %d does not match expected size %dn",
  1145.                      var->val_len, sizeof(long));
  1146.             break;
  1147.         }
  1148.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSIFINDEX;
  1149.         rc = ipAddressIfIndex_set(rowreq_ctx, *((long *) var->val.string));
  1150.         break;
  1151.         /*
  1152.          * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1153.          */
  1154.     case COLUMN_IPADDRESSTYPE:
  1155.         if (var->val_len != sizeof(u_long)) {
  1156.             rc = SNMP_ERR_WRONGLENGTH;
  1157.             snmp_log(LOG_ERR,
  1158.                      "varbind size of %d does not match expected size %dn",
  1159.                      var->val_len, sizeof(u_long));
  1160.             break;
  1161.         }
  1162.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSTYPE;
  1163.         rc = ipAddressType_set(rowreq_ctx, *((u_long *) var->val.string));
  1164.         break;
  1165.         /*
  1166.          * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1167.          */
  1168.     case COLUMN_IPADDRESSSTATUS:
  1169.         if (var->val_len != sizeof(u_long)) {
  1170.             rc = SNMP_ERR_WRONGLENGTH;
  1171.             snmp_log(LOG_ERR,
  1172.                      "varbind size of %d does not match expected size %dn",
  1173.                      var->val_len, sizeof(u_long));
  1174.             break;
  1175.         }
  1176.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSSTATUS;
  1177.         rc = ipAddressStatus_set(rowreq_ctx,
  1178.                                  *((u_long *) var->val.string));
  1179.         break;
  1180.         /*
  1181.          * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
  1182.          */
  1183.     case COLUMN_IPADDRESSROWSTATUS:
  1184.         if (var->val_len != sizeof(u_long)) {
  1185.             rc = SNMP_ERR_WRONGLENGTH;
  1186.             snmp_log(LOG_ERR,
  1187.                      "varbind size of %d does not match expected size %dn",
  1188.                      var->val_len, sizeof(u_long));
  1189.             break;
  1190.         }
  1191.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSROWSTATUS;
  1192.         rc = ipAddressRowStatus_set(rowreq_ctx,
  1193.                                     *((u_long *) var->val.string));
  1194.         break;
  1195.         /*
  1196.          * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1197.          */
  1198.     case COLUMN_IPADDRESSSTORAGETYPE:
  1199.         if (var->val_len != sizeof(u_long)) {
  1200.             rc = SNMP_ERR_WRONGLENGTH;
  1201.             snmp_log(LOG_ERR,
  1202.                      "varbind size of %d does not match expected size %dn",
  1203.                      var->val_len, sizeof(u_long));
  1204.             break;
  1205.         }
  1206.         rowreq_ctx->column_set_flags |= FLAG_IPADDRESSSTORAGETYPE;
  1207.         rc = ipAddressStorageType_set(rowreq_ctx,
  1208.                                       *((u_long *) var->val.string));
  1209.         break;
  1210.     default:
  1211.         snmp_log(LOG_ERR,
  1212.                  "unknown column %d in _ipAddressTable_set_columnn",
  1213.                  column);
  1214.         break;
  1215.     }
  1216.     return rc;
  1217. }                               /* _ipAddressTable_set_column */
  1218. int
  1219. _mfd_ipAddressTable_set_values(netsnmp_mib_handler *handler,
  1220.                                netsnmp_handler_registration *reginfo,
  1221.                                netsnmp_agent_request_info *agtreq_info,
  1222.                                netsnmp_request_info *requests)
  1223. {
  1224.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  1225.         netsnmp_container_table_row_extract(requests);
  1226.     netsnmp_table_request_info *tri;
  1227.     int             rc = SNMP_ERR_NOERROR;
  1228.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_set_values",
  1229.                 "calledn"));
  1230.     netsnmp_assert(NULL != rowreq_ctx);
  1231.     rowreq_ctx->column_set_flags = 0;
  1232.     for (; requests; requests = requests->next) {
  1233.         /*
  1234.          * set column data
  1235.          */
  1236.         tri = netsnmp_extract_table_info(requests);
  1237.         if (NULL == tri)
  1238.             continue;
  1239.         rc = _ipAddressTable_set_column(rowreq_ctx,
  1240.                                         requests->requestvb, tri->colnum);
  1241.         if (MFD_SUCCESS != rc) {
  1242.             DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1243.                         "ipAddressTable_set_columnn", rc));
  1244.             netsnmp_set_request_error(agtreq_info, requests,
  1245.                                       SNMP_VALIDATE_ERR(rc));
  1246.         }
  1247.     }                           /* for results */
  1248.     return SNMP_ERR_NOERROR;
  1249. }                               /* _mfd_ipAddressTable_set_values */
  1250. /*----------------------------------------------------------------------
  1251.  *
  1252.  * SET: commit
  1253.  *
  1254.  *---------------------------------------------------------------------*/
  1255. /**
  1256.  * @internal
  1257.  * commit the values
  1258.  */
  1259. int
  1260. _mfd_ipAddressTable_commit(netsnmp_mib_handler *handler,
  1261.                            netsnmp_handler_registration *reginfo,
  1262.                            netsnmp_agent_request_info *agtreq_info,
  1263.                            netsnmp_request_info *requests)
  1264. {
  1265.     int             rc;
  1266.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  1267.         netsnmp_container_table_row_extract(requests);
  1268.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_commit",
  1269.                 "calledn"));
  1270.     netsnmp_assert(NULL != rowreq_ctx);
  1271.     rc = ipAddressTable_commit(rowreq_ctx);
  1272.     if (MFD_SUCCESS != rc) {
  1273.         DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1274.                     "ipAddressTable_commitn", rc));
  1275.         netsnmp_request_set_error_all(requests, SNMP_VALIDATE_ERR(rc));
  1276.     }
  1277.     return SNMP_ERR_NOERROR;
  1278. }
  1279. int
  1280. _mfd_ipAddressTable_undo_commit(netsnmp_mib_handler *handler,
  1281.                                 netsnmp_handler_registration *reginfo,
  1282.                                 netsnmp_agent_request_info *agtreq_info,
  1283.                                 netsnmp_request_info *requests)
  1284. {
  1285.     int             rc;
  1286.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  1287.         netsnmp_container_table_row_extract(requests);
  1288.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_commit",
  1289.                 "calledn"));
  1290.     netsnmp_assert(NULL != rowreq_ctx);
  1291.     rc = ipAddressTable_undo_commit(rowreq_ctx);
  1292.     if (MFD_SUCCESS != rc) {
  1293.         /*
  1294.          * nothing we can do about it but log it
  1295.          */
  1296.         DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1297.                     "ipAddressTable_undo_commitn", rc));
  1298.     }
  1299.     return SNMP_ERR_NOERROR;
  1300. }                               /* _mfd_ipAddressTable_commit */
  1301. /*----------------------------------------------------------------------
  1302.  *
  1303.  * SET: Undo
  1304.  *
  1305.  *---------------------------------------------------------------------*/
  1306. /**
  1307.  * @internal
  1308.  * undo the value for a particular column
  1309.  */
  1310. NETSNMP_STATIC_INLINE int
  1311. _ipAddressTable_undo_column(ipAddressTable_rowreq_ctx * rowreq_ctx,
  1312.                             netsnmp_variable_list * var, int column)
  1313. {
  1314.     int             rc = SNMPERR_SUCCESS;
  1315.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_undo_column",
  1316.                 "calledn"));
  1317.     netsnmp_assert(NULL != rowreq_ctx);
  1318.     switch (column) {
  1319.         /*
  1320.          * ipAddressIfIndex(3)/InterfaceIndex/ASN_INTEGER/long(long)//l/A/W/e/R/d/H 
  1321.          */
  1322.     case COLUMN_IPADDRESSIFINDEX:
  1323.         rc = ipAddressIfIndex_undo(rowreq_ctx);
  1324.         break;
  1325.         /*
  1326.          * ipAddressType(4)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1327.          */
  1328.     case COLUMN_IPADDRESSTYPE:
  1329.         rc = ipAddressType_undo(rowreq_ctx);
  1330.         break;
  1331.         /*
  1332.          * ipAddressStatus(7)/IpAddressStatusTC/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1333.          */
  1334.     case COLUMN_IPADDRESSSTATUS:
  1335.         rc = ipAddressStatus_undo(rowreq_ctx);
  1336.         break;
  1337.         /*
  1338.          * ipAddressRowStatus(10)/RowStatus/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h 
  1339.          */
  1340.     case COLUMN_IPADDRESSROWSTATUS:
  1341.         rc = ipAddressRowStatus_undo(rowreq_ctx);
  1342.         break;
  1343.         /*
  1344.          * ipAddressStorageType(11)/StorageType/ASN_INTEGER/long(u_long)//l/A/W/E/r/D/h 
  1345.          */
  1346.     case COLUMN_IPADDRESSSTORAGETYPE:
  1347.         rc = ipAddressStorageType_undo(rowreq_ctx);
  1348.         break;
  1349.     default:
  1350.         snmp_log(LOG_ERR,
  1351.                  "unknown column %d in _ipAddressTable_undo_columnn",
  1352.                  column);
  1353.         break;
  1354.     }
  1355.     return rc;
  1356. }                               /* _ipAddressTable_undo_column */
  1357. int
  1358. _mfd_ipAddressTable_undo_values(netsnmp_mib_handler *handler,
  1359.                                 netsnmp_handler_registration *reginfo,
  1360.                                 netsnmp_agent_request_info *agtreq_info,
  1361.                                 netsnmp_request_info *requests)
  1362. {
  1363.     int             rc;
  1364.     ipAddressTable_rowreq_ctx *rowreq_ctx =
  1365.         netsnmp_container_table_row_extract(requests);
  1366.     netsnmp_table_request_info *tri;
  1367.     DEBUGMSGTL(("internal:ipAddressTable:_mfd_ipAddressTable_undo_values",
  1368.                 "calledn"));
  1369.     netsnmp_assert(NULL != rowreq_ctx);
  1370.     for (; requests; requests = requests->next) {
  1371.         /*
  1372.          * set column data
  1373.          */
  1374.         tri = netsnmp_extract_table_info(requests);
  1375.         if (NULL == tri)
  1376.             continue;
  1377.         rc = _ipAddressTable_undo_column(rowreq_ctx, requests->requestvb,
  1378.                                          tri->colnum);
  1379.         if (MFD_SUCCESS != rc) {
  1380.             /*
  1381.              * nothing we can do about it but log it
  1382.              */
  1383.             DEBUGMSGTL(("verbose:ipAddressTable:mfd", "error %d from "
  1384.                         "ipAddressTable_undo_columnn", rc));
  1385.         }
  1386.     }                           /* for results */
  1387.     return SNMP_ERR_NOERROR;
  1388. }                               /* _mfd_ipAddressTable_undo_values */
  1389. /***********************************************************************
  1390.  *
  1391.  * DATA ACCESS
  1392.  *
  1393.  ***********************************************************************/
  1394. /**
  1395.  * @internal
  1396.  */
  1397. static int
  1398. _cache_load(netsnmp_cache * cache, void *vmagic)
  1399. {
  1400.     DEBUGMSGTL(("internal:ipAddressTable:_cache_load", "calledn"));
  1401.     if ((NULL == cache) || (NULL == cache->magic)) {
  1402.         snmp_log(LOG_ERR, "invalid cache for ipAddressTable_cache_loadn");
  1403.         return -1;
  1404.     }
  1405.     /** should only be called for an invalid or expired cache */
  1406.     netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
  1407.     /*
  1408.      * call user code
  1409.      */
  1410.     return ipAddressTable_cache_load((netsnmp_container *) cache->magic);
  1411. }                               /* _cache_load */
  1412. /**
  1413.  * @internal
  1414.  */
  1415. static void
  1416. _cache_item_free(ipAddressTable_rowreq_ctx * rowreq_ctx, void *context)
  1417. {
  1418.     DEBUGMSGTL(("internal:ipAddressTable:_cache_item_free", "calledn"));
  1419.     if (NULL == rowreq_ctx)
  1420.         return;
  1421.     ipAddressTable_release_rowreq_ctx(rowreq_ctx);
  1422. }                               /* _cache_item_free */
  1423. /**
  1424.  * @internal
  1425.  */
  1426. static void
  1427. _cache_free(netsnmp_cache * cache, void *magic)
  1428. {
  1429.     netsnmp_container *container;
  1430.     DEBUGMSGTL(("internal:ipAddressTable:_cache_free", "calledn"));
  1431.     if ((NULL == cache) || (NULL == cache->magic)) {
  1432.         snmp_log(LOG_ERR, "invalid cache in ipAddressTable_cache_freen");
  1433.         return;
  1434.     }
  1435.     container = (netsnmp_container *) cache->magic;
  1436.     /*
  1437.      * call user code
  1438.      */
  1439.     ipAddressTable_cache_free(container);
  1440.     /*
  1441.      * free all items. inefficient, but easy.
  1442.      */
  1443.     CONTAINER_CLEAR(container,
  1444.                     (netsnmp_container_obj_func *) _cache_item_free, NULL);
  1445. }                               /* _cache_free */
  1446. /**
  1447.  * @internal
  1448.  * initialize the iterator container with functions or wrappers
  1449.  */
  1450. void
  1451. _ipAddressTable_container_init(ipAddressTable_interface_ctx * if_ctx)
  1452. {
  1453.     DEBUGMSGTL(("internal:ipAddressTable:_ipAddressTable_container_init",
  1454.                 "calledn"));
  1455.     /*
  1456.      * set up the cache
  1457.      */
  1458.     if_ctx->cache = netsnmp_cache_create(30,    /* timeout in seconds */
  1459.                                          _cache_load, _cache_free,
  1460.                                          ipAddressTable_oid,
  1461.                                          ipAddressTable_oid_size);
  1462.     if (NULL == if_ctx->cache) {
  1463.         snmp_log(LOG_ERR, "error creating cache for ipAddressTablen");
  1464.         return;
  1465.     }
  1466.     if_ctx->cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
  1467.     ipAddressTable_container_init(&if_ctx->container, if_ctx->cache);
  1468.     if (NULL == if_ctx->container)
  1469.         if_ctx->container =
  1470.             netsnmp_container_find("ipAddressTable:table_container");
  1471.     if (NULL == if_ctx->container) {
  1472.         snmp_log(LOG_ERR, "error creating container in "
  1473.                  "ipAddressTable_container_initn");
  1474.         return;
  1475.     }
  1476.     if_ctx->cache->magic = (void *) if_ctx->container;
  1477. }                               /* _ipAddressTable_container_init */