1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 09:56:51 +03:00

dhcp6: Add function to iterate and fetch delegated prefixes

Add a function for fetching the next delegated prefix and another
one to reset the iteration to the first prefix.
This commit is contained in:
Patrik Flykt 2018-01-04 15:11:54 +02:00
parent 819c56f6fa
commit 652bf04254
3 changed files with 37 additions and 0 deletions

View File

@ -39,6 +39,7 @@ struct sd_dhcp6_lease {
DHCP6IA pd; DHCP6IA pd;
DHCP6Address *addr_iter; DHCP6Address *addr_iter;
DHCP6Address *prefix_iter;
struct in6_addr *dns; struct in6_addr *dns;
size_t dns_count; size_t dns_count;

View File

@ -176,6 +176,37 @@ void sd_dhcp6_lease_reset_address_iter(sd_dhcp6_lease *lease) {
lease->addr_iter = lease->ia.addresses; lease->addr_iter = lease->ia.addresses;
} }
int sd_dhcp6_lease_get_pd(sd_dhcp6_lease *lease, struct in6_addr *prefix,
uint8_t *prefix_len,
uint32_t *lifetime_preferred,
uint32_t *lifetime_valid) {
assert_return(lease, -EINVAL);
assert_return(prefix, -EINVAL);
assert_return(prefix_len, -EINVAL);
assert_return(lifetime_preferred, -EINVAL);
assert_return(lifetime_valid, -EINVAL);
if (!lease->prefix_iter)
return -ENOMSG;
memcpy(prefix, &lease->prefix_iter->iapdprefix.address,
sizeof(struct in6_addr));
*prefix_len = lease->prefix_iter->iapdprefix.prefixlen;
*lifetime_preferred =
be32toh(lease->prefix_iter->iapdprefix.lifetime_preferred);
*lifetime_valid =
be32toh(lease->prefix_iter->iapdprefix.lifetime_valid);
lease->prefix_iter = lease->prefix_iter->addresses_next;
return 0;
}
void sd_dhcp6_lease_reset_pd_prefix_iter(sd_dhcp6_lease *lease) {
if (lease)
lease->prefix_iter = lease->pd.addresses;
}
int dhcp6_lease_set_dns(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) { int dhcp6_lease_set_dns(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen) {
int r; int r;

View File

@ -36,6 +36,11 @@ int sd_dhcp6_lease_get_address(sd_dhcp6_lease *lease,
struct in6_addr *addr, struct in6_addr *addr,
uint32_t *lifetime_preferred, uint32_t *lifetime_preferred,
uint32_t *lifetime_valid); uint32_t *lifetime_valid);
void sd_dhcp6_lease_reset_pd_prefix_iter(sd_dhcp6_lease *lease);
int sd_dhcp6_lease_get_pd(sd_dhcp6_lease *lease, struct in6_addr *prefix,
uint8_t *prefix_len,
uint32_t *lifetime_preferred,
uint32_t *lifetime_valid);
int sd_dhcp6_lease_get_dns(sd_dhcp6_lease *lease, struct in6_addr **addrs); int sd_dhcp6_lease_get_dns(sd_dhcp6_lease *lease, struct in6_addr **addrs);
int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***domains); int sd_dhcp6_lease_get_domains(sd_dhcp6_lease *lease, char ***domains);