diff --git a/cmd/headscale/cli/policy.go b/cmd/headscale/cli/policy.go index 5b34a1e1c0..00c4566dd1 100644 --- a/cmd/headscale/cli/policy.go +++ b/cmd/headscale/cli/policy.go @@ -4,10 +4,9 @@ import ( "io" "os" + v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/rs/zerolog/log" "github.com/spf13/cobra" - - v1 "github.com/juanfont/headscale/gen/go/headscale/v1" ) func init() { diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index e4fef8074a..409e3dc43e 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -7,16 +7,15 @@ import ( "fmt" "os" + v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" "gopkg.in/yaml.v3" - - v1 "github.com/juanfont/headscale/gen/go/headscale/v1" - "github.com/juanfont/headscale/hscontrol" - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" ) const ( diff --git a/hscontrol/app.go b/hscontrol/app.go index fe025adcbe..b66e939b4d 100644 --- a/hscontrol/app.go +++ b/hscontrol/app.go @@ -23,6 +23,16 @@ import ( "github.com/gorilla/mux" grpcMiddleware "github.com/grpc-ecosystem/go-grpc-middleware" grpcRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/juanfont/headscale" + v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol/db" + "github.com/juanfont/headscale/hscontrol/derp" + derpServer "github.com/juanfont/headscale/hscontrol/derp/server" + "github.com/juanfont/headscale/hscontrol/mapper" + "github.com/juanfont/headscale/hscontrol/notifier" + "github.com/juanfont/headscale/hscontrol/policy" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" "github.com/patrickmn/go-cache" zerolog "github.com/philip-bui/grpc-zerolog" "github.com/pkg/profile" @@ -47,17 +57,6 @@ import ( "tailscale.com/types/dnstype" "tailscale.com/types/key" "tailscale.com/util/dnsname" - - "github.com/juanfont/headscale" - v1 "github.com/juanfont/headscale/gen/go/headscale/v1" - "github.com/juanfont/headscale/hscontrol/db" - "github.com/juanfont/headscale/hscontrol/derp" - derpServer "github.com/juanfont/headscale/hscontrol/derp/server" - "github.com/juanfont/headscale/hscontrol/mapper" - "github.com/juanfont/headscale/hscontrol/notifier" - "github.com/juanfont/headscale/hscontrol/policy" - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" ) var ( @@ -680,7 +679,7 @@ func (h *Headscale) Serve() error { Handler: router, ReadTimeout: types.HTTPTimeout, - // Long polling should not have any timeout, this is overriden + // Long polling should not have any timeout, this is overridden // further down the chain WriteTimeout: types.HTTPTimeout, } diff --git a/hscontrol/auth.go b/hscontrol/auth.go index 010d15a255..aaab03cebb 100644 --- a/hscontrol/auth.go +++ b/hscontrol/auth.go @@ -337,7 +337,6 @@ func (h *Headscale) handleAuthKey( if len(aclTags) > 0 { // This conditional preserves the existing behaviour, although SaaS would reset the tags on auth-key login err = h.db.SetTags(node.ID, aclTags) - if err != nil { log.Error(). Caller(). diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index b44d76ab6a..c190813433 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -13,13 +13,12 @@ import ( "github.com/glebarez/sqlite" "github.com/go-gormigrate/gormigrate/v2" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" "gorm.io/driver/postgres" "gorm.io/gorm" "gorm.io/gorm/logger" - - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" ) var errDatabaseNotSupported = errors.New("database type not supported") @@ -331,7 +330,7 @@ func NewHeadscaleDatabase( // IP v4 and v6 column. // Note that previously, the list _could_ contain more // than two addresses, which should not really happen. - // In that case, the first occurence of each type will + // In that case, the first occurrence of each type will // be kept. ID: "2024041121742", Migrate: func(tx *gorm.DB) error { diff --git a/hscontrol/db/ip.go b/hscontrol/db/ip.go index 7d06e2e89c..d0e030d6c5 100644 --- a/hscontrol/db/ip.go +++ b/hscontrol/db/ip.go @@ -76,7 +76,6 @@ func NewIPAllocator( if err != nil { return nil, fmt.Errorf("reading IPv6 addresses from database: %w", err) } - } var ips netipx.IPSetBuilder diff --git a/hscontrol/db/ip_test.go b/hscontrol/db/ip_test.go index c922fcdfdb..ce9c134c3b 100644 --- a/hscontrol/db/ip_test.go +++ b/hscontrol/db/ip_test.go @@ -18,9 +18,11 @@ var mpp = func(pref string) *netip.Prefix { p := netip.MustParsePrefix(pref) return &p } + var na = func(pref string) netip.Addr { return netip.MustParseAddr(pref) } + var nap = func(pref string) *netip.Addr { n := na(pref) return &n diff --git a/hscontrol/db/node_test.go b/hscontrol/db/node_test.go index d88d045833..065e70b77f 100644 --- a/hscontrol/db/node_test.go +++ b/hscontrol/db/node_test.go @@ -12,16 +12,15 @@ import ( "time" "github.com/google/go-cmp/cmp" + "github.com/juanfont/headscale/hscontrol/policy" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" "github.com/puzpuzpuz/xsync/v3" "github.com/stretchr/testify/assert" "gopkg.in/check.v1" "tailscale.com/tailcfg" "tailscale.com/types/key" "tailscale.com/types/ptr" - - "github.com/juanfont/headscale/hscontrol/policy" - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" ) func (s *Suite) TestGetNode(c *check.C) { diff --git a/hscontrol/db/policy.go b/hscontrol/db/policy.go index dcbdc8129f..49b419b575 100644 --- a/hscontrol/db/policy.go +++ b/hscontrol/db/policy.go @@ -1,12 +1,11 @@ package db import ( - "gorm.io/gorm" - "gorm.io/gorm/clause" - "errors" "github.com/juanfont/headscale/hscontrol/types" + "gorm.io/gorm" + "gorm.io/gorm/clause" ) // SetPolicy sets the policy in the database. diff --git a/hscontrol/db/routes.go b/hscontrol/db/routes.go index 3b89719084..fd837c291d 100644 --- a/hscontrol/db/routes.go +++ b/hscontrol/db/routes.go @@ -542,7 +542,6 @@ func failoverRoute( isLikelyConnected *xsync.MapOf[types.NodeID, bool], routeToReplace *types.Route, altRoutes types.Routes, - ) *failover { if routeToReplace == nil { return nil diff --git a/hscontrol/db/routes_test.go b/hscontrol/db/routes_test.go index 122a7ff376..2324a21b28 100644 --- a/hscontrol/db/routes_test.go +++ b/hscontrol/db/routes_test.go @@ -285,25 +285,30 @@ func (s *Suite) TestDeleteRoutes(c *check.C) { c.Assert(len(enabledRoutes1), check.Equals, 1) } -var ipp = func(s string) types.IPPrefix { return types.IPPrefix(netip.MustParsePrefix(s)) } -var n = func(nid types.NodeID) types.Node { - return types.Node{ID: nid} -} +var ( + ipp = func(s string) types.IPPrefix { return types.IPPrefix(netip.MustParsePrefix(s)) } + mkNode = func(nid types.NodeID) types.Node { + return types.Node{ID: nid} + } +) + var np = func(nid types.NodeID) *types.Node { - no := n(nid) + no := mkNode(nid) return &no } + var r = func(id uint, nid types.NodeID, prefix types.IPPrefix, enabled, primary bool) types.Route { return types.Route{ Model: gorm.Model{ ID: id, }, - Node: n(nid), + Node: mkNode(nid), Prefix: prefix, Enabled: enabled, IsPrimary: primary, } } + var rp = func(id uint, nid types.NodeID, prefix types.IPPrefix, enabled, primary bool) *types.Route { ro := r(id, nid, prefix, enabled, primary) return &ro diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index 73420419e0..702b7845e6 100644 --- a/hscontrol/mapper/mapper.go +++ b/hscontrol/mapper/mapper.go @@ -541,7 +541,6 @@ func appendPeerChanges( changed types.Nodes, cfg *types.Config, ) error { - packetFilter, err := pol.CompileFilterRules(append(peers, node)) if err != nil { return err diff --git a/hscontrol/metrics.go b/hscontrol/metrics.go index 835a6aac0a..4870e74e00 100644 --- a/hscontrol/metrics.go +++ b/hscontrol/metrics.go @@ -40,7 +40,7 @@ var ( mapResponseWriteUpdatesInStream = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: prometheusNamespace, Name: "mapresponse_write_updates_in_stream_total", - Help: "total count of writes that occured in a stream session, pre-68 nodes", + Help: "total count of writes that occurred in a stream session, pre-68 nodes", }, []string{"status"}) mapResponseEndpointUpdates = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: prometheusNamespace, diff --git a/hscontrol/notifier/notifier.go b/hscontrol/notifier/notifier.go index 483c3f3744..0b66377657 100644 --- a/hscontrol/notifier/notifier.go +++ b/hscontrol/notifier/notifier.go @@ -17,8 +17,10 @@ import ( "tailscale.com/util/set" ) -var debugDeadlock = envknob.Bool("HEADSCALE_DEBUG_DEADLOCK") -var debugDeadlockTimeout = envknob.RegisterDuration("HEADSCALE_DEBUG_DEADLOCK_TIMEOUT") +var ( + debugDeadlock = envknob.Bool("HEADSCALE_DEBUG_DEADLOCK") + debugDeadlockTimeout = envknob.RegisterDuration("HEADSCALE_DEBUG_DEADLOCK_TIMEOUT") +) func init() { deadlock.Opts.Disable = !debugDeadlock @@ -291,7 +293,6 @@ func newBatcher(batchTime time.Duration, n *Notifier) *batcher { patches: make(map[types.NodeID]tailcfg.PeerChange), n: n, } - } func (b *batcher) close() { @@ -393,7 +394,7 @@ func (b *batcher) doWork() { } // overwritePatch takes the current patch and a newer patch -// and override any field that has changed +// and override any field that has changed. func overwritePatch(currPatch, newPatch *tailcfg.PeerChange) { if newPatch.DERPRegion != 0 { currPatch.DERPRegion = newPatch.DERPRegion diff --git a/hscontrol/oidc.go b/hscontrol/oidc.go index bb836a06c2..fe4d357ce4 100644 --- a/hscontrol/oidc.go +++ b/hscontrol/oidc.go @@ -57,7 +57,6 @@ func (h *Headscale) initOIDC() error { // grab oidc config if it hasn't been already if h.oauth2Config == nil { h.oidcProvider, err = oidc.NewProvider(context.Background(), h.cfg.OIDC.Issuer) - if err != nil { return fmt.Errorf("creating OIDC provider from issuer config: %w", err) } diff --git a/hscontrol/policy/acls.go b/hscontrol/policy/acls.go index 64697e3320..2b3a50f7af 100644 --- a/hscontrol/policy/acls.go +++ b/hscontrol/policy/acls.go @@ -11,13 +11,12 @@ import ( "strings" "time" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" "github.com/tailscale/hujson" "go4.org/netipx" "tailscale.com/tailcfg" - - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" ) var ( diff --git a/hscontrol/policy/acls_test.go b/hscontrol/policy/acls_test.go index b3cc10f01a..6b2e0f9753 100644 --- a/hscontrol/policy/acls_test.go +++ b/hscontrol/policy/acls_test.go @@ -6,15 +6,14 @@ import ( "testing" "github.com/google/go-cmp/cmp" + "github.com/juanfont/headscale/hscontrol/types" + "github.com/juanfont/headscale/hscontrol/util" "github.com/rs/zerolog/log" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "go4.org/netipx" "gopkg.in/check.v1" "tailscale.com/tailcfg" - - "github.com/juanfont/headscale/hscontrol/types" - "github.com/juanfont/headscale/hscontrol/util" ) var iap = func(ipStr string) *netip.Addr { @@ -1783,7 +1782,7 @@ var tsExitNodeDest = []tailcfg.NetPortRange{ } // hsExitNodeDest is the list of destination IP ranges that are allowed when -// we use headscale "autogroup:internet" +// we use headscale "autogroup:internet". var hsExitNodeDest = []tailcfg.NetPortRange{ {IP: "0.0.0.0/5", Ports: tailcfg.PortRangeAny}, {IP: "8.0.0.0/7", Ports: tailcfg.PortRangeAny}, @@ -1840,7 +1839,7 @@ func TestTheInternet(t *testing.T) { internetPrefs := internetSet.Prefixes() - for i, _ := range internetPrefs { + for i := range internetPrefs { if internetPrefs[i].String() != hsExitNodeDest[i].IP { t.Errorf("prefix from internet set %q != hsExit list %q", internetPrefs[i].String(), hsExitNodeDest[i].IP) } diff --git a/hscontrol/policy/acls_types.go b/hscontrol/policy/acls_types.go index 25f02f16b5..5b5d183829 100644 --- a/hscontrol/policy/acls_types.go +++ b/hscontrol/policy/acls_types.go @@ -10,7 +10,7 @@ import ( // ACLPolicy represents a Tailscale ACL Policy. type ACLPolicy struct { - Groups Groups `json:"groups" ` + Groups Groups `json:"groups"` Hosts Hosts `json:"hosts"` TagOwners TagOwners `json:"tagOwners"` ACLs []ACL `json:"acls"` diff --git a/hscontrol/poll.go b/hscontrol/poll.go index 8122064b6d..b9bf65a240 100644 --- a/hscontrol/poll.go +++ b/hscontrol/poll.go @@ -184,7 +184,6 @@ func (m *mapSession) serve() { return } - } // serveLongPoll ensures the node gets the appropriate updates from either diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 2143d18265..0c077870fe 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -11,6 +11,7 @@ import ( "time" "github.com/coreos/go-oidc/v3/oidc" + "github.com/juanfont/headscale/hscontrol/util" "github.com/prometheus/common/model" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -19,8 +20,6 @@ import ( "tailscale.com/net/tsaddr" "tailscale.com/tailcfg" "tailscale.com/types/dnstype" - - "github.com/juanfont/headscale/hscontrol/util" ) const ( diff --git a/integration/cli_test.go b/integration/cli_test.go index 9bc67a8937..088db7869b 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -7,12 +7,11 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/juanfont/headscale/hscontrol/policy" "github.com/juanfont/headscale/integration/hsic" "github.com/juanfont/headscale/integration/tsic" + "github.com/stretchr/testify/assert" ) func executeAndUnmarshal[T any](headscale ControlServer, command []string, result T) error { @@ -481,7 +480,7 @@ func TestPreAuthKeyCorrectUserLoggedInCommand(t *testing.T) { assert.Nil(t, err) assert.Len(t, listNodes, 1) - assert.Equal(t, "user2", listNodes[0].User.Name) + assert.Equal(t, "user2", listNodes[0].GetUser().GetName()) } func TestApiKeyCommand(t *testing.T) { diff --git a/integration/control.go b/integration/control.go index 4260ac4b22..8a34bde83d 100644 --- a/integration/control.go +++ b/integration/control.go @@ -1,9 +1,8 @@ package integration import ( - "github.com/ory/dockertest/v3" - v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/ory/dockertest/v3" ) type ControlServer interface { diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 5b55a0a8ab..3794e085e3 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -177,9 +177,9 @@ func WithPostgres() Option { } // WithIPAllocationStrategy sets the tests IP Allocation strategy. -func WithIPAllocationStrategy(strat types.IPAllocationStrategy) Option { +func WithIPAllocationStrategy(strategy types.IPAllocationStrategy) Option { return func(hsic *HeadscaleInContainer) { - hsic.env["HEADSCALE_PREFIXES_ALLOCATION"] = string(strat) + hsic.env["HEADSCALE_PREFIXES_ALLOCATION"] = string(strategy) } }