The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
fd.c File Reference

BIO abstractions for file descriptors. More...

#include <freeradius-devel/bio/fd_priv.h>
#include <freeradius-devel/bio/null.h>
#include "fd_errno.h"
+ Include dependency graph for fd.c:

Go to the source code of this file.

Macros

#define ADDR_INIT
 
#define flag_blocked   info.read_blocked
 
#define flag_blocked   info.read_blocked
 
#define flag_blocked   info.read_blocked
 
#define flag_blocked   info.write_blocked
 
#define flag_blocked   info.write_blocked
 
#define flag_blocked   info.read_blocked
 
#define SOL_IP   IPPROTO_IP
 

Functions

fr_bio_tfr_bio_fd_alloc (TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_bio_fd_config_t const *cfg, size_t offset)
 Allocate a FD bio. More...
 
int fr_bio_fd_close (fr_bio_t *bio)
 Close the FD, but leave the bio allocated and alive. More...
 
int fr_bio_fd_connect (fr_bio_t *bio)
 Finalize a connect() More...
 
static int fr_bio_fd_destructor (fr_bio_fd_t *my)
 
fr_bio_fd_info_t const * fr_bio_fd_info (fr_bio_t *bio)
 Returns a pointer to the bio-specific information. More...
 
int fr_bio_fd_init_accept (fr_bio_fd_t *my)
 
int fr_bio_fd_init_common (fr_bio_fd_t *my)
 
int fr_bio_fd_init_connected (fr_bio_fd_t *my)
 
static int fr_bio_fd_init_file (fr_bio_fd_t *my)
 Files are a special case of connected sockets. More...
 
