Skip to content

Commit

Permalink
fix unmap 4in6 ip in wireguard
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Mar 21, 2024
1 parent 3f493a4 commit 5b2a568
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion adapter/outbound/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ func NewWireGuard(option WireGuardOption) (*WireGuard, error) {
return address.AddrPort(), nil
}
udpAddr, err := resolveUDPAddr(ctx, "udp", address.String())
return udpAddr.AddrPort(), err
if err != nil {
return netip.AddrPort{}, err
}
// net.ResolveUDPAddr maybe return 4in6 address, so unmap at here
addrPort := udpAddr.AddrPort()
return netip.AddrPortFrom(addrPort.Addr().Unmap(), addrPort.Port()), nil
}

var reserved [3]uint8
Expand Down
2 changes: 1 addition & 1 deletion dns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (r *Resolver) ipExchange(ctx context.Context, m *D.Msg) (msg *D.Msg, err er
func (r *Resolver) lookupIP(ctx context.Context, host string, dnsType uint16) ([]netip.Addr, error) {

if ip, err := netip.ParseAddr(host); err == nil {
isIPv4 := ip.Is4()
isIPv4 := ip.Is4() || ip.Is4In6()
if dnsType == D.TypeAAAA && !isIPv4 {
return []netip.Addr{ip}, nil
} else if dnsType == D.TypeA && isIPv4 {
Expand Down

0 comments on commit 5b2a568

Please sign in to comment.