Skip to content

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.

}

/// `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
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.
@colinmarc
Copy link
Contributor Author

Hi @sunfishcode, anything needed from me on this?

colinmarc added a commit to colinmarc/magic-mirror that referenced this pull request Jul 20, 2025
This is not actually sufficient for error handling in sendmmsg. The
following cases are unconsidered:

 - Only some of the buffer are sent
 - Only some of one of the iovecs is sent

We'll handle this when we migrate to rustix's sendmmsg, which is waiting
on the following PRs:

 - bytecodealliance/rustix#1171
 - bytecodealliance/rustix#1409

Note that those cases should be gracefully-ish handled by FEC and the
protocol (they're equivalent to dropped or biffed packets).
@sunfishcode sunfishcode merged commit 65b04ae into bytecodealliance:main Sep 9, 2025
51 checks passed
@sunfishcode
Copy link
Member

Thanks!

@sunfishcode
Copy link
Member

This is now released in rustix 1.1.1.

pekkarr added a commit to pekkarr/rustix that referenced this pull request Oct 25, 2025
`rustix::time` and the txtime socket options are only available with the `time`
feature, but they are unconditionally used in sockopt tests. Mark them with
`cfg(feature = "time")` to enable compiling sockopt tests with just the `net`
feature enabled. Otherwise `cargo test --features net` would end up with a
compile error.

Fixes: 65b04ae ("Add support for SO_TXTIME / SCM_TXTIME (bytecodealliance#1409)")
sunfishcode pushed a commit that referenced this pull request Oct 25, 2025
* Fix cfgs in sockopt tests

`rustix::time` and the txtime socket options are only available with the `time`
feature, but they are unconditionally used in sockopt tests. Mark them with
`cfg(feature = "time")` to enable compiling sockopt tests with just the `net`
feature enabled. Otherwise `cargo test --features net` would end up with a
compile error.

Fixes: 65b04ae ("Add support for SO_TXTIME / SCM_TXTIME (#1409)")

* Test `socket_passcred` only for Unix domain sockets

Since Linux 6.16, `SO_PASSCRED` is allowed only for `AF_UNIX`, `AF_NETLINK` and
`AF_BLUETOOTH` sockets. The tests used to get/set this option for IP sockets,
which doesn't work with new kernels, so make the tests use a Unix domain socket
instead.

On new kernels, the tests fail with:

```
---- sockopt::test_sockopts_ipv6 stdout ----

thread 'sockopt::test_sockopts_ipv6' panicked at tests/net/sockopt.rs:44:42:
called `Result::unwrap()` on an `Err` value: Os { code: 95, kind: Unsupported, message: "Operation not supported" }

---- sockopt::test_sockopts_ipv4 stdout ----

thread 'sockopt::test_sockopts_ipv4' panicked at tests/net/sockopt.rs:44:42:
called `Result::unwrap()` on an `Err` value: Os { code: 95, kind: Unsupported, message: "Operation not supported" }
```

The restriction was introduced to Linux in this commit:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7d8d93fdde50b86bbbf46a203c368ed320e729ab
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