return -ENOENT;
}
+static bool address_exists_internal(Set *addresses, int family, const union in_addr_union *in_addr) {
+ Address *address;
+ Iterator i;
+
+ SET_FOREACH(address, addresses, i) {
+ 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);
+
+ 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;
+}
+
static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r;
int address_add_foreign(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret);
+bool address_exists(Link *link, int family, const union in_addr_union *in_addr);
int address_update(Address *address, unsigned char flags, unsigned char scope, const struct ifa_cacheinfo *cinfo);
int address_drop(Address *address);
int address_configure(Address *address, Link *link, link_netlink_message_handler_t callback, bool update);
unsigned preference;
uint32_t mtu;
usec_t time_now;
- Address *address;
- Iterator i;
int r;
assert(link);
if (r < 0)
return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m");
- SET_FOREACH(address, link->addresses, i) {
- if (address->family != AF_INET6)
- continue;
- if (in_addr_equal(AF_INET6, &gateway, &address->in_addr)) {
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *buffer = NULL;
-
- (void) in_addr_to_string(AF_INET6, &address->in_addr, &buffer);
- log_link_debug(link, "No NDisc route added, gateway %s matches local address",
- strnull(buffer));
- }
- return 0;
- }
- }
-
- SET_FOREACH(address, link->addresses_foreign, i) {
- if (address->family != AF_INET6)
- continue;
- if (in_addr_equal(AF_INET6, &gateway, &address->in_addr)) {
- if (DEBUG_LOGGING) {
- _cleanup_free_ char *buffer = NULL;
+ if (address_exists(link, AF_INET6, &gateway)) {
+ if (DEBUG_LOGGING) {
+ _cleanup_free_ char *buffer = NULL;
- (void) in_addr_to_string(AF_INET6, &address->in_addr, &buffer);
- log_link_debug(link, "No NDisc route added, gateway %s matches local address",
- strnull(buffer));
- }
- return 0;
+ (void) in_addr_to_string(AF_INET6, &gateway, &buffer);
+ log_link_debug(link, "No NDisc route added, gateway %s matches local address",
+ strnull(buffer));
}
+ return 0;
}
r = sd_ndisc_router_get_preference(rt, &preference);