From 028e1114e65db1c6ecd28b86fcfa49b59b845b0e Mon Sep 17 00:00:00 2001 From: Aubrey Yang Date: Fri, 6 Jun 2025 10:54:15 +0900 Subject: [PATCH] Outbound: Fix sendthrough srcip precheck (#4750) Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- app/proxyman/outbound/handler.go | 26 +++++++++++++++----------- infra/conf/xray.go | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index 45821b0c..bc9c635b 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -279,11 +279,9 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (stat.Connecti outbounds := session.OutboundsFromContext(ctx) ob := outbounds[len(outbounds)-1] - addr := h.senderSettings.Via.AsAddress() var domain string - if addr.Family().IsDomain() { - domain = addr.Domain() - } + addr := h.senderSettings.Via.AsAddress() + domain = h.senderSettings.Via.GetDomain() switch { case h.senderSettings.ViaCidr != "": ob.Gateway = ParseRandomIP(addr, h.senderSettings.ViaCidr) @@ -291,18 +289,24 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (stat.Connecti case domain == "origin": if inbound := session.InboundFromContext(ctx); inbound != nil { - origin, _, err := net.SplitHostPort(inbound.Conn.LocalAddr().String()) - if err == nil { - ob.Gateway = net.ParseAddress(origin) + if inbound.Conn != nil { + origin, _, err := net.SplitHostPort(inbound.Conn.LocalAddr().String()) + if err == nil { + ob.Gateway = net.ParseAddress(origin) + errors.LogDebug(ctx, "use receive package ip as snedthrough: ", origin) + } } - } case domain == "srcip": if inbound := session.InboundFromContext(ctx); inbound != nil { - srcip, _, err := net.SplitHostPort(inbound.Conn.RemoteAddr().String()) - if err == nil { - ob.Gateway = net.ParseAddress(srcip) + if inbound.Conn != nil { + clientaddr, _, err := net.SplitHostPort(inbound.Conn.RemoteAddr().String()) + if err == nil { + ob.Gateway = net.ParseAddress(clientaddr) + errors.LogDebug(ctx, "use client src ip as snedthrough: ", clientaddr) + } } + } //case addr.Family().IsDomain(): default: diff --git a/infra/conf/xray.go b/infra/conf/xray.go index 4b084b56..42b8fa4d 100644 --- a/infra/conf/xray.go +++ b/infra/conf/xray.go @@ -292,7 +292,8 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) { senderSettings.ViaCidr = strings.Split(*c.SendThrough, "/")[1] } else { if address.Family().IsDomain() { - if address.Address.Domain() != "origin" { + domain := address.Address.Domain() + if domain != "origin" && domain != "srcip" { return nil, errors.New("unable to send through: " + address.String()) } }