aboutsummaryrefslogtreecommitdiffstats
path: root/src/configuration
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-12-21 00:17:31 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-12-21 00:17:31 +0100
commitaabefa50436af8d614520bb219d675953eeba6eb (patch)
tree9186ef07b94f12e75040d5163477ef1e549cee14 /src/configuration
parentConstant renamed to be consistent with kernel WG (diff)
downloadwireguard-rs-aabefa50436af8d614520bb219d675953eeba6eb.tar.xz
wireguard-rs-aabefa50436af8d614520bb219d675953eeba6eb.zip
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.
Diffstat (limited to 'src/configuration')
-rw-r--r--src/configuration/config.rs10
-rw-r--r--src/configuration/error.rs39
2 files changed, 30 insertions, 19 deletions
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<T: tun::Tun, B: udp::PlatformUDP> Configuration for WireguardConfig<T, B> {
fn set_fwmark(&self, mark: Option<u32>) -> 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,
}
}
}