From 10a2d7d172af0e3c275311b6fa7826789cc3a32b Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Mon, 16 Dec 2024 09:23:04 +0100 Subject: [PATCH] add INVALID type, and auto-set from configuration --- src/lib/bio/fd.c | 3 +++ src/lib/bio/fd.h | 1 + src/lib/bio/fd_config.c | 2 +- src/lib/bio/fd_open.c | 13 +++++++++++++ src/lib/bio/network.c | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/lib/bio/fd.c b/src/lib/bio/fd.c index 38ebc62f7d84b..d265edeb0d383 100644 --- a/src/lib/bio/fd.c +++ b/src/lib/bio/fd.c @@ -1364,6 +1364,9 @@ int fr_bio_fd_write_only(fr_bio_t *bio) fr_bio_fd_t *my = talloc_get_type_abort(bio, fr_bio_fd_t); switch (my->info.type) { + case FR_BIO_FD_INVALID: + return -1; + case FR_BIO_FD_UNCONNECTED: if (my->info.socket.type != SOCK_DGRAM) { fr_strerror_const("Only datagram sockets can be marked 'write-only'"); diff --git a/src/lib/bio/fd.h b/src/lib/bio/fd.h index e6f7c18d3cd52..fc945a89844d2 100644 --- a/src/lib/bio/fd.h +++ b/src/lib/bio/fd.h @@ -61,6 +61,7 @@ typedef enum { } fr_bio_fd_state_t; typedef enum { + FR_BIO_FD_INVALID, //!< not set FR_BIO_FD_UNCONNECTED, //!< unconnected UDP / datagram only // updates #fr_bio_fd_packet_ctx_t for reads, // uses #fr_bio_fd_packet_ctx_t for writes diff --git a/src/lib/bio/fd_config.c b/src/lib/bio/fd_config.c index c773bb93c088c..b458be89378dc 100644 --- a/src/lib/bio/fd_config.c +++ b/src/lib/bio/fd_config.c @@ -201,7 +201,7 @@ static int client_transport_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF { fr_bio_fd_config_t *fd_config = parent; - fd_config->type = FR_BIO_FD_CONNECTED; + if (fd_config->type == FR_BIO_FD_INVALID) fd_config->type = FR_BIO_FD_CONNECTED; return common_transport_parse(ctx, out, parent, ci, rule, client_transport_names, client_transport_names_len); diff --git a/src/lib/bio/fd_open.c b/src/lib/bio/fd_open.c index e74d3f2863c3b..fc42ba254b3b2 100644 --- a/src/lib/bio/fd_open.c +++ b/src/lib/bio/fd_open.c @@ -724,6 +724,9 @@ static void fr_bio_fd_name(fr_bio_fd_t *my) fr_bio_fd_config_t const *cfg = my->info.cfg; switch (my->info.type) { + case FR_BIO_FD_INVALID: + return; + case FR_BIO_FD_UNCONNECTED: fr_assert(cfg->socket_type == SOCK_DGRAM); @@ -830,6 +833,10 @@ int fr_bio_fd_check_config(fr_bio_fd_config_t const *cfg) * */ switch (cfg->type) { + case FR_BIO_FD_INVALID: + fr_strerror_const("No connection type was specified"); + return -1; + case FR_BIO_FD_CONNECTED: /* * Ensure that we have a destination address. @@ -910,6 +917,9 @@ int fr_bio_fd_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) * */ switch (cfg->type) { + case FR_BIO_FD_INVALID: + return -1; + case FR_BIO_FD_CONNECTED: /* * No source specified, just bootstrap it from the destination. @@ -1088,6 +1098,9 @@ int fr_bio_fd_open(fr_bio_t *bio, fr_bio_fd_config_t const *cfg) * / write functions. */ switch (cfg->type) { + case FR_BIO_FD_INVALID: + return -1; + /* * Unconnected UDP or datagram AF_LOCAL server sockets. */ diff --git a/src/lib/bio/network.c b/src/lib/bio/network.c index 018cec168a29e..50c1a9020f440 100644 --- a/src/lib/bio/network.c +++ b/src/lib/bio/network.c @@ -132,6 +132,7 @@ fr_bio_t *fr_bio_network_alloc(TALLOC_CTX *ctx, fr_ipaddr_t const *allow, fr_ipa case FR_BIO_FD_UNCONNECTED: break; + case FR_BIO_FD_INVALID: case FR_BIO_FD_CONNECTED: case FR_BIO_FD_ACCEPTED: return NULL;