Blame libnm/nm-device-ovs-port.c

Packit Service 87a54e
/* SPDX-License-Identifier: LGPL-2.1-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2017, 2018 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit Service 2bceb2
#include "libnm/nm-default-libnm.h"
Packit 5756e2
Packit 5756e2
#include "nm-device-ovs-port.h"
Packit 5756e2
Packit 5756e2
#include "nm-object-private.h"
Packit 5756e2
#include "nm-setting-ovs-port.h"
Packit 5756e2
#include "nm-setting-ovs-port.h"
Packit 5756e2
#include "nm-setting-connection.h"
Packit 5756e2
#include "nm-core-internal.h"
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit Service a1bd4f
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_SLAVES, );
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NMLDBusPropertyAO slaves;
Packit 5756e2
} NMDeviceOvsPortPrivate;
Packit 5756e2
Packit 5756e2
struct _NMDeviceOvsPort {
Packit Service a1bd4f
    NMDevice               parent;
Packit Service a1bd4f
    NMDeviceOvsPortPrivate _priv;
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
struct _NMDeviceOvsPortClass {
Packit Service a1bd4f
    NMDeviceClass parent;
Packit 5756e2
};
Packit 5756e2
Packit Service a1bd4f
G_DEFINE_TYPE(NMDeviceOvsPort, nm_device_ovs_port, NM_TYPE_DEVICE)
Packit 5756e2
Packit Service a1bd4f
#define NM_DEVICE_OVS_PORT_GET_PRIVATE(self) \
Packit Service a1bd4f
    _NM_GET_PRIVATE(self, NMDeviceOvsPort, NM_IS_DEVICE_OVS_PORT, NMObject, NMDevice)
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nm_device_ovs_port_get_slaves:
Packit 5756e2
 * @device: a #NMDeviceOvsPort
Packit 5756e2
 *
Packit 5756e2
 * Gets the interfaces currently enslaved to @device.
Packit 5756e2
 *
Packit 5756e2
 * Returns: (element-type NMDevice): the #GPtrArray containing
Packit 5756e2
 * #NMDevices that are slaves of @device. This is the internal
Packit 5756e2
 * copy used by the device, and must not be modified.
Packit 5756e2
 *
Packit 5756e2
 * Since: 1.14
Packit 5756e2
 **/
