mirror of
https://github.com/systemd/systemd.git
synced 2025-01-05 13:18:06 +03:00
Merge pull request #16505 from yuwata/network-manage-foreign-routes-cleanups
network: do not enumerate foreign routes when ManageForeignRoutes=no, and tiny cleanups
This commit is contained in:
commit
d735e4f2d6
@ -431,6 +431,32 @@ int address_get(Link *link,
|
||||
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;
|
||||
|
||||
|
@ -57,6 +57,7 @@ void address_free(Address *address);
|
||||
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);
|
||||
|
@ -4229,7 +4229,7 @@ int link_save(Link *link) {
|
||||
sd_dhcp6_lease_get_dns,
|
||||
NULL);
|
||||
|
||||
/* Make sure to flush out old entries before we use the NDISC data */
|
||||
/* Make sure to flush out old entries before we use the NDisc data */
|
||||
ndisc_vacuum(link);
|
||||
|
||||
if (link->network->ipv6_accept_ra_use_dns && link->ndisc_rdnss) {
|
||||
|
@ -505,7 +505,8 @@ int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, vo
|
||||
|
||||
log_link_debug(link,
|
||||
"%s route: dst: %s%s, src: %s, gw: %s, prefsrc: %s, scope: %s, table: %s, proto: %s, type: %s",
|
||||
(!route && !link->manager->manage_foreign_routes) || type == RTM_DELROUTE ? "Forgetting" :
|
||||
(!route && !link->manager->manage_foreign_routes) ? "Ignoring received foreign" :
|
||||
type == RTM_DELROUTE ? "Forgetting" :
|
||||
route ? "Received remembered" : "Remembering",
|
||||
strna(buf_dst), strempty(buf_dst_prefixlen),
|
||||
strna(buf_src), strna(buf_gw), strna(buf_prefsrc),
|
||||
@ -2031,6 +2032,9 @@ int manager_rtnl_enumerate_routes(Manager *m) {
|
||||
assert(m);
|
||||
assert(m->rtnl);
|
||||
|
||||
if (!m->manage_foreign_routes)
|
||||
return 0;
|
||||
|
||||
r = sd_rtnl_message_new_route(m->rtnl, &req, RTM_GETROUTE, 0, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -148,8 +148,6 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
unsigned preference;
|
||||
uint32_t mtu;
|
||||
usec_t time_now;
|
||||
Address *address;
|
||||
Iterator i;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
@ -166,34 +164,15 @@ 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");
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
(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);
|
||||
@ -836,14 +815,14 @@ static void ndisc_handler(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *r
|
||||
break;
|
||||
|
||||
case SD_NDISC_EVENT_TIMEOUT:
|
||||
log_link_debug(link, "NDISC handler get timeout event");
|
||||
log_link_debug(link, "NDisc handler get timeout event");
|
||||
link->ndisc_addresses_configured = true;
|
||||
link->ndisc_routes_configured = true;
|
||||
link_check_ready(link);
|
||||
|
||||
break;
|
||||
default:
|
||||
assert_not_reached("IPv6 Neighbor Discovery unknown event");
|
||||
assert_not_reached("Unknown NDisc event");
|
||||
}
|
||||
}
|
||||
|
||||
@ -969,7 +948,7 @@ int config_parse_ndisc_deny_listed_prefix(
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse NDISC deny-listed prefix, ignoring assignment: %s",
|
||||
"Failed to parse NDisc deny-listed prefix, ignoring assignment: %s",
|
||||
rvalue);
|
||||
return 0;
|
||||
}
|
||||
@ -979,7 +958,7 @@ int config_parse_ndisc_deny_listed_prefix(
|
||||
r = in_addr_from_string(AF_INET6, n, &ip);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"NDISC deny-listed prefix is invalid, ignoring assignment: %s", n);
|
||||
"NDisc deny-listed prefix is invalid, ignoring assignment: %s", n);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user