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

Adding support for sending/receiving ICMP packets (and more generally raw IP packets)? #2659

Open
gendx opened this issue Jul 15, 2020 · 11 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author.

Comments

@gendx
Copy link

gendx commented Jul 15, 2020

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.

Additional context
N/A

@gendx gendx added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Jul 15, 2020
@Darksonn Darksonn added the M-net Module: tokio/net label Jul 20, 2020
@Darksonn
Copy link
Contributor

Does the various OSes even provide an async API for this?

@hawkw
Copy link
Member

hawkw commented Jul 20, 2020

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?

@carllerche
Copy link
Member

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.

@carllerche carllerche added the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Jul 25, 2020
@fluxxu
Copy link
Contributor

fluxxu commented Jul 30, 2020

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.

@gendx
Copy link
Author

gendx commented Aug 3, 2020

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.

@GlenDC
Copy link

GlenDC commented May 30, 2022

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?

@Darksonn
Copy link
Contributor

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?

@pplmx
Copy link

pplmx commented Dec 26, 2023

Any progress?

@Darksonn
Copy link
Contributor

No. See my previous comment.

@pplmx
Copy link

pplmx commented Dec 27, 2023

OK, Thanks :)

@irvingoujAtDevolution
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author.
Projects
None yet
Development

No branches or pull requests

8 participants