diff options
Diffstat (limited to 'libnm-core/nm-setting-vxlan.c')
| -rw-r--r-- | libnm-core/nm-setting-vxlan.c | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/libnm-core/nm-setting-vxlan.c b/libnm-core/nm-setting-vxlan.c index 213219ba..ea8d4546 100644 --- a/libnm-core/nm-setting-vxlan.c +++ b/libnm-core/nm-setting-vxlan.c @@ -1,9 +1,9 @@ -/* SPDX-License-Identifier: LGPL-2.1+ */ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2015 Red Hat, Inc. */ -#include "nm-default.h" +#include "libnm-core/nm-default-libnm-core.h" #include "nm-setting-vxlan.h" @@ -312,43 +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) { - g_set_error_literal(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_MISSING_PROPERTY, - _("property is missing")); - 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 (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 { + if (!remote_is_valid) { g_set_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("'%s' is not a valid IP address"), - priv->remote); + _("'%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) @@ -383,6 +376,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) /*****************************************************************************/ static void +_addrstr_set(char **dst, const char *src) +{ + gs_free char *old = NULL; + + old = *dst; + if (!src) + *dst = NULL; + else if (!nm_utils_parse_inaddr(AF_UNSPEC, src, dst)) + *dst = g_strdup(src); +} +/*****************************************************************************/ + +static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMSettingVxlan * setting = NM_SETTING_VXLAN(object); @@ -458,12 +464,10 @@ set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *ps priv->id = g_value_get_uint(value); break; case PROP_LOCAL: - g_free(priv->local); - priv->local = g_value_dup_string(value); + _addrstr_set(&priv->local, g_value_get_string(value)); break; case PROP_REMOTE: - g_free(priv->remote); - priv->remote = g_value_dup_string(value); + _addrstr_set(&priv->remote, g_value_get_string(value)); break; case PROP_SOURCE_PORT_MIN: priv->source_port_min = g_value_get_uint(value); @@ -531,7 +535,7 @@ nm_setting_vxlan_init(NMSettingVxlan *self) NMSetting * nm_setting_vxlan_new(void) { - return (NMSetting *) g_object_new(NM_TYPE_SETTING_VXLAN, NULL); + return g_object_new(NM_TYPE_SETTING_VXLAN, NULL); } static void |