From b79eb1cea964829f287d77af13ff63b1fe872021 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 4 Feb 2022 16:45:23 +0800 Subject: [PATCH] [Fixed] Abnormal rule when host is ip addr --- adapter/inbound/socket.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/adapter/inbound/socket.go b/adapter/inbound/socket.go index f761bd9b..cca260c6 100644 --- a/adapter/inbound/socket.go +++ b/adapter/inbound/socket.go @@ -26,10 +26,20 @@ func NewInner(conn net.Conn, dst string, host string) *context.ConnContext { metadata.NetWork = C.TCP metadata.Type = C.INNER metadata.DNSMode = C.DNSMapping - metadata.AddrType = C.AtypDomainName metadata.Host = host - if _, port, err := parseAddr(dst); err == nil { + metadata.AddrType = C.AtypDomainName + + if ip, port, err := parseAddr(dst); err == nil { metadata.DstPort = port + if host == "" { + metadata.DstIP = ip + if ip.To4() == nil { + metadata.AddrType = C.AtypIPv6 + } else { + metadata.AddrType = C.AtypIPv4 + } + } } + return context.NewConnContext(conn, metadata) }