diff options
| author | Anshu Kumari <anskuma@redhat.com> | 2026-10-29 23:43:02 +0530 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-11-17 01:13:39 +0100 |
| commit | 0acf8a908e5730ce31a8e28d5c39b269cab3ea08 (patch) | |
| tree | cc98d4b0312d0d8fad7176aac8baa9622e5328b4 | |
| parent | 58213952646dd4713447ea33fc9f0a0dadcce797 (diff) | |
| download | passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.tar passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.tar.gz passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.tar.bz2 passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.tar.lz passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.tar.xz passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.tar.zst passt-0acf8a908e5730ce31a8e28d5c39b269cab3ea08.zip | |
dhcpv6: Inject custom options into DHCPv6 replies
Append user-specified options from --dhcpv6-opt to DHCPv6 reply
messages. Options that exceed available buffer space are skipped
with a rate-limited warning.
Link: https://bugs.passt.top/show_bug.cgi?id=192
Signed-off-by: Anshu Kumari <anskuma@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | dhcpv6.c | 44 | ||||
| -rw-r--r-- | dhcpv6.h | 3 | ||||
| -rw-r--r-- | tap.c | 2 |
3 files changed, 46 insertions, 3 deletions
@@ -892,16 +892,57 @@ static size_t dhcpv6_client_fqdn_fill(const struct iov_tail *data, } /** + * dhcpv6_user_opts_fill() - Append user-specified options to reply + * @buf: Response message buffer + * @offset: Current offset in buffer + * @now: Current timestamp + * + * Return: offset after appended user options + */ +static size_t dhcpv6_user_opts_fill(char *buf, size_t offset, + const struct timespec *now) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(dhcpv6_user_opts); i++) { + int vlen = dhcpv6_user_opts[i].len; + struct opt_hdr *hdr; + + if (!vlen) + continue; + + if (offset + sizeof(struct opt_hdr) + vlen > OPT_MAX_SIZE) { + warn_ratelimit(now, + "DHCPv6: option %u doesn't fit, skipping", + i); + continue; + } + + hdr = (struct opt_hdr *)(buf + offset); + hdr->t = htons(i); + hdr->l = htons(vlen); + offset += sizeof(struct opt_hdr); + + memcpy(buf + offset, dhcpv6_user_opts[i].val, vlen); + offset += vlen; + } + + return offset; +} + +/** * dhcpv6() - Check if this is a DHCPv6 message, reply as needed * @c: Execution context * @data: Single packet starting from UDP header * @saddr: Source IPv6 address of original message * @daddr: Destination IPv6 address of original message + * @now: Current timestamp * * Return: 0 if it's not a DHCPv6 message, 1 if handled, -1 on failure */ int dhcpv6(struct ctx *c, struct iov_tail *data, - const struct in6_addr *saddr, const struct in6_addr *daddr) + const struct in6_addr *saddr, const struct in6_addr *daddr, + const struct timespec *now) { const struct opt_server_id *server_id = NULL; const struct opt_hdr *client_id = NULL; @@ -1040,6 +1081,7 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, sizeof(struct opt_hdr) + ntohs(client_id->l); n = dhcpv6_dns_fill(c, (char *)&resp, n); n = dhcpv6_client_fqdn_fill(data, c, (char *)&resp, n); + n = dhcpv6_user_opts_fill((char *)&resp, n, now); resp.hdr.xid = mh->xid; @@ -7,7 +7,8 @@ #define DHCPV6_H int dhcpv6(struct ctx *c, struct iov_tail *data, - const struct in6_addr *saddr, const struct in6_addr *daddr); + const struct in6_addr *saddr, const struct in6_addr *daddr, + const struct timespec *now); void dhcpv6_init(const struct ctx *c); void dhcpv6_set_opt(uint16_t code, const char *val_str); const char *dhcpv6_opt_to_str(uint16_t code, char *buf, size_t buf_len, @@ -1045,7 +1045,7 @@ resume: if (proto == IPPROTO_UDP) { struct iov_tail uh_data = data; - if (dhcpv6(c, &uh_data, saddr, daddr)) + if (dhcpv6(c, &uh_data, saddr, daddr, now)) continue; } |
