diff --git a/src/acl/mod.rs b/src/acl/mod.rs index ecf8dcb6..dd3838b2 100644 --- a/src/acl/mod.rs +++ b/src/acl/mod.rs @@ -272,23 +272,20 @@ impl AccessControl { /// FIXME: This function may perform a DNS resolution pub async fn check_target_bypassed(&self, context: &Context, addr: &Address) -> bool { // Always redirect TCP DNS query (for android) - if cfg!(target_os = "android") { - let port = match *addr { - Address::SocketAddress(ref saddr) => saddr.port(), - Address::DomainNameAddress(ref _host, port) => port, - }; - if port == 53 { - return false; - } + if cfg!(target_os = "android") && addr.port() == 53 { + return false; } + // Addresses in bypass_list will be bypassed if self.black_list.check_address_matched(addr) { return true; } + // Addresses in proxy_list will be proxied if self.white_list.check_address_matched(addr) { return false; } + // Resolve hostname and check the list if cfg!(not(target_os = "android")) { if let Address::DomainNameAddress(ref host, port) = *addr { @@ -297,6 +294,7 @@ impl AccessControl { if self.black_list.check_ip_matched(&addr) { return true; } + if self.white_list.check_ip_matched(&addr) { return false; } @@ -304,6 +302,7 @@ impl AccessControl { } } } + // default rule match self.mode { Mode::BlackList => false, diff --git a/src/relay/socks5.rs b/src/relay/socks5.rs index 530ab2dc..eae71522 100644 --- a/src/relay/socks5.rs +++ b/src/relay/socks5.rs @@ -214,6 +214,7 @@ pub enum Address { } impl Address { + /// Parse from a `AsyncRead` pub async fn read_from(stream: &mut R) -> Result where R: AsyncRead + Unpin, @@ -303,10 +304,19 @@ impl Address { write_address(self, buf) } + /// Get required buffer size for serializing #[inline] pub fn serialized_len(&self) -> usize { get_addr_len(self) } + + /// Get associated port number + pub fn port(&self) -> u16 { + match *self { + Address::SocketAddress(addr) => addr.port(), + Address::DomainNameAddress(.., port) => port, + } + } } impl Debug for Address {