Skip to content

Commit

Permalink
fixed regression of client blocking ACL strategy
Browse files Browse the repository at this point in the history
- fixes #764
- bug introduced since v1.9.0
  • Loading branch information
zonyitoo committed Feb 10, 2022
1 parent c3a801a commit 46934f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crates/shadowsocks-service/src/server/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Shadowsocks Local Server Context

use std::sync::Arc;
use std::{net::SocketAddr, sync::Arc};

use shadowsocks::{
config::ServerType,
Expand Down Expand Up @@ -100,6 +100,14 @@ impl ServiceContext {
}
}

/// Check if client should be blocked
pub fn check_client_blocked(&self, addr: &SocketAddr) -> bool {
match self.acl {
None => false,
Some(ref acl) => acl.check_client_blocked(addr),
}
}

/// Try to connect IPv6 addresses first if hostname could be resolved to both IPv4 and IPv6
pub fn set_ipv6_first(&mut self, ipv6_first: bool) {
let context = Arc::get_mut(&mut self.context).expect("cannot set ipv6_first on a shared context");
Expand Down
5 changes: 5 additions & 0 deletions crates/shadowsocks-service/src/server/tcprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ impl TcpServer {
}
};

if self.context.check_client_blocked(&peer_addr) {
warn!("access denied from {} by ACL rules", peer_addr);
continue;
}

let client = TcpServerClient {
context: self.context.clone(),
method: svr_cfg.method(),
Expand Down
10 changes: 9 additions & 1 deletion crates/shadowsocks-service/src/server/udprelay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ impl UdpServer {
}
};

if self.context.check_client_blocked(&peer_addr) {
warn!(
"udp client {} outbound {} access denied by ACL rules",
peer_addr, target_addr
);
continue;
}

if self.context.check_outbound_blocked(&target_addr).await {
error!("udp client {} outbound {} blocked by ACL rules", peer_addr, target_addr);
warn!("udp client {} outbound {} blocked by ACL rules", peer_addr, target_addr);
continue;
}

Expand Down

0 comments on commit 46934f5

Please sign in to comment.