From fc0be1da93a3fd15eba8bf743af08211adf5c203 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 13 May 2024 10:32:58 +0200 Subject: [PATCH] tests: net: dhcpv6: Reapply LL address on iface up The test suite assigns LL address to the interface manually, hence need to reapply it whenever interface goes up. Signed-off-by: Robert Lubos --- tests/net/dhcpv6/src/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/net/dhcpv6/src/main.c b/tests/net/dhcpv6/src/main.c index ace0a0128c2ff5..c5046a2746a215 100644 --- a/tests/net/dhcpv6/src/main.c +++ b/tests/net/dhcpv6/src/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "../../../subsys/net/lib/dhcpv6/dhcpv6.c" @@ -18,6 +19,7 @@ static struct in6_addr test_prefix = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, static uint8_t test_prefix_len = 64; static uint8_t test_preference; static struct net_dhcpv6_duid_storage test_serverid; +static struct net_mgmt_event_callback net_mgmt_cb; typedef void (*test_dhcpv6_pkt_fn_t)(struct net_if *iface, struct net_pkt *pkt); @@ -176,6 +178,19 @@ static struct net_pkt *test_dhcpv6_create_message( return NULL; } +static void evt_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, + struct net_if *iface) +{ + ARG_UNUSED(cb); + + if (mgmt_event == NET_EVENT_IF_UP) { + struct in6_addr lladdr; + + net_ipv6_addr_create_iid(&lladdr, net_if_get_link_addr(test_ctx.iface)); + (void)net_if_ipv6_addr_add(test_ctx.iface, &lladdr, NET_ADDR_AUTOCONF, 0); + } +} + static void *dhcpv6_tests_setup(void) { struct in6_addr lladdr; @@ -190,6 +205,9 @@ static void *dhcpv6_tests_setup(void) generate_fake_server_duid(); + net_mgmt_init_event_callback(&net_mgmt_cb, evt_handler, NET_EVENT_IF_UP); + net_mgmt_add_event_callback(&net_mgmt_cb); + return NULL; }