Skip to content

Commit dc862ec

Browse files
mshawcroftTomasz Bursztyka
authored andcommitted
net/dhcpv4: Use net_if_ipv4_set_netmask()
Use the interface function rather than writing directly to the iface structure. Check for errors in nbuf read. Change-Id: I75311755c2060b640325962ada28adea597cb914 Signed-off-by: Marcus Shawcroft <[email protected]>
1 parent defbc89 commit dc862ec

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

subsys/net/ip/dhcpv4.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,25 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
534534
}
535535

536536
switch (type) {
537-
case DHCPV4_OPTIONS_SUBNET_MASK:
537+
case DHCPV4_OPTIONS_SUBNET_MASK: {
538+
struct in_addr netmask;
539+
538540
if (length != 4) {
539541
NET_ERR("options_subnet_mask, bad length");
540542
return NET_DROP;
541543
}
542544

543545
frag = net_nbuf_read(frag, pos, &pos, length,
544-
iface->ipv4.netmask.s4_addr);
546+
netmask.s4_addr);
547+
if (!frag && pos) {
548+
NET_ERR("options_subnet_mask, short packet");
549+
return NET_DROP;
550+
}
551+
net_if_ipv4_set_netmask(iface, &netmask);
545552
NET_DBG("options_subnet_mask %s",
546-
net_sprint_ipv4_addr(&iface->ipv4.netmask));
553+
net_sprint_ipv4_addr(&netmask));
547554
break;
555+
}
548556
case DHCPV4_OPTIONS_ROUTER: {
549557
struct in_addr router;
550558

0 commit comments

Comments
 (0)