summary refs log tree commit diff
path: root/libnm-core/nm-setting-ovs-interface.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-02-19 23:31:24 +0100
committerMichael Biebl <biebl@debian.org>2020-02-19 23:31:24 +0100
commite536d40eaea5dcdc0743b0a5e8e17faa46608a50 (patch)
tree0749832d8655215dac973866b4e724f3aea35448 /libnm-core/nm-setting-ovs-interface.c
parentf3c6d0765dff885e168b94f28e06ecc640315a74 (diff)
New upstream version 1.22.8 upstream/1.22.8
Diffstat (limited to 'libnm-core/nm-setting-ovs-interface.c')
-rw-r--r--libnm-core/nm-setting-ovs-interface.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/libnm-core/nm-setting-ovs-interface.c b/libnm-core/nm-setting-ovs-interface.c
index ecefd6a5..849b9a4e 100644
--- a/libnm-core/nm-setting-ovs-interface.c
+++ b/libnm-core/nm-setting-ovs-interface.c
@@ -67,6 +67,7 @@ _nm_setting_ovs_interface_verify_interface_type (NMSettingOvsInterface *self,
                                                  NMConnection *connection,
                                                  gboolean normalize,
                                                  gboolean *out_modified,
+                                                 const char **normalized_type,
                                                  GError **error)
 {
 	const char *type;
@@ -82,9 +83,11 @@ _nm_setting_ovs_interface_verify_interface_type (NMSettingOvsInterface *self,
 	} else
 		g_return_val_if_fail (!connection || NM_IS_CONNECTION (connection), FALSE);
 
+	g_return_val_if_fail (!normalized_type || !(*normalized_type), FALSE);
+
 	NM_SET_OUT (out_modified, FALSE);
 
-	type = self ? self->type : NULL;
+	type = self->type;
 
 	if (   type
 	    && !NM_IN_STRSET (type, "internal", "system", "patch", "dpdk")) {
@@ -212,6 +215,10 @@ _nm_setting_ovs_interface_verify_interface_type (NMSettingOvsInterface *self,
 		type = "internal";
 	else
 		type = "system";
+
+	if (normalized_type)
+		*normalized_type = type;
+
 normalize:
 	if (!normalize) {
 		if (!self) {
@@ -246,9 +253,11 @@ static int
 verify (NMSetting *setting, NMConnection *connection, GError **error)
 {
 	NMSettingOvsInterface *self = NM_SETTING_OVS_INTERFACE (setting);
+	NMSettingConnection *s_con = NULL;
+	const char *normalized_type = NULL;
+	int result = NM_SETTING_VERIFY_ERROR;
 
 	if (connection) {
-		NMSettingConnection *s_con;
 		const char *slave_type;
 
 		s_con = nm_connection_get_setting_connection (connection);
@@ -286,11 +295,39 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
 		}
 	}
 
-	return _nm_setting_ovs_interface_verify_interface_type (self,
-	                                                        connection,
-	                                                        FALSE,
-	                                                        NULL,
-	                                                        error);
+	result = _nm_setting_ovs_interface_verify_interface_type (self,
+	                                                          connection,
+	                                                          FALSE,
+	                                                          NULL,
+	                                                          &normalized_type,
+	                                                          error);
+
+	/* From 'man ovs-vswitchd.conf.db': OVS patch interfaces do not have
+	 * a limit on interface name length, all the other types do */
+	if (result != NM_SETTING_VERIFY_ERROR && s_con) {
+		gs_free_error GError *ifname_error = NULL;
+		const char *ifname = nm_setting_connection_get_interface_name (s_con);
+
+		normalized_type = self->type ? self->type : normalized_type;
+
+		if (   ifname
+		    && !nm_streq0 (normalized_type, "patch")
+		    && !nm_utils_ifname_valid (ifname,
+		                               NMU_IFACE_KERNEL,
+		                               &ifname_error)) {
+			g_clear_error (error);
+			g_set_error (error,
+			             NM_CONNECTION_ERROR,
+			             NM_CONNECTION_ERROR_INVALID_PROPERTY,
+			             "'%s': %s", ifname, ifname_error->message);
+			g_prefix_error (error, "%s.%s: ",
+			                NM_SETTING_CONNECTION_SETTING_NAME,
+			                NM_SETTING_CONNECTION_INTERFACE_NAME);
+			return NM_SETTING_VERIFY_ERROR;
+		}
+	}
+
+	return result;
 }
 
 /*****************************************************************************/