The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
Loading...
Searching...
No Matches
fd_priv.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: f81c4fd38eaf7b7bf3230243bd14212f903cadb7 $
20 * @file lib/bio/fd_priv.h
21 * @brief Private binary IO abstractions for file descriptors
22 *
23 * @copyright 2024 Network RADIUS SAS (legal@networkradius.com)
24 */
25RCSIDH(lib_bio_fd_privh, "$Id: f81c4fd38eaf7b7bf3230243bd14212f903cadb7 $")
26
27#include <freeradius-devel/util/syserror.h>
28
29#include <freeradius-devel/bio/bio_priv.h>
30#include <freeradius-devel/bio/fd.h>
31
32/** The largest payload of a UDP datagram.
33 *
34 */
35#define FR_BIO_FD_MAX_DATAGRAM (65535)
36
37/** Our FD bio structure.
38 *
39 */
40typedef struct fr_bio_fd_s {
42
44
45 struct sockaddr_storage remote_sockaddr; //!< for connected UDP sockets.
47
48 struct {
49 fr_bio_callback_t success; //!< for fr_bio_fd_connect()
50 fr_bio_callback_t error; //!< for fr_bio_fd_connect()
51 fr_bio_callback_t timeout; //!< for fr_bio_fd_connect()
52 fr_event_list_t *el; //!< for fr_bio_fd_connect()
53 fr_timer_t *ev; //!< for fr_bio_fd_connect()
55
56 uint8_t *accept_buffer; //!< A LISTEN datagram bio reads datagrams into this buffer, which is
57 ///< allocated once by fr_bio_fd_init_listen().
58 uint8_t *first_datagram; //!< The datagram which fr_bio_fd_accept() read to name the peer.
59 ///< Only fr_bio_fd_read_first_datagram() reads it.
60 size_t first_datagram_len; //!< Length of #first_datagram.
61
62 int max_tries; //!< how many times we retry on EINTR
63 size_t offset; //!< where #fr_bio_fd_packet_ctx_t is stored
64
65#if defined(IP_PKTINFO) || defined(IP_RECVDSTADDR) || defined(IPV6_PKTINFO)
66 struct iovec iov; //!< for recvfromto
67 struct msghdr msgh; //!< for recvfromto
68
69 /*
70 * A received packet can carry two control messages: the destination address, and the
71 * receive timestamp that fr_bio_fd_common_datagram() enables. If cbuf is too small for
72 * both control messages, then the kernel sets MSG_CTRUNC, and fd_fd_recvfromto_common()
73 * drops the packet.
74 */
75 uint8_t cbuf[CMSG_SPACE(sizeof(struct in6_pktinfo)) +
76 CMSG_SPACE(sizeof(union { struct timespec ts; struct timeval tv; }))]; //!< for recvfromto and sendfromto
77#endif
79
80#define fr_bio_fd_packet_ctx(_my, _packet_ctx) ((fr_bio_fd_packet_ctx_t *) (((uint8_t *) _packet_ctx) + _my->offset))
81
82int fr_filename_to_sockaddr(struct sockaddr_un *sun, socklen_t *sunlen, char const *filename) CC_HINT(nonnull);
83
85
87
89
91
93
void(* fr_bio_callback_t)(fr_bio_t *bio)
Definition base.h:86
#define RCSIDH(h, id)
Definition build.h:604
Run-time status of the socket.
Definition fd.h:144
socklen_t remote_sockaddr_len
Definition fd_priv.h:46
struct fr_bio_fd_s::@18 connect
int fr_bio_fd_unix_shutdown(fr_bio_t *bio)
Remove the Unix domain socket which this bio created.
Definition fd_open.c:499
size_t offset
where fr_bio_fd_packet_ctx_t is stored
Definition fd_priv.h:63
int fr_bio_fd_socket_name(fr_bio_fd_t *my)
Definition fd.c:714
fr_bio_fd_info_t info
Definition fd_priv.h:43
int max_tries
how many times we retry on EINTR
Definition fd_priv.h:62
int fr_bio_fd_init_connected(fr_bio_fd_t *my)
Definition fd.c:930
void fr_bio_fd_name(fr_bio_fd_t *my)
Set the name of an FD BIO.
Definition fd_open.c:897
int fr_filename_to_sockaddr(struct sockaddr_un *sun, socklen_t *sunlen, char const *filename)
Definition fd.c:696
int fr_bio_fd_init_listen(fr_bio_fd_t *my)
Definition fd.c:1026
uint8_t * first_datagram
The datagram which fr_bio_fd_accept() read to name the peer.
Definition fd_priv.h:58
uint8_t * accept_buffer
A LISTEN datagram bio reads datagrams into this buffer, which is allocated once by fr_bio_fd_init_lis...
Definition fd_priv.h:56
int fr_bio_fd_init_common(fr_bio_fd_t *my)
Definition fd.c:985
struct fr_bio_fd_s fr_bio_fd_t
Our FD bio structure.
size_t first_datagram_len
Length of first_datagram.
Definition fd_priv.h:60
struct sockaddr_storage remote_sockaddr
for connected UDP sockets.
Definition fd_priv.h:45
Our FD bio structure.
Definition fd_priv.h:40
Stores all information relating to an event list.
Definition event.c:375
unsigned char uint8_t
A timer event.
Definition timer.c:83
static fr_event_list_t * el
int nonnull(2, 5))