From 40c9dc8320f6985098163a3447106880c53e3366 Mon Sep 17 00:00:00 2001 From: xnumad <34810600+xnumad@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:33:40 +0200 Subject: [PATCH] tests/gnrc_ipv6_nib: rtr_ltime test: Test before removing from DRL Keep testing for options before removing default router --- tests/net/gnrc_ipv6_nib/main.c | 96 ++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/tests/net/gnrc_ipv6_nib/main.c b/tests/net/gnrc_ipv6_nib/main.c index 8d1f0d8e9e..212dcd3c57 100644 --- a/tests/net/gnrc_ipv6_nib/main.c +++ b/tests/net/gnrc_ipv6_nib/main.c @@ -1046,13 +1046,15 @@ static void test_handle_pkt__rtr_adv__invalid_opt_len(void) TEST_ASSERT_EQUAL_INT(0, msg_avail()); } +static void test_handle_pkt__rtr_adv__options_success(bool sl2ao, bool mtuo, bool pio, + uint8_t pio_flags, unsigned exp_addr_count, + _netif_exp_t exp_netif, bool is_first_check); + static void test_handle_pkt__rtr_adv__success(uint8_t rtr_adv_flags, bool set_rtr_adv_fields, bool sl2ao, bool mtuo, bool pio, uint8_t pio_flags) { - gnrc_ipv6_nib_pl_t prefix; - gnrc_ipv6_nib_nc_t nce; gnrc_ipv6_nib_ft_t route; void *state = NULL; size_t icmpv6_len = _set_rtr_adv(&_rem_ll, NDP_HOP_LIMIT, 0U, @@ -1101,6 +1103,8 @@ static void test_handle_pkt__rtr_adv__success(uint8_t rtr_adv_flags, TEST_ASSERT_EQUAL_INT(exp_netif.cur_hl, _mock_netif->cur_hl); } + test_handle_pkt__rtr_adv__options_success(sl2ao, mtuo, pio, pio_flags, exp_addr_count, exp_netif, true); + { /* * > The Router Lifetime applies only to @@ -1108,10 +1112,9 @@ static void test_handle_pkt__rtr_adv__success(uint8_t rtr_adv_flags, does not apply to information contained in other message fields or options. * - https://datatracker.ietf.org/doc/html/rfc4861#section-4.2 - * So (after default router list was tested), - * send a RA with Router Lifetime value of zero. + * So send a RA with Router Lifetime value of zero, * to test that _handle_rtr_timeout follows this behavior. - * If it doesn't, the following tests for RA options will fail. + * If it doesn't, the following tests for RA options again will fail. */ icmpv6_len = _set_rtr_adv(&_rem_ll, NDP_HOP_LIMIT, 0U, false, 0U, @@ -1125,7 +1128,18 @@ static void test_handle_pkt__rtr_adv__success(uint8_t rtr_adv_flags, rtr_adv->ltime = byteorder_htons(0); gnrc_ipv6_nib_handle_pkt(_mock_netif, ipv6, icmpv6, icmpv6_len); } - state = NULL; + test_handle_pkt__rtr_adv__options_success(sl2ao, mtuo, pio, pio_flags, exp_addr_count, exp_netif, false); +} + +static void test_handle_pkt__rtr_adv__options_success(bool sl2ao, bool mtuo, bool pio, + uint8_t pio_flags, + const unsigned exp_addr_count, + _netif_exp_t exp_netif, bool is_first_check) +{ + gnrc_ipv6_nib_pl_t prefix; + gnrc_ipv6_nib_nc_t nce; + void *state = NULL; + if (sl2ao) { TEST_ASSERT_MESSAGE(gnrc_ipv6_nib_nc_iter(0, &state, &nce), "No neighbor cache entry found"); @@ -1163,40 +1177,42 @@ static void test_handle_pkt__rtr_adv__success(uint8_t rtr_adv_flags, &_loc_gb) >= 0, "Address was not configured by PIO"); - /* Check if SLAAC generated a neighbor solicitation */ - TEST_ASSERT_EQUAL_INT(1, msg_avail()); - msg_receive(&msg); - TEST_ASSERT_EQUAL_INT(GNRC_NETAPI_MSG_TYPE_SND, msg.type); - pkt = msg.content.ptr; - /* first snip is a netif header to _mock_netif */ - TEST_ASSERT_NOT_NULL(pkt); - TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_NETIF, pkt->type); - TEST_ASSERT(sizeof(gnrc_netif_hdr_t) <= pkt->size); - netif_hdr = pkt->data; - TEST_ASSERT_EQUAL_INT(_mock_netif->pid, netif_hdr->if_pid); - /* second snip is an IPv6 header to solicited nodes of _loc_gb */ - TEST_ASSERT_NOT_NULL(pkt->next); - TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_IPV6, pkt->next->type); - TEST_ASSERT_EQUAL_INT(sizeof(ipv6_hdr_t), pkt->next->size); - ipv6_hdr = pkt->next->data; - TEST_ASSERT_MESSAGE(ipv6_addr_equal(&ipv6_hdr->dst, - &_loc_sol_nodes), - "ipv6_hdr->dst != _loc_sol_nodes"); - TEST_ASSERT_EQUAL_INT(255, ipv6_hdr->hl); - /* third snip is a valid solicited neighbor solicitation to - * _loc_gb */ - TEST_ASSERT_NOT_NULL(pkt->next->next); - TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_ICMPV6, pkt->next->next->type); - TEST_ASSERT_EQUAL_INT(sizeof(ndp_nbr_sol_t), pkt->next->next->size); - nbr_sol = pkt->next->next->data; - TEST_ASSERT_EQUAL_INT(ICMPV6_NBR_SOL, nbr_sol->type); - TEST_ASSERT_EQUAL_INT(0, nbr_sol->code); - TEST_ASSERT(!ipv6_addr_is_multicast(&nbr_sol->tgt)); - TEST_ASSERT_MESSAGE(ipv6_addr_equal(&_loc_gb, &nbr_sol->tgt), - "_loc_gb != nbr_sol->tgt"); - /* no further options */ - TEST_ASSERT_NULL(pkt->next->next->next); - gnrc_pktbuf_release(pkt); + if (is_first_check) { + /* Check if SLAAC generated a neighbor solicitation */ + TEST_ASSERT_EQUAL_INT(1, msg_avail()); + msg_receive(&msg); + TEST_ASSERT_EQUAL_INT(GNRC_NETAPI_MSG_TYPE_SND, msg.type); + pkt = msg.content.ptr; + /* first snip is a netif header to _mock_netif */ + TEST_ASSERT_NOT_NULL(pkt); + TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_NETIF, pkt->type); + TEST_ASSERT(sizeof(gnrc_netif_hdr_t) <= pkt->size); + netif_hdr = pkt->data; + TEST_ASSERT_EQUAL_INT(_mock_netif->pid, netif_hdr->if_pid); + /* second snip is an IPv6 header to solicited nodes of _loc_gb */ + TEST_ASSERT_NOT_NULL(pkt->next); + TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_IPV6, pkt->next->type); + TEST_ASSERT_EQUAL_INT(sizeof(ipv6_hdr_t), pkt->next->size); + ipv6_hdr = pkt->next->data; + TEST_ASSERT_MESSAGE(ipv6_addr_equal(&ipv6_hdr->dst, + &_loc_sol_nodes), + "ipv6_hdr->dst != _loc_sol_nodes"); + TEST_ASSERT_EQUAL_INT(255, ipv6_hdr->hl); + /* third snip is a valid solicited neighbor solicitation to + * _loc_gb */ + TEST_ASSERT_NOT_NULL(pkt->next->next); + TEST_ASSERT_EQUAL_INT(GNRC_NETTYPE_ICMPV6, pkt->next->next->type); + TEST_ASSERT_EQUAL_INT(sizeof(ndp_nbr_sol_t), pkt->next->next->size); + nbr_sol = pkt->next->next->data; + TEST_ASSERT_EQUAL_INT(ICMPV6_NBR_SOL, nbr_sol->type); + TEST_ASSERT_EQUAL_INT(0, nbr_sol->code); + TEST_ASSERT(!ipv6_addr_is_multicast(&nbr_sol->tgt)); + TEST_ASSERT_MESSAGE(ipv6_addr_equal(&_loc_gb, &nbr_sol->tgt), + "_loc_gb != nbr_sol->tgt"); + /* no further options */ + TEST_ASSERT_NULL(pkt->next->next->next); + gnrc_pktbuf_release(pkt); + } } else { TEST_ASSERT_MESSAGE(gnrc_netif_ipv6_addr_idx(_mock_netif,