Skip to content

Commit

Permalink
Pull request 317: 379 fix ipv6 upstream
Browse files Browse the repository at this point in the history
Updates #379.

Co-authored-by: Eugene Burkov [email protected]

Squashed commit of the following:

commit 767d954
Author: Stanislav Chzhen <[email protected]>
Date:   Tue Jan 30 19:31:07 2024 +0300

    upstream: imp code

commit 313c715
Author: Stanislav Chzhen <[email protected]>
Date:   Tue Jan 30 18:32:55 2024 +0300

    upstream: add todo

commit 83e1561
Author: Stanislav Chzhen <[email protected]>
Date:   Tue Jan 30 17:41:14 2024 +0300

    upstream: imp code

commit 5c48f20
Author: Stanislav Chzhen <[email protected]>
Date:   Tue Jan 30 14:42:48 2024 +0300

    upstream: fix ipv6 upstream
  • Loading branch information
schzhn authored and EugeneOne1 committed Jan 30, 2024
1 parent d56d33e commit 64814cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func validateUpstreamURL(u *url.URL) (err error) {
}

host := u.Host
// TODO(s.chzhen): Consider using [netutil.SplitHostPort].
h, port, splitErr := net.SplitHostPort(host)
if splitErr == nil {
// Validate port.
Expand All @@ -217,7 +218,14 @@ func validateUpstreamURL(u *url.URL) (err error) {
host = h
}

_, err = netip.ParseAddr(host)
// If it's an IPv6 address enclosed in square brackets with no port.
//
// See https://github.com/AdguardTeam/dnsproxy/issues/379.
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
_, err = netip.ParseAddr(host[1 : len(host)-1])
} else {
_, err = netip.ParseAddr(host)
}
if err == nil {
return nil
}
Expand Down
12 changes: 12 additions & 0 deletions upstream/upstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,18 @@ func TestAddressToUpstream(t *testing.T) {
addr: "h3://one.one.one.one",
opt: opt,
want: "https://one.one.one.one:443",
}, {
addr: "::ffff:1.1.1.1",
opt: nil,
want: "[::ffff:1.1.1.1]:53",
}, {
addr: "https://[2606:4700:4700::1111]/dns-query",
opt: nil,
want: "https://[2606:4700:4700::1111]:443/dns-query",
}, {
addr: "https://[2606:4700:4700::1111]:443/dns-query",
opt: nil,
want: "https://[2606:4700:4700::1111]:443/dns-query",
}}

for _, tc := range testCases {
Expand Down

0 comments on commit 64814cc

Please sign in to comment.