Skip to content

Commit

Permalink
feat(net): added dublin tracing strategy support for IPv6/UDP (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Mar 28, 2024
1 parent 818a327 commit 5626fe7
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 32 deletions.
19 changes: 5 additions & 14 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,20 +585,11 @@ impl TrippyConfig {
(true, _, _, _) => IpAddrFamily::Ipv4Only,
(_, true, _, _) => IpAddrFamily::Ipv6Only,
};

#[allow(clippy::match_same_arms)]
let multipath_strategy = match (multipath_strategy_cfg, addr_family) {
(MultipathStrategyConfig::Classic, _) => Ok(MultipathStrategy::Classic),
(MultipathStrategyConfig::Paris, _) => Ok(MultipathStrategy::Paris),
(
MultipathStrategyConfig::Dublin,
IpAddrFamily::Ipv4Only | IpAddrFamily::Ipv4thenIpv6 | IpAddrFamily::Ipv6thenIpv4,
) => Ok(MultipathStrategy::Dublin),
(MultipathStrategyConfig::Dublin, IpAddrFamily::Ipv6Only) => Err(anyhow!(
"Dublin multipath strategy not implemented for IPv6 yet!"
)),
}?;

let multipath_strategy = match multipath_strategy_cfg {
MultipathStrategyConfig::Classic => MultipathStrategy::Classic,
MultipathStrategyConfig::Paris => MultipathStrategy::Paris,
MultipathStrategyConfig::Dublin => MultipathStrategy::Dublin,
};
let port_direction = match (protocol, source_port, target_port, multipath_strategy_cfg) {
(Protocol::Icmp, _, _, _) => PortDirection::None,
(Protocol::Udp, None, None, _) => PortDirection::new_fixed_src(pid.max(1024)),
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ fn make_channel_config(
target_addr,
args.packet_size,
args.payload_pattern,
args.initial_sequence,
args.tos,
args.icmp_extension_parse_mode,
args.read_timeout,
Expand Down
4 changes: 4 additions & 0 deletions src/tracing/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ pub struct ChannelConfig {
pub target_addr: IpAddr,
pub packet_size: PacketSize,
pub payload_pattern: PayloadPattern,
pub initial_sequence: Sequence,
pub tos: TypeOfService,
pub icmp_extension_mode: IcmpExtensionParseMode,
pub read_timeout: Duration,
Expand All @@ -376,6 +377,7 @@ impl ChannelConfig {
target_addr: IpAddr,
packet_size: u16,
payload_pattern: u8,
initial_sequence: u16,
tos: u8,
icmp_extension_mode: IcmpExtensionParseMode,
read_timeout: Duration,
Expand All @@ -388,6 +390,7 @@ impl ChannelConfig {
target_addr,
packet_size: PacketSize(packet_size),
payload_pattern: PayloadPattern(payload_pattern),
initial_sequence: Sequence(initial_sequence),
tos: TypeOfService(tos),
icmp_extension_mode,
read_timeout,
Expand All @@ -405,6 +408,7 @@ impl Default for ChannelConfig {
target_addr: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
packet_size: PacketSize(defaults::DEFAULT_STRATEGY_PACKET_SIZE),
payload_pattern: PayloadPattern(defaults::DEFAULT_STRATEGY_PAYLOAD_PATTERN),
initial_sequence: Sequence(defaults::DEFAULT_STRATEGY_INITIAL_SEQUENCE),
tos: TypeOfService(defaults::DEFAULT_STRATEGY_TOS),
icmp_extension_mode: defaults::DEFAULT_ICMP_EXTENSION_PARSE_MODE,
read_timeout: defaults::DEFAULT_STRATEGY_READ_TIMEOUT,
Expand Down
5 changes: 4 additions & 1 deletion src/tracing/net/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::tracing::net::socket::Socket;
use crate::tracing::net::{ipv4, ipv6, platform, Network};
use crate::tracing::probe::{Probe, ProbeResponse};
use crate::tracing::types::{PacketSize, PayloadPattern, TypeOfService};
use crate::tracing::{ChannelConfig, Port, PrivilegeMode, Protocol};
use crate::tracing::{ChannelConfig, Port, PrivilegeMode, Protocol, Sequence};
use arrayvec::ArrayVec;
use std::net::IpAddr;
use std::time::{Duration, SystemTime};
Expand All @@ -25,6 +25,7 @@ pub struct TracerChannel<S: Socket> {
dest_addr: IpAddr,
packet_size: PacketSize,
payload_pattern: PayloadPattern,
initial_sequence: Sequence,
tos: TypeOfService,
icmp_extension_mode: IcmpExtensionParseMode,
read_timeout: Duration,
Expand Down Expand Up @@ -63,6 +64,7 @@ impl<S: Socket> TracerChannel<S> {
dest_addr: config.target_addr,
packet_size: config.packet_size,
payload_pattern: config.payload_pattern,
initial_sequence: config.initial_sequence,
tos: config.tos,
icmp_extension_mode: config.icmp_extension_mode,
read_timeout: config.read_timeout,
Expand Down Expand Up @@ -154,6 +156,7 @@ impl<S: Socket> TracerChannel<S> {
self.privilege_mode,
self.packet_size,
self.payload_pattern,
self.initial_sequence,
)
}
_ => unreachable!(),
Expand Down
11 changes: 10 additions & 1 deletion src/tracing/net/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,14 @@ fn extract_probe_resp_seq(
}
(Protocol::Udp, IpProtocol::Udp) => {
let (src_port, dest_port, checksum, identifier) = extract_udp_packet(ipv4)?;

Some(ProbeResponseSeq::Udp(ProbeResponseSeqUdp::new(
identifier,
IpAddr::V4(ipv4.get_destination()),
src_port,
dest_port,
checksum,
0,
false,
)))
}
(Protocol::Tcp, IpProtocol::Tcp) => {
Expand Down Expand Up @@ -1137,6 +1138,8 @@ mod tests {
src_port,
dest_port,
checksum,
payload_len,
has_magic,
}),
..
},
Expand All @@ -1154,6 +1157,8 @@ mod tests {
assert_eq!(31829, src_port);
assert_eq!(33030, dest_port);
assert_eq!(58571, checksum);
assert_eq!(0, payload_len);
assert!(!has_magic);
assert_eq!(None, extensions);
Ok(())
}
Expand Down Expand Up @@ -1189,6 +1194,8 @@ mod tests {
src_port,
dest_port,
checksum,
payload_len,
has_magic,
}),
..
},
Expand All @@ -1206,6 +1213,8 @@ mod tests {
assert_eq!(32779, src_port);
assert_eq!(33010, dest_port);
assert_eq!(10913, checksum);
assert_eq!(0, payload_len);
assert!(!has_magic);
assert_eq!(None, extensions);
Ok(())
}
Expand Down
Loading

0 comments on commit 5626fe7

Please sign in to comment.