1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

sd-dhcp6-lease: Name the structure containing IAADDR data

With this change the DHCP6_OPTION_IAADDR_LEN define can be removed in
favor of using sizeof(). Using the name of the struct and sizeof()
makes it clearer how much and what data is being copied from the
DHCPv6 message.
This commit is contained in:
Patrik Flykt 2014-10-08 11:00:07 +03:00
parent d46fbfb48d
commit ee3a5027f7
3 changed files with 17 additions and 16 deletions

View File

@ -38,7 +38,7 @@ struct DHCP6Address {
struct in6_addr address;
be32_t lifetime_preferred;
be32_t lifetime_valid;
} _packed_;
} iaaddr _packed_;
};
struct DHCP6IA {

View File

@ -32,7 +32,6 @@
#define DHCP6_OPTION_HDR_LEN 4
#define DHCP6_OPTION_IA_NA_LEN 12
#define DHCP6_OPTION_IA_TA_LEN 4
#define DHCP6_OPTION_IAADDR_LEN 24
static int option_append_hdr(uint8_t **buf, size_t *buflen, uint16_t optcode,
size_t optlen) {
@ -111,16 +110,16 @@ int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia) {
LIST_FOREACH(addresses, addr, ia->addresses) {
r = option_append_hdr(buf, buflen, DHCP6_OPTION_IAADDR,
DHCP6_OPTION_IAADDR_LEN);
sizeof(addr->iaaddr));
if (r < 0)
return r;
memcpy(*buf, &addr->address, DHCP6_OPTION_IAADDR_LEN);
memcpy(*buf, &addr->iaaddr, sizeof(addr->iaaddr));
*buf += DHCP6_OPTION_IAADDR_LEN;
*buflen -= DHCP6_OPTION_IAADDR_LEN;
*buf += sizeof(addr->iaaddr);
*buflen -= sizeof(addr->iaaddr);
ia_addrlen += DHCP6_OPTION_HDR_LEN + DHCP6_OPTION_IAADDR_LEN;
ia_addrlen += DHCP6_OPTION_HDR_LEN + sizeof(addr->iaaddr);
}
r = option_append_hdr(&ia_hdr, &ia_buflen, ia->type, len + ia_addrlen);
@ -192,7 +191,7 @@ int dhcp6_option_parse_ia(uint8_t **buf, size_t *buflen, uint16_t iatype,
case DHCP6_OPTION_IA_NA:
if (*buflen < DHCP6_OPTION_IA_NA_LEN + DHCP6_OPTION_HDR_LEN +
DHCP6_OPTION_IAADDR_LEN) {
sizeof(addr->iaaddr)) {
r = -ENOBUFS;
goto error;
}
@ -214,7 +213,7 @@ int dhcp6_option_parse_ia(uint8_t **buf, size_t *buflen, uint16_t iatype,
case DHCP6_OPTION_IA_TA:
if (*buflen < DHCP6_OPTION_IA_TA_LEN + DHCP6_OPTION_HDR_LEN +
DHCP6_OPTION_IAADDR_LEN) {
sizeof(addr->iaaddr)) {
r = -ENOBUFS;
goto error;
}
@ -250,10 +249,10 @@ int dhcp6_option_parse_ia(uint8_t **buf, size_t *buflen, uint16_t iatype,
LIST_INIT(addresses, addr);
memcpy(&addr->address, *buf, DHCP6_OPTION_IAADDR_LEN);
memcpy(&addr->iaaddr, *buf, sizeof(addr->iaaddr));
lt_valid = be32toh(addr->lifetime_valid);
lt_pref = be32toh(addr->lifetime_valid);
lt_valid = be32toh(addr->iaaddr.lifetime_valid);
lt_pref = be32toh(addr->iaaddr.lifetime_valid);
if (!lt_valid || lt_pref > lt_valid) {
log_dhcp6_client(client, "IA preferred %ds > valid %ds",

View File

@ -41,7 +41,7 @@ int dhcp6_lease_ia_rebind_expire(const DHCP6IA *ia, uint32_t *expire) {
assert_return(expire, -EINVAL);
LIST_FOREACH(addresses, addr, ia->addresses) {
t = be32toh(addr->lifetime_valid);
t = be32toh(addr->iaaddr.lifetime_valid);
if (valid < t)
valid = t;
}
@ -156,9 +156,11 @@ int sd_dhcp6_lease_get_next_address(sd_dhcp6_lease *lease,
if (!lease->addr_iter)
return -ENOMSG;
memcpy(addr, &lease->addr_iter->address, sizeof(struct in6_addr));
*lifetime_preferred = be32toh(lease->addr_iter->lifetime_preferred);
*lifetime_valid = be32toh(lease->addr_iter->lifetime_valid);
memcpy(addr, &lease->addr_iter->iaaddr.address,
sizeof(struct in6_addr));
*lifetime_preferred =
be32toh(lease->addr_iter->iaaddr.lifetime_preferred);
*lifetime_valid = be32toh(lease->addr_iter->iaaddr.lifetime_valid);
lease->addr_iter = lease->addr_iter->addresses_next;