The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Enumerations | Functions
fd.h File Reference

Binary IO abstractions for file descriptors. More...

#include <freeradius-devel/bio/base.h>
#include <freeradius-devel/util/socket.h>
#include <freeradius-devel/util/event.h>
#include <fcntl.h>
+ Include dependency graph for fd.h:

Go to the source code of this file.

Data Structures

struct  fr_bio_fd_config_t
 Configuration for sockets. More...
 
struct  fr_bio_fd_info_t
 Run-time status of the socket. More...
 
struct  fr_bio_fd_packet_ctx_t
 Per-packet context. More...
 

Macros

#define AF_FILE_BIO   (INT_MAX)
 
#define fr_bio_fd_connect(_x)   fr_bio_fd_connect_full(_x, NULL, NULL, NULL, NULL, NULL)
 

Enumerations

enum  fr_bio_fd_state_t {
  FR_BIO_FD_STATE_INVALID = 0 ,
  FR_BIO_FD_STATE_CLOSED ,
  FR_BIO_FD_STATE_OPEN ,
  FR_BIO_FD_STATE_CONNECTING
}
 
enum  fr_bio_fd_type_t {
  FR_BIO_FD_UNCONNECTED ,
  FR_BIO_FD_CONNECTED ,
  FR_BIO_FD_LISTEN ,
  FR_BIO_FD_ACCEPTED
}
 

Functions

int fr_bio_fd_accept (TALLOC_CTX *ctx, fr_bio_t **out, fr_bio_t *bio)
 Alternative to calling fr_bio_read() on new socket. More...
 
fr_bio_tfr_bio_fd_alloc (TALLOC_CTX *ctx, 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_full (fr_bio_t *bio, fr_event_list_t *el, fr_bio_callback_t connected_cb, fr_bio_callback_t error_cb, fr_time_delta_t *timeout, fr_bio_callback_t timeout_cb))
 Finalize a connect() More...
 
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_open (fr_bio_t *bio, fr_bio_fd_config_t const *cfg)
 Opens a socket and updates sock->fd. More...
 
int fr_bio_fd_reopen (fr_bio_t *bio)
 Reopen a file BIO. More...
 
int fr_bio_fd_write_only (fr_bio_t *bio)
 Mark up a bio as write-only. More...
 

Detailed Description

Binary IO abstractions for file descriptors.

Id
de40208e60fb7631c9c520dca58c311ecbeb4dd9

Allow reads and writes from file descriptors.

Definition in file fd.h.


Data Structure Documentation

◆ fr_bio_fd_config_t

struct fr_bio_fd_config_t

Configuration for sockets.

Each piece of information is broken out into a separate field, so that the configuration file parser can parse each field independently.

We also include more information here than we need in an fr_socket_t.

Definition at line 78 of file fd.h.

+ Collaboration diagram for fr_bio_fd_config_t:
Data Fields
bool async is it async
fr_ipaddr_t dst_ipaddr their IP address
uint16_t dst_port their port
char const * filename for files
int flags O_RDONLY, etc.
gid_t gid who owns the socket
char const * interface for binding to an interface
bool mkdir make intermediate directories
char const * path for Unix domain sockets
mode_t perm permissions for domain sockets
uint32_t recv_buff How big the kernel's receive buffer should be.
uint32_t send_buff How big the kernel's send buffer should be.
int socket_type SOCK_STREAM or SOCK_DGRAM.
fr_ipaddr_t src_ipaddr our IP address
uint16_t src_port our port
bool tcp_delay We do tcp_nodelay by default.
fr_bio_fd_type_t type accept, connected, unconnected, etc.
uid_t uid who owns the socket

◆ fr_bio_fd_info_t

struct fr_bio_fd_info_t

Run-time status of the socket.

Definition at line 110 of file fd.h.

+ Collaboration diagram for fr_bio_fd_info_t:
Data Fields
fr_bio_fd_config_t const * cfg so we know what was asked, vs what was granted.
int connect_errno from connect() or other APIs
bool eof are we at EOF?
bool read_blocked did we block on read?
fr_socket_t socket as connected socket
fr_bio_fd_state_t state connecting, open, closed, etc.
fr_bio_fd_type_t type type of the socket
bool write_blocked did we block on write?

