Skip to content
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

Fakedns #309

Merged
merged 4 commits into from
Mar 7, 2021
Merged

Fakedns #309

merged 4 commits into from
Mar 7, 2021

Conversation

yuhan6665
Copy link
Member

Port from
v2fly/v2ray-core#406
v2fly/v2ray-core#696
v2fly/v2ray-core#697
and some conflicts are resolved.
See original pr and commits for details.

xiaokangwang and others added 4 commits February 26, 2021 16:58
* Add fake dns

A new config object "fake" in DnsObject for toggling fake dns function

Compare with sniffing, fake dns is not limited to http and tls traffic.
It works across all inbounds. For example, when dns request come
from one inbound, the local DNS server of v2ray will response with a
unique fake IP for every unique domain name. Then later on v2ray
received a request to one of the fake IP from any inbounds, it will
override the request destination with the previously saved domain.

By default, v2ray cache up to 65535 addresses. The old records will
be discarded bases on LRU. The fake IP will be 240.x.x.x

* fix an edge case when encounter a fake IP in use

* Move lru to common.cache package

* Added the necessary change to obtain request IP from sniffer

* Refactor the code so that it may stop depending on global variables in the future.

* Replace string manipulation code with more generic codes, hopefully this will work for both IPv4 and IPv6 networks.

* Try to use IPv4 version of address if possible

* Added Test Case for Fake Dns

* Added More Test Case for Fake Dns

* Stop user from creating a instance with LRU size more than subnet size, it will create a infinite loop

* Move Fake DNS to a separate package

* Generated Code for fakedns

* Encapsulate Fake DNS as a Instance wide service

* Added Support for metadata sniffer, which will be used for Fake DNS

* Dependency injection for fake dns

* Fake DNS As a Sniffer

* Remove stub object

* Remove global variable

* Update generated protobuf file for metadata only sniffing

* Apply Fake DNS config to session

* Loading for fake dns settings

* Bug fix

* Include fake dns in all

* Fix FakeDns Lint Condition

* Fix sniffer config

* Fix lint message

* Fix dependency resolution

* Fix fake dns not loaded as sniffer

* reduce ttl for fake dns

* Apply Coding Style

* Apply Coding Style

* Apply Coding Style

* Apply Coding Style

* Apply Coding Style

* Fix crashed when no fake dns

* Apply Coding Style

* Fix Fake DNS do not apply to UDP socket

* Fixed a bug prevent FakeDNS App Setting from become effective

* Fixed a caveat prevent FakeDNS App Setting from become effective

* Use log comparison to reduce in issue when it comes to really high value typical for ipv6 subnet

* Add build tag for fakedns

* Removal of FakeDNS specific logic at DNS client: making it a standard dns client

* Regenerate auto generated file

* Amended version of configure file

* Bug fixes for fakeDNS

* Bug fixes for fakeDNS

* Fix test: remove reference to removed attribute

* Test: fix codacy issue

* Conf: Remove old field support

* Test: fix codacy issue

* Change test scale for TestFakeDnsHolderCreateMappingAndRollOver

* Test: fix codacy issue

Co-authored-by: yuhan6665 <1588741+yuhan6665@users.noreply.github.com>
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: kslr <kslrwang@gmail.com>
Turn off fake DNS for request sent from Routing and Freedom outbound.
Fake DNS now only apply to DNS outbound.
This is important for Android, where VPN service take over all system DNS
traffic and pass it to core.  "UseIp" option can be used in Freedom outbound
to avoid getting fake IP and fail connection.

Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Fallback means if the request IP is in the range of fakes,
when fakeDNS cache missed (most likely due to reboot), "tls" and "http"
sniffer will be used to identify domain
With the default ip range, now it is guarentee to return different ip within
4 hours.
It helps when core is rebooted, new DNS request still get fresh ip,
If there is request to the old fake ips, fake DNS can't find the domain,
other sniffers will get a chance to work.

Also fix an edge case where element is wrongly brought to top of LRU
@RPRX
Copy link
Member

RPRX commented Mar 5, 2021

感谢 PR,我触发一下测试

@RPRX RPRX closed this Mar 5, 2021
@RPRX RPRX reopened this Mar 5, 2021
@RPRX
Copy link
Member

RPRX commented Mar 6, 2021

这个 PR 需要补充些什么吗

@yuhan6665
Copy link
Member Author

这个 PR 需要补充些什么吗

没啥了吧,对于这几个提交如果有问题可以讨论

@RPRX RPRX merged commit f50eff5 into XTLS:main Mar 7, 2021
@RPRX
Copy link
Member

RPRX commented Mar 7, 2021

存在一些问题需要修复,合并前测试是 ok 的,合并后测试不通过,可能和昨天改了 DNS 有关

yuhan6665 added a commit to yuhan6665/Xray-core that referenced this pull request Mar 7, 2021
ghost pushed a commit that referenced this pull request Mar 7, 2021
Co-Authored-By: yuhan6665 <1588741+yuhan6665@users.noreply.github.com>
RPRX pushed a commit that referenced this pull request Mar 7, 2021
Co-authored-by: yuhan6665 <1588741+yuhan6665@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants