Skip to content

Commit 9d54465

Browse files
rluboskartben
authored andcommitted
net: dhcpv4: client: Handle Pad option
Pad option (option code 0) can be present in between other options for alignment. The option has a fixed 1-byte length (i. e. no length field), therefore it did not fall under the common processing code for unrecognized options (which include the length field at the second byte). Therefore, not processing this option explicitly could disturb other options processing, as the parser would wrongly interpret the next option code as the length field. This commit adds Pad option handling to fix the issue. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
1 parent f4408c0 commit 9d54465

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

subsys/net/lib/dhcpv4/dhcpv4.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,13 @@ static bool dhcpv4_parse_options(struct net_pkt *pkt,
979979
goto end;
980980
}
981981

982+
if (type == DHCPV4_OPTIONS_PAD) {
983+
/* Pad option has a fixed 1-byte length and should be
984+
* ignored.
985+
*/
986+
continue;
987+
}
988+
982989
if (net_pkt_read_u8(pkt, &length)) {
983990
NET_ERR("option parsing, bad length");
984991
return false;

subsys/net/lib/dhcpv4/dhcpv4_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct dhcp_msg {
5151
#define DHCPV4_SERVER_PORT 67
5252
#define DHCPV4_CLIENT_PORT 68
5353

54+
#define DHCPV4_OPTIONS_PAD 0
5455
#define DHCPV4_OPTIONS_SUBNET_MASK 1
5556
#define DHCPV4_OPTIONS_ROUTER 3
5657
#define DHCPV4_OPTIONS_DNS_SERVER 6

0 commit comments

Comments
 (0)