From: Alan T. DeKok Date: Thu, 16 May 2024 13:13:26 +0000 (-0400) Subject: move pasue / resume callbacks to client config structure X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fefa22958030849f87f21e356c8e894461cec91f;p=thirdparty%2Ffreeradius-server.git move pasue / resume callbacks to client config structure --- diff --git a/src/bin/radclient-ng.c b/src/bin/radclient-ng.c index 384a71fa864..ff8ab2b3de2 100644 --- a/src/bin/radclient-ng.c +++ b/src/bin/radclient-ng.c @@ -1686,6 +1686,15 @@ int main(int argc, char **argv) fr_exit_now(1); } + /* + * Set callbacks so that the socket is automatically + * paused or resumed when the socket becomes writeable. + */ + client_config.pause_resume_cfg = (fr_bio_packet_cb_funcs_t) { + .write_blocked = client_bio_write_pause, + .write_resume = client_bio_write_resume, + }; + /* * Open the RADIUS client bio, and then get the information associated with it. */ @@ -1695,15 +1704,6 @@ int main(int argc, char **argv) fr_exit_now(1); } - /* - * Set callbacks so that the socket is automatically - * paused or resumed when the socket becomes writeable. - */ - (void) fr_radius_client_bio_cb_set(client_bio, &(fr_bio_packet_cb_funcs_t) { - .write_blocked = client_bio_write_pause, - .write_resume = client_bio_write_resume, - }); - client_info = fr_radius_client_bio_info(client_bio); fr_assert(client_info != NULL); diff --git a/src/protocols/radius/client.c b/src/protocols/radius/client.c index 3e22b799eba..f48cb6cdcc4 100644 --- a/src/protocols/radius/client.c +++ b/src/protocols/radius/client.c @@ -90,6 +90,13 @@ fr_radius_client_fd_bio_t *fr_radius_client_fd_bio_alloc(TALLOC_CTX *ctx, size_t */ my->fd->uctx = my; + /* + * Set up read / write blocked / resume callbacks. + */ + if (cfg->pause_resume_cfg.write_blocked || cfg->pause_resume_cfg.read_blocked) { + fr_radius_client_bio_cb_set((fr_bio_packet_t *) my, &cfg->pause_resume_cfg); + } + my->info.fd_info = fr_bio_fd_info(my->fd); fr_assert(my->info.fd_info != NULL); @@ -551,6 +558,12 @@ int fr_radius_client_bio_cb_set(fr_bio_packet_t *bio, fr_bio_packet_cb_funcs_t c fr_radius_client_fd_bio_t *my = talloc_get_type_abort(bio, fr_radius_client_fd_bio_t); fr_bio_cb_funcs_t bio_cb = {}; + /* + * If we have a "blocked" function, we must have a "resume" function, and vice versa. + */ + fr_assert((cb->write_blocked != NULL) == (cb->write_resume != NULL)); + fr_assert((cb->read_blocked != NULL) == (cb->read_resume != NULL)); + #undef SET #define SET(_x) if (cb->_x) bio_cb._x = fr_bio_ ## _x diff --git a/src/protocols/radius/client.h b/src/protocols/radius/client.h index 7c067144470..a995ca8fc1a 100644 --- a/src/protocols/radius/client.h +++ b/src/protocols/radius/client.h @@ -38,6 +38,8 @@ typedef struct { fr_bio_retry_config_t retry_cfg; + fr_bio_packet_cb_funcs_t pause_resume_cfg; + bool outgoing[FR_RADIUS_CODE_MAX]; //!< allowed outgoing packet types fr_retry_config_t retry[FR_RADIUS_CODE_MAX]; //!< default retry configuration for each packet type