|
| static int | accept4 (int fd, struct sockaddr *sockaddr, socklen_t *salen, UNUSED int flags) |
| |
| int | fr_bio_fd_accept (TALLOC_CTX *ctx, fr_bio_t **out_p, fr_bio_t *bio) |
| | Accept a new connection on a socket.
|
| |
| static int | fr_bio_fd_accept_datagram (TALLOC_CTX *ctx, fr_bio_t **out_p, fr_bio_fd_t *parent) |
| | Accept a "connection" on a datagram listening socket.
|
| |
| static int | fr_bio_fd_accept_stream (fr_bio_fd_t *my, fr_bio_fd_t const *parent) |
| | Accept a stream socket and initialize its flags.
|
| |
| fr_bio_t * | fr_bio_fd_alloc (TALLOC_CTX *ctx, fr_bio_fd_config_t const *cfg, size_t offset) |
| | Allocate a FD bio.
|
| |
| int | fr_bio_fd_close (fr_bio_t *bio) |
| | Close the FD, but leave the bio allocated and alive.
|
| |
| 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()
|
| |
| static void | fr_bio_fd_el_connect (NDEBUG_UNUSED fr_event_list_t *el, NDEBUG_UNUSED int fd, NDEBUG_UNUSED int flags, void *uctx) |
| | Connect callback for when the socket is writable.
|
| |
| static void | fr_bio_fd_el_error (UNUSED fr_event_list_t *el, UNUSED int fd, UNUSED int flags, int fd_errno, void *uctx) |
| | FD error when trying to connect, give up on the BIO.
|
| |
| static void | fr_bio_fd_el_timeout (UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx) |
| | We have a timeout on the conenction.
|
| |
| static int | fr_bio_fd_eof (fr_bio_t *bio) |
| |
| fr_bio_fd_info_t const * | fr_bio_fd_info (fr_bio_t *bio) |
| | Returns a pointer to the bio-specific information.
|
| |
| int | fr_bio_fd_init_common (fr_bio_fd_t *my) |
| |
| int | fr_bio_fd_init_connected (fr_bio_fd_t *my) |
| |
| static int | fr_bio_fd_init_file (fr_bio_fd_t *my) |
| | Files are a special case of connected sockets.
|
| |
| int | fr_bio_fd_init_listen (fr_bio_fd_t *my) |
| |
| static ssize_t | fr_bio_fd_notconn_read (UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void *buffer, UNUSED size_t size) |
| | This FD isn't connected.
|
| |
| static ssize_t | fr_bio_fd_read_connected_datagram (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
| | Connected datagram read.
|
| |
| static ssize_t | fr_bio_fd_read_discard_datagram (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
| | Discard all reads from a UDP socket.
|
| |
| static ssize_t | fr_bio_fd_read_discard_stream (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
| | Discard all reads from a TCP socket.
|
| |
| static ssize_t | fr_bio_fd_read_first_datagram (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
| | Return the datagram which fr_bio_fd_accept() read from the listening socket.
|
| |
| static ssize_t | fr_bio_fd_read_stream (fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size) |
| | Stream read.
|
| |
| static ssize_t | fr_bio_fd_recvfrom (fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size) |
| | Read from a UDP socket where we know our IP.
|
| |
| static ssize_t | fr_bio_fd_recvmsg_dst (fr_bio_fd_t *parent, uint8_t *buffer, int flags, struct sockaddr_storage *from, socklen_t *from_len, fr_ipaddr_t *dst) |
| | Receive a datagram, and find the address which the datagram was sent to.
|
| |
| static ssize_t | fr_bio_fd_sendto (fr_bio_t *bio, void *packet_ctx, const void *buffer, size_t size) |
| | Write to a UDP socket where we know our IP.
|
| |
| static void | fr_bio_fd_set_open (fr_bio_fd_t *my) |
| |
| static int | fr_bio_fd_shutdown (fr_bio_t *bio) |
| | Orderly shutdown.
|
| |
| int | fr_bio_fd_socket_name (fr_bio_fd_t *my) |
| |
| static int | fr_bio_fd_try_connect (fr_bio_fd_t *my) |
| | Try to connect().
|
| |
| static ssize_t | fr_bio_fd_write (fr_bio_t *bio, UNUSED void *packet_ctx, const void *buffer, size_t size) |
| | Write to fd.
|
| |
| int | fr_bio_fd_write_only (fr_bio_t *bio) |
| | Mark up a bio as write-only.
|
| |
| static int | fr_bio_fd_write_resume (fr_bio_t *bio) |
| |
| int | fr_filename_to_sockaddr (struct sockaddr_un *sun, socklen_t *sunlen, char const *filename) |
| |
BIO abstractions for file descriptors.
- Id
- a7762af93055263c2ceed71f06fc8102b6f5d8a4
- Copyright
- 2024 Network RADIUS SAS (legal.nosp@m.@net.nosp@m.workr.nosp@m.adiu.nosp@m.s.com)
Definition in file fd.c.
| static int fr_bio_fd_accept_datagram |
( |
TALLOC_CTX * |
ctx, |
|
|
fr_bio_t ** |
out_p, |
|
|
fr_bio_fd_t * |
parent |
|
) |
| |
|
static |
Accept a "connection" on a datagram listening socket.
This function is really only useful for DTLS. A datagram socket has no connections, so a connection is made by taking the source IP and port of the first datagram, and opening a new socket which is connected to that peer. The kernel then delivers the datagrams of that peer to the new socket in preference to the listening socket. This only works when the peer sends one stream of datagrams. Other UDP applications can have several datagrams from the same source IP waiting in the listening socket, and those datagrams stay in the listening socket.
The new bio is a copy of the listening bio, except that it is a connected socket. It has its own file descriptor, as connect() is a property of the socket and not of the descriptor, so dup() would connect the listening socket. The new socket needs SO_REUSEPORT, as the new socket is bound to the address which the datagram was sent to, and the port of the listening socket. That address can be more specific than the address of the listening socket, when the listening socket is bound to a wildcard.
The datagram is read directly into a buffer which belongs to the listening bio, and which is allocated once when the listening bio opens. The one read gives the datagram, the source, and the destination. The datagram is out of the socket before the new socket exists, so if the new socket cannot be opened, the datagram is lost. The peer retransmits, as a lost datagram looks like any other lost datagram.
The datagram which named the peer is saved in the new bio. The first read of the new bio returns the saved datagram. The datagram is no longer in the kernel, so no event loop will tell the application that the new socket is readable. info.read_blocked is false, and the application MUST call fr_bio_read() once after fr_bio_fd_accept() returns, and then it can wait for events as usual.
- Parameters
-
| [in] | ctx | to allocate the new bio in. |
| [out] | out_p | the new bio. |
| [in] | parent | the listening datagram bio. |
- Returns
- <0 on error
- 0 for "no datagram is waiting"
- 1 for "the new bio is available"
Definition at line 1751 of file fd.c.
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.
The bio caches the cfg pointer, so the configuration has to live at least as long as the bio does. See fr_bio_fd_open().
- Parameters
-
| ctx | the talloc ctx |
| cfg | structure holding the configuration information |
| offset | only 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 1116 of file fd.c.
Return the datagram which fr_bio_fd_accept() read from the listening socket.
fr_bio_fd_accept_datagram() has to read the datagram in order to name the peer, so the datagram is no longer in the socket. The first read returns the saved datagram, and then switches to reading the connected socket.
A datagram which is larger than the buffer is truncated, in the same way as a read of the socket.
Definition at line 237 of file fd.c.