Skip to content

Commit defbc89

Browse files
mshawcroftTomasz Bursztyka
authored andcommitted
net/dhcpv4: Use router option to set IPv4 GW.
Change-Id: I58f47c02665990dcb656f7e6f7802e1958b420a8 Signed-off-by: Marcus Shawcroft <[email protected]>
1 parent 065c84d commit defbc89

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

subsys/net/ip/dhcpv4.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,33 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
545545
NET_DBG("options_subnet_mask %s",
546546
net_sprint_ipv4_addr(&iface->ipv4.netmask));
547547
break;
548+
case DHCPV4_OPTIONS_ROUTER: {
549+
struct in_addr router;
550+
551+
/* Router option may present 1 or more
552+
* addresses for routers on the clients
553+
* subnet. Routers should be listed in order
554+
* of preference. Hence we choose the first
555+
* and skip the rest.
556+
*/
557+
if (length % 4 != 0 || length < 4) {
558+
NET_ERR("options_router, bad length");
559+
return NET_DROP;
560+
}
561+
562+
frag = net_nbuf_read(frag, pos, &pos, 4,
563+
router.s4_addr);
564+
frag = net_nbuf_skip(frag, pos, &pos, length - 4);
565+
if (!frag && pos) {
566+
NET_ERR("options_router, short packet");
567+
return NET_DROP;
568+
}
569+
570+
NET_DBG("options_router: %s",
571+
net_sprint_ipv4_addr(&router));
572+
net_if_ipv4_set_gw(iface, &router);
573+
break;
574+
}
548575
case DHCPV4_OPTIONS_LEASE_TIME:
549576
if (length != 4) {
550577
NET_ERR("options_lease_time, bad length");

0 commit comments

Comments
 (0)