aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-17 19:52:40 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-17 19:52:40 +0100
commit64707b0471b5efe06ac2c93e350676d9d4049b72 (patch)
tree04276f7085fa90e4470986da1d66ce44faa4b24d /src/main.rs
parentUpdate UAPI semantics for remove (diff)
downloadwireguard-rs-64707b0471b5efe06ac2c93e350676d9d4049b72.tar.xz
wireguard-rs-64707b0471b5efe06ac2c93e350676d9d4049b72.zip
Update configuration API
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index e17a127..b1762cb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,24 +10,37 @@ mod configuration;
mod platform;
mod wireguard;
+use log;
+
+use std::env;
+
use platform::tun::PlatformTun;
-use platform::uapi::PlatformUAPI;
+use platform::uapi::{BindUAPI, PlatformUAPI};
use platform::*;
-use std::sync::Arc;
-use std::thread;
-use std::time::Duration;
-
fn main() {
- let name = "wg0";
+ let mut name = String::new();
+ let mut foreground = false;
+
+ for arg in env::args() {
+ if arg == "--foreground" || arg == "-f" {
+ foreground = true;
+ } else {
+ name = arg;
+ }
+ }
+
+ if name == "" {
+ return;
+ }
let _ = env_logger::builder().is_test(true).try_init();
// create UAPI socket
- let uapi = plt::UAPI::bind(name).unwrap();
+ let uapi = plt::UAPI::bind(name.as_str()).unwrap();
// create TUN device
- let (readers, writer, mtu) = plt::Tun::create(name).unwrap();
+ let (readers, writer, mtu) = plt::Tun::create(name.as_str()).unwrap();
// create WireGuard device
let wg: wireguard::Wireguard<plt::Tun, plt::Bind> =
@@ -36,9 +49,12 @@ fn main() {
// wrap in configuration interface and start UAPI server
let cfg = configuration::WireguardConfig::new(wg);
loop {
- let mut stream = uapi.accept().unwrap();
- configuration::uapi::handle(&mut stream.0, &cfg);
+ match uapi.connect() {
+ Ok(mut stream) => configuration::uapi::handle(&mut stream, &cfg),
+ Err(err) => {
+ log::info!("UAPI error: {:}", err);
+ break;
+ }
+ }
}
-
- thread::sleep(Duration::from_secs(600));
}