summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2012-09-19 10:36:47 -0400
committerDan Winship <danw@gnome.org>2012-09-27 13:57:20 -0400
commitde0163fc5c46eb9d04eb97075557012f81cd7567 (patch)
tree29d9f02c71014c26308af272035a59d398eb5822
parent6878d20ac430207b49f46c6fafe705747c02e199 (diff)
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.
-rw-r--r--libnm-util/nm-setting-vlan.c71
-rw-r--r--libnm-util/nm-setting-vlan.h7
2 files changed, 61 insertions, 17 deletions
diff --git a/libnm-util/nm-setting-vlan.c b/libnm-util/nm-setting-vlan.c
index f69e0d85..48e35e7e 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 <stdlib.h>
+#include <string.h>
#include <dbus/dbus-glib.h>
+
#include "nm-setting-vlan.h"
#include "nm-param-spec-specialized.h"
#include "nm-utils.h"
@@ -436,29 +439,67 @@ static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
-
- if (priv->iface_name && !priv->iface_name[0]) {
- g_set_error (error,
- NM_SETTING_VLAN_ERROR,
- NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
- NM_SETTING_VLAN_INTERFACE_NAME);
- return FALSE;
+ NMSettingConnection *s_con = NULL;
+ NMSettingWired *s_wired = NULL;
+ GSList *iter;
+
+ 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 (priv->parent && !priv->parent[0]) {
+ /* 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,
- NM_SETTING_VLAN_PARENT);
+ NM_SETTING_VLAN_INTERFACE_NAME);
return FALSE;
}
- if (priv->id > 4095) {
- g_set_error (error,
- NM_SETTING_VLAN_ERROR,
- NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
- NM_SETTING_VLAN_ID);
- 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;
+
+ 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 9d2d728b..019c6da0 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 ()