diff --git a/src/platform/linux/tun.rs b/src/platform/linux/tun.rs index 82fada1..304966d 100644 --- a/src/platform/linux/tun.rs +++ b/src/platform/linux/tun.rs @@ -106,8 +106,9 @@ impl Reader for LinuxTunReader { impl Writer for LinuxTunWriter { type Error = LinuxTunError; - fn write(&self, src: &[u8]) -> Result<(), Self::Error> { - match unsafe { libc::write(self.fd, src.as_ptr() as _, src.len() as _) } { + fn write(&self, src: &[u8], offset: usize) -> Result<(), Self::Error> { + let data = &src[offset..]; + match unsafe { libc::write(self.fd, data.as_ptr() as _, data.len() as _) } { -1 => Err(LinuxTunError::Closed), _ => Ok(()), } diff --git a/src/platform/tun.rs b/src/platform/tun.rs index 38c95bf..b54179c 100644 --- a/src/platform/tun.rs +++ b/src/platform/tun.rs @@ -25,7 +25,7 @@ pub trait Writer: Send + Sync + 'static { /// # Returns /// /// Unit type or an error - fn write(&self, src: &[u8]) -> Result<(), Self::Error>; + fn write(&self, src: &mut [u8], offset: usize) -> Result<(), Self::Error>; } pub trait Reader: Send + 'static { diff --git a/src/wireguard/router/receive.rs b/src/wireguard/router/receive.rs index 15eb8fb..034216a 100644 --- a/src/wireguard/router/receive.rs +++ b/src/wireguard/router/receive.rs @@ -173,7 +173,7 @@ impl> SequentialJob // (keep-alive and malformed packets will have no inner length) if let Some(inner) = inner_length(packet) { if inner + SIZE_TAG <= packet.len() { - let _ = peer.device.inbound.write(&packet[..inner]).map_err(|e| { + let _ = peer.device.inbound.write(&packet, inner).map_err(|e| { log::debug!("failed to write inbound packet to TUN: {:?}", e); }); }