Skip to content

Commit 85c99b9

Browse files
committed
ACL IP rules compatible with IPv4-mapped-IPv6
fix #1060
1 parent 9523eec commit 85c99b9

File tree

1 file changed

+19
-2
lines changed
  • crates/shadowsocks-service/src/acl

1 file changed

+19
-2
lines changed

crates/shadowsocks-service/src/acl/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,25 @@ impl Rules {
117117
/// Check if the specified address matches any rules
118118
fn check_ip_matched(&self, addr: &IpAddr) -> bool {
119119
match addr {
120-
IpAddr::V4(v4) => self.ipv4.contains(v4),
121-
IpAddr::V6(v6) => self.ipv6.contains(v6),
120+
IpAddr::V4(v4) => {
121+
if self.ipv4.contains(v4) {
122+
return true;
123+
}
124+
125+
let mapped_ipv6 = v4.to_ipv6_mapped();
126+
self.ipv6.contains(&mapped_ipv6)
127+
}
128+
IpAddr::V6(v6) => {
129+
if self.ipv6.contains(v6) {
130+
return true;
131+
}
132+
133+
if let Some(mapped_ipv4) = v6.to_ipv4_mapped() {
134+
return self.ipv4.contains(&mapped_ipv4);
135+
}
136+
137+
false
138+
}
122139
}
123140
}
124141

0 commit comments

Comments
 (0)