Skip to content

Commit

Permalink
Use socket instead of ping command when pinging on android
Browse files Browse the repository at this point in the history
Previous implementation spawned a process with tokio which in turn
registered a signal handler without ONASTACK flag set.
When using GO code, all signal handlers needs to have this flag
set otherwise a signal might be handled on a goroutine thread
which has a small stack and thus can overflow.

Reference: DROID-1825

Co-authored-by: David Lönnhager <[email protected]>
  • Loading branch information
Pururun and dlon committed Feb 27, 2025
1 parent 04b828a commit 56cde3c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 90 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions talpid-wireguard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ rand = "0.8.5"
surge-ping = "0.8.0"
rand_chacha = "0.3.1"
wireguard-go-rs = { path = "../wireguard-go-rs"}

[target.'cfg(target_os="android")'.dependencies]
duct = "0.13"

[target.'cfg(not(target_os="android"))'.dependencies]
byteorder = "1"
internet-checksum = "0.2"
socket2 = { workspace = true, features = ["all"] }
Expand Down
72 changes: 0 additions & 72 deletions talpid-wireguard/src/connectivity/pinger/android.rs

This file was deleted.

14 changes: 11 additions & 3 deletions talpid-wireguard/src/connectivity/pinger/icmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ impl Pinger {
/// Creates a new `Pinger`.
pub fn new(
addr: Ipv4Addr,
#[cfg(not(target_os = "windows"))] interface_name: String,
#[cfg(any(target_os = "linux", target_os = "macos"))] interface_name: String,
) -> Result<Self> {
let addr = SocketAddr::new(addr.into(), 0);
let sock =
Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::ICMPV4)).map_err(Error::Open)?;
let sock = Socket::new(
Domain::IPV4,
if cfg!(target_os = "android") {
Type::DGRAM
} else {
Type::RAW
},
Some(Protocol::ICMPV4),
)
.map_err(Error::Open)?;
sock.set_nonblocking(true).map_err(Error::Open)?;

#[cfg(target_os = "linux")]
Expand Down
12 changes: 3 additions & 9 deletions talpid-wireguard/src/connectivity/pinger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#[cfg(target_os = "android")]
#[path = "android.rs"]
mod imp;
mod icmp;

#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[path = "icmp.rs"]
mod imp;

pub use imp::Error;
pub use icmp::Error;

/// Trait for sending ICMP requests to get some traffic from a remote server
#[async_trait::async_trait]
Expand All @@ -22,7 +16,7 @@ pub fn new_pinger(
addr: std::net::Ipv4Addr,
#[cfg(any(target_os = "linux", target_os = "macos"))] interface_name: String,
) -> Result<Box<dyn Pinger>, Error> {
Ok(Box::new(imp::Pinger::new(
Ok(Box::new(icmp::Pinger::new(
addr,
#[cfg(any(target_os = "linux", target_os = "macos"))]
interface_name,
Expand Down

0 comments on commit 56cde3c

Please sign in to comment.