|
UDP Redirect
|
A simple yet flexible and very fast UDP redirector. Supports IPv4 and IPv6, including cross-family forwarding (IPv4 <-> IPv6). Tested on Linux x64 and MacOS / Darwin arm64.
Useful for redirecting UDP traffic (e.g., Wireguard VPN, DNS, etc.) when doing it at a different layer (e.g., from a firewall) is difficult. Does not modify the redirected packets.
Single file source code for convenience.
Community contributions are welcome.
Doxygen generated documentation: https://danpodeanu.github.io/udp-redirect/
By default, the listener accepts packets from any source and forwards replies to the most recently seen source. This makes the process an unauthenticated UDP relay. If the listen port is reachable by untrusted networks, lock it down with --listen-address-strict and/or --listen-sender-address + --listen-sender-port, and consider firewalling the listen port to expected sources only.
or
Cross-family forwarding is supported: the listen and connect sockets use independent address families, determined by --listen-address and --connect-address respectively.
Receive IPv4 packets and forward to an IPv6 backend:
Receive IPv6 packets and forward to an IPv4 backend:
Sample statistics output when invoked with --stats:
Runs in foreground and expects external process control (svscan, nohup, etc.)
| Argument | Parameters | Req/Opt | Description |
|---|---|---|---|
| --stats | optional | Display sent/received bytes statistics every 60 seconds. | |
| --verbose | optional | Verbose mode, can be specified multiple times. | |
| --debug | optional | Debug mode (e.g., very verbose). | |
| --version | optional | Display the version and exit. |
The UDP sender (e.g., wireguard client) sends packets to the UDP redirector specified below.
| Argument | Parameters | Req/Opt | Description |
|---|---|---|---|
| --listen-address | address | optional | Listen address (IPv4 or IPv6), defaults to INADDR_ANY / IN6ADDR_ANY. |
| --listen-port | port | required | Listen port. |
| --listen-interface | interface | optional | Listen interface name. |
| --listen-address-strict | optional | Security: By default, packets received from the connect endpoint will be sent to the source of the last packet received on the listener endpoint. In listen-address-strict mode, only accept packets from the same source as the first packet, or the source specified by listen-sender-address and listen-sender-port. |
The UDP redirector sends packets to the endpoint specified below.
| Argument | Parameters | Req/Opt | Description |
|---|---|---|---|
| --connect-address | address | optional if --connect-host is specified | Connect address (IPv4 or IPv6). |
| --connect-host | hostname | optional if --connect-address is specified | Connect host; overwrites --connect-address if both are specified. |
| --connect-port | port | required | Connect port. |
| --connect-address-strict | optional | Security: Only accept packets from connect-host and connect-port, otherwise accept from all sources. |
The UDP redirector sends packets from the local endpoint specified below. If any arguments are missing, it will be selected by the operating system (usually INADDR_ANY, random port, default interface).
| Argument | Parameters | Req/Opt | Description |
|---|---|---|---|
| --send-address | address | optional | Send packets from this address (IPv4 or IPv6). |
| --send-port | port | optional | Send packets from this port. |
| --send-interface | interface | optional | Send packets from this interface name. |
Both must be specified; listener drops packets if they do not arrive from this address / port.
| Argument | Parameters | Req/Opt | Description |
|---|---|---|---|
| --listen-sender-address | address | optional | Listen endpoint only accepts packets from this source address (IPv4 or IPv6). |
| --listen-sender-port | port | optional | Listen endpoint only accepts packets from this source port (must be set together, --listen-address-strict is implied). |
| Argument | Parameters | Req/Opt | Description |
|---|---|---|---|
| --ignore-errors | optional | Ignore most receive or send errors (host / network unreachable, etc.) instead of exiting. (default) | |
| --stop-errors | optional | Stop on most receive or send errors (host / network unreachable, etc.) |