The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Binary IO abstractions. More...
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/dlist.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 void(* | fr_bio_callback_t) (fr_bio_t *bio) |
typedef int(* | fr_bio_io_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_OOM , FR_BIO_ERROR_VERIFY , FR_BIO_ERROR_BUFFER_FULL , FR_BIO_ERROR_BUFFER_TOO_SMALL } |
Functions | |
void | fr_bio_cb_set (fr_bio_t *bio, fr_bio_cb_funcs_t const *cb)) |
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_t * | fr_bio_next (fr_bio_t *bio) |
static fr_bio_t * | fr_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... | |
Binary IO abstractions.
Create abstract binary input / output buffers.
Definition in file base.h.
struct fr_bio_cb_funcs_t |
Data Fields | ||
---|---|---|
fr_bio_callback_t | connected | called when the BIO is ready to be used |
fr_bio_callback_t | eof | called when the BIO is at EOF |
fr_bio_callback_t | failed | called when the BIO fails |
fr_bio_io_t | read_blocked | |
fr_bio_io_t | read_resume | "unblocked" is too similar to "blocked" |
fr_bio_callback_t | shutdown | called when the BIO is being shut down |
fr_bio_io_t | write_blocked | returns 0 for "couldn't block", 1 for "did block". |
fr_bio_io_t | write_resume |
struct 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 |
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.
bio | the binary IO handler |
packet_ctx | where the function can store per-packet information, such as src/dst IP/port for datagram sockets |
buffer | where the function should store data it reads |
size | the maximum amount of data to read. |
enum 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_OOM | out of memory |
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 |
void fr_bio_cb_set | ( | fr_bio_t * | bio, |
fr_bio_cb_funcs_t const * | cb | ||
) |
int fr_bio_destructor | ( | fr_bio_t * | bio | ) |
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 105 of file base.c.
|
inlinestatic |
Read raw data from a bio.
bio | the binary IO handler |
packet_ctx | packet-specific data associated with the buffer |
buffer | where to read the data |
size | amount of data to read. |
Definition at line 149 of file base.h.
int fr_bio_shutdown | ( | fr_bio_t * | bio | ) |
Shut down a set of BIOs.
We shut down the BIOs from the top to the bottom. This gives the TLS BIO an opportunity to call the SSL_shutdown() routine, which should then write to the FD BIO.
Definition at line 141 of file base.c.
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 185 of file base.c.
char const* fr_bio_strerror | ( | ssize_t | error | ) |
|
inlinestatic |
Write raw data to a bio.
bio | the binary IO handler |
packet_ctx | packet-specific data associated with the buffer |
buffer | the data to write. If NULL, will "flush" any pending data. |
size | amount of data to write. For flush, it should be SIZE_MAX |
Definition at line 172 of file base.h.