Skip to content

Commit

Permalink
add INVALID type, and auto-set from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Dec 16, 2024
1 parent cdc340b commit 10a2d7d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib/bio/fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down
1 change: 1 addition & 0 deletions src/lib/bio/fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/lib/bio/fd_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions src/lib/bio/fd_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions src/lib/bio/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 10a2d7d

Please sign in to comment.