From 7d84ef9064559a29b23ab86036f7ef62b450f90c Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Wed, 13 Jan 2021 18:10:04 +0100 Subject: Allows for erroneous Clippy lints Signed-off-by: Mathias Hall-Andersen --- src/platform/linux/tun.rs | 1 + src/platform/linux/udp.rs | 2 ++ src/platform/tun.rs | 1 + src/platform/udp.rs | 1 + src/wireguard/handshake/macs.rs | 1 + src/wireguard/handshake/ratelimiter.rs | 3 ++- src/wireguard/mod.rs | 21 +++++++++++---------- src/wireguard/router/device.rs | 1 + src/wireguard/router/tests/bench.rs | 4 ++++ src/wireguard/wireguard.rs | 9 ++++++--- 10 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/platform/linux/tun.rs b/src/platform/linux/tun.rs index 9157b38..82fada1 100644 --- a/src/platform/linux/tun.rs +++ b/src/platform/linux/tun.rs @@ -318,6 +318,7 @@ impl Tun for LinuxTun { impl PlatformTun for LinuxTun { type Status = LinuxTunStatus; + #[allow(clippy::type_complexity)] fn create(name: &str) -> Result<(Vec, Self::Writer, Self::Status), Self::Error> { // construct request struct let mut req = Ifreq { diff --git a/src/platform/linux/udp.rs b/src/platform/linux/udp.rs index e1ceb73..b62d5bf 100644 --- a/src/platform/linux/udp.rs +++ b/src/platform/linux/udp.rs @@ -666,6 +666,8 @@ impl LinuxUDP { impl PlatformUDP for LinuxUDP { type Owner = LinuxOwner; + #[allow(clippy::type_complexity)] + #[allow(clippy::unnecessary_unwrap)] fn bind(mut port: u16) -> Result<(Vec, Self::Writer, Self::Owner), Self::Error> { log::debug!("bind to port {}", port); diff --git a/src/platform/tun.rs b/src/platform/tun.rs index 801754e..38c95bf 100644 --- a/src/platform/tun.rs +++ b/src/platform/tun.rs @@ -58,5 +58,6 @@ pub trait Tun: Send + Sync + 'static { pub trait PlatformTun: Tun { type Status: Status; + #[allow(clippy::type_complexity)] fn create(name: &str) -> Result<(Vec, Self::Writer, Self::Status), Self::Error>; } diff --git a/src/platform/udp.rs b/src/platform/udp.rs index 4098b10..0b9c823 100644 --- a/src/platform/udp.rs +++ b/src/platform/udp.rs @@ -41,5 +41,6 @@ pub trait PlatformUDP: UDP { /// Bind to a new port, returning the reader/writer and /// an associated instance of the owner type, which closes the UDP socket upon "drop" /// and enables configuration of the fwmark value. + #[allow(clippy::type_complexity)] fn bind(port: u16) -> Result<(Vec, Self::Writer, Self::Owner), Self::Error>; } diff --git a/src/wireguard/handshake/macs.rs b/src/wireguard/handshake/macs.rs index 8d79c5e..f4f5586 100644 --- a/src/wireguard/handshake/macs.rs +++ b/src/wireguard/handshake/macs.rs @@ -141,6 +141,7 @@ impl Generator { pub fn process(&mut self, reply: &CookieReply) -> Result<(), HandshakeError> { let mac1 = self.last_mac1.ok_or(HandshakeError::InvalidState)?; let mut tau = [0u8; SIZE_COOKIE]; + #[allow(clippy::unnecessary_mut_passed)] XOPEN!( &self.cookie_key, // key &reply.f_nonce, // nonce diff --git a/src/wireguard/handshake/ratelimiter.rs b/src/wireguard/handshake/ratelimiter.rs index f6210fc..9e796a0 100644 --- a/src/wireguard/handshake/ratelimiter.rs +++ b/src/wireguard/handshake/ratelimiter.rs @@ -37,6 +37,7 @@ impl Drop for RateLimiter { impl RateLimiter { pub fn new() -> Self { + #[allow(clippy::mutex_atomic)] RateLimiter(Arc::new(RateLimiterInner { gc_dropped: (Mutex::new(false), Condvar::new()), gc_running: AtomicBool::from(false), @@ -143,7 +144,7 @@ mod tests { expected.push(Result { allowed: true, wait: Duration::new(0, 0), - text: "inital burst", + text: "initial burst", }); } diff --git a/src/wireguard/mod.rs b/src/wireguard/mod.rs index ca17737..e79a250 100644 --- a/src/wireguard/mod.rs +++ b/src/wireguard/mod.rs @@ -1,12 +1,11 @@ -/* The wireguard sub-module represents a full, pure, WireGuard implementation: - * - * The WireGuard device described here does not depend on particular IO implementations - * or UAPI, and can be instantiated in unit-tests with the dummy IO implementation. - * - * The code at this level serves to "glue" the handshake state-machine - * and the crypto-key router code together, - * e.g. every WireGuard peer consists of a handshake and router peer. - */ +/// The wireguard sub-module represents a full, pure, WireGuard implementation: +/// +/// The WireGuard device described here does not depend on particular IO implementations +/// or UAPI, and can be instantiated in unit-tests with the dummy IO implementation. +/// +/// The code at this level serves to "glue" the handshake state-machine +/// and the crypto-key router code together, +/// e.g. every WireGuard peer consists of one handshake peer and one router peer. mod constants; mod handshake; mod peer; @@ -14,12 +13,14 @@ mod queue; mod router; mod timers; mod types; -mod wireguard; mod workers; #[cfg(test)] mod tests; +#[allow(clippy::module_inception)] +mod wireguard; + // represents a WireGuard interface pub use wireguard::WireGuard; diff --git a/src/wireguard/router/device.rs b/src/wireguard/router/device.rs index 54e5149..eeae621 100644 --- a/src/wireguard/router/device.rs +++ b/src/wireguard/router/device.rs @@ -30,6 +30,7 @@ pub struct DeviceInner)>, // routing + #[allow(clippy::type_complexity)] pub(super) recv: RwLock>>>, /* receiver id -> decryption state */ pub(super) table: RoutingTable>, diff --git a/src/wireguard/router/tests/bench.rs b/src/wireguard/router/tests/bench.rs index 948a156..c2334b3 100644 --- a/src/wireguard/router/tests/bench.rs +++ b/src/wireguard/router/tests/bench.rs @@ -25,6 +25,7 @@ struct TransmissionCounter { } impl TransmissionCounter { + #[allow(dead_code)] fn new() -> TransmissionCounter { TransmissionCounter { sent: AtomicUsize::new(0), @@ -32,15 +33,18 @@ impl TransmissionCounter { } } + #[allow(dead_code)] fn reset(&self) { self.sent.store(0, Ordering::SeqCst); self.recv.store(0, Ordering::SeqCst); } + #[allow(dead_code)] fn sent(&self) -> usize { self.sent.load(Ordering::Acquire) } + #[allow(dead_code)] fn recv(&self) -> usize { self.recv.load(Ordering::Acquire) } diff --git a/src/wireguard/wireguard.rs b/src/wireguard/wireguard.rs index 35bd342..44d698f 100644 --- a/src/wireguard/wireguard.rs +++ b/src/wireguard/wireguard.rs @@ -13,19 +13,20 @@ use super::udp::UDP; use super::workers::{handshake_worker, tun_worker, udp_worker}; use std::fmt; +use std::thread; + use std::ops::Deref; use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; use std::sync::Arc; use std::sync::Condvar; use std::sync::Mutex as StdMutex; -use std::thread; use std::time::Instant; -use hjul::Runner; use rand::rngs::OsRng; use rand::Rng; -use spin::{Mutex, RwLock}; +use hjul::Runner; +use spin::{Mutex, RwLock}; use x25519_dalek::{PublicKey, StaticSecret}; pub struct WireguardInner { @@ -45,6 +46,7 @@ pub struct WireguardInner { pub mtu: AtomicUsize, // peer map + #[allow(clippy::type_complexity)] pub peers: RwLock< handshake::Device, T::Writer, B::Writer>>, >, @@ -85,6 +87,7 @@ impl Clone for WireGuard { } } +#[allow(clippy::mutex_atomic)] impl WaitCounter { pub fn wait(&self) { let mut nread = self.0.lock().unwrap(); -- cgit v1.2.3-59-g8ed1b