Skip to content
Snippets Groups Projects
Commit 5036f771 authored by Jan Hák's avatar Jan Hák Committed by Daniel Salzman
Browse files

kdig: close and deinit QUIC connection

parent 4d52d602
No related branches found
No related tags found
No related merge requests found
......@@ -762,6 +762,11 @@ void net_close(net_t *net)
return;
}
#ifdef LIBNGTCP2
if (net->quic.params.enable) {
quic_ctx_close(&net->quic);
}
#endif
tls_ctx_close(&net->tls);
close(net->sockfd);
net->sockfd = -1;
......@@ -795,6 +800,9 @@ void net_clean(net_t *net)
#ifdef LIBNGHTTP2
https_ctx_deinit(&net->https);
#endif
#ifdef LIBNGTCP2
quic_ctx_deinit(&net->quic);
#endif
tls_ctx_deinit(&net->tls);
}
......@@ -895,4 +895,61 @@ int quic_recv_dns_response(quic_ctx_t *ctx, uint8_t *buf, const size_t buf_len,
return KNOT_NET_ETIMEOUT;
}
void quic_ctx_close(quic_ctx_t *ctx)
{
if (ctx == NULL || ctx->state == CLOSED) {
return;
}
uint8_t enc_buf[MAX_PACKET_SIZE];
struct iovec msg_iov = {
.iov_base = enc_buf,
.iov_len = 0
};
struct msghdr msg = {
.msg_iov = &msg_iov,
.msg_iovlen = 1
};
ngtcp2_ssize nwrite = ngtcp2_conn_write_connection_close(ctx->conn,
(ngtcp2_path *)ngtcp2_conn_get_path(ctx->conn),
&ctx->pi, enc_buf, sizeof(enc_buf), ctx->last_err.error_code,
ctx->last_err.reason, ctx->last_err.reasonlen,
quic_timestamp());
if (nwrite <= 0) {
return;
}
msg_iov.iov_len = nwrite;
struct sockaddr_in6 si;
socklen_t si_len = sizeof(si);
if (getsockname(ctx->tls->sockfd, &si, &si_len) == 0) {
quic_set_enc(ctx->tls->sockfd, si.sin6_family, ctx->pi.ecn);
}
(void)sendmsg(ctx->tls->sockfd, &msg, 0);
ctx->state = CLOSED;
}
void quic_ctx_deinit(quic_ctx_t *ctx)
{
if (ctx == NULL) {
return;
}
if (ctx->conn) {
ngtcp2_conn_del(ctx->conn);
ctx->conn = NULL;
}
if (ctx->stream.in_buffer.iov_base != NULL) {
free(ctx->stream.in_buffer.iov_base);
}
if (ctx->stream.in_parsed != NULL) {
free(ctx->stream.in_parsed);
}
}
#endif
......@@ -114,4 +114,9 @@ int quic_send_dns_query(quic_ctx_t *ctx, int sockfd, struct addrinfo *srv,
int quic_recv_dns_response(quic_ctx_t *ctx, uint8_t *buf, const size_t buf_len,
struct addrinfo *srv);
void quic_ctx_close(quic_ctx_t *ctx);
void quic_ctx_deinit(quic_ctx_t *ctx);
#endif //LIBNGTCP2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment