initrd: fix parsing IPv6 prefix length

The generator didn't accept prefix lengths > 32 for IPv6:

$ src/initrd/nm-initrd-generator --stdout -- ip=[fd01::1]:::40::ens0
 <warn>  [1600851580.7875] cmdline-reader: Invalid IP mask: 40

https://bugzilla.redhat.com/show_bug.cgi?id=1879795
(cherry picked from commit 364c7c278a)
This commit is contained in:
Beniamino Galvani 2020-09-23 10:58:03 +02:00
parent eeef91aa6e
commit 09804cac6e
2 changed files with 5 additions and 3 deletions

View file

@ -426,12 +426,13 @@ reader_parse_ip (Reader *reader, const char *sysfs_dir, char *argument)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
if (netmask && *netmask) {
gboolean is_ipv4 = client_ip_family == AF_INET;
NMIPAddr addr;
if (nm_utils_parse_inaddr_bin (AF_INET, netmask, NULL, &addr))
if (is_ipv4 && nm_utils_parse_inaddr_bin (AF_INET, netmask, NULL, &addr))
client_ip_prefix = nm_utils_ip4_netmask_to_prefix (addr.addr4);
else
client_ip_prefix = _nm_utils_ascii_str_to_int64 (netmask, 10, 0, 32, -1);
client_ip_prefix = _nm_utils_ascii_str_to_int64 (netmask, 10, 0, is_ipv4 ? 32 : 128, -1);
if (client_ip_prefix == -1)
_LOGW (LOGD_CORE, "Invalid IP mask: %s", netmask);

View file

@ -341,7 +341,7 @@ test_multiple_merge (void)
{
gs_unref_hashtable GHashTable *connections = NULL;
const char *const*ARGV = NM_MAKE_STRV ("ip=192.0.2.2:::::eth0",
"ip=[2001:db8::2]:::::eth0");
"ip=[2001:db8::2]:::56::eth0");
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
@ -384,6 +384,7 @@ test_multiple_merge (void)
ip_addr = nm_setting_ip_config_get_address (s_ip6, 0);
g_assert (ip_addr);
g_assert_cmpstr (nm_ip_address_get_address (ip_addr), ==, "2001:db8::2");
g_assert_cmpint (nm_ip_address_get_prefix (ip_addr), ==, 56);
}
static void