|
Packit Service |
b23acc |
// SPDX-License-Identifier: LGPL-2.1+
|
|
Packit Service |
b23acc |
/*
|
|
Packit Service |
b23acc |
* Copyright (C) 2012 Red Hat, Inc.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-default.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-setting-bridge.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-setting-connection.h"
|
|
Packit Service |
b23acc |
#include "nm-utils.h"
|
|
Packit Service |
b23acc |
#include "nm-device-bridge.h"
|
|
Packit Service |
b23acc |
#include "nm-object-private.h"
|
|
Packit Service |
b23acc |
#include "nm-core-internal.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
|
|
Packit Service |
b23acc |
PROP_CARRIER,
|
|
Packit Service |
b23acc |
PROP_SLAVES,
|
|
Packit Service |
b23acc |
);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
typedef struct {
|
|
Packit Service |
b23acc |
NMLDBusPropertyAO slaves;
|
|
Packit Service |
b23acc |
bool carrier;
|
|
Packit Service |
b23acc |
} NMDeviceBridgePrivate;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
struct _NMDeviceBridge {
|
|
Packit Service |
b23acc |
NMDevice parent;
|
|
Packit Service |
b23acc |
NMDeviceBridgePrivate _priv;
|
|
Packit Service |
b23acc |
};
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
struct _NMDeviceBridgeClass {
|
|
Packit Service |
b23acc |
NMDeviceClass parent;
|
|
Packit Service |
b23acc |
};
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
G_DEFINE_TYPE (NMDeviceBridge, nm_device_bridge, NM_TYPE_DEVICE)
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#define NM_DEVICE_BRIDGE_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMDeviceBridge, NM_IS_DEVICE_BRIDGE, NMObject, NMDevice)
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_device_bridge_get_hw_address: (skip)
|
|
Packit Service |
b23acc |
* @device: a #NMDeviceBridge
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Gets the hardware (MAC) address of the #NMDeviceBridge
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Returns: the hardware address. This is the internal string used by the
|
|
Packit Service |
b23acc |
* device, and must not be modified.
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Deprecated: 1.24: Use nm_device_get_hw_address() instead.
|
|
Packit Service |
b23acc |
**/
|
|
Packit Service |
b23acc |
const char *
|
|
Packit Service |
b23acc |
nm_device_bridge_get_hw_address (NMDeviceBridge *device)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
return nm_device_get_hw_address (NM_DEVICE (device));
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_device_bridge_get_carrier:
|
|
Packit Service |
b23acc |
* @device: a #NMDeviceBridge
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Whether the device has carrier.
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Returns: %TRUE if the device has carrier
|
|
Packit Service |
b23acc |
**/
|
|
Packit Service |
b23acc |
gboolean
|
|
Packit Service |
b23acc |
nm_device_bridge_get_carrier (NMDeviceBridge *device)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
return NM_DEVICE_BRIDGE_GET_PRIVATE (device)->carrier;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* nm_device_bridge_get_slaves:
|
|
Packit Service |
b23acc |
* @device: a #NMDeviceBridge
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Gets the devices currently enslaved to @device.
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Returns: (element-type NMDevice): the #GPtrArray containing
|
|
Packit Service |
b23acc |
* #NMDevices that are slaves of @device. This is the internal
|
|
Packit Service |
b23acc |
* copy used by the device, and must not be modified.
|
|
Packit Service |
b23acc |
**/
|
|
Packit Service |
b23acc |
const GPtrArray *
|
|
Packit Service |
b23acc |
nm_device_bridge_get_slaves (NMDeviceBridge *device)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
g_return_val_if_fail (NM_IS_DEVICE_BRIDGE (device), FALSE);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
return nml_dbus_property_ao_get_objs_as_ptrarray (&NM_DEVICE_BRIDGE_GET_PRIVATE (device)->slaves);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static gboolean
|
|
Packit Service |
b23acc |
connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
if (!NM_DEVICE_CLASS (nm_device_bridge_parent_class)->connection_compatible (device, connection, error))
|
|
Packit Service |
b23acc |
return FALSE;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
if (!nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) {
|
|
Packit Service |
b23acc |
if ( _nm_connection_get_setting_bluetooth_for_nap (connection)
|
|
Packit Service |
b23acc |
&& nm_connection_is_type (connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
|
|
Packit Service |
b23acc |
/* a bluetooth NAP setting is a compatible connection for a bridge. */
|
|
Packit Service |
b23acc |
} else {
|
|
Packit Service |
b23acc |
g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
|
|
Packit Service |
b23acc |
_("The connection was not a bridge connection."));
|
|
Packit Service |
b23acc |
return FALSE;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/* FIXME: check ports? */
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
return TRUE;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static GType
|
|
Packit Service |
b23acc |
get_setting_type (NMDevice *device)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
return NM_TYPE_SETTING_BRIDGE;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/*****************************************************************************/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
nm_device_bridge_init (NMDeviceBridge *device)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
get_property (GObject *object,
|
|
Packit Service |
b23acc |
guint prop_id,
|
|
Packit Service |
b23acc |
GValue *value,
|
|
Packit Service |
b23acc |
GParamSpec *pspec)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
NMDeviceBridge *device = NM_DEVICE_BRIDGE (object);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
switch (prop_id) {
|
|
Packit Service |
b23acc |
case PROP_CARRIER:
|
|
Packit Service |
b23acc |
g_value_set_boolean (value, nm_device_bridge_get_carrier (device));
|
|
Packit Service |
b23acc |
break;
|
|
Packit Service |
b23acc |
case PROP_SLAVES:
|
|
Packit Service |
b23acc |
g_value_take_boxed (value, _nm_utils_copy_object_array (nm_device_bridge_get_slaves (device)));
|
|
Packit Service |
b23acc |
break;
|
|
Packit Service |
b23acc |
default:
|
|
Packit Service |
b23acc |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
Packit Service |
b23acc |
break;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_bridge = NML_DBUS_META_IFACE_INIT_PROP (
|
|
Packit Service |
b23acc |
NM_DBUS_INTERFACE_DEVICE_BRIDGE,
|
|
Packit Service |
b23acc |
nm_device_bridge_get_type,
|
|
Packit Service |
b23acc |
NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_HIGH,
|
|
Packit Service |
b23acc |
NML_DBUS_META_IFACE_DBUS_PROPERTIES (
|
|
Packit Service |
b23acc |
NML_DBUS_META_PROPERTY_INIT_B ("Carrier", PROP_CARRIER, NMDeviceBridge, _priv.carrier ),
|
|
Packit Service |
b23acc |
NML_DBUS_META_PROPERTY_INIT_FCN ("HwAddress", 0, "s", _nm_device_notify_update_prop_hw_address ),
|
|
Packit Service |
b23acc |
NML_DBUS_META_PROPERTY_INIT_AO_PROP ("Slaves", PROP_SLAVES, NMDeviceBridge, _priv.slaves, nm_device_get_type ),
|
|
Packit Service |
b23acc |
),
|
|
Packit Service |
b23acc |
);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
nm_device_bridge_class_init (NMDeviceBridgeClass *klass)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
Packit Service |
b23acc |
NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
|
|
Packit Service |
b23acc |
NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
object_class->get_property = get_property;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
_NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT (nm_object_class, NMDeviceBridge);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
_NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1 (nm_object_class, NMDeviceBridgePrivate, slaves);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
device_class->connection_compatible = connection_compatible;
|
|
Packit Service |
b23acc |
device_class->get_setting_type = get_setting_type;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* NMDeviceBridge:carrier:
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* Whether the device has carrier.
|
|
Packit Service |
b23acc |
**/
|
|
Packit Service |
b23acc |
obj_properties[PROP_CARRIER] =
|
|
Packit Service |
b23acc |
g_param_spec_boolean (NM_DEVICE_BRIDGE_CARRIER, "", "",
|
|
Packit Service |
b23acc |
FALSE,
|
|
Packit Service |
b23acc |
G_PARAM_READABLE |
|
|
Packit Service |
b23acc |
G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* NMDeviceBridge:slaves: (type GPtrArray(NMDevice))
|
|
Packit Service |
b23acc |
*
|
|
Packit Service |
b23acc |
* The devices enslaved to the bridge device.
|
|
Packit Service |
b23acc |
**/
|
|
Packit Service |
b23acc |
obj_properties[PROP_SLAVES] =
|
|
Packit Service |
b23acc |
g_param_spec_boxed (NM_DEVICE_BRIDGE_SLAVES, "", "",
|
|
Packit Service |
b23acc |
G_TYPE_PTR_ARRAY,
|
|
Packit Service |
b23acc |
G_PARAM_READABLE |
|
|
Packit Service |
b23acc |
G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
_nml_dbus_meta_class_init_with_properties (object_class, &_nml_dbus_meta_iface_nm_device_bridge);
|
|
Packit Service |
b23acc |
}
|