◆ fr_bio_fd_packet_ctx_t

struct fr_bio_fd_packet_ctx_t

Per-packet context.

For reading packets src_ip is *their* IP, and dst_ip is *our* IP.

For writing packets, src_ip is *our* IP, and dst_ip is *their* IP.

This context is returned only for datagram sockets.  For stream sockets (TCP and Unix domain), it
isn't used.  The caller can look at the socket information to determine src/dst ip/port.

Definition at line 49 of file fd.h.

+ Collaboration diagram for fr_bio_fd_packet_ctx_t:
Data Fields
fr_socket_t socket socket information, including FD.
fr_time_t when when the packet was received

Macro Definition Documentation

◆ AF_FILE_BIO

#define AF_FILE_BIO   (INT_MAX)

Definition at line 38 of file fd.h.

◆ fr_bio_fd_connect

#define fr_bio_fd_connect (   _x)    fr_bio_fd_connect_full(_x, NULL, NULL, NULL, NULL, NULL)

Definition at line 134 of file fd.h.

Enumeration Type Documentation

◆ fr_bio_fd_state_t

Enumerator
FR_BIO_FD_STATE_INVALID 
FR_BIO_FD_STATE_CLOSED 
FR_BIO_FD_STATE_OPEN 

error states must be before this

FR_BIO_FD_STATE_CONNECTING 

Definition at line 54 of file fd.h.

◆ fr_bio_fd_type_t

Enumerator
FR_BIO_FD_UNCONNECTED 

unconnected UDP / datagram only

FR_BIO_FD_CONNECTED 

connected client sockets (UDP or TCP)

FR_BIO_FD_LISTEN 

returns new fd in buffer on fr_bio_read() or fr_bio_fd_accept()

FR_BIO_FD_ACCEPTED 

temporarily until it's connected.

Definition at line 61 of file fd.h.

Function Documentation

◆ fr_bio_fd_accept()

int fr_bio_fd_accept ( TALLOC_CTX *  ctx,
fr_bio_t **  out,
fr_bio_t bio 
)

Alternative to calling fr_bio_read() on new socket.

Definition at line 1388 of file fd.c.

+ Here is the call graph for this function:

◆ fr_bio_fd_alloc()

fr_bio_t* fr_bio_fd_alloc ( TALLOC_CTX *  ctx,
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
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 1012 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 1058 of file fd.c.

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

◆ fr_bio_fd_connect_full()

int fr_bio_fd_connect_full ( fr_bio_t bio,
fr_event_list_t el,
fr_bio_callback_t  connected_cb,
fr_bio_callback_t  error_cb,
fr_time_delta_t timeout,
fr_bio_callback_t  timeout_cb 
)

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.

Parameters
biothe binary IO handler
elthe event list
connected_cbcallback to run when the BIO is connected
error_cbcallback to run when the FD has an error
timeoutwhen to time out the connect() attempt
timeout_cbto call when the timeout runs.
Returns
  • <0 on error
  • 0 for "try again later". If callbacks are set, the callbacks will try again. Otherwise the application has to try again.
  • 1 for "we are now connected".

Definition at line 1235 of file fd.c.

+ Here is the call 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 1323 of file fd.c.

+ Here is the caller graph for this function:

◆ fr_bio_fd_open()

int fr_bio_fd_open ( fr_bio_t bio,
fr_bio_fd_config_t const *  cfg 
)

Opens a socket and updates sock->fd.

If the socket is asynchronous, it also calls connect()

Definition at line 715 of file fd_open.c.

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

◆ fr_bio_fd_reopen()

int fr_bio_fd_reopen ( fr_bio_t bio)

Reopen a file BIO.

e.g. for log files.

Definition at line 1000 of file fd_open.c.

+ Here is the call graph for this function:
+ 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 1353 of file fd.c.

+ Here is the call graph for this function: