diff options
author | Chris Kuethe <ckuethe@cvs.openbsd.org> | 2009-06-02 21:17:36 +0000 |
---|---|---|
committer | Chris Kuethe <ckuethe@cvs.openbsd.org> | 2009-06-02 21:17:36 +0000 |
commit | 1826a3bf3b1afe9a2b45229acfa3271d148b26f0 (patch) | |
tree | 572e8a360bf44f8e63c8ad149ba54045821aa75f /sys | |
parent | 4823ff131830ffb9efb1bdbe1421c3ec3d44b5bc (diff) |
Add some extra protection against non-monotonic timestamps. ok stevesk
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/tty_endrun.c | 12 | ||||
-rw-r--r-- | sys/kern/tty_msts.c | 13 | ||||
-rw-r--r-- | sys/kern/tty_nmea.c | 12 |
3 files changed, 25 insertions, 12 deletions
diff --git a/sys/kern/tty_endrun.c b/sys/kern/tty_endrun.c index 202b56b4cf2..d60cdcc9899 100644 --- a/sys/kern/tty_endrun.c +++ b/sys/kern/tty_endrun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_endrun.c,v 1.1 2009/05/06 18:21:23 stevesk Exp $ */ +/* $OpenBSD: tty_endrun.c,v 1.2 2009/06/02 21:17:35 ckuethe Exp $ */ /* * Copyright (c) 2008 Marc Balmer <mbalmer@openbsd.org> @@ -210,7 +210,7 @@ endruninput(int c, struct tty *tp) np->ts.tv_sec = ts.tv_sec; np->ts.tv_nsec = ts.tv_nsec; np->gap = gap; - + /* * If a tty timestamp is available, make sure its value is * reasonable by comparing against the timestamp just taken. @@ -286,6 +286,7 @@ endrun_decode(struct endrun *np, struct tty *tp, char *fld[], int fldcnt) { int64_t date_nano, time_nano, offset_nano, endrun_now; char tfom; + int jumped = 0; if (fldcnt != NUMFLDS) { DPRINTF(("endrun: field count mismatch, %d\n", fldcnt)); @@ -312,7 +313,7 @@ endrun_decode(struct endrun *np, struct tty *tp, char *fld[], int fldcnt) DPRINTF(("endrun: time not monotonically increasing " "last %lld now %lld\n", (long long)np->last, (long long)endrun_now)); - return; + jumped = 1; } np->last = endrun_now; np->gap = 0LL; @@ -350,7 +351,6 @@ endrun_decode(struct endrun *np, struct tty *tp, char *fld[], int fldcnt) case '8': np->time.status = SENSOR_S_OK; np->signal.status = SENSOR_S_OK; - timeout_add_sec(&np->endrun_tout, TRUSTTIME); break; case '9': np->signal.status = SENSOR_S_WARN; @@ -368,6 +368,10 @@ endrun_decode(struct endrun *np, struct tty *tp, char *fld[], int fldcnt) np->tfom = tfom; } #endif + if (jumped) + np->time.status = SENSOR_S_WARN; + if (np->time.status == SENSOR_S_OK) + timeout_add_sec(&np->endrun_tout, TRUSTTIME); /* * If tty timestamping is requested, but no PPS signal is present, set diff --git a/sys/kern/tty_msts.c b/sys/kern/tty_msts.c index c00c94babd7..90495b6b55d 100644 --- a/sys/kern/tty_msts.c +++ b/sys/kern/tty_msts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_msts.c,v 1.14 2009/05/06 16:05:20 stevesk Exp $ */ +/* $OpenBSD: tty_msts.c,v 1.15 2009/06/02 21:17:35 ckuethe Exp $ */ /* * Copyright (c) 2008 Marc Balmer <mbalmer@openbsd.org> @@ -169,7 +169,7 @@ mstsinput(int c, struct tty *tp) np->ts.tv_sec = ts.tv_sec; np->ts.tv_nsec = ts.tv_nsec; np->gap = gap; - + /* * If a tty timestamp is available, make sure its value is * reasonable by comparing against the timestamp just taken. @@ -243,6 +243,7 @@ void msts_decode(struct msts *np, struct tty *tp, char *fld[], int fldcnt) { int64_t date_nano, time_nano, msts_now; + int jumped = 0; if (fldcnt != MAXFLDS) { DPRINTF(("msts: field count mismatch, %d\n", fldcnt)); @@ -263,7 +264,7 @@ msts_decode(struct msts *np, struct tty *tp, char *fld[], int fldcnt) msts_now = msts_now - 2 * 3600 * 1000000000LL; if (msts_now <= np->last) { DPRINTF(("msts: time not monotonically increasing\n")); - return; + jumped = 1; } np->last = msts_now; np->gap = 0LL; @@ -293,10 +294,14 @@ msts_decode(struct msts *np, struct tty *tp, char *fld[], int fldcnt) if (fld[3][0] == ' ' && fld[3][1] == ' ') { np->time.status = SENSOR_S_OK; np->signal.status = SENSOR_S_OK; - timeout_add_sec(&np->msts_tout, TRUSTTIME); } else np->signal.status = SENSOR_S_WARN; + if (jumped) + np->time.status = SENSOR_S_WARN; + if (np->time.status == SENSOR_S_OK) + timeout_add_sec(&np->msts_tout, TRUSTTIME); + /* * If tty timestamping is requested, but no PPS signal is present, set * the sensor state to CRITICAL. diff --git a/sys/kern/tty_nmea.c b/sys/kern/tty_nmea.c index 12889644e20..4fe88347f5b 100644 --- a/sys/kern/tty_nmea.c +++ b/sys/kern/tty_nmea.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty_nmea.c,v 1.34 2009/04/26 02:25:36 cnst Exp $ */ +/* $OpenBSD: tty_nmea.c,v 1.35 2009/06/02 21:17:35 ckuethe Exp $ */ /* * Copyright (c) 2006, 2007, 2008 Marc Balmer <mbalmer@openbsd.org> @@ -178,7 +178,7 @@ nmeainput(int c, struct tty *tp) } #endif np->gap = gap; - + /* * If a tty timestamp is available, make sure its value is * reasonable by comparing against the timestamp just taken. @@ -284,6 +284,7 @@ void nmea_gprmc(struct nmea *np, struct tty *tp, char *fld[], int fldcnt) { int64_t date_nano, time_nano, nmea_now; + int jumped = 0; if (fldcnt != 12 && fldcnt != 13) { DPRINTF(("gprmc: field count mismatch, %d\n", fldcnt)); @@ -300,7 +301,7 @@ nmea_gprmc(struct nmea *np, struct tty *tp, char *fld[], int fldcnt) nmea_now = date_nano + time_nano; if (nmea_now <= np->last) { DPRINTF(("gprmc: time not monotonically increasing\n")); - return; + jumped = 1; } np->last = nmea_now; np->gap = 0LL; @@ -363,7 +364,6 @@ nmea_gprmc(struct nmea *np, struct tty *tp, char *fld[], int fldcnt) case 'A': /* The GPS has a fix, (re)arm the timeout. */ np->time.status = SENSOR_S_OK; np->signal.status = SENSOR_S_OK; - timeout_add_sec(&np->nmea_tout, TRUSTTIME); break; case 'V': /* * The GPS indicates a warning status, do not add to @@ -375,6 +375,10 @@ nmea_gprmc(struct nmea *np, struct tty *tp, char *fld[], int fldcnt) break; } + if (jumped) + np->time.status = SENSOR_S_WARN; + if (np->time.status == SENSOR_S_OK) + timeout_add_sec(&np->nmea_tout, TRUSTTIME); /* * If tty timestamping is requested, but no PPS signal is present, set * the sensor state to CRITICAL. |