mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
network: use address_get() in address_exists()
And rename address_exists() to link_has_ipv6_address().
This commit is contained in:
parent
1d30fc5cb6
commit
c5a0aeb33a
@ -447,29 +447,23 @@ int address_get(Link *link, const Address *in, Address **ret) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static bool address_exists_internal(Set *addresses, int family, const union in_addr_union *in_addr) {
|
||||
Address *address;
|
||||
int link_has_ipv6_address(Link *link, const struct in6_addr *address) {
|
||||
_cleanup_(address_freep) Address *a = NULL;
|
||||
int r;
|
||||
|
||||
SET_FOREACH(address, addresses) {
|
||||
if (address->family != family)
|
||||
continue;
|
||||
if (in_addr_equal(address->family, &address->in_addr, in_addr))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool address_exists(Link *link, int family, const union in_addr_union *in_addr) {
|
||||
assert(link);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(in_addr);
|
||||
assert(address);
|
||||
|
||||
if (address_exists_internal(link->addresses, family, in_addr))
|
||||
return true;
|
||||
if (address_exists_internal(link->addresses_foreign, family, in_addr))
|
||||
return true;
|
||||
return false;
|
||||
r = address_new(&a);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
/* address_compare_func() only compares the local address for IPv6 case. So, it is enough to
|
||||
* set only family and the address. */
|
||||
a->family = AF_INET6;
|
||||
a->in_addr.in6 = *address;
|
||||
|
||||
return address_get(link, a, NULL) >= 0;
|
||||
}
|
||||
|
||||
static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
|
@ -49,7 +49,6 @@ typedef struct Address {
|
||||
int address_new(Address **ret);
|
||||
Address *address_free(Address *address);
|
||||
int address_get(Link *link, const Address *in, Address **ret);
|
||||
bool address_exists(Link *link, int family, const union in_addr_union *in_addr);
|
||||
int address_configure(const Address *address, Link *link, link_netlink_message_handler_t callback, bool update, Address **ret);
|
||||
int address_remove(const Address *address, Link *link, link_netlink_message_handler_t callback);
|
||||
bool address_equal(const Address *a1, const Address *a2);
|
||||
@ -63,6 +62,7 @@ int link_set_addresses(Link *link);
|
||||
int link_drop_addresses(Link *link);
|
||||
int link_drop_foreign_addresses(Link *link);
|
||||
bool link_address_is_dynamic(const Link *link, const Address *address);
|
||||
int link_has_ipv6_address(Link *link, const struct in6_addr *address);
|
||||
|
||||
void ipv4_dad_unref(Link *link);
|
||||
int ipv4_dad_stop(Link *link);
|
||||
|
@ -483,7 +483,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m");
|
||||
|
||||
if (address_exists(link, AF_INET6, &gateway)) {
|
||||
if (link_has_ipv6_address(link, &gateway.in6) > 0) {
|
||||
if (DEBUG_LOGGING) {
|
||||
_cleanup_free_ char *buffer = NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user