summaryrefslogtreecommitdiffstats
path: root/tests/libknot/test_xdp_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libknot/test_xdp_tcp.c')
-rw-r--r--tests/libknot/test_xdp_tcp.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/tests/libknot/test_xdp_tcp.c b/tests/libknot/test_xdp_tcp.c
index 7f3b994..4e02f57 100644
--- a/tests/libknot/test_xdp_tcp.c
+++ b/tests/libknot/test_xdp_tcp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2023 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/* Copyright (C) 2024 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -213,7 +213,7 @@ void test_syn(void)
knot_xdp_msg_t msg;
knot_tcp_relay_t rl = { 0 };
prepare_msg(&msg, KNOT_XDP_MSG_SYN, 1, 2);
- int ret = knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ int ret = knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "SYN: relay OK");
ret = knot_tcp_send(test_sock, &rl, 1, 1);
is_int(KNOT_EOK, ret, "SYN: send OK");
@@ -241,7 +241,7 @@ void test_syn_ack_no(void)
knot_xdp_msg_t msg;
knot_tcp_relay_t rl = { 0 };
prepare_msg(&msg, KNOT_XDP_MSG_SYN | KNOT_XDP_MSG_ACK, 1, 2);
- int ret = knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ int ret = knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "SYN+ACK deny: relay OK");
is_int(XDP_TCP_NOOP, rl.auto_answer, "SYN+ACK deny: no auto answer");
is_int(XDP_TCP_NOOP, rl.answer, "SYN+ACK deny: no answer");
@@ -256,7 +256,7 @@ void test_establish(void)
knot_tcp_relay_t rl = { 0 };
prepare_msg(&msg, KNOT_XDP_MSG_ACK, 1, 2);
prepare_seqack(&msg, 0, 1);
- int ret = knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ int ret = knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "establish: relay OK");
is_int(0, test_syn_table->usage, "SYN: no connection in SYN table");
is_int(1, test_table->usage, "SYN: one connection in normal table");
@@ -274,7 +274,7 @@ void test_syn_ack(void)
knot_xdp_msg_t msg;
knot_tcp_relay_t rl = { 0 };
prepare_msg(&msg, KNOT_XDP_MSG_SYN | KNOT_XDP_MSG_ACK, 1000, 2000);
- int ret = knot_tcp_recv(&rl, &msg, 1, test_table, NULL, XDP_TCP_IGNORE_NONE);
+ int ret = knot_tcp_recv(&rl, &msg, test_table, NULL, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "SYN+ACK: relay OK");
ret = knot_tcp_send(test_sock, &rl, 1, 1);
is_int(KNOT_EOK, ret, "SYN+ACK: send OK");
@@ -315,7 +315,10 @@ void test_data_fragments(void)
prepare_data(&msgs[3], "\x02""AB""\xff\xff""abcdefghijklmnopqrstuvwxyz...", 34);
assert(test_table);
- int ret = knot_tcp_recv(rls, msgs, CONNS, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ int ret = KNOT_EOK;
+ for (int i = 0; i < CONNS && ret == KNOT_EOK; i++) {
+ ret = knot_tcp_recv(&rls[i], &msgs[i], test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ }
is_int(KNOT_EOK, ret, "fragments: relay OK");
assert(test_sock);
ret = knot_tcp_send(test_sock, rls, CONNS, CONNS);
@@ -374,7 +377,7 @@ void test_close(void)
knot_xdp_msg_t wrong = msg;
wrong.seqno += INT32_MAX;
wrong.ackno += INT32_MAX;
- int ret = knot_tcp_recv(&rl, &wrong, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ int ret = knot_tcp_recv(&rl, &wrong, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "close: relay 0 OK");
is_int(KNOT_XDP_MSG_RST, rl.auto_answer, "close: reset wrong ackno");
is_int(rl.auto_seqno, wrong.ackno, "close: reset seqno");
@@ -383,7 +386,7 @@ void test_close(void)
check_sent(0, 1, 0, 0);
is_int(sent_seqno, wrong.ackno, "close: reset seqno sent");
- ret = knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ ret = knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "close: relay 1 OK");
ret = knot_tcp_send(test_sock, &rl, 1, 1);
is_int(KNOT_EOK, ret, "close: send OK");
@@ -395,7 +398,7 @@ void test_close(void)
msg.flags &= ~KNOT_XDP_MSG_FIN;
prepare_seqack(&msg, 0, 0);
- ret = knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ ret = knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "close: relay 2 OK");
ret = knot_tcp_send(test_sock, &rl, 1, 1);
is_int(KNOT_EOK, ret, "close: send 2 OK");
@@ -418,7 +421,10 @@ void test_many(void)
}
knot_tcp_relay_t *rls = malloc(CONNS * sizeof(*rls));
- int ret = knot_tcp_recv(rls, msgs, CONNS, test_table, NULL, XDP_TCP_IGNORE_NONE);
+ int ret = KNOT_EOK;
+ for (int i = 0; i < CONNS && ret == KNOT_EOK; i++) {
+ ret = knot_tcp_recv(&rls[i], &msgs[i], test_table, NULL, XDP_TCP_IGNORE_NONE);
+ }
is_int(KNOT_EOK, ret, "many: relay OK");
ret = knot_tcp_send(test_sock, rls, CONNS, CONNS);
is_int(KNOT_EOK, ret, "many: relay send OK");
@@ -435,7 +441,7 @@ void test_many(void)
fix_seqack(survive);
prepare_data(survive, "\x00\x00", 2);
assert(test_table);
- ret = knot_tcp_recv(&surv_rl, survive, 1, test_table, NULL, XDP_TCP_IGNORE_NONE);
+ ret = knot_tcp_recv(&surv_rl, survive, test_table, NULL, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "many/survivor: OK");
clean_sent();
@@ -479,7 +485,10 @@ 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_tcp_recv(rls, msgs, CONNS, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ int ret = KNOT_EOK;
+ for (int i = 0; i < CONNS && ret == KNOT_EOK; i++) {
+ ret = knot_tcp_recv(&rls[i], &msgs[i], test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ }
is_int(KNOT_EOK, ret, "ibufs: open OK");
ret = knot_tcp_send(test_sock, rls, CONNS, CONNS);
is_int(KNOT_EOK, ret, "ibufs: first send OK");
@@ -488,14 +497,16 @@ void test_ibufs_size(void)
msgs[i].flags = KNOT_XDP_MSG_TCP | KNOT_XDP_MSG_ACK;
}
fix_seqacks(msgs, CONNS);
- (void)knot_tcp_recv(rls, msgs, CONNS, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ for (int i = 0; i < CONNS && ret == KNOT_EOK; i++) {
+ ret = knot_tcp_recv(&rls[i], &msgs[i], test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ }
is_int(0, test_table->inbufs_total, "inbufs: initial total zero");
// first connection will start a fragment buf then finish it
fix_seqack(&msgs[0]);
prepare_data(&msgs[0], "\x00\x0a""lorem", 7);
- ret = knot_tcp_recv(&rls[0], &msgs[0], 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ ret = knot_tcp_recv(&rls[0], &msgs[0], test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "ibufs: must be OK");
ret = knot_tcp_send(test_sock, &rls[0], 1, 1);
is_int(KNOT_EOK, ret, "ibufs: must send OK");
@@ -509,7 +520,9 @@ 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_tcp_recv(rls, msgs, CONNS, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ for (int i = 0; i < CONNS && ret == KNOT_EOK; i++) {
+ ret = knot_tcp_recv(&rls[i], &msgs[i], test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ }
is_int(KNOT_EOK, ret, "inbufs: relay OK");
ret = knot_tcp_send(test_sock, rls, CONNS, CONNS);
is_int(KNOT_EOK, ret, "inbufs: send OK");
@@ -546,11 +559,11 @@ void test_obufs(void)
knot_tcp_relay_t rl = { 0 };
prepare_msg(&msg, KNOT_XDP_MSG_SYN, 1, 2);
- (void)knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE); // SYN
+ (void)knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE); // SYN
(void)knot_tcp_send(test_sock, &rl, 1, 1); // SYN+ACK
prepare_msg(&msg, KNOT_XDP_MSG_ACK, 1, 2);
prepare_seqack(&msg, 0, 1);
- (void)knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE); // ACK
+ (void)knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE); // ACK
size_t TEST_MSS = 1111;
size_t DATA_LEN = 65535; // with 2-byte len prefix, this is > 64k == window_size
@@ -588,7 +601,7 @@ void test_obufs(void)
memset(&rl, 0, sizeof(rl));
prepare_seqack(&msg, 0, TEST_MSS);
- ret = knot_tcp_recv(&rl, &msg, 1, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
+ ret = knot_tcp_recv(&rl, &msg, test_table, test_syn_table, XDP_TCP_IGNORE_NONE);
is_int(KNOT_EOK, ret, "obufs: ACKed data");
assert(rl.conn);
rl.conn->window_size = 65536;