diff --git a/app/proxyman/outbound/handler.go b/app/proxyman/outbound/handler.go index df7d52a4..3819f52b 100644 --- a/app/proxyman/outbound/handler.go +++ b/app/proxyman/outbound/handler.go @@ -273,7 +273,16 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (stat.Connecti outbounds := session.OutboundsFromContext(ctx) ob := outbounds[len(outbounds)-1] if h.senderSettings.ViaCidr == "" { - ob.Gateway = h.senderSettings.Via.AsAddress() + if h.senderSettings.Via.AsAddress().Family().IsDomain() && h.senderSettings.Via.AsAddress().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) + } + } + } else { + ob.Gateway = h.senderSettings.Via.AsAddress() + } } else { //Get a random address. ob.Gateway = ParseRandomIPv6(h.senderSettings.Via.AsAddress(), h.senderSettings.ViaCidr) } diff --git a/infra/conf/xray.go b/infra/conf/xray.go index 4de55bad..a9cc88bc 100644 --- a/infra/conf/xray.go +++ b/infra/conf/xray.go @@ -292,7 +292,9 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) { senderSettings.ViaCidr = strings.Split(*c.SendThrough, "/")[1] } else { if address.Family().IsDomain() { - return nil, errors.New("unable to send through: " + address.String()) + if address.Address.Domain() != "origin" { + return nil, errors.New("unable to send through: " + address.String()) + } } } senderSettings.Via = address.Build()