tokio
tokio copied to clipboard
Adding support for sending/receiving ICMP packets (and more generally raw IP packets)?
Is your feature request related to a problem? Please describe.
tokio::net
currently supports networking over TCP, UDP and Unix domain sockets. This doesn't include other protocols such as ICMP (ping). It would be interesting to have the ability to send/receive ICMP packets via Tokio's asynchronous interface.
Describe the solution you'd like
Adding the ability to handle ICMP packets in tokio::net
. I assume the API would be somewhat similar to tokio::net::UdpSocket
. Maybe the API should support handling all IP packets at a low level - not only ICMP? I'm not sure whether it would be feasible to implement on all OSes, maybe Linux or Unix should be supported first?
Describe alternatives you've considered
It seems that std::net
doesn't support ICMP either. I've found the following projects to handle ICMP in Rust. However, none of them seem to support an async
interface.
- https://crates.io/crates/pnet, which looks like the de facto crate to handle low-level networking in Rust.
- https://github.com/bparli/fastping-rs (which relies on
pnet
). - https://github.com/svartalf/rust-icmp (archived).
Additional context N/A
Does the various OSes even provide an async API for this?
You might want to check out something like capsule
for packet-level use cases. It's built on top of Tokio (although it looks like it has yet to be updated to the release version of 0.2) and uses DPDK.
As @Darksonn said, I'm not sure if there is a cross-platform way for Tokio to abstract over raw IP packets?
The next step would be to make a concrete proposal on how to do this.
- How would this be implemented?
- What is the portability story?
- Can this be implemented as a separate library?
I don't believe any of the core maintainers have a need for this functionality, so it would need to be user contributed.
FWIW:
This is a library implement ICMP ping using std::net
and socket2
: (Tested on Windows/macOS)
https://github.com/aisk/ping
And this is a library implement ICMP ping using tokio 0.1
only support UNIX
https://github.com/knsd/tokio-ping
Based on these two libraries, let me try to answer these questions:
How would this be implemented?
If we want to add an IcmpSocket
into tokio, we can either depend on socket2
or implement raw socket inside tokio, which I don't think is a good idea either way, because it feels like a big change to tokio.
What is the portability story?
It should be fine for basic pinging functionality, but once you want to implement more complex features, there will be some privilege issues: https://apple.stackexchange.com/questions/312857/how-does-macos-allow-standard-users-to-ping https://stackoverflow.com/questions/4282783/raw-sockets-privilege-for-normal-user
Can this be implemented as a separate library?
I think the answer is Yes.
What is the portability story?
It should be fine for basic pinging functionality, but once you want to implement more complex features, there will be some privilege issues: https://apple.stackexchange.com/questions/312857/how-does-macos-allow-standard-users-to-ping https://stackoverflow.com/questions/4282783/raw-sockets-privilege-for-normal-user
Using raw sockets and/or advanced features would assume that the binary is run as root
, but I don't think there should be a restriction that a Tokio-based program cannot be run as root.
Hi. Are there any active plans in regards to supporting this? Is there anyway I or others can help progressing this in whatever way is suitable?
Was planning to write it myself, but can't imagine it's going to help anyone if we have yet another packet. For example currently https://github.com/jcgruenhage/tokio-icmp-echo is the best way to go forward I guess to have something.
What would it take to start adding such support directly to tokio, or is this deemed out of scope?
There are no active plans at this time. In general, I would start by figuring out the minimal support needed by Tokio to make this implementable in external crates. E.g., what does it take to hook up the raw IP packets to the Tokio event loop? Can AsyncFd
handle it? What is the story for raw IP packets on windows?
Any progress?
No. See my previous comment.
OK, Thanks :)
What is the portability story?
It should be fine for basic pinging functionality, but once you want to implement more complex features, there will be some privilege issues: https://apple.stackexchange.com/questions/312857/how-does-macos-allow-standard-users-to-ping https://stackoverflow.com/questions/4282783/raw-sockets-privilege-for-normal-user
Using raw sockets and/or advanced features would assume that the binary is run as
root
, but I don't think there should be a restriction that a Tokio-based program cannot be run as root.
This is not an issue, the program only uses it at runtime, if it fails it fails, the user will restart it with privilege.