mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-15 22:39:54 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6529210568 | ||
|
|
009635c229 | ||
|
|
9db67f0e4e | ||
|
|
0fcf8f4dce | ||
|
|
541f8ea3d1 |
@@ -181,26 +181,29 @@ func (h *Handler) Tag() string {
|
||||
func (h *Handler) Dispatch(ctx context.Context, link *transport.Link) {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
content := session.ContentFromContext(ctx)
|
||||
if h.senderSettings != nil && h.senderSettings.TargetStrategy.HasStrategy() && ob.Target.Address.Family().IsDomain() && (content == nil || !content.SkipDNSResolve) {
|
||||
strategy := h.senderSettings.TargetStrategy
|
||||
if ob.Target.Network == net.Network_UDP && ob.OriginalTarget.Address != nil {
|
||||
strategy = strategy.GetDynamicStrategy(ob.OriginalTarget.Address.Family())
|
||||
}
|
||||
ips, err := internet.LookupForIP(ob.Target.Address.Domain(), strategy, nil)
|
||||
if err != nil {
|
||||
errors.LogInfoInner(ctx, err, "failed to resolve ip for target ", ob.Target.Address.Domain())
|
||||
if h.senderSettings.TargetStrategy.ForceIP() {
|
||||
err := errors.New("failed to resolve ip for target ", ob.Target.Address.Domain()).Base(err)
|
||||
session.SubmitOutboundErrorToOriginator(ctx, err)
|
||||
common.Interrupt(link.Writer)
|
||||
common.Interrupt(link.Reader)
|
||||
return
|
||||
}
|
||||
if h.senderSettings != nil && h.senderSettings.TargetStrategy.HasStrategy() && ob.Target.Address.Family().IsDomain() {
|
||||
if session.SkipDNSResolveFromContext(ctx) {
|
||||
errors.LogInfo(ctx, "bypassing targetStrategy ", h.senderSettings.TargetStrategy, " for ", ob.Target, "; preserving target domain")
|
||||
} else {
|
||||
unchangedDomain := ob.Target.Address.Domain()
|
||||
ob.Target.Address = net.IPAddress(ips[dice.Roll(len(ips))])
|
||||
errors.LogInfo(ctx, "target: ", unchangedDomain, " resolved to: ", ob.Target.Address.String())
|
||||
strategy := h.senderSettings.TargetStrategy
|
||||
if ob.Target.Network == net.Network_UDP && ob.OriginalTarget.Address != nil {
|
||||
strategy = strategy.GetDynamicStrategy(ob.OriginalTarget.Address.Family())
|
||||
}
|
||||
ips, err := internet.LookupForIP(ob.Target.Address.Domain(), strategy, nil)
|
||||
if err != nil {
|
||||
errors.LogInfoInner(ctx, err, "failed to resolve ip for target ", ob.Target.Address.Domain())
|
||||
if h.senderSettings.TargetStrategy.ForceIP() {
|
||||
err := errors.New("failed to resolve ip for target ", ob.Target.Address.Domain()).Base(err)
|
||||
session.SubmitOutboundErrorToOriginator(ctx, err)
|
||||
common.Interrupt(link.Writer)
|
||||
common.Interrupt(link.Reader)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
unchangedDomain := ob.Target.Address.Domain()
|
||||
ob.Target.Address = net.IPAddress(ips[dice.Roll(len(ips))])
|
||||
errors.LogInfo(ctx, "target: ", unchangedDomain, " resolved to: ", ob.Target.Address.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
if ob.Target.Network == net.Network_UDP && ob.OriginalTarget.Address != nil && ob.OriginalTarget.Address != ob.Target.Address {
|
||||
|
||||
@@ -44,9 +44,8 @@ func (c routingContext) GetRuleTag() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// GetSkipDNSResolve is a mock implementation here to match the interface,
|
||||
// SkipDNSResolve is set from dns module, no use if coming from a protobuf object?
|
||||
// TODO: please confirm @Vigilans
|
||||
// GetSkipDNSResolve implements routing.Context.
|
||||
// The protobuf RoutingContext has no skip flag, so API contexts use false.
|
||||
func (c routingContext) GetSkipDNSResolve() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -77,6 +77,11 @@ func ContentFromContext(ctx context.Context) *Content {
|
||||
return nil
|
||||
}
|
||||
|
||||
func SkipDNSResolveFromContext(ctx context.Context) bool {
|
||||
content := ContentFromContext(ctx)
|
||||
return content != nil && content.SkipDNSResolve
|
||||
}
|
||||
|
||||
func ContextWithIsReverseMux(ctx context.Context, isReverseMux bool) context.Context {
|
||||
return context.WithValue(ctx, isReverseMuxKey, isReverseMux)
|
||||
}
|
||||
|
||||
@@ -285,6 +285,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
}
|
||||
ob.Name = "freedom"
|
||||
ob.CanSpliceCopy = 1
|
||||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
var defaultRule *FinalRule
|
||||
if !h.usesDialerProxy { // freedom is not the final outbound, final rules do not apply (and the domain is not resolved)
|
||||
@@ -311,6 +312,13 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
||||
}
|
||||
}
|
||||
|
||||
if h.resolveStrategy.HasStrategy() && session.SkipDNSResolveFromContext(ctx) {
|
||||
errors.LogInfo(ctx, "using AsIs instead of sockopt.domainStrategy ", h.resolveStrategy, " for connection to ", destination, " (including UDP packet targets)")
|
||||
handler := *h
|
||||
handler.resolveStrategy = internet.DomainStrategy_AS_IS
|
||||
h = &handler
|
||||
}
|
||||
|
||||
input := link.Reader
|
||||
output := link.Writer
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
|
||||
|
||||
errors.LogInfo(ctx, "opening connection to ", destination)
|
||||
content := new(session.Content)
|
||||
content.SkipDNSResolve = true
|
||||
content.SkipDNSResolve = session.SkipDNSResolveFromContext(ctx)
|
||||
content.SniffingRequest = l.sniffingRequest
|
||||
|
||||
ctx = session.ContextWithContent(ctx, content)
|
||||
|
||||
@@ -248,7 +248,7 @@ func DialSystem(ctx context.Context, dest net.Destination, sockopt *SocketConfig
|
||||
dest = *newDest
|
||||
}
|
||||
|
||||
if sockopt.DomainStrategy.HasStrategy() && dest.Address.Family().IsDomain() {
|
||||
if sockopt.DomainStrategy.HasStrategy() && dest.Address.Family().IsDomain() && !(outboundName == "freedom" && session.SkipDNSResolveFromContext(ctx)) {
|
||||
finalStrategy := sockopt.DomainStrategy
|
||||
if outboundName == "freedom" && dest.Network == net.Network_UDP && origTargetAddr != nil && src == nil {
|
||||
finalStrategy = finalStrategy.GetDynamicStrategy(origTargetAddr.Family())
|
||||
|
||||
@@ -17,7 +17,7 @@ func DialTaggedOutbound(ctx context.Context, dispatcher routing.Dispatcher, dest
|
||||
return nil, errors.New("Instance context variable is not in context, dial denied. ")
|
||||
}
|
||||
content := new(session.Content)
|
||||
content.SkipDNSResolve = true
|
||||
content.SkipDNSResolve = tag != ""
|
||||
|
||||
ctx = session.ContextWithContent(ctx, content)
|
||||
ctx = session.SetForcedOutboundTagToContext(ctx, tag)
|
||||
|
||||
Reference in New Issue
Block a user