]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add cfg to alloc routine, too
authorAlan T. DeKok <aland@freeradius.org>
Tue, 23 Jan 2024 13:04:17 +0000 (08:04 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 23 Jan 2024 13:06:46 +0000 (08:06 -0500)
src/lib/bio/fd.c
src/lib/bio/fd.h

index 8ca8c7bf9d286fc1a61d4ebcb9c89b3e0d335bd3..49bb7be9ac72846511aa82d2cf1ef9e4837907d0 100644 (file)
@@ -917,15 +917,13 @@ int fr_bio_fd_init_accept(fr_bio_fd_t *my)
  *
  *  @param ctx         the talloc ctx
  *  @param cb          callbacks
- *  @param sock                structure holding socket information
- *                     src_ip is always *our* IP.  dst_ip is always *their* IP.
- *  @param type                type of the bio
+ *  @param cfg         structure holding configuration information
  *  @param offset      for datagram sockets, where #fr_bio_fd_packet_ctx_t is stored
  *  @return
  *     - NULL on error, memory allocation failed
  *     - !NULL the bio
  */
-fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_socket_t const *sock, fr_bio_fd_type_t type, size_t offset)
+fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_bio_fd_config_t const *cfg, size_t offset)
 {
        fr_bio_fd_t *my;
 
@@ -936,27 +934,15 @@ fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_socket_t co
        my->max_tries = 4;
        my->offset = offset;
 
-       if (sock) {
-               my->info.type = type;
-               my->info.state = FR_BIO_FD_STATE_CLOSED;
-
-               if ((my->info.socket.fd >= 0) &&
-                   (fr_bio_fd_init(&my->bio, sock) < 0)) {
-                       talloc_free(my);
-                       return NULL;
-               }
-       } else {
+       if (!cfg) {
                /*
-                *      We can allocate a "place-holder" FD bio, and then later fill it in with
-                *      fr_bio_fd_init().
-                *
-                *      @todo - maybe just use fr_bio_fd_open() all of the time?
+                *      Add place-holder information.
                 */
                my->info = (fr_bio_fd_info_t) {
                        .socket = {
                                .af = AF_UNSPEC,
                        },
-                       .type = type,
+                       .type = FR_BIO_FD_UNCONNECTED,
                        .read_blocked = true,
                        .write_blocked = true,
                        .eof = false,
@@ -965,6 +951,13 @@ fr_bio_t *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_socket_t co
 
                my->bio.read = fr_bio_eof_read;
                my->bio.write = fr_bio_null_write;
+       } else {
+               my->info.state = FR_BIO_FD_STATE_CLOSED;
+
+               if (fr_bio_fd_socket_open(&my->bio, cfg) < 0) {
+                       talloc_free(my);
+                       return NULL;
+               }
        }
 
        talloc_set_destructor(my, fr_bio_fd_destructor);
index bb3c411a579f9b10c562654f2ad4864310fe37c1..933a0cb0f291606c601f40ba3e9f6d8e784f3bb2 100644 (file)
@@ -107,7 +107,7 @@ typedef struct {
        fr_bio_fd_config_t const *cfg;  //!< so we know what was asked, vs what was granted.
 } fr_bio_fd_info_t;
 
-fr_bio_t       *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_socket_t const *sock, fr_bio_fd_type_t type, size_t offset) CC_HINT(nonnull(1));
+fr_bio_t       *fr_bio_fd_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_bio_fd_config_t const *cfg, size_t offset) CC_HINT(nonnull(1));
 
 int            fr_bio_fd_close(fr_bio_t *bio) CC_HINT(nonnull);