]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: serialize InvertRule= in [RoutingPolicyRule]
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 28 Aug 2020 03:47:44 +0000 (12:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 3 Sep 2020 23:47:22 +0000 (08:47 +0900)
src/network/networkd-routing-policy-rule.c
src/network/test-routing-policy-rule.c

index bb5648cc53d4528e16f912626ee30d6f36c210a9..4befc2f498201e42c62f304ab41f943b439268d3 100644 (file)
@@ -1280,8 +1280,9 @@ int routing_policy_serialize_rules(Set *rules, FILE *f) {
                         space = true;
                 }
 
-                fprintf(f, "%stable=%"PRIu32 "\n",
+                fprintf(f, "%sinvert_rule=%s table=%"PRIu32"\n",
                         space ? " " : "",
+                        yes_no(rule->invert_rule),
                         rule->table);
         }
 
@@ -1453,6 +1454,13 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
                                         log_warning_errno(r, "Failed to parse RPDB rule suppress_prefixlen, ignoring: %s", b);
                                         continue;
                                 }
+                        } else if (streq(a, "invert_rule")) {
+                                r = parse_boolean(b);
+                                if (r < 0) {
+                                        log_warning_errno(r, "Failed to parse RPDB rule invert_rule, ignoring: %s", b);
+                                        continue;
+                                }
+                                rule->invert_rule = r;
                         }
                 }
 
index b539e11dad9bf78e9be977a647b90338db592702..0a0434aaabafdb5c541f43e938485304424a08da 100644 (file)
@@ -62,31 +62,30 @@ int main(int argc, char **argv) {
         test_setup_logging(LOG_DEBUG);
 
         test_rule_serialization("basic parsing",
-                                "RULE=from=1.2.3.4/32 to=2.3.4.5/32 family=AF_INET tos=5 priority=10 fwmark=1/2 table=10", NULL);
+                                "RULE=from=1.2.3.4/32 to=2.3.4.5/32 family=AF_INET tos=5 priority=10 fwmark=1/2 invert_rule=yes table=10", NULL);
 
         test_rule_serialization("ignored values",
                                 "RULE=something=to=ignore from=1.2.3.4/32 from=1.2.3.4/32"
                                 "   \t  to=2.3.4.5/24 to=2.3.4.5/32 tos=5 fwmark=2 fwmark=1 table=10 table=20",
-                                "RULE=from=1.2.3.4/32"
-                                " to=2.3.4.5/32 family=AF_INET tos=5 fwmark=1/0 table=20");
+                                "RULE=from=1.2.3.4/32 to=2.3.4.5/32 family=AF_INET tos=5 fwmark=1/0 invert_rule=no table=20");
 
         test_rule_serialization("ipv6",
-                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 table=6", NULL);
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 invert_rule=yes table=6", NULL);
 
-        assert_se(asprintf(&p, "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 table=%d", RT_TABLE_MAIN) >= 0);
+        assert_se(asprintf(&p, "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 invert_rule=no table=%d", RT_TABLE_MAIN) >= 0);
         test_rule_serialization("default table",
                                 "RULE=from=1::2/64 to=2::3/64", p);
 
         test_rule_serialization("incoming interface",
                                 "RULE=from=1::2/64 to=2::3/64 table=1 iif=lo",
-                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=lo table=1");
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=lo invert_rule=no table=1");
 
         test_rule_serialization("outgoing interface",
-                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 oif=eth0 table=1", NULL);
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 oif=eth0 invert_rule=no table=1", NULL);
 
         test_rule_serialization("freeing interface names",
                                 "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=e0 iif=e1 oif=e0 oif=e1 table=1",
-                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=e1 oif=e1 table=1");
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=e1 oif=e1 invert_rule=no table=1");
 
         return 0;
 }