[GH-ISSUE #2220] Allow passing in a custom client UDP socket to send data from #926

Closed
opened 2026-03-16 00:59:35 +03:00 by kerem · 5 comments
Owner

Originally created by @jamilbk on GitHub (May 24, 2024).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2220

Is your feature request related to a problem? Please describe.
We use hickory (thanks for the library!) to send DNS requests from a VPN tunnel process. If the server we're sending the requests to happens to be in the VPN's routing table (for example, 0.0.0.0/0 for full-route tunneling), a packet loop ensues and the request never reaches the server. This is because we have no control over the socket created by hickory to send the query from.

Describe the solution you'd like
It would be great if there was some way to pass in our own socket so that we can configure it as necessary to prevent packet loops. Another option would be to somehow return or expose a function for "getting at" the socket so we can apply the necessary config to it then.

Describe alternatives you've considered
Forking hickory to implement our own patch.

Additional context
This would be mainly used for Android and Linux platforms that don't have automatic packet loop detection, and instead rely on protect in Android and fwmark in Linux to signal to the routing table not to route the packet back into the VPN interface. Apple's NECP seems to automagically prevent this case for Apple platforms (macOS / iOS tested).

Originally created by @jamilbk on GitHub (May 24, 2024). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/2220 **Is your feature request related to a problem? Please describe.** We use hickory (thanks for the library!) to send DNS requests from a VPN tunnel process. If the server we're sending the requests to happens to be in the VPN's routing table (for example, `0.0.0.0/0` for full-route tunneling), a packet loop ensues and the request never reaches the server. This is because we have no control over the socket created by hickory to send the query from. **Describe the solution you'd like** It would be great if there was some way to pass in our own socket so that we can configure it as necessary to prevent packet loops. Another option would be to somehow return or expose a function for "getting at" the socket so we can apply the necessary config to it then. **Describe alternatives you've considered** Forking hickory to implement our own patch. **Additional context** This would be mainly used for Android and Linux platforms that don't have automatic packet loop detection, and instead rely on [`protect`](https://developer.android.com/reference/android/net/VpnService#protect(java.net.Socket)) in Android and `fwmark` in Linux to signal to the routing table **not** to route the packet back into the VPN interface. Apple's [NECP](https://forums.developer.apple.com/forums/thread/725715) seems to automagically prevent this case for Apple platforms (macOS / iOS tested).
kerem closed this issue 2026-03-16 00:59:40 +03:00
Author
Owner

@djc commented on GitHub (May 25, 2024):

Which library are you using? Are you able to use a custom RuntimeProvider for this?

<!-- gh-comment-id:2131272985 --> @djc commented on GitHub (May 25, 2024): Which library are you using? Are you able to use a custom [`RuntimeProvider`](https://docs.rs/hickory-resolver/latest/hickory_resolver/name_server/trait.RuntimeProvider.html) for this?
Author
Owner

@fmartinsons commented on GitHub (May 28, 2024):

Hello, I recently encounter the need described by @jamilbk , I need to perform DNS request which follow a specific routing table, I have a wwan0 interface expose by some LTE USB dongle and the setup of to use name server configured for this interface, we must bind to it.

Long story short, I would like to use bind_device

@djc As my previous link suggested , I use tokio and the specific config for that in hickory.

Do you see a way to customize the underlying socket that will be used inside hickory ?

Thanks !

<!-- gh-comment-id:2135289934 --> @fmartinsons commented on GitHub (May 28, 2024): Hello, I recently encounter the need described by @jamilbk , I need to perform DNS request which follow a specific routing table, I have a `wwan0` interface expose by some LTE USB dongle and the setup of to use name server configured for this interface, we must bind to it. Long story short, I would like to use [bind_device](https://docs.rs/tokio/latest/tokio/net/struct.UdpSocket.html#method.bind_device) @djc As my previous link suggested , I use tokio and the specific config for that in hickory. Do you see a way to customize the underlying socket that will be used inside hickory ? Thanks !
Author
Owner

@djc commented on GitHub (May 28, 2024):

You haven't really answered the question in my previous comment.

<!-- gh-comment-id:2135342738 --> @djc commented on GitHub (May 28, 2024): You haven't really answered the question in my previous comment.
Author
Owner

@fmartinsons commented on GitHub (May 28, 2024):

You haven't really answered the question in my previous comment.

Sorry, I may have misunderstood but I don't see what kind of library you want to know, in this context, I thought it was the async runtime.
For the second part, it seems you suggest to look at using a custom RuntimeProvider and by the look at the link you provided, the socket is exposed there.

I'll give it a try and come back here if I manage to come up with something working.

Thanks

<!-- gh-comment-id:2135470134 --> @fmartinsons commented on GitHub (May 28, 2024): > You haven't really answered the question in my previous comment. Sorry, I may have misunderstood but I don't see what kind of library you want to know, in this context, I thought it was the async runtime. For the second part, it seems you suggest to look at using a custom RuntimeProvider and by the look at the link you provided, the socket is exposed there. I'll give it a try and come back here if I manage to come up with something working. Thanks
Author
Owner

@fmartinsons commented on GitHub (May 29, 2024):

Ok that was fairly easy thanks to this example I managed to use bind_device to the socket returned by bind_udp trait method and it perfectly fit what I wanted.

Thank you very much @djc for the help.

<!-- gh-comment-id:2136568878 --> @fmartinsons commented on GitHub (May 29, 2024): Ok that was fairly easy thanks to [this example](https://github.com/hickory-dns/hickory-dns/blob/main/crates/resolver/examples/custom_provider.rs) I managed to use bind_device to the socket returned by bind_udp trait method and it perfectly fit what I wanted. Thank you very much @djc for the help.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#926
No description provided.