wireguard-uapi

Crates.iowireguard-uapi
lib.rswireguard-uapi
version3.0.1
created_at2019-10-01 05:07:41.609349+00
updated_at2025-05-10 20:24:09.759974+00
descriptionControl WireGuard interfaces.
homepage
repositoryhttps://github.com/gluxon/wireguard-uapi-rs
max_upload_size
id169014
size186,406
Brandon Cheng (gluxon)

documentation

README

wireguard-uapi-rs

Build Status codecov Crates version docs.rs MIT

This library implements the WireGuard Netlink API in Rust for Linux.

  • If you're just reading a WireGuard device interface, this library fully supports that functionality.
  • If you're creating new WireGuard device interfaces, this library has partial support. Creating and deleting device interfaces is possible, but there's no ability at the moment for adding IP addresses to those devices.

Here's a quick example.

use failure;
use wireguard_uapi::{DeviceInterface, WgSocket};

fn main() -> Result<(), failure::Error> {
  let mut wg = WgSocket::connect()?;
  let device = wg.get_device(DeviceInterface::from_name("wgtest0"))?;

  print_device(&device);
  Ok(())
}

Permissions

Compiled binaries need the CAP_NET_ADMIN capability to read network interfaces. If you're getting an access error while using this library, make sure the compiled executable has that permission. If you trust your compiled binary, one way to grant it is:

sudo setcap CAP_NET_ADMIN=+eip ./my-compiled-binary

Developing

Similar to the above, the compiled test binaries need permission to interface with the kernel. The easiest way to do this (that the author is aware of) is to run the tests with sudo.

# .cargo/config.toml

[target.x86_64-unknown-linux-gnu]
runner = "sudo"

[target.aarch64-unknown-linux-gnu]
runner = "sudo"

Disclaimer

This isn't an official WireGuard product. (Although I'm interested in making it so.)

Feel free to file bugs.

Commit count: 160

cargo fmt