Skip to content

Commit

Permalink
Don't repeat back-to-back types in parameter lists (#216)
Browse files Browse the repository at this point in the history
This makes parameter lists a bit easier to read and conforms with
typical Golang style to use type elisions where applicable.
  • Loading branch information
Joshua Crowgey committed Apr 23, 2020
1 parent dc1de7a commit 7aeaa21
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion interface.go
Expand Up @@ -47,7 +47,7 @@ import (
// one Lookup per IP/name/connection ==========================================
//
type Lookup interface {
DoLookup(name string, nameServer string) (interface{}, []interface{}, Status, error)
DoLookup(name, nameServer string) (interface{}, []interface{}, Status, error)
DoZonefileLookup(record *dns.Token) (interface{}, Status, error)
}

Expand Down
2 changes: 1 addition & 1 deletion lookup.go
Expand Up @@ -67,7 +67,7 @@ func parseNormalInputLine(line string) (string, string) {
}
}

func makeName(name string, prefix string, nameOverride string) (string, bool) {
func makeName(name, prefix, nameOverride string) (string, bool) {
if nameOverride != "" {
return nameOverride, true
}
Expand Down
7 changes: 4 additions & 3 deletions modules/alookup/alookup.go
Expand Up @@ -36,14 +36,14 @@ type Lookup struct {
miekg.Lookup
}

func (s *Lookup) DoLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
if nameServer == "" {
nameServer = s.Factory.Factory.RandomNameServer()
}
return s.DoTargetedLookup(name, nameServer)
}

func (s *Lookup) doLookupProtocol(name string, nameServer string, dnsType uint16, candidateSet map[string][]miekg.Answer, cnameSet map[string][]miekg.Answer, origName string, depth int) ([]string, []interface{}, zdns.Status, error) {
func (s *Lookup) doLookupProtocol(name, nameServer string, dnsType uint16, candidateSet map[string][]miekg.Answer, cnameSet map[string][]miekg.Answer, origName string, depth int) ([]string, []interface{}, zdns.Status, error) {
// avoid infinite loops
if name == origName && depth != 0 {
return nil, make([]interface{}, 0), zdns.STATUS_ERROR, errors.New("Infinite redirection loop")
Expand All @@ -63,6 +63,7 @@ func (s *Lookup) doLookupProtocol(name string, nameServer string, dnsType uint16
if status != zdns.STATUS_NOERROR || err != nil {
return nil, trace, status, err
}

for _, a := range miekgResult.(miekg.Result).Answers {
// filter only valid answers of requested type or CNAME (#163)
if ans, ok := a.(miekg.Answer); ok {
Expand Down Expand Up @@ -115,7 +116,7 @@ func (s *Lookup) doLookupProtocol(name string, nameServer string, dnsType uint16
}
}

func (s *Lookup) DoTargetedLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoTargetedLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
res := Result{}
candidateSet := map[string][]miekg.Answer{}
cnameSet := map[string][]miekg.Answer{}
Expand Down
4 changes: 2 additions & 2 deletions modules/axfr/axfr.go
Expand Up @@ -51,7 +51,7 @@ func dotName(name string) string {
return strings.Join([]string{name, "."}, "")
}

func (s *Lookup) DoAXFR(name string, server string) AXFRServerResult {
func (s *Lookup) DoAXFR(name, server string) AXFRServerResult {
var retv AXFRServerResult
retv.Server = server
// check if the server address is blacklisted and if so, exclude
Expand Down Expand Up @@ -95,7 +95,7 @@ func (s *Lookup) DoAXFR(name string, server string) AXFRServerResult {
return retv
}

func (s *Lookup) DoLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
var retv AXFRResult
if nameServer == "" {
parsedNS, trace, status, err := s.DoNSLookup(name, true, false, nameServer)
Expand Down
2 changes: 1 addition & 1 deletion modules/bindversion/bindversion.go
Expand Up @@ -33,7 +33,7 @@ type Lookup struct {
miekg.Lookup
}

func (s *Lookup) DoLookup(_ string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(_, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
var res Result
res.Resolver = nameServer
innerRes, trace, status, err := s.DoTxtLookup("VERSION.BIND", nameServer)
Expand Down
22 changes: 11 additions & 11 deletions modules/miekg/miekg.go
Expand Up @@ -332,12 +332,12 @@ func (s *Lookup) Initialize(nameServer string, dnsType uint16, dnsClass uint16,
return nil
}

func (s *Lookup) doLookup(dnsType uint16, dnsClass uint16, name string, nameServer string, recursive bool) (Result, zdns.Status, error) {
func (s *Lookup) doLookup(dnsType, dnsClass uint16, name, nameServer string, recursive bool) (Result, zdns.Status, error) {
return DoLookupWorker(s.Factory.Client, s.Factory.TCPClient, dnsType, dnsClass, name, nameServer, recursive)
}

// Expose the inner logic so other tools can use it
func DoLookupWorker(udp *dns.Client, tcp *dns.Client, dnsType uint16, dnsClass uint16, name string, nameServer string, recursive bool) (Result, zdns.Status, error) {
func DoLookupWorker(udp *dns.Client, tcp *dns.Client, dnsType, dnsClass uint16, name, nameServer string, recursive bool) (Result, zdns.Status, error) {
res := Result{Answers: []interface{}{}, Authorities: []interface{}{}, Additional: []interface{}{}}
res.Resolver = nameServer

Expand Down Expand Up @@ -440,7 +440,7 @@ func (s *Lookup) cacheUpdate(layer string, result Result, depth int) {
}
}

func (s *Lookup) tracedRetryingLookup(dnsType uint16, dnsClass uint16, name string, nameServer string, recursive bool) (Result, []interface{}, zdns.Status, error) {
func (s *Lookup) tracedRetryingLookup(dnsType, dnsClass uint16, name, nameServer string, recursive bool) (Result, []interface{}, zdns.Status, error) {

res, status, err := s.retryingLookup(dnsType, dnsClass, name, nameServer, recursive)

Expand All @@ -462,7 +462,7 @@ func (s *Lookup) tracedRetryingLookup(dnsType uint16, dnsClass uint16, name stri
return res, trace, status, err
}

func (s *Lookup) retryingLookup(dnsType uint16, dnsClass uint16, name string, nameServer string, recursive bool) (Result, zdns.Status, error) {
func (s *Lookup) retryingLookup(dnsType, dnsClass uint16, name, nameServer string, recursive bool) (Result, zdns.Status, error) {
s.VerboseLog(1, "****WIRE LOOKUP*** ", dns.TypeToString[dnsType], " ", name, " ", nameServer)

var origTimeout time.Duration
Expand Down Expand Up @@ -492,7 +492,7 @@ func (s *Lookup) retryingLookup(dnsType uint16, dnsClass uint16, name string, na
panic("loop must return")
}

func (s *Lookup) cachedRetryingLookup(dnsType uint16, dnsClass uint16, name string, nameServer string, layer string, depth int) (Result, IsCached, zdns.Status, error) {
func (s *Lookup) cachedRetryingLookup(dnsType, dnsClass uint16, name, nameServer, layer string, depth int) (Result, IsCached, zdns.Status, error) {
var isCached IsCached
isCached = false
s.VerboseLog(depth+1, "Cached retrying lookup. Name: ", name, ", Layer: ", layer, ", Nameserver: ", nameServer)
Expand Down Expand Up @@ -557,7 +557,7 @@ func (s *Lookup) cachedRetryingLookup(dnsType uint16, dnsClass uint16, name stri
return result, isCached, status, err
}

func nameIsBeneath(name string, layer string) (bool, string) {
func nameIsBeneath(name, layer string) (bool, string) {
name = strings.ToLower(name)
layer = strings.ToLower(layer)
name = strings.TrimSuffix(name, ".")
Expand All @@ -571,7 +571,7 @@ func nameIsBeneath(name string, layer string) (bool, string) {
return false, ""
}

func nextAuthority(name string, layer string) (string, error) {
func nextAuthority(name, layer string) (string, error) {
// We are our own authority for PTRs
// (This is dealt with elsewhere)
if strings.HasSuffix(name, "in-addr.arpa") && layer == "." {
Expand Down Expand Up @@ -707,7 +707,7 @@ func handleStatus(status *zdns.Status, err error) (*zdns.Status, error) {
}
}

func (s *Lookup) iterateOnAuthorities(dnsType uint16, dnsClass uint16, name string,
func (s *Lookup) iterateOnAuthorities(dnsType, dnsClass uint16, name string,
depth int, result Result, layer string, trace []interface{}) (Result, []interface{}, zdns.Status, error) {
//
if len(result.Authorities) == 0 {
Expand Down Expand Up @@ -755,7 +755,7 @@ func (s *Lookup) iterateOnAuthorities(dnsType uint16, dnsClass uint16, name stri
return r, trace, zdns.STATUS_ERROR, errors.New("could not find authoritative name server")
}

func (s *Lookup) iterativeLookup(dnsType uint16, dnsClass uint16, name string, nameServer string,
func (s *Lookup) iterativeLookup(dnsType, dnsClass uint16, name, nameServer string,
depth int, layer string, trace []interface{}) (Result, []interface{}, zdns.Status, error) {
//
if log.GetLevel() == log.DebugLevel {
Expand Down Expand Up @@ -808,7 +808,7 @@ func (s *Lookup) iterativeLookup(dnsType uint16, dnsClass uint16, name string, n
}
}

func (s *Lookup) DoMiekgLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoMiekgLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
if s.DNSType == dns.TypePTR {
var err error
name, err = dns.ReverseAddr(name)
Expand Down Expand Up @@ -912,7 +912,7 @@ func (s *Lookup) DoTxtLookup(name string, nameServer string) (string, []interfac
}

// allow miekg to be used as a ZDNS module
func (s *Lookup) DoLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
return s.DoMiekgLookup(name, nameServer)
}

Expand Down
4 changes: 2 additions & 2 deletions modules/mxlookup/mxlookup.go
Expand Up @@ -57,7 +57,7 @@ func dotName(name string) string {
return strings.Join([]string{name, "."}, "")
}

func (s *Lookup) LookupIPs(name string, nameServer string) (CachedAddresses, []interface{}) {
func (s *Lookup) LookupIPs(name, nameServer string) (CachedAddresses, []interface{}) {
s.Factory.Factory.CHmu.Lock()
// XXX this should be changed to a miekglookup
res, found := s.Factory.Factory.CacheHash.Get(name)
Expand Down Expand Up @@ -103,7 +103,7 @@ func (s *Lookup) LookupIPs(name string, nameServer string) (CachedAddresses, []i
return retv, trace
}

func (s *Lookup) DoLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
retv := Result{Servers: []MXRecord{}}
res, trace, status, err := s.DoTypedMiekgLookup(name, dns.TypeMX, nameServer)
if status != zdns.STATUS_NOERROR {
Expand Down
4 changes: 2 additions & 2 deletions modules/nslookup/nslookup.go
Expand Up @@ -63,7 +63,7 @@ func (s *Lookup) lookupIPs(name string, dnsType uint16, nameServer string) ([]st
return addresses, trace
}

func (s *Lookup) DoNSLookup(name string, lookupIPv4 bool, lookupIPv6 bool, nameServer string) (Result, []interface{}, zdns.Status, error) {
func (s *Lookup) DoNSLookup(name string, lookupIPv4, lookupIPv6 bool, nameServer string) (Result, []interface{}, zdns.Status, error) {
var retv Result
res, trace, status, err := s.DoTypedMiekgLookup(name, dns.TypeNS, nameServer)
if status != zdns.STATUS_NOERROR || err != nil {
Expand Down Expand Up @@ -124,7 +124,7 @@ func (s *Lookup) DoNSLookup(name string, lookupIPv4 bool, lookupIPv6 bool, nameS

}

func (s *Lookup) DoLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
return s.DoNSLookup(name, s.Factory.Factory.IPv4Lookup, s.Factory.Factory.IPv6Lookup, nameServer)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/spf/spf.go
Expand Up @@ -32,7 +32,7 @@ type Lookup struct {
miekg.Lookup
}

func (s *Lookup) DoLookup(name string, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
func (s *Lookup) DoLookup(name, nameServer string) (interface{}, []interface{}, zdns.Status, error) {
var res Result
innerRes, trace, status, err := s.DoTxtLookup(name, nameServer)
if status != zdns.STATUS_NOERROR {
Expand Down

0 comments on commit 7aeaa21

Please sign in to comment.