pub struct WireGuardInterface {
pub name: [u8; 16],
pub static_key: X25519KeyPair,
pub listen_port: u16,
pub tunnel_address: Option<IpAddress>,
pub tunnel_prefix: u8,
pub peers: BTreeMap<u64, WireGuardPeer>,
pub mtu: u16,
pub is_up: bool,
pub packets_in: u64,
pub packets_out: u64,
/* private fields */
}Expand description
WireGuard virtual network interface (wg0)
Fields§
§name: [u8; 16]Interface name
static_key: X25519KeyPairLocal static key pair
listen_port: u16Listening UDP port
tunnel_address: Option<IpAddress>Tunnel IP address
tunnel_prefix: u8Tunnel subnet prefix length
peers: BTreeMap<u64, WireGuardPeer>Peer table: hash of public key -> peer
mtu: u16Interface MTU
is_up: boolWhether the interface is up
packets_in: u64Packet counter for statistics
packets_out: u64Implementations§
Source§impl WireGuardInterface
impl WireGuardInterface
Sourcepub fn new(name: &[u8], static_key: X25519KeyPair, listen_port: u16) -> Self
pub fn new(name: &[u8], static_key: X25519KeyPair, listen_port: u16) -> Self
Create a new WireGuard interface
Sourcepub fn set_address(&mut self, addr: IpAddress, prefix: u8)
pub fn set_address(&mut self, addr: IpAddress, prefix: u8)
Set tunnel IP address
Sourcepub fn calculate_mtu(outer_mtu: u16, is_ipv6: bool) -> u16
pub fn calculate_mtu(outer_mtu: u16, is_ipv6: bool) -> u16
Calculate effective MTU based on outer transport.
- IPv4 outer: outer_mtu - 20 (IP) - 8 (UDP) - 32 (WG overhead) = outer_mtu - 60
- IPv6 outer: outer_mtu - 40 (IP) - 8 (UDP) - 32 (WG overhead) = outer_mtu - 80
Sourcepub fn add_peer(&mut self, peer: WireGuardPeer) -> Result<(), WireGuardError>
pub fn add_peer(&mut self, peer: WireGuardPeer) -> Result<(), WireGuardError>
Add a peer
Sourcepub fn remove_peer(
&mut self,
public_key: &[u8; 32],
) -> Result<(), WireGuardError>
pub fn remove_peer( &mut self, public_key: &[u8; 32], ) -> Result<(), WireGuardError>
Remove a peer by public key
Sourcepub fn get_peer(&self, public_key: &[u8; 32]) -> Option<&WireGuardPeer>
pub fn get_peer(&self, public_key: &[u8; 32]) -> Option<&WireGuardPeer>
Look up a peer by public key
Sourcepub fn get_peer_mut(
&mut self,
public_key: &[u8; 32],
) -> Option<&mut WireGuardPeer>
pub fn get_peer_mut( &mut self, public_key: &[u8; 32], ) -> Option<&mut WireGuardPeer>
Look up a peer mutably by public key
Sourcepub fn find_peer_for_ip(&self, dst: &Ipv4Address) -> Option<&WireGuardPeer>
pub fn find_peer_for_ip(&self, dst: &Ipv4Address) -> Option<&WireGuardPeer>
Find a peer that handles a given destination IP
Sourcepub fn up(&mut self) -> Result<(), WireGuardError>
pub fn up(&mut self) -> Result<(), WireGuardError>
Bring the interface up
Sourcepub fn alloc_sender_index(&mut self) -> u32
pub fn alloc_sender_index(&mut self) -> u32
Allocate a new sender index
Sourcepub fn peer_count(&self) -> usize
pub fn peer_count(&self) -> usize
Get peer count