diff options
author | Jake McGinty <me@jake.su> | 2018-04-05 00:54:12 -0700 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-04-05 00:54:12 -0700 |
commit | 29c8d5636fb7b86e4f9a47a93b2324a53e271a17 (patch) | |
tree | 5105c68647dd4ff83ce64b2c9e629949b192294b /src/udp/frame.rs | |
parent | tools: delete passthrough route in wg-quick > del_if (diff) | |
download | wireguard-rs-29c8d5636fb7b86e4f9a47a93b2324a53e271a17.tar.xz wireguard-rs-29c8d5636fb7b86e4f9a47a93b2324a53e271a17.zip |
udp: only convert 'mapped', not 'compatible' adddresses, to IPv4 internally
Diffstat (limited to '')
-rw-r--r-- | src/udp/frame.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/udp/frame.rs b/src/udp/frame.rs index 7f38e57..1f4feaf 100644 --- a/src/udp/frame.rs +++ b/src/udp/frame.rs @@ -7,6 +7,7 @@ use futures::{Async, Future, Poll, Stream, Sink, StartSend, AsyncSink, future, s use nix::sys::socket::{sockopt, setsockopt}; use udp::{ConnectedUdpSocket, UdpSocket}; use tokio_core::reactor::Handle; +use std::net::Ipv6Addr; pub enum Socket { Unconnected(UdpSocket), @@ -154,13 +155,23 @@ impl UdpFramed { } } +fn v6_mapped_to_v4(addr: Ipv6Addr) -> Option<Ipv4Addr> { + match addr.segments() { + [0, 0, 0, 0, 0, f, g, h] if f == 0xffff => { + Some(Ipv4Addr::new((g >> 8) as u8, g as u8, + (h >> 8) as u8, h as u8)) + }, + _ => None + } +} + pub type PeerServerMessage = (SocketAddr, Vec<u8>); pub struct VecUdpCodec; impl VecUdpCodec { fn decode(&mut self, src: &SocketAddr, buf: &[u8]) -> io::Result<PeerServerMessage> { let unmapped_ip = match src.ip() { IpAddr::V6(v6addr) => { - if let Some(v4addr) = v6addr.to_ipv4() { + if let Some(v4addr) = v6_mapped_to_v4(v6addr) { IpAddr::V4(v4addr) } else { IpAddr::V6(v6addr) |