networkd: unbork rule serialization
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Nov 2017 10:06:55 +0000 (10:06 +0000)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 27 Nov 2017 10:06:55 +0000 (10:06 +0000)
We'd write something like

RULE=from=250.250.240.0/24 to=(null)/0 tos=0 fwmark=0/0 table=12
RULE=from=250.250.250.0/24 to=(null)/0 tos=0 fwmark=0/0 table=11

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

index 93a2571..9ffbe39 100644 (file)
@@ -1005,7 +1005,6 @@ static void print_string_set(FILE *f, const char *field, OrderedSet *s) {
 static int manager_save(Manager *m) {
         _cleanup_ordered_set_free_free_ OrderedSet *dns = NULL, *ntp = NULL, *search_domains = NULL, *route_domains = NULL;
         RoutingPolicyRule *rule = NULL;
-        bool space = false;
         Link *link;
         Iterator i;
         _cleanup_free_ char *temp_path = NULL;
@@ -1132,28 +1131,48 @@ static int manager_save(Manager *m) {
 
         SET_FOREACH(rule, m->rules, i) {
                 _cleanup_free_ char *from_str = NULL, *to_str = NULL;
+                bool space = false;
+
                 fputs("RULE=", f);
 
                 if (!in_addr_is_null(rule->family, &rule->from)) {
                         r = in_addr_to_string(rule->family, &rule->from, &from_str);
                         if (r < 0)
                                 goto fail;
+
+                        fprintf(f, "from=%s/%hhu",
+                                from_str, rule->from_prefixlen);
+                        space = true;
                 }
 
                 if (!in_addr_is_null(rule->family, &rule->to)) {
                         r = in_addr_to_string(rule->family, &rule->to, &to_str);
                         if (r < 0)
                                 goto fail;
+
+                        fprintf(f, "%sto=%s/%hhu",
+                                space ? " " : "",
+                                to_str, rule->to_prefixlen);
+                        space = true;
                 }
 
-                fprintf(f, "from=%s%s/%hhu to=%s%s/%hhu tos=%hhu fwmark=%"PRIu32"/%"PRIu32" table=%"PRIu32,
-                        space ? " " : "", from_str, rule->from_prefixlen,
-                        space ? " " : "", to_str, rule->to_prefixlen,
-                        rule->tos,
-                        rule->fwmark, rule->fwmask,
-                        rule->table);
+                if (rule->tos != 0) {
+                        fprintf(f, "%stos=%hhu",
+                                space ? " " : "",
+                                rule->tos);
+                        space = true;
+                }
+
+                if (rule->fwmark != 0) {
+                        fprintf(f, "%sfwmark=%"PRIu32"/%"PRIu32,
+                                space ? " " : "",
+                                rule->fwmark, rule->fwmask);
+                        space = true;
+                }
 
-                fputc('\n', f);
+                fprintf(f, "%stable=%"PRIu32 "\n",
+                        space ? " " : "",
+                        rule->table);
         }
 
         r = fflush_and_check(f);
index 221ab4c..775b85e 100644 (file)
@@ -885,9 +885,6 @@ int routing_policy_rule_load(Manager *m) {
                 if (!p)
                         continue;
 
-                p = strchr(*i, '=');
-                p++;
-
                 r = routing_policy_rule_new(&rule);
                 if (r < 0)
                         return r;