Packit 5756e2
const GPtrArray *
Packit Service a1bd4f
nm_device_ovs_port_get_slaves(NMDeviceOvsPort *device)
Packit 5756e2
{
Packit Service a1bd4f
    g_return_val_if_fail(NM_IS_DEVICE_OVS_PORT(device), FALSE);
Packit 5756e2
Packit Service a1bd4f
    return nml_dbus_property_ao_get_objs_as_ptrarray(
Packit Service a1bd4f
        &NM_DEVICE_OVS_PORT_GET_PRIVATE(device)->slaves);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static const char *
Packit Service a1bd4f
get_type_description(NMDevice *device)
Packit 5756e2
{
Packit Service a1bd4f
    return "ovs-port";
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static gboolean
Packit Service a1bd4f
connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
Packit 5756e2
{
Packit Service a1bd4f
    const char *iface_name;
Packit Service a1bd4f
Packit Service a1bd4f
    if (!NM_DEVICE_CLASS(nm_device_ovs_port_parent_class)
Packit Service a1bd4f
             ->connection_compatible(device, connection, error))
Packit Service a1bd4f
        return FALSE;
Packit Service a1bd4f
Packit Service a1bd4f
    if (!nm_connection_is_type(connection, NM_SETTING_OVS_PORT_SETTING_NAME)) {
Packit Service a1bd4f
        g_set_error_literal(error,
Packit Service a1bd4f
                            NM_DEVICE_ERROR,
Packit Service a1bd4f
                            NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
Packit Service a1bd4f
                            _("The connection was not a ovs_port connection."));
Packit Service a1bd4f
        return FALSE;
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    iface_name = nm_connection_get_interface_name(connection);
Packit Service a1bd4f
    if (!iface_name) {
Packit Service a1bd4f
        g_set_error_literal(error,
Packit Service a1bd4f
                            NM_DEVICE_ERROR,
Packit Service a1bd4f
                            NM_DEVICE_ERROR_INVALID_CONNECTION,
Packit Service a1bd4f
                            _("The connection did not specify an interface name."));
Packit Service a1bd4f
        return FALSE;
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    return TRUE;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static GType
Packit Service a1bd4f
get_setting_type(NMDevice *device)
Packit 5756e2
{
Packit Service a1bd4f
    return NM_TYPE_SETTING_OVS_PORT;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
Packit 5756e2
{
Packit Service a1bd4f
    NMDeviceOvsPort *device = NM_DEVICE_OVS_PORT(object);
Packit Service a1bd4f
Packit Service a1bd4f
    switch (prop_id) {
Packit Service a1bd4f
    case PROP_SLAVES:
Packit Service a1bd4f
        g_value_take_boxed(value,
Packit Service a1bd4f
                           _nm_utils_copy_object_array(nm_device_ovs_port_get_slaves(device)));
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    default:
Packit Service a1bd4f
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/*****************************************************************************/
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nm_device_ovs_port_init(NMDeviceOvsPort *device)
Packit Service a1bd4f
{}
Packit Service a1bd4f
Packit Service a1bd4f
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_ovsport =
Packit Service a1bd4f
    NML_DBUS_META_IFACE_INIT_PROP(NM_DBUS_INTERFACE_DEVICE_OVS_PORT,
Packit Service a1bd4f
                                  nm_device_ovs_port_get_type,
Packit Service a1bd4f
                                  NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_30,
Packit Service a1bd4f
                                  NML_DBUS_META_IFACE_DBUS_PROPERTIES(
Packit Service a1bd4f
                                      NML_DBUS_META_PROPERTY_INIT_AO_PROP("Slaves",
Packit Service a1bd4f
                                                                          PROP_SLAVES,
Packit Service a1bd4f
                                                                          NMDeviceOvsPort,
Packit Service a1bd4f
                                                                          _priv.slaves,
Packit Service a1bd4f
                                                                          nm_device_get_type), ), );
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nm_device_ovs_port_class_init(NMDeviceOvsPortClass *klass)
Packit 5756e2
{
Packit Service a1bd4f
    GObjectClass * object_class    = G_OBJECT_CLASS(klass);
Packit Service a1bd4f
    NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass);
Packit Service a1bd4f
    NMDeviceClass *device_class    = NM_DEVICE_CLASS(klass);
Packit Service a1bd4f
Packit Service a1bd4f
    object_class->get_property = get_property;
Packit Service a1bd4f
Packit Service a1bd4f
    _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT(nm_object_class, NMDeviceOvsPort);
Packit Service a1bd4f
Packit Service a1bd4f
    _NM_OBJECT_CLASS_INIT_PROPERTY_AO_FIELDS_1(nm_object_class, NMDeviceOvsPortPrivate, slaves);
Packit Service a1bd4f
Packit Service a1bd4f
    device_class->get_type_description  = get_type_description;
Packit Service a1bd4f
    device_class->connection_compatible = connection_compatible;
Packit Service a1bd4f
    device_class->get_setting_type      = get_setting_type;
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NMDeviceOvsPort:slaves: (type GPtrArray(NMDevice))
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Gets the interfaces currently enslaved to the device.
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Since: 1.22
Packit Service a1bd4f
     */
Packit Service a1bd4f
    obj_properties[PROP_SLAVES] = g_param_spec_boxed(NM_DEVICE_OVS_PORT_SLAVES,
Packit Service a1bd4f
                                                     "",
Packit Service a1bd4f
                                                     "",
Packit Service a1bd4f
                                                     G_TYPE_PTR_ARRAY,
Packit Service a1bd4f
                                                     G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
Packit Service a1bd4f
Packit Service a1bd4f
    _nml_dbus_meta_class_init_with_properties(object_class,
Packit Service a1bd4f
                                              &_nml_dbus_meta_iface_nm_device_ovsport);
Packit 5756e2
}