blob: e17a1271446e55efd4f9cd9ccb1d42b3f491ed19 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#![feature(test)]
#![allow(dead_code)]
extern crate jemallocator;
#[global_allocator]
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
mod configuration;
mod platform;
mod wireguard;
use platform::tun::PlatformTun;
use platform::uapi::PlatformUAPI;
use platform::*;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
fn main() {
let name = "wg0";
let _ = env_logger::builder().is_test(true).try_init();
// create UAPI socket
let uapi = plt::UAPI::bind(name).unwrap();
// create TUN device
let (readers, writer, mtu) = plt::Tun::create(name).unwrap();
// create WireGuard device
let wg: wireguard::Wireguard<plt::Tun, plt::Bind> =
wireguard::Wireguard::new(readers, writer, mtu);
// 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);
}
thread::sleep(Duration::from_secs(600));
}
|