PERFORCE change 81915 for review
Victor Cruceru
soc-victor at FreeBSD.org
Fri Aug 12 21:55:16 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=81915
Change 81915 by soc-victor at soc-victor_82.76.158.176 on 2005/08/12 21:54:35
Added the first version of the SNMP instrumentation for the hrNetworkTable.
Affected files ...
.. //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII.c#2 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#18 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#6 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c#1 add
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#16 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#20 edit
Differences ...
==== //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII.c#2 (text+ko) ====
@@ -34,6 +34,9 @@
#include "mibII_oid.h"
#include <net/if_types.h>
+/*just a prototype below*/
+u_int
+mib2_getIfIndex(const char* dev_name);
/*****************************/
@@ -1564,3 +1567,19 @@
ifp->xnotify_data = NULL;
ifp->xnotify_mod = NULL;
}
+
+
+/*
+ * Get the MIB II ifIndex for the device with
+ * the name passed as argument (ie "rl0")
+ */
+u_int
+mib2_getIfIndex(const char* dev_name){
+ struct mibindexmap *map;
+
+ STAILQ_FOREACH(map, &mibindexmap_list, link)
+ if (strcmp(map->name, dev_name) == 0) {
+ return map->ifindex;
+ }
+ return 0;
+}
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#18 (text+ko) ====
@@ -35,7 +35,8 @@
hostres_device_tbl.c \
hostres_processor_tbl.c \
hostres_diskstorage_tbl.c \
- hostres_partition_tbl.c
+ hostres_partition_tbl.c \
+ hostres_network_tbl.c
WARNS?= 6
#Not having NDEBUG defined will enable assertions and a lot of output on stderr
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#6 (text+ko) ====
@@ -68,6 +68,9 @@
void
handleDiskStorage(int32_t ds_index, const char* disk_dev_name);
+struct hrDeviceTblEntry*
+hrDeviceTblEntry_find_by_name(const char *dev_name);
+
static
struct hrDiskStorageTblEntry*
hrDiskStorageEntry_create( const struct hrDeviceTblEntry* devEntry) {
@@ -195,7 +198,7 @@
}
-static
+
struct hrDeviceTblEntry*
hrDeviceTblEntry_find_by_name(const char *dev_name) {
struct deviceNameMapEntry *map;
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#16 (text+ko) ====
@@ -199,6 +199,10 @@
STAILQ_INIT(&hrState_g.partition_name_map);
TAILQ_INIT(&hrState_g.hr_partition_tbl);
+
+ /*data structures initialization for hrNetworkTable*/
+ TAILQ_INIT(&hrState_g.hr_network_tbl);
+
hrState_g.hr_storage_tick = 0;
hrState_g.hr_fs_tick = 0;
@@ -207,6 +211,7 @@
hrState_g.hr_processor_tick = 0;
hrState_g.hr_disk_storage_tick = 0;
hrState_g.hr_partition_tick = 0;
+ hrState_g.hr_network_tick = 0;
hrState_g.hrStorage_tbl_age = 0;
hrState_g.hrFS_tbl_age = 0;
@@ -214,6 +219,7 @@
hrState_g.hrDevice_tbl_age = 0;
hrState_g.hrDiskStorage_age = 0;
hrState_g.hrPartition_tbl_age = 0;
+ hrState_g.hrNetwork_tbl_age = 0;
init_hrStorage_tbl_v();
init_hrFS_tbl_v();
@@ -224,6 +230,7 @@
init_hrDiskStorage_tbl_v();
init_hrPartition_tbl_v();
+ init_hrNetwork_tbl_v();
if ((hrState_g.devd_sock = create_devd_socket()) < 0) {
HR_DPRINTF((stderr, "Failed to create the socket to devd pipe.\n"));
@@ -243,6 +250,8 @@
static
int hostres_fini(void)
{
+ /* here I free the resources used by this module*/
+
if (hrState_g.cpus_load_timer != NULL) {
timer_stop(hrState_g.cpus_load_timer);
hrState_g.cpus_load_timer = NULL;
@@ -257,7 +266,7 @@
close(hrState_g.devd_sock);
}
- /* here I free the resources used by this module*/
+
if( hrState_g.utmp_fp != (FILE*)NULL ) {
if( fclose(hrState_g.utmp_fp) != 0 ) {
syslog(LOG_ERR, "fclose failed: %m ");
@@ -291,6 +300,7 @@
fini_DiskStorage_tbl_v();
fini_hrDevice_tbl_v();
fini_hrPartition_tbl_v();
+ fini_hrNetwork_tbl_v();
hrState_g.hr_storage_tick = 0;
hrState_g.hr_fs_tick = 0;
@@ -299,6 +309,7 @@
hrState_g.hr_processor_tick = 0;
hrState_g.hr_disk_storage_tick = 0;
hrState_g.hr_partition_tick = 0;
+ hrState_g.hr_network_tick = 0;
hrState_g.hrStorage_tbl_age = 0;
hrState_g.hrFS_tbl_age = 0;
@@ -306,7 +317,8 @@
hrState_g.hrDevice_tbl_age = 0;
hrState_g.hrDiskStorage_age = 0;
hrState_g.hrPartition_tbl_age = 0;
-
+ hrState_g.hrNetwork_tbl_age = 0;
+
hrState_g.dev_root = NULL;
hrState_g.hrSWOSIndex = 0;
@@ -454,16 +466,6 @@
-int op_hrNetworkTable(struct snmp_context *ctx __unused,
- struct snmp_value *value __unused,
- u_int sub __unused,
- u_int iidx __unused,
- enum snmp_op curr_op __unused)
-{
- return (SNMP_ERR_NOSUCHNAME);
-}
-
-
int op_hrPrinterTable(struct snmp_context *ctx __unused,
struct snmp_value *value __unused,
u_int sub __unused,
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#20 (text+ko) ====
@@ -303,6 +303,17 @@
};
+struct hrNetworkTblEntry {
+ int32_t index;
+ int32_t ifIndex;
+ TAILQ_ENTRY(hrNetworkTblEntry) link;
+#define HR_NETWORK_FOUND 0x001
+ uint32_t flags;
+
+};
+TAILQ_HEAD(network_tbl, hrNetworkTblEntry);
+
+
/*
* This structure is used to hold a SNMP table entry
* for HOST-RESOURCES-MIB's hrDeviceTable
@@ -454,7 +465,17 @@
partition_tbl hr_partition_tbl; /*the head of the list with hrPatitionTable's entries */
uint32_t next_hrPartition_index; /*next int available for indexing the hrPartitionTable*/
time_t hrPartition_tbl_age;
- uint64_t hr_partition_tick; /*last (agent) tick when hrDeviceTable was updated */
+ uint64_t hr_partition_tick; /*last (agent) tick when hrDeviceTable was updated */
+
+ /*
+ * next items are used for hrNetworksTable
+ */
+
+ struct
+ network_tbl hr_network_tbl; /*the head of the list with hrNetworkTable's entries */
+ time_t hrNetwork_tbl_age;
+ uint64_t hr_network_tick; /*last (agent) tick when hrDeviceTable was updated */
+
};
@@ -664,5 +685,21 @@
*/
void fini_hrPartition_tbl_v(void);
+
+/*
+ * Init the things for hrNetworkTable
+ */
+void init_hrNetwork_tbl_v(void);
+
+/*
+ * Finalization routine for hrNetworkTable
+ * It destroys the lists and frees any allocated heap memory
+ */
+void fini_hrNetwork_tbl_v(void);
+
+#define HR_NETWORK_TBL_REFRESH 7
+
+void refresh_Network_tbl_v(void);
+
#endif /*__HOSTRES_SNMP_H_INCLUDED__ */
More information about the p4-projects
mailing list