Skip to content

Commit db4ce6a

Browse files
authored
Add the TCP_FUNCTION_BLK socket option, on FreeBSD (#2539)
1 parent 3806b37 commit db4ce6a

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

changelog/2539.added.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the `TCP_FUNCTION_BLK` sockopt, on FreeBSD.

src/sys/socket/sockopt.rs

+11
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,18 @@ sockopt_impl!(
300300
libc::SO_REUSEPORT_LB,
301301
bool
302302
);
303+
#[cfg(target_os = "freebsd")]
303304
#[cfg(feature = "net")]
305+
sockopt_impl!(
306+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
307+
/// Select or query the set of functions that TCP will use for this connection. This allows a
308+
/// user to select an alternate TCP stack.
309+
TcpFunctionBlk,
310+
Both,
311+
libc::IPPROTO_TCP,
312+
libc::TCP_FUNCTION_BLK,
313+
libc::tcp_function_set
314+
);
304315
sockopt_impl!(
305316
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
306317
/// Used to disable Nagle's algorithm.

test/sys/test_sockopt.rs

+22
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,28 @@ fn test_tcp_congestion() {
281281
assert_eq!(getsockopt(&fd, sockopt::TcpCongestion).unwrap(), val);
282282
}
283283

284+
#[test]
285+
#[cfg(target_os = "freebsd")]
286+
fn test_tcp_function_blk() {
287+
use std::ffi::CStr;
288+
289+
let fd = socket(
290+
AddressFamily::Inet,
291+
SockType::Stream,
292+
SockFlag::empty(),
293+
None,
294+
)
295+
.unwrap();
296+
297+
let tfs = getsockopt(&fd, sockopt::TcpFunctionBlk).unwrap();
298+
let name = unsafe { CStr::from_ptr(tfs.function_set_name.as_ptr()) };
299+
assert!(!name.to_bytes().is_empty());
300+
301+
// We can't know at compile time what options are available. So just test the setter by a
302+
// no-op set.
303+
setsockopt(&fd, sockopt::TcpFunctionBlk, &tfs).unwrap();
304+
}
305+
284306
#[test]
285307
#[cfg(linux_android)]
286308
fn test_bindtodevice() {

0 commit comments

Comments
 (0)