From e012a3628baaf5c3786d41b18e78b42ac5dfbcf7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 31 May 2024 09:29:14 +0200 Subject: [PATCH] Renovate: Update module github.com/beevik/ntp to v1.4.3 (#104) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 +-- vendor/github.com/beevik/ntp/RELEASE_NOTES.md | 8 +++++ vendor/github.com/beevik/ntp/ntp.go | 36 +++++++++---------- vendor/modules.txt | 2 +- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 6d9a852..f482f73 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/sapcc/ntp_exporter go 1.22 require ( - github.com/beevik/ntp v1.4.2 + github.com/beevik/ntp v1.4.3 github.com/prometheus/client_golang v1.19.1 github.com/sapcc/go-api-declarations v1.11.2 github.com/sapcc/go-bits v0.0.0-20240530080859-f4579fb3a074 diff --git a/go.sum b/go.sum index 02dc8ec..f250c90 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/beevik/ntp v1.4.2 h1:cjYhZqczanf6br/ocViahE75ipj7CmKQAh7fSBaCNK4= -github.com/beevik/ntp v1.4.2/go.mod h1:zkATLTt8VUZuOfYX2KgOnir4yvtAxWbnUUA24umXFnc= +github.com/beevik/ntp v1.4.3 h1:PlbTvE5NNy4QHmA4Mg57n7mcFTmr1W1j3gcK7L1lqho= +github.com/beevik/ntp v1.4.3/go.mod h1:Unr8Zg+2dRn7d8bHFuehIMSvvUYssHMxW3Q5Nx4RW5Q= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/vendor/github.com/beevik/ntp/RELEASE_NOTES.md b/vendor/github.com/beevik/ntp/RELEASE_NOTES.md index f53ad47..f55458c 100644 --- a/vendor/github.com/beevik/ntp/RELEASE_NOTES.md +++ b/vendor/github.com/beevik/ntp/RELEASE_NOTES.md @@ -1,3 +1,11 @@ +Release v1.4.3 +============== + +**Fixes** + +* Fixed an overflow bug in the clock offset calculation introduced by + release v1.4.2. + Release v1.4.2 ============== diff --git a/vendor/github.com/beevik/ntp/ntp.go b/vendor/github.com/beevik/ntp/ntp.go index 8306ffa..197e19f 100644 --- a/vendor/github.com/beevik/ntp/ntp.go +++ b/vendor/github.com/beevik/ntp/ntp.go @@ -735,32 +735,32 @@ func generateResponse(h *header, recvTime ntpTime, authErr error) *Response { // dst = Destination Timestamp (client receive time) func rtt(org, rec, xmt, dst ntpTime) time.Duration { - // round trip delay time - // rtt = (dst-org) - (xmt-rec) - a := dst.Time().Sub(org.Time()) - b := xmt.Time().Sub(rec.Time()) + a := int64(dst - org) + b := int64(xmt - rec) rtt := a - b if rtt < 0 { rtt = 0 } - return rtt + return ntpTime(rtt).Duration() } func offset(org, rec, xmt, dst ntpTime) time.Duration { - // local clock offset - // offset = ((rec-org) + (xmt-dst)) / 2 - // The inputs are 64-bit unsigned ints. The output is a 63-bit signed int. - // Need to handle conversions with care. See: - // https://www.eecis.udel.edu/~mills/time.html - a := int64(rec) - int64(org) - b := int64(xmt) - int64(dst) - d := (a + b) / 2 - - if d > 0 { - return ntpTime(d).Duration() - } else { - return -ntpTime(-d).Duration() + // The inputs are 64-bit unsigned integer timestamps. These timestamps can + // "roll over" at the end of an NTP era, which occurs approximately every + // 136 years starting from the year 1900. To ensure an accurate offset + // calculation when an era boundary is crossed, we need to take care that + // the difference between two 64-bit timestamp values is accurately + // calculated even when they are in neighboring eras. + // + // See: https://www.eecis.udel.edu/~mills/y2k.html + + a := int64(rec - org) + b := int64(xmt - dst) + offset := a + (b-a)/2 + if offset < 0 { + return -ntpTime(-offset).Duration() } + return ntpTime(offset).Duration() } func minError(org, rec, xmt, dst ntpTime) time.Duration { diff --git a/vendor/modules.txt b/vendor/modules.txt index 1f5d7be..78b2ba8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/beevik/ntp v1.4.2 +# github.com/beevik/ntp v1.4.3 ## explicit; go 1.17 github.com/beevik/ntp # github.com/beorn7/perks v1.0.1