From a93cc5d911320b87150ac1ae89a999ceeb691e27 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Jan 2023 21:21:52 +0900 Subject: [PATCH 1/4] test-network: drop unused file --- .../conf/25-dhcp-client-with-static-address.network | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 test/test-network/conf/25-dhcp-client-with-static-address.network diff --git a/test/test-network/conf/25-dhcp-client-with-static-address.network b/test/test-network/conf/25-dhcp-client-with-static-address.network deleted file mode 100644 index 7c9d94957f..0000000000 --- a/test/test-network/conf/25-dhcp-client-with-static-address.network +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later -[Match] -Name=veth99 - -[Network] -DHCP=ipv4 -IPv6AcceptRA=no -Address=192.168.5.250 From e5e0743189797afc58cbfe0a742a2c66eb921dd5 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Jan 2023 18:21:34 +0900 Subject: [PATCH 2/4] 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. --- src/network/networkd-address.c | 11 +++++------ src/network/test-networkd-conf.c | 4 ++-- .../conf/25-dhcp-client-ipv4-only.network | 2 +- 3 files changed, 8 insertions(+), 9 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); diff --git a/test/test-network/conf/25-dhcp-client-ipv4-only.network b/test/test-network/conf/25-dhcp-client-ipv4-only.network index bd8843b177..80d6bdc1d4 100644 --- a/test/test-network/conf/25-dhcp-client-ipv4-only.network +++ b/test/test-network/conf/25-dhcp-client-ipv4-only.network @@ -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 From 3402357063f73cc96ff0412b46242b4175d1c11f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Jan 2023 21:20:24 +0900 Subject: [PATCH 3/4] in-addr-util: drop unused mode to parse prefix length --- src/basic/in-addr-util.c | 8 ----- src/basic/in-addr-util.h | 1 - src/test/test-in-addr-util.c | 61 +++++++++++++++--------------------- 3 files changed, 25 insertions(+), 45 deletions(-) diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index 07ac87c6c4..30d90cce0d 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -898,14 +898,6 @@ int in_addr_prefix_from_string_auto_internal( break; case PREFIXLEN_REFUSE: return -ENOANO; /* To distinguish this error from others. */ - case PREFIXLEN_LEGACY: - if (family == AF_INET) { - r = in4_addr_default_prefixlen(&buffer.in, &k); - if (r < 0) - return r; - } else - k = 0; - break; default: assert_not_reached(); } diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h index 19354ad404..200b9eb69d 100644 --- a/src/basic/in-addr-util.h +++ b/src/basic/in-addr-util.h @@ -153,7 +153,6 @@ int in_addr_prefix_from_string(const char *p, int family, union in_addr_union *r typedef enum InAddrPrefixLenMode { PREFIXLEN_FULL, /* Default to prefixlen of address size, 32 for IPv4 or 128 for IPv6, if not specified. */ PREFIXLEN_REFUSE, /* Fail with -ENOANO if prefixlen is not specified. */ - PREFIXLEN_LEGACY, /* Default to legacy default prefixlen calculation from address if not specified. */ } InAddrPrefixLenMode; int in_addr_prefix_from_string_auto_internal(const char *p, InAddrPrefixLenMode mode, int *ret_family, union in_addr_union *ret_prefix, unsigned char *ret_prefixlen); diff --git a/src/test/test-in-addr-util.c b/src/test/test-in-addr-util.c index 31d767e41d..93ab1c5d48 100644 --- a/src/test/test-in-addr-util.c +++ b/src/test/test-in-addr-util.c @@ -14,9 +14,7 @@ static void test_in_addr_prefix_from_string_one( const union in_addr_union *u, unsigned char prefixlen, int ret_refuse, - unsigned char prefixlen_refuse, - int ret_legacy, - unsigned char prefixlen_legacy) { + unsigned char prefixlen_refuse) { union in_addr_union q; unsigned char l; @@ -46,43 +44,34 @@ static void test_in_addr_prefix_from_string_one( assert_se(in_addr_equal(family, &q, u)); assert_se(l == prefixlen_refuse); } - - r = in_addr_prefix_from_string_auto_internal(p, PREFIXLEN_LEGACY, &f, &q, &l); - assert_se(r == ret_legacy); - - if (r >= 0) { - assert_se(f == family); - assert_se(in_addr_equal(family, &q, u)); - assert_se(l == prefixlen_legacy); - } } TEST(in_addr_prefix_from_string) { - test_in_addr_prefix_from_string_one("", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("/", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("/8", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, -ENOANO, 0, 0, 8); - test_in_addr_prefix_from_string_one("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, 0, 0, 0, 0); - test_in_addr_prefix_from_string_one("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, 0, 1, 0, 1); - test_in_addr_prefix_from_string_one("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, 0, 2, 0, 2); - test_in_addr_prefix_from_string_one("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, 0, 32, 0, 32); - test_in_addr_prefix_from_string_one("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0); - test_in_addr_prefix_from_string_one("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0); - test_in_addr_prefix_from_string_one("::1", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("/", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("/8", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("1.2.3.4", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, -ENOANO, 0); + test_in_addr_prefix_from_string_one("1.2.3.4/0", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 0, 0, 0); + test_in_addr_prefix_from_string_one("1.2.3.4/1", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 1, 0, 1); + test_in_addr_prefix_from_string_one("1.2.3.4/2", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 2, 0, 2); + test_in_addr_prefix_from_string_one("1.2.3.4/32", AF_INET, 0, &(union in_addr_union) { .in = (struct in_addr) { .s_addr = htobe32(0x01020304) } }, 32, 0, 32); + test_in_addr_prefix_from_string_one("1.2.3.4/33", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0); + test_in_addr_prefix_from_string_one("1.2.3.4/-1", AF_INET, -ERANGE, NULL, 0, -ERANGE, 0); + test_in_addr_prefix_from_string_one("::1", AF_INET, -EINVAL, NULL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("/", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("/8", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0, -EINVAL, 0); - test_in_addr_prefix_from_string_one("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, -ENOANO, 0, 0, 0); - test_in_addr_prefix_from_string_one("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, 0, 0, 0, 0); - test_in_addr_prefix_from_string_one("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, 0, 1, 0, 1); - test_in_addr_prefix_from_string_one("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, 0, 2, 0, 2); - test_in_addr_prefix_from_string_one("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, 0, 32, 0, 32); - test_in_addr_prefix_from_string_one("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, 0, 33, 0, 33); - test_in_addr_prefix_from_string_one("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, 0, 64, 0, 64); - test_in_addr_prefix_from_string_one("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, 0, 128, 0, 128); - test_in_addr_prefix_from_string_one("::1/129", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0); - test_in_addr_prefix_from_string_one("::1/-1", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0, -ERANGE, 0); + test_in_addr_prefix_from_string_one("", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("/", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("/8", AF_INET6, -EINVAL, NULL, 0, -EINVAL, 0); + test_in_addr_prefix_from_string_one("::1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, -ENOANO, 0); + test_in_addr_prefix_from_string_one("::1/0", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 0, 0, 0); + test_in_addr_prefix_from_string_one("::1/1", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 1, 0, 1); + test_in_addr_prefix_from_string_one("::1/2", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 2, 0, 2); + test_in_addr_prefix_from_string_one("::1/32", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 32, 0, 32); + test_in_addr_prefix_from_string_one("::1/33", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 33, 0, 33); + test_in_addr_prefix_from_string_one("::1/64", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 64, 0, 64); + test_in_addr_prefix_from_string_one("::1/128", AF_INET6, 0, &(union in_addr_union) { .in6 = IN6ADDR_LOOPBACK_INIT }, 128, 0, 128); + test_in_addr_prefix_from_string_one("::1/129", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0); + test_in_addr_prefix_from_string_one("::1/-1", AF_INET6, -ERANGE, NULL, 0, -ERANGE, 0); } static void test_in_addr_prefix_to_string_valid(int family, const char *p) { From 580586291fa17d9a5e98de9dce3658baed163a18 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 19 Jan 2023 21:27:24 +0900 Subject: [PATCH 4/4] NEWS: mention that Address= assumes /32 or /128 prefix length if not specified --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index eb7c24c830..67bb7a9b8d 100644 --- a/NEWS +++ b/NEWS @@ -136,6 +136,10 @@ CHANGES WITH 253 in spe: it stops. This is the analog of the [DHCPv4] SendRelease= setting. It is enabled by default. + * If the Address= setting in [Network] or [Address] sections in .network + specified without its prefix length, then now systemd-networkd assumes + /32 for IPv4 or /128 for IPv6 addresses. + Changes in systemd-dissect: * systemd-dissect gained a new option --list, to print the paths fo the