feat(cli): add support for configuring outgoing TTL and hop limit

Introduce a `--ttl` flag to allow users to set the IPv4 TTL or IPv6 hop limit, providing control over packet lifespan and helping diagnose network topology issues.
This commit is contained in:
Nils Andreas Svee committed 2026-05-05 00:45:56 +07:00
1 parent 5132e0e247
commit 8c8a679533
8 files changed
+204 -7

No files matched your search

@@ -17,3 +17,4 @@ mod negotiation;
mod no_test;
mod open;
mod probes_replies;
mod ttl;
@@ -0,0 +1,49 @@
use crate::socket_options::socket_ttl;
use super::*;
#[test]
fn connect_accepts_valid_ttl_config_values() {
for ttl in [None, Some(1), Some(255)] {
let mut config = default_test_config(SocketAddr::from(([127, 0, 0, 1], 9)));
config.socket_config.ttl = ttl;
Client::connect(config).unwrap();
}
}
#[test]
fn connect_applies_configured_ipv4_ttl_before_open_and_close_preserves_it() {
let params = Params {
protocol_version: PROTOCOL_VERSION,
duration_ns: 3_000_000_000,
interval_ns: 1_000_000_000,
received_stats: ReceivedStats::Both,
stamp_at: StampAt::Both,
clock: Clock::Both,
..Params::default()
};
let server = open_success_server(params.clone());
let mut config = default_test_config(server.addr);
config.socket_config.ttl = Some(64);
let mut client = Client::connect(config).unwrap();
assert_eq!(socket_ttl(&client.socket, client.remote).unwrap(), 64);
client.open(ClientTimestamp::now()).unwrap();
server.join();
client.close(ClientTimestamp::now()).unwrap();
assert_eq!(socket_ttl(&client.socket, client.remote).unwrap(), 64);
}
#[test]
fn connect_rejects_invalid_ttl_values() {
for ttl in [0, 256] {
let mut config = default_test_config(SocketAddr::from(([127, 0, 0, 1], 9)));
config.socket_config.ttl = Some(ttl);
assert!(matches!(
Client::connect(config),
Err(ClientError::InvalidConfig { .. })
));
}
}