-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for IDNA #640
base: master
Are you sure you want to change the base?
Add support for IDNA #640
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
"golang.org/x/net/idna" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
@@ -55,6 +56,8 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b | |
fallbackProtocol = "ip6" | ||
} | ||
|
||
target = internationalizeDNSDomain(logger, target) | ||
|
||
level.Info(logger).Log("msg", "Resolving target address", "ip_protocol", IPProtocol) | ||
resolveStart := time.Now() | ||
|
||
|
@@ -119,3 +122,18 @@ func ipHash(ip net.IP) float64 { | |
h.Write(ip) | ||
return float64(h.Sum32()) | ||
} | ||
|
||
func internationalizeDNSDomain(logger log.Logger, domain string) string { | ||
if net.ParseIP(domain) != nil { | ||
// IP addresses don't need to be internationalized. | ||
return domain | ||
} | ||
idnaDomain, err := idna.Lookup.ToASCII(domain) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should be silently ignoring errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow we pass :: in some tests, which creates an error disallowed rune U+003A. I need to investigate why, but I was thinking that it would be safe to ignore those errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what's going on here. You have to try to handle the hostname as an IP address (either IPv4 or IPv6), Basically:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks |
||
return domain | ||
} | ||
if idnaDomain != domain { | ||
level.Info(logger).Log("msg", "Domain internationalized", "unicode", domain, "ascii", idnaDomain) | ||
} | ||
return idnaDomain | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is correct, let's leave this out.