diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index bdbd17aac..567cb73e5 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5788,7 +5788,7 @@ _nm_sett_info_property_override_create_array_ip_config(int addr_family) .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway), .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, gateway), - .direct_set_string_ip_address_addr_family = addr_family); + .direct_set_string_ip_address_addr_family = addr_family + 1); _nm_properties_override_gobj( properties_override, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index ccf80e971..2ae854c9d 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -668,7 +668,7 @@ _property_direct_set_string(const NMSettInfoProperty *property_info, char **dst, } if (property_info->direct_set_string_ip_address_addr_family != 0) { s = _nm_utils_ipaddr_canonical_or_invalid( - property_info->direct_set_string_ip_address_addr_family, + property_info->direct_set_string_ip_address_addr_family - 1, src); goto out_take; } diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index b4c67079e..8e804dadf 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4585,6 +4585,13 @@ test_setting_metadata(void) + (!!sip->direct_set_string_ascii_strdown) + (sip->direct_set_string_ip_address_addr_family != 0); + G_STATIC_ASSERT_EXPR(AF_UNSPEC + 1 != 0); + g_assert(NM_IN_SET((int) sip->direct_set_string_ip_address_addr_family, + 0, + AF_UNSPEC + 1, + AF_INET + 1, + AF_INET6 + 1)); + /* currently, we have no cases where special options are mixed. There is no problem to support * that, but as it's not needed, don't do it for now. */ g_assert_cmpint(n_special_options, <=, 1); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index f18f16cfd..429dc2b84 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -767,8 +767,10 @@ struct _NMSettInfoProperty { * MAC address length. */ guint8 direct_set_string_mac_address_len : 5; - /* If non-zero, this is the addr-family (AF_INET/AF_INET6) for normalizing an IP - * address. */ + /* If non-zero, this is the addr-family (AF_UNSPEC/AF_INET/AF_INET6) for normalizing an IP + * address. Note that AF_UNSPEC is zero, so to differentiate between zero and AF_UNSPEC + * this value is actually the address family + 1. So either zero or AF_UNSPEC+1, AF_INET+1, + * or AF_INET6+1. */ guint8 direct_set_string_ip_address_addr_family : 5; /* Usually, properties that are set to the default value for the GParamSpec