From ed6596f9d7bba89455af033efcc10087a334d4bb Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 15 Jun 2026 09:53:18 +0000 Subject: [PATCH] policy, mapper, capver, hscontrol: remove dead code --- hscontrol/capver/capver.go | 38 ------------------------- hscontrol/mapper/mapper.go | 6 ---- hscontrol/policy/matcher/export_test.go | 38 +++++++++++++++++++++++++ hscontrol/policy/matcher/matcher.go | 32 --------------------- hscontrol/policy/v2/types.go | 38 ------------------------- hscontrol/tailsql.go | 4 --- 6 files changed, 38 insertions(+), 118 deletions(-) create mode 100644 hscontrol/policy/matcher/export_test.go diff --git a/hscontrol/capver/capver.go b/hscontrol/capver/capver.go index 86a653dd..31b43044 100644 --- a/hscontrol/capver/capver.go +++ b/hscontrol/capver/capver.go @@ -3,7 +3,6 @@ package capver //go:generate go run ../../tools/capver/main.go import ( - "slices" "sort" "strings" @@ -32,13 +31,6 @@ func tailscaleVersSorted() []string { return vers } -func capVersSorted() []tailcfg.CapabilityVersion { - capVers := xmaps.Keys(capVerToTailscaleVer) - slices.Sort(capVers) - - return capVers -} - // TailscaleVersion returns the Tailscale version for the given [tailcfg.CapabilityVersion]. func TailscaleVersion(ver tailcfg.CapabilityVersion) string { return capVerToTailscaleVer[ver] @@ -66,21 +58,6 @@ func CapabilityVersion(ver string) tailcfg.CapabilityVersion { return 0 } -// TailscaleLatest returns the n latest Tailscale versions. -func TailscaleLatest(n int) []string { - if n <= 0 { - return nil - } - - tsSorted := tailscaleVersSorted() - - if n > len(tsSorted) { - return tsSorted - } - - return tsSorted[len(tsSorted)-n:] -} - // TailscaleLatestMajorMinor returns the n latest Tailscale versions (e.g. 1.80). func TailscaleLatestMajorMinor(n int, stripV bool) []string { if n <= 0 { @@ -107,18 +84,3 @@ func TailscaleLatestMajorMinor(n int, stripV bool) []string { return majorSl[len(majorSl)-n:] } - -// CapVerLatest returns the n latest [tailcfg.CapabilityVersion] values. -func CapVerLatest(n int) []tailcfg.CapabilityVersion { - if n <= 0 { - return nil - } - - s := capVersSorted() - - if n > len(s) { - return s - } - - return s[len(s)-n:] -} diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index a9a43073..af5852ce 100644 --- a/hscontrol/mapper/mapper.go +++ b/hscontrol/mapper/mapper.go @@ -51,12 +51,6 @@ type mapper struct { created time.Time } -//nolint:unused -type patch struct { - timestamp time.Time - change *tailcfg.PeerChange -} - func newMapper( cfg *types.Config, state *state.State, diff --git a/hscontrol/policy/matcher/export_test.go b/hscontrol/policy/matcher/export_test.go new file mode 100644 index 00000000..c218d51a --- /dev/null +++ b/hscontrol/policy/matcher/export_test.go @@ -0,0 +1,38 @@ +package matcher + +import ( + "github.com/juanfont/headscale/hscontrol/util" + "go4.org/netipx" +) + +// MatchFromStrings builds a [Match] from raw source and destination +// strings. Unparseable entries are silently dropped (fail-open): the +// resulting [Match] is narrower than the input described, but never +// wider. Callers that need strict validation should pre-validate +// their inputs via [util.ParseIPSet]. +func MatchFromStrings(sources, destinations []string) Match { + srcs := new(netipx.IPSetBuilder) + dests := new(netipx.IPSetBuilder) + + for _, srcIP := range sources { + set, _ := util.ParseIPSet(srcIP, nil) + + srcs.AddSet(set) + } + + for _, dest := range destinations { + set, _ := util.ParseIPSet(dest, nil) + + dests.AddSet(set) + } + + srcsSet, _ := srcs.IPSet() + destsSet, _ := dests.IPSet() + + match := Match{ + srcs: srcsSet, + dests: destsSet, + } + + return match +} diff --git a/hscontrol/policy/matcher/matcher.go b/hscontrol/policy/matcher/matcher.go index fd537834..39e7b573 100644 --- a/hscontrol/policy/matcher/matcher.go +++ b/hscontrol/policy/matcher/matcher.go @@ -80,38 +80,6 @@ func MatchFromFilterRule(rule tailcfg.FilterRule) Match { } } -// MatchFromStrings builds a [Match] from raw source and destination -// strings. Unparseable entries are silently dropped (fail-open): the -// resulting [Match] is narrower than the input described, but never -// wider. Callers that need strict validation should pre-validate -// their inputs via [util.ParseIPSet]. -func MatchFromStrings(sources, destinations []string) Match { - srcs := new(netipx.IPSetBuilder) - dests := new(netipx.IPSetBuilder) - - for _, srcIP := range sources { - set, _ := util.ParseIPSet(srcIP, nil) - - srcs.AddSet(set) - } - - for _, dest := range destinations { - set, _ := util.ParseIPSet(dest, nil) - - dests.AddSet(set) - } - - srcsSet, _ := srcs.IPSet() - destsSet, _ := dests.IPSet() - - match := Match{ - srcs: srcsSet, - dests: destsSet, - } - - return match -} - func (m *Match) SrcsContainsIPs(ips ...netip.Addr) bool { return slices.ContainsFunc(ips, m.srcs.Contains) } diff --git a/hscontrol/policy/v2/types.go b/hscontrol/policy/v2/types.go index 30b06ca1..d38d9cb0 100644 --- a/hscontrol/policy/v2/types.go +++ b/hscontrol/policy/v2/types.go @@ -1747,44 +1747,6 @@ func (p *Protocol) String() string { return string(*p) } -// Description returns the human-readable description of the [Protocol]. -func (p *Protocol) Description() string { - switch *p { - case ProtocolNameICMP: - return "Internet Control Message Protocol" - case ProtocolNameIGMP: - return "Internet Group Management Protocol" - case ProtocolNameIPv4: - return "IPv4 encapsulation" - case ProtocolNameTCP: - return "Transmission Control Protocol" - case ProtocolNameEGP: - return "Exterior Gateway Protocol" - case ProtocolNameIGP: - return "Interior Gateway Protocol" - case ProtocolNameUDP: - return "User Datagram Protocol" - case ProtocolNameGRE: - return "Generic Routing Encapsulation" - case ProtocolNameESP: - return "Encapsulating Security Payload" - case ProtocolNameAH: - return "Authentication Header" - case ProtocolNameIPv6ICMP: - return "Internet Control Message Protocol for IPv6" - case ProtocolNameSCTP: - return "Stream Control Transmission Protocol" - case ProtocolNameFC: - return "Fibre Channel" - case ProtocolNameIPInIP: - return "IP-in-IP Encapsulation" - case ProtocolNameWildcard: - return "Wildcard (not supported - use specific protocol)" - default: - return "Unknown Protocol" - } -} - // toIANAProtocolNumbers converts a [Protocol] to its IANA protocol numbers. // Since validation happens during [Protocol.UnmarshalJSON], this method should not fail for valid [Protocol] values. func (p *Protocol) toIANAProtocolNumbers() []int { diff --git a/hscontrol/tailsql.go b/hscontrol/tailsql.go index 7f2a52ba..25c6869a 100644 --- a/hscontrol/tailsql.go +++ b/hscontrol/tailsql.go @@ -38,9 +38,6 @@ func runTailSQLService(ctx context.Context, logf logger.Logf, stateDir, dbPath s Hostname: opts.Hostname, Logf: logger.Discard, } - // if *doDebugLog { - // tsNode.Logf = logf - // } defer tsNode.Close() logf("Starting tailscale (hostname=%q)", opts.Hostname) @@ -87,7 +84,6 @@ func runTailSQLService(ctx context.Context, logf logger.Logf, stateDir, dbPath s http.Redirect(w, r, target, http.StatusPermanentRedirect) //nolint:gosec // G710: target prefixed by trusted base URL })) }() - // log.Printf("Redirecting HTTP to HTTPS at %q", base) // For the real service, start a separate listener. // Note: Replaces the port 80 listener.