From aabefa50436af8d614520bb219d675953eeba6eb Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sat, 21 Dec 2019 00:17:31 +0100 Subject: Remove unused test code. - make naming consistent with the kernel module. - better distribution of functionality from src/wireguard.rs - more consistent "import pattern" throughout the project. - remove unused test code. --- src/configuration/config.rs | 10 ++++++---- src/configuration/error.rs | 39 ++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 19 deletions(-) (limited to 'src/configuration') diff --git a/src/configuration/config.rs b/src/configuration/config.rs index 94b79f7..ac6e9a1 100644 --- a/src/configuration/config.rs +++ b/src/configuration/config.rs @@ -288,13 +288,15 @@ impl Configuration for WireguardConfig { fn set_fwmark(&self, mark: Option) -> Result<(), ConfigError> { log::trace!("Config, Set fwmark: {:?}", mark); - match self.lock().bind.as_mut() { Some(bind) => { - bind.set_fwmark(mark).unwrap(); // TODO: handle - Ok(()) + if bind.set_fwmark(mark).is_err() { + Err(ConfigError::IOError) + } else { + Ok(()) + } } - None => Err(ConfigError::NotListening), + None => Ok(()), } } diff --git a/src/configuration/error.rs b/src/configuration/error.rs index fca194f..de790e2 100644 --- a/src/configuration/error.rs +++ b/src/configuration/error.rs @@ -1,9 +1,11 @@ use std::error::Error; use std::fmt; +#[cfg(unix)] +use libc::*; + #[derive(Debug)] pub enum ConfigError { - NotListening, FailedToBind, InvalidHexValue, InvalidPortNumber, @@ -35,24 +37,31 @@ impl Error for ConfigError { } } +#[cfg(unix)] impl ConfigError { pub fn errno(&self) -> i32 { // TODO: obtain the correct errorno values match self { - ConfigError::NotListening => 2, - ConfigError::FailedToBind => 3, - ConfigError::InvalidHexValue => 4, - ConfigError::InvalidPortNumber => 5, - ConfigError::InvalidFwmark => 6, - ConfigError::InvalidSocketAddr => 10, - ConfigError::InvalidKeepaliveInterval => 11, - ConfigError::InvalidAllowedIp => 12, - ConfigError::InvalidOperation => 15, - ConfigError::UnsupportedValue => 7, - ConfigError::LineTooLong => 13, - ConfigError::InvalidKey => 8, - ConfigError::UnsupportedProtocolVersion => 9, - ConfigError::IOError => 14, + // insufficient perms + ConfigError::FailedToBind => EPERM, + + // parsing of value failed + ConfigError::InvalidHexValue => EINVAL, + ConfigError::InvalidPortNumber => EINVAL, + ConfigError::InvalidFwmark => EINVAL, + ConfigError::InvalidSocketAddr => EINVAL, + ConfigError::InvalidKeepaliveInterval => EINVAL, + ConfigError::InvalidAllowedIp => EINVAL, + ConfigError::InvalidOperation => EINVAL, + ConfigError::UnsupportedValue => EINVAL, + + // other protocol errors + ConfigError::LineTooLong => EPROTO, + ConfigError::InvalidKey => EPROTO, + ConfigError::UnsupportedProtocolVersion => EPROTO, + + // IO + ConfigError::IOError => EIO, } } } -- cgit v1.2.3-59-g8ed1b