This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push: new 3e68694bd netutils/dhcpc: Set BOOTP BROADCAST flag when IPFORWARD is enabled 3e68694bd is described below commit 3e68694bdf312111fa99d096aca30dcda6fbeee3 Author: Zhe Weng <weng...@xiaomi.com> AuthorDate: Mon Jun 12 16:18:41 2023 +0800 netutils/dhcpc: Set BOOTP BROADCAST flag when IPFORWARD is enabled Socket binded to INADDR_ANY is not intended to receive unicast traffic before being fully configured, at least dhclient configured with socket-only won't do so on Linux and BSDs (https://github.com/isc-projects/dhcp/blob/v4_4_3/common/socket.c#L1201). We can sometimes receive unicast traffic before being fully configured, it's good, but not always, so we need to set the broadcast flag under some situations. Signed-off-by: Zhe Weng <weng...@xiaomi.com> --- netutils/dhcpc/Kconfig | 7 ++++++- netutils/dhcpc/dhcpc.c | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/netutils/dhcpc/Kconfig b/netutils/dhcpc/Kconfig index d82b1edf0..1016479a5 100644 --- a/netutils/dhcpc/Kconfig +++ b/netutils/dhcpc/Kconfig @@ -32,10 +32,15 @@ config NETUTILS_DHCPC_RETRIES config NETUTILS_DHCPC_BOOTP_FLAGS hex "Flags of Bootstrap" - default 0x0000 + default 0x0000 if !NET_IPFORWARD + default 0x8000 if NET_IPFORWARD ---help--- This setting to set the BOOTP broadcast flags. Reference RFC1542: Clarifications and Extensions for the Bootstrap Protocol. + Note: We're not always able to receive unicast traffic before + being fully configured, e.g. with forward enabled. Then we need + to enable the broadcast flag under these situations. + endif diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c index e716a9d4a..219ddfa87 100644 --- a/netutils/dhcpc/dhcpc.c +++ b/netutils/dhcpc/dhcpc.c @@ -267,8 +267,12 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, /* Broadcast DISCOVER message to all servers */ case DHCPDISCOVER: - /* REVISIT: We don't need the broadcast flag since we can receive - * unicast traffic before being fully configured. + /* Socket binded to INADDR_ANY is not intended to receive unicast + * traffic before being fully configured, at least dhclient + * configured with socket-only won't do so on Linux and BSDs. + * We can sometimes receive unicast traffic before being fully + * configured, it's good, but not always, so we need to set the + * broadcast flag under some situations. */ /* Broadcast bit. */ @@ -283,9 +287,6 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc, /* Send REQUEST message to the server that sent the *first* OFFER */ case DHCPREQUEST: - /* REVISIT: We don't need the broadcast flag since we can receive - * unicast traffic before being fully configured. - */ /* Broadcast bit. */