net-snmp 5.7
|
00001 #include <net-snmp/net-snmp-config.h> 00002 #include <net-snmp/net-snmp-features.h> 00003 #include <net-snmp/net-snmp-includes.h> 00004 #include <net-snmp/agent/net-snmp-agent-includes.h> 00005 00006 #include <net-snmp/agent/snmp_get_statistic.h> 00007 00008 netsnmp_feature_provide(helper_statistics) 00009 netsnmp_feature_child_of(helper_statistics, mib_helpers) 00010 00011 #ifdef NETSNMP_FEATURE_REQUIRE_HELPER_STATISTICS 00012 /* if we're not needed, then neither is this */ 00013 netsnmp_feature_require(statistics) 00014 #endif 00015 00016 #ifndef NETSNMP_FEATURE_REMOVE_HELPER_STATISTICS 00017 static int 00018 netsnmp_get_statistic_helper_handler(netsnmp_mib_handler *handler, 00019 netsnmp_handler_registration *reginfo, 00020 netsnmp_agent_request_info *reqinfo, 00021 netsnmp_request_info *requests) 00022 { 00023 if (reqinfo->mode == MODE_GET) { 00024 const oid idx = requests->requestvb->name[reginfo->rootoid_len - 2] + 00025 (oid)(uintptr_t)handler->myvoid; 00026 uint32_t value; 00027 00028 if (idx > NETSNMP_STAT_MAX_STATS) 00029 return SNMP_ERR_GENERR; 00030 value = snmp_get_statistic(idx); 00031 snmp_set_var_typed_value(requests->requestvb, ASN_COUNTER, 00032 (const u_char*)&value, sizeof(value)); 00033 return SNMP_ERR_NOERROR; 00034 } 00035 return SNMP_ERR_GENERR; 00036 } 00037 00038 static netsnmp_mib_handler * 00039 netsnmp_get_statistic_handler(int offset) 00040 { 00041 netsnmp_mib_handler *ret = 00042 netsnmp_create_handler("get_statistic", 00043 netsnmp_get_statistic_helper_handler); 00044 if (ret) { 00045 ret->flags |= MIB_HANDLER_AUTO_NEXT; 00046 ret->myvoid = (void*)(uintptr_t)offset; 00047 } 00048 return ret; 00049 } 00050 00051 int 00052 netsnmp_register_statistic_handler(netsnmp_handler_registration *reginfo, 00053 oid start, int begin, int end) 00054 { 00055 netsnmp_inject_handler(reginfo, 00056 netsnmp_get_statistic_handler(begin - start)); 00057 return netsnmp_register_scalar_group(reginfo, start, start + (end - begin)); 00058 } 00059 #else /* !NETSNMP_FEATURE_REMOVE_HELPER_GET_STATISTICS */ 00060 netsnmp_feature_unused(helper_statistics); 00061 #endif