diff --git a/mongoose.c b/mongoose.c index d26443ad..4a805831 100644 --- a/mongoose.c +++ b/mongoose.c @@ -6832,6 +6832,8 @@ static void onstatechange(struct mg_tcpip_if *ifp) { if (ifp->l2type == MG_TCPIP_L2_ETH || ifp->l2type == MG_TCPIP_L2_PPPoE) // TODO(): print other l2 MG_INFO((" MAC: %M", mg_print_mac, ifp->mac)); + if (ifp->l2type == MG_TCPIP_L2_ETH) + mg_tcpip_arp_request(ifp, ifp->ip, ifp->mac); // gratuitous ARP annc } else if (ifp->state == MG_TCPIP_STATE_IP) { if (ifp->gw != 0 && ifp->l2type == MG_TCPIP_L2_ETH) mg_tcpip_arp_request(ifp, ifp->gw, NULL); // unsolicited GW ARP request @@ -7502,6 +7504,19 @@ static void onstate6change(struct mg_tcpip_if *ifp) { MG_INFO((" GW: %M", mg_print_ip6, &ifp->gw6)); if (ifp->l2type == MG_TCPIP_L2_ETH) // TODO(): print other l2 MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac)); + if (ifp->l2type == MG_TCPIP_L2_ETH) { // gratuitous NA annc + tx_ndp_na(ifp, // RFC-4861 7.2.6 + mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, + (struct mg_addr *) &ip6_allnodes), + ifp->ip6ll, (uint64_t *) ip6_allnodes.addr.ip6, false, + ifp->mac); + if (ifp->ip6[0] != 0 && ifp->ip6[1] != 0) + tx_ndp_na(ifp, // RFC-9131 4.1 + mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, + (struct mg_addr *) &ip6_allrouters), + ifp->ip6, (uint64_t *) ip6_allrouters.addr.ip6, false, + ifp->mac); + } } else if (ifp->state6 == MG_TCPIP_STATE_IP) { if ((ifp->gw6[0] != 0 || ifp->gw6[1] != 0) && (ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE)) tx_ndp_ns(ifp, ifp->gw6, NULL); // unsolicited GW hwaddr resolution diff --git a/src/net_builtin.c b/src/net_builtin.c index 10c26da5..faca0f31 100644 --- a/src/net_builtin.c +++ b/src/net_builtin.c @@ -389,6 +389,8 @@ static void onstatechange(struct mg_tcpip_if *ifp) { if (ifp->l2type == MG_TCPIP_L2_ETH || ifp->l2type == MG_TCPIP_L2_PPPoE) // TODO(): print other l2 MG_INFO((" MAC: %M", mg_print_mac, ifp->mac)); + if (ifp->l2type == MG_TCPIP_L2_ETH) + mg_tcpip_arp_request(ifp, ifp->ip, ifp->mac); // gratuitous ARP annc } else if (ifp->state == MG_TCPIP_STATE_IP) { if (ifp->gw != 0 && ifp->l2type == MG_TCPIP_L2_ETH) mg_tcpip_arp_request(ifp, ifp->gw, NULL); // unsolicited GW ARP request @@ -1059,6 +1061,19 @@ static void onstate6change(struct mg_tcpip_if *ifp) { MG_INFO((" GW: %M", mg_print_ip6, &ifp->gw6)); if (ifp->l2type == MG_TCPIP_L2_ETH) // TODO(): print other l2 MG_INFO((" MAC: %M", mg_print_mac, &ifp->mac)); + if (ifp->l2type == MG_TCPIP_L2_ETH) { // gratuitous NA annc + tx_ndp_na(ifp, // RFC-4861 7.2.6 + mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, + (struct mg_addr *) &ip6_allnodes), + ifp->ip6ll, (uint64_t *) ip6_allnodes.addr.ip6, false, + ifp->mac); + if (ifp->ip6[0] != 0 && ifp->ip6[1] != 0) + tx_ndp_na(ifp, // RFC-9131 4.1 + mg_l2_mapip(ifp->l2type, MG_TCPIP_L2ADDR_MCAST6, + (struct mg_addr *) &ip6_allrouters), + ifp->ip6, (uint64_t *) ip6_allrouters.addr.ip6, false, + ifp->mac); + } } else if (ifp->state6 == MG_TCPIP_STATE_IP) { if ((ifp->gw6[0] != 0 || ifp->gw6[1] != 0) && (ifp->l2type != MG_TCPIP_L2_PPP && ifp->l2type != MG_TCPIP_L2_PPPoE)) tx_ndp_ns(ifp, ifp->gw6, NULL); // unsolicited GW hwaddr resolution diff --git a/test/mip_test.c b/test/mip_test.c index 06ecfc63..ca63981b 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -62,7 +62,7 @@ static bool executed = false; static void mif_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { if (ev == MG_TCPIP_EV_ST_CHG) { - ASSERT(*(uint8_t *) ev_data == MG_TCPIP_STATE_READY); + ASSERT(*(uint8_t *) ev_data == MG_TCPIP_STATE_UP); executed = true; } (void) ifp; @@ -72,7 +72,7 @@ static void test_statechange(void) { struct mg_tcpip_if iface; memset(&iface, 0, sizeof(iface)); iface.ip = mg_htonl(0x01020304); - iface.state = MG_TCPIP_STATE_READY; + iface.state = MG_TCPIP_STATE_UP; // READY now sends gratuitous ARP iface.driver = &mg_tcpip_driver_mock; iface.fn = mif_fn; onstatechange(&iface); @@ -82,7 +82,7 @@ static void test_statechange(void) { #if MG_ENABLE_IPV6 static void mif6_fn(struct mg_tcpip_if *ifp, int ev, void *ev_data) { if (ev == MG_TCPIP_EV_ST6_CHG) { - ASSERT(*(uint8_t *) ev_data == MG_TCPIP_STATE_READY); + ASSERT(*(uint8_t *) ev_data == MG_TCPIP_STATE_REQ); executed = true; } (void) ifp; @@ -93,7 +93,7 @@ static void test_state6change(void) { memset(&iface, 0, sizeof(iface)); iface.ip6[0] = mg_htonll(0x01020304); iface.ip6[1] = mg_htonll(0x05060708); - iface.state6 = MG_TCPIP_STATE_READY; + iface.state6 = MG_TCPIP_STATE_REQ; // READY now sends gratuitous NA, > UP iface.driver = &mg_tcpip_driver_mock; iface.fn = mif6_fn; onstate6change(&iface);