From 5b555a2e176bd5310d2efa614f67c96cb314eda4 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Mon, 11 Nov 2019 23:13:46 +0100 Subject: Work on UAPI serialize device --- src/configuration/config.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/configuration/config.rs') diff --git a/src/configuration/config.rs b/src/configuration/config.rs index ed78e43..b1c0121 100644 --- a/src/configuration/config.rs +++ b/src/configuration/config.rs @@ -19,6 +19,7 @@ pub struct PeerState { pub last_handshake_time_nsec: u64, pub public_key: PublicKey, pub allowed_ips: Vec<(IpAddr, u32)>, + pub preshared_key: Option<[u8; 32]>, } pub struct WireguardConfig { @@ -157,15 +158,26 @@ pub trait Configuration { /// The ip should be masked to remove any set bits right of the first "masklen" bits. fn add_allowed_ip(&self, peer: &PublicKey, ip: IpAddr, masklen: u32) -> Option; + fn get_listen_port(&self) -> Option; + /// Returns the state of all peers /// /// # Returns /// /// A list of structures describing the state of each peer fn get_peers(&self) -> Vec; + + fn get_fwmark(&self) -> Option; } impl Configuration for WireguardConfig { + fn get_fwmark(&self) -> Option { + self.network + .lock() + .as_ref() + .and_then(|bind| bind.get_fwmark()) + } + fn set_private_key(&self, sk: Option) { self.wireguard.set_key(sk) } @@ -178,6 +190,10 @@ impl Configuration for WireguardConfig { 1 } + fn get_listen_port(&self) -> Option { + self.network.lock().as_ref().map(|bind| bind.get_port()) + } + fn set_listen_port(&self, port: Option) -> Option { let mut bind = self.network.lock(); @@ -285,6 +301,7 @@ impl Configuration for WireguardConfig { fn get_peers(&self) -> Vec { let peers = self.wireguard.list_peers(); let mut state = Vec::with_capacity(peers.len()); + for p in peers { // convert the system time to (secs, nano) since epoch let last_handshake = (*p.walltime_last_handshake.lock()) @@ -293,6 +310,7 @@ impl Configuration for WireguardConfig { // extract state into PeerState state.push(PeerState { + preshared_key: self.wireguard.get_psk(&p.pk), rx_bytes: p.rx_bytes.load(Ordering::Relaxed), tx_bytes: p.tx_bytes.load(Ordering::Relaxed), allowed_ips: p.router.list_allowed_ips(), -- cgit v1.2.3-59-g8ed1b