diff options
| author | Michael Biebl <biebl@debian.org> | 2016-03-01 16:55:22 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2016-03-01 16:55:22 +0100 |
| commit | c2de0d98ba39e0a1a970d066fd19be786092f376 (patch) | |
| tree | 3838363c06a6019db6cf1f882ea34ebded63c38b /src/devices/nm-device-factory.c | |
| parent | 494f296a3baab08522617b24b1f126d8f9a17502 (diff) | |
Imported Upstream version 1.1.91 upstream/1.1.91
Diffstat (limited to 'src/devices/nm-device-factory.c')
| -rw-r--r-- | src/devices/nm-device-factory.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 75731b14..bd0ec002 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -18,17 +18,16 @@ * Copyright (C) 2014 Red Hat, Inc. */ -#include "config.h" +#include "nm-default.h" #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <string.h> - #include <gmodule.h> #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 }; @@ -156,35 +155,46 @@ nm_device_factory_get_connection_parent (NMDeviceFactory *factory, return NULL; } -static char * -get_virtual_iface_name (NMDeviceFactory *factory, - NMConnection *connection, - const char *parent_iface) -{ - const char *iface; - - /* For any other virtual connection, NMSettingConnection:interface-name is - * the virtual device name. - */ - iface = nm_connection_get_interface_name (connection); - g_return_val_if_fail (iface != NULL, NULL); - return g_strdup (iface); -} - char * -nm_device_factory_get_virtual_iface_name (NMDeviceFactory *factory, - NMConnection *connection, - const char *parent_iface) +nm_device_factory_get_connection_iface (NMDeviceFactory *factory, + NMConnection *connection, + const char *parent_iface, + GError **error) { + NMDeviceFactoryInterface *klass; + 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)) + klass = NM_DEVICE_FACTORY_GET_INTERFACE (factory); + + if (klass->get_connection_iface) + ifname = klass->get_connection_iface (factory, connection, parent_iface); + else + ifname = g_strdup (nm_connection_get_interface_name (connection)); + + if (!ifname) { + g_set_error (error, + NM_MANAGER_ERROR, + NM_MANAGER_ERROR_FAILED, + "failed to determine interface name: error determine 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; + if (!nm_utils_iface_valid_name (ifname)) { + g_set_error (error, + NM_MANAGER_ERROR, + NM_MANAGER_ERROR_FAILED, + "failed to determine interface name: name \"%s\" is invalid", + ifname); + g_free (ifname); + return NULL; + } + + return ifname; } /*******************************************************************/ @@ -192,8 +202,6 @@ nm_device_factory_get_virtual_iface_name (NMDeviceFactory *factory, static void nm_device_factory_default_init (NMDeviceFactoryInterface *factory_iface) { - factory_iface->get_virtual_iface_name = get_virtual_iface_name; - /* Signals */ signals[DEVICE_ADDED] = g_signal_new (NM_DEVICE_FACTORY_DEVICE_ADDED, NM_TYPE_DEVICE_FACTORY, |