etcp_router: sess_id как локальный счётчик переустановок (не в протоколе)

This commit is contained in:
evgeny committed 2026-09-05 20:38:17 +03:00
1 parent 2d04bf941b
commit 01ea6913ae
4 files changed
+26 -64

No files matched your search

+12 -42
View File
@@ -718,54 +718,25 @@ static int test_client_restart(void) {
return 0;
}
static int test_sess_id_change(void) {
TEST("sess_id change — 0→1 with START triggers restart");
static int test_sess_id_increment(void) {
TEST("sess_id — 0 on create, increments on restart");
struct UASYNC* ua; struct UTUN_INSTANCE inst; etcp_recv_fn recv_cb;
SETUP();
g_notify_count = 0;
int n = rand() % 10 + 1;
rx_reset(0xC1);
pump_data(recv_cb, &inst, 0xC1, n, 0);
if (rx.delivered != n) FAIL("initial pump failed");
rx_reset(0xC2);
uint8_t data[] = { TEST_SVC_ID, 0xC2, 0 };
uint8_t f = (1 << ROUTER_SESS_ID_SHIFT) | ROUTER_FLAG_START;
inject(recv_cb, &inst, TEST_REMOTE_NODE, TEST_SVC_ID, 0, data + 1, 2, 0, f);
if (g_notify_count != 1) FAIL("restart not notified");
if (rx.delivered < 1) FAIL("data after restart not delivered");
TEARDOWN();
PASS();
return 0;
}
static int test_sess_id_wrap(void) {
TEST("sess_id wrap — 3→0 with START triggers restart");
struct UASYNC* ua; struct UTUN_INSTANCE inst; etcp_recv_fn recv_cb;
SETUP();
g_notify_count = 0;
int n = rand() % 10 + 1;
uint8_t f3 = (3 << ROUTER_SESS_ID_SHIFT);
rx_reset(0xD1);
struct ETCP_ROUTER_CONN* c = etcp_router_conn_get(&inst, TOPO_GROUP_UTUN, TEST_REMOTE_NODE, TEST_SVC_ID);
if (!c) FAIL("rconn not found");
c->peer_sess_id = 3;
if (c->sess_id != 0) FAIL("sess_id != 0 on fresh conn");
pump_data(recv_cb, &inst, 0xD1, n, f3);
if (rx.delivered != n) FAIL("initial pump failed");
etcp_router_conn_restart(&inst, TOPO_GROUP_UTUN, TEST_REMOTE_NODE, TEST_SVC_ID);
c = etcp_router_conn_get(&inst, TOPO_GROUP_UTUN, TEST_REMOTE_NODE, TEST_SVC_ID);
if (!c) FAIL("rconn not found after first restart");
if (c->sess_id != 1) FAIL("sess_id != 1 after first restart");
rx_reset(0xD2);
g_notify_count = 0;
uint8_t data[] = { TEST_SVC_ID, 0xD2, 0 };
uint8_t f0 = (0 << ROUTER_SESS_ID_SHIFT) | ROUTER_FLAG_START;
inject(recv_cb, &inst, TEST_REMOTE_NODE, TEST_SVC_ID, 0, data + 1, 2, 0, f0);
if (g_notify_count != 1) FAIL("restart not notified on wrap");
if (rx.delivered < 1) FAIL("data after wrap not delivered");
etcp_router_conn_restart(&inst, TOPO_GROUP_UTUN, TEST_REMOTE_NODE, TEST_SVC_ID);
c = etcp_router_conn_get(&inst, TOPO_GROUP_UTUN, TEST_REMOTE_NODE, TEST_SVC_ID);
if (c->sess_id != 2) FAIL("sess_id != 2 after second restart");
etcp_router_conn_close(c);
TEARDOWN();
PASS();
return 0;
@@ -1187,8 +1158,7 @@ int main(void) {
test_conn_send_no_bgp();
test_rst_flag();
test_client_restart();
test_sess_id_change();
test_sess_id_wrap();
test_sess_id_increment();
test_server_reinit();
if (setup_sign_keys() != 0) { printf(" SKIP signed tests — crypto init failed\n"); }