• Stars
    star
    343
  • Rank 123,371 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Proxy UDP traffic over a TCP stream

udp-over-tcp

A library (and binaries) for tunneling UDP datagrams over a TCP stream.

Some programs/protocols only work over UDP. And some networks only allow TCP. This is where udp-over-tcp comes in handy. This library comes in two parts:

  • udp2tcp - Forwards incoming UDP datagrams over a TCP stream. The return stream is translated back to datagrams and sent back out over UDP again. This part can be easily used as both a library and a binary. So it can be run standalone, but can also easily be included in other Rust programs. The UDP socket is connected to the peer address of the first incoming datagram. So one [Udp2Tcp] instance can handle traffic from a single peer only.
  • tcp2udp - Accepts connections over TCP and translates + forwards the incoming stream as UDP datagrams to the destination specified during setup / on the command line. Designed mostly to be a standalone executable to run on servers. But can be consumed as a Rust library as well. tcp2udp continues to accept new incoming TCP connections, and creates a new UDP socket for each. So a single tcp2udp server can be used to service many udp2tcp clients.

Protocol

The format of the data inside the TCP stream is very simple. Each datagram is preceded with a 16 bit unsigned integer in big endian byte order, specifying the length of the datagram.

tcp2udp server example

Make the server listen for TCP connections that it can then forward to a local UDP service. This will listen on 10.0.0.1:5001/TCP and forward anything that comes in to 127.0.0.1:51820/UDP:

user@server $ RUST_LOG=debug tcp2udp \
    --tcp-listen 10.0.0.0:5001 \
    --udp-forward 127.0.0.1:51820

RUST_LOG can be used to set logging level. See documentation for env_logger for information. The crate must be built with the env_logger feature for this to be active.

REDACT_LOGS=1 can be set to redact the IPs of the peers using the service from the logs. Allows having logging turned on but without storing potentially user sensitive data to disk.

udp2tcp example

This is one way you could integrate udp2tcp into your Rust program. This will connect a TCP socket to 1.2.3.4:9000 and bind a UDP socket to a random port on the loopback interface. It will then connect the UDP socket to the socket addr of the first incoming datagram and start forwarding all traffic to (and from) the TCP socket.

let udp_listen_addr = "127.0.0.1:0".parse().unwrap();
let tcp_forward_addr = "1.2.3.4:9000".parse().unwrap();

// Create a UDP -> TCP forwarder. This will connect the TCP socket
// to `tcp_forward_addr`
let udp2tcp = udp_over_tcp::Udp2Tcp::new(
    udp_listen_addr,
    tcp_forward_addr,
    udp_over_tcp::TcpOptions::default(),
)
.await?;

// Read out which address the UDP actually bound to. Useful if you specified port
// zero to get a random port from the OS.
let local_udp_addr = udp2tcp.local_udp_addr()?;

spin_up_some_udp_thing(local_udp_addr);

// Run the forwarder until the TCP socket disconnects or an error happens.
udp2tcp.run().await?;

More Repositories

1

mullvadvpn-app

The Mullvad VPN client app for desktop and mobile
Rust
4,976
star
2

mullvad-browser

Privacy-focused browser for Linux, macOS and Windows. Made in collaboration between @torproject and @mullvad
1,259
star
3

dns-blocklists

Lists and configuration for our DNS blocking service
Shell
976
star
4

windows-service-rs

Windows services in Rust
Rust
501
star
5

encrypted-dns-profiles

macOS and iOS profiles to configure our DNS over TLS and DNS over HTTPS service. Can be applied with human interaction, or via MDM.
242
star
6

browser-extension

Mullvad Browser Extension improves your browsing experience while using Mullvad VPN.
TypeScript
191
star
7

libwfp

C++ library for interacting with the Windows Filtering Platform (WFP)
C++
82
star
8

nftnl-rs

Rust bindings and abstraction for libnftnl, low-level userspace access to the in-kernel nf_tables subsystem
Rust
71
star
9

pfctl-rs

Library and CLI for interfacing with the PF firewall on macOS
Rust
64
star
10

jsonrpc-client-rs

A JSON-RPC 2.0 client in and for Rust
Rust
53
star
11

jnix

Procedural macros for automatically generating conversion code between Rust and Java
Rust
47
star
12

message-queue

A redis pubsub -> websocket message queue
Go
37
star
13

mullvadvpn-app-binaries

Extra binaries to bundle with Mullvad VPN app
C
36
star
14

win-split-tunnel

Mullvad split tunnel driver for Windows
C++
36
star
15

system-configuration-rs

Bindings to System Configuration framework for macOS
Rust
35
star
16

oqs-rs

Rust bindings and key exchange for liboqs (Open Quantum Safe), a library for quantum-resistant cryptographic algorithms
Rust
35
star
17

system-transparency

Shell
33
star
18

coding-guidelines

Guides and texts about how we develop, format and work with code at Mullvad
32
star
19

windows-libraries

C++ libraries for Windows
C++
23
star
20

mullvad-wg.sh

Configuration script for using Mullvad with WireGuard on linux
Shell
19
star
21

openvpn-plugin-rs

A crate allowing easy creation of OpenVPN plugins in Rust
Rust
18
star
22

NSEventMonitor

Node.js module for monitoring NSEvents
Objective-C++
17
star
23

windows-security

Node add-on to access security features on Windows
C++
15
star
24

apisocks5

Censorship circumvention. Reroute and optionally obfuscate traffic destined for the Mullvad API.
Go
14
star
25

mnl-rs

Rust bindings and abstraction for libmnl. A minimalistic user-space library oriented to Netlink developers
Rust
8
star
26

wgephemeralpeer

Mullvad Post-Quantum-secure WireGuard tunnels for vanilla WireGuard and custom integrations.
Go
8
star
27

mullvadvpn-app-tests

Rust
3
star
28

infrastructure-ansible-packages

Ansible installation packages used by the Infrastructure Team
Shell
3
star
29

globe-mesh-builder

Parses SHP (shapefiles) and produce OpenGL compatible vertex and index buffers for drawing a spherical world map (globe). Used by the Mullvad VPN app to generate map data
Rust
2
star
30

hyper-dnscache

An implementation of the hyper Resolve trait that can cache in memory
Rust
2
star
31

grpc-sandbox

App team playing around with gRPC
Rust
2
star
32

mullvadvpn-app-assets

This repository contains the graphical assets used in mullvadvpn-app
Shell
1
star
33

heathrow_wifi

DIGITAL Command Language
1
star
34

wireguard-go

Go
1
star
35

client-binaries

Binaries that are bundled with the Mullvad VPN client.
Shell
1
star
36

supply-chain

Shared third party code audits
1
star
37

mullvadvpn-app-screenshots

Screenshots for CI purposes
1
star