static ssize_t fr_bio_fd_read_accept (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
 Return an fd on read() More...
 
static ssize_t fr_bio_fd_read_connected_datagram (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
 Connected datagram read. More...
 
static ssize_t fr_bio_fd_read_discard (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
 Discard all reads from a UDP socket. More...
 
static ssize_t fr_bio_fd_read_stream (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
 Stream read. More...
 
static ssize_t fr_bio_fd_recvfrom (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
 Read from a UDP socket where we know our IP. More...
 
static ssize_t fr_bio_fd_sendto (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size)
 Write to a UDP socket where we know our IP. More...
 
int fr_bio_fd_socket_name (fr_bio_fd_t *my)
 
static ssize_t fr_bio_fd_try_connect (fr_bio_fd_t *my)
 Try to connect(). More...
 
static ssize_t fr_bio_fd_write (fr_bio_t *bio, UNUSED void *packet_ctx, const void *buffer, size_t size)
 Write to fd. More...
 
int fr_bio_fd_write_only (fr_bio_t *bio)
 Mark up a bio as write-only. More...
 
int fr_filename_to_sockaddr (struct sockaddr_un *sun, socklen_t *sunlen, char const *filename)
 

Detailed Description

BIO abstractions for file descriptors.

Id
0de587887903f000ff585244a239e25735bbb00d

Definition in file fd.c.

Macro Definition Documentation

◆ ADDR_INIT

#define ADDR_INIT
Value:
do { \
addr->when = fr_time(); \
addr->socket.type = my->info.socket.type; \
addr->socket.fd = -1; \
addr->socket.inet.ifindex = my->info.socket.inet.ifindex; \
} while (0)
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition: state_test.c:8

Definition at line 84 of file fd.c.

◆ flag_blocked [1/6]

#define flag_blocked   info.read_blocked

◆ flag_blocked [2/6]

#define flag_blocked   info.read_blocked

◆ flag_blocked [3/6]

#define flag_blocked   info.read_blocked

◆ flag_blocked [4/6]

#define flag_blocked   info.write_blocked

◆ flag_blocked [5/6]

#define flag_blocked   info.write_blocked

◆ flag_blocked [6/6]

#define flag_blocked   info.read_blocked

◆ SOL_IP

#define SOL_IP   IPPROTO_IP

Definition at line 33 of file fd.c.

Function Documentation

◆ fr_bio_fd_alloc()

fr_bio_t* fr_bio_fd_alloc ( TALLOC_CTX *  ctx,
fr_bio_cb_funcs_t cb,
fr_bio_fd_config_t const *  cfg,
size_t  offset 
)

Allocate a FD bio.

The caller is responsible for tracking the FD, and all associated management of it. The bio API is intended to be simple, and does not provide wrapper functions for various ioctls. The caller should instead do that work.

Once the FD is give to the bio, its lifetime is "owned" by the bio. Calling talloc_free(bio) will close the FD.

The caller can still manage the FD for being readable / writeable. However, the caller should not call this bio directly (unless it is the only one). Instead, the caller should read from / write to the previous bio which will then eventually call this one.

Before updating any event handler readable / writeable callbacks, the caller should check fr_bio_fd_at_eof(). If true, then the handlers should not be inserted. The previous bios should still be called to process any pending data, until they return EOF.

The main purpose of an FD bio is to wrap the FD in a bio container. That, and handling retries on read / write, along with returning EOF as an error instead of zero.

Note that the read / write functions can return partial data. It is the callers responsibility to ensure that any writes continue from where they left off (otherwise dat awill be missing). And any partial reads should go to a memory bio.

If a read returns EOF, then the FD remains open until talloc_free(bio) or fr_bio_fd_close() is called.

Parameters
ctxthe talloc ctx
cbcallbacks
cfgstructure holding configuration information
offsetonly for unconnected datagram sockets, where fr_bio_fd_packet_ctx_t is stored
Returns
  • NULL on error, memory allocation failed
  • !NULL the bio

Definition at line 1018 of file fd.c.

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

◆ fr_bio_fd_close()

int fr_bio_fd_close ( fr_bio_t bio)

Close the FD, but leave the bio allocated and alive.

Definition at line 1062 of file fd.c.

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

◆ fr_bio_fd_connect()

int fr_bio_fd_connect ( fr_bio_t bio)

Finalize a connect()

connect() said "come back when the socket is writeable". It's now writeable, so we check if there was a connection error.

Definition at line 1125 of file fd.c.

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

◆ fr_bio_fd_destructor()

static int fr_bio_fd_destructor ( fr_bio_fd_t my)
static

Definition at line 94 of file fd.c.

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

◆ fr_bio_fd_info()

fr_bio_fd_info_t const* fr_bio_fd_info ( fr_bio_t bio)

Returns a pointer to the bio-specific information.

Definition at line 1167 of file fd.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_init_accept()

int fr_bio_fd_init_accept ( fr_bio_fd_t my)

Definition at line 966 of file fd.c.

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

◆ fr_bio_fd_init_common()

int fr_bio_fd_init_common ( fr_bio_fd_t my)

< stream socket

< connected datagram

< we know our IP address

Definition at line 845 of file fd.c.

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

◆ fr_bio_fd_init_connected()

int fr_bio_fd_init_connected ( fr_bio_fd_t my)

Definition at line 782 of file fd.c.

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

◆ fr_bio_fd_init_file()

static int fr_bio_fd_init_file ( fr_bio_fd_t my)
static

Files are a special case of connected sockets.

Definition at line 748 of file fd.c.

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

◆ fr_bio_fd_read_accept()

static ssize_t fr_bio_fd_read_accept ( fr_bio_t bio,
void *  packet_ctx,
void *  buffer,
size_t  size 
)
static

Return an fd on read()

With packet_ctx containing information about the socket.

Definition at line 893 of file fd.c.

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

◆ fr_bio_fd_read_connected_datagram()

static ssize_t fr_bio_fd_read_connected_datagram ( fr_bio_t bio,
UNUSED void *  packet_ctx,
void *  buffer,
size_t  size 
)
static

Connected datagram read.

The difference between this and stream protocols is that for datagrams. a read of zero means "no packets", where a read of zero on a steam socket means "EOF".

Connected sockets do not update per-packet contexts.

Definition at line 148 of file fd.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_read_discard()

static ssize_t fr_bio_fd_read_discard ( fr_bio_t bio,
UNUSED void *  packet_ctx,
void *  buffer,
size_t  size 
)
static

Discard all reads from a UDP socket.

Definition at line 1177 of file fd.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_read_stream()

static ssize_t fr_bio_fd_read_stream ( fr_bio_t bio,
UNUSED void *  packet_ctx,
void *  buffer,
size_t  size 
)
static

Stream read.

Definition at line 109 of file fd.c.

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

◆ fr_bio_fd_recvfrom()

static ssize_t fr_bio_fd_recvfrom ( fr_bio_t bio,
void *  packet_ctx,
void *  buffer,
size_t  size 
)
static

Read from a UDP socket where we know our IP.

Definition at line 169 of file fd.c.

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

◆ fr_bio_fd_sendto()

static ssize_t fr_bio_fd_sendto ( fr_bio_t bio,
void *  packet_ctx,
const void *  buffer,
size_t  size 
)
static

Write to a UDP socket where we know our IP.

Definition at line 251 of file fd.c.

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

◆ fr_bio_fd_socket_name()

int fr_bio_fd_socket_name ( fr_bio_fd_t my)

Definition at line 646 of file fd.c.

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

◆ fr_bio_fd_try_connect()

static ssize_t fr_bio_fd_try_connect ( fr_bio_fd_t my)
static

Try to connect().

If connect is blocking, we either succeed or error immediately. Otherwise, the caller has to select the socket for writeability, and then call fr_bio_fd_connect() as soon as the socket is writeable.

Definition at line 682 of file fd.c.

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

◆ fr_bio_fd_write()

static ssize_t fr_bio_fd_write ( fr_bio_t bio,
UNUSED void *  packet_ctx,
const void *  buffer,
size_t  size 
)
static

Write to fd.

This function is used for connected sockets, where we ignore the packet_ctx.

Definition at line 210 of file fd.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_write_only()

int fr_bio_fd_write_only ( fr_bio_t bio)

Mark up a bio as write-only.

Definition at line 1199 of file fd.c.

+ Here is the call graph for this function:

◆ fr_filename_to_sockaddr()

int fr_filename_to_sockaddr ( struct sockaddr_un *  sun,
socklen_t *  sunlen,
char const *  filename 
)

Definition at line 628 of file fd.c.

+ Here is the caller graph for this function: