From 65a253f7146df793eb9fdabc5a6ef54c633efec0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 20 Oct 2020 13:38:43 +0200 Subject: libnm: fix detecting address family for error message in NMSettingVxlan.verify() The address family of local/remote addresses must correspond. Fix the detection of the address family, so that error message is correct. --- libnm-core/nm-setting-vxlan.c | 59 ++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/libnm-core/nm-setting-vxlan.c b/libnm-core/nm-setting-vxlan.c index 34d2cd476f..44772fc57f 100644 --- a/libnm-core/nm-setting-vxlan.c +++ b/libnm-core/nm-setting-vxlan.c @@ -312,39 +312,36 @@ nm_setting_vxlan_get_l3_miss(NMSettingVxlan *setting) static gboolean verify(NMSetting *setting, NMConnection *connection, GError **error) { - NMSettingVxlanPrivate *priv = NM_SETTING_VXLAN_GET_PRIVATE(setting); - int family = AF_UNSPEC; - - if (priv->remote) { - if (nm_utils_ipaddr_is_valid(AF_INET, priv->remote)) - family = AF_INET; - else if (nm_utils_ipaddr_is_valid(AF_INET6, priv->remote)) - family = AF_INET6; - else { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("'%s' is not a valid IP address"), - priv->remote); - g_prefix_error(error, - "%s.%s: ", - NM_SETTING_VXLAN_SETTING_NAME, - NM_SETTING_VXLAN_REMOTE); - return FALSE; - } + NMSettingVxlanPrivate *priv = NM_SETTING_VXLAN_GET_PRIVATE(setting); + int addr_family = AF_UNSPEC; + gboolean remote_is_valid = TRUE; + gboolean local_is_valid = TRUE; + + if (priv->remote && !nm_utils_parse_inaddr_bin(addr_family, priv->remote, &addr_family, NULL)) + remote_is_valid = FALSE; + if (priv->local && !nm_utils_parse_inaddr_bin(addr_family, priv->local, &addr_family, NULL)) + local_is_valid = FALSE; + + if (!remote_is_valid) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("'%s' is not a valid IP%s address"), + priv->remote, + addr_family == AF_UNSPEC ? "" : (addr_family == AF_INET ? "4" : "6")); + g_prefix_error(error, "%s.%s: ", NM_SETTING_VXLAN_SETTING_NAME, NM_SETTING_VXLAN_REMOTE); + return FALSE; } - if (priv->local) { - if (!nm_utils_ipaddr_is_valid(family, priv->local)) { - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("'%s' is not a valid IP%c address"), - priv->local, - family == AF_INET ? '4' : '6'); - g_prefix_error(error, "%s.%s: ", NM_SETTING_VXLAN_SETTING_NAME, NM_SETTING_VXLAN_LOCAL); - return FALSE; - } + if (!local_is_valid) { + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("'%s' is not a valid IP%s address"), + priv->local, + addr_family == AF_UNSPEC ? "" : (addr_family == AF_INET ? "4" : "6")); + g_prefix_error(error, "%s.%s: ", NM_SETTING_VXLAN_SETTING_NAME, NM_SETTING_VXLAN_LOCAL); + return FALSE; } if (priv->parent && !nm_utils_ifname_valid_kernel(priv->parent, NULL) -- cgit v1.2.3