From b48ea36192617b978e3729d85c8bb148bd02c417 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Wed, 25 Feb 2026 14:14:44 -0300 Subject: [PATCH] add tests for TCP RST handling --- test/mip_test.c | 55 ++++++++++++++++++- .../arduino/sim800-mqtt/mongoose_config.h | 2 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/test/mip_test.c b/test/mip_test.c index 8af7f580..06ecfc63 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -378,8 +378,8 @@ static void test_tcp_basics(bool ipv6) { init_tcp_tests(&mgr, &e, &ipp, &driver, &mif, fn); - // https://datatracker.ietf.org/doc/html/rfc9293#section-3.5.2 Reset - // Generation non-used port. Group 1 in RFC send SYN, expect RST + ACK + // - https://datatracker.ietf.org/doc/html/rfc9293#section-3.5.2 + // Reset generation, non-used port. Group 1 in RFC send SYN expect RST + ACK create_tcp_seg(&e, &ipp, 1234, 4321, TH_SYN, 1, 69, 0, NULL, 0); mg_mgr_poll(&mgr, 0); // make sure we clean former stuff in buffer while (!received_response(&s_driver_data)) mg_mgr_poll(&mgr, 0); @@ -469,7 +469,7 @@ static void test_tcp_basics(bool ipv6) { ASSERT(t->flags == TH_RST); ASSERT(t->seq == mg_htonl(4321)); - // we currently don't validate checksum, no silently discarded segment test + // no silently discarded segment test init_tcp_handshake(&e, &ipp, &mgr); // starts with seq_no=1000, ackno=2 @@ -681,6 +681,55 @@ static void test_tcp_basics(bool ipv6) { s_driver_data.len = 0; mg_mgr_free(&mgr); + // Test RST handling + // https://datatracker.ietf.org/doc/html/rfc9293#section-3.5.3 + init_tcp_tests(&mgr, &e, &ipp, &driver, &mif, fn); + init_tcp_handshake(&e, &ipp, &mgr); // starts with seq_no=1000, ackno=2 + + // RST with seq_no way out of window + create_tcp_seg(&e, &ipp, 1000000, 2, TH_RST, 1, 80, 0, NULL, 0); + mg_mgr_poll(&mgr, 0); + ASSERT(!received_response(&s_driver_data)); + // make sure it is NOT closed + ASSERT(mgr.conns->next != NULL); // two connections: listener + ours + + { // RST with seq_no within window but alien address + uint32_t ip4 = 0; +#if MG_ENABLE_IPV6 // forge source address + uint64_t ip6_0 = 0; + if (ipp.ip6 != NULL) { + ip6_0 = ip6.src[0]; + ip6.src[0] = ip6.src[0] << 1; + } else +#endif + { + ip4 = ip.src; + ip.src = ip.src << 1; + } + create_tcp_seg(&e, &ipp, 1010, 2, TH_RST, 1, 80, 0, NULL, 0); + mg_mgr_poll(&mgr, 0); + ASSERT(!received_response(&s_driver_data)); + // make sure it is NOT closed + ASSERT(mgr.conns->next != NULL); // two connections: listener + ours +#if MG_ENABLE_IPV6 // restore source address + if (ipp.ip6 != NULL) { + ip6.src[0] = ip6_0; + } else +#endif + { + ip.src = ip4; + } + } + // RST with seq_no within window + create_tcp_seg(&e, &ipp, 1010, 2, TH_RST, 1, 80, 0, NULL, 0); + mg_mgr_poll(&mgr, 0); + ASSERT(!received_response(&s_driver_data)); + // make sure it is closed + ASSERT(mgr.conns->next == NULL); // only one connection: the listener + + s_driver_data.len = 0; + mg_mgr_free(&mgr); + // Test responses to a connecting client // https://datatracker.ietf.org/doc/html/rfc9293#section-3.5 // NOTE: Mongoose ignores any data until connection is actually established diff --git a/tutorials/mqtt/mqtt-client/arduino/sim800-mqtt/mongoose_config.h b/tutorials/mqtt/mqtt-client/arduino/sim800-mqtt/mongoose_config.h index 803047e2..193ea6ba 100644 --- a/tutorials/mqtt/mqtt-client/arduino/sim800-mqtt/mongoose_config.h +++ b/tutorials/mqtt/mqtt-client/arduino/sim800-mqtt/mongoose_config.h @@ -10,7 +10,7 @@ #define MG_ARCH MG_ARCH_CUSTOM #define MG_ENABLE_SOCKET 0 #define MG_ENABLE_TCPIP 1 -#define MG_ENABLE_DRIVER_PPP 1 +#define MG_ENABLE_DRIVER_ATCMD 1 #define MG_ENABLE_TCPIP_DRIVER_INIT 0 #define MG_ENABLE_TCPIP_PRINT_DEBUG_STATS 0 #define MG_ENABLE_CUSTOM_MILLIS 1