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 <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)
 

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_ACCEPT
}
 

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...
 
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_write_only (fr_bio_t *bio)
 Mark up a bio as write-only. More...
 

Detailed Description

Binary IO abstractions for file descriptors.

Id
7c695251c409536b2789d34acdc02b71e13d741d

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 76 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
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 107 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.
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 48 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 37 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 53 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_ACCEPT 

returns new fd in buffer on fr_bio_read()

Definition at line 60 of file fd.h.

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_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_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 717 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 1199 of file fd.c.

+ Here is the call graph for this function: