diff --git a/go.mod b/go.mod index a32f89ca5b..7cb6391842 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/cavaliergopher/grab/v3 v3.0.1 github.com/cheggaaa/pb/v3 v3.1.6 github.com/containers/common v0.60.4 - github.com/containers/gvisor-tap-vsock v0.8.2 + github.com/containers/gvisor-tap-vsock v0.8.3 github.com/containers/image/v5 v5.32.2 github.com/containers/libhvee v0.9.0 github.com/coreos/go-systemd/v22 v22.5.0 @@ -146,7 +146,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.22 // indirect github.com/mdlayher/socket v0.4.1 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/miekg/dns v1.1.62 // indirect + github.com/miekg/dns v1.1.63 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/moby/sys/mountinfo v0.7.2 // indirect @@ -163,8 +163,6 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect github.com/proglottis/gpgme v0.1.3 // indirect - github.com/qdm12/dns/v2 v2.0.0-rc6 // indirect - github.com/qdm12/gosettings v0.4.1 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect diff --git a/go.sum b/go.sum index 085f6c2266..cf828f8d91 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containers/common v0.60.4 h1:H5+LAMHPZEqX6vVNOQ+IguVsaFl8kbO/SZ/VPXjxhy0= github.com/containers/common v0.60.4/go.mod h1:I0upBi1qJX3QmzGbUOBN1LVP6RvkKhd3qQpZbQT+Q54= -github.com/containers/gvisor-tap-vsock v0.8.2 h1:uQMBCCHlIIj62fPjbvgm6AL5EzsP6TP5eviByOJEsOg= -github.com/containers/gvisor-tap-vsock v0.8.2/go.mod h1:EMRe2o63ddq2zxcP0hTysmxCf/5JlaNEg8/gpzP0ox4= +github.com/containers/gvisor-tap-vsock v0.8.3 h1:Am3VdjXTn8Mn+dNhgkiRcCFOTSM8u9aWKLW3KTHOGjk= +github.com/containers/gvisor-tap-vsock v0.8.3/go.mod h1:46MvrqNuRNbjV4ZsZ3mHVJjR2Eh+fpyRh72EvWWFFjU= github.com/containers/image/v5 v5.32.2 h1:SzNE2Y6sf9b1GJoC8qjCuMBXwQrACFp4p0RK15+4gmQ= github.com/containers/image/v5 v5.32.2/go.mod h1:v1l73VeMugfj/QtKI+jhYbwnwFCFnNGckvbST3rQ5Hk= github.com/containers/libhvee v0.9.0 h1:5UxJMka1lDfxTeITA25Pd8QVVttJAG43eQS1Getw1tc= @@ -271,8 +271,8 @@ github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnE github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI= github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= -github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ= -github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ= +github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY= +github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= @@ -340,10 +340,6 @@ github.com/prometheus/common v0.51.1 h1:eIjN50Bwglz6a/c3hAgSMcofL3nD+nFQkV6Dd4Ds github.com/prometheus/common v0.51.1/go.mod h1:lrWtQx+iDfn2mbH5GUzlH9TSHyfZpHkSiG1W7y3sF2Q= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= -github.com/qdm12/dns/v2 v2.0.0-rc6 h1:h5KpuqZ3IMoSbz2a0OkHzIVc9/jk2vuIm9RoKJuaI78= -github.com/qdm12/dns/v2 v2.0.0-rc6/go.mod h1:Oh34IJIG55BgHoACOf+cgZCgDiFuiJZ6r6gQW58FN+k= -github.com/qdm12/gosettings v0.4.1 h1:c7+14jO1Y2kFXBCUfS2+QE2NgwTKfzcdJzGEFRItCI8= -github.com/qdm12/gosettings v0.4.1/go.mod h1:uItKwGXibJp2pQ0am6MBKilpjfvYTGiH+zXHd10jFj8= github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns.go index 9168dff056..92b00daf89 100644 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns.go +++ b/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns.go @@ -1,15 +1,14 @@ package dns import ( + "context" "encoding/json" - "errors" "fmt" "net" "net/http" "strings" "sync" - "github.com/areYouLazy/libhosty" "github.com/containers/gvisor-tap-vsock/pkg/types" "github.com/miekg/dns" log "github.com/sirupsen/logrus" @@ -18,34 +17,13 @@ import ( type dnsHandler struct { zones []types.Zone zonesLock sync.RWMutex - udpClient *dns.Client - tcpClient *dns.Client - hostsFile *HostsFile - dnsConfig *dnsConfig } -func newDNSHandler(zones []types.Zone) (*dnsHandler, error) { - dnsConfig, err := newDNSConfig() - if err != nil { - return nil, err - } - - hostsFile, err := NewHostsFile("") - if err != nil { - return nil, err - } - - return &dnsHandler{ - zones: zones, - tcpClient: &dns.Client{Net: "tcp"}, - udpClient: &dns.Client{Net: "udp"}, - dnsConfig: dnsConfig, - hostsFile: hostsFile, - }, nil -} - -func (h *dnsHandler) handle(w dns.ResponseWriter, dnsClient *dns.Client, r *dns.Msg, responseMessageSize int) { - m := h.addAnswers(dnsClient, r) +func (h *dnsHandler) handle(w dns.ResponseWriter, r *dns.Msg, responseMessageSize int) { + m := new(dns.Msg) + m.SetReply(r) + m.RecursionAvailable = true + h.addAnswers(m) edns0 := r.IsEdns0() if edns0 != nil { responseMessageSize = int(edns0.UDPSize()) @@ -57,25 +35,23 @@ func (h *dnsHandler) handle(w dns.ResponseWriter, dnsClient *dns.Client, r *dns. } func (h *dnsHandler) handleTCP(w dns.ResponseWriter, r *dns.Msg) { - h.handle(w, h.tcpClient, r, dns.MaxMsgSize) + h.handle(w, r, dns.MaxMsgSize) } func (h *dnsHandler) handleUDP(w dns.ResponseWriter, r *dns.Msg) { - h.handle(w, h.udpClient, r, dns.MinMsgSize) + h.handle(w, r, dns.MinMsgSize) } func (h *dnsHandler) addLocalAnswers(m *dns.Msg, q dns.Question) bool { - // resolve only ipv4 requests - if q.Qtype != dns.TypeA { - return false - } - h.zonesLock.RLock() defer h.zonesLock.RUnlock() for _, zone := range h.zones { zoneSuffix := fmt.Sprintf(".%s", zone.Name) if strings.HasSuffix(q.Name, zoneSuffix) { + if q.Qtype != dns.TypeA { + return false + } for _, record := range zone.Records { withoutZone := strings.TrimSuffix(q.Name, zoneSuffix) if (record.Name != "" && record.Name == withoutZone) || @@ -107,55 +83,127 @@ func (h *dnsHandler) addLocalAnswers(m *dns.Msg, q dns.Question) bool { m.Rcode = dns.RcodeNameError return true } - ip, err := h.hostsFile.LookupByHostname(q.Name) - if err != nil { - // ignore only ErrHostnameNotFound error - if !errors.Is(err, libhosty.ErrHostnameNotFound) { - log.Errorf("Error during looking in hosts file records: %v", err) - } - } else { - m.Answer = append(m.Answer, &dns.A{ - Hdr: dns.RR_Header{ - Name: q.Name, - Rrtype: dns.TypeA, - Class: dns.ClassINET, - Ttl: 0, - }, - A: ip, - }) - return true - } } return false } -func (h *dnsHandler) addAnswers(dnsClient *dns.Client, r *dns.Msg) *dns.Msg { - m := new(dns.Msg) - m.SetReply(r) - m.RecursionAvailable = true - +func (h *dnsHandler) addAnswers(m *dns.Msg) { for _, q := range m.Question { if done := h.addLocalAnswers(m, q); done { - return m + return + } - // ignore IPv6 request, we support only IPv4 requests for now - } else if q.Qtype == dns.TypeAAAA { - return m + resolver := net.Resolver{ + PreferGo: false, } - } - for _, nameserver := range h.dnsConfig.Nameservers() { - msg := r.Copy() - r, _, err := dnsClient.Exchange(msg, nameserver) - // return first good answer - if err == nil { - return r + switch q.Qtype { + case dns.TypeA: + ips, err := resolver.LookupIPAddr(context.TODO(), q.Name) + if err != nil { + m.Rcode = dns.RcodeNameError + return + } + for _, ip := range ips { + if len(ip.IP.To4()) != net.IPv4len { + continue + } + m.Answer = append(m.Answer, &dns.A{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeA, + Class: dns.ClassINET, + Ttl: 0, + }, + A: ip.IP.To4(), + }) + } + case dns.TypeCNAME: + cname, err := resolver.LookupCNAME(context.TODO(), q.Name) + if err != nil { + m.Rcode = dns.RcodeNameError + return + } + m.Answer = append(m.Answer, &dns.CNAME{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeCNAME, + Class: dns.ClassINET, + Ttl: 0, + }, + Target: cname, + }) + case dns.TypeMX: + records, err := resolver.LookupMX(context.TODO(), q.Name) + if err != nil { + m.Rcode = dns.RcodeNameError + return + } + for _, mx := range records { + m.Answer = append(m.Answer, &dns.MX{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeMX, + Class: dns.ClassINET, + Ttl: 0, + }, + Mx: mx.Host, + Preference: mx.Pref, + }) + } + case dns.TypeNS: + records, err := resolver.LookupNS(context.TODO(), q.Name) + if err != nil { + m.Rcode = dns.RcodeNameError + return + } + for _, ns := range records { + m.Answer = append(m.Answer, &dns.NS{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeNS, + Class: dns.ClassINET, + Ttl: 0, + }, + Ns: ns.Host, + }) + } + case dns.TypeSRV: + _, records, err := resolver.LookupSRV(context.TODO(), "", "", q.Name) + if err != nil { + m.Rcode = dns.RcodeNameError + return + } + for _, srv := range records { + m.Answer = append(m.Answer, &dns.SRV{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeSRV, + Class: dns.ClassINET, + Ttl: 0, + }, + Port: srv.Port, + Priority: srv.Priority, + Target: srv.Target, + Weight: srv.Weight, + }) + } + case dns.TypeTXT: + records, err := resolver.LookupTXT(context.TODO(), q.Name) + if err != nil { + m.Rcode = dns.RcodeNameError + return + } + m.Answer = append(m.Answer, &dns.TXT{ + Hdr: dns.RR_Header{ + Name: q.Name, + Rrtype: dns.TypeTXT, + Class: dns.ClassINET, + Ttl: 0, + }, + Txt: records, + }) } - log.Debugf("Error during DNS Exchange: %s", err) } - - // return the error if none of configured nameservers has right answer - m.Rcode = dns.RcodeNameError - return m } type Server struct { @@ -165,10 +213,7 @@ type Server struct { } func New(udpConn net.PacketConn, tcpLn net.Listener, zones []types.Zone) (*Server, error) { - handler, err := newDNSHandler(zones) - if err != nil { - return nil, err - } + handler := &dnsHandler{zones: zones} return &Server{udpConn: udpConn, tcpLn: tcpLn, handler: handler}, nil } diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config.go deleted file mode 100644 index 1abdfe0c2f..0000000000 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config.go +++ /dev/null @@ -1,24 +0,0 @@ -package dns - -import "sync" - -type dnsConfig struct { - mu sync.RWMutex - nameservers []string -} - -func newDNSConfig() (*dnsConfig, error) { - r := &dnsConfig{nameservers: []string{}} - if err := r.init(); err != nil { - return nil, err - } - - return r, nil -} - -func (r *dnsConfig) Nameservers() []string { - r.mu.RLock() - defer r.mu.RUnlock() - - return r.nameservers -} diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config_unix.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config_unix.go deleted file mode 100644 index c1e90487ac..0000000000 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config_unix.go +++ /dev/null @@ -1,67 +0,0 @@ -//go:build !windows - -package dns - -import ( - "net" - "net/netip" - - "github.com/containers/gvisor-tap-vsock/pkg/utils" - "github.com/miekg/dns" - log "github.com/sirupsen/logrus" -) - -func (r *dnsConfig) init() error { - if err := r.refreshNameservers(); err != nil { - return err - } - - w, err := utils.NewFileWatcher(etcResolvConfPath) - if err != nil { - return err - } - - if err := w.Start(func() { _ = r.refreshNameservers() }); err != nil { - return err - } - - return nil -} - -func (r *dnsConfig) refreshNameservers() error { - nsList, err := getDNSHostAndPort(etcResolvConfPath) - if err != nil { - log.Errorf("can't load dns nameservers: %v", err) - return err - } - - log.Infof("reloading dns nameservers to %v", nsList) - - r.mu.Lock() - r.nameservers = nsList - r.mu.Unlock() - return nil -} - -const etcResolvConfPath = "/etc/resolv.conf" - -func getDNSHostAndPort(path string) ([]string, error) { - conf, err := dns.ClientConfigFromFile(path) - if err != nil { - return []string{}, err - } - hosts := make([]string, 0, len(conf.Servers)) - for _, server := range conf.Servers { - dnsIP, err := netip.ParseAddr(server) - if err != nil { - log.Errorf("Failed to parse DNS IP address: %s", server) - continue - } - // add only ipv4 dns addresses - if dnsIP.Is4() { - hosts = append(hosts, net.JoinHostPort(server, conf.Port)) - } - } - - return hosts, nil -} diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config_windows.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config_windows.go deleted file mode 100644 index 431727dfc5..0000000000 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/dns_config_windows.go +++ /dev/null @@ -1,34 +0,0 @@ -//go:build windows - -package dns - -import ( - "net" - "strconv" - - qdmDns "github.com/qdm12/dns/v2/pkg/nameserver" -) - -func (r *dnsConfig) init() error { - nsList, err := getDNSHostAndPort() - if err != nil { - return err - } - - r.nameservers = nsList - return nil -} - -func getDNSHostAndPort() ([]string, error) { - nameservers := qdmDns.GetDNSServers() - - var dnsServers []string - for _, n := range nameservers { - // return only ipv4 nameservers - if n.Addr().Is4() { - dnsServers = append(dnsServers, net.JoinHostPort(n.Addr().String(), strconv.Itoa(int(n.Port())))) - } - } - - return dnsServers, nil -} diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/hosts_file.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/hosts_file.go deleted file mode 100644 index 106129ee4e..0000000000 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/services/dns/hosts_file.go +++ /dev/null @@ -1,79 +0,0 @@ -package dns - -import ( - "net" - "sync" - - "github.com/areYouLazy/libhosty" - "github.com/containers/gvisor-tap-vsock/pkg/utils" - log "github.com/sirupsen/logrus" -) - -type HostsFile struct { - hostsReadLock sync.RWMutex - hostsFilePath string - hostsFile *libhosty.HostsFile -} - -// NewHostsFile Creates new HostsFile instance -// Pass ""(empty string) if you want to use default hosts file -func NewHostsFile(hostsPath string) (*HostsFile, error) { - hostsFile, err := readHostsFile(hostsPath) - if err != nil { - return nil, err - } - - h := &HostsFile{ - hostsFile: hostsFile, - hostsFilePath: hostsFile.Config.FilePath, - } - if err := h.startWatch(); err != nil { - return nil, err - } - - return h, nil -} - -func (h *HostsFile) startWatch() error { - watcher, err := utils.NewFileWatcher(h.hostsFilePath) - if err != nil { - log.Errorf("Hosts file adding watcher error: %s", err) - return err - } - - if err := watcher.Start(h.updateHostsFile); err != nil { - log.Errorf("Hosts file adding watcher error: %s", err) - return err - } - - return nil -} - -func (h *HostsFile) LookupByHostname(name string) (net.IP, error) { - h.hostsReadLock.RLock() - defer h.hostsReadLock.RUnlock() - - _, ip, err := h.hostsFile.LookupByHostname(name) - return ip, err -} - -func (h *HostsFile) updateHostsFile() { - newHosts, err := readHostsFile(h.hostsFilePath) - if err != nil { - log.Errorf("Hosts file read error:%s", err) - return - } - - h.hostsReadLock.Lock() - defer h.hostsReadLock.Unlock() - - h.hostsFile = newHosts -} - -func readHostsFile(hostsFilePath string) (*libhosty.HostsFile, error) { - config, err := libhosty.NewHostsFileConfig(hostsFilePath) - if err != nil { - return nil, err - } - return libhosty.InitWithConfig(config) -} diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/utils/filewatcher.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/utils/filewatcher.go index 0993d38ed7..9c76397b5e 100644 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/utils/filewatcher.go +++ b/vendor/github.com/containers/gvisor-tap-vsock/pkg/utils/filewatcher.go @@ -1,84 +1,63 @@ package utils import ( - "fmt" - "path/filepath" + "os" "time" - - "github.com/fsnotify/fsnotify" ) // FileWatcher is an utility that type FileWatcher struct { - w *fsnotify.Watcher path string - writeGracePeriod time.Duration - timer *time.Timer + closeCh chan struct{} + pollInterval time.Duration } -func NewFileWatcher(path string) (*FileWatcher, error) { - watcher, err := fsnotify.NewWatcher() - if err != nil { - return nil, err +func NewFileWatcher(path string) *FileWatcher { + return &FileWatcher{ + path: path, + pollInterval: 5 * time.Second, // 5s is the default inode cache timeout in linux for most systems. + closeCh: make(chan struct{}), } - - return &FileWatcher{w: watcher, path: path, writeGracePeriod: 200 * time.Millisecond}, nil } -func (fw *FileWatcher) Start(changeHandler func()) error { - // Ensure that the target that we're watching is not a symlink as we won't get any events when we're watching - // a symlink. - fileRealPath, err := filepath.EvalSymlinks(fw.path) - if err != nil { - return fmt.Errorf("adding watcher failed: %s", err) - } - - // watch the directory instead of the individual file to ensure the notification still works when the file is modified - // through moving/renaming rather than writing into it directly (like what most modern editor does by default). - // ref: https://github.com/fsnotify/fsnotify/blob/a9bc2e01792f868516acf80817f7d7d7b3315409/README.md#watching-a-file-doesnt-work-well - if err = fw.w.Add(filepath.Dir(fileRealPath)); err != nil { - return fmt.Errorf("adding watcher failed: %s", err) - } +func (fw *FileWatcher) Start(changeHandler func()) { + prevModTime := fw.fileModTime(fw.path) + // use polling-based approach to detect file changes + // we can't use fsnotify/fsnotify due to issues with symlink+socket. see #462. go func() { for { select { - case _, ok := <-fw.w.Errors: - if !ok { - return // watcher is closed. - } - case event, ok := <-fw.w.Events: + case _, ok := <-fw.closeCh: if !ok { return // watcher is closed. } + case <-time.After(fw.pollInterval): + } - if event.Name != fileRealPath { - continue // we don't care about this file. - } + modTime := fw.fileModTime(fw.path) + if modTime.IsZero() { + continue // file does not exists + } - // Create may not always followed by Write e.g. when we replace the file with mv. - if event.Op.Has(fsnotify.Create) || event.Op.Has(fsnotify.Write) { - // as per the documentation, receiving Write does not mean that the write is finished. - // we try our best here to ignore "unfinished" write by assuming that after [writeGracePeriod] of - // inactivity the write has been finished. - fw.debounce(changeHandler) - } + if !prevModTime.Equal(modTime) { + changeHandler() + prevModTime = modTime } } }() - - return nil } -func (fw *FileWatcher) debounce(fn func()) { - if fw.timer != nil { - fw.timer.Stop() +func (fw *FileWatcher) fileModTime(path string) time.Time { + info, err := os.Stat(path) + if err != nil { + return time.Time{} } - fw.timer = time.AfterFunc(fw.writeGracePeriod, fn) + return info.ModTime() } -func (fw *FileWatcher) Stop() error { - return fw.w.Close() +func (fw *FileWatcher) Stop() { + close(fw.closeCh) } diff --git a/vendor/github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork/mux.go b/vendor/github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork/mux.go index 6b991d3962..59629f34f2 100644 --- a/vendor/github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork/mux.go +++ b/vendor/github.com/containers/gvisor-tap-vsock/pkg/virtualnetwork/mux.go @@ -15,7 +15,7 @@ import ( "gvisor.dev/gvisor/pkg/tcpip/network/ipv4" ) -func (n *VirtualNetwork) Mux() *http.ServeMux { +func (n *VirtualNetwork) ServicesMux() *http.ServeMux { mux := http.NewServeMux() mux.Handle("/services/", http.StripPrefix("/services", n.servicesMux)) mux.HandleFunc("/stats", func(w http.ResponseWriter, _ *http.Request) { @@ -27,26 +27,6 @@ func (n *VirtualNetwork) Mux() *http.ServeMux { mux.HandleFunc("/leases", func(w http.ResponseWriter, _ *http.Request) { _ = json.NewEncoder(w).Encode(n.ipPool.Leases()) }) - mux.HandleFunc(types.ConnectPath, func(w http.ResponseWriter, _ *http.Request) { - hj, ok := w.(http.Hijacker) - if !ok { - http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError) - return - } - conn, bufrw, err := hj.Hijack() - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - defer conn.Close() - - if err := bufrw.Flush(); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - _ = n.networkSwitch.Accept(context.Background(), conn, n.configuration.Protocol) - }) mux.HandleFunc("/tunnel", func(w http.ResponseWriter, r *http.Request) { ip := r.URL.Query().Get("ip") if ip == "" { @@ -98,3 +78,28 @@ func (n *VirtualNetwork) Mux() *http.ServeMux { }) return mux } + +func (n *VirtualNetwork) Mux() *http.ServeMux { + mux := n.ServicesMux() + mux.HandleFunc(types.ConnectPath, func(w http.ResponseWriter, _ *http.Request) { + hj, ok := w.(http.Hijacker) + if !ok { + http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError) + return + } + conn, bufrw, err := hj.Hijack() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + defer conn.Close() + + if err := bufrw.Flush(); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + _ = n.networkSwitch.Accept(context.Background(), conn, n.configuration.Protocol) + }) + return mux +} diff --git a/vendor/github.com/miekg/dns/README.md b/vendor/github.com/miekg/dns/README.md index 8d5a2a4789..9831c37baf 100644 --- a/vendor/github.com/miekg/dns/README.md +++ b/vendor/github.com/miekg/dns/README.md @@ -85,6 +85,7 @@ A not-so-up-to-date-list-that-may-be-actually-current: * https://github.com/wintbiit/NineDNS * https://linuxcontainers.org/incus/ * https://ifconfig.es +* https://github.com/zmap/zdns Send pull request if you want to be listed here. diff --git a/vendor/github.com/miekg/dns/dnssec.go b/vendor/github.com/miekg/dns/dnssec.go index 1be87eae63..ffdafcebda 100644 --- a/vendor/github.com/miekg/dns/dnssec.go +++ b/vendor/github.com/miekg/dns/dnssec.go @@ -250,14 +250,6 @@ func (d *DS) ToCDS() *CDS { // zero, it is used as-is, otherwise the TTL of the RRset is used as the // OrigTTL. func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error { - if k == nil { - return ErrPrivKey - } - // s.Inception and s.Expiration may be 0 (rollover etc.), the rest must be set - if rr.KeyTag == 0 || len(rr.SignerName) == 0 || rr.Algorithm == 0 { - return ErrKey - } - h0 := rrset[0].Header() rr.Hdr.Rrtype = TypeRRSIG rr.Hdr.Name = h0.Name @@ -272,6 +264,18 @@ func (rr *RRSIG) Sign(k crypto.Signer, rrset []RR) error { rr.Labels-- // wildcard, remove from label count } + return rr.signAsIs(k, rrset) +} + +func (rr *RRSIG) signAsIs(k crypto.Signer, rrset []RR) error { + if k == nil { + return ErrPrivKey + } + // s.Inception and s.Expiration may be 0 (rollover etc.), the rest must be set + if rr.KeyTag == 0 || len(rr.SignerName) == 0 || rr.Algorithm == 0 { + return ErrKey + } + sigwire := new(rrsigWireFmt) sigwire.TypeCovered = rr.TypeCovered sigwire.Algorithm = rr.Algorithm @@ -370,9 +374,12 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error { if rr.Algorithm != k.Algorithm { return ErrKey } - if !strings.EqualFold(rr.SignerName, k.Hdr.Name) { + + signerName := CanonicalName(rr.SignerName) + if !equal(signerName, k.Hdr.Name) { return ErrKey } + if k.Protocol != 3 { return ErrKey } @@ -384,9 +391,18 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error { } // IsRRset checked that we have at least one RR and that the RRs in - // the set have consistent type, class, and name. Also check that type and - // class matches the RRSIG record. - if h0 := rrset[0].Header(); h0.Class != rr.Hdr.Class || h0.Rrtype != rr.TypeCovered { + // the set have consistent type, class, and name. Also check that type, + // class and name matches the RRSIG record. + // Also checks RFC 4035 5.3.1 the number of labels in the RRset owner + // name MUST be greater than or equal to the value in the RRSIG RR's Labels field. + // RFC 4035 5.3.1 Signer's Name MUST be the name of the zone that [contains the RRset]. + // Since we don't have SOA info, checking suffix may be the best we can do...? + if h0 := rrset[0].Header(); h0.Class != rr.Hdr.Class || + h0.Rrtype != rr.TypeCovered || + uint8(CountLabel(h0.Name)) < rr.Labels || + !equal(h0.Name, rr.Hdr.Name) || + !strings.HasSuffix(CanonicalName(h0.Name), signerName) { + return ErrRRset } @@ -400,7 +416,7 @@ func (rr *RRSIG) Verify(k *DNSKEY, rrset []RR) error { sigwire.Expiration = rr.Expiration sigwire.Inception = rr.Inception sigwire.KeyTag = rr.KeyTag - sigwire.SignerName = CanonicalName(rr.SignerName) + sigwire.SignerName = signerName // Create the desired binary blob signeddata := make([]byte, DefaultMsgSize) n, err := packSigWire(sigwire, signeddata) diff --git a/vendor/github.com/miekg/dns/edns.go b/vendor/github.com/miekg/dns/edns.go index c1bbdaae2e..0447fd826a 100644 --- a/vendor/github.com/miekg/dns/edns.go +++ b/vendor/github.com/miekg/dns/edns.go @@ -58,7 +58,7 @@ func makeDataOpt(code uint16) EDNS0 { case EDNS0EDE: return new(EDNS0_EDE) case EDNS0ESU: - return &EDNS0_ESU{Code: EDNS0ESU} + return new(EDNS0_ESU) default: e := new(EDNS0_LOCAL) e.Code = code @@ -66,8 +66,7 @@ func makeDataOpt(code uint16) EDNS0 { } } -// OPT is the EDNS0 RR appended to messages to convey extra (meta) information. -// See RFC 6891. +// OPT is the EDNS0 RR appended to messages to convey extra (meta) information. See RFC 6891. type OPT struct { Hdr RR_Header Option []EDNS0 `dns:"opt"` @@ -144,8 +143,6 @@ func (*OPT) parse(c *zlexer, origin string) *ParseError { func (rr *OPT) isDuplicate(r2 RR) bool { return false } -// return the old value -> delete SetVersion? - // Version returns the EDNS version used. Only zero is defined. func (rr *OPT) Version() uint8 { return uint8(rr.Hdr.Ttl & 0x00FF0000 >> 16) @@ -236,8 +233,8 @@ type EDNS0 interface { // e.Nsid = "AA" // o.Option = append(o.Option, e) type EDNS0_NSID struct { - Code uint16 // Always EDNS0NSID - Nsid string // This string needs to be hex encoded + Code uint16 // always EDNS0NSID + Nsid string // string needs to be hex encoded } func (e *EDNS0_NSID) pack() ([]byte, error) { @@ -275,7 +272,7 @@ func (e *EDNS0_NSID) copy() EDNS0 { return &EDNS0_NSID{e.Code, e.Nsid} // When packing it will apply SourceNetmask. If you need more advanced logic, // patches welcome and good luck. type EDNS0_SUBNET struct { - Code uint16 // Always EDNS0SUBNET + Code uint16 // always EDNS0SUBNET Family uint16 // 1 for IP, 2 for IP6 SourceNetmask uint8 SourceScope uint8 @@ -399,8 +396,8 @@ func (e *EDNS0_SUBNET) copy() EDNS0 { // // There is no guarantee that the Cookie string has a specific length. type EDNS0_COOKIE struct { - Code uint16 // Always EDNS0COOKIE - Cookie string // Hex-encoded cookie data + Code uint16 // always EDNS0COOKIE + Cookie string // hex encoded cookie data } func (e *EDNS0_COOKIE) pack() ([]byte, error) { @@ -430,7 +427,7 @@ func (e *EDNS0_COOKIE) copy() EDNS0 { return &EDNS0_COOKIE{e.Code, e.C // e.Lease = 120 // in seconds // o.Option = append(o.Option, e) type EDNS0_UL struct { - Code uint16 // Always EDNS0UL + Code uint16 // always EDNS0UL Lease uint32 KeyLease uint32 } @@ -469,7 +466,7 @@ func (e *EDNS0_UL) unpack(b []byte) error { // EDNS0_LLQ stands for Long Lived Queries: http://tools.ietf.org/html/draft-sekar-dns-llq-01 // Implemented for completeness, as the EDNS0 type code is assigned. type EDNS0_LLQ struct { - Code uint16 // Always EDNS0LLQ + Code uint16 // always EDNS0LLQ Version uint16 Opcode uint16 Error uint16 @@ -515,7 +512,7 @@ func (e *EDNS0_LLQ) copy() EDNS0 { // EDNS0_DAU implements the EDNS0 "DNSSEC Algorithm Understood" option. See RFC 6975. type EDNS0_DAU struct { - Code uint16 // Always EDNS0DAU + Code uint16 // always EDNS0DAU AlgCode []uint8 } @@ -539,7 +536,7 @@ func (e *EDNS0_DAU) copy() EDNS0 { return &EDNS0_DAU{e.Code, e.AlgCode} } // EDNS0_DHU implements the EDNS0 "DS Hash Understood" option. See RFC 6975. type EDNS0_DHU struct { - Code uint16 // Always EDNS0DHU + Code uint16 // always EDNS0DHU AlgCode []uint8 } @@ -563,7 +560,7 @@ func (e *EDNS0_DHU) copy() EDNS0 { return &EDNS0_DHU{e.Code, e.AlgCode} } // EDNS0_N3U implements the EDNS0 "NSEC3 Hash Understood" option. See RFC 6975. type EDNS0_N3U struct { - Code uint16 // Always EDNS0N3U + Code uint16 // always EDNS0N3U AlgCode []uint8 } @@ -588,7 +585,7 @@ func (e *EDNS0_N3U) copy() EDNS0 { return &EDNS0_N3U{e.Code, e.AlgCode} } // EDNS0_EXPIRE implements the EDNS0 option as described in RFC 7314. type EDNS0_EXPIRE struct { - Code uint16 // Always EDNS0EXPIRE + Code uint16 // always EDNS0EXPIRE Expire uint32 Empty bool // Empty is used to signal an empty Expire option in a backwards compatible way, it's not used on the wire. } @@ -668,7 +665,7 @@ func (e *EDNS0_LOCAL) unpack(b []byte) error { // EDNS0_TCP_KEEPALIVE is an EDNS0 option that instructs the server to keep // the TCP connection alive. See RFC 7828. type EDNS0_TCP_KEEPALIVE struct { - Code uint16 // Always EDNSTCPKEEPALIVE + Code uint16 // always EDNSTCPKEEPALIVE // Timeout is an idle timeout value for the TCP connection, specified in // units of 100 milliseconds, encoded in network byte order. If set to 0, @@ -839,13 +836,12 @@ func (e *EDNS0_EDE) unpack(b []byte) error { return nil } -// The EDNS0_ESU option for ENUM Source-URI Extension +// The EDNS0_ESU option for ENUM Source-URI Extension. type EDNS0_ESU struct { - Code uint16 + Code uint16 // always EDNS0ESU Uri string } -// Option implements the EDNS0 interface. func (e *EDNS0_ESU) Option() uint16 { return EDNS0ESU } func (e *EDNS0_ESU) String() string { return e.Uri } func (e *EDNS0_ESU) copy() EDNS0 { return &EDNS0_ESU{e.Code, e.Uri} } diff --git a/vendor/github.com/miekg/dns/listen_no_reuseport.go b/vendor/github.com/miekg/dns/listen_no_socket_options.go similarity index 61% rename from vendor/github.com/miekg/dns/listen_no_reuseport.go rename to vendor/github.com/miekg/dns/listen_no_socket_options.go index 8cebb2f171..9e4010bdcc 100644 --- a/vendor/github.com/miekg/dns/listen_no_reuseport.go +++ b/vendor/github.com/miekg/dns/listen_no_socket_options.go @@ -3,9 +3,15 @@ package dns -import "net" +import ( + "fmt" + "net" +) -const supportsReusePort = false +const ( + supportsReusePort = false + supportsReuseAddr = false +) func listenTCP(network, addr string, reuseport, reuseaddr bool) (net.Listener, error) { if reuseport || reuseaddr { @@ -15,8 +21,6 @@ func listenTCP(network, addr string, reuseport, reuseaddr bool) (net.Listener, e return net.Listen(network, addr) } -const supportsReuseAddr = false - func listenUDP(network, addr string, reuseport, reuseaddr bool) (net.PacketConn, error) { if reuseport || reuseaddr { // TODO(tmthrgd): return an error? @@ -24,3 +28,13 @@ func listenUDP(network, addr string, reuseport, reuseaddr bool) (net.PacketConn, return net.ListenPacket(network, addr) } + +// this is just for test compatibility +func checkReuseport(fd uintptr) (bool, error) { + return false, fmt.Errorf("not supported") +} + +// this is just for test compatibility +func checkReuseaddr(fd uintptr) (bool, error) { + return false, fmt.Errorf("not supported") +} diff --git a/vendor/github.com/miekg/dns/listen_reuseport.go b/vendor/github.com/miekg/dns/listen_socket_options.go similarity index 66% rename from vendor/github.com/miekg/dns/listen_reuseport.go rename to vendor/github.com/miekg/dns/listen_socket_options.go index 41326f20b7..35dfc9498a 100644 --- a/vendor/github.com/miekg/dns/listen_reuseport.go +++ b/vendor/github.com/miekg/dns/listen_socket_options.go @@ -39,10 +39,40 @@ func reuseaddrControl(network, address string, c syscall.RawConn) error { return opErr } +func reuseaddrandportControl(network, address string, c syscall.RawConn) error { + err := reuseaddrControl(network, address, c) + if err != nil { + return err + } + + return reuseportControl(network, address, c) +} + +// this is just for test compatibility +func checkReuseport(fd uintptr) (bool, error) { + v, err := unix.GetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT) + if err != nil { + return false, err + } + + return v == 1, nil +} + +// this is just for test compatibility +func checkReuseaddr(fd uintptr) (bool, error) { + v, err := unix.GetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR) + if err != nil { + return false, err + } + + return v == 1, nil +} + func listenTCP(network, addr string, reuseport, reuseaddr bool) (net.Listener, error) { var lc net.ListenConfig switch { case reuseaddr && reuseport: + lc.Control = reuseaddrandportControl case reuseport: lc.Control = reuseportControl case reuseaddr: @@ -56,6 +86,7 @@ func listenUDP(network, addr string, reuseport, reuseaddr bool) (net.PacketConn, var lc net.ListenConfig switch { case reuseaddr && reuseport: + lc.Control = reuseaddrandportControl case reuseport: lc.Control = reuseportControl case reuseaddr: diff --git a/vendor/github.com/miekg/dns/server.go b/vendor/github.com/miekg/dns/server.go index 81580d1e5f..b04d370f68 100644 --- a/vendor/github.com/miekg/dns/server.go +++ b/vendor/github.com/miekg/dns/server.go @@ -226,6 +226,7 @@ type Server struct { // If NotifyStartedFunc is set it is called once the server has started listening. NotifyStartedFunc func() // DecorateReader is optional, allows customization of the process that reads raw DNS messages. + // The decorated reader must not mutate the data read from the conn. DecorateReader DecorateReader // DecorateWriter is optional, allows customization of the process that writes raw DNS messages. DecorateWriter DecorateWriter diff --git a/vendor/github.com/miekg/dns/sig0.go b/vendor/github.com/miekg/dns/sig0.go index 2c4b103521..057bb57873 100644 --- a/vendor/github.com/miekg/dns/sig0.go +++ b/vendor/github.com/miekg/dns/sig0.go @@ -7,7 +7,6 @@ import ( "crypto/rsa" "encoding/binary" "math/big" - "strings" "time" ) @@ -151,7 +150,7 @@ func (rr *SIG) Verify(k *KEY, buf []byte) error { } // If key has come from the DNS name compression might // have mangled the case of the name - if !strings.EqualFold(signername, k.Header().Name) { + if !equal(signername, k.Header().Name) { return &Error{err: "signer name doesn't match key name"} } sigend := offset diff --git a/vendor/github.com/miekg/dns/version.go b/vendor/github.com/miekg/dns/version.go index 00c8629f27..e290e3dff7 100644 --- a/vendor/github.com/miekg/dns/version.go +++ b/vendor/github.com/miekg/dns/version.go @@ -3,7 +3,7 @@ package dns import "fmt" // Version is current version of this library. -var Version = v{1, 1, 62} +var Version = v{1, 1, 63} // v holds the version of this library. type v struct { diff --git a/vendor/github.com/qdm12/dns/v2/LICENSE b/vendor/github.com/qdm12/dns/v2/LICENSE deleted file mode 100644 index 2abb0fa978..0000000000 --- a/vendor/github.com/qdm12/dns/v2/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Quentin McGaw - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/getlocal_unix.go b/vendor/github.com/qdm12/dns/v2/pkg/nameserver/getlocal_unix.go deleted file mode 100644 index 508300a3e5..0000000000 --- a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/getlocal_unix.go +++ /dev/null @@ -1,51 +0,0 @@ -//go:build !js && !windows - -package nameserver - -import ( - "net/netip" - "os" - "strings" -) - -func GetDNSServers() (nameservers []netip.AddrPort) { - const filename = "/etc/resolv.conf" - return getLocalNameservers(filename) -} - -func getLocalNameservers(filename string) (nameservers []netip.AddrPort) { - const defaultNameserverPort = 53 - defaultLocalNameservers := []netip.AddrPort{ - netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), defaultNameserverPort), - netip.AddrPortFrom(netip.AddrFrom16([16]byte{0, 0, 0, 0, 0, 0, 0, 1}), defaultNameserverPort), - } - - data, err := os.ReadFile(filename) - if err != nil { - return defaultLocalNameservers - } - - lines := strings.Split(string(data), "\n") - for _, line := range lines { - if line == "" { - continue - } - fields := strings.Fields(line) - if len(fields) == 0 || fields[0] != "nameserver" { - continue - } - for _, field := range fields[1:] { - ip, err := netip.ParseAddr(field) - if err != nil { - continue - } - nameservers = append(nameservers, - netip.AddrPortFrom(ip, defaultNameserverPort)) - } - } - - if len(nameservers) == 0 { - return defaultLocalNameservers - } - return nameservers -} diff --git a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/getlocal_windows.go b/vendor/github.com/qdm12/dns/v2/pkg/nameserver/getlocal_windows.go deleted file mode 100644 index 06f233dd36..0000000000 --- a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/getlocal_windows.go +++ /dev/null @@ -1,275 +0,0 @@ -package nameserver - -import ( - "errors" - "fmt" - "net/netip" - "syscall" - "unsafe" -) - -func GetDNSServers() (nameservers []netip.AddrPort) { - const defaultDNSPort = 53 - defaultLocalNameservers := []netip.AddrPort{ - netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), defaultDNSPort), - netip.AddrPortFrom(netip.AddrFrom16([16]byte{0, 0, 0, 0, 0, 0, 0, 1}), defaultDNSPort), - } - - adapterAddresses, err := getAdapterAddresses() - if err != nil { - return defaultLocalNameservers - } - - for _, adapterAddress := range adapterAddresses { - const statusUp = 0x01 - if adapterAddress.operStatus != statusUp { - continue - } - - if adapterAddress.firstGatewayAddress == nil { - // Only search DNS servers for adapters having a gateway - continue - } - - dnsServerAddress := adapterAddress.firstDnsServerAddress - for dnsServerAddress != nil { - ip, ok := sockAddressToIP(dnsServerAddress.address.rawSockAddrAny) - if !ok || ipIsSiteLocalAnycast(ip) { - // fec0/10 IPv6 addresses are site local anycast DNS - // addresses Microsoft sets by default if no other - // IPv6 DNS address is set. Site local anycast is - // deprecated since 2004, see - // https://datatracker.ietf.org/doc/html/rfc3879 - dnsServerAddress = dnsServerAddress.next - continue - } - - nameserver := netip.AddrPortFrom(ip, defaultDNSPort) - nameservers = append(nameservers, nameserver) - dnsServerAddress = dnsServerAddress.next - } - } - - if len(nameservers) == 0 { - return defaultLocalNameservers - } - return nameservers -} - -var ( - errBufferOverflowUnexpected = errors.New("unexpected buffer overflowed because buffer was large enough") -) - -func getAdapterAddresses() ( - adapterAddresses []*ipAdapterAddresses, err error) { - var buffer []byte - const initialBufferLength uint32 = 15000 - sizeVar := initialBufferLength - - for { - buffer = make([]byte, sizeVar) - err := runProcGetAdaptersAddresses( - (*ipAdapterAddresses)(unsafe.Pointer(&buffer[0])), - &sizeVar) - if err != nil { - if err.(syscall.Errno) == syscall.ERROR_BUFFER_OVERFLOW { - if sizeVar <= uint32(len(buffer)) { - return nil, fmt.Errorf("%w: buffer size variable %d is "+ - "equal or lower to the buffer current length %d", - errBufferOverflowUnexpected, sizeVar, len(buffer)) - } - continue - } - return nil, fmt.Errorf("getting adapters addresses: %w", err) - } - - noDataFound := sizeVar == 0 - if noDataFound { - return nil, nil - } - break - } - - adapterAddress := (*ipAdapterAddresses)(unsafe.Pointer(&buffer[0])) - for adapterAddress != nil { - adapterAddresses = append(adapterAddresses, adapterAddress) - adapterAddress = adapterAddress.next - } - - return adapterAddresses, nil -} - -var ( - procGetAdaptersAddresses = syscall.NewLazyDLL("iphlpapi.dll"). - NewProc("GetAdaptersAddresses") -) - -func runProcGetAdaptersAddresses(adapterAddresses *ipAdapterAddresses, - sizePointer *uint32) (errcode error) { - const family = syscall.AF_UNSPEC - const GAA_FLAG_SKIP_UNICAST = 0x0001 - const GAA_FLAG_SKIP_ANYCAST = 0x0002 - const GAA_FLAG_SKIP_MULTICAST = 0x0004 - const GAA_FLAG_SKIP_FRIENDLY_NAME = 0x0020 - const GAA_FLAG_INCLUDE_GATEWAYS = 0x0080 - const flags = GAA_FLAG_SKIP_UNICAST | GAA_FLAG_SKIP_ANYCAST | - GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_SKIP_FRIENDLY_NAME | - GAA_FLAG_INCLUDE_GATEWAYS - const reserved = 0 - // See https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses - r1, _, err := syscall.SyscallN(procGetAdaptersAddresses.Addr(), - uintptr(family), uintptr(flags), uintptr(reserved), - uintptr(unsafe.Pointer(adapterAddresses)), - uintptr(unsafe.Pointer(sizePointer))) - switch { - case err != 0: - return err - case r1 != 0: - return syscall.Errno(r1) - default: - return nil - } -} - -func sockAddressToIP(rawSockAddress *syscall.RawSockaddrAny) (ip netip.Addr, ok bool) { - if rawSockAddress == nil { - return netip.Addr{}, false - } - - sockAddress, err := rawSockAddress.Sockaddr() - if err != nil { - return netip.Addr{}, false - } - - switch sockAddress := sockAddress.(type) { - case *syscall.SockaddrInet4: - return netip.AddrFrom4([4]byte{ - sockAddress.Addr[0], sockAddress.Addr[1], sockAddress.Addr[2], sockAddress.Addr[3]}), - true - case *syscall.SockaddrInet6: - return netip.AddrFrom16([16]byte{ - sockAddress.Addr[0], sockAddress.Addr[1], sockAddress.Addr[2], sockAddress.Addr[3], - sockAddress.Addr[4], sockAddress.Addr[5], sockAddress.Addr[6], sockAddress.Addr[7], - sockAddress.Addr[8], sockAddress.Addr[9], sockAddress.Addr[10], sockAddress.Addr[11], - sockAddress.Addr[12], sockAddress.Addr[13], sockAddress.Addr[14], sockAddress.Addr[15]}), - true - default: - return netip.Addr{}, false - } -} - -func ipIsSiteLocalAnycast(ip netip.Addr) bool { - if !ip.Is6() { - return false - } - - array := ip.As16() - return array[0] == 0xfe && array[1] == 0xc0 -} - -// See https://learn.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh -type ipAdapterAddresses struct { - // The order of fields DOES matter since they are read - // raw from a bytes buffer. However, we are only interested - // in a few select fields, so unneeded fields are either - // named as "_" or removed if they are after the fields - // we are interested in. - _ uint32 - _ uint32 - next *ipAdapterAddresses - _ *byte - _ *ipAdapterUnicastAddress - _ *ipAdapterAnycastAddress - _ *ipAdapterMulticastAddress - firstDnsServerAddress *ipAdapterDnsServerAdapter - _ *uint16 - _ *uint16 - _ *uint16 - _ [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte - _ uint32 - _ uint32 - _ uint32 - _ uint32 - operStatus uint32 - _ uint32 - _ [16]uint32 - _ *ipAdapterPrefix - _ uint64 - _ uint64 - _ *ipAdapterWinsServerAddress - firstGatewayAddress *ipAdapterGatewayAddress - // Additional fields not needed here -} - -type ipAdapterUnicastAddress struct { - // The order of fields DOES matter since they are read raw - // from a bytes buffer. However, we are not interested in - // the value of any field, so they are all named as "_". - _ uint32 - _ uint32 - _ *ipAdapterUnicastAddress - _ ipAdapterSocketAddress - _ int32 - _ int32 - _ int32 - _ uint32 - _ uint32 - _ uint32 - _ uint8 -} - -type ipAdapterAnycastAddress struct { - // The order of fields DOES matter since they are read raw - // from a bytes buffer. However, we are not interested in - // the value of any field, so they are all named as "_". - _ uint32 - _ uint32 - _ *ipAdapterAnycastAddress - _ ipAdapterSocketAddress -} - -type ipAdapterMulticastAddress struct { - // The order of fields DOES matter since they are read raw - // from a bytes buffer. However, we are only interested in - // a few select fields, so unneeded fields are named as "_". - _ uint32 - _ uint32 - _ *ipAdapterMulticastAddress - _ ipAdapterSocketAddress -} - -type ipAdapterDnsServerAdapter struct { - // The order of fields DOES matter since they are read raw - // from a bytes buffer. However, we are only interested in - // a few select fields, so unneeded fields are named as "_". - _ uint32 - _ uint32 - next *ipAdapterDnsServerAdapter - address ipAdapterSocketAddress -} - -type ipAdapterPrefix struct { - _ uint32 - _ uint32 - _ *ipAdapterPrefix - _ ipAdapterSocketAddress - _ uint32 -} - -type ipAdapterWinsServerAddress struct { - _ uint32 - _ uint32 - _ *ipAdapterWinsServerAddress - _ ipAdapterSocketAddress -} - -type ipAdapterGatewayAddress struct { - _ uint32 - _ uint32 - _ *ipAdapterGatewayAddress - _ ipAdapterSocketAddress -} - -type ipAdapterSocketAddress struct { - rawSockAddrAny *syscall.RawSockaddrAny -} diff --git a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/internal.go b/vendor/github.com/qdm12/dns/v2/pkg/nameserver/internal.go deleted file mode 100644 index 42abf5e404..0000000000 --- a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/internal.go +++ /dev/null @@ -1,47 +0,0 @@ -package nameserver - -import ( - "context" - "fmt" - "net" - "net/netip" - "time" - - "github.com/qdm12/gosettings" -) - -type SettingsInternalDNS struct { - // IP is the IP address to use for the DNS. - // It defaults to 127.0.0.1 if nil. - IP netip.Addr - // Port is the port to reach the DNS server on. - // It defaults to 53 if left unset. - Port uint16 - // Timeout is the dialer timeout. By default there is - // no timeout. - Timeout time.Duration -} - -func (s *SettingsInternalDNS) SetDefaults() { - s.IP = gosettings.DefaultValidator(s.IP, netip.AddrFrom4([4]byte{127, 0, 0, 1})) - const defaultPort = 53 - s.Port = gosettings.DefaultComparable(s.Port, defaultPort) -} - -func (s SettingsInternalDNS) Validate() (err error) { - return nil -} - -// UseDNSInternally changes the Go program DNS only. -func UseDNSInternally(settings SettingsInternalDNS) { - settings.SetDefaults() - - dialer := net.Dialer{ - Timeout: settings.Timeout, - } - - net.DefaultResolver.PreferGo = true - net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) { - return dialer.DialContext(ctx, "udp", net.JoinHostPort(settings.IP.String(), fmt.Sprint(settings.Port))) - } -} diff --git a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/system.go b/vendor/github.com/qdm12/dns/v2/pkg/nameserver/system.go deleted file mode 100644 index 271849701c..0000000000 --- a/vendor/github.com/qdm12/dns/v2/pkg/nameserver/system.go +++ /dev/null @@ -1,108 +0,0 @@ -package nameserver - -import ( - "errors" - "fmt" - "net/netip" - "os" - "path/filepath" - "strings" - - "github.com/qdm12/gosettings" -) - -type SettingsSystemDNS struct { - // IP is the IP address to use for the DNS. - // It defaults to 127.0.0.1 if nil. - IP netip.Addr - // ResolvPath is the path to the resolv configuration file. - // It defaults to /etc/resolv.conf. - ResolvPath string -} - -func (s *SettingsSystemDNS) SetDefaults() { - s.IP = gosettings.DefaultValidator(s.IP, netip.AddrFrom4([4]byte{127, 0, 0, 1})) - s.ResolvPath = gosettings.DefaultComparable(s.ResolvPath, "/etc/resolv.conf") -} - -var ( - ErrResolvPathIsDirectory = errors.New("resolv path is a directory") -) - -func (s *SettingsSystemDNS) Validate() (err error) { - stat, err := os.Stat(s.ResolvPath) - switch { - case errors.Is(err, os.ErrNotExist): // it will be created - case err != nil: - return fmt.Errorf("stating resolv path: %w", err) - case stat.IsDir(): - return fmt.Errorf("%w: %s", ErrResolvPathIsDirectory, s.ResolvPath) - } - return nil -} - -// UseDNSSystemWide changes the nameserver to use for DNS system wide. -// If resolvConfPath is empty, it defaults to /etc/resolv.conf. -func UseDNSSystemWide(settings SettingsSystemDNS) (err error) { - settings.SetDefaults() - - stat, err := os.Stat(settings.ResolvPath) - switch { - case errors.Is(err, os.ErrNotExist): - return createResolvFile(settings.ResolvPath, settings.IP) - case err != nil: - return fmt.Errorf("stating resolv path: %w", err) - case stat.IsDir(): - return fmt.Errorf("%w: %s", ErrResolvPathIsDirectory, settings.ResolvPath) - } - - return patchResolvFile(settings.ResolvPath, settings.IP) -} - -func createResolvFile(resolvPath string, ip netip.Addr) (err error) { - parentDirectory := filepath.Dir(resolvPath) - const defaultPerms os.FileMode = 0o755 - err = os.MkdirAll(parentDirectory, defaultPerms) - if err != nil { - return fmt.Errorf("creating resolv path parent directory: %w", err) - } - - const filePermissions os.FileMode = 0600 - data := []byte("nameserver " + ip.String() + "\n") - err = os.WriteFile(resolvPath, data, filePermissions) - if err != nil { - return fmt.Errorf("creating resolv file: %w", err) - } - return nil -} - -func patchResolvFile(resolvPath string, ip netip.Addr) (err error) { - data, err := os.ReadFile(resolvPath) - if err != nil { - return fmt.Errorf("reading file: %w", err) - } - - lines := strings.Split(string(data), "\n") - patchedLines := make([]string, 0, len(lines)+1) - patchedLines = append(patchedLines, "nameserver "+ip.String()) - for _, line := range lines { - if !strings.HasPrefix(line, "nameserver ") { - patchedLines = append(patchedLines, line) - } - } - - patchedString := strings.Join(patchedLines, "\n") - patchedString = strings.TrimRight(patchedString, "\n") - hadTrailNewLine := patchedLines[len(patchedLines)-1] == "" - if hadTrailNewLine { - patchedString += "\n" - } - - patchedData := []byte(patchedString) - const permissions os.FileMode = 0600 - err = os.WriteFile(resolvPath, patchedData, permissions) - if err != nil { - return fmt.Errorf("writing resolv file: %w", err) - } - return nil -} diff --git a/vendor/github.com/qdm12/gosettings/.dockerignore b/vendor/github.com/qdm12/gosettings/.dockerignore deleted file mode 100644 index 395dee76aa..0000000000 --- a/vendor/github.com/qdm12/gosettings/.dockerignore +++ /dev/null @@ -1,7 +0,0 @@ -/.devcontainer -/.git -/.github -/.dockerignore -/Dockerfile -/LICENSE -/README.md \ No newline at end of file diff --git a/vendor/github.com/qdm12/gosettings/.golangci.yml b/vendor/github.com/qdm12/gosettings/.golangci.yml deleted file mode 100644 index a1e7a27815..0000000000 --- a/vendor/github.com/qdm12/gosettings/.golangci.yml +++ /dev/null @@ -1,92 +0,0 @@ -linters-settings: - misspell: - locale: US - revive: - rules: - - name: exported - arguments: - - disableStutteringCheck - -issues: - include: - - EXC0012 - exclude-rules: - - text: "exported: exported var Err*" - linters: - - revive - - text: "mnd: Magic number: 127, in detected" - linters: - - gomnd - - path: _test\.go - linters: - - goerr113 - -linters: - enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - containedctx - - cyclop - - decorder - - dogsled - - dupl - - durationcheck - - errchkjson - - errname - - errorlint - - execinquery - - exhaustive - - exportloopref - - forcetypeassert - - gci - - gochecknoglobals - - gochecknoinits - - gocognit - - goconst - - gocritic - - gocyclo - - godot - - goerr113 - - goheader - - goimports - - gomnd - - gomoddirectives - - goprintffuncname - - gosec - - grouper - - importas - - interfacebloat - - ireturn - - lll - - maintidx - - makezero - - misspell - - nakedret - - nestif - - nilerr - - nilnil - - noctx - - nolintlint - - nosprintfhostport - - prealloc - - predeclared - - promlinter - - reassign - - revive - - rowserrcheck - - sqlclosecheck - - tenv - - thelper - - tparallel - - unconvert - - unparam - - usestdlibvars - - wastedassign - - whitespace - -run: - skip-dirs: - - .devcontainer - - .github diff --git a/vendor/github.com/qdm12/gosettings/Dockerfile b/vendor/github.com/qdm12/gosettings/Dockerfile deleted file mode 100644 index d7c9579aea..0000000000 --- a/vendor/github.com/qdm12/gosettings/Dockerfile +++ /dev/null @@ -1,42 +0,0 @@ -ARG ALPINE_VERSION=3.18 -ARG GO_VERSION=1.21 -ARG GOLANGCI_LINT_VERSION=v1.52.2 -ARG MOCKGEN_VERSION=v1.6.0 - -FROM qmcgaw/binpot:golangci-lint-${GOLANGCI_LINT_VERSION} AS golangci-lint -FROM qmcgaw/binpot:mockgen-${MOCKGEN_VERSION} AS mockgen - -FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base -# Note: findutils needed to have xargs support `-d` flag for mocks stage. -RUN apk --update add git g++ findutils -ENV CGO_ENABLED=0 -COPY --from=golangci-lint /bin /go/bin/golangci-lint -COPY --from=mockgen /bin /go/bin/mockgen -WORKDIR /tmp/gobuild -COPY go.mod go.sum ./ -RUN go mod download -COPY . . - -FROM --platform=${BUILDPLATFORM} base AS mocks -RUN git init && \ - git config user.email ci@localhost && \ - git config user.name ci && \ - git config core.fileMode false && \ - git add -A && \ - git commit -m "snapshot" && \ - grep -lr -E '^// Code generated by MockGen\. DO NOT EDIT\.$' . | xargs -r -d '\n' rm && \ - go generate -run "mockgen" ./... && \ - git diff --exit-code && \ - rm -rf .git/ - -FROM base AS test -# Note on the go race detector: -# - we set CGO_ENABLED=1 to have it enabled -# - we installed g++ to support the race detector -ENV CGO_ENABLED=1 -ENTRYPOINT go test -race -coverpkg=./... -coverprofile=coverage.txt -covermode=atomic ./... - -FROM base AS lint -RUN golangci-lint run --timeout=10m - - diff --git a/vendor/github.com/qdm12/gosettings/LICENSE b/vendor/github.com/qdm12/gosettings/LICENSE deleted file mode 100644 index 834bc45523..0000000000 --- a/vendor/github.com/qdm12/gosettings/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Quentin McGaw - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/qdm12/gosettings/README.md b/vendor/github.com/qdm12/gosettings/README.md deleted file mode 100644 index 0df3c989d5..0000000000 --- a/vendor/github.com/qdm12/gosettings/README.md +++ /dev/null @@ -1,142 +0,0 @@ -# Gosettings - -`gosettings` is a Go package providing **helper functions for working with settings**. - -**Go.dev documentation:** - -- [gosettings](https://pkg.go.dev/github.com/qdm12/gosettings) -- [gosettings/validate](https://pkg.go.dev/github.com/qdm12/gosettings/validate) -- [gosettings/reader](https://pkg.go.dev/github.com/qdm12/gosettings/reader) - -Add it to your Go project with: - -```sh -go get github.com/qdm12/gosettings -``` - -💁 Only compatible with Go 1.18+ since it now uses generics. - -Features: - -- Define settings struct methods: - - `Copy`: use `gosettings.CopyPointer` and `gosettings.CopySlice` - - `SetDefaults`: `gosettings.Default*` functions (see [pkg.go.dev/github.com/qdm12/gosettings](https://pkg.go.dev/github.com/qdm12/gosettings)) - - `OverrideWith`: `gosettings.OverrideWith*` functions (see [pkg.go.dev/github.com/qdm12/gosettings](https://pkg.go.dev/github.com/qdm12/gosettings)) - - `Validate`: `validate.*` functions from [`github.com/qdm12/gosettings/validate`](https://pkg.go.dev/github.com/qdm12/gosettings/validate) -- Reading settings from multiple sources with precedence with [`github.com/qdm12/gosettings/reader`](https://pkg.go.dev/github.com/qdm12/gosettings/reader) - - Environment variable implementation `env.New(env.Settings{Environ: os.Environ()})` in subpackage [`github.com/qdm12/gosettings/reader/sources/env`](https://pkg.go.dev/github.com/qdm12/gosettings/reader/sources/env) - - Flag implementation `flag.New(os.Args)` in subpackage [`github.com/qdm12/gosettings/reader/sources/flag`](https://pkg.go.dev/github.com/qdm12/gosettings/reader/sources/flag) -- Minor feature notes: - - No use of `reflect` for better runtime safety - - Single dependency on [kernel.org/pub/linux/libs/security/libcap/cap](https://kernel.org/pub/linux/libs/security/libcap/cap) to validate listening ports for programs with Linux capabalities - -## Philosophy - -After having worked with Go and settings from different sources for years, I have come with a design I am happy with. - -### Settings struct - -Each component has a settings struct, where the zero value of a field should be **meaningless**. -For example, if the value `0` is allowed for a field, then it must be an `*int` field. -On the contrary, you could have an `int` field if the zero value `0` is meaningless. -The reasoning behind this is that you want the zero Go value to be considered as 'unset field' so that the field value can be defaulted and overridden by another settings struct. See the below interface comments for more details on what this allows. - -Next, each of your settings struct should *ideally* implement the following interface: - -```go -type Settings interface { - // SetDefaults sets default values for all unset fields. - // All pointer fields must be defaulted to a non nil value. - // Usage: - // - Once on the base settings at the start of the program. - // - If the user requests a reset of the settings, on an empty settings struct. - SetDefaults() - // Validate validates all the settings and return an error if any field value is invalid. - // It should only be called after `SetDefaults()` is called, and therefore should assume - // all pointer fields are set and NOT nil. - // Usage: - // - Validate settings early at program start - // - Validate new settings given, after calling .Copy() + .OverrideWith(newSettings) - Validate() (err error) - // Copy deep copies all the settings to a new Settings object. - // Usage: - // - Copy settings before modifying them with OverrideWith(), to validate them with Validate() before actually using them. - Copy() Settings - // OverrideWith sets all the set values of the other settings to the fields of the receiver settings. - // Usage: - // - Update settings at runtime - OverrideWith(other Settings) - // ToLinesNode returns a (tree) node with the settings as lines, for displaying settings - // in a formatted tree, where you can nest settings node to display a full settings tree. - ToLinesNode() *gotree.Node - // String returns the string representation of the settings. - // It should simply return `s.ToLinesNode().String()` to show a tree of settings. - String() string -} -``` - -💁 This is my recommendation, and obviously you don't need to: - -- define this interface -- have all these methods exported -- define `ToLinesNode` with [gotree](https://github.com/qdm12/gotree) if you don't want to - -➡️ [**Example settings implementation**](examples/settings/settings.go) - -More concrete settings implementation examples using this library are notably: - -- [Gluetun](https://github.com/qdm12/gluetun/tree/master/internal/configuration) -- [qdm12/dns](https://github.com/qdm12/dns/tree/v2.0.0-beta/internal/config) -- [tinier](https://github.com/qdm12/tinier/tree/main/internal/config) - -### Settings methods usage - -In the following Go examples, we use the [example settings implementation](examples/settings/settings.go). - -#### Read settings from multiple sources - -The `Reader` from the [`github.com/qdm12/gosettings/reader`](https://pkg.go.dev/github.com/qdm12/gosettings/reader) package can be used to read and parse settings from one or more sources. A source implements the interface: - -```go -type Source interface { - String() string - Get(key string) (value string, isSet bool) - KeyTransform(key string) string -} -``` - -There are already defined sources such as `reader.Env` for environment variables. - -A simple example (runnable [here](examples/reader/main.go)) would be: - -```go -flagSource := flag.New([]string{"program", "--key1=A"}) -envSource := env.New(env.Settings{Environ: []string{"KEY1=B", "KEY2=2"}}) -reader := reader.New(reader.Settings{ - Sources: []reader.Source{flagSource, envSource}, -}) - -value := reader.String("KEY1") -// flag source takes precedence -fmt.Println(value) // Prints "A" - -n, err := reader.Int("KEY2") -if err != nil { - panic(err) -} -// flag source has no value, so the environment -// variable source is used. -fmt.Println(n) // Prints "2" -``` - -You can perform more advanced parsing, for example with the methods `BoolPtr`, `CSV`, `Duration`, `Float64`, `Uint16Ptr`, etc. - -Each of these parsing methods accept [some options](reader/options.go), notably to: - -- Force the string value to be lowercased -- Accept empty string values as 'set values' -- Define retro-compatible keys - -#### Updating settings at runtime - -🚧 To be completed 🚧 diff --git a/vendor/github.com/qdm12/gosettings/copy.go b/vendor/github.com/qdm12/gosettings/copy.go deleted file mode 100644 index 5668684310..0000000000 --- a/vendor/github.com/qdm12/gosettings/copy.go +++ /dev/null @@ -1,22 +0,0 @@ -package gosettings - -import ( - "golang.org/x/exp/slices" -) - -// CopyPointer returns a new pointer to the copied value of the -// original argument value. -func CopyPointer[T any](original *T) (copied *T) { - if original == nil { - return nil - } - copied = new(T) - *copied = *original - return copied -} - -// CopySlice returns a new slice with each element of the -// original slice copied. -func CopySlice[T any](original []T) (copied []T) { - return slices.Clone(original) -} diff --git a/vendor/github.com/qdm12/gosettings/defaults.go b/vendor/github.com/qdm12/gosettings/defaults.go deleted file mode 100644 index 5a69913926..0000000000 --- a/vendor/github.com/qdm12/gosettings/defaults.go +++ /dev/null @@ -1,55 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -package gosettings - -// DefaultComparable returns the existing argument if it is not the zero -// value, otherwise it returns the defaultValue argument. -// If used with an interface and an implementation of the interface, -// it must be instantiated with the interface type, for example: -// variable := DefaultComparable[Interface](variable, &implementation{}) -// Avoid using this function for non-interface pointers, use DefaultPointer -// instead to create a new pointer. -func DefaultComparable[T comparable](existing, defaultValue T) (result T) { //nolint:ireturn - var zero T - if existing != zero { - return existing - } - return defaultValue -} - -// DefaultPointer returns the existing argument if it is not nil. -// Otherwise it returns a new pointer to the defaultValue argument. -// To default an interface to an implementation, use DefaultComparable. -func DefaultPointer[T any](existing *T, defaultValue T) (result *T) { - if existing != nil { - return existing - } - result = new(T) - *result = defaultValue - return result -} - -// DefaultSlice returns the existing slice argument if is not nil. -// Otherwise it returns a new slice with the copied values of the -// defaultValue slice argument. -// Note it is preferrable to use this function for added mutation safety -// on the result, but one can use DefaultSliceRaw if performance matters. -func DefaultSlice[T any](existing, defaultValue []T) (result []T) { - if existing != nil || defaultValue == nil { - return existing - } - result = make([]T, len(defaultValue)) - copy(result, defaultValue) - return result -} - -// DefaultValidator returns the existing argument if it is valid, -// otherwise it returns the defaultValue argument. -func DefaultValidator[T SelfValidator](existing, defaultValue T) ( //nolint:ireturn - result T) { - if existing.IsValid() { - return existing - } - return defaultValue -} diff --git a/vendor/github.com/qdm12/gosettings/interfaces.go b/vendor/github.com/qdm12/gosettings/interfaces.go deleted file mode 100644 index 98814c7083..0000000000 --- a/vendor/github.com/qdm12/gosettings/interfaces.go +++ /dev/null @@ -1,9 +0,0 @@ -package gosettings - -// SelfValidator is an interface for a type that can validate itself. -// This is notably the case of netip.IP and netip.Prefix, and can be -// implemented by the user of this library as well. -type SelfValidator interface { - // IsValid returns true if the value is valid, false otherwise. - IsValid() bool -} diff --git a/vendor/github.com/qdm12/gosettings/messages.go b/vendor/github.com/qdm12/gosettings/messages.go deleted file mode 100644 index 0119d5a326..0000000000 --- a/vendor/github.com/qdm12/gosettings/messages.go +++ /dev/null @@ -1,78 +0,0 @@ -package gosettings - -import ( - "math" -) - -// BoolToYesNo returns "yes" if the given boolean is true, -// "no" if the given boolean is false, and an empty string -// if the given boolean pointer is nil. -func BoolToYesNo(b *bool) string { - switch { - case b == nil: - return "" - case *b: - return "yes" - default: - return "no" - } -} - -// ObfuscateKey returns an obfuscated key for logging purposes. -// If the key is empty, `[not set]` is returned. -// If the key has up to 128 bits of security with 2 characters removed, -// it will be obfuscated as `[set]`. -// If the key has at least 128 bits of security if at least 2 -// characters are removed from it, it will be obfuscated as -// `start_of_key...end_of_key`, where the start and end parts -// are each at least 1 character long, and up to 3 characters long. -// Note the security bits are calculated by assuming each unique -// character in the given key is a symbol in the alphabet, -// which gives a worst case scenario regarding the alphabet size. -// This will likely produce lower security bits estimated compared -// to the actual security bits of the key, but it's better this way -// to avoid divulging information about the key when it should not be. -// Finally, the 128 bits security is chosen because this function is -// to be used for logging purposes, which should not be exposed publicly -// either. -func ObfuscateKey(key string) (obfuscatedKey string) { - if key == "" { - return "[not set]" - } - - // Guesstimate on how large the alphabet is for the key - // given. This is the worst case scenario alphabet size - // so it's fine to use this security-wise for this purpose. - uniqueCharacters := make(map[rune]struct{}, len(key)) - for _, r := range key { - uniqueCharacters[r] = struct{}{} - } - numberOfUniqueCharacters := len(uniqueCharacters) - - const minimumSecurityBits = 128 - minimumCharactersCount := int(math.Ceil(minimumSecurityBits / math.Log2(float64(numberOfUniqueCharacters)))) - - charactersToShow := len(key) - minimumCharactersCount - - // No point showing less than 2 characters - const minCharactersToShow = 2 - if charactersToShow < minCharactersToShow { - // not enough security bits in original key - // to divulge any information. - return "[set]" - } - - // No point showing more than 6 characters - const maxCharactersToShow = 6 - if charactersToShow > maxCharactersToShow { - charactersToShow = maxCharactersToShow - } - - const numberOfParts = 2 - startCharacters := charactersToShow / numberOfParts - endCharacters := charactersToShow - startCharacters - - startPart := key[:startCharacters] - endPart := key[len(key)-endCharacters:] - return startPart + "..." + endPart -} diff --git a/vendor/github.com/qdm12/gosettings/override.go b/vendor/github.com/qdm12/gosettings/override.go deleted file mode 100644 index 0337ce0a7d..0000000000 --- a/vendor/github.com/qdm12/gosettings/override.go +++ /dev/null @@ -1,56 +0,0 @@ -//go:build go1.18 -// +build go1.18 - -package gosettings - -// OverrideWithComparable returns the other argument if it is not -// the zero value, otherwise it returns the existing argument. -// If used with an interface and an implementation of the interface, -// it must be instantiated with the interface type, for example: -// variable := OverrideWithComparable[Interface](variable, &implementation{}) -// Avoid using this function for non-interface pointers, use OverrideWithPointer -// instead to create a new pointer. -func OverrideWithComparable[T comparable](existing, other T) (result T) { //nolint:ireturn - var zero T - if other == zero { - return existing - } - return other -} - -// OverrideWithPointer returns the existing argument if the other argument -// is nil. Otherwise it returns a new pointer to the copied value -// of the other argument value, for added mutation safety. -// To override an interface and an implementation, use OverrideWithComparable. -func OverrideWithPointer[T any](existing, other *T) (result *T) { - if other == nil { - return existing - } - result = new(T) - *result = *other - return result -} - -// OverrideWithSlice returns the existing slice argument if the other -// slice argument is nil. Otherwise it returns a new slice with the -// copied values of the other slice argument. -// Note it is preferrable to use this function for added mutation safety -// on the result, but one can use OverrideWithSliceRaw if performance matters. -func OverrideWithSlice[T any](existing, other []T) (result []T) { - if other == nil { - return existing - } - result = make([]T, len(other)) - copy(result, other) - return result -} - -// OverrideWithValidator returns the existing argument if other is not valid, -// otherwise it returns the other argument. -func OverrideWithValidator[T SelfValidator](existing, other T) ( //nolint:ireturn - result T) { - if !other.IsValid() { - return existing - } - return other -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 3088fcbc17..f7ce73a5e8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -92,7 +92,7 @@ github.com/cloudflare/circl/sign/ed448 # github.com/containers/common v0.60.4 ## explicit; go 1.21.0 github.com/containers/common/pkg/strongunits -# github.com/containers/gvisor-tap-vsock v0.8.2 +# github.com/containers/gvisor-tap-vsock v0.8.3 ## explicit; go 1.22.0 github.com/containers/gvisor-tap-vsock/pkg/client github.com/containers/gvisor-tap-vsock/pkg/fs @@ -534,7 +534,7 @@ github.com/mdlayher/vsock # github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d ## explicit github.com/mgutz/ansi -# github.com/miekg/dns v1.1.62 +# github.com/miekg/dns v1.1.63 ## explicit; go 1.19 github.com/miekg/dns # github.com/miekg/pkcs11 v1.1.1 @@ -662,12 +662,6 @@ github.com/power-devops/perfstat # github.com/proglottis/gpgme v0.1.3 ## explicit; go 1.11 github.com/proglottis/gpgme -# github.com/qdm12/dns/v2 v2.0.0-rc6 -## explicit; go 1.21 -github.com/qdm12/dns/v2/pkg/nameserver -# github.com/qdm12/gosettings v0.4.1 -## explicit; go 1.21 -github.com/qdm12/gosettings # github.com/r3labs/sse/v2 v2.10.0 ## explicit; go 1.13 github.com/r3labs/sse/v2