summaryrefslogtreecommitdiff
path: root/libnm-util/nm-setting-vlan.c
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 /libnm-util/nm-setting-vlan.c
parent6878d20ac430207b49f46c6fafe705747c02e199 (diff)
downloadNetworkManager-de0163fc5c46eb9d04eb97075557012f81cd7567.tar.gz
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.
Diffstat (limited to 'libnm-util/nm-setting-vlan.c')
-rw-r--r--libnm-util/nm-setting-vlan.c71
1 files changed, 56 insertions, 15 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 <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 |