diff --git a/src/config.rs b/src/config.rs index e4ea700..f4e38e7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -138,8 +138,7 @@ impl Config { // Read private key from file or CLI argument let (group_readable, world_readable) = matches .value_of("private-key-file") - .map(is_file_insecurely_readable) - .flatten() + .and_then(is_file_insecurely_readable) .unwrap_or_default(); if group_readable { warnings.push("Private key file is group-readable. This is insecure.".into()); diff --git a/src/wg.rs b/src/wg.rs index 60767e3..1d06444 100644 --- a/src/wg.rs +++ b/src/wg.rs @@ -224,24 +224,22 @@ impl WireGuardTunnel { .ok() // Only care if the packet is destined for this tunnel .filter(|packet| Ipv4Addr::from(packet.dst_addr()) == self.source_peer_ip) - .map(|packet| match packet.protocol() { + .and_then(|packet| match packet.protocol() { IpProtocol::Tcp => Some(PortProtocol::Tcp), IpProtocol::Udp => Some(PortProtocol::Udp), // Unrecognized protocol, so we cannot determine where to route _ => None, - }) - .flatten(), + }), Ok(IpVersion::Ipv6) => Ipv6Packet::new_checked(&packet) .ok() // Only care if the packet is destined for this tunnel .filter(|packet| Ipv6Addr::from(packet.dst_addr()) == self.source_peer_ip) - .map(|packet| match packet.next_header() { + .and_then(|packet| match packet.next_header() { IpProtocol::Tcp => Some(PortProtocol::Tcp), IpProtocol::Udp => Some(PortProtocol::Udp), // Unrecognized protocol, so we cannot determine where to route _ => None, - }) - .flatten(), + }), _ => None, } }