Skip to content
This repository was archived by the owner on Jan 3, 2024. It is now read-only.

Commit 402f550

Browse files
committed
Use slog internally
1 parent a50f6e4 commit 402f550

File tree

12 files changed

+393
-146
lines changed

12 files changed

+393
-146
lines changed

Cargo.lock

Lines changed: 162 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ hex = "0.4"
1414
untrusted = "0.7"
1515
libc = "0.2"
1616
parking_lot = "0.10"
17+
slog = "2.5"
18+
slog-term = "2.5"
1719

1820
[target.'cfg(not(target_arch="arm"))'.dependencies]
1921
ring = "0.16"

src/device/integration_tests/mod.rs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod tests {
1111
use hex::encode;
1212
#[cfg(not(target_arch = "arm"))]
1313
use ring::rand::*;
14+
use slog::*;
1415
use std::io::prelude::*;
1516
use std::io::{BufReader, Read, Write};
1617
use std::net::*;
@@ -246,12 +247,19 @@ mod tests {
246247
impl WGHandle {
247248
/// Create a new interface for the tunnel with the given address
248249
fn init(addr_v4: IpAddr, addr_v6: IpAddr) -> WGHandle {
250+
let logger = Logger::root(
251+
slog_term::FullFormat::new(slog_term::PlainSyncDecorator::new(std::io::stdout()))
252+
.build()
253+
.fuse(),
254+
slog::o!(),
255+
);
256+
249257
WGHandle::init_with_config(
250258
addr_v4,
251259
addr_v6,
252260
DeviceConfig {
253261
n_threads: 2,
254-
log_level: Verbosity::None,
262+
logger,
255263
use_connected_socket: true,
256264
#[cfg(target_os = "linux")]
257265
use_multi_queue: true,
@@ -529,12 +537,19 @@ mod tests {
529537
let addr_v4 = next_ip();
530538
let addr_v6 = next_ip_v6();
531539

540+
let logger = Logger::root(
541+
slog_term::FullFormat::new(slog_term::PlainSyncDecorator::new(std::io::stdout()))
542+
.build()
543+
.fuse(),
544+
slog::o!(),
545+
);
546+
532547
let mut wg = WGHandle::init_with_config(
533548
addr_v4,
534549
addr_v6,
535550
DeviceConfig {
536551
n_threads: 2,
537-
log_level: Verbosity::None,
552+
logger,
538553
use_connected_socket: false,
539554
#[cfg(target_os = "linux")]
540555
use_multi_queue: true,
@@ -672,6 +687,61 @@ mod tests {
672687
assert_eq!(response, encode(peer.key.public_key().as_bytes()));
673688
}
674689

690+
/// Test if wireguard can handle connection with an ipv6 endpoint
691+
#[test]
692+
#[cfg(target_os = "linux")] // Can't make docker work with ipv6 on macOS ATM
693+
fn test_wg_start_ipv6_endpoint_not_connected() {
694+
let port = next_port();
695+
let private_key = X25519SecretKey::new();
696+
let public_key = private_key.public_key();
697+
let addr_v4 = next_ip();
698+
let addr_v6 = next_ip_v6();
699+
700+
let logger = Logger::root(
701+
slog_term::FullFormat::new(slog_term::PlainSyncDecorator::new(std::io::stdout()))
702+
.build()
703+
.fuse(),
704+
slog::o!(),
705+
);
706+
707+
let mut wg = WGHandle::init_with_config(
708+
addr_v4,
709+
addr_v6,
710+
DeviceConfig {
711+
n_threads: 2,
712+
logger,
713+
use_connected_socket: false,
714+
#[cfg(target_os = "linux")]
715+
use_multi_queue: true,
716+
},
717+
);
718+
719+
assert_eq!(wg.wg_set_port(port), "errno=0\n\n");
720+
assert_eq!(wg.wg_set_key(&private_key), "errno=0\n\n");
721+
722+
let mut peer = Peer::new(
723+
SocketAddr::new(
724+
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
725+
next_port(),
726+
),
727+
vec![AllowedIp {
728+
ip: next_ip_v6(),
729+
cidr: 128,
730+
}],
731+
);
732+
733+
peer.start_in_container(&public_key, &addr_v6, port);
734+
735+
let peer = Arc::new(peer);
736+
737+
wg.add_peer(Arc::clone(&peer));
738+
wg.start();
739+
740+
let response = peer.get_request();
741+
742+
assert_eq!(response, encode(peer.key.public_key().as_bytes()));
743+
}
744+
675745
/// Test many concurrent connections
676746
#[test]
677747
fn test_wg_concurrent() {

0 commit comments

Comments
 (0)