On Sun, Nov 21, 2021 at 11:18:29AM +0100, [email protected] wrote:
> >Synopsis: session uptime is wrong
> >Category: system
> >Environment:
> System : OpenBSD 7.0
> Details : OpenBSD 7.0 (GENERIC.MP) #698: Thu Sep 30 21:07:33 MDT
> 2021
>
> [email protected]:/usr/src/sys/arch/octeon/compile/GENERIC.MP
>
> Architecture: OpenBSD.octeon
> Machine : octeon
> >Description:
> On a router (octeon with no RTC) the uptime looks like so:
>
> 11:12AM up 2 days, 15:56, 1 user, load averages: 0.01, 0.03, 0.01
>
> The pppoe(4) interface however displays 51 days uptime for a session:
>
>
> pppoe0: flags=8851<UP,POINTOPOINT,RUNNING,SIMPLEX,MULTICAST> mtu 1500
> description: Telekom
> index 7 priority 0 llprio 3
> dev: vlan7 state: session
> sid: 0x3f2f PADI retries: 1 PADR retries: 0 time: 51d 08:03:55
> <cut>
Same here on an edgerouter 4; already seen on tech@ in my reply to
bket's "Print learned DNS from sppp(4) in ifconfig(8)" where the
freshly rebooted box shows a session of 19 days in ifconfig output.
> I reason that my router rebooted (which it did two days ago) and
> used microuptime() to fill the session time, and then NTP updated
> the time and we have this timejump. What should be done is the
> uptime in seconds should be gotten and the ifconfig code that does
> the ioctl(2) does the appropriate math.
I can't test/reboot my box at the moment, but this minimal diff should
fix it. One could also rename the variables and polish further, but
I focus on the fix alone until I can test myself.
Index: sys/net/if_pppoe.c
===================================================================
RCS file: /cvs/src/sys/net/if_pppoe.c,v
retrieving revision 1.78
diff -u -p -r1.78 if_pppoe.c
--- sys/net/if_pppoe.c 19 Jul 2021 19:00:58 -0000 1.78
+++ sys/net/if_pppoe.c 21 Nov 2021 23:50:45 -0000
@@ -586,7 +586,7 @@ breakbreak:
PPPOEDEBUG(("%s: session 0x%x connected\n",
sc->sc_sppp.pp_if.if_xname, session));
sc->sc_state = PPPOE_STATE_SESSION;
- microtime(&sc->sc_session_time);
+ getmicrouptime(&sc->sc_session_time);
sc->sc_sppp.pp_up(&sc->sc_sppp); /* notify upper layers
*/
break;
Index: sbin/ifconfig/ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.450
diff -u -p -r1.450 ifconfig.c
--- sbin/ifconfig/ifconfig.c 17 Nov 2021 18:00:24 -0000 1.450
+++ sbin/ifconfig/ifconfig.c 22 Nov 2021 00:25:04 -0000
@@ -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');
}