Skip to content

Commit 5084339

Browse files
committed
sys::socket adding GetOnly TCP_FUNCTION_ALIAS for freebsd.
to complete `TCP_FUNCTION_BLK` as to get the alias name, if existent, of the TCP stack.
1 parent e7e9809 commit 5084339

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

changelog/2558.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add the `TCP_FUNCTION_ALIAS` sockopt, on FreeBSD.

src/sys/socket/sockopt.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,19 @@ sockopt_impl!(
330330
libc::TCP_FUNCTION_BLK,
331331
libc::tcp_function_set
332332
);
333+
#[cfg(target_os = "freebsd")]
334+
#[cfg(feature = "net")]
335+
sockopt_impl!(
336+
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
337+
/// Query the alias name of the set of function of the socket's TCP stack.
338+
/// Uses the same field for the main name when getting from TCP_FUNCTION_BLK.
339+
/// Empty if no alias.
340+
TcpFunctionAlias,
341+
GetOnly,
342+
libc::IPPROTO_TCP,
343+
libc::TCP_FUNCTION_ALIAS,
344+
libc::tcp_function_set
345+
);
333346
sockopt_impl!(
334347
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
335348
/// Used to disable Nagle's algorithm.

test/sys/test_sockopt.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn test_tcp_congestion() {
283283

284284
#[test]
285285
#[cfg(target_os = "freebsd")]
286-
fn test_tcp_function_blk() {
286+
fn test_tcp_function_blk_alias() {
287287
use std::ffi::CStr;
288288

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

301+
let aliastfs = getsockopt(&fd, sockopt::TcpFunctionAlias).unwrap();
302+
let aliasname =
303+
unsafe { CStr::from_ptr(aliastfs.function_set_name.as_ptr()) };
304+
// freebsd default tcp stack has no alias.
305+
assert!(aliasname.to_bytes().is_empty());
306+
301307
// We can't know at compile time what options are available. So just test the setter by a
302308
// no-op set.
309+
// TODO: test if we can load for example BBR tcp stack kernel module.
303310
setsockopt(&fd, sockopt::TcpFunctionBlk, &tfs).unwrap();
304311
}
305312

0 commit comments

Comments
 (0)