Home | History | Annotate | Line # | Download | only in quic
      1      1.1  christos /*
      2      1.1  christos  * Copyright 2022-2025 The OpenSSL Project Authors. All Rights Reserved.
      3      1.1  christos  *
      4      1.1  christos  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5      1.1  christos  * this file except in compliance with the License.  You can obtain a copy
      6      1.1  christos  * in the file LICENSE in the source distribution or at
      7      1.1  christos  * https://www.openssl.org/source/license.html
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos #include "internal/quic_demux.h"
     11      1.1  christos #include "internal/quic_wire_pkt.h"
     12      1.1  christos #include "internal/common.h"
     13      1.1  christos #include <openssl/lhash.h>
     14      1.1  christos #include <openssl/err.h>
     15      1.1  christos 
     16  1.1.1.2  christos #define URXE_DEMUX_STATE_FREE 0 /* on urx_free list */
     17  1.1.1.2  christos #define URXE_DEMUX_STATE_PENDING 1 /* on urx_pending list */
     18  1.1.1.2  christos #define URXE_DEMUX_STATE_ISSUED 2 /* on neither list */
     19      1.1  christos 
     20  1.1.1.2  christos #define DEMUX_MAX_MSGS_PER_CALL 32
     21      1.1  christos 
     22  1.1.1.2  christos #define DEMUX_DEFAULT_MTU 1500
     23      1.1  christos 
     24      1.1  christos struct quic_demux_st {
     25      1.1  christos     /* The underlying transport BIO with datagram semantics. */
     26  1.1.1.2  christos     BIO *net_bio;
     27      1.1  christos 
     28      1.1  christos     /*
     29      1.1  christos      * QUIC short packets do not contain the length of the connection ID field,
     30      1.1  christos      * therefore it must be known contextually. The demuxer requires connection
     31      1.1  christos      * IDs of the same length to be used for all incoming packets.
     32      1.1  christos      */
     33  1.1.1.2  christos     size_t short_conn_id_len;
     34      1.1  christos 
     35      1.1  christos     /*
     36      1.1  christos      * Our current understanding of the upper bound on an incoming datagram size
     37      1.1  christos      * in bytes.
     38      1.1  christos      */
     39  1.1.1.2  christos     size_t mtu;
     40      1.1  christos 
     41      1.1  christos     /* The datagram_id to use for the next datagram we receive. */
     42  1.1.1.2  christos     uint64_t next_datagram_id;
     43      1.1  christos 
     44      1.1  christos     /* Time retrieval callback. */
     45  1.1.1.2  christos     OSSL_TIME (*now)(void *arg);
     46  1.1.1.2  christos     void *now_arg;
     47      1.1  christos 
     48      1.1  christos     /* The default packet handler, if any. */
     49  1.1.1.2  christos     ossl_quic_demux_cb_fn *default_cb;
     50  1.1.1.2  christos     void *default_cb_arg;
     51      1.1  christos 
     52      1.1  christos     /*
     53      1.1  christos      * List of URXEs which are not currently in use (i.e., not filled with
     54      1.1  christos      * unconsumed data). These are moved to the pending list as they are filled.
     55      1.1  christos      */
     56  1.1.1.2  christos     QUIC_URXE_LIST urx_free;
     57      1.1  christos 
     58      1.1  christos     /*
     59      1.1  christos      * List of URXEs which are filled with received encrypted data. These are
     60      1.1  christos      * removed from this list as we invoke the callbacks for each of them. They
     61      1.1  christos      * are then not on any list managed by us; we forget about them until our
     62      1.1  christos      * user calls ossl_quic_demux_release_urxe to return the URXE to us, at
     63      1.1  christos      * which point we add it to the free list.
     64      1.1  christos      */
     65  1.1.1.2  christos     QUIC_URXE_LIST urx_pending;
     66      1.1  christos 
     67      1.1  christos     /* Whether to use local address support. */
     68  1.1.1.2  christos     char use_local_addr;
     69      1.1  christos };
     70      1.1  christos 
     71      1.1  christos QUIC_DEMUX *ossl_quic_demux_new(BIO *net_bio,
     72  1.1.1.2  christos     size_t short_conn_id_len,
     73  1.1.1.2  christos     OSSL_TIME (*now)(void *arg),
     74  1.1.1.2  christos     void *now_arg)
     75      1.1  christos {
     76      1.1  christos     QUIC_DEMUX *demux;
     77      1.1  christos 
     78      1.1  christos     demux = OPENSSL_zalloc(sizeof(QUIC_DEMUX));
     79      1.1  christos     if (demux == NULL)
     80      1.1  christos         return NULL;
     81      1.1  christos 
     82  1.1.1.2  christos     demux->net_bio = net_bio;
     83  1.1.1.2  christos     demux->short_conn_id_len = short_conn_id_len;
     84      1.1  christos     /* We update this if possible when we get a BIO. */
     85  1.1.1.2  christos     demux->mtu = DEMUX_DEFAULT_MTU;
     86  1.1.1.2  christos     demux->now = now;
     87  1.1.1.2  christos     demux->now_arg = now_arg;
     88      1.1  christos 
     89      1.1  christos     if (net_bio != NULL
     90      1.1  christos         && BIO_dgram_get_local_addr_cap(net_bio)
     91      1.1  christos         && BIO_dgram_set_local_addr_enable(net_bio, 1))
     92      1.1  christos         demux->use_local_addr = 1;
     93      1.1  christos 
     94      1.1  christos     return demux;
     95      1.1  christos }
     96      1.1  christos 
     97      1.1  christos static void demux_free_urxl(QUIC_URXE_LIST *l)
     98      1.1  christos {
     99      1.1  christos     QUIC_URXE *e, *enext;
    100      1.1  christos 
    101      1.1  christos     for (e = ossl_list_urxe_head(l); e != NULL; e = enext) {
    102      1.1  christos         enext = ossl_list_urxe_next(e);
    103      1.1  christos         ossl_list_urxe_remove(l, e);
    104      1.1  christos         OPENSSL_free(e);
    105      1.1  christos     }
    106      1.1  christos }
    107      1.1  christos 
    108      1.1  christos void ossl_quic_demux_free(QUIC_DEMUX *demux)
    109      1.1  christos {
    110      1.1  christos     if (demux == NULL)
    111      1.1  christos         return;
    112      1.1  christos 
    113      1.1  christos     /* Free all URXEs we are holding. */
    114      1.1  christos     demux_free_urxl(&demux->urx_free);
    115      1.1  christos     demux_free_urxl(&demux->urx_pending);
    116      1.1  christos 
    117      1.1  christos     OPENSSL_free(demux);
    118      1.1  christos }
    119      1.1  christos 
    120      1.1  christos void ossl_quic_demux_set_bio(QUIC_DEMUX *demux, BIO *net_bio)
    121      1.1  christos {
    122      1.1  christos     unsigned int mtu;
    123      1.1  christos 
    124      1.1  christos     demux->net_bio = net_bio;
    125      1.1  christos 
    126      1.1  christos     if (net_bio != NULL) {
    127      1.1  christos         /*
    128      1.1  christos          * Try to determine our MTU if possible. The BIO is not required to
    129      1.1  christos          * support this, in which case we remain at the last known MTU, or our
    130      1.1  christos          * initial default.
    131      1.1  christos          */
    132      1.1  christos         mtu = BIO_dgram_get_mtu(net_bio);
    133      1.1  christos         if (mtu >= QUIC_MIN_INITIAL_DGRAM_LEN)
    134      1.1  christos             ossl_quic_demux_set_mtu(demux, mtu); /* best effort */
    135      1.1  christos     }
    136      1.1  christos }
    137      1.1  christos 
    138      1.1  christos int ossl_quic_demux_set_mtu(QUIC_DEMUX *demux, unsigned int mtu)
    139      1.1  christos {
    140      1.1  christos     if (mtu < QUIC_MIN_INITIAL_DGRAM_LEN)
    141      1.1  christos         return 0;
    142      1.1  christos 
    143      1.1  christos     demux->mtu = mtu;
    144      1.1  christos     return 1;
    145      1.1  christos }
    146      1.1  christos 
    147      1.1  christos void ossl_quic_demux_set_default_handler(QUIC_DEMUX *demux,
    148  1.1.1.2  christos     ossl_quic_demux_cb_fn *cb,
    149  1.1.1.2  christos     void *cb_arg)
    150      1.1  christos {
    151  1.1.1.2  christos     demux->default_cb = cb;
    152  1.1.1.2  christos     demux->default_cb_arg = cb_arg;
    153      1.1  christos }
    154      1.1  christos 
    155      1.1  christos static QUIC_URXE *demux_alloc_urxe(size_t alloc_len)
    156      1.1  christos {
    157      1.1  christos     QUIC_URXE *e;
    158      1.1  christos 
    159      1.1  christos     if (alloc_len >= SIZE_MAX - sizeof(QUIC_URXE))
    160      1.1  christos         return NULL;
    161      1.1  christos 
    162      1.1  christos     e = OPENSSL_malloc(sizeof(QUIC_URXE) + alloc_len);
    163      1.1  christos     if (e == NULL)
    164      1.1  christos         return NULL;
    165      1.1  christos 
    166      1.1  christos     ossl_list_urxe_init_elem(e);
    167  1.1.1.2  christos     e->alloc_len = alloc_len;
    168  1.1.1.2  christos     e->data_len = 0;
    169      1.1  christos     return e;
    170      1.1  christos }
    171      1.1  christos 
    172      1.1  christos static QUIC_URXE *demux_resize_urxe(QUIC_DEMUX *demux, QUIC_URXE *e,
    173  1.1.1.2  christos     size_t new_alloc_len)
    174      1.1  christos {
    175      1.1  christos     QUIC_URXE *e2, *prev;
    176      1.1  christos 
    177      1.1  christos     if (!ossl_assert(e->demux_state == URXE_DEMUX_STATE_FREE))
    178      1.1  christos         /* Never attempt to resize a URXE which is not on the free list. */
    179      1.1  christos         return NULL;
    180      1.1  christos 
    181      1.1  christos     prev = ossl_list_urxe_prev(e);
    182      1.1  christos     ossl_list_urxe_remove(&demux->urx_free, e);
    183      1.1  christos 
    184  1.1.1.2  christos     if (new_alloc_len >= SIZE_MAX - sizeof(QUIC_URXE))
    185  1.1.1.2  christos         return NULL;
    186  1.1.1.2  christos 
    187      1.1  christos     e2 = OPENSSL_realloc(e, sizeof(QUIC_URXE) + new_alloc_len);
    188      1.1  christos     if (e2 == NULL) {
    189      1.1  christos         /* Failed to resize, abort. */
    190      1.1  christos         if (prev == NULL)
    191      1.1  christos             ossl_list_urxe_insert_head(&demux->urx_free, e);
    192      1.1  christos         else
    193      1.1  christos             ossl_list_urxe_insert_after(&demux->urx_free, prev, e);
    194      1.1  christos 
    195      1.1  christos         return NULL;
    196      1.1  christos     }
    197      1.1  christos 
    198      1.1  christos     if (prev == NULL)
    199      1.1  christos         ossl_list_urxe_insert_head(&demux->urx_free, e2);
    200      1.1  christos     else
    201      1.1  christos         ossl_list_urxe_insert_after(&demux->urx_free, prev, e2);
    202      1.1  christos 
    203      1.1  christos     e2->alloc_len = new_alloc_len;
    204      1.1  christos     return e2;
    205      1.1  christos }
    206      1.1  christos 
    207      1.1  christos static QUIC_URXE *demux_reserve_urxe(QUIC_DEMUX *demux, QUIC_URXE *e,
    208  1.1.1.2  christos     size_t alloc_len)
    209      1.1  christos {
    210      1.1  christos     return e->alloc_len < alloc_len ? demux_resize_urxe(demux, e, alloc_len) : e;
    211      1.1  christos }
    212      1.1  christos 
    213      1.1  christos static int demux_ensure_free_urxe(QUIC_DEMUX *demux, size_t min_num_free)
    214      1.1  christos {
    215      1.1  christos     QUIC_URXE *e;
    216      1.1  christos 
    217      1.1  christos     while (ossl_list_urxe_num(&demux->urx_free) < min_num_free) {
    218      1.1  christos         e = demux_alloc_urxe(demux->mtu);
    219      1.1  christos         if (e == NULL)
    220      1.1  christos             return 0;
    221      1.1  christos 
    222      1.1  christos         ossl_list_urxe_insert_tail(&demux->urx_free, e);
    223      1.1  christos         e->demux_state = URXE_DEMUX_STATE_FREE;
    224      1.1  christos     }
    225      1.1  christos 
    226      1.1  christos     return 1;
    227      1.1  christos }
    228      1.1  christos 
    229      1.1  christos /*
    230      1.1  christos  * Receive datagrams from network, placing them into URXEs.
    231      1.1  christos  *
    232      1.1  christos  * Returns 1 on success or 0 on failure.
    233      1.1  christos  *
    234      1.1  christos  * Precondition: at least one URXE is free
    235      1.1  christos  * Precondition: there are no pending URXEs
    236      1.1  christos  */
    237      1.1  christos static int demux_recv(QUIC_DEMUX *demux)
    238      1.1  christos {
    239      1.1  christos     BIO_MSG msg[DEMUX_MAX_MSGS_PER_CALL];
    240      1.1  christos     size_t rd, i;
    241      1.1  christos     QUIC_URXE *urxe = ossl_list_urxe_head(&demux->urx_free), *unext;
    242      1.1  christos     OSSL_TIME now;
    243      1.1  christos 
    244      1.1  christos     /* This should never be called when we have any pending URXE. */
    245      1.1  christos     assert(ossl_list_urxe_head(&demux->urx_pending) == NULL);
    246      1.1  christos     assert(urxe->demux_state == URXE_DEMUX_STATE_FREE);
    247      1.1  christos 
    248      1.1  christos     if (demux->net_bio == NULL)
    249      1.1  christos         /*
    250      1.1  christos          * If no BIO is plugged in, treat this as no datagram being available.
    251      1.1  christos          */
    252      1.1  christos         return QUIC_DEMUX_PUMP_RES_TRANSIENT_FAIL;
    253      1.1  christos 
    254      1.1  christos     /*
    255      1.1  christos      * Opportunistically receive as many messages as possible in a single
    256      1.1  christos      * syscall, determined by how many free URXEs are available.
    257      1.1  christos      */
    258      1.1  christos     for (i = 0; i < (ossl_ssize_t)OSSL_NELEM(msg);
    259  1.1.1.2  christos         ++i, urxe = ossl_list_urxe_next(urxe)) {
    260      1.1  christos         if (urxe == NULL) {
    261      1.1  christos             /* We need at least one URXE to receive into. */
    262      1.1  christos             if (!ossl_assert(i > 0))
    263      1.1  christos                 return QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL;
    264      1.1  christos 
    265      1.1  christos             break;
    266      1.1  christos         }
    267      1.1  christos 
    268      1.1  christos         /* Ensure the URXE is big enough. */
    269      1.1  christos         urxe = demux_reserve_urxe(demux, urxe, demux->mtu);
    270      1.1  christos         if (urxe == NULL)
    271      1.1  christos             /* Allocation error, fail. */
    272      1.1  christos             return QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL;
    273      1.1  christos 
    274      1.1  christos         /* Ensure we zero any fields added to BIO_MSG at a later date. */
    275      1.1  christos         memset(&msg[i], 0, sizeof(BIO_MSG));
    276  1.1.1.2  christos         msg[i].data = ossl_quic_urxe_data(urxe);
    277      1.1  christos         msg[i].data_len = urxe->alloc_len;
    278  1.1.1.2  christos         msg[i].peer = &urxe->peer;
    279      1.1  christos         BIO_ADDR_clear(&urxe->peer);
    280      1.1  christos         if (demux->use_local_addr)
    281      1.1  christos             msg[i].local = &urxe->local;
    282      1.1  christos         else
    283      1.1  christos             BIO_ADDR_clear(&urxe->local);
    284      1.1  christos     }
    285      1.1  christos 
    286      1.1  christos     ERR_set_mark();
    287      1.1  christos     if (!BIO_recvmmsg(demux->net_bio, msg, sizeof(BIO_MSG), i, 0, &rd)) {
    288      1.1  christos         if (BIO_err_is_non_fatal(ERR_peek_last_error())) {
    289      1.1  christos             /* Transient error, clear the error and stop. */
    290      1.1  christos             ERR_pop_to_mark();
    291      1.1  christos             return QUIC_DEMUX_PUMP_RES_TRANSIENT_FAIL;
    292      1.1  christos         } else {
    293      1.1  christos             /* Non-transient error, do not clear the error. */
    294      1.1  christos             ERR_clear_last_mark();
    295      1.1  christos             return QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL;
    296      1.1  christos         }
    297      1.1  christos     }
    298      1.1  christos 
    299      1.1  christos     ERR_clear_last_mark();
    300      1.1  christos     now = demux->now != NULL ? demux->now(demux->now_arg) : ossl_time_zero();
    301      1.1  christos 
    302      1.1  christos     urxe = ossl_list_urxe_head(&demux->urx_free);
    303      1.1  christos     for (i = 0; i < rd; ++i, urxe = unext) {
    304      1.1  christos         unext = ossl_list_urxe_next(urxe);
    305      1.1  christos         /* Set URXE with actual length of received datagram. */
    306  1.1.1.2  christos         urxe->data_len = msg[i].data_len;
    307      1.1  christos         /* Time we received datagram. */
    308  1.1.1.2  christos         urxe->time = now;
    309  1.1.1.2  christos         urxe->datagram_id = demux->next_datagram_id++;
    310      1.1  christos         /* Move from free list to pending list. */
    311      1.1  christos         ossl_list_urxe_remove(&demux->urx_free, urxe);
    312      1.1  christos         ossl_list_urxe_insert_tail(&demux->urx_pending, urxe);
    313      1.1  christos         urxe->demux_state = URXE_DEMUX_STATE_PENDING;
    314      1.1  christos     }
    315      1.1  christos 
    316      1.1  christos     return QUIC_DEMUX_PUMP_RES_OK;
    317      1.1  christos }
    318      1.1  christos 
    319      1.1  christos /* Extract destination connection ID from the first packet in a datagram. */
    320      1.1  christos static int demux_identify_conn_id(QUIC_DEMUX *demux,
    321  1.1.1.2  christos     QUIC_URXE *e,
    322  1.1.1.2  christos     QUIC_CONN_ID *dst_conn_id)
    323      1.1  christos {
    324      1.1  christos     return ossl_quic_wire_get_pkt_hdr_dst_conn_id(ossl_quic_urxe_data(e),
    325  1.1.1.2  christos         e->data_len,
    326  1.1.1.2  christos         demux->short_conn_id_len,
    327  1.1.1.2  christos         dst_conn_id);
    328      1.1  christos }
    329      1.1  christos 
    330      1.1  christos /*
    331      1.1  christos  * Process a single pending URXE.
    332      1.1  christos  * Returning 1 on success, 0 on failure.
    333      1.1  christos  */
    334      1.1  christos static int demux_process_pending_urxe(QUIC_DEMUX *demux, QUIC_URXE *e)
    335      1.1  christos {
    336      1.1  christos     QUIC_CONN_ID dst_conn_id;
    337      1.1  christos     int dst_conn_id_ok = 0;
    338      1.1  christos 
    339      1.1  christos     /* The next URXE we process should be at the head of the pending list. */
    340      1.1  christos     if (!ossl_assert(e == ossl_list_urxe_head(&demux->urx_pending)))
    341      1.1  christos         return 0;
    342      1.1  christos 
    343      1.1  christos     assert(e->demux_state == URXE_DEMUX_STATE_PENDING);
    344      1.1  christos 
    345      1.1  christos     /* Determine the DCID of the first packet in the datagram. */
    346      1.1  christos     dst_conn_id_ok = demux_identify_conn_id(demux, e, &dst_conn_id);
    347      1.1  christos 
    348      1.1  christos     ossl_list_urxe_remove(&demux->urx_pending, e);
    349      1.1  christos     if (demux->default_cb != NULL) {
    350      1.1  christos         /*
    351      1.1  christos          * Pass to default handler for routing. The URXE now belongs to the
    352      1.1  christos          * callback.
    353      1.1  christos          */
    354      1.1  christos         e->demux_state = URXE_DEMUX_STATE_ISSUED;
    355      1.1  christos         demux->default_cb(e, demux->default_cb_arg,
    356  1.1.1.2  christos             dst_conn_id_ok ? &dst_conn_id : NULL);
    357      1.1  christos     } else {
    358      1.1  christos         /* Discard. */
    359      1.1  christos         ossl_list_urxe_insert_tail(&demux->urx_free, e);
    360      1.1  christos         e->demux_state = URXE_DEMUX_STATE_FREE;
    361      1.1  christos     }
    362      1.1  christos 
    363      1.1  christos     return 1; /* keep processing pending URXEs */
    364      1.1  christos }
    365      1.1  christos 
    366      1.1  christos /* Process pending URXEs to generate callbacks. */
    367      1.1  christos static int demux_process_pending_urxl(QUIC_DEMUX *demux)
    368      1.1  christos {
    369      1.1  christos     QUIC_URXE *e;
    370      1.1  christos     int ret;
    371      1.1  christos 
    372      1.1  christos     while ((e = ossl_list_urxe_head(&demux->urx_pending)) != NULL)
    373      1.1  christos         if ((ret = demux_process_pending_urxe(demux, e)) <= 0)
    374      1.1  christos             return ret;
    375      1.1  christos 
    376      1.1  christos     return 1;
    377      1.1  christos }
    378      1.1  christos 
    379      1.1  christos /*
    380      1.1  christos  * Drain the pending URXE list, processing any pending URXEs by making their
    381      1.1  christos  * callbacks. If no URXEs are pending, a network read is attempted first.
    382      1.1  christos  */
    383      1.1  christos int ossl_quic_demux_pump(QUIC_DEMUX *demux)
    384      1.1  christos {
    385      1.1  christos     int ret;
    386      1.1  christos 
    387      1.1  christos     if (ossl_list_urxe_head(&demux->urx_pending) == NULL) {
    388      1.1  christos         ret = demux_ensure_free_urxe(demux, DEMUX_MAX_MSGS_PER_CALL);
    389      1.1  christos         if (ret != 1)
    390      1.1  christos             return QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL;
    391      1.1  christos 
    392      1.1  christos         ret = demux_recv(demux);
    393      1.1  christos         if (ret != QUIC_DEMUX_PUMP_RES_OK)
    394      1.1  christos             return ret;
    395      1.1  christos 
    396      1.1  christos         /*
    397      1.1  christos          * If demux_recv returned successfully, we should always have something.
    398      1.1  christos          */
    399      1.1  christos         assert(ossl_list_urxe_head(&demux->urx_pending) != NULL);
    400      1.1  christos     }
    401      1.1  christos 
    402      1.1  christos     if ((ret = demux_process_pending_urxl(demux)) <= 0)
    403      1.1  christos         return QUIC_DEMUX_PUMP_RES_PERMANENT_FAIL;
    404      1.1  christos 
    405      1.1  christos     return QUIC_DEMUX_PUMP_RES_OK;
    406      1.1  christos }
    407      1.1  christos 
    408      1.1  christos /* Artificially inject a packet into the demuxer for testing purposes. */
    409      1.1  christos int ossl_quic_demux_inject(QUIC_DEMUX *demux,
    410  1.1.1.2  christos     const unsigned char *buf,
    411  1.1.1.2  christos     size_t buf_len,
    412  1.1.1.2  christos     const BIO_ADDR *peer,
    413  1.1.1.2  christos     const BIO_ADDR *local)
    414      1.1  christos {
    415      1.1  christos     int ret;
    416      1.1  christos     QUIC_URXE *urxe;
    417      1.1  christos 
    418      1.1  christos     ret = demux_ensure_free_urxe(demux, 1);
    419      1.1  christos     if (ret != 1)
    420      1.1  christos         return 0;
    421      1.1  christos 
    422      1.1  christos     urxe = ossl_list_urxe_head(&demux->urx_free);
    423      1.1  christos 
    424      1.1  christos     assert(urxe->demux_state == URXE_DEMUX_STATE_FREE);
    425      1.1  christos 
    426      1.1  christos     urxe = demux_reserve_urxe(demux, urxe, buf_len);
    427      1.1  christos     if (urxe == NULL)
    428      1.1  christos         return 0;
    429      1.1  christos 
    430      1.1  christos     memcpy(ossl_quic_urxe_data(urxe), buf, buf_len);
    431      1.1  christos     urxe->data_len = buf_len;
    432      1.1  christos 
    433      1.1  christos     if (peer != NULL)
    434      1.1  christos         urxe->peer = *peer;
    435      1.1  christos     else
    436      1.1  christos         BIO_ADDR_clear(&urxe->peer);
    437      1.1  christos 
    438      1.1  christos     if (local != NULL)
    439      1.1  christos         urxe->local = *local;
    440      1.1  christos     else
    441      1.1  christos         BIO_ADDR_clear(&urxe->local);
    442      1.1  christos 
    443      1.1  christos     urxe->time
    444      1.1  christos         = demux->now != NULL ? demux->now(demux->now_arg) : ossl_time_zero();
    445      1.1  christos 
    446      1.1  christos     /* Move from free list to pending list. */
    447      1.1  christos     ossl_list_urxe_remove(&demux->urx_free, urxe);
    448      1.1  christos     urxe->datagram_id = demux->next_datagram_id++;
    449      1.1  christos     ossl_list_urxe_insert_tail(&demux->urx_pending, urxe);
    450      1.1  christos     urxe->demux_state = URXE_DEMUX_STATE_PENDING;
    451      1.1  christos 
    452      1.1  christos     return demux_process_pending_urxl(demux) > 0;
    453      1.1  christos }
    454      1.1  christos 
    455      1.1  christos /* Called by our user to return a URXE to the free list. */
    456      1.1  christos void ossl_quic_demux_release_urxe(QUIC_DEMUX *demux,
    457  1.1.1.2  christos     QUIC_URXE *e)
    458      1.1  christos {
    459      1.1  christos     assert(ossl_list_urxe_prev(e) == NULL && ossl_list_urxe_next(e) == NULL);
    460      1.1  christos     assert(e->demux_state == URXE_DEMUX_STATE_ISSUED);
    461      1.1  christos     ossl_list_urxe_insert_tail(&demux->urx_free, e);
    462      1.1  christos     e->demux_state = URXE_DEMUX_STATE_FREE;
    463      1.1  christos }
    464      1.1  christos 
    465      1.1  christos void ossl_quic_demux_reinject_urxe(QUIC_DEMUX *demux,
    466  1.1.1.2  christos     QUIC_URXE *e)
    467      1.1  christos {
    468      1.1  christos     assert(ossl_list_urxe_prev(e) == NULL && ossl_list_urxe_next(e) == NULL);
    469      1.1  christos     assert(e->demux_state == URXE_DEMUX_STATE_ISSUED);
    470      1.1  christos     ossl_list_urxe_insert_head(&demux->urx_pending, e);
    471      1.1  christos     e->demux_state = URXE_DEMUX_STATE_PENDING;
    472      1.1  christos }
    473      1.1  christos 
    474      1.1  christos int ossl_quic_demux_has_pending(const QUIC_DEMUX *demux)
    475      1.1  christos {
    476      1.1  christos     return ossl_list_urxe_head(&demux->urx_pending) != NULL;
    477      1.1  christos }
    478