diff options
author | Klemens Nanni <kn@cvs.openbsd.org> | 2021-11-23 19:13:46 +0000 |
---|---|---|
committer | Klemens Nanni <kn@cvs.openbsd.org> | 2021-11-23 19:13:46 +0000 |
commit | 89641d993fe9c9b9e4e3a95876cecbf8bcfde4d2 (patch) | |
tree | a26c7a8a12c522a21495645bfb179f331d2cedab /sbin/ifconfig/ifconfig.c | |
parent | 6fe2284e1fb50b7276a6e4683c41c5151b62ca92 (diff) |
Use system uptime not UTC time to calculate PPPoE session duration
Systems without RTC are likely to boot with wrong time, but pppoe(4) used
microtime(9) anyway to remember when a new session began.
(In)adequately, ifconfig(8) used gettimeofday(2) and calculated the
difference between two absoloute dates to infer the PPPoE session duration.
This goes off the rails if the wall clock jumps in between, e.g. due to NTP
kicking in.
Use getmicrouptime(9) and clock_gettime(2)/CLOCK_BOOTTIME instead to rely
on the monotonically increasing system uptime instead to fix this.
Reported and tested by Peter J. Philipp <pjp AT delphinusdns DOT org> on
some octeon box without RTC.
I've seen this on a Edgerouter 4 as well (2m uptime, 19d session).
OK claudio
Diffstat (limited to 'sbin/ifconfig/ifconfig.c')
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index ae58b9e65c9..5f901401965 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.450 2021/11/17 18:00:24 bket Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.451 2021/11/23 19:13:45 kn Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -5362,12 +5362,13 @@ pppoe_status(void) printf(" PADR retries: %d", state.padr_retry_no); if (state.state == PPPOE_STATE_SESSION) { - struct timeval temp_time; + struct timespec temp_time; time_t diff_time, day = 0; unsigned int hour = 0, min = 0, sec = 0; if (state.session_time.tv_sec != 0) { - gettimeofday(&temp_time, NULL); + if (clock_gettime(CLOCK_BOOTTIME, &temp_time) == -1) + goto notime; diff_time = temp_time.tv_sec - state.session_time.tv_sec; @@ -5387,6 +5388,7 @@ pppoe_status(void) printf("%lldd ", (long long)day); printf("%02u:%02u:%02u", hour, min, sec); } +notime: putchar('\n'); } |