Skip to content

Commit 8756e05

Browse files
committed
cleanup
1 parent 6334048 commit 8756e05

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

hinting/dns_search_domain_fallbacks.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ func domainsFromHostnames(hostnames []string) (domains []string) {
1313
domains = append(domains, "local")
1414
continue
1515
}
16-
domainString := ""
16+
domain := ""
1717
slices.Reverse(labels)
1818
for _, label := range labels[:len(labels)-1] {
19-
if domainString == "" {
20-
domainString = label
19+
if domain == "" {
20+
domain = label
2121
// do not add TLD to domains candidate list
2222
continue
2323
}
24-
domainString = strings.Join([]string{label, domainString}, ".")
24+
domain = strings.Join([]string{label, domain}, ".")
2525
// Filter out Effective ccTLDs (of the form "co.uk"), as we are only interested in the ETLD+1 domains
26-
if 5 == len(domainString) && // TODO: complete TLD specific exceptions, or directly use PSL
26+
if 5 == len(domain) && // TODO: complete TLD specific exceptions, or directly use PSL
2727
(label == "co" ||
2828
label == "ac" ||
2929
label == "re" ||
3030
label == "ne") {
3131
// do not add country-code second-level ETLD domains to domains candidate list
3232
continue
3333
}
34-
if !slices.Contains(domains, domainString) {
35-
domains = append(domains, domainString)
34+
if !slices.Contains(domains, domain) {
35+
domains = append(domains, domain)
3636
}
3737
}
3838
}
3939
// order search domains by hostname from most specific to least specific,
40-
// a more specific search domains of an earlier hostname might sort after
40+
// a more specific search domain of an earlier hostname might sort after
4141
// a search domain derived from a later hostname.
4242
slices.Reverse(domains)
4343
return

hinting/dns_search_domain_fallbacks_reverse.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,68 +28,68 @@ func reverseLookupDomains(addr netip.Addr) (domains []string) {
2828
// Fallbacks to obtain an external public IP address using DNS.
2929

3030
// getAkaNS returns one random authoritative nameserver for akamai.net.
31-
func getAkaNS() (nameserver *string, err error) {
31+
func getAkaNS() (nameserver string, err error) {
3232
// try default resolver
3333
resolver := net.Resolver{}
3434
ctx := context.TODO()
3535
nameservers, err := resolver.LookupNS(ctx, akamaiDomain)
3636
if err == nil {
37-
return &nameservers[rand.Intn(len(nameservers))].Host, err
37+
return nameservers[rand.Intn(len(nameservers))].Host, err
3838
}
3939

4040
m := new(dns.Msg)
4141
m.SetQuestion(akamaiDomain, dns.TypeNS)
4242
// try Quad9
4343
in, err := dns.Exchange(m, quad9DNSResolver)
4444
if err != nil {
45-
return nil, err
45+
return "", err
4646
}
4747
if len(in.Answer) < 1 {
4848
err = errors.New("getAkaNS: No DNS RR answer")
49-
return nil, err
49+
return "", err
5050
}
5151
if ns, ok := in.Answer[rand.Intn(len(in.Answer))].(*dns.NS); ok {
52-
return &ns.Ns, nil
52+
return ns.Ns, nil
5353
}
54-
return nil, errors.New("getAkaNS: Invalid NS record")
54+
return "", errors.New("getAkaNS: Invalid NS record")
5555
}
5656

5757
// getExternalIP returns the external IP used for DNS resolution of the executing host using nameserver.
58-
func getExternalIPbyNS(nameserver *string) (addr *netip.Addr, err error) {
59-
if nameserver == nil {
58+
func getExternalIP(nameserver string) (addr netip.Addr, err error) {
59+
if nameserver == "" {
6060
// Default external authoritative nameserver
61-
nameserver = &akamaiNameserver
61+
nameserver = akamaiNameserver
6262
}
6363
m := new(dns.Msg)
6464
// The akamai.net nameservers reply to queries for the name `whoami`
6565
// with the IP address of the host sending the query.
6666
m.SetQuestion("whoami.akamai.net.", dns.TypeA)
67-
in, err := dns.Exchange(m, net.JoinHostPort(*nameserver, "53"))
67+
in, err := dns.Exchange(m, net.JoinHostPort(nameserver, "53"))
6868
if err != nil {
69-
return nil, err
69+
return netip.Addr{}, err
7070
}
7171
if len(in.Answer) < 1 {
7272
err = errors.New("getExternalIP: No DNS RR answer")
73-
return nil, err
73+
return netip.Addr{}, err
7474
}
7575
if a, ok := in.Answer[0].(*dns.A); ok {
7676
if addr, ok := netip.AddrFromSlice(a.A); ok {
77-
return &addr, nil
77+
return addr, nil
7878
}
79-
return nil, &net.AddrError{Err: "invalid IP address", Addr: a.A.String()}
79+
return netip.Addr{}, &net.AddrError{Err: "invalid IP address", Addr: a.A.String()}
8080
}
81-
return nil, errors.New("getExternalIP: Invalid A record")
81+
return netip.Addr{}, errors.New("getExternalIP: Invalid A record")
8282
}
8383

8484
// queryExternalIP returns the external IP used for DNS resolution of the executing host.
85-
func queryExternalIP() (addr *netip.Addr, err error) {
85+
func queryExternalIP() (addr netip.Addr, err error) {
8686
// Try with default NS
87-
addr, err = getExternalIPbyNS(nil)
87+
addr, err = getExternalIP("")
8888
if err != nil {
8989
// try with looking up alternative NS
9090
ns, err := getAkaNS()
9191
if err == nil {
92-
addr, err = getExternalIPbyNS(ns)
92+
addr, err = getExternalIP(ns)
9393
}
9494
}
9595
return

hinting/dns_search_domain_fallbacks_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
)
88

99
func TestReverseLookupDomains(t *testing.T) {
10-
1110
testCases := []struct {
1211
name string
1312
values []struct {
@@ -74,6 +73,7 @@ func TestReverseLookupDomains(t *testing.T) {
7473
},
7574
},
7675
}
76+
7777
for _, tc := range testCases {
7878
t.Log(tc.name)
7979
for _, v := range tc.values {
@@ -86,7 +86,6 @@ func TestReverseLookupDomains(t *testing.T) {
8686
}
8787

8888
func TestDomainsFromHostnamesDerivation(t *testing.T) {
89-
9089
testCases := []struct {
9190
name string
9291
values []struct {

0 commit comments

Comments
 (0)