-
Notifications
You must be signed in to change notification settings - Fork 8.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ip match feature for dns #2037
Conversation
Reviewers @vcptr |
按照工作逻辑, 又重新理解了一下,应该叫 |
是的,找了几个相关的
|
@vcptr 配置已经修改为 |
@weaving118 实现的代码比较清晰,基本OK的~ |
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4) | ||
if len(s.tag) > 0 { | ||
ctx = session.ContextWithInbound(ctx, &session.Inbound{ | ||
Tag: s.tag, | ||
}) | ||
} | ||
ips, err := client.QueryIP(ctx, domain, option) | ||
ips, err = s.Match(idx, client, domain, ips) | ||
cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里判断应该在cancle()后调用,Match返回后可直接返回;
然后在调用queryIPTimeout
的循环内,判断err == ErrExpectedIPNonMatch可马上执行continue,或者进一步判断虑如果用户没有配置下一个服务器情况下,强行使用本次结果。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 这里在
queryIPTimeout
应该是单个DNS查询处理结果,对是否继续下一个,应该还是需要放在lookupIPInternal
中处理了。 - 现在DNS策略是如果都配置了expectIPs,且都没有不匹配,返回nil,这个也比较符合预期,强行返回可能返回被墙的IP或者非当前就近IP(一般推荐是最后一个不填写expectIPs,这样就不会匹配了)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
再提交了commit,这里也再优化了下,按这几天事件跑的情况,如果第一个DNS返回是empty response
,基本第二个也是nil,所有如果是empty response
等错误,直接返回了
|
@vcptr 有空帮忙再看看,多谢。 |
有一个类似功能的软件 DnsChooser,可以参考下 |
这个流程图里面的 expectIPs 没有“否”的情况 https://github.com/weaving118/manual/raw/master/resources/dns_flowchart.svg?sanitize=true |
背景
添加的功能逻辑
有IP配置
项,当解析到域名返回的IP都不在当前IP段时,继续下一个DNS解析没有IP配置
项,和原来逻辑一致添加配置示例:
逻辑参考
相关issue
PS