Skip to content

Commit

Permalink
net: dhcp: avoid build warnings when event mgmt disabled
Browse files Browse the repository at this point in the history
If CONFIG_NET_MGMT_EVENT is not enabled then
net_mgmt_init_event_callback() is defined to a macro that ignores its
arguments, causing the callback structure and the handler to be unused
producing a build warning.

Signed-off-by: Peter Bigot <[email protected]>
  • Loading branch information
pabigot committed Mar 7, 2021
1 parent 1ce264e commit ea49d42
Showing 1 changed file with 8 additions and 0 deletions.
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;
}

0 comments on commit ea49d42

Please sign in to comment.