diff --git a/src/lib.rs b/src/lib.rs index 78e6d0b..94c1280 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,6 +108,7 @@ pub struct Options { dns_over_tcp: bool, dns_addr: Option, ipv6_enabled: bool, + bypass_ip: Option, } impl Options { @@ -141,6 +142,11 @@ impl Options { self.mtu = Some(mtu); self } + + pub fn with_bypass_ip(mut self, ip: Option) -> Self { + self.bypass_ip = ip; + self + } } pub fn tun_to_proxy<'a>( diff --git a/src/main.rs b/src/main.rs index c513d1d..dfaae3d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,12 +110,18 @@ fn main() -> ExitCode { Some(_fd) => { options = options.with_mtu(args.tun_mtu); #[cfg(not(target_family = "unix"))] - panic!("Not supported"); + panic!("Not supported file descriptor"); #[cfg(target_family = "unix")] NetworkInterface::Fd(_fd) } }; + let bypass_tun_ip = match args.bypass_ip { + Some(addr) => addr, + None => args.proxy.addr.ip(), + }; + options = options.with_bypass_ip(Some(bypass_tun_ip)); + let block = || -> Result<(), Error> { #[cfg(target_os = "linux")] { diff --git a/src/tun2proxy.rs b/src/tun2proxy.rs index 2488f15..d746f13 100644 --- a/src/tun2proxy.rs +++ b/src/tun2proxy.rs @@ -250,7 +250,7 @@ impl<'a> TunToProxy<'a> { }; #[cfg(target_os = "windows")] - let tun = match _interface { + let mut tun = match _interface { NetworkInterface::Named(name) => WinTunInterface::new(name.as_str(), Medium::Ip)?, }; @@ -260,6 +260,9 @@ impl<'a> TunToProxy<'a> { poll.registry() .register(&mut SourceFd(&tun.as_raw_fd()), TUN_TOKEN, Interest::READABLE)?; + #[cfg(target_os = "windows")] + poll.registry().register(&mut tun, TUN_TOKEN, Interest::READABLE)?; + #[cfg(target_family = "unix")] let (exit_sender, mut exit_receiver) = mio::unix::pipe::new()?; #[cfg(target_family = "unix")] diff --git a/src/wintuninterface.rs b/src/wintuninterface.rs index 99a87be..3a7aada 100644 --- a/src/wintuninterface.rs +++ b/src/wintuninterface.rs @@ -1,3 +1,4 @@ +use mio::{event, Interest, Registry, Token}; use smoltcp::{ phy::{self, Device, DeviceCapabilities, Medium}, time::Instant, @@ -22,6 +23,20 @@ pub struct WinTunInterface { // } // } +impl event::Source for WinTunInterface { + fn register(&mut self, _registry: &Registry, _token: Token, _interests: Interest) -> io::Result<()> { + Err(io::Error::new(io::ErrorKind::Other, "register")) + } + + fn reregister(&mut self, _registry: &Registry, _token: Token, _interests: Interest) -> io::Result<()> { + Err(io::Error::new(io::ErrorKind::Other, "reregister")) + } + + fn deregister(&mut self, _registry: &Registry) -> io::Result<()> { + Err(io::Error::new(io::ErrorKind::Other, "deregister")) + } +} + impl WinTunInterface { pub fn new(name: &str, medium: Medium) -> io::Result { let wintun = unsafe { wintun::load() }.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;