]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/routing-policy-rule: assume FRA_PROTOCOL attribute is always set
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 16 Feb 2025 20:26:25 +0000 (05:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 16 Feb 2025 21:20:36 +0000 (06:20 +0900)
Since kernel v4.17 (1b71af6053af1bd2f849e9fda4f71c1e3f145dcf), the
attribute is always set in each netlink message for routing policy rule.
Now, our base line is v5.4. Hence, we can drop the workaround.

README
src/network/networkd-routing-policy-rule.c

diff --git a/README b/README
index 2f89fffe0b2be1459202d42bca6e68df6270c3a4..346f1aad42cc36ff5e6a906549e48be8c851381b 100644 (file)
--- a/README
+++ b/README
@@ -39,7 +39,8 @@ REQUIREMENTS:
                      ≥ 4.11 for nsfs NS_GET_NSTYPE
                      ≥ 4.13 for TIOCGPTPEER
                      ≥ 4.15 for cgroup-bpf device hook and cpu controller in cgroup v2
-                     ≥ 4.17 for cgroup-bpf socket address hooks and /sys/power/resume_offset
+                     ≥ 4.17 for cgroup-bpf socket address hooks, /sys/power/resume_offset,
+                            and FRA_PROTOCOL attribute for fib rules
                      ≥ 4.20 for PSI (used by systemd-oomd)
                      ≥ 5.2 for cgroup freezer and new mount API
                      ≥ 5.3 for bounded loops in BPF program, keyring namespacing,
index 2cac730a4170a0ab9454137a07e7cbcfc41620e6..9811f60dcb514ece3f0edcedb1ebaeb36e41ed0b 100644 (file)
@@ -1059,26 +1059,6 @@ int link_request_static_routing_policy_rules(Link *link) {
         return 0;
 }
 
-static const RoutingPolicyRule kernel_rules[] = {
-        { .family = AF_INET,  .priority_set = true, .priority = 0,     .table = RT_TABLE_LOCAL,   .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
-        { .family = AF_INET,  .priority_set = true, .priority = 1000,  .table = RT_TABLE_UNSPEC,  .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, .l3mdev = true },
-        { .family = AF_INET,  .priority_set = true, .priority = 32766, .table = RT_TABLE_MAIN,    .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
-        { .family = AF_INET,  .priority_set = true, .priority = 32767, .table = RT_TABLE_DEFAULT, .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
-        { .family = AF_INET6, .priority_set = true, .priority = 0,     .table = RT_TABLE_LOCAL,   .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
-        { .family = AF_INET6, .priority_set = true, .priority = 1000,  .table = RT_TABLE_UNSPEC,  .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, .l3mdev = true },
-        { .family = AF_INET6, .priority_set = true, .priority = 32766, .table = RT_TABLE_MAIN,    .action = FR_ACT_TO_TBL, .uid_range.start = UID_INVALID, .uid_range.end = UID_INVALID, .suppress_prefixlen = -1, .suppress_ifgroup = -1, },
-};
-
-static bool routing_policy_rule_is_created_by_kernel(const RoutingPolicyRule *rule) {
-        assert(rule);
-
-        FOREACH_ELEMENT(i, kernel_rules)
-                if (routing_policy_rule_equal(rule, i, i->family, i->priority))
-                        return true;
-
-        return false;
-}
-
 int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
         int r;
 
@@ -1258,16 +1238,10 @@ int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Man
                 return 0;
         }
 
-        /* If FRA_PROTOCOL is supported by kernel, then the attribute is always appended. If the received
-         * message does not have FRA_PROTOCOL, then we need to adjust the protocol of the rule. That requires
-         * all properties compared in the routing_policy_rule_compare_func(), hence it must be done after
-         * reading them. */
+        /* The kernel always sets the FRA_PROTOCOL attribute, and it is necessary for comparing rules.
+         * Hence, -ENODATA here is critical. */
         r = sd_netlink_message_read_u8(message, FRA_PROTOCOL, &tmp->protocol);
-        if (r == -ENODATA)
-                /* As .network files does not have setting to specify protocol, we can assume the
-                 * protocol of the received rule is RTPROT_KERNEL or RTPROT_STATIC. */
-                tmp->protocol = routing_policy_rule_is_created_by_kernel(tmp) ? RTPROT_KERNEL : RTPROT_STATIC;
-        else if (r < 0) {
+        if (r < 0) {
                 log_warning_errno(r, "rtnl: could not get FRA_PROTOCOL attribute, ignoring: %m");
                 return 0;
         }