mirror of
https://github.com/juanfont/headscale.git
synced 2026-07-08 00:50:20 +09:00
util: remove dead helpers and stale comments
This commit is contained in:
+2
-19
@@ -150,24 +150,6 @@ func GenerateIPv4DNSRootDomain(ipPrefix netip.Prefix) []dnsname.FQDN {
|
||||
return fqdns
|
||||
}
|
||||
|
||||
// generateMagicDNSRootDomains generates a list of DNS entries to be included in [tailcfg.DNSConfig.Routes] in [tailcfg.MapResponse].
|
||||
// This list of reverse DNS entries instructs the OS on what subnets and domains the Tailscale embedded DNS
|
||||
// server (listening in 100.100.100.100 udp/53) should be used for.
|
||||
//
|
||||
// Tailscale.com includes in the list:
|
||||
// - the [types.DNSConfig.BaseDomain] of the user
|
||||
// - the reverse DNS entry for IPv6 (0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa., see below more on IPv6)
|
||||
// - the reverse DNS entries for the IPv4 subnets covered by the user's `IPPrefix`.
|
||||
// In the public SaaS this is [64-127].100.in-addr.arpa.
|
||||
//
|
||||
// The main purpose of this function is then generating the list of IPv4 entries. For the 100.64.0.0/10, this
|
||||
// is clear, and could be hardcoded. But we are allowing any range as `IPPrefix`, so we need to find out the
|
||||
// subnets when we have 172.16.0.0/16 (i.e., [0-255].16.172.in-addr.arpa.), or any other subnet.
|
||||
//
|
||||
// How IN-ADDR.ARPA domains work is defined in RFC1035 (section 3.5). Tailscale.com seems to adhere to this,
|
||||
// and do not make use of RFC2317 ("Classless IN-ADDR.ARPA delegation") - hence generating the entries for the next
|
||||
// class block only.
|
||||
|
||||
// GenerateIPv6DNSRootDomain generates the IPv6 reverse DNS root domains.
|
||||
// From the netmask we can find out the wildcard bits (the bits that are not set in the netmask).
|
||||
// This allows us to then calculate the subnets included in the subsequent class block and generate the entries.
|
||||
@@ -192,7 +174,8 @@ func GenerateIPv6DNSRootDomain(ipPrefix netip.Prefix) []dnsname.FQDN {
|
||||
for i := range maskBits / nibbleLen {
|
||||
prefixConstantParts = append(
|
||||
[]string{string(nibbleStr[i])},
|
||||
prefixConstantParts...)
|
||||
prefixConstantParts...,
|
||||
)
|
||||
}
|
||||
|
||||
makeDomain := func(variablePrefix ...string) (dnsname.FQDN, error) {
|
||||
|
||||
@@ -32,19 +32,15 @@ type DBLogWrapper struct {
|
||||
}
|
||||
|
||||
func NewDBLogWrapper(origin *zerolog.Logger, slowThreshold time.Duration, skipErrRecordNotFound bool, parameterizedQueries bool) *DBLogWrapper {
|
||||
l := &DBLogWrapper{
|
||||
return &DBLogWrapper{
|
||||
Logger: origin,
|
||||
Level: origin.GetLevel(),
|
||||
SlowThreshold: slowThreshold,
|
||||
SkipErrRecordNotFound: skipErrRecordNotFound,
|
||||
ParameterizedQueries: parameterizedQueries,
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
type DBLogWrapperOption func(*DBLogWrapper)
|
||||
|
||||
func (l *DBLogWrapper) LogMode(gormLogger.LogLevel) gormLogger.Interface {
|
||||
return l
|
||||
}
|
||||
@@ -71,16 +67,16 @@ func (l *DBLogWrapper) Trace(ctx context.Context, begin time.Time, fc func() (sq
|
||||
}
|
||||
|
||||
if err != nil && (!errors.Is(err, gorm.ErrRecordNotFound) || !l.SkipErrRecordNotFound) {
|
||||
l.Logger.Error().Err(err).Fields(fields).Msgf("")
|
||||
l.Logger.Error().Err(err).Fields(fields).Msg("")
|
||||
return
|
||||
}
|
||||
|
||||
if l.SlowThreshold != 0 && elapsed > l.SlowThreshold {
|
||||
l.Logger.Warn().Fields(fields).Msgf("")
|
||||
l.Logger.Warn().Fields(fields).Msg("")
|
||||
return
|
||||
}
|
||||
|
||||
l.Logger.Debug().Fields(fields).Msgf("")
|
||||
l.Logger.Debug().Fields(fields).Msg("")
|
||||
}
|
||||
|
||||
func (l *DBLogWrapper) ParamsFilter(ctx context.Context, sql string, params ...any) (string, []any) {
|
||||
|
||||
@@ -3,10 +3,7 @@ package util
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
// GenerateRandomBytes returns securely generated random bytes.
|
||||
@@ -79,40 +76,3 @@ func MustGenerateRandomStringDNSSafe(size int) string {
|
||||
|
||||
return hash
|
||||
}
|
||||
|
||||
func TailNodesToString(nodes []*tailcfg.Node) string {
|
||||
temp := make([]string, len(nodes))
|
||||
|
||||
for index, node := range nodes {
|
||||
temp[index] = node.Name
|
||||
}
|
||||
|
||||
return fmt.Sprintf("[ %s ](%d)", strings.Join(temp, ", "), len(temp))
|
||||
}
|
||||
|
||||
func TailMapResponseToString(resp tailcfg.MapResponse) string {
|
||||
return fmt.Sprintf(
|
||||
"{ Node: %s, Peers: %s }",
|
||||
resp.Node.Name,
|
||||
TailNodesToString(resp.Peers),
|
||||
)
|
||||
}
|
||||
|
||||
func TailcfgFilterRulesToString(rules []tailcfg.FilterRule) string {
|
||||
var sb strings.Builder
|
||||
|
||||
for index, rule := range rules {
|
||||
fmt.Fprintf(&sb, `
|
||||
{
|
||||
SrcIPs: %v
|
||||
DstIPs: %v
|
||||
}
|
||||
`, rule.SrcIPs, rule.DstPorts)
|
||||
|
||||
if index < len(rules)-1 {
|
||||
sb.WriteString(", ")
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf("[ %s ](%d)", sb.String(), len(rules))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user