diff --git a/userspace/snmpd/Makefile b/userspace/snmpd/Makefile index f391dab23fa056e0bec3d8d86afce3436c41bbe3..1c8cd1c55b0ccaf9b2c74e8b1c31356449d32cce 100644 --- a/userspace/snmpd/Makefile +++ b/userspace/snmpd/Makefile @@ -26,6 +26,7 @@ CFLAGS += -DWRS_WITH_SNMP_HACKISH_LOG=0 SHLIB = wrsSnmp.so SOURCES = \ init.c \ + snmp_shmem.c \ wrsScalar.c \ wrsPstats.c \ wrsPpsi.c \ diff --git a/userspace/snmpd/init.c b/userspace/snmpd/init.c index 0819fc6da545d51b65f37363784fb6a9f83d6b4c..d66257b4883a8aa828290dea920da9f5d4dabf08 100644 --- a/userspace/snmpd/init.c +++ b/userspace/snmpd/init.c @@ -7,6 +7,7 @@ /* The sub-init functions */ #include "wrsSnmp.h" +#include "snmp_shmem.h" #include "wrsPtpDataTable.h" #include "wrsTemperature.h" #include "wrsOSStatus.h" @@ -16,6 +17,7 @@ FILE *wrs_logf; /* for the local-hack messages */ void init_wrsSnmp(void) { + init_shm(); init_wrsScalar(); init_wrsPstats(); init_wrsPpsi(); diff --git a/userspace/snmpd/snmp_shmem.c b/userspace/snmpd/snmp_shmem.c new file mode 100644 index 0000000000000000000000000000000000000000..98ff848c15205850433ac7dd19d56e5328c0b61a --- /dev/null +++ b/userspace/snmpd/snmp_shmem.c @@ -0,0 +1,69 @@ +#include "wrsSnmp.h" + + +struct wrs_shm_head *hal_head; +struct hal_shmem_header *hal_shmem; +struct hal_port_state *hal_ports; +int hal_nports_local; + +struct wrs_shm_head *ppsi_head; +static struct pp_globals *ppg; +struct wr_servo_state_t *ppsi_servo; + + + +void init_shm(void) +{ + hal_head = wrs_shm_get(wrs_shm_hal, "", WRS_SHM_READ); + if (!hal_head) { + snmp_log(LOG_ERR, "unable to open shm for HAL!\n"); + exit(-1); + } + /* check hal's shm version */ + if (hal_head->version != HAL_SHMEM_VERSION) { + snmp_log(LOG_ERR, "unknown hal's shm version %i " + "(known is %i)\n", hal_head->version, + HAL_SHMEM_VERSION); + exit(-1); + } + + hal_shmem = (void *)hal_head + hal_head->data_off; + /* Assume number of ports does not change in runtime */ + hal_nports_local = hal_shmem->nports; + if (hal_nports_local > WRS_N_PORTS) { + snmp_log(LOG_ERR, "Too many ports reported by HAL. " + "%d vs %d supported\n", + hal_nports_local, WRS_N_PORTS); + exit(-1); + } + /* Even after HAL restart, HAL will place structures at the same + * addresses. No need to re-dereference pointer at each read. */ + hal_ports = wrs_shm_follow(hal_head, hal_shmem->ports); + if (!hal_ports) { + snmp_log(LOG_ERR, "Unalbe to follow hal_ports pointer in HAL's" + " shmem"); + exit(-1); + } + + ppsi_head = wrs_shm_get(wrs_shm_ptp, "", WRS_SHM_READ); + if (!ppsi_head) { + snmp_log(LOG_ERR, "unable to open shm for PPSI!\n"); + exit(-1); + } + + /* check hal's shm version */ + if (ppsi_head->version != WRS_PPSI_SHMEM_VERSION) { + snmp_log(LOG_ERR, "unknown PPSI's shm version %i " + "(known is %i)\n", + ppsi_head->version, WRS_PPSI_SHMEM_VERSION); + exit(-1); + } + ppg = (void *)ppsi_head + ppsi_head->data_off; + + ppsi_servo = wrs_shm_follow(ppsi_head, ppg->global_ext_data); + if (!ppsi_servo) { + snmp_log(LOG_ERR, "Cannot follow ppsi_servo in shmem.\n"); + exit(-1); + } + +} diff --git a/userspace/snmpd/snmp_shmem.h b/userspace/snmpd/snmp_shmem.h new file mode 100644 index 0000000000000000000000000000000000000000..2ee526751176da94f773cc100e96c200e4737ead --- /dev/null +++ b/userspace/snmpd/snmp_shmem.h @@ -0,0 +1,6 @@ +#ifndef WRS_SNMP_SHMEM_H +#define WRS_SNMP_SHMEM_H + +void init_shm(); + +#endif /* WRS_SNMP_SHMEM_H */ diff --git a/userspace/snmpd/wrsPpsi.c b/userspace/snmpd/wrsPpsi.c index b018e9928c60f49e6773f13a2cfd2d725a5cf90f..63523539bcc715d50df3164f4305700073f5f529 100644 --- a/userspace/snmpd/wrsPpsi.c +++ b/userspace/snmpd/wrsPpsi.c @@ -241,62 +241,6 @@ static void wrs_get_temperatures(void) } } -void init_shm(void) -{ - hal_head = wrs_shm_get(wrs_shm_hal, "", WRS_SHM_READ); - if (!hal_head) { - snmp_log(LOG_ERR, "unable to open shm for HAL!\n"); - exit(-1); - } - /* check hal's shm version */ - if (hal_head->version != HAL_SHMEM_VERSION) { - snmp_log(LOG_ERR, "unknown hal's shm version %i " - "(known is %i)\n", hal_head->version, - HAL_SHMEM_VERSION); - exit(-1); - } - - hal_shmem = (void *)hal_head + hal_head->data_off; - /* Assume number of ports does not change in runtime */ - hal_nports_local = hal_shmem->nports; - if (hal_nports_local > WRS_N_PORTS) { - snmp_log(LOG_ERR, "Too many ports reported by HAL. " - "%d vs %d supported\n", - hal_nports_local, WRS_N_PORTS); - exit(-1); - } - /* Even after HAL restart, HAL will place structures at the same - * addresses. No need to re-dereference pointer at each read. */ - hal_ports = wrs_shm_follow(hal_head, hal_shmem->ports); - if (!hal_ports) { - snmp_log(LOG_ERR, "Unalbe to follow hal_ports pointer in HAL's" - " shmem"); - exit(-1); - } - - ppsi_head = wrs_shm_get(wrs_shm_ptp, "", WRS_SHM_READ); - if (!ppsi_head) { - snmp_log(LOG_ERR, "unable to open shm for PPSI!\n"); - exit(-1); - } - - /* check hal's shm version */ - if (ppsi_head->version != WRS_PPSI_SHMEM_VERSION) { - snmp_log(LOG_ERR, "wr_mon: unknown PPSI's shm version %i " - "(known is %i)\n", - ppsi_head->version, WRS_PPSI_SHMEM_VERSION); - exit(-1); - } - ppg = (void *)ppsi_head + ppsi_head->data_off; - - ppsi_servo = wrs_shm_follow(ppsi_head, ppg->global_ext_data); - if (!ppsi_servo) { - snmp_log(LOG_ERR, "Cannot follow ppsi_servo in shmem.\n"); - exit(-1); - } - -} - static void wrs_ppsi_get_per_port(void) { unsigned ii, i; @@ -602,8 +546,6 @@ init_wrsPpsi(void) netsnmp_iterator_info *iinfo; netsnmp_handler_registration *reginfo; - /* open shm */ - init_shm(); /* do the registration for the scalars/globals */ hreg = netsnmp_create_handler_registration(