quic: fix passive disconnect handling & refactor

Type: refactor

Change-Id: Ie54a77252e9f58a90f9e1f9595b9ede354952f70
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
This commit is contained in:
Nathan Skrzypczak
2019-07-04 14:32:40 +02:00
parent 0cbc71d783
commit e92090b4f4
4 changed files with 751 additions and 540 deletions

View File

@ -0,0 +1,12 @@
diff --git a/lib/quicly.c b/lib/quicly.c
index fac85f2..80e1bcd 100644
--- a/lib/quicly.c
+++ b/lib/quicly.c
@@ -3240,6 +3240,7 @@ static int initiate_close(quicly_conn_t *conn, int err, uint64_t frame_type, con
int quicly_close(quicly_conn_t *conn, int err, const char *reason_phrase)
{
assert(err == 0 || QUICLY_ERROR_IS_QUIC_APPLICATION(err));
+ update_now(conn->super.ctx);
return initiate_close(conn, err, QUICLY_FRAME_TYPE_PADDING /* used when err == 0 */, reason_phrase);
}

View File

@ -58,7 +58,7 @@
clib_warning ("ECHO-ERROR: "_fmt, ##_args); \
}
typedef enum
typedef enum echo_session_flag_
{
SESSION_FLAG_NOFLAG = 0,
SESSION_FLAG_SHOULD_CLOSE = 1,
@ -1309,11 +1309,6 @@ session_disconnected_handler (session_disconnected_msg_t * mp)
}
s = pool_elt_at_index (em->sessions, p[0]);
if (s->session_type == QUIC_SESSION_TYPE_STREAM)
s->flags |= SESSION_FLAG_SHOULD_CLOSE; /* tell thread to close session */
else
echo_cleanup_session (em, s); /* We can clean Qsessions right away */
app_alloc_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt,
SESSION_CTRL_EVT_DISCONNECTED_REPLY);
rmp = (session_disconnected_reply_msg_t *) app_evt->evt->data;
@ -1322,6 +1317,11 @@ session_disconnected_handler (session_disconnected_msg_t * mp)
rmp->context = mp->context;
app_send_ctrl_evt_to_vpp (s->vpp_evt_q, app_evt);
if (s->session_type == QUIC_SESSION_TYPE_STREAM)
s->flags |= SESSION_FLAG_SHOULD_CLOSE; /* tell thread to close session */
else
echo_cleanup_session (em, s); /* We can clean Qsessions right away */
if (s->session_type == QUIC_SESSION_TYPE_STREAM)
session_print_stats (em, s);
}
@ -1460,7 +1460,11 @@ server_run (echo_main_t * em)
/* Cleanup */
server_send_unbind (em);
wait_for_state_change (em, STATE_DISCONNECTED, TIMEOUT);
if (wait_for_state_change (em, STATE_DISCONNECTED, TIMEOUT))
{
ECHO_FAIL ("Timeout waiting for state disconnected");
return;
}
}
/*
@ -1627,8 +1631,8 @@ vl_api_unbind_uri_reply_t_handler (vl_api_unbind_uri_reply_t * mp)
echo_main_t *em = &echo_main;
if (mp->retval != 0)
{
/* ECHO_FAIL ("returned %d", ntohl (mp->retval));
return; FIXME : UDPC issue */
ECHO_FAIL ("returned %d", ntohl (mp->retval));
return;
}
em->state = STATE_DISCONNECTED;
listen_session = pool_elt_at_index (em->sessions, em->listen_session_index);

File diff suppressed because it is too large Load Diff

View File

@ -32,11 +32,30 @@
**/
#define QUIC_DEBUG 0
#define QUIC_DEFAULT_CA_CERT_PATH "/etc/ssl/certs/ca-certificates.crt"
#define QUIC_TSTAMP_RESOLUTION 0.001 /* QUIC tick resolution (1ms) */
#define QUIC_TIMER_HANDLE_INVALID ((u32) ~0)
#define QUIC_SESSION_INVALID ((u32) ~0 - 1)
#define QUIC_MAX_PACKET_SIZE 1280
#define QUIC_INT_MAX 0x3FFFFFFFFFFFFFFF
#define QUIC_FIFO_SIZE (64 << 10)
#define QUIC_SEND_PACKET_VEC_SIZE 16
/* Taken from quicly.c */
#define QUICLY_QUIC_BIT 0x40
#define QUICLY_PACKET_TYPE_INITIAL (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0)
#define QUICLY_PACKET_TYPE_0RTT (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x10)
#define QUICLY_PACKET_TYPE_HANDSHAKE (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x20)
#define QUICLY_PACKET_TYPE_RETRY (QUICLY_LONG_HEADER_BIT | QUICLY_QUIC_BIT | 0x30)
#define QUICLY_PACKET_TYPE_BITMASK 0xf0
/* error codes */
#define QUIC_ERROR_FULL_FIFO 0xff10
#define QUIC_APP_ERROR_CLOSE_NOTIFY QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0)
#define QUIC_APP_ALLOCATION_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x1)
#define QUIC_APP_ACCEPT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x2)
#define QUIC_APP_CONNECT_NOTIFY_ERROR QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(0x3)
#if QUIC_DEBUG
#define QUIC_DBG(_lvl, _fmt, _args...) \
@ -46,29 +65,39 @@
#define QUIC_DBG(_lvl, _fmt, _args...)
#endif
#define QUIC_CONN_STATE_OPENED 0
#define QUIC_CONN_STATE_HANDSHAKE 1
#define QUIC_CONN_STATE_READY 2
typedef enum quic_ctx_conn_state_
{
QUIC_CONN_STATE_OPENED,
QUIC_CONN_STATE_HANDSHAKE,
QUIC_CONN_STATE_READY,
QUIC_CONN_STATE_PASSIVE_CLOSING,
} quic_ctx_conn_state_t;
typedef enum quic_ctx_flags_
{
QUIC_F_IS_STREAM = (1 << 0),
QUIC_F_IS_LISTENER = (1 << 1),
} quic_ctx_flags_t;
/* *INDENT-OFF* */
typedef CLIB_PACKED (struct quic_ctx_id_
typedef struct quic_ctx_id_
{
u32 parent_app_wrk_id;
u32 parent_app_id;
union {
CLIB_PACKED (struct {
session_handle_t udp_session_handle;
union { /** QUIC ctx case */
struct {
quicly_conn_t *conn;
u32 listener_ctx_id;
u32 client_opaque;
u8 *srv_hostname;
u8 conn_state;
u8 udp_is_ip4;
});
CLIB_PACKED (struct {
};
struct { /** STREAM ctx case */
quicly_stream_t *stream;
u32 quic_connection_ctx_id;
});
};
};
u8 is_stream;
}) quic_ctx_id_t;
} quic_ctx_id_t;
/* *INDENT-ON* */
STATIC_ASSERT (sizeof (quic_ctx_id_t) <= 42, "ctx id must be less than 42");
@ -82,11 +111,11 @@ typedef struct quic_ctx_
transport_connection_t connection;
quic_ctx_id_t c_quic_ctx_id;
};
u8 *srv_hostname;
u32 client_opaque;
session_handle_t udp_session_handle;
u32 timer_handle;
u8 conn_state;
u8 is_listener;
u32 parent_app_wrk_id;
u32 parent_app_id;
u8 flags;
} quic_ctx_t;
typedef struct quic_stream_data_
@ -118,8 +147,6 @@ typedef struct quic_main_
quicly_context_t quicly_ctx;
ptls_handshake_properties_t hs_properties;
quicly_cid_plaintext_t next_cid;
u8 use_test_cert_in_ca;
char *ca_cert_path;
} quic_main_t;
#endif /* __included_quic_h__ */