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

feat(network): add DNS fallback (truncated) PacketProxy #26

Merged
merged 10 commits into from
Jul 24, 2023

Conversation

jyyi1
Copy link
Contributor

@jyyi1 jyyi1 commented Jun 26, 2023

I added dnstruncated.NewPacketProxy() to the SDK. This type can be used when the remote Shadowsocks server doesn't support UDP traffic at all. By using this PacketProxy, we will always set the TC (truncated) bit in the DNS responses for all UDP DNS requests. So a well-implemented DNS client (e.g. the browser, the dig command) should retry the same DNS request over TCP.

Related PR: #24 , #27

Copy link
Contributor

@fortuna fortuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose a change to lwip2transport.Device that would make it easier to provide custom handlers. See comments.

transport/dnstruncate/packet_listener.go Outdated Show resolved Hide resolved
transport/dnstruncate/packet_listener.go Outdated Show resolved Hide resolved
jyyi1 added a commit that referenced this pull request Jul 19, 2023
This PR introduces a network stack neutral `network.PacketProxy` that can be used to **relay** (e.g. a UDP proxy server) or **process** (e.g. a local DNS server) UDP packets. It is more efficient than the `transport.PacketListener` when you try to implement a local UDP server that can process UDP requests and get the responses without going to the internet (see #26 ).
network/packet_proxy_mock.go Outdated Show resolved Hide resolved
if !h.closed.CompareAndSwap(false, true) {
return network.ErrClosed
}
h.respWriter.Close() // TODO(junyi): potential inf loop (rw.Close -> req.Close -> rw.Close ...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you figure out the loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no problem for this (because I've checked closed), but I will create another one with both the fix and a reproducing test case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see the TODO there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a reproducing test in #30 , will fix the potential issue in that pr.

network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Show resolved Hide resolved
@jyyi1 jyyi1 requested a review from fortuna July 20, 2023 23:15
if !h.closed.CompareAndSwap(false, true) {
return network.ErrClosed
}
h.respWriter.Close() // TODO(junyi): potential inf loop (rw.Close -> req.Close -> rw.Close ...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see the TODO there

network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
network/dnstruncate/packet_proxy.go Show resolved Hide resolved
@jyyi1 jyyi1 changed the title feat(transport): add DNS fallback (truncated) PacketListener feat(network): add DNS fallback (truncated) PacketProxy Jul 21, 2023
@jyyi1 jyyi1 requested a review from fortuna July 21, 2023 19:01
network/dnstruncate/packet_proxy.go Outdated Show resolved Hide resolved
@jyyi1 jyyi1 merged commit 35b8cde into main Jul 24, 2023
4 checks passed
@jyyi1 jyyi1 deleted the junyi/dns-fallback-legacy branch July 24, 2023 15:33
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.

2 participants