summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-01-21 17:36:08 +0100
committerThomas Haller <thaller@redhat.com>2016-01-21 18:38:52 +0100
commit944065c1154a656846dcf37e1cce35d3fb1792ed (patch)
tree5db416e6bd9a5e85b0678bc7e43828dfba74e0ba
parentf2399a69760e8d14b91e523127eb187d6337530f (diff)
core: check generated virtual interfaceplatform name
https://bugzilla.redhat.com/show_bug.cgi?id=1300755
-rw-r--r--src/devices/nm-device-factory.c48
-rw-r--r--src/devices/nm-device-factory.h3
-rw-r--r--src/nm-manager.c19
3 files changed, 48 insertions, 22 deletions
diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c
index 75731b14f2..2c2aae9d27 100644
--- a/src/devices/nm-device-factory.c
+++ b/src/devices/nm-device-factory.c
@@ -29,6 +29,7 @@
#include "nm-device-factory.h"
#include "nm-default.h"
#include "nm-platform.h"
+#include "nm-utils.h"
const NMLinkType _nm_device_factory_no_default_links[] = { NM_LINK_TYPE_NONE };
const char *_nm_device_factory_no_default_settings[] = { NULL };
@@ -174,17 +175,54 @@ get_virtual_iface_name (NMDeviceFactory *factory,
char *
nm_device_factory_get_virtual_iface_name (NMDeviceFactory *factory,
NMConnection *connection,
- const char *parent_iface)
+ const char *parent_iface,
+ GError **error)
{
+ char *ifname;
+
g_return_val_if_fail (factory != NULL, NULL);
g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ if (!nm_connection_is_virtual (connection)) {
+ g_set_error (error,
+ NM_MANAGER_ERROR,
+ NM_MANAGER_ERROR_FAILED,
+ "failed to determine virtual interface name: connection type '%s' is not a software device",
+ nm_connection_get_connection_type (connection));
+ return NULL;
+ }
- if (!nm_connection_is_virtual (connection))
+ if (!NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_virtual_iface_name) {
+ g_set_error (error,
+ NM_MANAGER_ERROR,
+ NM_MANAGER_ERROR_FAILED,
+ "failed to determine virtual interface name: cannot generate name for %s",
+ nm_connection_get_connection_type (connection));
return NULL;
+ }
- if (NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_virtual_iface_name)
- return NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_virtual_iface_name (factory, connection, parent_iface);
- return NULL;
+ ifname = NM_DEVICE_FACTORY_GET_INTERFACE (factory)->get_virtual_iface_name (factory, connection, parent_iface);
+ if (!ifname) {
+ g_set_error (error,
+ NM_MANAGER_ERROR,
+ NM_MANAGER_ERROR_FAILED,
+ "failed to determine virtual interface name: error generating name for %s",
+ nm_connection_get_connection_type (connection));
+ return NULL;
+ }
+
+ if (!nm_utils_iface_valid_name (ifname)) {
+ g_set_error (error,
+ NM_MANAGER_ERROR,
+ NM_MANAGER_ERROR_FAILED,
+ "failed to determine virtual interface name: invalid name \"%s\" generated",
+ ifname);
+ g_free (ifname);
+ return NULL;
+ }
+
+ return ifname;
}
/*******************************************************************/
diff --git a/src/devices/nm-device-factory.h b/src/devices/nm-device-factory.h
index 9b7cb35a1d..943fc5cd13 100644
--- a/src/devices/nm-device-factory.h
+++ b/src/devices/nm-device-factory.h
@@ -177,7 +177,8 @@ const char *nm_device_factory_get_connection_parent (NMDeviceFactory *factory,
char * nm_device_factory_get_virtual_iface_name (NMDeviceFactory *factory,
NMConnection *connection,
- const char *parent_iface);
+ const char *parent_iface,
+ GError **error);
void nm_device_factory_start (NMDeviceFactory *factory);
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 42d4b0a7ab..c2b4e531ab 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -974,15 +974,6 @@ get_virtual_iface_name (NMManager *self,
if (out_parent)
*out_parent = NULL;
- if (!nm_connection_is_virtual (connection)) {
- g_set_error (error,
- NM_MANAGER_ERROR,
- NM_MANAGER_ERROR_FAILED,
- "NetworkManager plugin for '%s' unavailable",
- nm_connection_get_connection_type (connection));
- return NULL;
- }
-
factory = nm_device_factory_manager_find_factory_for_connection (connection);
if (!factory) {
g_set_error (error,
@@ -996,14 +987,10 @@ get_virtual_iface_name (NMManager *self,
parent = find_parent_device_for_connection (self, connection);
iface = nm_device_factory_get_virtual_iface_name (factory,
connection,
- parent ? nm_device_get_ip_iface (parent) : NULL);
- if (!iface) {
- g_set_error_literal (error,
- NM_MANAGER_ERROR,
- NM_MANAGER_ERROR_UNKNOWN_DEVICE,
- "failed to determine virtual interface name");
+ parent ? nm_device_get_ip_iface (parent) : NULL,
+ error);
+ if (!iface)
return NULL;
- }
if (out_parent)
*out_parent = parent;