From de0163fc5c46eb9d04eb97075557012f81cd7567 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Wed, 19 Sep 2012 10:36:47 -0400 Subject: [PATCH] libnm-util: Improve NMSettingVlan's verify() Do slightly more validation if NMSettingVlan properties, and make sure that at least one method of specifying a parent is used. Remove the check that id is in range, since gobject will not allow you to set the property to a value outside its declared range anyway. --- libnm-util/nm-setting-vlan.c | 69 ++++++++++++++++++++++++++++-------- libnm-util/nm-setting-vlan.h | 7 ++-- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/libnm-util/nm-setting-vlan.c b/libnm-util/nm-setting-vlan.c index f69e0d8552..48e35e7e55 100644 --- a/libnm-util/nm-setting-vlan.c +++ b/libnm-util/nm-setting-vlan.c @@ -21,7 +21,10 @@ * (C) Copyright 2011 - 2012 Red Hat, Inc. */ +#include +#include #include + #include "nm-setting-vlan.h" #include "nm-param-spec-specialized.h" #include "nm-utils.h" @@ -436,8 +439,22 @@ static gboolean verify (NMSetting *setting, GSList *all_settings, GError **error) { NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting); + NMSettingConnection *s_con = NULL; + NMSettingWired *s_wired = NULL; + GSList *iter; - if (priv->iface_name && !priv->iface_name[0]) { + for (iter = all_settings; iter; iter = iter->next) { + if (NM_IS_SETTING_CONNECTION (iter->data)) + s_con = iter->data; + else if (NM_IS_SETTING_WIRED (iter->data)) + s_wired = iter->data; + } + + /* If iface_name is specified, it must be a valid interface name. We + * don't check that it matches parent and/or id, because we allowing + * renaming vlans to arbitrary names. + */ + if (priv->iface_name && !nm_utils_iface_valid_name (priv->iface_name)) { g_set_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, @@ -445,20 +462,44 @@ verify (NMSetting *setting, GSList *all_settings, GError **error) return FALSE; } - if (priv->parent && !priv->parent[0]) { - g_set_error (error, - NM_SETTING_VLAN_ERROR, - NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, - NM_SETTING_VLAN_PARENT); - return FALSE; - } + if (priv->parent) { + if (nm_utils_is_uuid (priv->parent)) { + /* If we have an NMSettingConnection:master with slave-type="vlan", + * then it must be the same UUID. + */ + if (s_con) { + const char *master = NULL, *slave_type = NULL; - if (priv->id > 4095) { - g_set_error (error, - NM_SETTING_VLAN_ERROR, - NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, - NM_SETTING_VLAN_ID); - return FALSE; + slave_type = nm_setting_connection_get_slave_type (s_con); + if (!g_strcmp0 (slave_type, NM_SETTING_VLAN_SETTING_NAME)) + master = nm_setting_connection_get_master (s_con); + + if (master && g_strcmp0 (priv->parent, master) != 0) { + g_set_error (error, + NM_SETTING_VLAN_ERROR, + NM_SETTING_VLAN_ERROR_INVALID_PARENT, + NM_SETTING_CONNECTION_MASTER); + return FALSE; + } + } + } else if (!nm_utils_iface_valid_name (priv->parent)) { + /* parent must be either a UUID or an interface name */ + g_set_error (error, + NM_SETTING_VLAN_ERROR, + NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, + NM_SETTING_VLAN_PARENT); + return FALSE; + } + } else { + /* If parent is NULL, the parent must be specified via + * NMSettingWired:mac-address. + */ + if (!s_wired || !nm_setting_wired_get_mac_address (s_wired)) { + g_set_error (error, + NM_SETTING_VLAN_ERROR, + NM_SETTING_VLAN_ERROR_MISSING_PROPERTY, + NM_SETTING_VLAN_PARENT); + } } if (priv->flags & ~(NM_VLAN_FLAG_REORDER_HEADERS | diff --git a/libnm-util/nm-setting-vlan.h b/libnm-util/nm-setting-vlan.h index 9d2d728b3c..019c6da071 100644 --- a/libnm-util/nm-setting-vlan.h +++ b/libnm-util/nm-setting-vlan.h @@ -43,12 +43,15 @@ G_BEGIN_DECLS * @NM_SETTING_VLAN_ERROR_UNKNOWN: unknown or unclassified error * @NM_SETTING_VLAN_ERROR_INVALID_PROPERTY: the property was invalid * @NM_SETTING_VLAN_ERROR_MISSING_PROPERTY: the property was missing and is - * required + * required + * @NM_SETTING_VLAN_ERROR_INVALID_PARENT: the VLAN parent was specified + * inconsistently */ typedef enum { NM_SETTING_VLAN_ERROR_UNKNOWN = 0, /*< nick=Unknown >*/ NM_SETTING_VLAN_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/ - NM_SETTING_VLAN_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/ + NM_SETTING_VLAN_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/ + NM_SETTING_VLAN_ERROR_INVALID_PARENT /*< nick=InvalidParent >*/ } NMSettingVlanError; #define NM_SETTING_VLAN_ERROR nm_setting_vlan_error_quark ()