#userspace #tcp #stack #tun #space #user #packet

fake-tcp

A TUN interface based, user space, asynchronous and high performance TCP stack that allows packet oriented tunneling with minimum overhead

13 unstable releases (4 breaking)

0.5.0 Oct 25, 2022
0.4.0 Apr 16, 2022
0.3.1 Apr 10, 2022
0.2.3 Dec 7, 2021
0.2.0 Nov 19, 2021

#27 in #tun

Download history 6/week @ 2024-02-18 10/week @ 2024-02-25 1/week @ 2024-03-03 6/week @ 2024-03-10 131/week @ 2024-03-31

137 downloads per month
Used in phantun

MIT/Apache

30KB
590 lines

fake-tcp

A TUN interface based, user space, asynchronous and high performance TCP stack that allows packet oriented tunneling with minimum overhead.

License

Copyright 2021 Datong Sun dndx@idndx.com

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. Files in the project may not be copied, modified, or distributed except according to those terms.


lib.rs:

A minimum, userspace TCP based datagram stack

Overview

fake-tcp is a reusable library that implements a minimum TCP stack in user space using the Tun interface. It allows programs to send datagrams as if they are part of a TCP connection. fake-tcp has been tested to be able to pass through a variety of NAT and stateful firewalls while fully preserves certain desirable behavior such as out of order delivery and no congestion/flow controls.

Core Concepts

The core of the fake-tcp crate compose of two structures. Stack and Socket.

Stack

Stack represents a virtual TCP stack that operates at Layer 3. It is responsible for:

  • TCP active and passive open and handshake
  • RST handling
  • Interact with the Tun interface at Layer 3
  • Distribute incoming datagrams to corresponding Socket

Socket

Socket represents a TCP connection. It registers the identifying tuple (src_ip, src_port, dest_ip, dest_port) inside the Stack so so that incoming packets can be distributed to the right Socket with using a channel. It is also what the client should use for sending/receiving datagrams.

Examples

Please see client.rs and server.rs files from the phantun crate for how to use this library in client/server mode, respectively.

Dependencies

~9–21MB
~267K SLoC