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

net: dhcp: avoid build warnings when event mgmt disabled #33105

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions subsys/net/ip/dhcpv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ LOG_MODULE_REGISTER(net_dhcpv4, CONFIG_NET_DHCPV4_LOG_LEVEL);
static sys_slist_t dhcpv4_ifaces;
static struct k_delayed_work timeout_work;

#ifdef CONFIG_NET_MGMT_EVENT
static struct net_mgmt_event_callback mgmt4_cb;
#endif /* CONFIG_NET_MGMT_EVENT */

/* RFC 1497 [17] */
static const uint8_t magic_cookie[4] = { 0x63, 0x82, 0x53, 0x63 };
Expand Down Expand Up @@ -276,13 +278,15 @@ static struct net_pkt *dhcpv4_create_message(struct net_if *iface, uint8_t type,
return NULL;
}

#ifdef CONFIG_NET_MGMT_EVENT
static void dhcpv4_immediate_timeout(struct net_if_dhcpv4 *dhcpv4)
{
NET_DBG("force timeout dhcpv4=%p", dhcpv4);
dhcpv4->timer_start = k_uptime_get() - 1;
dhcpv4->request_time = 0U;
k_delayed_work_submit(&timeout_work, K_NO_WAIT);
}
#endif /* CONFIG_NET_MGMT_EVENT */

static void dhcpv4_set_timeout(struct net_if_dhcpv4 *dhcpv4,
uint32_t timeout)
Expand Down Expand Up @@ -1066,6 +1070,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
return NET_OK;
}

#ifdef CONFIG_NET_MGMT_EVENT
static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb,
uint32_t mgmt_event, struct net_if *iface)
{
Expand Down Expand Up @@ -1101,6 +1106,7 @@ static void dhcpv4_iface_event_handler(struct net_mgmt_event_callback *cb,
dhcpv4_immediate_timeout(&iface->config.dhcpv4);
}
}
#endif /* CONFIG_NET_MGMT_EVENT */

const char *net_dhcpv4_state_name(enum net_dhcpv4_state state)
{
Expand Down Expand Up @@ -1237,11 +1243,13 @@ int net_dhcpv4_init(void)

k_delayed_work_init(&timeout_work, dhcpv4_timeout);

#ifdef CONFIG_NET_MGMT_EVENT
/* Catch network interface UP or DOWN events and renew the address
* if interface is coming back up again.
*/
net_mgmt_init_event_callback(&mgmt4_cb, dhcpv4_iface_event_handler,
NET_EVENT_IF_DOWN | NET_EVENT_IF_UP);
#endif /* CONFIG_NET_MGMT_EVENT */

return 0;
}