Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(net): tracer panic for ICMP TimeExceeded packets with code 1 (#979) #980

Merged
merged 5 commits into from
Feb 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(net): added mockall for Socket trait
fujiapple852 committed Feb 4, 2024

Unverified

This user has not yet uploaded their public signing key.
commit 7ea34a4fe8ef38bc03e4198a81b7aad8ef9254d1
24 changes: 24 additions & 0 deletions src/tracing/net/socket.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use crate::tracing::error::IoResult as Result;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::time::Duration;

#[cfg_attr(test, mockall::automock)]
pub trait Socket
where
Self: Sized,
@@ -46,3 +47,26 @@ where
fn icmp_error_info(&mut self) -> Result<IpAddr>;
fn close(&mut self) -> Result<()>;
}

#[cfg(test)]
pub mod tests {
#[macro_export]
macro_rules! mocket_read {
($packet: expr) => {
move |buf: &mut [u8]| -> IoResult<usize> {
buf[..$packet.len()].copy_from_slice(&$packet);
Ok(buf.len())
}
};
}

#[macro_export]
macro_rules! mocket_recv_from {
($packet: expr, $addr: expr) => {
move |buf: &mut [u8]| -> IoResult<(usize, Option<SocketAddr>)> {
buf[..$packet.len()].copy_from_slice(&$packet);
Ok((buf.len(), Some($addr)))
}
};
}
}