diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-11-21 11:43:16 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-11-21 11:43:16 +0100 |
commit | 92dbb4c46a5651afb8f92375e0ed154673929eeb (patch) | |
tree | f274dbaa58256e1fb412ae3934e02e2b19cb47f5 /src/configuration/uapi | |
parent | Better compartmentalization of cryptokey router (diff) | |
download | wireguard-rs-92dbb4c46a5651afb8f92375e0ed154673929eeb.tar.xz wireguard-rs-92dbb4c46a5651afb8f92375e0ed154673929eeb.zip |
Clean dependencies and imports
Diffstat (limited to 'src/configuration/uapi')
-rw-r--r-- | src/configuration/uapi/get.rs | 12 | ||||
-rw-r--r-- | src/configuration/uapi/mod.rs | 13 | ||||
-rw-r--r-- | src/configuration/uapi/set.rs | 12 |
3 files changed, 26 insertions, 11 deletions
diff --git a/src/configuration/uapi/get.rs b/src/configuration/uapi/get.rs index 43d4735..f0746b3 100644 --- a/src/configuration/uapi/get.rs +++ b/src/configuration/uapi/get.rs @@ -2,12 +2,13 @@ use log; use std::io; use super::Configuration; +use super::Endpoint; pub fn serialize<C: Configuration, W: io::Write>(writer: &mut W, config: &C) -> io::Result<()> { let mut write = |key: &'static str, value: String| { debug_assert!(value.is_ascii()); debug_assert!(key.is_ascii()); - log::trace!("UAPI: return : {} = {}", key, value); + log::trace!("UAPI: return : {}={}", key, value); writer.write(key.as_ref())?; writer.write(b"=")?; writer.write(value.as_ref())?; @@ -30,6 +31,7 @@ pub fn serialize<C: Configuration, W: io::Write>(writer: &mut W, config: &C) -> // serialize all peers let mut peers = config.get_peers(); while let Some(p) = peers.pop() { + write("public_key", hex::encode(p.public_key.as_bytes()))?; write("rx_bytes", p.rx_bytes.to_string())?; write("tx_bytes", p.tx_bytes.to_string())?; write( @@ -40,7 +42,13 @@ pub fn serialize<C: Configuration, W: io::Write>(writer: &mut W, config: &C) -> "last_handshake_time_nsec", p.last_handshake_time_nsec.to_string(), )?; - write("public_key", hex::encode(p.public_key.as_bytes()))?; + write( + "persistent_keepalive_interval", + p.persistent_keepalive_interval.to_string(), + )?; + if let Some(endpoint) = p.endpoint { + write("endpoint", endpoint.into_address().to_string())?; + } write("preshared_key", hex::encode(p.preshared_key))?; for (ip, cidr) in p.allowed_ips { write("allowed_ip", ip.to_string() + "/" + &cidr.to_string())?; diff --git a/src/configuration/uapi/mod.rs b/src/configuration/uapi/mod.rs index 3cb88c0..4f0b741 100644 --- a/src/configuration/uapi/mod.rs +++ b/src/configuration/uapi/mod.rs @@ -4,6 +4,7 @@ mod set; use log; use std::io::{Read, Write}; +use super::Endpoint; use super::{ConfigError, Configuration}; use get::serialize; @@ -55,14 +56,12 @@ pub fn handle<S: Read + Write, C: Configuration>(stream: &mut S, config: &C) { loop { let ln = readline(stream)?; if ln == "" { - // end of transcript - parser.parse_line("", "")?; // flush final peer - break Ok(()); - } else { - let (k, v) = keypair(ln.as_str())?; - parser.parse_line(k, v)?; - }; + break; + } + let (k, v) = keypair(ln.as_str())?; + parser.parse_line(k, v)?; } + parser.parse_line("", "") } _ => Err(ConfigError::InvalidOperation), } diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs index 882e4a7..b44ee1c 100644 --- a/src/configuration/uapi/set.rs +++ b/src/configuration/uapi/set.rs @@ -56,33 +56,40 @@ impl<'a, C: Configuration> LineParser<'a, C> { // flush peer updates to configuration fn flush_peer<C: Configuration>(config: &C, peer: &ParsedPeer) -> Option<ConfigError> { if peer.remove { + log::trace!("flush peer, remove peer"); config.remove_peer(&peer.public_key); return None; } if !peer.update_only { + log::trace!("flush peer, add peer"); config.add_peer(&peer.public_key); } - for (ip, masklen) in &peer.allowed_ips { - config.add_allowed_ip(&peer.public_key, *ip, *masklen); + for (ip, cidr) in &peer.allowed_ips { + log::trace!("flush peer, add allowed_ips : {}/{}", ip.to_string(), cidr); + config.add_allowed_ip(&peer.public_key, *ip, *cidr); } if let Some(psk) = peer.preshared_key { + log::trace!("flush peer, set preshared_key {}", hex::encode(psk)); config.set_preshared_key(&peer.public_key, psk); } if let Some(secs) = peer.persistent_keepalive_interval { + log::trace!("flush peer, set persistent_keepalive_interval {}", secs); config.set_persistent_keepalive_interval(&peer.public_key, secs); } if let Some(version) = peer.protocol_version { + log::trace!("flush peer, set protocol_version {}", version); if version == 0 || version > config.get_protocol_version() { return Some(ConfigError::UnsupportedProtocolVersion); } } if let Some(endpoint) = peer.endpoint { + log::trace!("flush peer, set endpoint {}", endpoint.to_string()); config.set_endpoint(&peer.public_key, endpoint); }; @@ -232,6 +239,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { // flush (used at end of transcipt) "" => { + log::trace!("UAPI, Set, processes end of transaction"); flush_peer(self.config, &peer); Ok(()) } |