dhcpv4: Add option parsing diagnostics.
Change-Id: I81a4fa5df561217bfae0d48eb458bf45cfe55d16 Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>
This commit is contained in:
parent
739278e09d
commit
065c84d5a6
1 changed files with 16 additions and 0 deletions
|
@ -522,31 +522,39 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
|
||||||
frag = net_nbuf_read_u8(frag, pos, &pos, &type);
|
frag = net_nbuf_read_u8(frag, pos, &pos, &type);
|
||||||
|
|
||||||
if (type == DHCPV4_OPTIONS_END) {
|
if (type == DHCPV4_OPTIONS_END) {
|
||||||
|
NET_DBG("options_end");
|
||||||
end = true;
|
end = true;
|
||||||
return NET_OK;
|
return NET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_nbuf_read_u8(frag, pos, &pos, &length);
|
frag = net_nbuf_read_u8(frag, pos, &pos, &length);
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
|
NET_ERR("option parsing, bad length");
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DHCPV4_OPTIONS_SUBNET_MASK:
|
case DHCPV4_OPTIONS_SUBNET_MASK:
|
||||||
if (length != 4) {
|
if (length != 4) {
|
||||||
|
NET_ERR("options_subnet_mask, bad length");
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_nbuf_read(frag, pos, &pos, length,
|
frag = net_nbuf_read(frag, pos, &pos, length,
|
||||||
iface->ipv4.netmask.s4_addr);
|
iface->ipv4.netmask.s4_addr);
|
||||||
|
NET_DBG("options_subnet_mask %s",
|
||||||
|
net_sprint_ipv4_addr(&iface->ipv4.netmask));
|
||||||
break;
|
break;
|
||||||
case DHCPV4_OPTIONS_LEASE_TIME:
|
case DHCPV4_OPTIONS_LEASE_TIME:
|
||||||
if (length != 4) {
|
if (length != 4) {
|
||||||
|
NET_ERR("options_lease_time, bad length");
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_nbuf_read_be32(frag, pos, &pos,
|
frag = net_nbuf_read_be32(frag, pos, &pos,
|
||||||
&iface->dhcpv4.lease_time);
|
&iface->dhcpv4.lease_time);
|
||||||
|
NET_DBG("options_lease_time: %u",
|
||||||
|
iface->dhcpv4.lease_time);
|
||||||
if (!iface->dhcpv4.lease_time) {
|
if (!iface->dhcpv4.lease_time) {
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
@ -554,11 +562,14 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
|
||||||
break;
|
break;
|
||||||
case DHCPV4_OPTIONS_RENEWAL:
|
case DHCPV4_OPTIONS_RENEWAL:
|
||||||
if (length != 4) {
|
if (length != 4) {
|
||||||
|
NET_DBG("options_renewal, bad length");
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_nbuf_read_be32(frag, pos, &pos,
|
frag = net_nbuf_read_be32(frag, pos, &pos,
|
||||||
&iface->dhcpv4.renewal_time);
|
&iface->dhcpv4.renewal_time);
|
||||||
|
NET_DBG("options_renewal: %u",
|
||||||
|
iface->dhcpv4.renewal_time);
|
||||||
if (!iface->dhcpv4.renewal_time) {
|
if (!iface->dhcpv4.renewal_time) {
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
@ -566,20 +577,25 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf,
|
||||||
break;
|
break;
|
||||||
case DHCPV4_OPTIONS_SERVER_ID:
|
case DHCPV4_OPTIONS_SERVER_ID:
|
||||||
if (length != 4) {
|
if (length != 4) {
|
||||||
|
NET_DBG("options_server_id, bad length");
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_nbuf_read(frag, pos, &pos, length,
|
frag = net_nbuf_read(frag, pos, &pos, length,
|
||||||
iface->dhcpv4.server_id.s4_addr);
|
iface->dhcpv4.server_id.s4_addr);
|
||||||
|
NET_DBG("options_server_id: %s",
|
||||||
|
net_sprint_ipv4_addr(&iface->dhcpv4.server_id));
|
||||||
break;
|
break;
|
||||||
case DHCPV4_OPTIONS_MSG_TYPE:
|
case DHCPV4_OPTIONS_MSG_TYPE:
|
||||||
if (length != 1) {
|
if (length != 1) {
|
||||||
|
NET_DBG("options_msg_type, bad length");
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_nbuf_read_u8(frag, pos, &pos, msg_type);
|
frag = net_nbuf_read_u8(frag, pos, &pos, msg_type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
NET_DBG("option unknown: %d", type);
|
||||||
frag = net_nbuf_skip(frag, pos, &pos, length);
|
frag = net_nbuf_skip(frag, pos, &pos, length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue