Skip to content

Commit

Permalink
QUIC PORT: Formalise states of a port
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #22674)
  • Loading branch information
hlandau committed Dec 21, 2023
1 parent 963cf3a commit 0225d42
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/internal/quic_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ int ossl_quic_port_get_tx_init_dcid_len(const QUIC_PORT *port);
/* For testing use. While enabled, ticking is not performed. */
void ossl_quic_port_set_inhibit_tick(QUIC_PORT *port, int inhibit);

/* Returns 1 if the port is running/healthy, 0 if it has failed. */
int ossl_quic_port_is_running(const QUIC_PORT *port);

/*
* Events
* ======
Expand Down
22 changes: 19 additions & 3 deletions ssl/quic/quic_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ static int port_init(QUIC_PORT *port)
ossl_quic_reactor_init(&port->rtor, port_tick, port, ossl_time_zero());
port->rx_short_dcid_len = (unsigned char)rx_short_dcid_len;
port->tx_init_dcid_len = INIT_DCID_LEN;
port->state = QUIC_PORT_STATE_RUNNING;
return 1;

err:
Expand All @@ -109,6 +110,19 @@ static void port_cleanup(QUIC_PORT *port)
port->lcidm = NULL;
}

static void port_transition_failed(QUIC_PORT *port)
{
if (port->state == QUIC_PORT_STATE_FAILED)
return;

port->state = QUIC_PORT_STATE_FAILED;
}

int ossl_quic_port_is_running(const QUIC_PORT *port)
{
return port->state == QUIC_PORT_STATE_RUNNING;
}

QUIC_REACTOR *ossl_quic_port_get0_reactor(QUIC_PORT *port)
{
return &port->rtor;
Expand Down Expand Up @@ -438,6 +452,10 @@ static void port_default_packet_handler(QUIC_URXE *e, void *arg,
QUIC_PKT_HDR hdr;
QUIC_CHANNEL *ch = NULL, *new_ch = NULL;

/* Don't handle anything if we are no longer running. */
if (!ossl_quic_port_is_running(port))
goto undesirable;

if (dcid != NULL
&& ossl_quic_lcidm_lookup(port->lcidm, dcid, NULL,
(void **)&ch)) {
Expand All @@ -461,8 +479,6 @@ static void port_default_packet_handler(QUIC_URXE *e, void *arg,
if (port->tserver_ch == NULL)
goto undesirable;

// TODO fsm

/*
* We have got a packet for an unknown DCID. This might be an attempt to
* open a new connection.
Expand Down Expand Up @@ -526,7 +542,7 @@ void ossl_quic_port_raise_net_error(QUIC_PORT *port)
{
QUIC_CHANNEL *ch;

// TODO fsm
port_transition_failed(port);

LIST_FOREACH(ch, ch, &port->channel_list)
ossl_quic_channel_raise_net_error(ch);
Expand Down
16 changes: 16 additions & 0 deletions ssl/quic/quic_port_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
*/
DECLARE_LIST_OF(ch, QUIC_CHANNEL);

/* A port is always in one of the following states: */
enum {
/* Initial and steady state. */
QUIC_PORT_STATE_RUNNING,

/*
* Terminal state indicating port is no longer functioning. There are no
* transitions out of this state. May be triggered by e.g. a permanent
* network BIO error.
*/
QUIC_PORT_STATE_FAILED
};

struct quic_port_st {
OSSL_LIB_CTX *libctx;
const char *propq;
Expand Down Expand Up @@ -63,6 +76,9 @@ struct quic_port_st {
/* For clients, CID length used for outgoing Initial packets. */
unsigned char tx_init_dcid_len;

/* Port state (QUIC_PORT_STATE_*). */
unsigned int state : 1;

/* Is this port created to support multiple connections? */
unsigned int is_multi_conn : 1;

Expand Down

0 comments on commit 0225d42

Please sign in to comment.