2011-10-14 10:13:49 -04:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2011 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
|
|
|
|
|
#include <linux/if_infiniband.h>
|
|
|
|
|
|
|
|
|
|
#include "nm-device-infiniband.h"
|
|
|
|
|
#include "nm-logging.h"
|
|
|
|
|
#include "NetworkManagerUtils.h"
|
|
|
|
|
#include "nm-device-private.h"
|
2012-02-08 12:56:52 -05:00
|
|
|
#include "nm-enum-types.h"
|
2013-05-07 12:18:41 -04:00
|
|
|
#include "nm-dbus-manager.h"
|
2014-07-17 17:06:44 -04:00
|
|
|
#include "nm-activation-request.h"
|
|
|
|
|
#include "nm-ip4-config.h"
|
|
|
|
|
#include "nm-platform.h"
|
2014-09-05 16:07:43 -05:00
|
|
|
#include "nm-device-factory.h"
|
2014-10-21 22:09:52 -04:00
|
|
|
#include "nm-core-internal.h"
|
2011-10-14 10:13:49 -04:00
|
|
|
|
|
|
|
|
#include "nm-device-infiniband-glue.h"
|
|
|
|
|
|
|
|
|
|
|
2013-05-07 16:18:19 -04:00
|
|
|
G_DEFINE_TYPE (NMDeviceInfiniband, nm_device_infiniband, NM_TYPE_DEVICE)
|
2011-10-14 10:13:49 -04:00
|
|
|
|
|
|
|
|
#define NM_DEVICE_INFINIBAND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_INFINIBAND, NMDeviceInfinibandPrivate))
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2013-05-01 09:28:16 -04:00
|
|
|
int dummy;
|
2011-10-14 10:13:49 -04:00
|
|
|
} NMDeviceInfinibandPrivate;
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_infiniband_init (NMDeviceInfiniband * self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 15:15:38 +02:00
|
|
|
static NMDeviceCapabilities
|
2012-09-27 12:12:15 -04:00
|
|
|
get_generic_capabilities (NMDevice *dev)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
2013-05-17 10:58:38 -05:00
|
|
|
return NM_DEVICE_CAP_CARRIER_DETECT;
|
2011-10-14 10:13:49 -04:00
|
|
|
}
|
|
|
|
|
|
2011-11-14 14:52:40 -05:00
|
|
|
static NMActStageReturn
|
2012-09-27 12:12:15 -04:00
|
|
|
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
2011-11-14 14:52:40 -05:00
|
|
|
{
|
2013-09-11 09:19:21 -05:00
|
|
|
NMActStageReturn ret;
|
2011-11-14 14:52:40 -05:00
|
|
|
NMActRequest *req;
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
const char *transport_mode;
|
2012-11-16 13:57:47 -06:00
|
|
|
char *mode_path;
|
2011-11-14 14:52:40 -05:00
|
|
|
gboolean ok;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
2013-09-11 09:19:21 -05:00
|
|
|
ret = NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->act_stage1_prepare (dev, reason);
|
|
|
|
|
if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2011-11-14 14:52:40 -05:00
|
|
|
req = nm_device_get_act_request (dev);
|
|
|
|
|
g_return_val_if_fail (req != NULL, NM_ACT_STAGE_RETURN_FAILURE);
|
|
|
|
|
|
|
|
|
|
connection = nm_act_request_get_connection (req);
|
|
|
|
|
g_assert (connection);
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
g_assert (s_infiniband);
|
|
|
|
|
|
|
|
|
|
transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband);
|
|
|
|
|
|
2014-03-12 12:49:34 +01:00
|
|
|
mode_path = g_strdup_printf ("/sys/class/net/%s/mode",
|
|
|
|
|
ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (dev)));
|
2011-11-14 14:52:40 -05:00
|
|
|
if (!g_file_test (mode_path, G_FILE_TEST_EXISTS)) {
|
|
|
|
|
g_free (mode_path);
|
|
|
|
|
|
|
|
|
|
if (!strcmp (transport_mode, "datagram"))
|
|
|
|
|
return NM_ACT_STAGE_RETURN_SUCCESS;
|
|
|
|
|
else {
|
|
|
|
|
*reason = NM_DEVICE_STATE_REASON_INFINIBAND_MODE;
|
|
|
|
|
return NM_ACT_STAGE_RETURN_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
ok = nm_platform_sysctl_set (NM_PLATFORM_GET, mode_path, transport_mode);
|
2011-11-14 14:52:40 -05:00
|
|
|
g_free (mode_path);
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
*reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
|
|
|
|
|
return NM_ACT_STAGE_RETURN_FAILURE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 09:19:21 -05:00
|
|
|
return NM_ACT_STAGE_RETURN_SUCCESS;
|
2011-11-14 14:52:40 -05:00
|
|
|
}
|
|
|
|
|
|
2011-10-14 10:13:49 -04:00
|
|
|
static void
|
2012-09-27 12:12:15 -04:00
|
|
|
ip4_config_pre_commit (NMDevice *self, NMIP4Config *config)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
guint32 mtu;
|
|
|
|
|
|
2011-12-05 12:27:49 +01:00
|
|
|
connection = nm_device_get_connection (self);
|
2011-10-14 10:13:49 -04:00
|
|
|
g_assert (connection);
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
g_assert (s_infiniband);
|
|
|
|
|
|
|
|
|
|
/* MTU override */
|
|
|
|
|
mtu = nm_setting_infiniband_get_mtu (s_infiniband);
|
|
|
|
|
if (mtu)
|
2014-10-09 18:51:11 +02:00
|
|
|
nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_USER);
|
2011-10-14 10:13:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2014-05-30 13:44:53 -05:00
|
|
|
check_connection_compatible (NMDevice *device, NMConnection *connection)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->check_connection_compatible (device, connection))
|
2013-03-07 07:44:36 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME))
|
2011-10-14 10:13:49 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
2014-05-30 13:44:53 -05:00
|
|
|
if (!s_infiniband)
|
2011-10-14 10:13:49 -04:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (s_infiniband) {
|
2014-07-30 10:57:45 -04:00
|
|
|
const char *mac;
|
|
|
|
|
|
2011-10-14 10:13:49 -04:00
|
|
|
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
2014-07-30 10:57:45 -04:00
|
|
|
if (mac && !nm_utils_hwaddr_matches (mac, -1, nm_device_get_hw_address (device), -1))
|
2011-10-14 10:13:49 -04:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-27 12:12:15 -04:00
|
|
|
complete_connection (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *specific_object,
|
|
|
|
|
const GSList *existing_connections,
|
|
|
|
|
GError **error)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
2014-07-30 10:57:45 -04:00
|
|
|
const char *setting_mac;
|
2014-06-21 12:44:56 -04:00
|
|
|
const char *hw_address;
|
2011-10-14 10:13:49 -04:00
|
|
|
|
|
|
|
|
nm_utils_complete_generic (connection,
|
|
|
|
|
NM_SETTING_INFINIBAND_SETTING_NAME,
|
|
|
|
|
existing_connections,
|
|
|
|
|
NULL,
|
2014-08-25 16:21:59 +02:00
|
|
|
_("InfiniBand connection"),
|
2014-08-05 17:11:57 -04:00
|
|
|
NULL,
|
2011-10-14 10:13:49 -04:00
|
|
|
TRUE);
|
|
|
|
|
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
if (!s_infiniband) {
|
|
|
|
|
s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new ();
|
|
|
|
|
nm_connection_add_setting (connection, NM_SETTING (s_infiniband));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setting_mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
2014-06-21 12:44:56 -04:00
|
|
|
hw_address = nm_device_get_hw_address (device);
|
2011-10-14 10:13:49 -04:00
|
|
|
if (setting_mac) {
|
|
|
|
|
/* Make sure the setting MAC (if any) matches the device's MAC */
|
2014-07-30 10:57:45 -04:00
|
|
|
if (!nm_utils_hwaddr_matches (setting_mac, -1, hw_address, -1)) {
|
2011-10-14 10:13:49 -04:00
|
|
|
g_set_error_literal (error,
|
libnm-core: merge NMSetting*Error into NMConnectionError
Each setting type was defining its own error type, but most of them
had exactly the same three errors ("unknown", "missing property", and
"invalid property"), and none of the other values was of much use
programmatically anyway.
So, this commit merges NMSettingError, NMSettingAdslError, etc, all
into NMConnectionError. (The reason for merging into NMConnectionError
rather than NMSettingError is that we also already have
"NMSettingsError", for errors related to the settings service, so
"NMConnectionError" is a less-confusable name for settings/connection
errors than "NMSettingError".)
Also, make sure that all of the affected error messages are localized,
and (where appropriate) prefix them with the relevant property name.
Renamed error codes:
NM_SETTING_ERROR_PROPERTY_NOT_FOUND -> NM_CONNECTION_ERROR_PROPERTY_NOT_FOUND
NM_SETTING_ERROR_PROPERTY_NOT_SECRET -> NM_CONNECTION_ERROR_PROPERTY_NOT_SECRET
Remapped error codes:
NM_SETTING_*_ERROR_MISSING_PROPERTY -> NM_CONNECTION_ERROR_MISSING_PROPERTY
NM_SETTING_*_ERROR_INVALID_PROPERTY -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_ERROR_PROPERTY_TYPE_MISMATCH -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_BLUETOOTH_ERROR_TYPE_SETTING_NOT_FOUND -> NM_CONNECTION_ERROR_INVALID_SETTING
NM_SETTING_BOND_ERROR_INVALID_OPTION -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_BOND_ERROR_MISSING_OPTION -> NM_CONNECTION_ERROR_MISSING_PROPERTY
NM_SETTING_CONNECTION_ERROR_TYPE_SETTING_NOT_FOUND -> NM_CONNECTION_ERROR_MISSING_SETTING
NM_SETTING_CONNECTION_ERROR_SLAVE_SETTING_NOT_FOUND -> NM_CONNECTION_ERROR_MISSING_SETTING
NM_SETTING_IP4_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_IP6_CONFIG_ERROR_NOT_ALLOWED_FOR_METHOD -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_VLAN_ERROR_INVALID_PARENT -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_WIRELESS_SECURITY_ERROR_MISSING_802_1X_SETTING -> NM_CONNECTION_ERROR_MISSING_SETTING
NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_802_1X -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME -> NM_CONNECTION_ERROR_MISSING_PROPERTY
NM_SETTING_WIRELESS_SECURITY_ERROR_SHARED_KEY_REQUIRES_WEP -> NM_CONNECTION_ERROR_INVALID_PROPERTY
NM_SETTING_WIRELESS_ERROR_CHANNEL_REQUIRES_BAND -> NM_CONNECTION_ERROR_MISSING_PROPERTY
Dropped error codes (were previously defined but unused):
NM_SETTING_CDMA_ERROR_MISSING_SERIAL_SETTING
NM_SETTING_CONNECTION_ERROR_IP_CONFIG_NOT_ALLOWED
NM_SETTING_GSM_ERROR_MISSING_SERIAL_SETTING
NM_SETTING_PPP_ERROR_REQUIRE_MPPE_NOT_ALLOWED
NM_SETTING_PPPOE_ERROR_MISSING_PPP_SETTING
NM_SETTING_SERIAL_ERROR_MISSING_PPP_SETTING
NM_SETTING_WIRELESS_ERROR_MISSING_SECURITY_SETTING
2014-10-20 13:52:23 -04:00
|
|
|
NM_CONNECTION_ERROR,
|
|
|
|
|
NM_CONNECTION_ERROR_INVALID_PROPERTY,
|
|
|
|
|
_("connection does not match device"));
|
|
|
|
|
g_prefix_error (error, "%s.%s: ", NM_SETTING_INFINIBAND_SETTING_NAME, NM_SETTING_INFINIBAND_MAC_ADDRESS);
|
2011-10-14 10:13:49 -04:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* Lock the connection to this device by default */
|
2014-07-30 10:57:45 -04:00
|
|
|
g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_MAC_ADDRESS, hw_address, NULL);
|
2011-10-14 10:13:49 -04:00
|
|
|
}
|
|
|
|
|
|
2012-03-16 13:48:11 -04:00
|
|
|
if (!nm_setting_infiniband_get_transport_mode (s_infiniband))
|
2012-03-16 15:20:58 -05:00
|
|
|
g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL);
|
2012-03-16 13:48:11 -04:00
|
|
|
|
2011-10-14 10:13:49 -04:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-07 16:07:28 -06:00
|
|
|
static void
|
|
|
|
|
update_connection (NMDevice *device, NMConnection *connection)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
2013-11-07 16:07:28 -06:00
|
|
|
NMSettingInfiniband *s_infiniband = nm_connection_get_setting_infiniband (connection);
|
2014-06-21 12:44:56 -04:00
|
|
|
const char *mac = nm_device_get_hw_address (device);
|
2014-03-12 13:01:37 +01:00
|
|
|
char *mode_path, *contents = NULL;
|
2013-11-07 16:07:28 -06:00
|
|
|
const char *transport_mode = "datagram";
|
|
|
|
|
|
|
|
|
|
if (!s_infiniband) {
|
|
|
|
|
s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new ();
|
|
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_infiniband);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 10:57:45 -04:00
|
|
|
if (mac && !nm_utils_hwaddr_matches (mac, -1, NULL, INFINIBAND_ALEN))
|
|
|
|
|
g_object_set (s_infiniband, NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
|
2013-11-07 16:07:28 -06:00
|
|
|
|
2014-03-12 12:49:34 +01:00
|
|
|
mode_path = g_strdup_printf ("/sys/class/net/%s/mode",
|
|
|
|
|
ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (device)));
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
contents = nm_platform_sysctl_get (NM_PLATFORM_GET, mode_path);
|
2014-03-12 13:01:37 +01:00
|
|
|
g_free (mode_path);
|
|
|
|
|
if (contents) {
|
2013-11-07 16:07:28 -06:00
|
|
|
if (strstr (contents, "datagram"))
|
|
|
|
|
transport_mode = "datagram";
|
|
|
|
|
else if (strstr (contents, "connected"))
|
|
|
|
|
transport_mode = "connected";
|
2014-03-12 13:01:37 +01:00
|
|
|
g_free (contents);
|
2013-11-07 16:07:28 -06:00
|
|
|
}
|
|
|
|
|
g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_TRANSPORT_MODE, transport_mode, NULL);
|
2011-10-14 10:13:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_infiniband_class_init (NMDeviceInfinibandClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (NMDeviceInfinibandPrivate));
|
|
|
|
|
|
|
|
|
|
/* virtual methods */
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
|
2012-09-27 12:12:15 -04:00
|
|
|
parent_class->get_generic_capabilities = get_generic_capabilities;
|
|
|
|
|
parent_class->check_connection_compatible = check_connection_compatible;
|
|
|
|
|
parent_class->complete_connection = complete_connection;
|
2013-11-07 16:07:28 -06:00
|
|
|
parent_class->update_connection = update_connection;
|
2011-10-14 10:13:49 -04:00
|
|
|
|
2012-09-27 12:12:15 -04:00
|
|
|
parent_class->act_stage1_prepare = act_stage1_prepare;
|
|
|
|
|
parent_class->ip4_config_pre_commit = ip4_config_pre_commit;
|
2011-10-14 10:13:49 -04:00
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
|
2013-05-07 12:18:41 -04:00
|
|
|
nm_dbus_manager_register_exported_type (nm_dbus_manager_get (),
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
&dbus_glib_nm_device_infiniband_object_info);
|
2011-10-14 10:13:49 -04:00
|
|
|
}
|
2014-09-05 16:07:43 -05:00
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
|
|
#define NM_TYPE_INFINIBAND_FACTORY (nm_infiniband_factory_get_type ())
|
|
|
|
|
#define NM_INFINIBAND_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INFINIBAND_FACTORY, NMInfinibandFactory))
|
|
|
|
|
|
|
|
|
|
static NMDevice *
|
|
|
|
|
new_link (NMDeviceFactory *factory, NMPlatformLink *plink, GError **error)
|
|
|
|
|
{
|
2014-09-17 14:17:30 -05:00
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
|
|
|
|
|
NM_DEVICE_PLATFORM_DEVICE, plink,
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "InfiniBand",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
|
|
|
|
|
NULL);
|
2014-09-05 16:07:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMDevice *
|
|
|
|
|
create_virtual_device_for_connection (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
NMDevice *parent,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
int p_key, parent_ifindex;
|
|
|
|
|
const char *iface;
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
if (!NM_IS_DEVICE_INFINIBAND (parent)) {
|
|
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
|
|
|
|
"Parent interface %s must be an InfiniBand interface",
|
|
|
|
|
nm_device_get_iface (parent));
|
2014-09-05 16:07:43 -05:00
|
|
|
return NULL;
|
2014-09-17 14:17:30 -05:00
|
|
|
}
|
2014-09-05 16:07:43 -05:00
|
|
|
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
|
|
|
|
|
iface = nm_setting_infiniband_get_virtual_interface_name (s_infiniband);
|
2014-09-17 14:17:30 -05:00
|
|
|
g_assert (iface);
|
2014-09-05 16:07:43 -05:00
|
|
|
|
|
|
|
|
parent_ifindex = nm_device_get_ifindex (parent);
|
|
|
|
|
p_key = nm_setting_infiniband_get_p_key (s_infiniband);
|
|
|
|
|
|
2014-09-18 12:53:19 -05:00
|
|
|
if ( !nm_platform_infiniband_partition_add (NM_PLATFORM_GET, parent_ifindex, p_key, NULL)
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
&& nm_platform_get_error (NM_PLATFORM_GET) != NM_PLATFORM_ERROR_EXISTS) {
|
2014-09-17 14:17:30 -05:00
|
|
|
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
|
|
|
|
|
"Failed to create InfiniBand P_Key interface '%s' for '%s': %s",
|
|
|
|
|
iface,
|
|
|
|
|
nm_connection_get_id (connection),
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_get_error_msg (NM_PLATFORM_GET));
|
2014-09-05 16:07:43 -05:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
|
|
|
|
|
NM_DEVICE_IFACE, iface,
|
|
|
|
|
NM_DEVICE_DRIVER, nm_device_get_driver (parent),
|
|
|
|
|
NM_DEVICE_TYPE_DESC, "InfiniBand",
|
|
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-18 17:50:47 -05:00
|
|
|
static const char *
|
|
|
|
|
get_connection_parent (NMDeviceFactory *factory, NMConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
g_assert (s_infiniband);
|
|
|
|
|
|
|
|
|
|
return nm_setting_infiniband_get_parent (s_infiniband);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_virtual_iface_name (NMDeviceFactory *factory,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *parent_iface)
|
|
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME), NULL);
|
|
|
|
|
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
g_assert (s_infiniband);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_strcmp0 (parent_iface, nm_setting_infiniband_get_parent (s_infiniband)) == 0, NULL);
|
|
|
|
|
|
|
|
|
|
return g_strdup (nm_setting_infiniband_get_virtual_interface_name (s_infiniband));
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 14:17:30 -05:00
|
|
|
NM_DEVICE_FACTORY_DEFINE_INTERNAL (INFINIBAND, Infiniband, infiniband,
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES (NM_LINK_TYPE_INFINIBAND)
|
|
|
|
|
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES (NM_SETTING_INFINIBAND_SETTING_NAME),
|
|
|
|
|
factory_iface->new_link = new_link;
|
2014-09-05 16:07:43 -05:00
|
|
|
factory_iface->create_virtual_device_for_connection = create_virtual_device_for_connection;
|
2014-09-18 17:50:47 -05:00
|
|
|
factory_iface->get_connection_parent = get_connection_parent;
|
|
|
|
|
factory_iface->get_virtual_iface_name = get_virtual_iface_name;
|
2014-09-05 16:07:43 -05:00
|
|
|
)
|
|
|
|
|
|