From 7542884451656a6e200ad761dba32c900a0cef4b Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sun, 26 Feb 2023 20:33:50 +0800 Subject: [PATCH] chore: log shows dialMode --- control/control_plane.go | 12 ++++++------ control/tcp.go | 4 +++- control/udp.go | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/control/control_plane.go b/control/control_plane.go index ba2ad76..1cf4926 100644 --- a/control/control_plane.go +++ b/control/control_plane.go @@ -405,22 +405,22 @@ func (c *ControlPlane) dnsUpstreamReadyCallback(raw *url.URL, dnsUpstream *dns.U return nil } -func (c *ControlPlane) ChooseDialTarget(outbound consts.OutboundIndex, dst netip.AddrPort, domain string) (dialTarget string) { - mode := consts.DialMode_Ip +func (c *ControlPlane) ChooseDialTarget(outbound consts.OutboundIndex, dst netip.AddrPort, domain string) (dialTarget string, dialMode consts.DialMode) { + dialMode = consts.DialMode_Ip if !outbound.IsReserved() && domain != "" { switch c.dialMode { case consts.DialMode_Domain: cache := c.dnsController.LookupDnsRespCache(domain, common.AddrToDnsType(dst.Addr())) if cache != nil && cache.IncludeIp(dst.Addr()) { - mode = consts.DialMode_Domain + dialMode = consts.DialMode_Domain } case consts.DialMode_DomainPlus: - mode = consts.DialMode_Domain + dialMode = consts.DialMode_Domain } } - switch mode { + switch dialMode { case consts.DialMode_Ip: dialTarget = dst.String() case consts.DialMode_Domain: @@ -430,7 +430,7 @@ func (c *ControlPlane) ChooseDialTarget(outbound consts.OutboundIndex, dst netip "to": dialTarget, }).Debugln("Rewrite dial target to domain") } - return dialTarget + return dialTarget, dialMode } func (c *ControlPlane) ListenAndServe(port uint16) (err error) { diff --git a/control/tcp.go b/control/tcp.go index 9dd945d..6d9b35b 100644 --- a/control/tcp.go +++ b/control/tcp.go @@ -97,6 +97,7 @@ func (c *ControlPlane) handleConn(lConn net.Conn) (err error) { return fmt.Errorf("failed to select dialer from group %v (%v): %w", outbound.Name, networkType.String(), err) } + dialTarget, dialMode := c.ChooseDialTarget(outboundIndex, dst, domain) if c.log.IsLevelEnabled(logrus.InfoLevel) { c.log.WithFields(logrus.Fields{ "network": networkType.String(), @@ -107,11 +108,12 @@ func (c *ControlPlane) handleConn(lConn net.Conn) (err error) { "pid": routingResult.Pid, "pname": ProcessName2String(routingResult.Pname[:]), "mac": Mac2String(routingResult.Mac[:]), + "dialMode": dialMode, }).Infof("%v <-> %v", RefineSourceToShow(src, dst.Addr(), consts.LanWanFlag_NotApplicable), RefineAddrPortToShow(dst)) } // Dial and relay. - rConn, err := d.Dial(MagicNetwork("tcp", routingResult.Mark), c.ChooseDialTarget(outboundIndex, dst, domain)) + rConn, err := d.Dial(MagicNetwork("tcp", routingResult.Mark), dialTarget) if err != nil { return fmt.Errorf("failed to dial %v: %w", dst, err) } diff --git a/control/udp.go b/control/udp.go index 9e9f066..00080bd 100644 --- a/control/udp.go +++ b/control/udp.go @@ -193,7 +193,7 @@ func (c *ControlPlane) handlePkt(lConn *net.UDPConn, data []byte, src, pktDst, r // TODO: Rewritten domain should not use full-cone (such as VMess Packet Addr). // Maybe we should set up a mapping for UDP: Dialer + Target Domain => Remote Resolved IP. // However, games may not use QUIC for communication, thus we cannot use domain to dial, which is fine. - dialTarget := c.ChooseDialTarget(outboundIndex, realDst, domain) + dialTarget, dialMode := c.ChooseDialTarget(outboundIndex, realDst, domain) // Get udp endpoint. var ue *UdpEndpoint @@ -266,6 +266,7 @@ getNew: "pid": routingResult.Pid, "pname": ProcessName2String(routingResult.Pname[:]), "mac": Mac2String(routingResult.Mac[:]), + "dialMode": dialMode, } c.log.WithFields(fields).Infof("%v <-> %v", RefineSourceToShow(realSrc, realDst.Addr(), lanWanFlag), RefineAddrPortToShow(realDst)) }