]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: split out core logic route_type_is_reject()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Aug 2024 08:59:50 +0000 (17:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 5 Aug 2024 00:15:15 +0000 (09:15 +0900)
Preparation for later change.

src/network/networkd-route-nexthop.c
src/network/networkd-route-util.c
src/network/networkd-route-util.h
src/network/networkd-route.c

index 11215c36c717f063bedb643f4b2241c63fd0a6e3..f2d976beb15b8130b21e6693e2670558c0af536b 100644 (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)))
index 8d63b9b058aba869c4ae1059acc914b3a942ce5d..9bb1e0f70703ad5b9be09987146df921ce609260 100644 (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) {
index 2df7faadc8e763a27c0bc022b13ea77d73f2837a..2905a4913b1fa8768743d1245bb41643f539bf39 100644 (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) {
index 9b6be2f2bfa49ef3f55fbd550d22a345cd84cdb0..d9a6e259db9e8ff46acfa88d8554289f54cebb86 100644 (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;