Skip to content

Commit 2ce1cf7

Browse files
committed
Add the TCP_FUNCTION_BLK socket option, on FreeBSD
1 parent 0e4353a commit 2ce1cf7

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,6 @@ path = "test/test_clearenv.rs"
107107
[[test]]
108108
name = "test-prctl"
109109
path = "test/sys/test_prctl.rs"
110+
111+
[patch.crates-io]
112+
libc = { git = "https://github.com/asomers/libc.git", rev = "5344e1a71517b265e7c2fe14ada8cb6c56e152e0" }

changelog/2539.added.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 22 additions & 0 deletions
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.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)