Skip to content

Commit 572a88b

Browse files
committed
Fix DHCPv6 options serialization to prevent extra bytes in replies
In the `generate_reply_options` function, fixed an issue where DHCPv6 reply packets contained extra unintended bytes at the end. The problem was due to the `options` pointer not being incremented after copying the `opt_rapid` and `boot_file_url` options into the packet buffer. Changes made: - After copying `opt_rapid`, the `options` pointer is now incremented by `reply_options.opt_rapid_len`. - After copying `boot_file_url`, the `options` pointer is now incremented by `reply_options.opt_boot_file_len`. These changes ensure that all DHCPv6 options are correctly serialized in the packet buffer without overlaps or gaps. By properly advancing the `options` pointer, we prevent unintended data from being included at the end of the packet, eliminating the extra bytes that were being sent. This fix addresses the issue where clients were receiving malformed DHCPv6 packets due to the extra bytes, which could lead to communication errors or unexpected behavior.
1 parent a6d0032 commit 572a88b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/nodes/dhcpv6_node.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ static int generate_reply_options(struct rte_mbuf *m, uint8_t *options, int opti
247247
memcpy(options, (void *)&reply_options.opt_iana, reply_options.opt_iana_len);
248248
options += reply_options.opt_iana_len;
249249
}
250-
if (reply_options.opt_rapid_len)
250+
if (reply_options.opt_rapid_len) {
251251
memcpy(options, &reply_options.opt_rapid, reply_options.opt_rapid_len);
252+
options += reply_options.opt_rapid_len; // **Added this line**
253+
}
252254

253255
// Add DNS server option
254256
memcpy(options, &dns_opt.opt_code, sizeof(dns_opt.opt_code));
@@ -258,8 +260,10 @@ static int generate_reply_options(struct rte_mbuf *m, uint8_t *options, int opti
258260
memcpy(options, dhcpv6_dns->array, dhcpv6_dns->len);
259261
options += dhcpv6_dns->len;
260262

261-
if (reply_options.pxe_mode != DP_PXE_MODE_NONE)
263+
if (reply_options.pxe_mode != DP_PXE_MODE_NONE) {
262264
memcpy(options, &reply_options.boot_file_url, reply_options.opt_boot_file_len);
265+
options += reply_options.opt_boot_file_len; // **Added this line**
266+
}
263267

264268
return reply_options_len;
265269
}

0 commit comments

Comments
 (0)