The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
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>
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_t * | fr_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... | |
Binary IO abstractions for file descriptors.
Allow reads and writes from file descriptors.
Definition in file fd.h.
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.
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 |
struct 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? |
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.
Data Fields | ||
---|---|---|
fr_socket_t | socket | socket information, including FD. |
fr_time_t | when | when the packet was received |
#define fr_bio_fd_connect | ( | _x | ) | fr_bio_fd_connect_full(_x, NULL, NULL, NULL, NULL, NULL) |
enum fr_bio_fd_state_t |
enum 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. |
Alternative to calling fr_bio_read() on new socket.
Definition at line 1388 of file fd.c.
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.
ctx | the talloc ctx |
cfg | structure holding configuration information |
offset | only for unconnected datagram sockets, where fr_bio_fd_packet_ctx_t is stored |
Definition at line 1012 of file fd.c.
int fr_bio_fd_close | ( | fr_bio_t * | bio | ) |
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.
bio | the binary IO handler |
el | the event list |
connected_cb | callback to run when the BIO is connected |
error_cb | callback to run when the FD has an error |
timeout | when to time out the connect() attempt |
timeout_cb | to call when the timeout runs. |
Definition at line 1235 of file fd.c.
fr_bio_fd_info_t const* fr_bio_fd_info | ( | fr_bio_t * | bio | ) |
int fr_bio_fd_open | ( | fr_bio_t * | bio, |
fr_bio_fd_config_t const * | cfg | ||
) |
int fr_bio_fd_reopen | ( | fr_bio_t * | bio | ) |