Skip to content

Commit

Permalink
fix udp proxy not work when being exit node (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
KKRainbow committed Jun 5, 2024
1 parent 6e77e6b commit b43c078
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions easytier/src/common/global_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub struct GlobalCtx {
stun_info_collection: Box<dyn StunInfoCollectorTrait>,

running_listeners: Mutex<Vec<url::Url>>,

enable_exit_node: bool,
}

impl std::fmt::Debug for GlobalCtx {
Expand Down Expand Up @@ -90,6 +92,8 @@ impl GlobalCtx {

let stun_info_collection = Arc::new(StunInfoCollector::new_with_default_servers());

let enable_exit_node = config_fs.get_flags().enable_exit_node;

GlobalCtx {
inst_name: config_fs.get_inst_name(),
id,
Expand All @@ -108,6 +112,8 @@ impl GlobalCtx {
stun_info_collection: Box::new(stun_info_collection),

running_listeners: Mutex::new(Vec::new()),

enable_exit_node,
}
}

Expand Down Expand Up @@ -224,6 +230,10 @@ impl GlobalCtx {
hasher.write(&key[0..16]);
key
}

pub fn enable_exit_node(&self) -> bool {
self.enable_exit_node
}
}

#[cfg(test)]
Expand Down
4 changes: 4 additions & 0 deletions easytier/src/gateway/icmp_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ impl IcmpProxy {
}

async fn try_handle_peer_packet(&self, packet: &ZCPacket) -> Option<()> {
if self.cidr_set.is_empty() && !self.global_ctx.enable_exit_node() {
return None;
}

let _ = self.global_ctx.get_ipv4()?;
let hdr = packet.peer_manager_header().unwrap();
let is_exit_node = hdr.is_exit_node();
Expand Down
4 changes: 4 additions & 0 deletions easytier/src/gateway/tcp_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ impl TcpProxy {
}

async fn try_handle_peer_packet(&self, packet: &mut ZCPacket) -> Option<()> {
if self.cidr_set.is_empty() && !self.global_ctx.enable_exit_node() {
return None;
}

let ipv4_addr = self.global_ctx.get_ipv4()?;
let hdr = packet.peer_manager_header().unwrap();
let is_exit_node = hdr.is_exit_node();
Expand Down
2 changes: 1 addition & 1 deletion easytier/src/gateway/udp_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub struct UdpProxy {

impl UdpProxy {
async fn try_handle_packet(&self, packet: &ZCPacket) -> Option<()> {
if self.cidr_set.is_empty() {
if self.cidr_set.is_empty() && !self.global_ctx.enable_exit_node() {
return None;
}

Expand Down

0 comments on commit b43c078

Please sign in to comment.