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

sys::socket adding GetOnly TCP_FUNCTION_ALIAS for freebsd. #2558

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog/2558.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the `TCP_FUNCTION_ALIAS` sockopt, on FreeBSD.
13 changes: 13 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,19 @@ sockopt_impl!(
libc::TCP_FUNCTION_BLK,
libc::tcp_function_set
);
#[cfg(target_os = "freebsd")]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Query the alias name of the set of function of the socket's TCP stack.
/// Uses the same field for the main name when getting from TCP_FUNCTION_BLK.
/// Empty if no alias.
TcpFunctionAlias,
GetOnly,
libc::IPPROTO_TCP,
libc::TCP_FUNCTION_ALIAS,
libc::tcp_function_set
);
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Used to disable Nagle's algorithm.
Expand Down
9 changes: 8 additions & 1 deletion test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ fn test_tcp_congestion() {

#[test]
#[cfg(target_os = "freebsd")]
fn test_tcp_function_blk() {
fn test_tcp_function_blk_alias() {
use std::ffi::CStr;

let fd = socket(
Expand All @@ -298,8 +298,15 @@ fn test_tcp_function_blk() {
let name = unsafe { CStr::from_ptr(tfs.function_set_name.as_ptr()) };
assert!(!name.to_bytes().is_empty());

let aliastfs = getsockopt(&fd, sockopt::TcpFunctionAlias).unwrap();
let aliasname =
unsafe { CStr::from_ptr(aliastfs.function_set_name.as_ptr()) };
// freebsd default tcp stack has no alias.
assert!(aliasname.to_bytes().is_empty());

// We can't know at compile time what options are available. So just test the setter by a
// no-op set.
// TODO: test if we can load for example BBR tcp stack kernel module.
Copy link
Member

Choose a reason for hiding this comment

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

We just need to ensure the wrapper works, so it is not necessary to do further tests, but having them harms nothing:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is more in case future related flag additions, some of which need this alternative stack to work.

setsockopt(&fd, sockopt::TcpFunctionBlk, &tfs).unwrap();
}

Expand Down
Loading