]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: add whitespace after family= and priority= in serialized routing policy...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 28 Aug 2020 03:34:36 +0000 (12:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 3 Sep 2020 23:44:19 +0000 (08:44 +0900)
This also makes priority= serialized only when its value is non-zero.

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

index 36b6138abad4729f2524758a49a8cf23e65bdfe4..bb5648cc53d4528e16f912626ee30d6f36c210a9 100644 (file)
@@ -1202,10 +1202,12 @@ int routing_policy_serialize_rules(Set *rules, FILE *f) {
                 }
 
                 family_str = af_to_name(rule->family);
-                if (family_str)
-                fprintf(f, "%sfamily=%s",
-                        space ? " " : "",
-                        family_str);
+                if (family_str) {
+                        fprintf(f, "%sfamily=%s",
+                                space ? " " : "",
+                                family_str);
+                        space = true;
+                }
 
                 if (rule->tos != 0) {
                         fprintf(f, "%stos=%hhu",
@@ -1214,9 +1216,12 @@ int routing_policy_serialize_rules(Set *rules, FILE *f) {
                         space = true;
                 }
 
-                fprintf(f, "%spriority=%"PRIu32,
-                        space ? " " : "",
-                        rule->priority);
+                if (rule->priority != 0) {
+                        fprintf(f, "%spriority=%"PRIu32,
+                                space ? " " : "",
+                                rule->priority);
+                        space = true;
+                }
 
                 if (rule->fwmark != 0) {
                         fprintf(f, "%sfwmark=%"PRIu32"/%"PRIu32,
index d84d746c3fa8e2dd423b159bb716b4546437bd86..b539e11dad9bf78e9be977a647b90338db592702 100644 (file)
@@ -62,31 +62,31 @@ 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=0 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 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 priority=0 fwmark=1/0 table=20");
+                                " to=2.3.4.5/32 family=AF_INET tos=5 fwmark=1/0 table=20");
 
         test_rule_serialization("ipv6",
-                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 priority=0 table=6", NULL);
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 table=6", NULL);
 
-        assert_se(asprintf(&p, "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 priority=0 table=%d", RT_TABLE_MAIN) >= 0);
+        assert_se(asprintf(&p, "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 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 priority=0 iif=lo table=1");
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=lo table=1");
 
         test_rule_serialization("outgoing interface",
-                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 priority=0 oif=eth0 table=1", NULL);
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 oif=eth0 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 priority=0 iif=e1 oif=e1 table=1");
+                                "RULE=from=1::2/64 to=2::3/64 family=AF_INET6 iif=e1 oif=e1 table=1");
 
         return 0;
 }