Routing: fix router select wrong outbound when failed to resolve domain to ip#5138
Routing: fix router select wrong outbound when failed to resolve domain to ip#5138patterniha wants to merge 1 commit intomainfrom
Conversation
f033f0b to
fc7a3c1
Compare
|
我不确定这个是否应该导到默认出站,router 里其它项有这类问题吗 |
routing to default-outbound is for when no-rule-matched not domain-failed-to resolve. in my example ///
All other values are already specified in inbounds, only resolve-domain-to-ip takes a while and it may return error. |
|
My opinion is, this is not a problem. If you don't have IP, it will not match IP rule and go to other rules. User need to define reasonable default outbound. |
|
I want to bypass(route direct) all Iran/China-IPs-Domains and use proxy(or fragment) for others. Can you tell me how I can do this so that I can be sure that no Iran/China-IPs-Domain passes through the proxy? (I use fakedns) /// The problem is not that a domain may not have an IP address, the problem is that a DNS-Server may be unavailable for just a few moments for whatever reason. /// This is a fundamental and security problem, so i reopen it. |
|
。。。 |
|
总是考虑临时不可用的DNS服务器会很麻烦 上次被恶心的是ECH record查询 这路由又来 |
|
想要安全性 未知域没能解出来ip,或者国外ip 这不是理由,不知道在乱改什么 |
It's not a domain problem, it's a dns-server problem, dns-servers may be unavailable for just a moment, for any reason(packet-lost, ...) |
|
Can you change to default direct, some IP to direct and all other IPs to proxy |
This creates other problems, for example foreign-cryptocurrency-websites can see my real-IP, and ban my account(Iran is sanctioned). so domestic-websites should bypass and foreign-websites should pass through the proxy, and neither should replace the other. |
|
You can try default to blackhole |
I already thought about it, the problem is that we make a DNS request after encountering each rule. for example if we have 10 IP-rules and dns-server is not available we send 10 dns-requests and wait 40-seconds!(suppose each request-timeout is 4 seconds) /// also, we may have more than 2-IP-rule(or 2-ip-rule with multiple IPs), so default-blackhole-idea does not work. for example, in serverless-for-Iran i want: So how can you make sure these rules are always strictly enforced? |
|
第一,解不出来ip就应该走代理 第二,解不出来ip直接封锁也可以 第三,路由模块只会发起一到两次dns请求 这三点无论哪一条都能解决你的需求 |
how? This is exactly what this PR does.
No, we have separate requests for each IP-rule, until we get a response and cache the result, then we use the cache for other-IP-rules. |
|
解不出来ip,你就不知道该如何分流,说明是未知域 只需要默认block就行了 然后路由模块发起dns请求次数问题 |
|
In short, if you solve this problem, i close this PR: How can I strictly enforce these rules? |
|
@patterniha 没路由就应该发默认出口 就该减少本地解析次数 |
No, this is completely wrong, if a rule does not have |
|
this is exactly what i say, if a rule does not apply, we go to next-rule. and if a domain failed to resolve to IP(and we use "IPOnDemand"/"IPIfNonMatch"), the IP-rule(rule which has but if a rule does not have |
|
I think the discussion got a bit messy, In short, In many situations we want to: And this PR ensures that these rules are strictly enforced. |
|
I thought about it and found another solution. the problem is that we make a DNS request after encountering each rule, and we only cache the successful query. Xray-core/features/routing/dns/context.go Lines 21 to 23 in 1952488 Xray-core/features/routing/dns/context.go Lines 31 to 34 in 1952488 so we should cache the error as well, otherwise we have dns-request for each IP-rule(if dns-server is not available), and this cause many problems(choosing wrong outbound, waiting too long and ...) also, i can achieve my goal by adding so i close this PR, and open a new PR for caching dns-error. |
|
Please don't cache error, each new DNS request must be retry again |
so if we have 10 IP-rules we have 10 dns-requests and we wait 40 seconds!!! also how to solve: #5138 (comment) @yuhan6665 i think you misunderstood, this cache is only for router in "IPIfNonMatch"/"IPIfNonMatch" mode. in routing we need to use built-in-dns only once for all rules. this cache is only used for one-dispatch and we don't have this cache for next-dispatch |
suppose we want to route domains with range-A IPs to outbound-1, and route others to outbound-2,
and domains with range-A IPs should not be routed to outbound-2 under any circumstances.
so the config is:
suppose the domain "example.com" has ip in range-A, but built-in-dns-servers are unavailable for a while(for any reason), so domain failed to resolve to ip and rule-1 does not apply and rule-2 apply and "example.com" route to outbound-2!!! but "example.com" has range-A ip and should not route to outbound-2.
there are many examples where domains with certain range IPs should not be routed to a specific outbound.
///
As a result, in "IPOnDemand"/"IPIfNonMatch" mode, when a domain failed to resolve to ip(after encountering an ip-rule), router should return error immediately and should not select any outbound.