diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-29 16:53:59 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-29 16:53:59 +0100 |
commit | e04a11a8cae5f4f8d29febdb38b93d236c700def (patch) | |
tree | ec756778c5462069ccdad7a30840829391132f19 /src/wireguard/router/device.rs | |
parent | First full test of pure WireGuard (diff) | |
download | wireguard-rs-e04a11a8cae5f4f8d29febdb38b93d236c700def.tar.xz wireguard-rs-e04a11a8cae5f4f8d29febdb38b93d236c700def.zip |
Unified use of make_packet during tests
Diffstat (limited to 'src/wireguard/router/device.rs')
-rw-r--r-- | src/wireguard/router/device.rs | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/src/wireguard/router/device.rs b/src/wireguard/router/device.rs index 254b3de..0818637 100644 --- a/src/wireguard/router/device.rs +++ b/src/wireguard/router/device.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; + use std::net::{Ipv4Addr, Ipv6Addr}; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::mpsc::sync_channel; @@ -14,13 +15,15 @@ use zerocopy::LayoutVerified; use super::anti_replay::AntiReplay; use super::constants::*; -use super::ip::*; + use super::messages::{TransportHeader, TYPE_TRANSPORT}; use super::peer::{new_peer, Peer, PeerInner}; use super::types::{Callbacks, RouterError}; use super::workers::{worker_parallel, JobParallel, Operation}; use super::SIZE_MESSAGE_PREFIX; +use super::route::get_route; + use super::super::{bind, tun, Endpoint, KeyPair}; pub struct DeviceInner<E: Endpoint, C: Callbacks, T: tun::Writer, B: bind::Writer<E>> { @@ -84,40 +87,6 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: bind::Writer<E>> Drop for Dev } } -#[inline(always)] -fn get_route<E: Endpoint, C: Callbacks, T: tun::Writer, B: bind::Writer<E>>( - device: &Arc<DeviceInner<E, C, T, B>>, - packet: &[u8], -) -> Option<Arc<PeerInner<E, C, T, B>>> { - match packet.get(0)? >> 4 { - VERSION_IP4 => { - // check length and cast to IPv4 header - let (header, _): (LayoutVerified<&[u8], IPv4Header>, _) = - LayoutVerified::new_from_prefix(packet)?; - - // lookup destination address - device - .ipv4 - .read() - .longest_match(Ipv4Addr::from(header.f_destination)) - .and_then(|(_, _, p)| Some(p.clone())) - } - VERSION_IP6 => { - // check length and cast to IPv6 header - let (header, _): (LayoutVerified<&[u8], IPv6Header>, _) = - LayoutVerified::new_from_prefix(packet)?; - - // lookup destination address - device - .ipv6 - .read() - .longest_match(Ipv6Addr::from(header.f_destination)) - .and_then(|(_, _, p)| Some(p.clone())) - } - _ => None, - } -} - impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: bind::Writer<E>> Device<E, C, T, B> { pub fn new(num_workers: usize, tun: T) -> Device<E, C, T, B> { // allocate shared device state |