-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b784982
commit 00df4a0
Showing
4 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::cerr; | ||
|
||
use super::RawSocket; | ||
|
||
impl RawSocket { | ||
pub(crate) fn so_timestamp(&self, options: u32) -> std::io::Result<()> { | ||
// Documentation on the timestamping calls: | ||
// | ||
// - linux: https://www.kernel.org/doc/Documentation/networking/timestamping.txt | ||
// - freebsd: https://man.freebsd.org/cgi/man.cgi?setsockopt | ||
// | ||
// SAFETY: | ||
// | ||
// - the socket is provided by (safe) rust, and will outlive the call | ||
// - method is guaranteed to be a valid "name" argument | ||
// - the options pointer outlives the call | ||
// - the `option_len` corresponds with the options pointer | ||
// | ||
// Only some bits are valid to set in `options`, but setting invalid bits is | ||
// perfectly safe | ||
// | ||
// > Setting other bit returns EINVAL and does not change the current state. | ||
unsafe { | ||
cerr(libc::setsockopt( | ||
self.fd, | ||
libc::SOL_SOCKET, | ||
libc::SO_TIMESTAMP, | ||
&options as *const _ as *const libc::c_void, | ||
std::mem::size_of_val(&options) as libc::socklen_t, | ||
)) | ||
}?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use crate::raw_socket::RawSocket; | ||
|
||
use super::InterfaceTimestampMode; | ||
|
||
pub(super) fn configure_timestamping( | ||
socket: &RawSocket, | ||
mode: InterfaceTimestampMode, | ||
) -> std::io::Result<()> { | ||
match mode { | ||
InterfaceTimestampMode::None => Ok(()), | ||
InterfaceTimestampMode::SoftwareRecv => socket.so_timestamp(1), | ||
_ => Err(std::io::ErrorKind::Unsupported.into()), | ||
} | ||
} |