Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix all ns mode #305

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions pkg/miekg/miekg.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ func (s *RoutineLookupFactory) Initialize(c *zdns.GlobalConf) {
LocalAddr: &net.UDPAddr{IP: s.LocalAddr},
}
if c.RecycleSockets {
// create PacketConn for use throughout thread's life
conn, err := net.ListenUDP("udp", &net.UDPAddr{s.LocalAddr, 0, ""})
if err != nil {
log.Fatal("unable to create socket", err)
}
s.Conn = new(dns.Conn)
s.Conn.Conn = conn
}
// create PacketConn for use throughout thread's life
conn, err := net.ListenUDP("udp", &net.UDPAddr{s.LocalAddr, 0, ""})
if err != nil {
log.Fatal("unable to create socket", err)
}
s.Conn = new(dns.Conn)
s.Conn.Conn = conn
}
}
if !c.UDPOnly {
s.TCPClient = new(dns.Client)
Expand Down Expand Up @@ -320,10 +320,10 @@ func DoLookupWorker(udp *dns.Client, tcp *dns.Client, conn *dns.Conn, q Question
if udp != nil {
res.Protocol = "udp"
if conn != nil {
dst, _ := net.ResolveUDPAddr("udp", nameServer)
r, _, err = udp.ExchangeWithConnTo(m, conn, dst)
dst, _ := net.ResolveUDPAddr("udp", nameServer)
r, _, err = udp.ExchangeWithConnTo(m, conn, dst)
} else {
r, _, err = udp.Exchange(m, nameServer)
r, _, err = udp.Exchange(m, nameServer)
}
// if record comes back truncated, but we have a TCP connection, try again with that
if r != nil && (r.Truncated || r.Rcode == dns.RcodeBadTrunc) {
Expand Down Expand Up @@ -809,6 +809,7 @@ func (s *Lookup) DoIpsLookup(lc LookupClient, name string, nameServer string, dn
}

func (s *Lookup) DoTargetedLookup(l LookupClient, name, nameServer string, lookupIpv4 bool, lookupIpv6 bool) (interface{}, []interface{}, zdns.Status, error) {
name = strings.ToLower(name)
res := IpResult{}
candidateSet := map[string][]Answer{}
cnameSet := map[string][]Answer{}
Expand Down Expand Up @@ -944,7 +945,8 @@ func (s *Lookup) DoLookupAllNameservers(l LookupClient, name, nameServer string)
for _, nserver := range nsResults.Servers {
// Use all the ipv4 and ipv6 addresses of each nameserver
nameserver := nserver.Name
ips := append(nserver.IPv4Addresses, nserver.IPv6Addresses...)
// TODO(#304): Figure out how to lookup via IPv6 addresses as well
ips := nserver.IPv4Addresses
for _, ip := range ips {
curServer = net.JoinHostPort(ip, "53")
res, trace, status, _ := l.ProtocolLookup(s, Question{Name: name, Type: s.DNSType, Class: s.DNSClass}, curServer)
Expand Down
28 changes: 3 additions & 25 deletions pkg/miekg/miekg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,9 @@ func TestErrorInTargetedLookup(t *testing.T) {
assert.Equal(t, status, protocolStatus[domain_ns_1])
}

// Test One NS with one IP with only ipv4-lookup
// Test One NS with one IP with only ipv4-lookup. Note that
// currently we do lookup only via IPv4 NS addresses and hence
// IPv6 NS addresses are ignored.
func TestAllNsLookupOneNs(t *testing.T) {
gc, a, mc := InitTest(t)

Expand Down Expand Up @@ -1001,36 +1003,12 @@ func TestAllNsLookupOneNs(t *testing.T) {
Flags: DNSFlags{},
}

ns3 := net.JoinHostPort(ipv6_1, "53")
domain_ns_3 := domain_ns{domain: domain1, ns: ns3}
ipv4_3 := "192.0.2.2"
mockResults[domain_ns_3] = Result{
Answers: []interface{}{
Answer{
Ttl: 3600,
Type: "A",
Class: "IN",
Name: "example.com.",
Answer: ipv4_3,
},
},
Additional: nil,
Authorities: nil,
Protocol: "",
Flags: DNSFlags{},
}

expectedRes := []ExtendedResult{
{
Nameserver: ns_domain1,
Status: zdns.STATUS_NOERROR,
Res: mockResults[domain_ns_2],
},
{
Nameserver: ns_domain1,
Status: zdns.STATUS_NOERROR,
Res: mockResults[domain_ns_3],
},
}

res, _, _, _ := a.DoLookupAllNameservers(mc, "example.com", ns1)
Expand Down