The FreeRADIUS server $Id: f3670dba8951ca10eb4948feb3dc3db9423a334f $
Loading...
Searching...
No Matches
Macros | 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 dependency graph for bio_fd_tests.c:

Go to the source code of this file.

Macros

#define _BIO_PRIVATE   1
 

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 bool ipv6_loopback_usable (void)
 Read one packet through an unconnected UDP bio bound to the wildcard address.
 
static int loopback_listen (uint16_t *port)
 Open a TCP socket listening on loopback.
 
static void recvfromto_test (int af)
 
static void test_deferred_connect_success_calls_connected_cb (void)
 A deferred connect which succeeds has to call the connected callback.
 
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.

Macro Definition Documentation

◆ _BIO_PRIVATE

#define _BIO_PRIVATE   1

Definition at line 26 of file bio_fd_tests.c.

Function Documentation

◆ cb_connected()

static void cb_connected ( fr_bio_t *  bio)
static

Definition at line 35 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 36 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 37 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ ipv6_loopback_usable()

static bool ipv6_loopback_usable ( void  )
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. See if the IPv6 loopback address can be used

Some hosts and containers turn IPv6 off. The bind() fails there, and errno says why.

Definition at line 179 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 50 of file bio_fd_tests.c.

+ Here is the caller graph for this function:

◆ recvfromto_test()

static void recvfromto_test ( int  af)
static

Definition at line 197 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 85 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 280 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 285 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 31 of file bio_fd_tests.c.

◆ error_count

int error_count
static

Definition at line 32 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 },
}
#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)

Definition at line 290 of file bio_fd_tests.c.

◆ timeout_count

int timeout_count
static

Definition at line 33 of file bio_fd_tests.c.