Commit 3a82aacf authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: bugfix 1164, replace time() with monotinic version from libwr

It was possible that SNMP objects in expert branch don't update.
It pop-up in following scenario:
1. slave switch is started with no ntp configured
2. read via snmp from slave
3. master switch is started with no ntp configured
4. slave sync to master and set it's time, by this system clock on slave is set
   to earlier date
5. read via snmp from slave will end up in the same results in expert branch of
   the MIB.

Our part of SNMP implementation used "time" function for calculating SNMP's
cache timeouts. When clock is set backwards then cache can be valid for very
long time.

Monotonic clock is used instead from ulit.c (libwr)

Add util.c to the compilation.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 05f51137
......@@ -29,6 +29,7 @@ SOURCES = \
dot-config.c \
snmp_shmem.c \
snmp_mmap.c \
util.c \
wrsScalar.c \
wrsGeneralStatusGroup.c \
wrsOSStatusGroup.c \
......
../libwr/util.c
\ No newline at end of file
......@@ -518,7 +518,7 @@ time_t wrsBootStatus_data_fill(void)
{
static time_t time_update;
time_t time_cur;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSBOOTSTATUS_CACHE_TIMEOUT) {
......
......@@ -17,7 +17,7 @@ time_t wrsCpuLoad_data_fill(void)
struct sysinfo info;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSCPULOAD_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -27,7 +27,7 @@ time_t wrsCurrentTime_data_fill(void)
struct tm tm;
uint64_t wrs_d_current_64;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSCURRENTTIME_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -44,7 +44,7 @@ time_t wrsDiskTable_data_fill(unsigned int *ret_n_rows)
if (ret_n_rows)
*ret_n_rows = n_rows;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSDISKTABLE_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -231,7 +231,7 @@ time_t wrsGeneralStatus_data_fill(void)
WRS_MAIN_SYSTEM_STATUS_BUG;
}
time_update = time(NULL);
time_update = get_monotonic_sec();
/* there was an update, return current time */
return time_update;
......
......@@ -29,7 +29,7 @@ time_t wrsMemory_data_fill(void)
int ret = 0;
char key[41]; /* 1 for null char */
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSMEMORY_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -202,7 +202,7 @@ time_t wrsNetworkingStatus_data_fill(void)
/* cache not updated, return last update time */
return time_update;
}
time_update = time(NULL);
time_update = get_monotonic_sec();
if (run_once) {
run_once = 0;
......
......@@ -60,7 +60,7 @@ time_t wrsOSStatus_data_fill(void)
/* cache not updated, return last update time */
return time_update;
}
time_update = time(NULL);
time_update = get_monotonic_sec();
memset(&wrsOSStatus_s, 0, sizeof(wrsOSStatus_s));
/*********************************************************************\
......
......@@ -36,7 +36,7 @@ time_t wrsPortStatusTable_data_fill(unsigned int *n_rows)
if (n_rows)
*n_rows = n_rows_local;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSPORTSTATUSTABLE_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -64,7 +64,7 @@ wrsPstatsTable_data_fill(unsigned int *n_rows)
if (n_rows)
*n_rows = WRS_N_PORTS;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSPSTATSTABLE_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -52,7 +52,7 @@ time_t wrsPtpDataTable_data_fill(unsigned int *n_rows)
if (n_rows)
*n_rows = n_rows_local;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSPTPDATATABLE_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -4,6 +4,7 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "libwr/util.h"
/* Crap! -- everybody makes them different, and even ppsi::ieee wants them */
#undef FALSE
......
......@@ -27,7 +27,7 @@ time_t wrsSpllStatus_data_fill(void)
static time_t time_update;
time_t time_cur;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSSPLLSTATUS_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -34,7 +34,7 @@ time_t wrsSpllVersion_data_fill(void)
static time_t time_update;
time_t time_cur;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSSPLLVERSION_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -42,7 +42,7 @@ time_t wrsStartCnt_data_fill(void){
time_t time_cur;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSSTARTCNT_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -42,7 +42,7 @@ time_t wrsTemperature_data_fill(void)
time_t time_cur;
static int first_run = 1;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
if (time_update
&& time_cur - time_update < WRSTEMPERATURE_CACHE_TIMEOUT) {
/* cache not updated, return last update time */
......
......@@ -73,7 +73,7 @@ time_t wrsTimingStatus_data_fill(void)
get_wrsPTPFramesFlowing(port_status_nrows);
}
time_update = time(NULL);
time_update = get_monotonic_sec();
/* there was an update, return current time */
return time_update;
}
......
......@@ -82,7 +82,7 @@ time_t wrsVersion_data_fill(void)
static int run_once = 0;
time_t time_cur;
time_cur = time(NULL);
time_cur = get_monotonic_sec();
/* assume that version does not change in runtime */
if (run_once) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment