From 2e44a55112073818ad5402acafe3f71d93597165 Mon Sep 17 00:00:00 2001 From: Juan Bono Date: Sun, 10 Apr 2022 23:46:28 -0300 Subject: [PATCH 1/7] remove unnecessary semicolons Signed-off-by: Juan Bono --- src/configuration/uapi/mod.rs | 2 +- src/configuration/uapi/set.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/configuration/uapi/mod.rs b/src/configuration/uapi/mod.rs index 63a8d5f7..c41e2e86 100644 --- a/src/configuration/uapi/mod.rs +++ b/src/configuration/uapi/mod.rs @@ -40,7 +40,7 @@ pub fn handle(stream: &mut S, config: &C) { (Some(key), Some(value)) => Ok((key, value)), _ => Err(ConfigError::LineTooLong), } - }; + } // read operation line match readline(stream)?.as_str() { diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs index 665f090b..5ff30734 100644 --- a/src/configuration/uapi/set.rs +++ b/src/configuration/uapi/set.rs @@ -101,7 +101,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { }; None - }; + } // parse line and update parser state match self.state { From 3cf74715180f21b9b494c65775187a81eca65bfa Mon Sep 17 00:00:00 2001 From: Juan Bono Date: Mon, 11 Apr 2022 00:04:31 -0300 Subject: [PATCH 2/7] fix clippy warnings from tests Signed-off-by: Juan Bono --- src/wireguard/router/receive.rs | 8 +++----- src/wireguard/router/send.rs | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/wireguard/router/receive.rs b/src/wireguard/router/receive.rs index 15eb8fbe..e37f97b4 100644 --- a/src/wireguard/router/receive.rs +++ b/src/wireguard/router/receive.rs @@ -64,9 +64,8 @@ impl> ParallelJob * since this can cause dropping of packets (leaving the window) due to scheduling. */ fn parallel_work(&self) { - debug_assert_eq!( - self.is_ready(), - false, + debug_assert!( + !self.is_ready(), "doing parallel work on completed job" ); log::trace!("processing parallel receive job"); @@ -132,9 +131,8 @@ impl> SequentialJob } fn sequential_work(self) { - debug_assert_eq!( + debug_assert!( self.is_ready(), - true, "doing sequential work on an incomplete job" ); log::trace!("processing sequential receive job"); diff --git a/src/wireguard/router/send.rs b/src/wireguard/router/send.rs index 7e142095..34520a8b 100644 --- a/src/wireguard/router/send.rs +++ b/src/wireguard/router/send.rs @@ -57,9 +57,8 @@ impl> ParallelJob } fn parallel_work(&self) { - debug_assert_eq!( - self.is_ready(), - false, + debug_assert!( + !self.is_ready(), "doing parallel work on completed job" ); log::trace!("processing parallel send job"); @@ -117,9 +116,8 @@ impl> SequentialJob } fn sequential_work(self) { - debug_assert_eq!( + debug_assert!( self.is_ready(), - true, "doing sequential work on an incomplete job" ); From 7c025194d261938898e802b6f0751b93b24c1c39 Mon Sep 17 00:00:00 2001 From: Juan Bono Date: Mon, 11 Apr 2022 00:16:05 -0300 Subject: [PATCH 3/7] fix 'needless borrows' warnings Signed-off-by: Juan Bono --- src/configuration/uapi/set.rs | 4 ++-- src/wireguard/handshake/noise.rs | 4 ++-- src/wireguard/handshake/peer.rs | 2 +- src/wireguard/router/peer.rs | 4 ++-- src/wireguard/router/receive.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/configuration/uapi/set.rs b/src/configuration/uapi/set.rs index 5ff30734..bb4ddbef 100644 --- a/src/configuration/uapi/set.rs +++ b/src/configuration/uapi/set.rs @@ -167,7 +167,7 @@ impl<'a, C: Configuration> LineParser<'a, C> { ParserState::Peer(ref mut peer) => match key { // opt: new peer "public_key" => { - flush_peer(self.config, &peer); + flush_peer(self.config, peer); self.state = Self::new_peer(value)?; Ok(()) } @@ -247,7 +247,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); + flush_peer(self.config, peer); Ok(()) } diff --git a/src/wireguard/handshake/noise.rs b/src/wireguard/handshake/noise.rs index 92c8c5f4..da2b66c1 100644 --- a/src/wireguard/handshake/noise.rs +++ b/src/wireguard/handshake/noise.rs @@ -271,7 +271,7 @@ pub(super) fn create_initiation( // (C, k) := Kdf2(C, DH(E_priv, S_pub)) - let (ck, key) = KDF2!(&ck, shared_secret(&eph_sk, &pk)?.as_bytes()); + let (ck, key) = KDF2!(&ck, shared_secret(&eph_sk, pk)?.as_bytes()); // msg.static := Aead(k, 0, S_pub, H) @@ -444,7 +444,7 @@ pub(super) fn create_response( // C := Kdf1(C, DH(E_priv, S_pub)) - let ck = KDF1!(&ck, shared_secret(&eph_sk, &pk)?.as_bytes()); + let ck = KDF1!(&ck, shared_secret(&eph_sk, pk)?.as_bytes()); // (C, tau, k) := Kdf3(C, Q) diff --git a/src/wireguard/handshake/peer.rs b/src/wireguard/handshake/peer.rs index f8477254..964006c1 100644 --- a/src/wireguard/handshake/peer.rs +++ b/src/wireguard/handshake/peer.rs @@ -95,7 +95,7 @@ impl Peer { // check replay attack if let Some(timestamp_old) = *timestamp { - if !timestamp::compare(×tamp_old, ×tamp_new) { + if !timestamp::compare(×tamp_old, timestamp_new) { return Err(HandshakeError::OldTimestamp); } }; diff --git a/src/wireguard/router/peer.rs b/src/wireguard/router/peer.rs index 0803b138..3f193dc4 100644 --- a/src/wireguard/router/peer.rs +++ b/src/wireguard/router/peer.rs @@ -324,12 +324,12 @@ impl> Peer> ParallelJob } // check crypto-key router - packet.len() == SIZE_TAG || peer.device.table.check_route(&peer, &packet) + packet.len() == SIZE_TAG || peer.device.table.check_route(peer, packet) })(); // remove message in case of failure: From ca7167bfa1648f6e22837c05fc2296e6b5b6f386 Mon Sep 17 00:00:00 2001 From: Juan Bono Date: Mon, 11 Apr 2022 00:23:49 -0300 Subject: [PATCH 4/7] use std::mem::take instead of std::mem::replace Signed-off-by: Juan Bono --- src/wireguard/router/peer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wireguard/router/peer.rs b/src/wireguard/router/peer.rs index 3f193dc4..79615156 100644 --- a/src/wireguard/router/peer.rs +++ b/src/wireguard/router/peer.rs @@ -440,7 +440,7 @@ impl> PeerHandle Date: Mon, 11 Apr 2022 00:24:32 -0300 Subject: [PATCH 5/7] derive Default impl for Response and Initiation Signed-off-by: Juan Bono --- src/wireguard/handshake/messages.rs | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/wireguard/handshake/messages.rs b/src/wireguard/handshake/messages.rs index 29d80afc..554799dd 100644 --- a/src/wireguard/handshake/messages.rs +++ b/src/wireguard/handshake/messages.rs @@ -36,14 +36,14 @@ pub const MAX_HANDSHAKE_MSG_SIZE: usize = max( /* Handshake messsages */ #[repr(packed)] -#[derive(Copy, Clone, FromBytes, AsBytes)] +#[derive(Copy, Clone, FromBytes, AsBytes, Default)] pub struct Response { pub noise: NoiseResponse, // inner message covered by macs pub macs: MacsFooter, } #[repr(packed)] -#[derive(Copy, Clone, FromBytes, AsBytes)] +#[derive(Copy, Clone, FromBytes, AsBytes, Default)] pub struct Initiation { pub noise: NoiseInitiation, // inner message covered by macs pub macs: MacsFooter, @@ -130,24 +130,6 @@ impl CookieReply { /* Default values */ -impl Default for Response { - fn default() -> Self { - Self { - noise: Default::default(), - macs: Default::default(), - } - } -} - -impl Default for Initiation { - fn default() -> Self { - Self { - noise: Default::default(), - macs: Default::default(), - } - } -} - impl Default for CookieReply { fn default() -> Self { Self { From 2e1021ee052f74900d7ede034e7caa7717346cbb Mon Sep 17 00:00:00 2001 From: Juan Bono Date: Mon, 11 Apr 2022 00:36:55 -0300 Subject: [PATCH 6/7] fix misc warnings Signed-off-by: Juan Bono --- src/configuration/uapi/mod.rs | 2 +- src/platform/udp.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/configuration/uapi/mod.rs b/src/configuration/uapi/mod.rs index c41e2e86..cf1bb30e 100644 --- a/src/configuration/uapi/mod.rs +++ b/src/configuration/uapi/mod.rs @@ -53,7 +53,7 @@ pub fn handle(stream: &mut S, config: &C) { let mut parser = LineParser::new(config); loop { let ln = readline(stream)?; - if ln == "" { + if ln.is_empty() { break; } let (k, v) = keypair(ln.as_str())?; diff --git a/src/platform/udp.rs b/src/platform/udp.rs index 0b9c823c..0af2d411 100644 --- a/src/platform/udp.rs +++ b/src/platform/udp.rs @@ -13,6 +13,7 @@ pub trait Writer: Send + Sync + 'static { fn write(&self, buf: &[u8], dst: &mut E) -> Result<(), Self::Error>; } +#[allow(clippy::upper_case_acronyms)] pub trait UDP: Send + Sync + 'static { type Error: Error; type Endpoint: Endpoint; From 3c680c4f62bc4fee7d8e619573f9e4d5f3fe5043 Mon Sep 17 00:00:00 2001 From: Juan Bono Date: Mon, 11 Apr 2022 00:39:46 -0300 Subject: [PATCH 7/7] fix 'wrong_self_convention' warning by renaming into_address Signed-off-by: Juan Bono --- src/platform/dummy/endpoint.rs | 2 +- src/platform/endpoint.rs | 2 +- src/platform/linux/udp.rs | 2 +- src/wireguard/router/device.rs | 2 +- src/wireguard/router/peer.rs | 2 +- src/wireguard/workers.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/dummy/endpoint.rs b/src/platform/dummy/endpoint.rs index f5fc32c4..05d7d82b 100644 --- a/src/platform/dummy/endpoint.rs +++ b/src/platform/dummy/endpoint.rs @@ -10,7 +10,7 @@ impl Endpoint for UnitEndpoint { UnitEndpoint {} } - fn into_address(&self) -> SocketAddr { + fn to_address(&self) -> SocketAddr { "127.0.0.1:8080".parse().unwrap() } diff --git a/src/platform/endpoint.rs b/src/platform/endpoint.rs index 4702aab3..ef4da9a5 100644 --- a/src/platform/endpoint.rs +++ b/src/platform/endpoint.rs @@ -2,6 +2,6 @@ use std::net::SocketAddr; pub trait Endpoint: Send + 'static { fn from_address(addr: SocketAddr) -> Self; - fn into_address(&self) -> SocketAddr; + fn to_address(&self) -> SocketAddr; fn clear_src(&mut self); } diff --git a/src/platform/linux/udp.rs b/src/platform/linux/udp.rs index b62d5bfa..28ece0db 100644 --- a/src/platform/linux/udp.rs +++ b/src/platform/linux/udp.rs @@ -165,7 +165,7 @@ impl Endpoint for LinuxEndpoint { } } - fn into_address(&self) -> SocketAddr { + fn to_address(&self) -> SocketAddr { match self { LinuxEndpoint::V4(EndpointV4 { ref dst, .. }) => { SocketAddr::V4(SocketAddrV4::new( diff --git a/src/wireguard/router/device.rs b/src/wireguard/router/device.rs index eeae621e..f7945dd5 100644 --- a/src/wireguard/router/device.rs +++ b/src/wireguard/router/device.rs @@ -209,7 +209,7 @@ impl> DeviceHandle< /// /// # Returns pub fn recv(&self, src: E, msg: Vec) -> Result<(), RouterError> { - log::trace!("receive, src: {}", src.into_address()); + log::trace!("receive, src: {}", src.to_address()); // parse / cast let (header, _) = match LayoutVerified::new_from_prefix(&msg[..]) { diff --git a/src/wireguard/router/peer.rs b/src/wireguard/router/peer.rs index 79615156..8ba6f021 100644 --- a/src/wireguard/router/peer.rs +++ b/src/wireguard/router/peer.rs @@ -376,7 +376,7 @@ impl> PeerHandle Option { log::trace!("peer.get_endpoint"); - self.peer.endpoint.lock().as_ref().map(|e| e.into_address()) + self.peer.endpoint.lock().as_ref().map(|e| e.to_address()) } /// Zero all key-material related to the peer diff --git a/src/wireguard/workers.rs b/src/wireguard/workers.rs index 27acf2f5..ad4cc554 100644 --- a/src/wireguard/workers.rs +++ b/src/wireguard/workers.rs @@ -184,7 +184,7 @@ pub fn handshake_worker( &mut OsRng, &msg[..], if under_load { - Some(src.into_address()) + Some(src.to_address()) } else { None },