Skip to content

Commit 49d1a1d

Browse files
author
Maciej Wójcik
committed
lint fixes
1 parent 5804ea0 commit 49d1a1d

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

examples/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{net::SocketAddr, str::FromStr};
22

33
use defguard_wireguard_rs::{
4-
host::Peer, key::Key, net::IpAddrMask, InterfaceConfiguration, Kernel, Userspace, WGApi,
4+
host::Peer, key::Key, net::IpAddrMask, InterfaceConfiguration, Kernel, WGApi,
55
WireguardInterfaceApi,
66
};
77
use x25519_dalek::{EphemeralSecret, PublicKey};

examples/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::str::FromStr;
22

33
use defguard_wireguard_rs::{
4-
host::Peer, key::Key, net::IpAddrMask, InterfaceConfiguration, Kernel, Userspace, WGApi,
4+
host::Peer, key::Key, net::IpAddrMask, InterfaceConfiguration, Kernel, WGApi,
55
WireguardInterfaceApi,
66
};
77
use x25519_dalek::{EphemeralSecret, PublicKey};

examples/userspace.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
use std::{
2-
io::{stdin, stdout, Read, Write},
3-
net::SocketAddr,
4-
str::FromStr,
5-
};
1+
#[cfg(target_os = "macos")]
2+
use std::io::{stdin, stdout, Read, Write};
63

7-
use defguard_wireguard_rs::{host::Peer, key::Key, net::IpAddrMask, InterfaceConfiguration};
84
#[cfg(target_os = "macos")]
95
use defguard_wireguard_rs::{Userspace, WGApi, WireguardInterfaceApi};
10-
use x25519_dalek::{EphemeralSecret, PublicKey};
116

7+
#[cfg(target_os = "macos")]
128
fn pause() {
139
let mut stdout = stdout();
1410
stdout.write_all(b"Press Enter to continue...").unwrap();

src/netlink.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ fn get_interface_index(ifname: &str) -> NetlinkResult<Option<u32>> {
467467
Ok(None)
468468
}
469469

470+
#[cfg(test)]
470471
/// Get default route for a given address family.
471472
pub(crate) fn get_gateway(address_family: AddressFamily) -> NetlinkResult<Option<IpAddr>> {
472473
let header = RouteHeader {
@@ -493,16 +494,13 @@ pub(crate) fn get_gateway(address_family: AddressFamily) -> NetlinkResult<Option
493494
// Because messages can't be properly filtered, find the first `Gateway`.
494495
if let RouteNetlinkMessage::NewRoute(RouteMessage { attributes, .. }) = message {
495496
for nla in attributes {
496-
match nla {
497-
RouteAttribute::Gateway(address) => {
498-
debug!("Found gateway {address:?}");
499-
match address {
500-
RouteAddress::Inet(ipv4) => return Ok(Some(IpAddr::V4(ipv4))),
501-
RouteAddress::Inet6(ipv6) => return Ok(Some(IpAddr::V6(ipv6))),
502-
_ => (),
503-
}
497+
if let RouteAttribute::Gateway(address) = nla {
498+
debug!("Found gateway {address:?}");
499+
match address {
500+
RouteAddress::Inet(ipv4) => return Ok(Some(IpAddr::V4(ipv4))),
501+
RouteAddress::Inet6(ipv6) => return Ok(Some(IpAddr::V6(ipv6))),
502+
_ => (),
504503
}
505-
_ => (),
506504
}
507505
}
508506
}

src/wgapi_linux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl WireguardInterfaceApi for WGApi<Kernel> {
5353
// Assign IP addresses to the interface.
5454
for address in &config.addresses {
5555
debug!("Assigning address {address} to interface {}", self.ifname);
56-
self.assign_address(&address)?;
56+
self.assign_address(address)?;
5757
debug!(
5858
"Address {address} assigned to interface {} successfully",
5959
self.ifname
@@ -102,9 +102,9 @@ impl WireguardInterfaceApi for WGApi<Kernel> {
102102
/// If allowed IPs contain a default route, instead of adding a route for every peer, the following changes are made:
103103
/// - A new default route is added
104104
/// - The current default route is suppressed by modifying the main routing table rule with `suppress_prefixlen 0`, this makes
105-
/// it so that the whole main routing table rules are still applied except for the default route rules (so the new default route is used instead)
105+
/// it so that the whole main routing table rules are still applied except for the default route rules (so the new default route is used instead)
106106
/// - A rule pushing all traffic through the WireGuard interface is added with the exception of traffic marked with 51820 (default) fwmark which
107-
/// is used for the WireGuard traffic itself (so it doesn't get stuck in a loop)
107+
/// is used for the WireGuard traffic itself (so it doesn't get stuck in a loop)
108108
///
109109
fn configure_peer_routing(&self, peers: &[Peer]) -> Result<(), WireguardInterfaceError> {
110110
add_peer_routing(peers, &self.ifname)?;

0 commit comments

Comments
 (0)