Satisfying staticcheck linter

This commit is contained in:
Cuong Manh Le
2023-08-10 00:33:42 +07:00
committed by Cuong Manh Le
parent 5dd6336953
commit d292e03d1b
8 changed files with 18 additions and 49 deletions
+1 -1
View File
@@ -15,5 +15,5 @@ type LeaseFileFormat string
const ( const (
Dnsmasq LeaseFileFormat = "dnsmasq" Dnsmasq LeaseFileFormat = "dnsmasq"
IscDhcpd = "isc-dhcpd" IscDhcpd LeaseFileFormat = "isc-dhcpd"
) )
+4 -25
View File
@@ -50,10 +50,9 @@ var (
) )
var ( var (
v = viper.NewWithOptions(viper.KeyDelimiter("::")) v = viper.NewWithOptions(viper.KeyDelimiter("::"))
defaultConfigWritten = false defaultConfigFile = "ctrld.toml"
defaultConfigFile = "ctrld.toml" rootCertPool *x509.CertPool
rootCertPool *x509.CertPool
) )
var basicModeFlags = []string{"listen", "primary_upstream", "secondary_upstream", "domains"} var basicModeFlags = []string{"listen", "primary_upstream", "secondary_upstream", "domains"}
@@ -897,7 +896,6 @@ func readConfigFile(writeDefaultConfig bool) bool {
} }
mainLog.Load().Info().Msg("writing default config file to: " + fp) mainLog.Load().Info().Msg("writing default config file to: " + fp)
} }
defaultConfigWritten = true
return false return false
} }
@@ -1382,7 +1380,7 @@ func fieldErrorMsg(fe validator.FieldError) string {
case "cidr": case "cidr":
return fmt.Sprintf("invalid value: %s", fe.Value()) return fmt.Sprintf("invalid value: %s", fe.Value())
case "required_unless", "required": case "required_unless", "required":
return fmt.Sprintf("value is required") return "value is required"
case "dnsrcode": case "dnsrcode":
return fmt.Sprintf("invalid DNS rcode value: %s", fe.Value()) return fmt.Sprintf("invalid DNS rcode value: %s", fe.Value())
case "ipstack": case "ipstack":
@@ -1396,25 +1394,6 @@ func fieldErrorMsg(fe validator.FieldError) string {
return "" return ""
} }
// couldBeDirectListener reports whether ctrld can be a direct listener on port 53.
// It returns true only if ctrld can listen on port 53 for all interfaces. That means
// there's no other software listening on port 53.
//
// If someone listening on port 53, or ctrld could only listen on port 53 for a specific
// interface, ctrld could only be configured as a DNS forwarder.
func couldBeDirectListener(lc *ctrld.ListenerConfig) bool {
if lc == nil || lc.Port != 53 {
return false
}
switch lc.IP {
case "", "::", "0.0.0.0":
return true
default:
return false
}
}
func isLoopback(ipStr string) bool { func isLoopback(ipStr string) bool {
ip := net.ParseIP(ipStr) ip := net.ParseIP(ipStr)
if ip == nil { if ip == nil {
-11
View File
@@ -326,17 +326,6 @@ var (
windowsEADDRINUSE = syscall.Errno(10048) windowsEADDRINUSE = syscall.Errno(10048)
) )
func errUrlConnRefused(err error) bool {
var urlErr *url.Error
if errors.As(err, &urlErr) {
var opErr *net.OpError
if errors.As(urlErr.Err, &opErr) {
return errors.Is(opErr.Err, syscall.ECONNREFUSED) || errors.Is(opErr.Err, windowsECONNREFUSED)
}
}
return false
}
func errUrlNetworkError(err error) bool { func errUrlNetworkError(err error) bool {
var urlErr *url.Error var urlErr *url.Error
if errors.As(err, &urlErr) { if errors.As(err, &urlErr) {
+2 -4
View File
@@ -98,11 +98,9 @@ func (m *mdns) probeLoop(conns []*net.UDPConn, remoteAddr net.Addr, quitCh chan
if err != nil { if err != nil {
ctrld.ProxyLogger.Load().Warn().Err(err).Msg("error while probing mdns") ctrld.ProxyLogger.Load().Warn().Err(err).Msg("error while probing mdns")
bo.BackOff(context.Background(), errors.New("mdns probe backoff")) bo.BackOff(context.Background(), errors.New("mdns probe backoff"))
continue
} }
select { break
case <-quitCh:
break
}
} }
<-quitCh <-quitCh
for _, conn := range conns { for _, conn := range conns {
+2 -1
View File
@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore U1000 satisfy CI. //lint:file-ignore U1000 Ignore, this file is forked from upstream code.
//lint:file-ignore ST1005 Ignore, this file is forked from upstream code.
package dns package dns
+2
View File
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//lint:file-ignore U1000 Ignore this file, it's a copy.
package dns package dns
import ( import (
+6
View File
@@ -1,6 +1,7 @@
package router package router
import ( import (
"bytes"
"fmt" "fmt"
"net" "net"
"os" "os"
@@ -116,6 +117,11 @@ func (or *osRouter) Cleanup() error {
return nil return nil
} }
func isPfsense() bool {
b, err := os.ReadFile("/etc/platform")
return err == nil && bytes.HasPrefix(b, []byte("pfSense"))
}
const bsdInitScript = `#!/bin/sh const bsdInitScript = `#!/bin/sh
# PROVIDE: {{.Name}} # PROVIDE: {{.Name}}
+1 -7
View File
@@ -93,8 +93,7 @@ func IsOldOpenwrt() bool {
var routerPlatform atomic.Pointer[router] var routerPlatform atomic.Pointer[router]
type router struct { type router struct {
name string name string
sendClientInfo bool
} }
// Name returns name of the router platform. // Name returns name of the router platform.
@@ -241,8 +240,3 @@ func unameU() []byte {
out, _ := exec.Command("uname", "-u").Output() out, _ := exec.Command("uname", "-u").Output()
return out return out
} }
func isPfsense() bool {
b, err := os.ReadFile("/etc/platform")
return err == nil && bytes.HasPrefix(b, []byte("pfSense"))
}