]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: fix serialization of {Incoming,Outgoing}Interface
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Nov 2017 11:51:08 +0000 (11:51 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Nov 2017 08:25:38 +0000 (09:25 +0100)
Let's just say that the code wasn't fully functional ;(

Since we only had the parser for serialization, and not the writer, we are
free to change the format. So while at it, let's use shorter names in the
serialization format that match the surrounding style.

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

index 09c1015f2cad99cf3cf5cf30e0f1c420cc248f99..20f748944eaff22d59f8b9608cb08e14ee0ace0e 100644 (file)
@@ -905,6 +905,20 @@ int routing_policy_serialize_rules(Set *rules, FILE *f) {
                         space = true;
                 }
 
+                if (rule->iif) {
+                        fprintf(f, "%siif=%s",
+                                space ? " " : "",
+                                rule->iif);
+                        space = true;
+                }
+
+                if (rule->oif) {
+                        fprintf(f, "%soif=%s",
+                                space ? " " : "",
+                                rule->oif);
+                        space = true;
+                }
+
                 fprintf(f, "%stable=%"PRIu32 "\n",
                         space ? " " : "",
                         rule->table);
@@ -1001,14 +1015,14 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
                                         log_error_errno(r, "Failed to parse RPDB rule firewall mark or mask, ignoring: %s", a);
                                         continue;
                                 }
-                        } else if (streq(a, "IncomingInterface")) {
+                        } else if (streq(a, "iif")) {
 
-                                rule->iif = strdup(a);
+                                rule->iif = strdup(b);
                                 if (!rule->iif)
                                         return log_oom();
-                        } else if (streq(a, "OutgoingInterface")) {
+                        } else if (streq(a, "oif")) {
 
-                                rule->oif = strdup(a);
+                                rule->oif = strdup(b);
                                 if (!rule->oif)
                                         return log_oom();
                         }
index a4c568e325b20f69bc8794e0e4b9435a67b412af..c619dbc1594387959d93a94b2d4692337cd4727d 100644 (file)
@@ -89,5 +89,12 @@ int main(int argc, char **argv) {
         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 iif=lo table=1");
+
+        test_rule_serialization("outgoing interface",
+                                "RULE=from=1::2/64 to=2::3/64 oif=eth0 table=1", NULL);
+
         return 0;
 }