mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-02-22 16:50:43 +00:00
Outbound: Add outbound sendThrough origin behavior (#4349)
* added support of sending through origin for outbounds * added strings package import * usage of net.SplitHostPort instead of manual splitting --------- Co-authored-by: poly <poly@>
This commit is contained in:
parent
b786a50aee
commit
89792aee9d
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user