MCPcopy Index your code
hub / github.com/DefGuard/wireguard-rs

github.com/DefGuard/wireguard-rs @v0.10.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.10.0 ↗ · + Follow
303 symbols 632 edges 27 files 82 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
<img src="https://github.com/DefGuard/wireguard-rs/raw/v0.10.0/docs/header.png" alt="defguard">

defguard_wireguard_rs is a multi-platform Rust library providing a unified high-level API for managing WireGuard interfaces using native OS kernel and userspace WireGuard protocol implementations. It can be used to create your own WireGuard:tm: VPN servers or clients for secure and private networking.

It was developed as part of defguard security platform and used in the gateway/server as well as desktop client.

Supported platforms

  • Native OS Kernel: Linux, FreeBSD (and pfSense/OPNSense), NetBSD, Windows
  • Userspace: Linux, macOS, FreeBSD, NetBSD

Unique features

  • Peer routing - see WGApi docs.
  • Configuring DNS resolver - see WGApi docs.
  • On FreeBSD network interfaces are managed using ioctl.
  • On Linux, handle network routing using netlink.
  • fwmark handling

Windows support

Please note that WireGuard-NT dll file has to be placed under resources-windows/binaries/wireguard.dll path relative to your binary.

Windows development

For Windows development you'll need:

  1. The stable-x86_64-pc-windows-gnu Rust toolchain. Use rustup to change the toolchain:
rustup install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
  1. Install MSYS2

  2. Then run this in the MSYS2 terminal:

pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86_64-nasm
  1. Finally add msys to your PATH:
# cmd
set PATH=C:\msys64\ucrt64\bin;%PATH%
# power-shell
$env:PATH = "C:\msys64\ucrt64\bin;" + $env:PATH

More info can be found here.

Examples

  • Client: https://github.com/DefGuard/wireguard-rs/blob/main/examples/client.rs
  • Server: https://github.com/DefGuard/wireguard-rs/blob/main/examples/server.rs

Documentation

See the documentation for more information.

Community and Support

Reach out to our community via GitHub Discussions

Contribution

Please review the Contributing guide for information on how to get started contributing to the project. You might also find our environment setup guide handy.

Legal

WireGuard® is registered trademarks of Jason A. Donenfeld.

Extension points exported contracts — how you extend this code

WireguardInterfaceApi (Interface)
API for managing a WireGuard interface. Specific interface being managed is identified by name. [4 implementers]
src/wireguard_interface.rs
SocketFromRaw (Interface)
(no doc) [2 implementers]
src/bsd/sockaddr.rs

Core symbols most depended-on inside this repo

netlink_request
called by 17
src/netlink.rs
c_int_to_error
called by 15
src/bsd/mod.rs
create_socket
called by 13
src/bsd/mod.rs
execute
called by 10
src/bsd/route.rs
pack
called by 9
src/bsd/nvlist.rs
unpack
called by 9
src/bsd/nvlist.rs
address_family
called by 7
src/netlink.rs
make_ifr_name
called by 7
src/bsd/ifconfig.rs

Shape

Method 157
Function 106
Class 29
Enum 9
Interface 2

Languages

Rust100%

Modules by API surface

src/bsd/nvlist.rs38 symbols
src/netlink.rs31 symbols
src/bsd/mod.rs29 symbols
src/key.rs22 symbols
src/bsd/route.rs18 symbols
src/bsd/ifconfig.rs17 symbols
src/wgapi_windows.rs16 symbols
src/wgapi_userspace.rs16 symbols
src/bsd/sockaddr.rs16 symbols
src/net.rs15 symbols
src/host.rs11 symbols
src/peer.rs10 symbols

For agents

$ claude mcp add wireguard-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact