Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys: make auto init default with DHCPv6 client #21178

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ ifneq (,$(filter dhcpv6_%,$(USEMODULE)))
endif

ifneq (,$(filter dhcpv6_client,$(USEMODULE)))
DEFAULT_MODULE += auto_init_dhcpv6_client
USEMODULE += event
USEMODULE += event_timeout
ifneq (,$(filter ztimer,$(USEMODULE)))
Expand Down
6 changes: 3 additions & 3 deletions sys/auto_init/include/auto_init_priorities.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,19 @@ extern "C" {
/**
* @brief DHCPv6 client priority
*/
#define AUTO_INIT_PRIO_MOD_DHCPV6_CLIENT 1470
#define AUTO_INIT_PRIO_MOD_DHCPV6_CLIENT 1480
#endif
#ifndef AUTO_INIT_PRIO_MOD_DHCPV6_RELAY
/**
* @brief DHCPv6 relay priority
*/
#define AUTO_INIT_PRIO_MOD_DHCPV6_RELAY 1480
#define AUTO_INIT_PRIO_MOD_DHCPV6_RELAY 1490
#endif
#ifndef AUTO_INIT_PRIO_MOD_DHCPV6_CLIENT_SIMPLE_PD
/**
* @brief DHCPv6 client simple PD priority
*/
#define AUTO_INIT_PRIO_MOD_DHCPV6_CLIENT_SIMPLE_PD 1490
#define AUTO_INIT_PRIO_MOD_DHCPV6_CLIENT_SIMPLE_PD 1470
#endif
#ifndef AUTO_INIT_PRIO_MOD_GNRC_IPV6_AUTO_SUBNETS
/**
Expand Down
10 changes: 10 additions & 0 deletions sys/include/net/dhcpv6/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ typedef struct __attribute__((packed)) {
} dhcpv6_duid_l2_t;

#if defined(MODULE_AUTO_INIT_DHCPV6_CLIENT) || defined(DOXYGEN)
/**
* @brief Configure a hook function to be executed during dhcpv6 client's
* auto init.
*
* @param[in] _hook The hook function to be called during auto init.
* @param[in] netif The network interface the client should listen on.
* SOCK_ADDR_ANY_NETIF for any interface
*/
void dhcpv6_client_set_init_hook(void (*_hook)(void), uint16_t netif);

/**
* @brief Auto-initializes the client in its own thread
*
Expand Down
25 changes: 24 additions & 1 deletion sys/net/application_layer/dhcpv6/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ static char _thread_stack[DHCPV6_CLIENT_STACK_SIZE];
static void *_thread(void *args);
static kernel_pid_t _thread_pid;

static void (*_init_hook)(void) = NULL;
static uint16_t _dhcpv6_netif = SOCK_ADDR_ANY_NETIF;

void dhcpv6_client_set_init_hook(void (*_hook)(void), uint16_t netif)
{
/* set hook function to call during auto init */
_init_hook = _hook;
/* specify interface to use for DHCPv6 */
_dhcpv6_netif = netif;
}

void dhcpv6_client_auto_init(void)
{
if (_thread_pid <= 0) {
Expand All @@ -145,9 +156,21 @@ static void *_thread(void *args)
{
(void)args;
event_queue_t auto_init_event_queue;
/* initialize client event queue */
event_queue_init(&auto_init_event_queue);
dhcpv6_client_init(&auto_init_event_queue, SOCK_ADDR_ANY_NETIF);
/* initialize DHCPv6 client either on any interface or
* (if configured via the init hook) a specific one */
dhcpv6_client_init(&auto_init_event_queue, _dhcpv6_netif);

/* execute init hook if set */
if (_init_hook != NULL)
{
_init_hook();
}

/* start DHCPv6 client */
dhcpv6_client_start();
/* start event loop of DHCPv6 client */
event_loop(&auto_init_event_queue); /* never returns */
return NULL;
}
Expand Down
41 changes: 10 additions & 31 deletions sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@

#include "net/gnrc/dhcpv6/client/simple_pd.h"

#if IS_USED(MODULE_AUTO_INIT_DHCPV6_CLIENT)
#error "Module `gnrc_dhcpv6_client_simple_pd` is mutually exclusive to \
`auto_init_dhcpv6_client`"
#endif

static char _stack[DHCPV6_CLIENT_STACK_SIZE];

/**
* @brief Find upstream network interface
*
Expand Down Expand Up @@ -123,39 +116,25 @@
/**
* @brief The DHCPv6 client thread
*/
static void *_dhcpv6_cl_simple_pd_thread(void *args)
static void _dhcpv6_client_simple_pd_init_hook(void)
{
event_queue_t event_queue;
gnrc_netif_t *upstream_netif = _find_upstream_netif();

(void)args;
if (upstream_netif == NULL) {
LOG_ERROR("DHCPv6: No upstream interface found!\n");
return NULL;
}
_configure_upstream_netif(upstream_netif);
/* initialize client event queue */
event_queue_init(&event_queue);
/* initialize DHCPv6 client on border interface */
dhcpv6_client_init(&event_queue, upstream_netif->pid);
/* configure client to request prefix delegation for WPAN interfaces */
_configure_dhcpv6_client();
/* set client configuration mode to stateful */
dhcpv6_client_set_conf_mode(DHCPV6_CLIENT_CONF_MODE_STATEFUL);
/* start DHCPv6 client */
dhcpv6_client_start();
/* start event loop of DHCPv6 client */
event_loop(&event_queue); /* never returns */
return NULL;
}

void gnrc_dhcpv6_client_simple_pd_init(void)
{
/* start DHCPv6 client thread to request prefix for WPAN */
thread_create(_stack, DHCPV6_CLIENT_STACK_SIZE,
DHCPV6_CLIENT_PRIORITY,
0,
_dhcpv6_cl_simple_pd_thread, NULL, "dhcpv6-client");
gnrc_netif_t *upstream_netif = _find_upstream_netif();

if (upstream_netif == NULL) {
LOG_ERROR("DHCPv6: No upstream interface found!\n");
return ;

Check warning on line 133 in sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c

View workflow job for this annotation

GitHub Actions / static-tests

semicolon is isolated from other tokens
}
_configure_upstream_netif(upstream_netif);

dhcpv6_client_set_init_hook(_dhcpv6_client_simple_pd_init_hook, upstream_netif->pid);
}

/** @} */