1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-28 02:50:16 +03:00

network: split out core logic route_type_is_reject()

Preparation for later change.
This commit is contained in:
Yu Watanabe 2024-08-04 17:59:50 +09:00
parent 2d00f4c306
commit 0c7bb54238
4 changed files with 17 additions and 14 deletions

View File

@ -148,7 +148,7 @@ DEFINE_PRIVATE_HASH_OPS_WITH_KEY_DESTRUCTOR(
route_nexthop_free);
static size_t route_n_nexthops(const Route *route) {
if (route->nexthop_id != 0 || route_type_is_reject(route))
if (route->nexthop_id != 0 || route_is_reject(route))
return 0;
if (ordered_set_isempty(route->nexthops))
@ -246,7 +246,7 @@ int route_nexthops_copy(const Route *src, const RouteNextHop *nh, Route *dest) {
assert(src);
assert(dest);
if (src->nexthop_id != 0 || route_type_is_reject(src))
if (src->nexthop_id != 0 || route_is_reject(src))
return 0;
if (nh)
@ -292,7 +292,7 @@ bool route_nexthops_needs_adjust(const Route *route) {
* Hence, we cannot know if the nexthop is blackhole or not. */
return route->type != RTN_BLACKHOLE;
if (route_type_is_reject(route))
if (route_is_reject(route))
return false;
if (ordered_set_isempty(route->nexthops))
@ -350,7 +350,7 @@ int route_adjust_nexthops(Route *route, Link *link) {
return true; /* updated */
}
if (route_type_is_reject(route))
if (route_is_reject(route))
return false;
if (ordered_set_isempty(route->nexthops))
@ -439,7 +439,7 @@ int route_nexthops_is_ready_to_configure(const Route *route, Manager *manager) {
return true;
}
if (route_type_is_reject(route))
if (route_is_reject(route))
return true;
if (ordered_set_isempty(route->nexthops))
@ -468,7 +468,7 @@ int route_nexthops_to_string(const Route *route, char **ret) {
return 0;
}
if (route_type_is_reject(route)) {
if (route_is_reject(route)) {
buf = strdup("gw: n/a");
if (!buf)
return -ENOMEM;
@ -625,7 +625,7 @@ int route_nexthops_set_netlink_message(const Route *route, sd_netlink_message *m
if (route->nexthop_id != 0)
return sd_netlink_message_append_u32(message, RTA_NH_ID, route->nexthop_id);
if (route_type_is_reject(route))
if (route_is_reject(route))
return 0;
/* We request IPv6 multipath routes separately. Even though, if weight is non-zero, we need to use
@ -750,7 +750,7 @@ int route_nexthops_read_netlink_message(Route *route, sd_netlink_message *messag
if (r < 0 && r != -ENODATA)
return log_warning_errno(r, "rtnl: received route message with invalid nexthop id, ignoring: %m");
if (route->nexthop_id != 0 || route_type_is_reject(route))
if (route->nexthop_id != 0 || route_is_reject(route))
/* IPv6 routes with reject type are always assigned to the loopback interface. See kernel's
* fib6_nh_init() in net/ipv6/route.c. However, we'd like to make it consistent with IPv4
* routes. Hence, skip reading of RTA_OIF. */
@ -899,7 +899,7 @@ int route_section_verify_nexthops(Route *route) {
"Ignoring [Route] section from line %u.",
route->section->filename, route->section->line);
if (route_type_is_reject(route) &&
if (route_is_reject(route) &&
(route->gateway_from_dhcp_or_ra ||
in_addr_is_set(route->nexthop.family, &route->nexthop.gw) ||
!ordered_set_isempty(route->nexthops)))

View File

@ -39,10 +39,12 @@ unsigned routes_max(void) {
return cached;
}
bool route_type_is_reject(const Route *route) {
assert(route);
bool route_type_is_reject(uint8_t type) {
return IN_SET(type, RTN_UNREACHABLE, RTN_PROHIBIT, RTN_BLACKHOLE, RTN_THROW);
}
return IN_SET(route->type, RTN_UNREACHABLE, RTN_PROHIBIT, RTN_BLACKHOLE, RTN_THROW);
bool route_is_reject(const Route *route) {
return route_type_is_reject(ASSERT_PTR(route)->type);
}
static bool route_lifetime_is_valid(const Route *route) {

View File

@ -13,7 +13,8 @@ typedef struct Route Route;
unsigned routes_max(void);
bool route_type_is_reject(const Route *route);
bool route_type_is_reject(uint8_t type);
bool route_is_reject(const Route *route);
bool link_find_default_gateway(Link *link, int family, Route **gw);
static inline bool link_has_default_gateway(Link *link, int family) {

View File

@ -912,7 +912,7 @@ int link_request_route(
assert(route);
assert(route->source != NETWORK_CONFIG_SOURCE_FOREIGN);
if (route->family == AF_INET || route_type_is_reject(route) || ordered_set_isempty(route->nexthops))
if (route->family == AF_INET || route_is_reject(route) || ordered_set_isempty(route->nexthops))
return link_request_route_one(link, route, NULL, message_counter, netlink_handler);
RouteNextHop *nh;