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 19, 2024
1 parent 4b6a5e3 commit 39a16ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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.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.
setsockopt(&fd, sockopt::TcpFunctionBlk, &tfs).unwrap();
}

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

0 comments on commit 39a16ea

Please sign in to comment.