Skip to content

Commit 065c84d

Browse files
mshawcroftTomasz Bursztyka
authored andcommitted
dhcpv4: Add option parsing diagnostics.
Change-Id: I81a4fa5df561217bfae0d48eb458bf45cfe55d16 Signed-off-by: Marcus Shawcroft <[email protected]>
1 parent 739278e commit 065c84d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

subsys/net/ip/dhcpv4.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,64 +522,80 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
522522
frag = net_nbuf_read_u8(frag, pos, &pos, &type);
523523

524524
if (type == DHCPV4_OPTIONS_END) {
525+
NET_DBG("options_end");
525526
end = true;
526527
return NET_OK;
527528
}
528529

529530
frag = net_nbuf_read_u8(frag, pos, &pos, &length);
530531
if (!frag) {
532+
NET_ERR("option parsing, bad length");
531533
return NET_DROP;
532534
}
533535

534536
switch (type) {
535537
case DHCPV4_OPTIONS_SUBNET_MASK:
536538
if (length != 4) {
539+
NET_ERR("options_subnet_mask, bad length");
537540
return NET_DROP;
538541
}
539542

540543
frag = net_nbuf_read(frag, pos, &pos, length,
541544
iface->ipv4.netmask.s4_addr);
545+
NET_DBG("options_subnet_mask %s",
546+
net_sprint_ipv4_addr(&iface->ipv4.netmask));
542547
break;
543548
case DHCPV4_OPTIONS_LEASE_TIME:
544549
if (length != 4) {
550+
NET_ERR("options_lease_time, bad length");
545551
return NET_DROP;
546552
}
547553

548554
frag = net_nbuf_read_be32(frag, pos, &pos,
549555
&iface->dhcpv4.lease_time);
556+
NET_DBG("options_lease_time: %u",
557+
iface->dhcpv4.lease_time);
550558
if (!iface->dhcpv4.lease_time) {
551559
return NET_DROP;
552560
}
553561

554562
break;
555563
case DHCPV4_OPTIONS_RENEWAL:
556564
if (length != 4) {
565+
NET_DBG("options_renewal, bad length");
557566
return NET_DROP;
558567
}
559568

560569
frag = net_nbuf_read_be32(frag, pos, &pos,
561570
&iface->dhcpv4.renewal_time);
571+
NET_DBG("options_renewal: %u",
572+
iface->dhcpv4.renewal_time);
562573
if (!iface->dhcpv4.renewal_time) {
563574
return NET_DROP;
564575
}
565576

566577
break;
567578
case DHCPV4_OPTIONS_SERVER_ID:
568579
if (length != 4) {
580+
NET_DBG("options_server_id, bad length");
569581
return NET_DROP;
570582
}
571583

572584
frag = net_nbuf_read(frag, pos, &pos, length,
573585
iface->dhcpv4.server_id.s4_addr);
586+
NET_DBG("options_server_id: %s",
587+
net_sprint_ipv4_addr(&iface->dhcpv4.server_id));
574588
break;
575589
case DHCPV4_OPTIONS_MSG_TYPE:
576590
if (length != 1) {
591+
NET_DBG("options_msg_type, bad length");
577592
return NET_DROP;
578593
}
579594

580595
frag = net_nbuf_read_u8(frag, pos, &pos, msg_type);
581596
break;
582597
default:
598+
NET_DBG("option unknown: %d", type);
583599
frag = net_nbuf_skip(frag, pos, &pos, length);
584600
break;
585601
}

0 commit comments

Comments
 (0)