fix: unmap 4in6 address in dialer and wireguard
This commit is contained in:
parent
a973a6c7d2
commit
c0fc5d142f
2 changed files with 10 additions and 5 deletions
|
@ -77,7 +77,7 @@ type wgNetDialer struct {
|
||||||
var _ dialer.NetDialer = &wgNetDialer{}
|
var _ dialer.NetDialer = &wgNetDialer{}
|
||||||
|
|
||||||
func (d wgNetDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
func (d wgNetDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
return d.tunDevice.DialContext(ctx, network, M.ParseSocksaddr(address))
|
return d.tunDevice.DialContext(ctx, network, M.ParseSocksaddr(address).Unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWireGuard(option WireGuardOption) (*WireGuard, error) {
|
func NewWireGuard(option WireGuardOption) (*WireGuard, error) {
|
||||||
|
@ -225,7 +225,7 @@ func (w *WireGuard) DialContext(ctx context.Context, metadata *C.Metadata, opts
|
||||||
conn, err = dialer.NewDialer(options...).DialContext(ctx, "tcp", metadata.RemoteAddress())
|
conn, err = dialer.NewDialer(options...).DialContext(ctx, "tcp", metadata.RemoteAddress())
|
||||||
} else {
|
} else {
|
||||||
port, _ := strconv.Atoi(metadata.DstPort)
|
port, _ := strconv.Atoi(metadata.DstPort)
|
||||||
conn, err = w.tunDevice.DialContext(ctx, "tcp", M.SocksaddrFrom(metadata.DstIP, uint16(port)))
|
conn, err = w.tunDevice.DialContext(ctx, "tcp", M.SocksaddrFrom(metadata.DstIP, uint16(port)).Unwrap())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -257,7 +257,7 @@ func (w *WireGuard) ListenPacketContext(ctx context.Context, metadata *C.Metadat
|
||||||
metadata.DstIP = ip
|
metadata.DstIP = ip
|
||||||
}
|
}
|
||||||
port, _ := strconv.Atoi(metadata.DstPort)
|
port, _ := strconv.Atoi(metadata.DstPort)
|
||||||
pc, err = w.tunDevice.ListenPacket(ctx, M.SocksaddrFrom(metadata.DstIP, uint16(port)))
|
pc, err = w.tunDevice.ListenPacket(ctx, M.SocksaddrFrom(metadata.DstIP, uint16(port)).Unwrap())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,13 +302,18 @@ func parseAddr(ctx context.Context, network, address string, preferResolver reso
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "-1", fmt.Errorf("dns resolve failed: %w", err)
|
return nil, "-1", fmt.Errorf("dns resolve failed: %w", err)
|
||||||
}
|
}
|
||||||
|
for i, ip := range ips {
|
||||||
|
if ip.Is4In6() {
|
||||||
|
ips[i] = ip.Unmap()
|
||||||
|
}
|
||||||
|
}
|
||||||
return ips, port, nil
|
return ips, port, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortationAddr(ips []netip.Addr) (ipv4s, ipv6s []netip.Addr) {
|
func sortationAddr(ips []netip.Addr) (ipv4s, ipv6s []netip.Addr) {
|
||||||
for _, v := range ips {
|
for _, v := range ips {
|
||||||
if v.Is4() || v.Is4In6() {
|
if v.Is4() { // 4in6 parse was in parseAddr
|
||||||
ipv4s = append(ipv4s, v.Unmap())
|
ipv4s = append(ipv4s, v)
|
||||||
} else {
|
} else {
|
||||||
ipv6s = append(ipv6s, v)
|
ipv6s = append(ipv6s, v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue