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

Binary IO abstractions. More...

#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dlist.h>
+ Include dependency graph for base.h:

Go to the source code of this file.

Data Structures

struct  fr_bio_cb_funcs_t
 
struct  fr_bio_s
 

Macros

#define _CONST   const
 
#define fr_bio_error(_x)   (-(FR_BIO_ERROR_ ## _x))
 
#define XDEBUG(fmt, ...)   fprintf(stderr, fmt, ## __VA_ARGS__)
 

Typedefs

typedef int(* fr_bio_accept_t) (fr_bio_t *bio, TALLOC_CTX *ctx, fr_bio_t **accepted)
 Accept a new connection on a bio. More...
 
typedef int(* fr_bio_callback_t) (fr_bio_t *bio)
 
typedef ssize_t(* fr_bio_read_t) (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
 Do a raw read from a socket, or other data source. More...
 
typedef struct fr_bio_s fr_bio_t
 
typedef ssize_t(* fr_bio_write_t) (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size)
 

Enumerations

enum  fr_bio_error_type_t {
  FR_BIO_ERROR_NONE = 0 ,
  FR_BIO_ERROR_IO_WOULD_BLOCK ,
  FR_BIO_ERROR_IO ,
  FR_BIO_ERROR_GENERIC ,
  FR_BIO_ERROR_VERIFY ,
  FR_BIO_ERROR_BUFFER_FULL ,
  FR_BIO_ERROR_BUFFER_TOO_SMALL ,
  FR_BIO_ERROR_EOF
}
 

Functions

int fr_bio_destructor (fr_bio_t *bio)
 Free this bio. More...
 
int fr_bio_free (fr_bio_t *bio)
 Free this bio, and everything it calls. More...
 
static fr_bio_tfr_bio_next (fr_bio_t *bio)
 
static fr_bio_tfr_bio_prev (fr_bio_t *bio)
 
static ssize_t fr_bio_read (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
 Read raw data from a bio. More...
 
int fr_bio_shutdown (fr_bio_t *bio)
 Shut down a set of BIOs. More...
 
int fr_bio_shutdown_intermediate (fr_bio_t *bio)
 Like fr_bio_shutdown(), but can be called by anyone in the chain. More...
 
char const * fr_bio_strerror (ssize_t error)
 
static ssize_t fr_bio_write (fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
 Write raw data to a bio. More...
 

Detailed Description

Binary IO abstractions.

Id
b3549cfb06fa84d6e66f22e90b8686ded7c8c447

Create abstract binary input / output buffers.

Definition in file base.h.


Data Structure Documentation

◆ fr_bio_cb_funcs_t

struct fr_bio_cb_funcs_t

Definition at line 86 of file base.h.

+ Collaboration diagram for fr_bio_cb_funcs_t:
Data Fields
fr_bio_callback_t activate
fr_bio_callback_t shutdown

◆ fr_bio_s

struct fr_bio_s

Definition at line 103 of file base.h.

+ Collaboration diagram for fr_bio_s:
Data Fields
fr_dlist_t _CONST entry in the linked list of multiple bios
fr_bio_read_t _CONST read read from the underlying bio
void * uctx user ctx, caller can manually set it.
fr_bio_write_t _CONST write write to the underlying bio

Macro Definition Documentation

◆ _CONST

#define _CONST   const

Definition at line 42 of file base.h.

◆ fr_bio_error

#define fr_bio_error (   _x)    (-(FR_BIO_ERROR_ ## _x))

Definition at line 184 of file base.h.

◆ XDEBUG

#define XDEBUG (   fmt,
  ... 
)    fprintf(stderr, fmt, ## __VA_ARGS__)

Definition at line 35 of file base.h.

Typedef Documentation

◆ fr_bio_accept_t

typedef int(* fr_bio_accept_t) (fr_bio_t *bio, TALLOC_CTX *ctx, fr_bio_t **accepted)

Accept a new connection on a bio.

Parameters
biothe binary IO handler
ctxthe talloc ctx for the new bio.
[out]acceptedthe accepted bio
Returns
  • <0 on error
  • 0 for "we did nothing, and there is no new bio available"
  • 1 for "the accepted bio is available"

Definition at line 101 of file base.h.

◆ fr_bio_callback_t

typedef int(* fr_bio_callback_t) (fr_bio_t *bio)

Definition at line 84 of file base.h.

◆ fr_bio_read_t

typedef ssize_t(* fr_bio_read_t) (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)

Do a raw read from a socket, or other data source.

These functions should be careful about packet_ctx. This handling depends on a number of factors. Note that the packet_ctx may be NULL!

Stream sockets will generally ignore packet_ctx.

Datagram sockets generally write src/dst IP/port to the packet context. This same packet_ctx is then passed to bio->write(), which can use it to send the data to the correct destination.

Parameters
biothe binary IO handler
packet_ctxwhere the function can store per-packet information, such as src/dst IP/port for datagram sockets
bufferwhere the function should store data it reads
sizethe maximum amount of data to read.
Returns
  • <0 for error
  • 0 for "no data available". Note that this does NOT mean EOF! It could mean "we do not have a full packet"
  • >0 for amount of data which was read.

Definition at line 81 of file base.h.

◆ fr_bio_t

typedef struct fr_bio_s fr_bio_t

Definition at line 1 of file base.h.

◆ fr_bio_write_t

typedef ssize_t(* fr_bio_write_t) (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size)

Definition at line 82 of file base.h.

Enumeration Type Documentation

◆ fr_bio_error_type_t

Enumerator
FR_BIO_ERROR_NONE 
FR_BIO_ERROR_IO_WOULD_BLOCK 

IO would block.

FR_BIO_ERROR_IO 

IO error - check errno.

FR_BIO_ERROR_GENERIC 

generic "failed" error - check fr_strerror()

FR_BIO_ERROR_VERIFY 

some packet verification error

FR_BIO_ERROR_BUFFER_FULL 

the buffer is full

FR_BIO_ERROR_BUFFER_TOO_SMALL 

the output buffer is too small for the data

FR_BIO_ERROR_EOF 

at EOF

Definition at line 47 of file base.h.

Function Documentation

◆ fr_bio_destructor()

int fr_bio_destructor ( fr_bio_t bio)

Free this bio.

The bio can only be freed if it is not in any chain.

Definition at line 34 of file base.c.

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

◆ fr_bio_free()

int fr_bio_free ( fr_bio_t bio)

Free this bio, and everything it calls.

We unlink the bio chain, and then free it individually. If there's an error, the bio chain is relinked. That way the error can be addressed (somehow) and this function can be called again.

Note that we do not support talloc_free() for the bio chain. Each individual bio has to be unlinked from the chain before the destructor will allow it to be freed. This functionality is by design.

We want to have an API where bios are created "bottom up", so that it is impossible for an application to create an incorrect chain. However, creating the chain bottom up means that the lower bios not parented from the higher bios, and therefore talloc_free() won't free them. As a result, we need an explicit bio_free() function.

Definition at line 113 of file base.c.

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

◆ fr_bio_next()

static fr_bio_t* fr_bio_next ( fr_bio_t bio)
inlinestatic

Definition at line 121 of file base.h.

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

◆ fr_bio_prev()

static fr_bio_t* fr_bio_prev ( fr_bio_t bio)
inlinestatic

Definition at line 112 of file base.h.

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

◆ fr_bio_read()

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

Read raw data from a bio.

Parameters
biothe binary IO handler
packet_ctxpacket-specific data associated with the buffer
bufferwhere to read the data
sizeamount of data to read.
Returns
  • <0 for error. The return code will be fr_bio_error(ERROR_NAME)
  • 0 for "did not read any data". Note that EOF is an error return.
  • >0 for amount of data read.

Definition at line 141 of file base.h.

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

◆ fr_bio_shutdown()

int fr_bio_shutdown ( fr_bio_t bio)

Shut down a set of BIOs.

Must be called from the top-most bio.

Will shut down the bios from the bottom-up.

The shutdown function MUST be callable multiple times without breaking.

Definition at line 152 of file base.c.

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

◆ fr_bio_shutdown_intermediate()

int fr_bio_shutdown_intermediate ( fr_bio_t bio)

Like fr_bio_shutdown(), but can be called by anyone in the chain.

Definition at line 186 of file base.c.

+ Here is the call graph for this function:

◆ fr_bio_strerror()

char const* fr_bio_strerror ( ssize_t  error)

Definition at line 197 of file base.c.

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

◆ fr_bio_write()

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

Write raw data to a bio.

Parameters
biothe binary IO handler
packet_ctxpacket-specific data associated with the buffer
bufferthe data to write. If NULL, will "flush" any pending data.
sizeamount of data to write. For flush, it should be SIZE_MAX
Returns
  • <0 for error. The return code will be fr_bio_error(ERROR_NAME)
  • 0 for "did not write any data"
  • >0 for amount of data written. Should always be equal to size!

Definition at line 164 of file base.h.

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