Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.24
go-version: 1.25
- run: sudo apt-get install libpcap-dev
- uses: golangci/golangci-lint-action@v3
- uses: golangci/golangci-lint-action@v9
- run: |
go get -v -u github.com/u-root/u-root/tools/checklicenses
go run github.com/u-root/u-root/tools/checklicenses -c .github/workflows/config.json
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.24
go-version: 1.25
- run: sudo apt-get install libpcap-dev libcap2-bin
- run: go build -v ./...
# fuzzing, need to specify each package separately
Expand Down
60 changes: 38 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
version: "2"
linters:
# extra linters to enable with default set:
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- revive # replacement of golint
- asciicheck # code does not contain non-ASCII identifiers
- contextcheck # check when function use a non-inherited context
- errorlint # error wrapping
- gofmt # formatting
- misspell # commonly misspelled English words in comments
- prealloc # slice declarations that could potentially be pre-allocated
- nilerr # code that returns nil even if it checks that the error is not nil
- predeclared # code that shadows one of Go's predeclared identifiers
- reassign # package variables are not reassigned
- unconvert # unnecessary type conversions
- unparam # unused function parameters
- usestdlibvars # possibility to use variables/constants from the Go standard library
- whitespace # leading and trailing whitespace
issues:
exclude-rules:
# not worth it
- path: _test\.go
linters:
- revive
- asciicheck
- contextcheck
- errorlint
- misspell
- nilerr
- prealloc
- predeclared
- reassign
- revive
- unconvert
- unparam
- usestdlibvars
- whitespace
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- revive
path: _test\.go
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ actions:
- "bash -c \"curl -s https://src.fedoraproject.org/rpms/facebook-time/raw/main/f/facebook-time.spec | sed -e '/^Patch[0-9]/d' -e 's|^%global commit.*|%global commit '$(git rev-parse HEAD)'|' -e 's|^%global date.*|%global date '$(date +%Y%m%d)'|' -e 's|mv fbclock-bin %{gobuilddir}/bin/fbclock-bin|mkdir -p %{gobuilddir}/bin \\&\\& mv fbclock-bin %{gobuilddir}/bin/fbclock-bin|' > facebook-time.spec\""
- "curl -s -o go-vendor-tools.toml https://src.fedoraproject.org/rpms/facebook-time/raw/main/f/go-vendor-tools.toml"
create-archive:
- "spectool -g facebook-time.spec"
- "bash -c 'git archive --format=tar.gz --prefix=time-$(git rev-parse HEAD)/ HEAD -o time-$(git rev-parse HEAD).tar.gz'"
- "go_vendor_archive create facebook-time.spec"
- "bash -c 'echo time-$(git rev-parse HEAD).tar.gz'"

Expand Down
2 changes: 1 addition & 1 deletion clock/clock_64bit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !386
//go:build linux && !386

