Skip to content

Commit

Permalink
tests: net: dhcpv6: Reapply LL address on iface up
Browse files Browse the repository at this point in the history
The test suite assigns LL address to the interface manually, hence need
to reapply it whenever interface goes up.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
  • Loading branch information
rlubos committed May 13, 2024
1 parent 90c6940 commit fc0be1d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/net/dhcpv6/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <zephyr/net/dummy.h>
#include <zephyr/net/ethernet.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_mgmt.h>

#include "../../../subsys/net/lib/dhcpv6/dhcpv6.c"

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit fc0be1d

Please sign in to comment.