diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-10-01 15:42:41 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-10-02 23:05:05 +0900 |
commit | 6f8c3de6b7ff74f567b015f0e75c32b06d9d5d41 (patch) | |
tree | 59d1755e65f96ba7e6294c36a7b27b3e10dd3327 /src/libsystemd-network | |
parent | 4ec5b5c7785b21d958118cb741c98654bcb9e25a (diff) | |
download | systemd-6f8c3de6b7ff74f567b015f0e75c32b06d9d5d41.tar.gz |
sd-dhcp6-client: simplify dhcp6_option_append_ia()
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/dhcp6-option.c | 47 |
1 files changed, 9 insertions, 38 deletions
diff --git a/src/libsystemd-network/dhcp6-option.c b/src/libsystemd-network/dhcp6-option.c index 4fd75fbf3b..de54c36a71 100644 --- a/src/libsystemd-network/dhcp6-option.c +++ b/src/libsystemd-network/dhcp6-option.c @@ -282,7 +282,6 @@ int dhcp6_option_append_vendor_option(uint8_t **buf, size_t *buflen, OrderedSet static int option_append_ia_address(uint8_t **buf, size_t *buflen, const struct iaaddr *address) { struct iaaddr a; - int r; assert(buf); assert(*buf); @@ -294,19 +293,11 @@ static int option_append_ia_address(uint8_t **buf, size_t *buflen, const struct .address = address->address, }; - r = option_append_hdr(buf, buflen, SD_DHCP6_OPTION_IAADDR, sizeof(struct iaaddr)); - if (r < 0) - return r; - - *buf = mempcpy(*buf, &a, sizeof(struct iaaddr)); - *buflen -= sizeof(struct iaaddr); - - return offsetof(DHCP6Option, data) + sizeof(struct iaaddr); + return dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_IAADDR, sizeof(struct iaaddr), &a); } static int option_append_pd_prefix(uint8_t **buf, size_t *buflen, const struct iapdprefix *prefix) { struct iapdprefix p; - int r; assert(buf); assert(*buf); @@ -322,21 +313,13 @@ static int option_append_pd_prefix(uint8_t **buf, size_t *buflen, const struct i .address = prefix->address, }; - r = option_append_hdr(buf, buflen, SD_DHCP6_OPTION_IA_PD_PREFIX, sizeof(struct iapdprefix)); - if (r < 0) - return r; - - *buf = mempcpy(*buf, &p, sizeof(struct iapdprefix)); - *buflen -= sizeof(struct iapdprefix); - - return offsetof(DHCP6Option, data) + sizeof(struct iapdprefix); + return dhcp6_option_append(buf, buflen, SD_DHCP6_OPTION_IA_PD_PREFIX, sizeof(struct iapdprefix), &p); } int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia) { struct ia_header header; - size_t ia_buflen; - uint8_t *ia_hdr; - uint16_t len; + uint8_t data[512], *p; + size_t len, size; int r; assert(buf); @@ -366,31 +349,19 @@ int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, const DHCP6IA *ia) { assert_not_reached(); } - if (*buflen < offsetof(DHCP6Option, data) + len) - return -ENOBUFS; - - ia_hdr = *buf; - ia_buflen = *buflen; - - /* The header will be written at the end of this function. */ - *buf += offsetof(DHCP6Option, data); - *buflen -= offsetof(DHCP6Option, data); - - *buf = mempcpy(*buf, &header, len); - *buflen -= len; + p = mempcpy(data, &header, len); + size = sizeof(data) - len; LIST_FOREACH(addresses, addr, ia->addresses) { if (ia->type == SD_DHCP6_OPTION_IA_PD) - r = option_append_pd_prefix(buf, buflen, &addr->iapdprefix); + r = option_append_pd_prefix(&p, &size, &addr->iapdprefix); else - r = option_append_ia_address(buf, buflen, &addr->iaaddr); + r = option_append_ia_address(&p, &size, &addr->iaaddr); if (r < 0) return r; - - len += r; } - return option_append_hdr(&ia_hdr, &ia_buflen, ia->type, len); + return dhcp6_option_append(buf, buflen, ia->type, p - data, data); } int dhcp6_option_append_fqdn(uint8_t **buf, size_t *buflen, const char *fqdn) { |