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

Add recv_with_ancillary_data for udp socket #1679

Closed
wants to merge 2 commits into from

Conversation

yuguorui
Copy link

Add recv_with_ancillary_data for udp socket to facilitate IP_PKTINFO and IP_RECVORIGDSTADDR usage.

IP_RECVORIGDSTADDR is very handly for UDP transparent proxy with tproxy, and these patches are precondition for tokio to support ancillary data receiving.

struct cmsghdr parsing is not included in these patches on purpose, to avoid introducing addtional dependencies.

recv_with_ancillary_data allows to cooperate with sockopts such as IP_PKTINFO
and IP_RECVORIGDSTADDR to obtain ancillary data. For more information,
please refer to the manual page[1].

[1] https://man7.org/linux/man-pages/man7/ip.7.html
Add support for set_pktinfo and some basic unittests for set_pktinfo and
recv_with_ancillary_data.
@Thomasdezeeuw
Copy link
Collaborator

Mio follows the API provided by the std lib, so this won't be accepted by Mio. However it's something I'm willing to consider for socket2: https://github.com/rust-lang/socket2.

@yuguorui
Copy link
Author

Mio follows the API provided by the std lib, so this won't be accepted by Mio. However it's something I'm willing to consider for socket2: https://github.com/rust-lang/socket2.

Thanks for your reminding.
I understand that socket2 maybe a more advanced networking API, but it doesn't seem to be event driven, could socket2 be effectively driven by tokio?

@Thomasdezeeuw
Copy link
Collaborator

Thanks for your reminding. I understand that socket2 maybe a more advanced networking API, but it doesn't seem to be event driven, could socket2 be effectively driven by tokio?

You can use socket2::SockRef to call any method on socket2::Socket on mio::net::UdpSocket.

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.

None yet

2 participants