mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-07 23:27:46 +00:00
Do not allow errors in printing function to screw up DNS lookups
This commit is contained in:
parent
edb775941e
commit
cdbed3ed9b
2 changed files with 24 additions and 16 deletions
|
@ -78,6 +78,7 @@ pub fn extract_ipaddr_from_dns_message(message: &Message) -> Result<IpAddr, Stri
|
||||||
if let Some(cname) = cname {
|
if let Some(cname) = cname {
|
||||||
return Err(cname);
|
return Err(cname);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(format!("{:?}", message.answers()))
|
Err(format!("{:?}", message.answers()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,3 @@
|
||||||
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},
|
|
||||||
phy::{Device, Medium, RxToken, TunTapInterface, TxToken},
|
|
||||||
socket::{tcp, tcp::State, udp, udp::UdpMetadata},
|
|
||||||
time::Instant,
|
|
||||||
wire::{IpCidr, IpProtocol, Ipv4Packet, Ipv6Packet, TcpPacket, UdpPacket, UDP_HEADER_LEN},
|
|
||||||
};
|
|
||||||
use socks5_impl::protocol::{Address, StreamOperation, UdpHeader, UserKey};
|
|
||||||
use std::collections::LinkedList;
|
use std::collections::LinkedList;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
|
@ -19,6 +9,18 @@ use std::{
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use mio::{event::Event, net::TcpStream, net::UdpSocket, unix::SourceFd, Events, Interest, Poll, Token};
|
||||||
|
use smoltcp::{
|
||||||
|
iface::{Config, Interface, SocketHandle, SocketSet},
|
||||||
|
phy::{Device, Medium, RxToken, TunTapInterface, TxToken},
|
||||||
|
socket::{tcp, tcp::State, udp, udp::UdpMetadata},
|
||||||
|
time::Instant,
|
||||||
|
wire::{IpCidr, IpProtocol, Ipv4Packet, Ipv6Packet, TcpPacket, UdpPacket, UDP_HEADER_LEN},
|
||||||
|
};
|
||||||
|
use socks5_impl::protocol::{Address, StreamOperation, UdpHeader, UserKey};
|
||||||
|
|
||||||
|
use crate::{dns, error::Error, error::Result, virtdevice::VirtualTunDevice, NetworkInterface, Options};
|
||||||
|
|
||||||
#[derive(Hash, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)]
|
#[derive(Hash, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)]
|
||||||
pub(crate) struct ConnectionInfo {
|
pub(crate) struct ConnectionInfo {
|
||||||
pub(crate) src: SocketAddr,
|
pub(crate) src: SocketAddr,
|
||||||
|
@ -167,7 +169,8 @@ fn connection_tuple(frame: &[u8]) -> Result<(ConnectionInfo, bool, usize, usize)
|
||||||
const SERVER_WRITE_CLOSED: u8 = 1;
|
const SERVER_WRITE_CLOSED: u8 = 1;
|
||||||
const CLIENT_WRITE_CLOSED: u8 = 2;
|
const CLIENT_WRITE_CLOSED: u8 = 2;
|
||||||
|
|
||||||
const UDP_ASSO_TIMEOUT: u64 = 10; // seconds
|
const UDP_ASSO_TIMEOUT: u64 = 10;
|
||||||
|
// seconds
|
||||||
const DNS_PORT: u16 = 53;
|
const DNS_PORT: u16 = 53;
|
||||||
|
|
||||||
struct TcpConnectState {
|
struct TcpConnectState {
|
||||||
|
@ -578,9 +581,13 @@ impl<'a> TunToProxy<'a> {
|
||||||
let data = buf[2..len + 2].to_vec();
|
let data = buf[2..len + 2].to_vec();
|
||||||
|
|
||||||
let message = dns::parse_data_to_dns_message(&data, false)?;
|
let message = dns::parse_data_to_dns_message(&data, false)?;
|
||||||
let name = dns::extract_domain_from_dns_message(&message)?;
|
|
||||||
let ip = dns::extract_ipaddr_from_dns_message(&message)?;
|
if let (Ok(name), Ok(ip)) = (
|
||||||
|
dns::extract_domain_from_dns_message(&message),
|
||||||
|
dns::extract_ipaddr_from_dns_message(&message),
|
||||||
|
) {
|
||||||
log::info!("DNS over TCP ======== {} -> {}", name, ip);
|
log::info!("DNS over TCP ======== {} -> {}", name, ip);
|
||||||
|
}
|
||||||
state
|
state
|
||||||
.tcp_proxy_handler
|
.tcp_proxy_handler
|
||||||
.consume_data(OutgoingDirection::ToClient, len + 2);
|
.consume_data(OutgoingDirection::ToClient, len + 2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue