Fix bugs in #235

This commit is contained in:
Max Lv
2020-05-07 13:43:33 +08:00
parent b6c3fb0bab
commit 1aa8a0cb57
2 changed files with 16 additions and 11 deletions
+2 -2
View File
@@ -282,8 +282,8 @@ impl AccessControl {
pub fn check_ip_in_proxy_list(&self, ip: &IpAddr) -> bool {
match self.mode {
Mode::BlackList => self.black_list.check_ip_matched(ip),
Mode::WhiteList => !self.white_list.check_ip_matched(ip),
Mode::BlackList => !self.black_list.check_ip_matched(ip),
Mode::WhiteList => self.white_list.check_ip_matched(ip),
}
}
+14 -9
View File
@@ -291,9 +291,6 @@ impl Context {
/// Add a record to the reverse lookup cache
#[cfg(feature = "local-dns-relay")]
pub fn add_to_reverse_lookup_cache(&self, addr: &IpAddr, forward: bool) {
if self.check_ip_in_proxy_list(addr) == forward {
return;
}
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
reverse_lookup_cache.insert(addr.clone(), forward);
}
@@ -314,13 +311,21 @@ impl Context {
// Proxy everything by default
None => true,
Some(ref a) => {
// do the reverse lookup in our local cache
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
// if a qname is found
if let Some(forward) = reverse_lookup_cache.get(ip) {
!*forward
// first check the IP list
if a.check_ip_in_proxy_list(ip) {
true
} else {
a.check_ip_in_proxy_list(ip)
// do the reverse lookup in our local cache
let mut reverse_lookup_cache = self.reverse_lookup_cache.lock();
// if a qname is found
if let Some(forward) = reverse_lookup_cache.get(ip) {
// if qname is resolved by remote,
// we should proxy it as well
*forward
} else {
// by default not proxied
false
}
}
}
}