summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFujiApple <fujiapple852@gmail.com>2024-02-10 19:04:22 +0800
committerFujiApple <fujiapple852@gmail.com>2024-02-11 23:32:11 +0800
commit1321afe2463bf3b480c2c91b4b4fb34c2875e587 (patch)
treecf9c74643e44d273f8a72ac03353a3faebb75fe7
parent0edcbaf36a0daf03b85b916db56748c3169ee3c0 (diff)
test(net): added ipv4 test `test_recv_icmp_probe_destination_unreachable_icmp_no_extensions`
-rw-r--r--src/tracing/net/ipv4.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tracing/net/ipv4.rs b/src/tracing/net/ipv4.rs
index 8c41c27..2cabe9e 100644
--- a/src/tracing/net/ipv4.rs
+++ b/src/tracing/net/ipv4.rs
@@ -1078,6 +1078,50 @@ mod tests {
Ok(())
}
+ #[test]
+ fn test_recv_icmp_probe_destination_unreachable_icmp_no_extensions() -> anyhow::Result<()> {
+ let expected_read_buf = hex_literal::hex!(
+ "
+ 45 20 00 38 00 00 40 00 70 01 33 ea 14 00 00 fe
+ c0 a8 01 15 03 01 fc fe 00 00 00 00 45 00 00 54
+ 00 00 40 00 80 01 23 ee c0 a8 01 15 14 00 00 fe
+ 08 00 fb d9 7b 01 81 24
+ "
+ );
+ let mut mocket = MockSocket::new();
+ mocket
+ .expect_read()
+ .times(1)
+ .returning(mocket_read!(expected_read_buf));
+ let resp = recv_icmp_probe(
+ &mut mocket,
+ Protocol::Icmp,
+ IcmpExtensionParseMode::Disabled,
+ )?
+ .unwrap();
+
+ let ProbeResponse::DestinationUnreachable(
+ ProbeResponseData {
+ addr,
+ resp_seq:
+ ProbeResponseSeq::Icmp(ProbeResponseSeqIcmp {
+ identifier,
+ sequence,
+ }),
+ ..
+ },
+ extensions,
+ ) = resp
+ else {
+ panic!("expected DestinationUnreachable")
+ };
+ assert_eq!(IpAddr::V4(Ipv4Addr::from_str("20.0.0.254").unwrap()), addr);
+ assert_eq!(31489, identifier);
+ assert_eq!(33060, sequence);
+ assert_eq!(None, extensions);
+ Ok(())
+ }
+
// This IPv4/ICMP TimeExceeded packet has code 1 ("Fragment reassembly
// time exceeded") and must be ignored.
//