The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
Functions | Variables
bio_fd_tests.c File Reference

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/util/syserror.h>
#include <poll.h>
+ Include dependency graph for bio_fd_tests.c:

Go to the source code of this file.

Functions

static void cb_connected (fr_bio_t *bio)
 
static void cb_error (fr_bio_t *bio)
 
static void cb_timeout (fr_bio_t *bio)
 
static int ipv6_loopback_usable (void)
 See if the IPv6 loopback address can be used.
 
static int loopback_listen (uint16_t *port)
 Open a TCP socket listening on loopback.
 
static void recvfromto_test (int af)
 Read one packet through an unconnected UDP bio bound to the wildcard address.
 
static void test_deferred_connect_success_calls_connected_cb (void)
 A deferred connect which succeeds has to call the connected callback.
 
static void test_listen_accept (void)
 Accept a TCP connection through a listening bio.
 
static void test_recvfromto4 (void)
 
static void test_recvfromto6 (void)
 

Variables

static int connected_count
 
static int error_count
 
 TEST_LIST
 
static int timeout_count
 

Detailed Description

Tests for the FD bio.

Definition in file bio_fd_tests.c.

Function Documentation

◆ cb_connected()

static void cb_connected ( fr_bio_t *  bio)
static

Definition at line 36 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ cb_error()

static void cb_error ( fr_bio_t *  bio)
static

Definition at line 37 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ cb_timeout()

static void cb_timeout ( fr_bio_t *  bio)
static

Definition at line 38 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ 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 173 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ 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]portthe port which the kernel picked.
Returns
  • >=0 the listening socket.
  • <0 on error.

Definition at line 51 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ 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 203 of file bio_fd_tests.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 86 of file bio_fd_tests.c.

+ Here is the call graph for this function:

◆ 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 307 of file bio_fd_tests.c.

+ Here is the call graph for this function:

◆ test_recvfromto4()

static void test_recvfromto4 ( void  )
static

Definition at line 291 of file bio_fd_tests.c.

+ Here is the call graph for this function:

◆ test_recvfromto6()

static void test_recvfromto6 ( void  )
static

Definition at line 296 of file bio_fd_tests.c.

+ Here is the call graph for this function:

Variable Documentation

◆ connected_count

int connected_count
static

Definition at line 32 of file bio_fd_tests.c.

◆ error_count

int error_count
static

Definition at line 33 of file bio_fd_tests.c.

◆ TEST_LIST

TEST_LIST
Initial value:
= {
{ "deferred_connect_success_calls_connected_cb", test_deferred_connect_success_calls_connected_cb },
{ "recvfromto4", test_recvfromto4 },
{ "recvfromto6", test_recvfromto6 },
{ "listen_accept", test_listen_accept },
}
#define TEST_TERMINATOR
Definition acutest.h:77
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_recvfromto4(void)
static void test_listen_accept(void)
Accept a TCP connection through a listening bio.

Definition at line 413 of file bio_fd_tests.c.

◆ timeout_count

int timeout_count
static

Definition at line 34 of file bio_fd_tests.c.