]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/netdev: fix resetting of 'inherit' field
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 16 Sep 2023 21:54:18 +0000 (23:54 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 22 Sep 2023 06:17:42 +0000 (08:17 +0200)
We have two fields: inherit and ttl, and ttl is ignored if inherit is true.
Setting TTL=inherit and later TTL=n would not work because we didn't unset
inherit.

src/network/netdev/geneve.c
src/network/netdev/vxlan.c

index f5f325711cd3f4c833c7c3063f36a1c9c785fd45..c60fe6974d5417157b3caed5bcb46d6b27b60bf2 100644 (file)
@@ -224,16 +224,22 @@ int config_parse_geneve_ttl(
         assert(data);
 
         Geneve *v = ASSERT_PTR(userdata);
+        int r;
 
         if (streq(rvalue, "inherit")) {
                 v->inherit = true;
+                v->ttl = 0;  /* unset the unused ttl field for clarity */
                 return 0;
         }
 
-        return config_parse_uint8_bounded(
+        r = config_parse_uint8_bounded(
                         unit, filename, line, section, section_line, lvalue, rvalue,
                         0, UINT8_MAX, true,
                         &v->ttl);
+        if (r <= 0)
+                return r;
+        v->inherit = false;
+        return 0;
 }
 
 static int netdev_geneve_verify(NetDev *netdev, const char *filename) {
index c91ed24cda12e1e6f7ec3a255ee5bbfe49e7f224..b7d3ee50859088cbbc2e28e769c781aa171a4b31 100644 (file)
@@ -351,34 +351,27 @@ int config_parse_vxlan_ttl(
                 void *data,
                 void *userdata) {
 
-        VxLan *v = userdata;
-        unsigned f;
-        int r;
-
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if (streq(rvalue, "inherit"))
-                v->inherit = true;
-        else {
-                r = safe_atou(rvalue, &f);
-                if (r < 0) {
-                        log_syntax(unit, LOG_WARNING, filename, line, r,
-                                   "Failed to parse VXLAN TTL '%s', ignoring assignment: %m", rvalue);
-                        return 0;
-                }
-
-                if (f > 255) {
-                        log_syntax(unit, LOG_WARNING, filename, line, 0,
-                                   "Invalid VXLAN TTL '%s'. TTL must be <= 255. Ignoring assignment.", rvalue);
-                        return 0;
-                }
+        VxLan *v = ASSERT_PTR(userdata);
+        int r;
 
-                v->ttl = f;
+        if (streq(rvalue, "inherit")) {
+                v->inherit = true;
+                v->ttl = 0;  /* unset the unused ttl field for clarity */
+                return 0;
         }
 
+        r = config_parse_unsigned_bounded(
+                        unit, filename, line, section, section_line, lvalue, rvalue,
+                        0, UINT8_MAX, true,
+                        &v->ttl);
+        if (r <= 0)
+                return r;
+        v->inherit = false;
         return 0;
 }