]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: assume prefix length is full address size
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 19 Jan 2023 09:21:34 +0000 (18:21 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 19 Jan 2023 13:09:10 +0000 (22:09 +0900)
The commit 0f707207b9fc04d45ad176930cfefc77c0068545 enables strong
warning about missing prefix length in Address= setting.
The change was done in v241, and was about 4 years ago.
Let's drop the legacy assumption and make the parser consistent with
'ip address' command.

C.f. #11307.
Closes #26102.

src/network/networkd-address.c
src/network/test-networkd-conf.c
test/test-network/conf/25-dhcp-client-ipv4-only.network

index c691a5e0575c05d261196697e09fbe85cd00ed6c..b8b9dc153b088a68b1cad66ae71b773568a6dc06 100644 (file)
@@ -1683,12 +1683,11 @@ int config_parse_address(
         /* Address=address/prefixlen */
         r = in_addr_prefix_from_string_auto_internal(rvalue, PREFIXLEN_REFUSE, &f, &buffer, &prefixlen);
         if (r == -ENOANO) {
-                log_syntax(unit, LOG_WARNING, filename, line, r,
-                           "An address '%s' is specified without prefix length. "
-                           "The behavior of parsing addresses without prefix length will be changed in the future release. "
-                           "Please specify prefix length explicitly.", rvalue);
-
-                r = in_addr_prefix_from_string_auto_internal(rvalue, PREFIXLEN_LEGACY, &f, &buffer, &prefixlen);
+                r = in_addr_prefix_from_string_auto(rvalue, &f, &buffer, &prefixlen);
+                if (r >= 0)
+                        log_syntax(unit, LOG_WARNING, filename, line, r,
+                                   "An address '%s' is specified without prefix length. Assuming the prefix length is %u."
+                                   "Please specify the prefix length explicitly.", rvalue, prefixlen);
         }
         if (r < 0) {
                 log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid address '%s', ignoring assignment: %m", rvalue);
index 2e4ca0cb5f87d7af87da08375741c78fcf30f43b..f6f068706a81926f86e6c5ce50cc8d8574090692 100644 (file)
@@ -197,7 +197,7 @@ TEST(config_parse_address) {
         test_config_parse_address_one("", AF_INET, 0, NULL, 0);
         test_config_parse_address_one("/", AF_INET, 0, NULL, 0);
         test_config_parse_address_one("/8", AF_INET, 0, NULL, 0);
-        test_config_parse_address_one("1.2.3.4", AF_INET, 1, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 8);
+        test_config_parse_address_one("1.2.3.4", AF_INET, 1, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32);
         test_config_parse_address_one("1.2.3.4/0", AF_INET, 1, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0);
         test_config_parse_address_one("1.2.3.4/1", AF_INET, 1, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1);
         test_config_parse_address_one("1.2.3.4/2", AF_INET, 1, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2);
@@ -208,7 +208,7 @@ TEST(config_parse_address) {
         test_config_parse_address_one("", AF_INET6, 0, NULL, 0);
         test_config_parse_address_one("/", AF_INET6, 0, NULL, 0);
         test_config_parse_address_one("/8", AF_INET6, 0, NULL, 0);
-        test_config_parse_address_one("::1", AF_INET6, 1, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0);
+        test_config_parse_address_one("::1", AF_INET6, 1, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128);
         test_config_parse_address_one("::1/0", AF_INET6, 1, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0);
         test_config_parse_address_one("::1/1", AF_INET6, 1, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1);
         test_config_parse_address_one("::1/2", AF_INET6, 1, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2);
index bd8843b177847727ea67775e9286e4f94c54587e..80d6bdc1d428673f339914a5fe309011cbc5ac7b 100644 (file)
@@ -5,7 +5,7 @@ Name=veth99
 [Network]
 DHCP=ipv4
 IPv6AcceptRA=no
-Address=192.168.5.250
+Address=192.168.5.250/24
 
 [DHCPv4]
 UseDomains=yes