narrowlink / ipstack

Asynchronous lightweight userspace implementation of TCP/IP stack for Tun device
Apache License 2.0
51 stars 12 forks source link

support processing other packet from ipstack #15

Closed xmh0511 closed 9 months ago

SajjadPourali commented 9 months ago

It is better to create two types for the IpStackStream: one for UnknownTransport, which we know is IP but is neither TCP nor UDP, and another for UnknowNetwork for anything that is not IP. I believe these types allow users to implement their protocols manually.


Since ICMP is not primarily designed to transfer data, we have to create an enum that supports the most useful types of ICMP in the IpStack usage scenarios, such as Echo.

SajjadPourali commented 9 months ago

Something like this?

https://github.com/narrowlink/ipstack/commit/670226a9565655c8dcbc927582012e48b2c56580


https://github.com/narrowlink/ipstack/blob/670226a9565655c8dcbc927582012e48b2c56580/src/stream/mod.rs#L12-L17

xmh0511 commented 9 months ago

I think providing the raw packet produced by tun for all the other cases other than tcp and udp has the maximum flexible because we may want to do the following things:

  1. process the packet by using the familiar crate.
  2. send the complete packet to the remote to be processed.

Even for Icmp packet, if we pre-process it to produce IpStackUnknownTransport, we can only get the payload, or we must re-produce the original packet from the result, which is not necessary.

SajjadPourali commented 9 months ago

@xmh0511: could you please check examples/tun.rs in the main branch?

https://github.com/narrowlink/ipstack/blob/main/examples/tun.rs#L113-L134

Screenshot 2024-01-20 at 8 06 59 PM
xmh0511 commented 9 months ago

@SajjadPourali I have tried the latest version. Currently, in the branch IpStackStream::UnknownTransport(u), u.payload() will return the payload part of the IP packet, which is the ICMP message, and u.send just need the ICMP message too, right?

SajjadPourali commented 9 months ago

@SajjadPourali I have tried the latest version. Currently, in the branch IpStackStream::UnknownTransport(u), u.payload() will return the payload part of the IP packet, which is the ICMP message, and u.send just need the ICMP message too, right?

True, there also another one that called UnknownNetwork that is similar to the raw that you mentioned.