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

network: address: introduce manager_get_address()

And make manager_has_address() return true only when the link which has
the address is ready.
This commit is contained in:
Yu Watanabe 2022-02-25 12:59:58 +09:00
parent 04386f56b5
commit 77e9be1ee4
2 changed files with 24 additions and 7 deletions

View File

@ -602,19 +602,35 @@ int link_get_address(Link *link, int family, const union in_addr_union *address,
return -ENOENT;
}
int manager_has_address(Manager *manager, int family, const union in_addr_union *address, bool check_ready) {
Address *a;
int manager_get_address(Manager *manager, int family, const union in_addr_union *address, unsigned char prefixlen, Address **ret) {
Link *link;
assert(manager);
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
HASHMAP_FOREACH(link, manager->links_by_index)
if (link_get_address(link, family, address, 0, &a) >= 0)
return check_ready ? address_is_ready(a) : address_exists(a);
HASHMAP_FOREACH(link, manager->links_by_index) {
if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
continue;
return false;
if (link_get_address(link, family, address, prefixlen, ret) >= 0)
return 0;
}
return -ENOENT;
}
bool manager_has_address(Manager *manager, int family, const union in_addr_union *address, bool check_ready) {
Address *a;
assert(manager);
assert(IN_SET(family, AF_INET, AF_INET6));
assert(address);
if (manager_get_address(manager, family, address, 0, &a) < 0)
return false;
return check_ready ? address_is_ready(a) : address_exists(a);
}
const char* format_lifetime(char *buf, size_t l, usec_t lifetime_usec) {

View File

@ -88,7 +88,8 @@ static inline int link_get_ipv4_address(Link *link, const struct in_addr *addres
assert(address);
return link_get_address(link, AF_INET, &(union in_addr_union) { .in = *address }, prefixlen, ret);
}
int manager_has_address(Manager *manager, int family, const union in_addr_union *address, bool check_ready);
int manager_get_address(Manager *manager, int family, const union in_addr_union *address, unsigned char prefixlen, Address **ret);
bool manager_has_address(Manager *manager, int family, const union in_addr_union *address, bool check_ready);
void address_cancel_request(Address *address);
int link_request_address(