Skip to content
Snippets Groups Projects
Commit cb626605 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman
Browse files

xdp-tcp: bugfix: better handling of different conn-closing states

parent a6971a40
No related branches found
No related tags found
1 merge request!1394xdp-tcp: evolution and bugfixes
......@@ -330,11 +330,12 @@ int knot_tcp_relay(knot_xdp_socket_t *socket, knot_xdp_msg_t msgs[], uint32_t ms
} else {
switch ((*conn)->state) {
case XDP_TCP_NORMAL:
case XDP_TCP_CLOSING1: // just a mess, ignore
break;
case XDP_TCP_ESTABLISHING:
(*conn)->state = XDP_TCP_NORMAL;
break;
case XDP_TCP_CLOSING:
case XDP_TCP_CLOSING2:
tcp_table_del(conn, tcp_table);
break;
}
......@@ -344,7 +345,7 @@ int knot_tcp_relay(knot_xdp_socket_t *socket, knot_xdp_msg_t msgs[], uint32_t ms
if (!seq_ack_match) {
resp_ack(msg, KNOT_XDP_MSG_RST);
} else {
if ((*conn)->state == XDP_TCP_CLOSING) {
if ((*conn)->state == XDP_TCP_CLOSING1) {
resp_ack(msg, KNOT_XDP_MSG_ACK);
relay.action = XDP_TCP_CLOSE;
if (knot_tcp_relay_dynarray_add(relays, &relay) == NULL) {
......@@ -357,7 +358,7 @@ int knot_tcp_relay(knot_xdp_socket_t *socket, knot_xdp_msg_t msgs[], uint32_t ms
if (knot_tcp_relay_dynarray_add(relays, &relay) == NULL) {
ret = KNOT_ENOMEM;
}
(*conn)->state = XDP_TCP_CLOSING;
(*conn)->state = XDP_TCP_CLOSING2;
(*conn)->ackno++;
}
}
......@@ -504,7 +505,7 @@ int knot_tcp_send(knot_xdp_socket_t *socket, knot_tcp_relay_t relays[], uint32_t
msg->payload.iov_len = 0;
assert(rl->conn != NULL);
rl->conn->ackno++;
rl->conn->state = XDP_TCP_CLOSING;
rl->conn->state = XDP_TCP_CLOSING1;
break;
case XDP_TCP_RESET:
default:
......@@ -555,7 +556,7 @@ int knot_tcp_sweep(knot_tcp_table_t *tcp_table, knot_xdp_socket_t *socket,
reset_buf_size -= MIN(reset_buf_size, conn->inbuf.iov_len);
} else if (now - conn->last_active >= close_timeout) {
if (conn->state != XDP_TCP_CLOSING) {
if (conn->state != XDP_TCP_CLOSING1) {
rl.answer = XDP_TCP_CLOSE;
if (close_count != NULL) {
(*close_count)++;
......@@ -566,7 +567,10 @@ int knot_tcp_sweep(knot_tcp_table_t *tcp_table, knot_xdp_socket_t *socket,
}
rl.conn = conn;
(void)knot_tcp_relay_dynarray_add(&relays, &rl);
if (rl.answer != XDP_TCP_NOOP) {
(void)knot_tcp_relay_dynarray_add(&relays, &rl);
rl.answer = XDP_TCP_NOOP;
}
if (relays.size >= max_at_once) {
break;
}
......
......@@ -42,7 +42,8 @@ typedef enum {
typedef enum {
XDP_TCP_NORMAL,
XDP_TCP_ESTABLISHING,
XDP_TCP_CLOSING,
XDP_TCP_CLOSING1, // FIN+ACK sent
XDP_TCP_CLOSING2, // FIND+ACK received and sent
} knot_tcp_state_t;
typedef enum {
......
......@@ -326,7 +326,7 @@ void test_close(void)
knot_tcp_relay_t *rl = &knot_tcp_relay_dynarray_arr(&relays)[0];
is_int(XDP_TCP_CLOSE, rl->action, "close: relay action");
ok(rl->conn == test_conn, "close: same connection");
is_int(XDP_TCP_CLOSING, rl->conn->state, "close: conn state");
is_int(XDP_TCP_CLOSING2, rl->conn->state, "close: conn state");
knot_tcp_relay_free(&relays);
msg.flags &= ~KNOT_XDP_MSG_FIN;
......
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