|
|
|
@ -1,4 +1,4 @@ |
|
|
|
use crate::{error::Error, error::Result, virtdevice::VirtualTunDevice, NetworkInterface, Options}; |
|
|
|
use crate::{dns, error::Error, error::Result, virtdevice::VirtualTunDevice, NetworkInterface, Options}; |
|
|
|
use mio::{event::Event, net::TcpStream, net::UdpSocket, unix::SourceFd, Events, Interest, Poll, Token}; |
|
|
|
use smoltcp::{ |
|
|
|
iface::{Config, Interface, SocketHandle, SocketSet}, |
|
|
|
@ -468,7 +468,15 @@ impl<'a> TunToProxy<'a> { |
|
|
|
let (info, _first_packet, payload_offset, payload_size) = result?; |
|
|
|
let origin_dst = SocketAddr::try_from(&info.dst)?; |
|
|
|
let connection_info = match &mut self.options.virtual_dns { |
|
|
|
None => info, |
|
|
|
None => { |
|
|
|
let mut info = info; |
|
|
|
let port = origin_dst.port(); |
|
|
|
if port == 53 && info.protocol == IpProtocol::Udp && dns::addr_is_private(&origin_dst) { |
|
|
|
let dns_addr: SocketAddr = "8.8.8.8:53".parse()?; // TODO: Configurable
|
|
|
|
info.dst = Address::from(dns_addr); |
|
|
|
} |
|
|
|
info |
|
|
|
} |
|
|
|
Some(virtual_dns) => { |
|
|
|
let dst_ip = origin_dst.ip(); |
|
|
|
virtual_dns.touch_ip(&dst_ip); |
|
|
|
@ -798,7 +806,7 @@ impl<'a> TunToProxy<'a> { |
|
|
|
Ok(read_result) => read_result, |
|
|
|
Err(error) => { |
|
|
|
if error.kind() != std::io::ErrorKind::WouldBlock { |
|
|
|
log::error!("Read from proxy: {}", error); |
|
|
|
log::error!("{} Read from proxy: {}", conn_info.dst, error); |
|
|
|
} |
|
|
|
vecbuf.len() |
|
|
|
} |
|
|
|
|