mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2026-12-02 02:34:36 +00:00
Keep IPv4-mapped list entries matching in relay()
The previous commit looked the lists up in the plain IPv4 form only, so an entry in the ::ffff:a.b.c.d form stopped matching. That is the form `usage` and the pairing logs print, so an admin copying an address from them, or an existing list file holding one, lost the throttle and the mid-session blocklist check. relay() now matches either form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JAxkkiaGp2k8okvs4MpCUq
This commit is contained in:
1 parent
f3d43ff192
commit
c5318a3c1e
1 file changed
+34
-28
+34
-28
@@ -544,9 +544,10 @@ async fn relay(
|
|||||||
total_limiter: Limiter,
|
total_limiter: Limiter,
|
||||||
id: String,
|
id: String,
|
||||||
) -> ResultType<()> {
|
) -> ResultType<()> {
|
||||||
// The dual-stack listener reports an IPv4 client as ::ffff:a.b.c.d, while the lists hold the
|
let ip = addr.ip().to_string();
|
||||||
// IPv4 form that `ba` and `Ba` are given.
|
// The dual-stack listener reports an IPv4 client as ::ffff:a.b.c.d; lists may hold either form.
|
||||||
let ip = hbb_common::try_into_v4(addr).ip().to_string();
|
let unmapped = hbb_common::try_into_v4(addr).ip().to_string();
|
||||||
|
let listed = |list: &HashSet<String>| list.contains(&ip) || list.contains(&unmapped);
|
||||||
let mut tm = std::time::Instant::now();
|
let mut tm = std::time::Instant::now();
|
||||||
let mut elapsed = 0;
|
let mut elapsed = 0;
|
||||||
let mut total = 0;
|
let mut total = 0;
|
||||||
@@ -610,11 +611,11 @@ async fn relay(
|
|||||||
|
|
||||||
let n = tm.elapsed().as_millis() as usize;
|
let n = tm.elapsed().as_millis() as usize;
|
||||||
if n >= 1_000 {
|
if n >= 1_000 {
|
||||||
if BLOCKLIST.read().await.get(&ip).is_some() {
|
if listed(&*BLOCKLIST.read().await) {
|
||||||
log::info!("{} blocked", ip);
|
log::info!("{} blocked", ip);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
blacked = BLACKLIST.read().await.get(&ip).is_some();
|
blacked = listed(&*BLACKLIST.read().await);
|
||||||
tm = std::time::Instant::now();
|
tm = std::time::Instant::now();
|
||||||
let speed = total_s / n;
|
let speed = total_s / n;
|
||||||
if speed > highest_s {
|
if speed > highest_s {
|
||||||
@@ -698,29 +699,34 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn a_blocklisted_ipv4_client_on_the_dual_stack_listener_is_cut_off() {
|
async fn a_blocklisted_ipv4_client_on_the_dual_stack_listener_is_cut_off() {
|
||||||
let ip = "192.0.2.55";
|
// The plain form is what `ba` is usually given; the mapped one is what `usage` shows.
|
||||||
BLOCKLIST.write().await.insert(ip.to_owned());
|
for entry in ["192.0.2.55", "::ffff:192.0.2.55"] {
|
||||||
let mut stream = TestStream {
|
BLOCKLIST.write().await.insert(entry.to_owned());
|
||||||
data: None,
|
let mut stream = TestStream {
|
||||||
blocked: false,
|
data: None,
|
||||||
};
|
blocked: false,
|
||||||
let mut peer: Box<dyn StreamTrait> = Box::new(TestStream {
|
};
|
||||||
data: None,
|
let mut peer: Box<dyn StreamTrait> = Box::new(TestStream {
|
||||||
blocked: false,
|
data: None,
|
||||||
});
|
blocked: false,
|
||||||
let result = timeout(
|
});
|
||||||
10_000,
|
let result = timeout(
|
||||||
relay(
|
10_000,
|
||||||
format!("[::ffff:{ip}]:1").parse().unwrap(),
|
relay(
|
||||||
&mut stream,
|
"[::ffff:192.0.2.55]:1".parse().unwrap(),
|
||||||
&mut peer,
|
&mut stream,
|
||||||
Limiter::new(1_000_000.),
|
&mut peer,
|
||||||
"blocklist-test".to_owned(),
|
Limiter::new(1_000_000.),
|
||||||
),
|
"blocklist-test".to_owned(),
|
||||||
)
|
),
|
||||||
.await;
|
)
|
||||||
BLOCKLIST.write().await.remove(ip);
|
.await;
|
||||||
assert!(result.expect("the relay kept a blocklisted client").is_ok());
|
BLOCKLIST.write().await.remove(entry);
|
||||||
|
assert!(
|
||||||
|
matches!(result, Ok(Ok(()))),
|
||||||
|
"the relay kept a client blocklisted as {entry}"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user