/*
Copyright (c) Facebook, Inc. and its affiliates.
Expand Down
34 changes: 34 additions & 0 deletions clock/clock_64bit_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//go:build darwin && !386

/*
Copyright (c) Facebook, Inc. and its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clock

import (
"time"

"github.com/facebook/time/phc/unix"
)

func setFreq(tx *unix.Timex, freqPPB float64) {
tx.Freq = int64(freqPPB * PPBToTimexPPM)
}

func setTime(tx *unix.Timex, sec, usec time.Duration) {
tx.Time.Sec = int64(sec)
tx.Time.Usec = int32(usec)
}
61 changes: 61 additions & 0 deletions clock/clock_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright (c) Facebook, Inc. and its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package clock

import (
"testing"
"time"

"github.com/facebook/time/phc/unix"
"github.com/stretchr/testify/require"
)

func TestSetTime(t *testing.T) {
tx := &unix.Timex{}
setTime(tx, 5*time.Second, 123*time.Nanosecond)
require.Equal(t, int64(5*time.Second), tx.Time.Sec)
require.Equal(t, int64(123*time.Nanosecond), tx.Time.Usec)
}

func TestSetTimeNegative(t *testing.T) {
tx := &unix.Timex{}
setTime(tx, -1*time.Second, -500*time.Nanosecond)
require.Equal(t, int64(-1*time.Second), tx.Time.Sec)
require.Equal(t, int64(-500*time.Nanosecond), tx.Time.Usec)
}

func TestFrequencyPPB(t *testing.T) {
tx := &unix.Timex{}
wantState, err := unix.Adjtimex(tx)
require.NoError(t, err)

freqPPB, state, err := FrequencyPPB(0)
require.NoError(t, err)
require.Equal(t, wantState, state)
require.Equal(t, float64(tx.Freq)/PPBToTimexPPM, freqPPB)
}

func TestMaxFreqPPB(t *testing.T) {
tx := &unix.Timex{}
wantState, err := unix.Adjtimex(tx)
require.NoError(t, err)

maxFreq, state, err := MaxFreqPPB(0)
require.NoError(t, err)
require.Equal(t, wantState, state)
require.Equal(t, 500000.0, maxFreq)
}
39 changes: 1 addition & 38 deletions clock/clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ package clock

import (
"testing"
"time"

"github.com/facebook/time/phc/unix"
"github.com/stretchr/testify/require"
"golang.org/x/sys/unix"
)

func TestSetFreq(t *testing.T) {
Expand All @@ -36,42 +35,6 @@ func TestSetFreq(t *testing.T) {
require.Equal(t, int64(0), tx.Freq)
}

func TestSetTime(t *testing.T) {
tx := &unix.Timex{}
setTime(tx, 5*time.Second, 123*time.Nanosecond)
require.Equal(t, int64(5*time.Second), tx.Time.Sec)
require.Equal(t, int64(123*time.Nanosecond), tx.Time.Usec)
}

func TestSetTimeNegative(t *testing.T) {
tx := &unix.Timex{}
setTime(tx, -1*time.Second, -500*time.Nanosecond)
require.Equal(t, int64(-1*time.Second), tx.Time.Sec)
require.Equal(t, int64(-500*time.Nanosecond), tx.Time.Usec)
}

func TestFrequencyPPB(t *testing.T) {
tx := &unix.Timex{}
wantState, err := unix.Adjtimex(tx)
require.NoError(t, err)

freqPPB, state, err := FrequencyPPB(0)
require.NoError(t, err)
require.Equal(t, wantState, state)
require.Equal(t, float64(tx.Freq)/PPBToTimexPPM, freqPPB)
}

func TestMaxFreqPPB(t *testing.T) {
tx := &unix.Timex{}
wantState, err := unix.Adjtimex(tx)
require.NoError(t, err)

maxFreq, state, err := MaxFreqPPB(0)
require.NoError(t, err)
require.Equal(t, wantState, state)
require.Equal(t, 500000.0, maxFreq)
}

func TestFrequencyPPBInvalidClock(t *testing.T) {
_, _, err := FrequencyPPB(-1)
require.Error(t, err)
Expand Down
8 changes: 4 additions & 4 deletions cmd/ntpcheck/checker/chrony.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (n *ChronyCheck) Run() (*NTPCheckResult, error) {
}
sourceData, ok := packet.(*chrony.ReplySourceData)
if !ok {
return nil, fmt.Errorf("Got wrong 'sourcedata' response %+v", packet)
return nil, fmt.Errorf("got wrong 'sourcedata' response %+v", packet)
}
// get ntpdata when using a unix socket
// Skip sources with unresolved addresses (IPADDR_ID family) as they don't have valid IPs
Expand All @@ -137,7 +137,7 @@ func (n *ChronyCheck) Run() (*NTPCheckResult, error) {
} else {
rpyNTPData2, ok := packet.(*chrony.ReplyNTPData2)
if !ok {
return nil, fmt.Errorf("Got wrong 'ntpdata' response %+v", packet)
return nil, fmt.Errorf("got wrong 'ntpdata' response %+v", packet)
}
ntpData = &rpyNTPData2.NTPData
}
Expand All @@ -153,7 +153,7 @@ func (n *ChronyCheck) Run() (*NTPCheckResult, error) {
}
ntpSourceName, ok = packet.(*chrony.ReplyNTPSourceName)
if !ok {
return nil, fmt.Errorf("Got wrong 'sourcename' response %+v", packet)
return nil, fmt.Errorf("got wrong 'sourcename' response %+v", packet)
}
}
peer, err := NewPeerFromChrony(sourceData, ntpData, ntpSourceName)
Expand Down Expand Up @@ -192,7 +192,7 @@ func (n *ChronyCheck) ServerStats() (*ServerStats, error) {
case *chrony.ReplyServerStats4:
serverStats = NewServerStatsFromChrony4(stats)
default:
return nil, fmt.Errorf("Got wrong 'serverstats' response %+v", packet)
return nil, fmt.Errorf("got wrong 'serverstats' response %+v", packet)
}
log.Debugf("ServerStats: %v", serverStats)
return serverStats, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/ntpcheck/checker/ntpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (n *NTPCheck) ServerStats() (*ServerStats, error) {
log.Debugf("Data string: '%s'", string(serverVars.Data))

if serverVars.HasError() || (len(serverVars.Data) <= 0) {
return nil, fmt.Errorf("Got bad 'server variables' response %+v", serverVars)
return nil, fmt.Errorf("got bad 'server variables' response %+v", serverVars)
}

serverStats, err := NewServerStatsFromNTP(serverVars)
Expand Down
6 changes: 3 additions & 3 deletions cmd/ntpcheck/checker/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ type Peer struct {
// sanityCheckPeerVars checks if we parsed enough info from NTPD response
func sanityCheckPeerVars(p *Peer) error {
if p == nil {
return errors.New("No peer")
return errors.New("no peer")
}
if p.Stratum == 0 {
return errors.New("Incomplete data, stratum 0 in peer variables")
return errors.New("incomplete data, stratum 0 in peer variables")
}
if p.PPoll == 0 || p.HPoll == 0 {
return errors.New("Incomplete data, poll 0 in peer variables")
return errors.New("incomplete data, poll 0 in peer variables")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/ntpcheck/checker/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ type SystemVariables struct {
// sanityCheckSysVars checks if we parsed enough info from NTPD response
func sanityCheckSysVars(sysVars *SystemVariables) error {
if sysVars == nil {
return errors.New("No system variables")
return errors.New("no system variables")
}
if sysVars.Stratum == 0 {
return errors.New("Incomplete data, stratum 0 in system variables")
return errors.New("incomplete data, stratum 0 in system variables")
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ntpcheck/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
// refID converts ip into ReFID format and prints it on stdout
func refID(ipStr string) error {
if ipStr == "" {
return fmt.Errorf("Error: no IP provided")
return fmt.Errorf("no IP provided")
}

ip := net.ParseIP(ipStr)
Expand Down
29 changes: 29 additions & 0 deletions cmd/ziffy/node/lookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright (c) Facebook, Inc. and its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package node

import (
"net"
)

func getLookUpName(ip string) string {
addr, err := net.LookupAddr(ip)
if err != nil || len(addr) == 0 {
return ip
}
return addr[0]
}
Loading
Loading