Skip to content

fix(lwip): forward-declare struct dhcp before DHCP extra-option hook (IDFGH-17738)#18668

Open
TeTeHacko wants to merge 1 commit into
espressif:masterfrom
TeTeHacko:fix/lwip-dhcp-extra-option-struct-forward-decl
Open

fix(lwip): forward-declare struct dhcp before DHCP extra-option hook (IDFGH-17738)#18668
TeTeHacko wants to merge 1 commit into
espressif:masterfrom
TeTeHacko:fix/lwip-dhcp-extra-option-struct-forward-decl

Conversation

@TeTeHacko
Copy link
Copy Markdown

Problem

When CONFIG_LWIP_HOOK_DHCP_EXTRA_OPTION_CUSTOM (or ..._DEFAULT) is
enabled, components/lwip/port/include/lwip_default_hooks.h declares:

void lwip_dhcp_on_extra_option(struct dhcp *dhcp, ...);

but struct dhcp is only forward-declared further down, inside the
#ifdef CONFIG_LWIP_IPV4 block — after this prototype. Every
translation unit that includes the header therefore declares struct dhcp
inside the parameter list, which GCC reports as:

error: 'struct dhcp' declared inside parameter list will not be visible
outside of this definition or declaration [-Werror]

The lwip component is built with -Werror, and this particular GCC
diagnostic has no individual -W flag, so it cannot be waived with
-Wno-error=.... The result: any project that enables the DHCP
extra-option hook fails to build.

Reproduction

  • ESP-IDF v6.0.1 and current master (GCC 13.2, xtensa-esp32s3)
  • CONFIG_LWIP_HOOK_DHCP_EXTRA_OPTION_CUSTOM=y with an app-provided
    lwip_dhcp_on_extra_option() implementation

Fix

Add a struct dhcp; forward declaration ahead of the prototype. A pointer
parameter only needs an incomplete type, so this is minimal and
sufficient. The redundant forward declaration inside CONFIG_LWIP_IPV4
is left untouched to keep the diff to a single added line.

When CONFIG_LWIP_HOOK_DHCP_EXTRA_OPTION_CUSTOM (or _DEFAULT) is enabled,
lwip_default_hooks.h declares

    void lwip_dhcp_on_extra_option(struct dhcp *dhcp, ...);

while `struct dhcp` is only forward-declared further down, inside the
`#ifdef CONFIG_LWIP_IPV4` block. Any translation unit that includes the
header therefore declares `struct dhcp` inside the parameter list, which
GCC reports as:

    error: 'struct dhcp' declared inside parameter list will not be
    visible outside of this definition or declaration [-Werror]

The lwip component is built with -Werror and this diagnostic has no
individual -W flag to waive, so every project enabling the DHCP
extra-option hook fails to build. Reproduced on ESP-IDF v6.0.1 and
current master (GCC 13.2, xtensa-esp32s3).

Add a `struct dhcp;` forward declaration ahead of the prototype. A
pointer parameter only needs an incomplete type, so this is minimal and
sufficient; the redundant forward decl inside CONFIG_LWIP_IPV4 is left
untouched.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 29, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot changed the title fix(lwip): forward-declare struct dhcp before DHCP extra-option hook fix(lwip): forward-declare struct dhcp before DHCP extra-option hook (IDFGH-17738) May 29, 2026
@espressif-bot espressif-bot added the Status: Opened Issue is new label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Opened Issue is new

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants