MCPcopy Index your code
hub / github.com/automesh-network/netstack-smoltcp

github.com/automesh-network/netstack-smoltcp @v0.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.4 ↗ · + Follow
83 symbols 115 edges 9 files 3 documented · 4% updated 2mo agov0.1.4 · 2025-07-11★ 442 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Netstack Smoltcp

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.

Crates.io MIT licensed Apache licensed, Version 2.0 Build Status

Features

  • Supports Future Send and non-Send, mostly pepole use Send.
  • Supports ICMP protocol drive by TCP runner to use ICMP ping.
  • Supports filtering packets by source and destination IP addresses.
  • Can read IP packets from netstack, write IP packets to netstack.
  • Can receive TcpStream from TcpListener exposed from netstack.
  • Can receive UDP datagram from UdpSocket exposed from netstack.
  • Implements popular future streaming traits and asynchronous IO traits:
    • TcpListener implements futures Stream/Sink trait
    • TcpStream implements tokio AsyncRead/AsyncWrite trait
    • UdpSocket(ReadHalf/WriteHalf) implements futures Stream/Sink trait.

Platforms

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: - linux-amd64: x86_64-unknown-linux-gnu - android-arm64: aarch64-linux-android - android-amd64: x86_64-linux-android - macos-amd64: x86_64-apple-darwin - macos-arm64: aarch64-apple-darwin - ios-arm64: aarch64-apple-ios - windows-amd64: x86_64-pc-windows-msvc - windows-arm64: aarch64-pc-windows-msvc

Example

// let device = tun2::create_as_async(&cfg)?;
// let framed = device.into_framed();

let (stack, runner, udp_socket, tcp_listener) = netstack_smoltcp::StackBuilder::default()
    .stack_buffer_size(512)
    .tcp_buffer_size(4096)
    .enable_udp(true)
    .enable_tcp(true)
    .enable_icmp(true)
    .build()
    .unwrap();
let mut udp_socket = udp_socket.unwrap(); // udp enabled
let mut tcp_listener = tcp_listener.unwrap(); // tcp/icmp enabled
if let Some(runner) = runner {
    tokio::spawn(runner);
}

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;
});

License

This project is licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

at your option.

Contribution

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.

Inspired By

Special thanks to these amazing projects that inspired netstack-smoltcp (in no particular order): - shadowsocks-rust - netstack-lwip - rust-tun-active - rust-tun - smoltcp

Core symbols most depended-on inside this repo

split
called by 3
src/udp.rs
src_addr
called by 3
src/packet.rs
dst_addr
called by 3
src/packet.rs
payload
called by 3
src/packet.rs
add
called by 2
src/filter.rs
build
called by 2
src/stack.rs
add_fn
called by 1
src/filter.rs
is_allowed
called by 1
src/filter.rs

Shape

Method 57
Class 16
Function 8
Enum 2

Languages

Rust100%

Modules by API surface

src/stack.rs20 symbols
src/tcp.rs19 symbols
src/udp.rs10 symbols
src/filter.rs8 symbols
src/device.rs8 symbols
examples/forward.rs8 symbols
src/packet.rs6 symbols
src/runner.rs4 symbols

For agents

$ claude mcp add netstack-smoltcp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page