Skip to content

Commit

Permalink
Add the TCP_FUNCTION_BLK socket option, on FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Nov 15, 2024
1 parent 0e4353a commit 2ce1cf7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,6 @@ path = "test/test_clearenv.rs"
[[test]]
name = "test-prctl"
path = "test/sys/test_prctl.rs"

[patch.crates-io]
libc = { git = "https://github.com/asomers/libc.git", rev = "5344e1a71517b265e7c2fe14ada8cb6c56e152e0" }
1 change: 1 addition & 0 deletions changelog/2539.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the `TCP_FUNCTION_BLK` sockopt, on FreeBSD.
11 changes: 11 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,18 @@ sockopt_impl!(
libc::SO_REUSEPORT_LB,
bool
);
#[cfg(target_os = "freebsd")]
#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Select or query the set of functions that TCP will use for this connection. This allows a
/// user to select an alternate TCP stack.
TcpFunctionBlk,
Both,
libc::IPPROTO_TCP,
libc::TCP_FUNCTION_BLK,
libc::tcp_function_set
);
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Used to disable Nagle's algorithm.
Expand Down
22 changes: 22 additions & 0 deletions test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,28 @@ fn test_tcp_congestion() {
assert_eq!(getsockopt(&fd, sockopt::TcpCongestion).unwrap(), val);
}

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

let fd = socket(
AddressFamily::Inet,
SockType::Stream,
SockFlag::empty(),
None,
)
.unwrap();

let tfs = getsockopt(&fd, sockopt::TcpFunctionBlk).unwrap();
let name = unsafe{ CStr::from_ptr(tfs.function_set_name.as_ptr()) };
assert!(!name.is_empty());

// We can't know at compile time what options are available. So just test the setter by a
// no-op set.
setsockopt(&fd, sockopt::TcpFunctionBlk, &tfs).unwrap();
}

#[test]
#[cfg(linux_android)]
fn test_bindtodevice() {
Expand Down

0 comments on commit 2ce1cf7

Please sign in to comment.