Tests for the FD bio.
More...
#include <freeradius-devel/util/test/acutest_common_init.h>
#include <freeradius-devel/util/test/acutest_helpers.h>
#include <freeradius-devel/bio/bio_priv.h>
#include <freeradius-devel/bio/fd.h>
#include <freeradius-devel/bio/mem.h>
#include <freeradius-devel/server/cf_parse.h>
#include <freeradius-devel/server/cf_util.h>
#include <freeradius-devel/util/syserror.h>
#include <poll.h>
Go to the source code of this file.
|
| struct | cfg_pair_t |
| | One key / value pair in the transport subsection of a test configuration. More...
|
| |
Tests for the FD bio.
- Copyright
- 2026 Network RADIUS SAS (legal.nosp@m.@net.nosp@m.workr.nosp@m.adiu.nosp@m.s.com)
Definition in file bio_fd_tests.c.
◆ cfg_pair_t
One key / value pair in the transport subsection of a test configuration.
Definition at line 615 of file bio_fd_tests.c.
| Data Fields |
|
char const * |
name |
|
|
char const * |
value |
|
◆ blocked_connect()
| static int blocked_connect |
( |
TALLOC_CTX * |
ctx, |
|
|
int * |
listen_out, |
|
|
fr_bio_t ** |
bio_out |
|
) |
| |
|
static |
Open a non-blocking TCP bio to a listening socket which never calls accept()
The listening socket has a small receive buffer, and the bio has a small send buffer, so a few kilobytes of writes fill both buffers. The kernel then has no room for another byte.
- Parameters
-
| [in] | ctx | to allocate the bio in. |
| [out] | listen_out | the listening socket. The caller closes the socket. |
| [out] | bio_out | the connected FD bio. |
- Returns
- 0 on success.
- <0 on error.
< the FD bio keeps a pointer to this, and outlives this function
Definition at line 432 of file bio_fd_tests.c.
◆ cb_connected()
| static void cb_connected |
( |
fr_bio_t * |
bio | ) |
|
|
static |
◆ cb_error()
◆ cb_timeout()
| static void cb_timeout |
( |
fr_bio_t * |
bio | ) |
|
|
static |
◆ cb_write_blocked()
| static int cb_write_blocked |
( |
fr_bio_t * |
bio | ) |
|
|
static |
◆ ipv6_loopback_usable()
| static int ipv6_loopback_usable |
( |
void |
| ) |
|
|
static |
See if the IPv6 loopback address can be used.
Some hosts and containers turn IPv6 off. The socket() or bind() fails there.
- Returns
- 0 the IPv6 loopback address can be used.
- the errno from the socket() or bind() which failed. The errno is saved before close() can change it.
Definition at line 176 of file bio_fd_tests.c.
◆ loopback_listen()
| static int loopback_listen |
( |
uint16_t * |
port | ) |
|
|
static |
Open a TCP socket listening on loopback.
The kernel completes the TCP handshake for any listening socket, and the test needs only the handshake. The test never calls accept(), so the kernel holds the new connection in the backlog of the listening socket.
- Parameters
-
| [out] | port | the port which the kernel picked. |
- Returns
- >=0 the listening socket.
- <0 on error.
Definition at line 54 of file bio_fd_tests.c.
◆ parse_client_config()
Parse "transport" and the transport subsection with fr_bio_fd_client_config.
The caller sets the socket type before the parse. rlm_radius sets the type of the socket in the same way, as the "mode" decides if the sockets are connected.
- Parameters
-
| [in] | ctx | to allocate the configuration in. |
| [out] | cfg | where to write the parsed configuration. |
| [in] | type | of the socket, set before the parse. |
| [in] | transport | name of the transport, which is also the name of the subsection. |
| [in] | pairs | for the subsection, terminated by an entry with a NULL name. May be NULL. |
- Returns
- 0 on success.
- <0 on error.
Definition at line 634 of file bio_fd_tests.c.
◆ recvfromto_test()
| static void recvfromto_test |
( |
int |
af | ) |
|
|
static |
Read one packet through an unconnected UDP bio bound to the wildcard address.
The local address of a bio bound to the wildcard address does not identify the address that a packet was sent to. fr_bio_fd_init_common() therefore installs fr_bio_fd_recvfromto4() or fr_bio_fd_recvfromto6(). Those two functions read the destination address from a control message (data which recvmsg() returns beside the packet), and copy the destination port from the port of the bio.
fr_bio_fd_common_datagram() also enables receive timestamps, so each packet carries two control messages. If cbuf in fr_bio_fd_t is too small for both control messages, then the bio drops every packet.
Definition at line 206 of file bio_fd_tests.c.
◆ test_client_config_connected_tcp()
| static void test_client_config_connected_tcp |
( |
void |
| ) |
|
|
static |
A client configuration for a connected socket still takes the destination of the "tcp" subsection.
The unconnected sockets have their own "tcp" subsection with no destination, and the change must leave the connected sockets alone.
Definition at line 759 of file bio_fd_tests.c.
◆ test_client_config_unconnected_rejects_other_transports()
| static void test_client_config_unconnected_rejects_other_transports |
( |
void |
| ) |
|
|
static |
A client configuration for an unconnected socket rejects every transport except "udp" and "tcp".
Definition at line 737 of file bio_fd_tests.c.
◆ test_client_config_unconnected_tcp()
| static void test_client_config_unconnected_tcp |
( |
void |
| ) |
|
|
static |
A client configuration for an unconnected socket accepts "tcp".
The destination of the socket is not in the configuration, as the caller sets the destination later.
Definition at line 686 of file bio_fd_tests.c.
◆ test_client_config_unconnected_tcp_options()
| static void test_client_config_unconnected_tcp_options |
( |
void |
| ) |
|
|
static |
The "tcp" subsection of an unconnected socket takes the stream socket options.
Definition at line 714 of file bio_fd_tests.c.
◆ test_client_config_unconnected_udp()
| static void test_client_config_unconnected_udp |
( |
void |
| ) |
|
|
static |
A client configuration for an unconnected socket accepts "udp".
Definition at line 663 of file bio_fd_tests.c.
◆ test_deferred_connect_success_calls_connected_cb()
| static void test_deferred_connect_success_calls_connected_cb |
( |
void |
| ) |
|
|
static |
A deferred connect which succeeds has to call the connected callback.
A non-blocking connect() to a listening loopback port can return EINPROGRESS. On EINPROGRESS, fr_bio_fd_connect_full() defers the connect, and the event loop calls fr_bio_fd_el_connect() once the socket is writable. fr_bio_fd_el_connect() then calls connect() a second time. If the handshake has finished, the second connect() can fail with EISCONN, so fr_bio_fd_try_connect() has to treat EISCONN as success.
The test needs a connect which succeeds, because a connect which fails may not reach fr_bio_fd_el_connect(). kqueue can report a refused connect with EV_EOF, and event.c passes EV_EOF to the error callback, fr_bio_fd_el_error().
Definition at line 89 of file bio_fd_tests.c.
◆ test_eagain_calls_fd_write_blocked_cb()
| static void test_eagain_calls_fd_write_blocked_cb |
( |
void |
| ) |
|
|
static |
The write_blocked callback of an FD bio with no other bios still runs on EAGAIN.
The FD bio is the head of the chain, so the head callback is the callback of the FD bio.
Definition at line 584 of file bio_fd_tests.c.
◆ test_eagain_calls_head_write_blocked_cb()
| static void test_eagain_calls_head_write_blocked_cb |
( |
void |
| ) |
|
|
static |
A write which blocks with no bytes accepted has to run the write_blocked callback of the head bio.
The application sets write_blocked on the head of the chain, not on the FD bio. The FD bio runs fr_bio_write_blocked() when a write is partial. When the socket has no room at all, the write fails with EAGAIN, and the FD bio has to run fr_bio_write_blocked() for that case, too.
Definition at line 544 of file bio_fd_tests.c.
◆ test_listen_accept()
| static void test_listen_accept |
( |
void |
| ) |
|
|
static |
Accept a TCP connection through a listening bio.
fr_bio_fd_accept() returns 0 when no connection is waiting, and 1 with a new connected bio when one is. The listening bio must not change: the new socket, its name, and its read and write routines all belong to the new bio.
Definition at line 310 of file bio_fd_tests.c.
◆ test_recvfromto4()
| static void test_recvfromto4 |
( |
void |
| ) |
|
|
static |
◆ test_recvfromto6()
| static void test_recvfromto6 |
( |
void |
| ) |
|
|
static |
◆ write_until_blocked()
Write one byte at a time until the socket has no room.
A one byte write cannot be partial. The kernel either takes the byte, or fails the write with EAGAIN. The test therefore exercises the "no bytes accepted" path of the FD bio, which is different from the "some bytes accepted" path.
- Returns
- the number of bytes written before the bio blocked.
- <0 if the bio never blocked, or returned an error other than "would block".
Definition at line 520 of file bio_fd_tests.c.
◆ blocked_count
◆ connected_count
◆ error_count
◆ TEST_LIST
Initial value:= {
}
static void test_deferred_connect_success_calls_connected_cb(void)
A deferred connect which succeeds has to call the connected callback.
static void test_recvfromto6(void)
static void test_eagain_calls_fd_write_blocked_cb(void)
The write_blocked callback of an FD bio with no other bios still runs on EAGAIN.
static void test_recvfromto4(void)
static void test_eagain_calls_head_write_blocked_cb(void)
A write which blocks with no bytes accepted has to run the write_blocked callback of the head bio.
static void test_listen_accept(void)
Accept a TCP connection through a listening bio.
static void test_client_config_unconnected_tcp_options(void)
The "tcp" subsection of an unconnected socket takes the stream socket options.
static void test_client_config_unconnected_tcp(void)
A client configuration for an unconnected socket accepts "tcp".
static void test_client_config_connected_tcp(void)
A client configuration for a connected socket still takes the destination of the "tcp" subsection.
static void test_client_config_unconnected_udp(void)
A client configuration for an unconnected socket accepts "udp".
static void test_client_config_unconnected_rejects_other_transports(void)
A client configuration for an unconnected socket rejects every transport except "udp" and "tcp".
Definition at line 780 of file bio_fd_tests.c.
◆ timeout_count