PERFORCE change 81959 for review
Victor Cruceru
soc-victor at FreeBSD.org
Sat Aug 13 22:45:01 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=81959
Change 81959 by soc-victor at soc-victor_82.76.158.176 on 2005/08/13 22:44:57
The very first SNMP instrumentation for hrSWInstalledTable: for now only O/S
is instrumented, need to analyze the installed packages.
Also fixed a few things in other places.
Affected files ...
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#19 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c#3 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#9 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#18 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#22 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c#1 add
Differences ...
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#19 (text+ko) ====
@@ -36,7 +36,8 @@
hostres_processor_tbl.c \
hostres_diskstorage_tbl.c \
hostres_partition_tbl.c \
- hostres_network_tbl.c
+ hostres_network_tbl.c \
+ hostres_swinstalled_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_fs_tbl.c#5 (text+ko) ====
@@ -60,7 +60,7 @@
strncpy(entry->mountPoint, name, sizeof(entry->mountPoint)-1);
STAILQ_FOREACH(map, &hrState_g.fs_name_map, link)
- if (strcmp(map->a_name, entry->mountPoint) == 0) {
+ if (strncmp(map->a_name, entry->mountPoint, sizeof(map->a_name) - 1) == 0) {
entry->index = map->hrIndex;
map->entry_p = entry;
break;
@@ -120,7 +120,7 @@
struct hrFSTblEntry *entry = NULL;
TAILQ_FOREACH(entry, &hrState_g.hr_fs_tbl, link)
- if (strncmp(entry->mountPoint, name, 255) == 0)
+ if (strncmp(entry->mountPoint, name, sizeof(entry->mountPoint) - 1) == 0)
return (entry);
return (NULL);
}
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c#3 (text+ko) ====
@@ -273,6 +273,7 @@
if (ioctl(hrState_g.ifnet_sock, SIOCGIFCONF, (char *) &ifc) < 0) {
syslog(LOG_ERR,"failed to SIOCGIFCONF: %m");
close(hrState_g.ifnet_sock);
+ hrState_g.ifnet_sock = -1;
return;
}
@@ -374,7 +375,7 @@
}
-void refresh_Network_tbl_v(void) {
+void refresh_hrNetwork_tbl_v(void) {
struct hrNetworkTblEntry *entry = NULL, *entry_tmp = NULL;
if ( this_tick <= hrState_g.hr_network_tick) {
@@ -436,7 +437,7 @@
if ( (time(NULL) - hrState_g.hrNetwork_tbl_age) > HR_NETWORK_TBL_REFRESH ) {
HR_DPRINTF((stderr, "%s: need refresh\n ",__func__));
- refresh_Network_tbl_v();
+ refresh_hrNetwork_tbl_v();
}
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#9 (text+ko) ====
@@ -82,7 +82,7 @@
* Get kernel boot path. For FreeBSD it seems that no arguments are present.
* Returns NULL if an error occured. The returned data is a pointer to a global strorage
*/
-static
+
u_char* OS_getSystemInitialLoadParameters(void);
/*
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#18 (text+ko) ====
@@ -207,7 +207,14 @@
/*data structures initialization for hrNetworkTable*/
TAILQ_INIT(&hrState_g.hr_network_tbl);
-
+ /*data structures initialization for hrSWInstalledTable*/
+ hrState_g.next_hrSWInstalled_index = 1;
+ STAILQ_INIT(&hrState_g.sw_installed_name_map);
+ TAILQ_INIT(&hrState_g.hr_sw_installed_tbl);
+ hrState_g.hr_sw_installed_tick = 0;
+ hrState_g.hr_sw_installed_change_tick = 0;
+ hrState_g.hrSWInstalled_tbl_age = 0;
+
hrState_g.hr_storage_tick = 0;
hrState_g.hr_fs_tick = 0;
hrState_g.hr_swrun_tick = 0;
@@ -236,6 +243,8 @@
init_hrPartition_tbl_v();
init_hrNetwork_tbl_v();
+ init_hrSWInstalled_tbl_v();
+
if ((hrState_g.devd_sock = create_devd_socket()) < 0) {
HR_DPRINTF((stderr, "Failed to create the socket to devd pipe.\n"));
}
@@ -308,6 +317,7 @@
fini_hrDevice_tbl_v();
fini_hrPartition_tbl_v();
fini_hrNetwork_tbl_v();
+ fini_hrSWInstalled_tbl_v();
hrState_g.hr_storage_tick = 0;
hrState_g.hr_fs_tick = 0;
@@ -334,6 +344,11 @@
hrState_g.fscale = 0;
hrState_g.ccpu = 0;
+ hrState_g.hr_sw_installed_tick = 0;
+ hrState_g.hr_sw_installed_change_tick = 0;
+ hrState_g.hrSWInstalled_tbl_age = 0;
+
+
if (hrState_g.ata_fd > 0) {
if (close(hrState_g.ata_fd) < 0) {
syslog(LOG_ERR,"close (/dev/ata) failed: %m");
@@ -495,14 +510,6 @@
}
-int op_hrSWInstalledTable(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);
-}
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#22 (text+ko) ====
@@ -118,7 +118,7 @@
*/
struct hrFSTblEntry {
int32_t index;
- u_char mountPoint[128+11];
+ u_char mountPoint[128+1];
u_char remoteMountPoint[128+1];
struct asn_oid type;
int32_t access; /* enum hrFSAccess, see above */
@@ -142,7 +142,7 @@
*/
struct FSNameMapEntry {
int32_t hrIndex; /*used for hrFSTblEntry::index*/
- u_char a_name[128]; /*map key*/
+ u_char a_name[128+1]; /*map key*/
/*
* next may be NULL if the respective hrFSTblEntry
@@ -366,6 +366,48 @@
STAILQ_HEAD(device_map_list, deviceNameMapEntry);
+enum SWInstalledType {
+ SWI_UNKNOWN = 1,
+ SWI_OPERATING_SYSTEM = 2,
+ SWI_DEVICE_DRIVER = 3,
+ SWI_APPLICATION = 4
+};
+
+
+/*
+ * This structure is used to hold a SNMP table entry
+ * for HOST-RESOURCES-MIB's hrSWInstalledTable
+ */
+struct hrSWInstalledTblEntry {
+ int32_t index;
+ u_char name[64+1];
+ struct asn_oid id;
+ int32_t type; /* one item from enum SWInstalledType, see above */
+ u_char date[11];
+#define HR_SWINSTALLED_FOUND 0x001
+ /*next items are not from the SNMP mib table, only to be used internally*/
+ uint32_t flags;
+ TAILQ_ENTRY(hrSWInstalledTblEntry) link;
+};
+
+TAILQ_HEAD(sw_installed_tbl, hrSWInstalledTblEntry);
+
+
+struct SWInstalledNameMapEntry {
+ int32_t hrIndex; /*used for hrSWInstalledTblEntry::index*/
+ u_char name[64+1]; /*map key*/
+
+ /*
+ * next may be NULL if the respective hrSWInstalledTblEntry
+ * is (temporally) gone
+ */
+ struct
+ hrSWInstalledTblEntry *entry_p;
+ STAILQ_ENTRY(SWInstalledNameMapEntry) link;
+};
+
+STAILQ_HEAD(sw_installed_map_list, SWInstalledNameMapEntry);
+
struct hostres_state {
FILE *utmp_fp; /*file pointer to keep an open instance of utmp*/
kvm_t *kd; /*kernel descriptor*/
@@ -414,7 +456,7 @@
time_t hrSWRun_tbl_age;
uint64_t hr_swrun_tick; /*last (agent) tick when hrSWRunTable and hrSWRunPerTable
were updated */
- int32_t hrSWOSIndex; /* the value of the MIB objecy with the same name*/
+ int32_t hrSWOSIndex; /* the value of the MIB object with the same name*/
/*
* next items are used for hrDeviceTable
@@ -480,8 +522,20 @@
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 */
+
+ /*
+ * next items are used for hrSWInstalledTable
+ */
+ struct
+ sw_installed_map_list sw_installed_name_map; /*for consistent table indexing*/
+ struct
+ sw_installed_tbl hr_sw_installed_tbl; /*the head of the list with hrSWInstalledTable's entries */
+ uint32_t next_hrSWInstalled_index; /*next int available for indexing the hrSWInstalledTable*/
+ uint64_t hr_sw_installed_tick; /*last (agent) tick when hrSWInstalledTable was fully updated */
+ uint64_t hr_sw_installed_change_tick; /*last (agent) tick when hrDeviceTable was last changed */
+ time_t hrSWInstalled_tbl_age;
};
@@ -704,7 +758,16 @@
#define HR_NETWORK_TBL_REFRESH 7
-void refresh_Network_tbl_v(void);
+void refresh_hrNetwork_tbl_v(void);
+
+
+void init_hrSWInstalled_tbl_v(void);
+
+void fini_hrSWInstalled_tbl_v(void);
+
+#define HR_SWINSTALLED_TBL_REFRESH 120
+
+void refresh_hrSWInstalled_tbl_v(void);
#endif /*__HOSTRES_SNMP_H_INCLUDED__ */
More information about the p4-projects
mailing list