Check ipv6 exit policies when trying to connect to an ipv6 port specifically

This commit is contained in:
Nick Mathewson 2020-12-22 09:28:26 -05:00
parent 87cb44a4e5
commit df4524d936
3 changed files with 15 additions and 3 deletions

View File

@ -217,6 +217,15 @@ impl TargetPort {
pub fn ipv6(port: u16) -> TargetPort {
TargetPort { ipv6: true, port }
}
/// Return true if this port is supported by the provided Relay.
pub fn is_supported_by(&self, r: &tor_netdir::Relay<'_>) -> bool {
if self.ipv6 {
r.supports_exit_port_ipv6(self.port)
} else {
r.supports_exit_port_ipv4(self.port)
}
}
}
impl ExitPolicy {

View File

@ -20,7 +20,7 @@ impl ExitPathBuilder {
/// Return true if `r` supports every port in `self.wantports`
fn ports_supported_by(&self, r: &Relay<'_>) -> bool {
self.wantports.iter().all(|p| r.supports_exit_port(p.port))
self.wantports.iter().all(|p| p.is_supported_by(r))
}
/// Try to create and return a path corresponding to the requirements of

View File

@ -380,10 +380,13 @@ impl<'a> Relay<'a> {
self.id() == other.id() && self.rsa_id() == other.rsa_id()
}
/// Return true if this relay allows exiting to `port` on IPv4.
// XXXX-A1 ipv4/ipv6
pub fn supports_exit_port(&self, port: u16) -> bool {
pub fn supports_exit_port_ipv4(&self, port: u16) -> bool {
!self.rs.is_flagged_bad_exit() && self.md.ipv4_policy().allows_port(port)
}
/// Return true if this relay allows exiting to `port` on IPv6.
pub fn supports_exit_port_ipv6(&self, port: u16) -> bool {
!self.rs.is_flagged_bad_exit() && self.md.ipv6_policy().allows_port(port)
}
/// Return true if this relay is suitable for use as a directory
/// cache.
pub fn is_dir_cache(&self) -> bool {