IPv6 enabled

This commit is contained in:
ssrlive 2023-08-23 10:35:21 +08:00
parent e518355756
commit d7861128f4
3 changed files with 24 additions and 9 deletions

View file

@ -99,6 +99,7 @@ pub struct Options {
virtual_dns: Option<virtdns::VirtualDns>,
mtu: Option<usize>,
dns_over_tcp: bool,
ipv6_enabled: bool,
}
impl Options {
@ -118,6 +119,11 @@ impl Options {
self
}
pub fn with_ipv6(mut self) -> Self {
self.ipv6_enabled = true;
self
}
pub fn with_mtu(mut self, mtu: usize) -> Self {
self.mtu = Some(mtu);
self

View file

@ -29,6 +29,14 @@ struct Args {
#[arg(short, long, value_name = "method", value_enum, default_value = "virtual")]
dns: ArgDns,
/// Enable DNS over TCP
#[arg(long)]
dns_over_tcp: bool,
/// IPv6 enabled
#[arg(short = '6', long)]
ipv6_enabled: bool,
/// Routing and system setup
#[arg(short, long, value_name = "method", value_enum)]
setup: Option<ArgSetup>,
@ -40,10 +48,6 @@ struct Args {
/// Verbosity level
#[arg(short, long, value_name = "level", value_enum, default_value = "info")]
verbosity: ArgVerbosity,
/// Enable DNS over TCP
#[arg(long)]
dns_over_tcp: bool,
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
@ -87,6 +91,10 @@ fn main() -> ExitCode {
options = options.with_dns_over_tcp();
}
if args.ipv6_enabled {
options = options.with_ipv6();
}
let interface = match args.tun_fd {
None => NetworkInterface::Named(args.tun.clone()),
Some(fd) => {

View file

@ -184,7 +184,6 @@ struct ConnectionState {
udp_origin_dst: Option<SocketAddr>,
udp_data_cache: LinkedList<Vec<u8>>,
udp_over_tcp_expiry: Option<::std::time::Instant>,
is_tcp_dns: bool,
}
pub(crate) trait TcpProxy {
@ -494,7 +493,6 @@ impl<'a> TunToProxy<'a> {
let tcp_proxy_handler = manager.new_tcp_proxy(info, false)?;
let server_addr = manager.get_server_addr();
let mut state = self.create_new_tcp_connection_state(server_addr, origin_dst, tcp_proxy_handler, false)?;
state.is_tcp_dns = true;
state.udp_origin_dst = Some(SocketAddr::try_from(original_info.dst.clone())?);
self.connection_map.insert(info.clone(), state);
@ -578,7 +576,9 @@ impl<'a> TunToProxy<'a> {
.tcp_proxy_handler
.consume_data(OutgoingDirection::ToClient, len + 2);
dns::remove_ipv6_entries(&mut message); // TODO: Configurable
if !self.options.ipv6_enabled {
dns::remove_ipv6_entries(&mut message);
}
to_send.push_back(message.to_vec()?);
if len + 2 == buf.len() {
@ -778,7 +778,6 @@ impl<'a> TunToProxy<'a> {
udp_origin_dst: None,
udp_data_cache: LinkedList::new(),
udp_over_tcp_expiry: None,
is_tcp_dns: false,
};
Ok(state)
}
@ -929,7 +928,9 @@ impl<'a> TunToProxy<'a> {
let buf = if info.dst.port() == DNS_PORT {
let mut message = dns::parse_data_to_dns_message(&buf[header.len()..], false)?;
dns::remove_ipv6_entries(&mut message); // TODO: Configurable
if !self.options.ipv6_enabled {
dns::remove_ipv6_entries(&mut message);
}
message.to_vec()?
} else {
buf[header.len()..].to_vec()