diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-01-19 18:21:34 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-01-19 22:09:10 +0900 |
commit | e5e0743189797afc58cbfe0a742a2c66eb921dd5 (patch) | |
tree | 9418d50c956223255b9b5d7e904a4db47eda8f11 /src/network | |
parent | a93cc5d911320b87150ac1ae89a999ceeb691e27 (diff) | |
download | systemd-e5e0743189797afc58cbfe0a742a2c66eb921dd5.tar.gz |
network: assume prefix length is full address size
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.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-address.c | 11 | ||||
-rw-r--r-- | src/network/test-networkd-conf.c | 4 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index c691a5e057..b8b9dc153b 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -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); diff --git a/src/network/test-networkd-conf.c b/src/network/test-networkd-conf.c index 2e4ca0cb5f..f6f068706a 100644 --- a/src/network/test-networkd-conf.c +++ b/src/network/test-networkd-conf.c @@ -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); |