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 not able to query IPv6 DNS servers because of too many colons in address #30

Merged
merged 5 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"fmt"
"net"
"runtime"
"time"

Expand Down Expand Up @@ -60,6 +61,11 @@ func SendDNSQuery(client *dns.Client, msg dns.Msg, dnsServerIP string) (*dns.Msg
logrus.Fatal("Please specify a DNS server IP explicitly with the `--dns-server-ip` flag.")
}
dnsServerIP = conf.Servers[0]

}
// If the server IP is IPv6, wrap it in square brackets to remove ambiguity from port number and address.
if net.ParseIP(dnsServerIP).To4() == nil {
dnsServerIP = "[" + dnsServerIP + "]"
Copy link
Owner

@bschaatsbergen bschaatsbergen Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation: I suggest checking whether the parsed dnsServerIP includes a trailing port. If it does, we should use the IP along with the trailing port. If there's no trailing port, consider appending :53 to the dnsServerIP.

Additionally, we should address another issue by allowing the user to pass a custom port through the --dns-server-ip flag. This would ensure support for a broader range of possibilities when wanting to query your own DNS server, folks tend to typically do so because they have either a custom port or use IPv6 for instance.

I'm curious to hear what you think. Also, I have doubts about the bracket notation; it seems a bit unclear, vague and not that 'clean' to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR to address your comment regarding the custom ports.
Besides that, I've cleaned up the implementation. JoinHostPort(..) does the exact same validation as I implemented before, but all in a single line 😄

}

logrus.Debugf("Sending DNS query to %s", dnsServerIP)
Expand Down
Loading