]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/address-label: several cleanups for conf parsers
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 17 Aug 2024 03:38:44 +0000 (12:38 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Aug 2024 11:48:48 +0000 (20:48 +0900)
- Check userdata, instead of data, though they point to the same
  position.
- Support an empty string.
- Use UINT32_MAX, as the label is uint32_t.

src/network/networkd-address-label.c

index 3bd7d3c5aed1fc0f2631efd514390d7b0da07dde..7497eff36c5b897ac1b2a2d81743d2a9a7232585 100644 (file)
@@ -234,12 +234,18 @@ int config_parse_address_label_prefix(
         assert(section);
         assert(lvalue);
         assert(rvalue);
-        assert(data);
+        assert(userdata);
 
         r = address_label_new_static(network, filename, section_line, &n);
         if (r < 0)
                 return log_oom();
 
+        if (isempty(rvalue)) {
+                n->prefix_set = false;
+                TAKE_PTR(n);
+                return 0;
+        }
+
         r = in_addr_prefix_from_string(rvalue, AF_INET6, &a, &prefixlen);
         if (r < 0) {
                 log_syntax(unit, LOG_WARNING, filename, line, r,
@@ -257,7 +263,6 @@ int config_parse_address_label_prefix(
         n->prefix = a.in6;
         n->prefixlen = prefixlen;
         n->prefix_set = true;
-
         TAKE_PTR(n);
         return 0;
 }
@@ -283,25 +288,30 @@ int config_parse_address_label(
         assert(section);
         assert(lvalue);
         assert(rvalue);
-        assert(data);
+        assert(userdata);
 
         r = address_label_new_static(network, filename, section_line, &n);
         if (r < 0)
                 return log_oom();
 
+        if (isempty(rvalue)) {
+                n->label = UINT32_MAX;
+                TAKE_PTR(n);
+                return 0;
+        }
+
         r = safe_atou32(rvalue, &k);
         if (r < 0) {
                 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse address label, ignoring: %s", rvalue);
                 return 0;
         }
 
-        if (k == UINT_MAX) {
+        if (k == UINT32_MAX) {
                 log_syntax(unit, LOG_WARNING, filename, line, 0, "Address label is invalid, ignoring: %s", rvalue);
                 return 0;
         }
 
         n->label = k;
         TAKE_PTR(n);
-
         return 0;
 }