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 <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-03-06 18:14:21 +02:00 committed by Carles Cufí
parent 223e81b968
commit 7072e75162
2 changed files with 9 additions and 3 deletions

View File

@ -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.

View File

@ -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;