mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-06-07 23:27:46 +00:00
Virtual DNS: Do not add trailing dot
This commit is contained in:
parent
b8c22db037
commit
b525d3f99e
1 changed files with 7 additions and 1 deletions
|
@ -19,6 +19,7 @@ struct NameCacheEntry {
|
||||||
/// The IP addresses are in the range of private IP addresses.
|
/// The IP addresses are in the range of private IP addresses.
|
||||||
/// The DNS server is implemented as a LRU cache.
|
/// The DNS server is implemented as a LRU cache.
|
||||||
pub struct VirtualDns {
|
pub struct VirtualDns {
|
||||||
|
trailing_dot: bool,
|
||||||
lru_cache: LruCache<IpAddr, NameCacheEntry>,
|
lru_cache: LruCache<IpAddr, NameCacheEntry>,
|
||||||
name_to_ip: HashMap<String, IpAddr>,
|
name_to_ip: HashMap<String, IpAddr>,
|
||||||
network_addr: IpAddr,
|
network_addr: IpAddr,
|
||||||
|
@ -35,6 +36,7 @@ impl Default for VirtualDns {
|
||||||
let broadcast_addr = calculate_broadcast_addr(start_addr, prefix_len);
|
let broadcast_addr = calculate_broadcast_addr(start_addr, prefix_len);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
trailing_dot: false,
|
||||||
next_addr: start_addr.into(),
|
next_addr: start_addr.into(),
|
||||||
name_to_ip: HashMap::default(),
|
name_to_ip: HashMap::default(),
|
||||||
network_addr: IpAddr::from(network_addr),
|
network_addr: IpAddr::from(network_addr),
|
||||||
|
@ -54,7 +56,11 @@ impl VirtualDns {
|
||||||
use crate::dns;
|
use crate::dns;
|
||||||
let message = dns::parse_data_to_dns_message(data, false)?;
|
let message = dns::parse_data_to_dns_message(data, false)?;
|
||||||
let qname = dns::extract_domain_from_dns_message(&message)?;
|
let qname = dns::extract_domain_from_dns_message(&message)?;
|
||||||
let ip = self.allocate_ip(qname.clone())?;
|
let mut insert_name = qname.clone();
|
||||||
|
if insert_name.ends_with('.') && !self.trailing_dot {
|
||||||
|
insert_name = String::from(insert_name.trim_end_matches('.'));
|
||||||
|
}
|
||||||
|
let ip = self.allocate_ip(insert_name)?;
|
||||||
let message = dns::build_dns_response(message, &qname, ip, 5)?;
|
let message = dns::build_dns_response(message, &qname, ip, 5)?;
|
||||||
Ok((message.to_vec()?, qname, ip))
|
Ok((message.to_vec()?, qname, ip))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue