From: Alan T. DeKok Date: Tue, 19 Mar 2024 00:40:37 +0000 (+1000) Subject: add fr_radius_client_bio_connect() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d424afaf4d2e81aef93cd7d18b60bd548bddd5aa;p=thirdparty%2Ffreeradius-server.git add fr_radius_client_bio_connect() which will do TCP (or eventually TLS) connected sockets --- diff --git a/src/protocols/radius/client.c b/src/protocols/radius/client.c index 1d911436d6a..16bc13226cc 100644 --- a/src/protocols/radius/client.c +++ b/src/protocols/radius/client.c @@ -329,3 +329,49 @@ fr_bio_t *fr_radius_client_bio_get_fd(fr_bio_packet_t *bio) return my->fd; } + +/** Try to connect a socket. + * + * Calls fr_bio_fd_connect() + * + * @param bio the packet bio + * @return + * - 0 for "connected, can continue" + * - fr_bio_error(IO_WOULD_BLOCK) for "not yet connected, please try again" + * - <0 for other fr_bio_error() + * + */ +int fr_radius_client_bio_connect(fr_bio_packet_t *bio) +{ + fr_radius_client_fd_bio_t *my = talloc_get_type_abort(bio, fr_radius_client_fd_bio_t); + + switch (my->fd_info->type) { + default: + fr_strerror_const("Invalid RADIUS client bio for connect"); + return fr_bio_error(GENERIC); + + case FR_BIO_FD_UNCONNECTED: + return 0; + + case FR_BIO_FD_CONNECTED: + break; + } + + switch(my->fd_info->state) { + case FR_BIO_FD_STATE_INVALID: + fr_strerror_const("Invalid RADIUS client bio state"); + return fr_bio_error(GENERIC); + + case FR_BIO_FD_STATE_CLOSED: + fr_strerror_const("RADIUS client bio is closed"); + return fr_bio_error(GENERIC); + + case FR_BIO_FD_STATE_OPEN: + return 0; + + case FR_BIO_FD_STATE_CONNECTING: + break; + } + + return fr_bio_fd_connect(my->fd); +} diff --git a/src/protocols/radius/client.h b/src/protocols/radius/client.h index df5a9c6c542..28bb4003d0d 100644 --- a/src/protocols/radius/client.h +++ b/src/protocols/radius/client.h @@ -36,11 +36,13 @@ typedef struct { fr_bio_retry_config_t retry_cfg; - bool allowed[FR_RADIUS_CODE_MAX]; //!< allowed outgoing packet types + bool allowed[FR_RADIUS_CODE_MAX]; //!< allowed outgoing packet types - fr_retry_config_t retry[FR_RADIUS_CODE_MAX]; //!< default retry configuration for each packet type + fr_retry_config_t retry[FR_RADIUS_CODE_MAX]; //!< default retry configuration for each packet type } fr_radius_client_config_t; fr_bio_packet_t *fr_radius_client_bio_alloc(TALLOC_CTX *ctx, fr_radius_client_config_t *cfg, fr_bio_fd_config_t const *fd_cfg) CC_HINT(nonnull); -fr_bio_t *fr_radius_client_bio_get_fd(fr_bio_packet_t *bio); +fr_bio_t *fr_radius_client_bio_get_fd(fr_bio_packet_t *bio) CC_HINT(nonnull); + +int fr_radius_client_bio_connect(fr_bio_packet_t *bio) CC_HINT(nonnull);