mirror of
https://github.com/systemd/systemd.git
synced 2026-08-08 09:01:02 +00:00
dhcp6: Add function appending an IA PD to the DHCP6 message
Add function that appends an IA PD option and any number of IA PD Prefix options.
This commit is contained in:
@@ -102,6 +102,7 @@ typedef struct DHCP6IA DHCP6IA;
|
||||
int dhcp6_option_append(uint8_t **buf, size_t *buflen, uint16_t code,
|
||||
size_t optlen, const void *optval);
|
||||
int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia);
|
||||
int dhcp6_option_append_pd(uint8_t *buf, size_t len, DHCP6IA *pd);
|
||||
int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn);
|
||||
int dhcp6_option_parse(uint8_t **buf, size_t *buflen, uint16_t *optcode,
|
||||
size_t *optlen, uint8_t **optvalue);
|
||||
|
||||
@@ -181,6 +181,42 @@ int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) {
|
||||
return r;
|
||||
}
|
||||
|
||||
int dhcp6_option_append_pd(uint8_t *buf, size_t len, DHCP6IA *pd) {
|
||||
DHCP6Option *option = (DHCP6Option *)buf;
|
||||
size_t i = sizeof(*option) + sizeof(pd->ia_pd);
|
||||
DHCP6Address *prefix;
|
||||
|
||||
assert_return(buf, -EINVAL);
|
||||
assert_return(pd, -EINVAL);
|
||||
assert_return(pd->type == SD_DHCP6_OPTION_IA_PD, -EINVAL);
|
||||
|
||||
if (len < i)
|
||||
return -ENOBUFS;
|
||||
|
||||
option->code = htobe16(SD_DHCP6_OPTION_IA_PD);
|
||||
|
||||
memcpy(&option->data, &pd->ia_pd, sizeof(pd->ia_pd));
|
||||
|
||||
LIST_FOREACH(addresses, prefix, pd->addresses) {
|
||||
DHCP6PDPrefixOption *prefix_opt;
|
||||
|
||||
if (len < i + sizeof(*prefix_opt))
|
||||
return -ENOBUFS;
|
||||
|
||||
prefix_opt = (DHCP6PDPrefixOption *)&buf[i];
|
||||
prefix_opt->option.code = htobe16(SD_DHCP6_OPTION_IA_PD_PREFIX);
|
||||
prefix_opt->option.len = htobe16(sizeof(prefix_opt->iapdprefix));
|
||||
|
||||
memcpy(&prefix_opt->iapdprefix, &prefix->iapdprefix,
|
||||
sizeof(struct iapdprefix));
|
||||
|
||||
i += sizeof(*prefix_opt);
|
||||
}
|
||||
|
||||
option->len = htobe16(i - sizeof(*option));
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static int option_parse_hdr(uint8_t **buf, size_t *buflen, uint16_t *optcode, size_t *optlen) {
|
||||
DHCP6Option *option = (DHCP6Option*) *buf;
|
||||
|
||||
Reference in New Issue
Block a user