dhcpd: Supports kernel mode compilation

The previous method of terminating the dhcp daemon via a global variable has been removed; instead, the `kill pid` command is used. Also, because the original `dhcp_start` method creates tasks via `task_create`, which is not supported in kernel mode, `dhcp_start` is not compiled in kernel mode. The daemon can be started in kernel mode using `dhcpd xxx &`.

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
This commit is contained in:
zhangshuai39 2025-08-07 14:33:52 +08:00 • committed by Alan C. Assis
parent 9ad4c3c395
commit 6830e297cf
4 changed files with 135 additions and 77 deletions

View file

@ -30,23 +30,27 @@ if(CONFIG_EXAMPLES_DHCPD)
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE})
nuttx_add_application(
NAME
dhcpd_start
SRCS
dhcpd_start.c
dhcpd_daemon.c
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE})
if(NOT CONFIG_BUILD_KERNEL)
nuttx_add_application(
NAME
dhcpd_start
SRCS
dhcpd_start.c
dhcpd_daemon.c
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE})
endif()
nuttx_add_application(
NAME
dhcpd_stop
SRCS
dhcpd_stop.c
dhcpd_daemon.c
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE})
if(CONFIG_SCHED_WAITPID)
nuttx_add_application(
NAME
dhcpd_stop
SRCS
dhcpd_stop.c
dhcpd_daemon.c
STACKSIZE
${CONFIG_DEFAULT_TASK_STACKSIZE})
endif()
add_definitions(-DCONFIG_NETUTILS_DHCPD_HOST=1 -DHAVE_SO_REUSEADDR=1
-DHAVE_SO_BROADCAST=1)

View file

@ -26,13 +26,23 @@ include $(APPDIR)/Make.defs
CSRCS = dhcpd_daemon.c
MAINSRC = dhcpd_start.c dhcpd_stop.c target.c
MAINSRC = target.c
# DHCPD built-in application info
PROGNAME = dhcpd_start dhcpd_stop dhcpd
PROGNAME = dhcpd
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_DHCPD)
ifneq ($(CONFIG_BUILD_KERNEL),y)
MAINSRC += dhcpd_start.c
PROGNAME += dhcpd_start
endif
ifeq ($(CONFIG_SCHED_WAITPID),y)
MAINSRC += dhcpd_stop.c
PROGNAME += dhcpd_stop
endif
include $(APPDIR)/Application.mk

View file

@ -128,10 +128,12 @@ int dhcpd_daemon(int argc, FAR char *argv[], bool daemon)
/* Then start the dhcpd */
if (daemon)
#ifndef CONFIG_BUILD_KERNEL
if (!daemon)
{
return dhcpd_run(devname);
return dhcpd_start(devname);
}
#endif
return dhcpd_start(devname);
return dhcpd_run(devname);
}