|
|
@ -7,6 +7,7 @@ use crate::ClientCtx;
|
|
|
|
use byteorder::{BigEndian, ByteOrder};
|
|
|
|
use byteorder::{BigEndian, ByteOrder};
|
|
|
|
use rand::prelude::*;
|
|
|
|
use rand::prelude::*;
|
|
|
|
use siphasher::sip128::Hasher128;
|
|
|
|
use siphasher::sip128::Hasher128;
|
|
|
|
|
|
|
|
use std::cmp;
|
|
|
|
use std::hash::Hasher;
|
|
|
|
use std::hash::Hasher;
|
|
|
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
|
|
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
|
|
|
use tokio::net::{TcpStream, UdpSocket};
|
|
|
|
use tokio::net::{TcpStream, UdpSocket};
|
|
|
@ -226,11 +227,12 @@ pub async fn get_cached_response_or_resolve(
|
|
|
|
#[cfg(feature = "metrics")]
|
|
|
|
#[cfg(feature = "metrics")]
|
|
|
|
globals.varz.client_queries_cached.inc();
|
|
|
|
globals.varz.client_queries_cached.inc();
|
|
|
|
cached_response.set_tid(original_tid);
|
|
|
|
cached_response.set_tid(original_tid);
|
|
|
|
|
|
|
|
let original_ttl = cached_response.original_ttl();
|
|
|
|
let mut ttl = cached_response.ttl();
|
|
|
|
let mut ttl = cached_response.ttl();
|
|
|
|
if ttl < globals.client_ttl_jitter {
|
|
|
|
if ttl.saturating_add(globals.client_ttl_holdon) > original_ttl {
|
|
|
|
let jitter = rand::thread_rng().gen::<u32>() % globals.client_ttl_jitter;
|
|
|
|
ttl = original_ttl;
|
|
|
|
ttl = globals.client_ttl_jitter.saturating_add(jitter);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ttl = cmp::max(1, ttl);
|
|
|
|
let mut response = cached_response.into_response();
|
|
|
|
let mut response = cached_response.into_response();
|
|
|
|
dns::set_ttl(&mut response, ttl)?;
|
|
|
|
dns::set_ttl(&mut response, ttl)?;
|
|
|
|
dns::recase_qname(&mut response, &packet_qname)?;
|
|
|
|
dns::recase_qname(&mut response, &packet_qname)?;
|
|
|
|