diff --git a/src/knot/server/xdp-handler.c b/src/knot/server/xdp-handler.c index 8b0b42095922afe4b3a4786b35df1889be65aad2..f8cc52fec4eb6d97737a7b8fd458d690ff28632a 100644 --- a/src/knot/server/xdp-handler.c +++ b/src/knot/server/xdp-handler.c @@ -175,8 +175,7 @@ int xdp_handle_msgs(xdp_handle_ctx_t *ctx, knot_xdp_socket_t *sock, } // handle TCP messages - int ret = knot_xdp_tcp_relay(sock, ctx->msg_recv, ctx->msg_recv_count, ctx->tcp_table, NULL, &ctx->tcp_relays, - NULL); // TODO NULL + int ret = knot_xdp_tcp_relay(sock, ctx->msg_recv, ctx->msg_recv_count, ctx->tcp_table, NULL, &ctx->tcp_relays); if (ret == KNOT_EOK && ctx->tcp_relays.size > 0) { uint8_t ans_buf[KNOT_WIRE_MAX_PKTSIZE]; diff --git a/src/libknot/xdp/tcp.c b/src/libknot/xdp/tcp.c index 410e50dab5d297d6a5124b39c2d710371662d9ab..74685b669b4c2c64be9138733e5d28c5789e63d0 100644 --- a/src/libknot/xdp/tcp.c +++ b/src/libknot/xdp/tcp.c @@ -26,7 +26,6 @@ #include "libknot/error.h" #include "libknot/xdp/tcp_iobuf.h" #include "contrib/macros.h" -#include "contrib/mempattern.h" #include "contrib/openbsd/siphash.h" #include "contrib/ucw/lists.h" @@ -203,7 +202,7 @@ static bool check_seq_ack(const knot_xdp_msg_t *msg, const knot_tcp_conn_t *conn _public_ int knot_xdp_tcp_relay(knot_xdp_socket_t *socket, knot_xdp_msg_t msgs[], uint32_t msg_count, knot_tcp_table_t *tcp_table, knot_tcp_table_t *syn_table, - knot_tcp_relay_dynarray_t *relays, knot_mm_t *mm) + knot_tcp_relay_dynarray_t *relays) { if (msg_count == 0) { return KNOT_EOK; diff --git a/src/libknot/xdp/tcp.h b/src/libknot/xdp/tcp.h index 832bd8797aed9fc7c33e6b64f440f4a9b450661e..115113127afe007494ceda5eb72c49f464d0b4bf 100644 --- a/src/libknot/xdp/tcp.h +++ b/src/libknot/xdp/tcp.h @@ -26,7 +26,6 @@ #pragma once #include "libknot/dynarray.h" -#include "libknot/mm_ctx.h" #include "libknot/xdp/msg.h" #include "libknot/xdp/xdp.h" @@ -130,13 +129,12 @@ void knot_tcp_table_free(knot_tcp_table_t *t); * \param tcp_table Table of TCP connections. * \param syn_table Optional: extra table for handling partially established connections. * \param relays Out: connection changes and data. - * \param mm Memory context. * * \return KNOT_E* */ int knot_xdp_tcp_relay(knot_xdp_socket_t *socket, knot_xdp_msg_t msgs[], uint32_t msg_count, knot_tcp_table_t *tcp_table, knot_tcp_table_t *syn_table, - knot_tcp_relay_dynarray_t *relays, knot_mm_t *mm); + knot_tcp_relay_dynarray_t *relays); /*! * \brief Answer one relay with one or more relays with data payload. diff --git a/src/utils/kxdpgun/main.c b/src/utils/kxdpgun/main.c index cb8a4ca55fb3ebdc45e93aade5a6d5808abf862a..f90cbf4973d8b2cbc71078c7f86bcf732065acd5 100644 --- a/src/utils/kxdpgun/main.c +++ b/src/utils/kxdpgun/main.c @@ -329,11 +329,6 @@ void *xdp_gun_thread(void *_ctx) kxdpgun_stats_t local_stats = { 0 }; unsigned stats_triggered = 0; - knot_mm_t mm; - if (ctx->tcp) { - mm_ctx_mempool(&mm, ctx->at_once * 16 * MM_DEFAULT_BLKSIZE); - } - knot_tcp_table_t *tcp_table = knot_tcp_table_new(ctx->qps); // FIXME: qps is not the best choice? if (tcp_table == NULL) { printf("failed to allocate TCP connection table\n"); @@ -430,7 +425,7 @@ void *xdp_gun_thread(void *_ctx) } if (ctx->tcp) { knot_tcp_relay_dynarray_t relays = { 0 }; - ret = knot_xdp_tcp_relay(xsk, pkts, recvd, tcp_table, NULL, &relays, &mm); + ret = knot_xdp_tcp_relay(xsk, pkts, recvd, tcp_table, NULL, &relays); if (ret != KNOT_EOK) { errors++; break; @@ -469,7 +464,6 @@ void *xdp_gun_thread(void *_ctx) } knot_xdp_tcp_relay_free(&relays); - mp_flush(mm.ctx); } else { for (int i = 0; i < recvd; i++) { (void)check_dns_payload(&pkts[i].payload, ctx, &local_stats); @@ -512,10 +506,6 @@ void *xdp_gun_thread(void *_ctx) knot_tcp_table_free(tcp_table); - if (ctx->tcp) { - mp_delete(mm.ctx); - } - printf("thread#%02u: sent %lu, received %lu, errors %lu\n", ctx->thread_id, local_stats.qry_sent, local_stats.ans_recv, errors); local_stats.duration = ctx->duration; diff --git a/tests/libknot/test_xdp_tcp.c b/tests/libknot/test_xdp_tcp.c index a03bcbd279e10cfbee8e5a38a953a9202c64c21a..03a6d00755b2553c53732b3544a16c5f61647a9a 100644 --- a/tests/libknot/test_xdp_tcp.c +++ b/tests/libknot/test_xdp_tcp.c @@ -196,7 +196,7 @@ void test_syn(void) knot_xdp_msg_t msg; knot_tcp_relay_dynarray_t relays = { 0 }; prepare_msg(&msg, KNOT_XDP_MSG_SYN, 1, 2); - int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "SYN: relay OK"); is_int(msg.seqno + 1, sent_ackno, "SYN: ackno"); check_sent(0, 0, 1, 0); @@ -223,7 +223,7 @@ void test_establish(void) knot_tcp_relay_dynarray_t relays = { 0 }; prepare_msg(&msg, KNOT_XDP_MSG_ACK, 1, 2); prepare_seqack(&msg, 0, 1); - int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "establish: relay OK"); check_sent(0, 0, 0, 0); is_int(0, relays.size, "establish: no relay"); @@ -242,7 +242,7 @@ void test_syn_ack(void) knot_xdp_msg_t msg; knot_tcp_relay_dynarray_t relays = { 0 }; prepare_msg(&msg, KNOT_XDP_MSG_SYN | KNOT_XDP_MSG_ACK, 1000, 2000); - int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "SYN+ACK: relay OK"); is_int(msg.seqno + 1, sent_ackno, "SYN+ACK: ackno"); check_sent(1, 0, 0, 0); @@ -280,7 +280,7 @@ void test_data_fragments(void) prepare_seqack(&msgs[3], 15, 0); prepare_data(&msgs[3], "\x02""AB""\xff\xff""abcdefghijklmnopqrstuvwxyz...", 34); - int ret = knot_xdp_tcp_relay(test_sock, msgs, sizeof(msgs) / sizeof(msgs[0]), test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, msgs, sizeof(msgs) / sizeof(msgs[0]), test_table, NULL, &relays); is_int(KNOT_EOK, ret, "fragments: relay OK"); is_int(msgs[3].ackno, sent_seqno, "fragments: seqno"); is_int(msgs[3].seqno + msgs[3].payload.iov_len, sent_ackno, "fragments: ackno"); @@ -320,7 +320,7 @@ void test_close(void) knot_tcp_relay_dynarray_t relays = { 0 }; prepare_msg(&msg, KNOT_XDP_MSG_FIN | KNOT_XDP_MSG_ACK, be16toh(test_conn->ip_rem.sin6_port), be16toh(test_conn->ip_loc.sin6_port)); prepare_seqack(&msg, 0, 0); - int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "close: relay 1 OK"); check_sent(0, 0, 0, 1); is_int(1, relays.size, "close: one relay"); @@ -332,7 +332,7 @@ void test_close(void) msg.flags &= ~KNOT_XDP_MSG_FIN; prepare_seqack(&msg, 0, 0); - ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays, NULL); + ret = knot_xdp_tcp_relay(test_sock, &msg, 1, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "close: relay 2 OK"); check_sent(0, 0, 0, 0); is_int(conns_pre - 1, test_table->usage, "close: connection removed"); @@ -352,7 +352,7 @@ void test_many(void) } knot_tcp_relay_dynarray_t relays = { 0 }; - int ret = knot_xdp_tcp_relay(test_sock, msgs, CONNS, test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, msgs, CONNS, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "many: relay OK"); check_sent(0, 0, CONNS, 0); is_int(CONNS, relays.size, "many: relays count"); @@ -365,7 +365,7 @@ void test_many(void) knot_tcp_conn_t *surv_conn = tcp_table_find(test_table, survive); fix_seqack(survive); prepare_data(survive, "\x00\x00", 2); - (void)knot_xdp_tcp_relay(test_sock, survive, 1, test_table, NULL, &relays, NULL); + (void)knot_xdp_tcp_relay(test_sock, survive, 1, test_table, NULL, &relays); is_int(1, relays.size, "many/survivor: one relay"); knot_tcp_relay_t *rl = &knot_tcp_relay_dynarray_arr(&relays)[0]; clean_sent(); @@ -401,7 +401,7 @@ void test_ibufs_size(void) for (int i = 0; i < CONNS; i++) { prepare_msg(&msgs[i], KNOT_XDP_MSG_SYN, i + 2000, 1); } - int ret = knot_xdp_tcp_relay(test_sock, msgs, CONNS, test_table, NULL, &relays, NULL); + int ret = knot_xdp_tcp_relay(test_sock, msgs, CONNS, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "ibufs: open OK"); check_sent(0, 0, CONNS, 0); for (int i = 0; i < CONNS; i++) { @@ -413,7 +413,7 @@ void test_ibufs_size(void) // first connection will start a fragment buf then finish it fix_seqack(&msgs[0]); prepare_data(&msgs[0], "\x00\x0a""lorem", 7); - ret = knot_xdp_tcp_relay(test_sock, &msgs[0], 1, test_table, NULL, &relays, NULL); + ret = knot_xdp_tcp_relay(test_sock, &msgs[0], 1, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "ibufs: must be OK"); check_sent(1, 0, 0, 0); is_int(7, test_table->inbufs_total, "inbufs: first inbuf"); @@ -425,7 +425,7 @@ void test_ibufs_size(void) prepare_data(&msgs[1], "\x00\xff""12345", 7); prepare_data(&msgs[2], "\xff\xff""abcde", 7); prepare_data(&msgs[3], "\xff\xff""abcde", 7); - ret = knot_xdp_tcp_relay(test_sock, msgs, CONNS, test_table, NULL, &relays, NULL); + ret = knot_xdp_tcp_relay(test_sock, msgs, CONNS, test_table, NULL, &relays); is_int(KNOT_EOK, ret, "inbufs: relay OK"); check_sent(CONNS, 0, 0, 0); is_int(21, test_table->inbufs_total, "inbufs: after change");