mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-08 01:43:35 +03:00
Outbound: Fix sendthrough srcip precheck (#4750)
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
parent
af7a76da67
commit
028e1114e6
@ -279,11 +279,9 @@ func (h *Handler) Dial(ctx context.Context, dest net.Destination) (stat.Connecti
|
|||||||
|
|
||||||
outbounds := session.OutboundsFromContext(ctx)
|
outbounds := session.OutboundsFromContext(ctx)
|
||||||
ob := outbounds[len(outbounds)-1]
|
ob := outbounds[len(outbounds)-1]
|
||||||
addr := h.senderSettings.Via.AsAddress()
|
|
||||||
var domain string
|
var domain string
|
||||||
if addr.Family().IsDomain() {
|
addr := h.senderSettings.Via.AsAddress()
|
||||||
domain = addr.Domain()
|
domain = h.senderSettings.Via.GetDomain()
|
||||||
}
|
|
||||||
switch {
|
switch {
|
||||||
case h.senderSettings.ViaCidr != "":
|
case h.senderSettings.ViaCidr != "":
|
||||||
ob.Gateway = ParseRandomIP(addr, 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":
|
case domain == "origin":
|
||||||
|
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
||||||
origin, _, err := net.SplitHostPort(inbound.Conn.LocalAddr().String())
|
if inbound.Conn != nil {
|
||||||
if err == nil {
|
origin, _, err := net.SplitHostPort(inbound.Conn.LocalAddr().String())
|
||||||
ob.Gateway = net.ParseAddress(origin)
|
if err == nil {
|
||||||
|
ob.Gateway = net.ParseAddress(origin)
|
||||||
|
errors.LogDebug(ctx, "use receive package ip as snedthrough: ", origin)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
case domain == "srcip":
|
case domain == "srcip":
|
||||||
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
if inbound := session.InboundFromContext(ctx); inbound != nil {
|
||||||
srcip, _, err := net.SplitHostPort(inbound.Conn.RemoteAddr().String())
|
if inbound.Conn != nil {
|
||||||
if err == nil {
|
clientaddr, _, err := net.SplitHostPort(inbound.Conn.RemoteAddr().String())
|
||||||
ob.Gateway = net.ParseAddress(srcip)
|
if err == nil {
|
||||||
|
ob.Gateway = net.ParseAddress(clientaddr)
|
||||||
|
errors.LogDebug(ctx, "use client src ip as snedthrough: ", clientaddr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//case addr.Family().IsDomain():
|
//case addr.Family().IsDomain():
|
||||||
default:
|
default:
|
||||||
|
@ -292,7 +292,8 @@ func (c *OutboundDetourConfig) Build() (*core.OutboundHandlerConfig, error) {
|
|||||||
senderSettings.ViaCidr = strings.Split(*c.SendThrough, "/")[1]
|
senderSettings.ViaCidr = strings.Split(*c.SendThrough, "/")[1]
|
||||||
} else {
|
} else {
|
||||||
if address.Family().IsDomain() {
|
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())
|
return nil, errors.New("unable to send through: " + address.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user