From 7072e75162452bf8a7a5cf04a4e1552b7371ec35 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Wed, 6 Mar 2024 18:14:21 +0200 Subject: [PATCH] net: dhcpv4: Network interface netmask was set too early When we receive the subnet mask option from the server, we cannot yet set the netmask to the network interface as the mask is tied to the IP address we received from the server. We need to delay the setting of netmask until we have added the requested IP address to the interface. Signed-off-by: Jukka Rissanen --- include/zephyr/net/net_if.h | 3 +++ subsys/net/lib/dhcpv4/dhcpv4.c | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/zephyr/net/net_if.h b/include/zephyr/net/net_if.h index fabd2cc5f89..bab22da1c05 100644 --- a/include/zephyr/net/net_if.h +++ b/include/zephyr/net/net_if.h @@ -425,6 +425,9 @@ struct net_if_dhcpv4 { /** Requested IP addr */ struct in_addr requested_ip; + /** Received netmask from the server */ + struct in_addr netmask; + /** * DHCPv4 client state in the process of network * address allocation. diff --git a/subsys/net/lib/dhcpv4/dhcpv4.c b/subsys/net/lib/dhcpv4/dhcpv4.c index 25f84b04e57..b278d95401f 100644 --- a/subsys/net/lib/dhcpv4/dhcpv4.c +++ b/subsys/net/lib/dhcpv4/dhcpv4.c @@ -902,9 +902,8 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt, return false; } - net_if_ipv4_set_netmask_by_addr(iface, - &iface->config.dhcpv4.requested_ip, - &netmask); + iface->config.dhcpv4.netmask = netmask; + NET_DBG("options_subnet_mask %s", net_sprint_ipv4_addr(&netmask)); break; @@ -1206,6 +1205,10 @@ static void dhcpv4_handle_msg_ack(struct net_if *iface) return; } + net_if_ipv4_set_netmask_by_addr(iface, + &iface->config.dhcpv4.requested_ip, + &iface->config.dhcpv4.netmask); + dhcpv4_enter_bound(iface); break;