Skip to content

Commit

Permalink
add panic if old code can be cleaned up
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Feb 5, 2025
1 parent 3e6b1bf commit 643703d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ func nodesChangedHook(db *db.HSDatabase, polMan policy.PolicyManager, notif *not

// Serve launches the HTTP and gRPC server service Headscale and the API.
func (h *Headscale) Serve() error {
capver.CanOldCodeBeCleanedUp()

if profilingEnabled {
if profilingPath != "" {
err := os.MkdirAll(profilingPath, os.ModePerm)
Expand All @@ -566,7 +568,7 @@ func (h *Headscale) Serve() error {

log.Info().
Caller().
Str("minimum_version", capver.TailscaleVersion(MinimumCapVersion)).
Str("minimum_version", capver.TailscaleVersion(capver.MinSupportedCapabilityVersion)).
Msg("Clients with a lower minimum version will be rejected")

// Fetch an initial DERP Map before we start serving
Expand Down
14 changes: 14 additions & 0 deletions hscontrol/capver/capver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import (
"tailscale.com/util/set"
)

const MinSupportedCapabilityVersion tailcfg.CapabilityVersion = 88

// CanOldCodeBeCleanedUp is intended to be called on startup to see if
// there are old code that can ble cleaned up, entries should contain
// a CapVer where something can be cleaned up and a panic if it can.
// This is only intended to catch things in tests.
//
// All uses of Capability version checks should be listed here.
func CanOldCodeBeCleanedUp() {
if MinSupportedCapabilityVersion >= 111 {
panic("LegacyDERP can be cleaned up in tail.go")
}
}

func tailscaleVersSorted() []string {
vers := xmaps.Keys(tailscaleToCapVer)
sort.Strings(vers)
Expand Down
10 changes: 3 additions & 7 deletions hscontrol/noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ func (ns *noiseServer) earlyNoise(protocolVersion int, writer io.Writer) error {
return nil
}

const (
MinSupportedCapabilityVersion tailcfg.CapabilityVersion = 88
)

func isSupportedVersion(version tailcfg.CapabilityVersion) bool {
return version >= MinimumCapVersion
return version >= capver.MinSupportedCapabilityVersion
}

func rejectUnsupported(
Expand All @@ -168,9 +164,9 @@ func rejectUnsupported(
if !isSupportedVersion(version) {
log.Error().
Caller().
Int("minimum_cap_ver", int(MinimumCapVersion)).
Int("minimum_cap_ver", int(capver.MinSupportedCapabilityVersion)).
Int("client_cap_ver", int(version)).
Str("minimum_version", capver.TailscaleVersion(MinimumCapVersion)).
Str("minimum_version", capver.TailscaleVersion(capver.MinSupportedCapabilityVersion)).
Str("client_version", capver.TailscaleVersion(version)).
Str("node_key", nkey.ShortString()).
Str("machine_key", mkey.ShortString()).
Expand Down

0 comments on commit 643703d

Please sign in to comment.