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

Add support for SO_TXTIME #1409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

colinmarc
Copy link
Contributor

This is an undocumented linux feature that lets you time outgoing packets.

This depends on sunfishcode/linux-raw-sys#153.

@@ -1522,6 +1526,20 @@ pub fn socket_peercred<Fd: AsFd>(fd: Fd) -> io::Result<super::UCred> {
backend::net::sockopt::socket_peercred(fd.as_fd())
}

/// `getsockopt(fd, SOL_SOCKET, SO_TXTIME)` — Get transmit timing settings.
#[cfg(all(target_os = "linux", feature = "time"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be #[cfg(linux_kernel)]? I don't get the distinction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linux_kernel is equivalent to any(target_os = "linux", target_os = "android")). If this feature compiles on Android, then we can enable it there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with linux_kernel, so I guess we'll see what happens in CI :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's a no on android.

@colinmarc
Copy link
Contributor Author

I just realized this needs the SCM_TXTIME part, to be useful. I'll add that in the next few days. Marking as a draft for now.

@colinmarc colinmarc marked this pull request as draft March 11, 2025 16:40
@colinmarc colinmarc force-pushed the so-txtime branch 4 times, most recently from f9105fd to b87a4b0 Compare March 12, 2025 14:40
@@ -94,6 +95,51 @@ pub enum ClockId {
BoottimeAlarm = bitcast!(c::CLOCK_BOOTTIME_ALARM),
}

#[cfg(not(any(apple, target_os = "wasi")))]
Copy link
Contributor Author

@colinmarc colinmarc Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this would be straightforward, but it's really not. libc has clockid_t, while linux-raw-sys has __kernel_clockid_t. Some platforms have neither. What's the best way to proceed with this? I need it for get_txtime, since the kernel returns the configured clock.

Nevermind, importing __kernel_clockid_t as clockid_t fixed it.

@colinmarc colinmarc force-pushed the so-txtime branch 5 times, most recently from 25f2f89 to 7372c46 Compare March 12, 2025 15:24
@colinmarc colinmarc marked this pull request as ready for review March 12, 2025 15:24
@colinmarc
Copy link
Contributor Author

Added SCM_TXTIME and a e2e test.

@sunfishcode
Copy link
Member

linux-raw-sys 0.9.3 is now released, with sunfishcode/linux-raw-sys#153.

@colinmarc colinmarc force-pushed the so-txtime branch 2 times, most recently from 9a91e1d to 45c36e3 Compare March 14, 2025 12:27
@colinmarc
Copy link
Contributor Author

linux-raw-sys 0.9.3 is now released, with sunfishcode/linux-raw-sys#153.

Great, thanks :) I rebased now and removed the hardcoded declarations.

This is an undocumented linux feature that lets you time outgoing
packets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants