Crates.io | netstack-smoltcp |
lib.rs | netstack-smoltcp |
version | 0.1.2 |
source | src |
created_at | 2024-04-10 07:43:15.004846 |
updated_at | 2024-04-14 07:32:46.88722 |
description | A netstack for the special purpose of turning packets from/to a TUN interface into TCP streams and UDP packets. It uses smoltcp-rs as the backend netstack. |
homepage | https://github.com/automesh-network/netstack-smoltcp |
repository | https://github.com/automesh-network/netstack-smoltcp |
max_upload_size | |
id | 1203235 |
size | 106,278 |
A netstack for the special purpose of turning packets from/to a TUN interface into TCP streams and UDP packets. It uses smoltcp-rs as the backend netstack.
This crate provides lightweight netstack support for Linux, iOS, macOS, Android and Windows. Currently, it works on most targets, but mainly tested the popular platforms which includes:
// let device = tun2::create_as_async(&cfg)?;
// let framed = device.into_framed();
// let mut builder = StackBuilder::default();
// let (runner, udp_socket, tcp_listener, stack) = builder.build();
// tokio::task::spawn(runner);
let (udp_socket, tcp_listener, stack) = StackBuilder::default().run();
let (mut stack_sink, mut stack_stream) = stack.split();
let (mut tun_sink, mut tun_stream) = framed.split();
// Reads packet from stack and sends to TUN.
tokio::spawn(async move {
while let Some(pkt) = stack_stream.next().await {
if let Ok(pkt) = pkt {
tun_sink.send(pkt).await.unwrap();
}
}
});
// Reads packet from TUN and sends to stack.
tokio::spawn(async move {
while let Some(pkt) = tun_stream.next().await {
if let Ok(pkt) = pkt {
stack_sink.send(pkt).await.unwrap();
}
}
});
// Extracts TCP connections from stack and sends them to the dispatcher.
tokio::spawn(async move {
handle_inbound_stream(tcp_listener).await;
});
// Receive and send UDP packets between netstack and NAT manager. The NAT
// manager would maintain UDP sessions and send them to the dispatcher.
tokio::spawn(async move {
handle_inbound_datagram(udp_socket).await;
});
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in netstack-smoltcp by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Special thanks to these amazing projects that inspired netstack-smoltcp: