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 <netinet/ether.h>
|
|
|
|
|
|
|
|
|
|
#include "nm-device-infiniband.h"
|
|
|
|
|
#include "nm-logging.h"
|
|
|
|
|
#include "nm-utils.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"
|
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))
|
|
|
|
|
|
|
|
|
|
#define NM_INFINIBAND_ERROR (nm_infiniband_error_quark ())
|
|
|
|
|
|
|
|
|
|
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 GQuark
|
|
|
|
|
nm_infiniband_error_quark (void)
|
|
|
|
|
{
|
|
|
|
|
static GQuark quark = 0;
|
|
|
|
|
if (!quark)
|
|
|
|
|
quark = g_quark_from_static_string ("nm-infiniband-error");
|
|
|
|
|
return quark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GObject*
|
|
|
|
|
constructor (GType type,
|
|
|
|
|
guint n_construct_params,
|
|
|
|
|
GObjectConstructParam *construct_params)
|
|
|
|
|
{
|
|
|
|
|
GObject *object;
|
|
|
|
|
NMDeviceInfinibandPrivate *priv;
|
|
|
|
|
NMDevice *self;
|
|
|
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (nm_device_infiniband_parent_class)->constructor (type,
|
|
|
|
|
n_construct_params,
|
|
|
|
|
construct_params);
|
|
|
|
|
if (!object)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
self = NM_DEVICE (object);
|
|
|
|
|
priv = NM_DEVICE_INFINIBAND_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
nm_log_dbg (LOGD_HW | LOGD_INFINIBAND, "(%s): kernel ifindex %d",
|
|
|
|
|
nm_device_get_iface (NM_DEVICE (self)),
|
|
|
|
|
nm_device_get_ifindex (NM_DEVICE (self)));
|
|
|
|
|
|
|
|
|
|
return object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
nm_device_infiniband_init (NMDeviceInfiniband * self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMDevice *
|
2013-05-29 12:57:13 -03:00
|
|
|
nm_device_infiniband_new (NMPlatformLink *platform_device)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
2013-05-29 12:57:13 -03:00
|
|
|
g_return_val_if_fail (platform_device != NULL, NULL);
|
2011-10-14 10:13:49 -04:00
|
|
|
|
|
|
|
|
return (NMDevice *) g_object_new (NM_TYPE_DEVICE_INFINIBAND,
|
2013-05-29 12:57:13 -03:00
|
|
|
NM_DEVICE_PLATFORM_DEVICE, platform_device,
|
2012-03-06 12:55:24 -05:00
|
|
|
NM_DEVICE_TYPE_DESC, "InfiniBand",
|
2011-11-18 00:34:08 -06:00
|
|
|
NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_INFINIBAND,
|
2011-10-14 10:13:49 -04:00
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static guint32
|
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
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
mode_path = g_strdup_printf ("/sys/class/net/%s/mode", nm_device_get_iface (dev));
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-16 13:57:47 -06:00
|
|
|
ok = nm_utils_do_sysctl (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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-28 18:35:30 -06:00
|
|
|
return NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->act_stage1_prepare (dev, reason);
|
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)
|
|
|
|
|
nm_ip4_config_set_mtu (config, mtu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2012-09-27 12:12:15 -04:00
|
|
|
check_connection_compatible (NMDevice *device,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
GError **error)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_infiniband;
|
|
|
|
|
const GByteArray *mac;
|
|
|
|
|
|
2013-03-07 07:44:36 -05:00
|
|
|
if (!NM_DEVICE_CLASS (nm_device_infiniband_parent_class)->check_connection_compatible (device, connection, error))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-10-14 10:13:49 -04:00
|
|
|
if (!nm_connection_is_type (connection, NM_SETTING_INFINIBAND_SETTING_NAME)) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_INFINIBAND_ERROR,
|
|
|
|
|
NM_INFINIBAND_ERROR_CONNECTION_NOT_INFINIBAND,
|
2012-03-06 12:55:24 -05:00
|
|
|
"The connection was not an InfiniBand connection.");
|
2011-10-14 10:13:49 -04:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s_infiniband = nm_connection_get_setting_infiniband (connection);
|
|
|
|
|
if (!s_infiniband) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
NM_INFINIBAND_ERROR, NM_INFINIBAND_ERROR_CONNECTION_INVALID,
|
|
|
|
|
"The connection was not a valid infiniband connection.");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s_infiniband) {
|
|
|
|
|
mac = nm_setting_infiniband_get_mac_address (s_infiniband);
|
2013-05-01 09:28:16 -04:00
|
|
|
if (mac && memcmp (mac->data, nm_device_get_hw_address (device, NULL), INFINIBAND_ALEN)) {
|
2011-10-14 10:13:49 -04:00
|
|
|
g_set_error (error,
|
|
|
|
|
NM_INFINIBAND_ERROR,
|
|
|
|
|
NM_INFINIBAND_ERROR_CONNECTION_INCOMPATIBLE,
|
|
|
|
|
"The connection's MAC address did not match this device.");
|
|
|
|
|
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;
|
|
|
|
|
const GByteArray *setting_mac;
|
2013-05-01 09:28:16 -04:00
|
|
|
const guint8 *hw_address;
|
2011-10-14 10:13:49 -04:00
|
|
|
|
|
|
|
|
nm_utils_complete_generic (connection,
|
|
|
|
|
NM_SETTING_INFINIBAND_SETTING_NAME,
|
|
|
|
|
existing_connections,
|
2012-03-06 12:55:24 -05:00
|
|
|
_("InfiniBand connection %d"),
|
2011-10-14 10:13:49 -04:00
|
|
|
NULL,
|
|
|
|
|
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);
|
2013-05-01 09:28:16 -04:00
|
|
|
hw_address = nm_device_get_hw_address (device, NULL);
|
2011-10-14 10:13:49 -04:00
|
|
|
if (setting_mac) {
|
|
|
|
|
/* Make sure the setting MAC (if any) matches the device's MAC */
|
2013-05-01 09:28:16 -04:00
|
|
|
if (memcmp (setting_mac->data, hw_address, INFINIBAND_ALEN)) {
|
2011-10-14 10:13:49 -04:00
|
|
|
g_set_error_literal (error,
|
|
|
|
|
NM_SETTING_INFINIBAND_ERROR,
|
|
|
|
|
NM_SETTING_INFINIBAND_ERROR_INVALID_PROPERTY,
|
|
|
|
|
NM_SETTING_INFINIBAND_MAC_ADDRESS);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
GByteArray *mac;
|
|
|
|
|
|
|
|
|
|
/* Lock the connection to this device by default */
|
2013-05-01 09:28:16 -04:00
|
|
|
mac = g_byte_array_sized_new (INFINIBAND_ALEN);
|
|
|
|
|
g_byte_array_append (mac, hw_address, INFINIBAND_ALEN);
|
2011-10-14 10:13:49 -04:00
|
|
|
g_object_set (G_OBJECT (s_infiniband), NM_SETTING_INFINIBAND_MAC_ADDRESS, mac, NULL);
|
|
|
|
|
g_byte_array_free (mac, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-03-06 14:58:03 -05:00
|
|
|
match_l2_config (NMDevice *self, NMConnection *connection)
|
2011-10-14 10:13:49 -04:00
|
|
|
{
|
2013-03-06 14:58:03 -05:00
|
|
|
/* FIXME */
|
2011-10-14 10:13:49 -04:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-01 09:28:16 -04:00
|
|
|
static const GByteArray *
|
|
|
|
|
get_connection_hw_address (NMDevice *device,
|
|
|
|
|
NMConnection *connection)
|
2012-02-12 13:54:09 -06:00
|
|
|
{
|
|
|
|
|
NMSettingInfiniband *s_ib;
|
|
|
|
|
|
|
|
|
|
s_ib = nm_connection_get_setting_infiniband (connection);
|
2013-05-01 09:28:16 -04:00
|
|
|
return s_ib ? nm_setting_infiniband_get_mac_address (s_ib) : NULL;
|
2012-02-12 13:54:09 -06:00
|
|
|
}
|
|
|
|
|
|
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->constructor = constructor;
|
|
|
|
|
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;
|
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;
|
2013-03-06 14:58:03 -05:00
|
|
|
parent_class->match_l2_config = match_l2_config;
|
2013-05-01 09:28:16 -04:00
|
|
|
parent_class->get_connection_hw_address = get_connection_hw_address;
|
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
|
|
|
|
|
|
|
|
dbus_g_error_domain_register (NM_INFINIBAND_ERROR, NULL, NM_TYPE_INFINIBAND_ERROR);
|
|
|
|
|
}
|