|
Packit Service |
87a54e |
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2013 - 2015 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-device-tun.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <stdlib.h>
|
|
Packit |
5756e2 |
#include <sys/types.h>
|
|
Packit |
5756e2 |
#include <linux/if_tun.h>
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-act-request.h"
|
|
Packit |
5756e2 |
#include "nm-device-private.h"
|
|
Packit |
5756e2 |
#include "nm-ip4-config.h"
|
|
Packit |
5756e2 |
#include "platform/nm-platform.h"
|
|
Packit |
5756e2 |
#include "nm-device-factory.h"
|
|
Packit |
5756e2 |
#include "nm-setting-tun.h"
|
|
Packit |
5756e2 |
#include "nm-core-internal.h"
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define _NMLOG_DEVICE_TYPE NMDeviceTun
|
|
Packit |
5756e2 |
#include "nm-device-logging.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_GOBJECT_PROPERTIES_DEFINE(NMDeviceTun,
|
|
Packit Service |
a1bd4f |
PROP_OWNER,
|
|
Packit Service |
a1bd4f |
PROP_GROUP,
|
|
Packit Service |
a1bd4f |
PROP_MODE,
|
|
Packit Service |
a1bd4f |
PROP_NO_PI,
|
|
Packit Service |
a1bd4f |
PROP_VNET_HDR,
|
|
Packit Service |
a1bd4f |
PROP_MULTI_QUEUE, );
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
NMPlatformLnkTun props;
|
|
Packit |
5756e2 |
} NMDeviceTunPrivate;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct _NMDeviceTun {
|
|
Packit Service |
a1bd4f |
NMDevice parent;
|
|
Packit Service |
a1bd4f |
NMDeviceTunPrivate _priv;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct _NMDeviceTunClass {
|
|
Packit Service |
a1bd4f |
NMDeviceClass parent;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_DEFINE_TYPE(NMDeviceTun, nm_device_tun, NM_TYPE_DEVICE)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NM_DEVICE_TUN_GET_PRIVATE(self) \
|
|
Packit Service |
a1bd4f |
_NM_GET_PRIVATE(self, NMDeviceTun, NM_IS_DEVICE_TUN, NMDevice)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
update_properties_from_struct(NMDeviceTun *self, const NMPlatformLnkTun *props)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMDeviceTunPrivate * priv = NM_DEVICE_TUN_GET_PRIVATE(self);
|
|
Packit Service |
a1bd4f |
const NMPlatformLnkTun props0 = {};
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!props) {
|
|
Packit Service |
a1bd4f |
/* allow passing %NULL to reset all properties. */
|
|
Packit Service |
a1bd4f |
props = &props;;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_freeze_notify(G_OBJECT(self));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define CHECK_PROPERTY_CHANGED_VALID(field, prop) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
if (priv->props.field != props->field \
|
|
Packit Service |
a1bd4f |
|| priv->props.field##_valid != props->field##_valid) { \
|
|
Packit Service |
a1bd4f |
priv->props.field##_valid = props->field##_valid; \
|
|
Packit Service |
a1bd4f |
priv->props.field = props->field; \
|
|
Packit Service |
a1bd4f |
_notify(self, prop); \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define CHECK_PROPERTY_CHANGED(field, prop) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
if (priv->props.field != props->field) { \
|
|
Packit Service |
a1bd4f |
priv->props.field = props->field; \
|
|
Packit Service |
a1bd4f |
_notify(self, prop); \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
CHECK_PROPERTY_CHANGED_VALID(owner, PROP_OWNER);
|
|
Packit Service |
a1bd4f |
CHECK_PROPERTY_CHANGED_VALID(group, PROP_GROUP);
|
|
Packit Service |
a1bd4f |
CHECK_PROPERTY_CHANGED(type, PROP_MODE);
|
|
Packit Service |
a1bd4f |
CHECK_PROPERTY_CHANGED(pi, PROP_NO_PI);
|
|
Packit Service |
a1bd4f |
CHECK_PROPERTY_CHANGED(vnet_hdr, PROP_VNET_HDR);
|
|
Packit Service |
a1bd4f |
CHECK_PROPERTY_CHANGED(multi_queue, PROP_MULTI_QUEUE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_thaw_notify(G_OBJECT(self));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
update_properties(NMDeviceTun *self)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMPlatformLnkTun props_storage;
|
|
Packit Service |
a1bd4f |
const NMPlatformLnkTun *props = NULL;
|
|
Packit Service |
a1bd4f |
int ifindex;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
ifindex = nm_device_get_ifindex(NM_DEVICE(self));
|
|
Packit Service |
a1bd4f |
if (ifindex > 0
|
|
Packit Service |
a1bd4f |
&& nm_platform_link_tun_get_properties(nm_device_get_platform(NM_DEVICE(self)),
|
|
Packit Service |
a1bd4f |
ifindex,
|
|
Packit Service |
a1bd4f |
&props_storage))
|
|
Packit Service |
a1bd4f |
props = &props_storage;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
update_properties_from_struct(self, props);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMDeviceCapabilities
|
|
Packit Service |
a1bd4f |
get_generic_capabilities(NMDevice *dev)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return NM_DEVICE_CAP_IS_SOFTWARE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
link_changed(NMDevice *device, const NMPlatformLink *pllink)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NM_DEVICE_CLASS(nm_device_tun_parent_class)->link_changed(device, pllink);
|
|
Packit Service |
a1bd4f |
update_properties(NM_DEVICE_TUN(device));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
complete_connection(NMDevice * device,
|
|
Packit Service |
a1bd4f |
NMConnection * connection,
|
|
Packit Service |
a1bd4f |
const char * specific_object,
|
|
Packit Service |
a1bd4f |
NMConnection *const *existing_connections,
|
|
Packit Service |
a1bd4f |
GError ** error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMSettingTun *s_tun;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_utils_complete_generic(nm_device_get_platform(device),
|
|
Packit Service |
a1bd4f |
connection,
|
|
Packit Service |
a1bd4f |
NM_SETTING_TUN_SETTING_NAME,
|
|
Packit Service |
a1bd4f |
existing_connections,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
_("TUN connection"),
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
TRUE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_tun = nm_connection_get_setting_tun(connection);
|
|
Packit Service |
a1bd4f |
if (!s_tun) {
|
|
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 |
"A 'tun' setting is required.");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
update_connection(NMDevice *device, NMConnection *connection)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMDeviceTun * self = NM_DEVICE_TUN(device);
|
|
Packit Service |
a1bd4f |
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self);
|
|
Packit Service |
a1bd4f |
NMSettingTun * s_tun;
|
|
Packit Service |
a1bd4f |
NMSettingTunMode mode;
|
|
Packit Service |
a1bd4f |
char s_buf[100];
|
|
Packit Service |
a1bd4f |
const char * str;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Note: since we read tun properties from sysctl for older kernels,
|
|
Packit Service |
a1bd4f |
* we don't get proper change notifications. Make sure that all our
|
|
Packit Service |
a1bd4f |
* tun properties are up to date at this point. We should not do this,
|
|
Packit Service |
a1bd4f |
* if we would entirely rely on netlink events. */
|
|
Packit Service |
a1bd4f |
update_properties(NM_DEVICE_TUN(device));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (priv->props.type) {
|
|
Packit Service |
a1bd4f |
case IFF_TUN:
|
|
Packit Service |
a1bd4f |
mode = NM_SETTING_TUN_MODE_TUN;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case IFF_TAP:
|
|
Packit Service |
a1bd4f |
mode = NM_SETTING_TUN_MODE_TAP;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
/* Huh? */
|
|
Packit Service |
a1bd4f |
return;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_tun = nm_connection_get_setting_tun(connection);
|
|
Packit Service |
a1bd4f |
if (!s_tun) {
|
|
Packit Service |
a1bd4f |
s_tun = (NMSettingTun *) nm_setting_tun_new();
|
|
Packit Service |
a1bd4f |
nm_connection_add_setting(connection, (NMSetting *) s_tun);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (mode != nm_setting_tun_get_mode(s_tun))
|
|
Packit Service |
a1bd4f |
g_object_set(G_OBJECT(s_tun), NM_SETTING_TUN_MODE, (guint) mode, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
str = priv->props.owner_valid ? nm_sprintf_buf(s_buf, "%" G_GINT32_FORMAT, priv->props.owner)
|
|
Packit Service |
a1bd4f |
: NULL;
|
|
Packit Service |
a1bd4f |
if (!nm_streq0(str, nm_setting_tun_get_owner(s_tun)))
|
|
Packit Service |
a1bd4f |
g_object_set(G_OBJECT(s_tun), NM_SETTING_TUN_OWNER, str, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
str = priv->props.group_valid ? nm_sprintf_buf(s_buf, "%" G_GINT32_FORMAT, priv->props.group)
|
|
Packit Service |
a1bd4f |
: NULL;
|
|
Packit Service |
a1bd4f |
if (!nm_streq0(str, nm_setting_tun_get_group(s_tun)))
|
|
Packit Service |
a1bd4f |
g_object_set(G_OBJECT(s_tun), NM_SETTING_TUN_GROUP, str, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (priv->props.pi != nm_setting_tun_get_pi(s_tun))
|
|
Packit Service |
a1bd4f |
g_object_set(G_OBJECT(s_tun), NM_SETTING_TUN_PI, (gboolean) priv->props.pi, NULL);
|
|
Packit Service |
a1bd4f |
if (priv->props.vnet_hdr != nm_setting_tun_get_vnet_hdr(s_tun))
|
|
Packit Service |
a1bd4f |
g_object_set(G_OBJECT(s_tun),
|
|
Packit Service |
a1bd4f |
NM_SETTING_TUN_VNET_HDR,
|
|
Packit Service |
a1bd4f |
(gboolean) priv->props.vnet_hdr,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit Service |
a1bd4f |
if (priv->props.multi_queue != nm_setting_tun_get_multi_queue(s_tun))
|
|
Packit Service |
a1bd4f |
g_object_set(G_OBJECT(s_tun),
|
|
Packit Service |
a1bd4f |
NM_SETTING_TUN_MULTI_QUEUE,
|
|
Packit Service |
a1bd4f |
(gboolean) priv->props.multi_queue,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
create_and_realize(NMDevice * device,
|
|
Packit Service |
a1bd4f |
NMConnection * connection,
|
|
Packit Service |
a1bd4f |
NMDevice * parent,
|
|
Packit Service |
a1bd4f |
const NMPlatformLink **out_plink,
|
|
Packit Service |
a1bd4f |
GError ** error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const char * iface = nm_device_get_iface(device);
|
|
Packit Service |
a1bd4f |
NMPlatformLnkTun props = {};
|
|
Packit Service |
a1bd4f |
NMSettingTun * s_tun;
|
|
Packit Service |
a1bd4f |
gint64 owner;
|
|
Packit Service |
a1bd4f |
gint64 group;
|
|
Packit Service |
a1bd4f |
int r;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_tun = nm_connection_get_setting_tun(connection);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(s_tun, FALSE);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (nm_setting_tun_get_mode(s_tun)) {
|
|
Packit Service |
a1bd4f |
case NM_SETTING_TUN_MODE_TAP:
|
|
Packit Service |
a1bd4f |
props.type = IFF_TAP;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case NM_SETTING_TUN_MODE_TUN:
|
|
Packit Service |
a1bd4f |
props.type = IFF_TUN;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
g_return_val_if_reached(FALSE);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
owner = _nm_utils_ascii_str_to_int64(nm_setting_tun_get_owner(s_tun), 10, 0, G_MAXINT32, -1);
|
|
Packit Service |
a1bd4f |
if (owner != -1) {
|
|
Packit Service |
a1bd4f |
props.owner_valid = TRUE;
|
|
Packit Service |
a1bd4f |
props.owner = owner;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
group = _nm_utils_ascii_str_to_int64(nm_setting_tun_get_group(s_tun), 10, 0, G_MAXINT32, -1);
|
|
Packit Service |
a1bd4f |
if (group != -1) {
|
|
Packit Service |
a1bd4f |
props.group_valid = TRUE;
|
|
Packit Service |
a1bd4f |
props.group = group;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
props.pi = nm_setting_tun_get_pi(s_tun);
|
|
Packit Service |
a1bd4f |
props.vnet_hdr = nm_setting_tun_get_vnet_hdr(s_tun);
|
|
Packit Service |
a1bd4f |
props.multi_queue = nm_setting_tun_get_multi_queue(s_tun);
|
|
Packit Service |
a1bd4f |
props.persist = TRUE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
r = nm_platform_link_tun_add(nm_device_get_platform(device), iface, &props, out_plink, NULL);
|
|
Packit Service |
a1bd4f |
if (r < 0) {
|
|
Packit Service |
a1bd4f |
g_set_error(error,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_ERROR,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_ERROR_CREATION_FAILED,
|
|
Packit Service |
a1bd4f |
"Failed to create TUN/TAP interface '%s' for '%s': %s",
|
|
Packit Service |
a1bd4f |
iface,
|
|
Packit Service |
a1bd4f |
nm_connection_get_id(connection),
|
|
Packit Service |
a1bd4f |
nm_strerror(r));
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
_same_og(const char *str, gboolean og_valid, guint32 og_num)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gint64 v;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
v = _nm_utils_ascii_str_to_int64(str, 10, 0, G_MAXINT32, -1);
|
|
Packit Service |
a1bd4f |
return (!og_valid && (v == (gint64) -1)) || (og_valid && (((guint32) v) == og_num));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
check_connection_compatible(NMDevice *device, NMConnection *connection, GError **error)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMDeviceTun * self = NM_DEVICE_TUN(device);
|
|
Packit Service |
a1bd4f |
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self);
|
|
Packit Service |
a1bd4f |
NMSettingTunMode mode;
|
|
Packit Service |
a1bd4f |
NMSettingTun * s_tun;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (!NM_DEVICE_CLASS(nm_device_tun_parent_class)
|
|
Packit Service |
a1bd4f |
->check_connection_compatible(device, connection, error))
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (nm_device_is_real(device)) {
|
|
Packit Service |
a1bd4f |
switch (priv->props.type) {
|
|
Packit Service |
a1bd4f |
case IFF_TUN:
|
|
Packit Service |
a1bd4f |
mode = NM_SETTING_TUN_MODE_TUN;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case IFF_TAP:
|
|
Packit Service |
a1bd4f |
mode = NM_SETTING_TUN_MODE_TAP;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"invalid tun type on device");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
s_tun = nm_connection_get_setting_tun(connection);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (mode != nm_setting_tun_get_mode(s_tun)) {
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"tun mode setting mismatches");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
if (!_same_og(nm_setting_tun_get_owner(s_tun),
|
|
Packit Service |
a1bd4f |
priv->props.owner_valid,
|
|
Packit Service |
a1bd4f |
priv->props.owner)) {
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"tun owner setting mismatches");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
if (!_same_og(nm_setting_tun_get_group(s_tun),
|
|
Packit Service |
a1bd4f |
priv->props.group_valid,
|
|
Packit Service |
a1bd4f |
priv->props.group)) {
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"tun group setting mismatches");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
if (nm_setting_tun_get_pi(s_tun) != priv->props.pi) {
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"tun pi setting mismatches");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
if (nm_setting_tun_get_vnet_hdr(s_tun) != priv->props.vnet_hdr) {
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"tun vnet-hdr setting mismatches");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
if (nm_setting_tun_get_multi_queue(s_tun) != priv->props.multi_queue) {
|
|
Packit Service |
a1bd4f |
nm_utils_error_set_literal(error,
|
|
Packit Service |
a1bd4f |
NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY,
|
|
Packit Service |
a1bd4f |
"tun multi-queue setting mismatches");
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMActStageReturn
|
|
Packit Service |
a1bd4f |
act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMDeviceTun * self = NM_DEVICE_TUN(device);
|
|
Packit Service |
a1bd4f |
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (priv->props.type == IFF_TUN) {
|
|
Packit Service |
a1bd4f |
/* Nothing to do for TUN devices */
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
if (!nm_device_hw_addr_set_cloned(device,
|
|
Packit Service |
a1bd4f |
nm_device_get_applied_connection(device),
|
|
Packit Service |
a1bd4f |
FALSE)) {
|
|
Packit Service |
a1bd4f |
*out_failure_reason = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
|
|
Packit Service |
a1bd4f |
return NM_ACT_STAGE_RETURN_FAILURE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return NM_ACT_STAGE_RETURN_SUCCESS;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
unrealize_notify(NMDevice *device)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NM_DEVICE_CLASS(nm_device_tun_parent_class)->unrealize_notify(device);
|
|
Packit Service |
a1bd4f |
update_properties_from_struct(NM_DEVICE_TUN(device), NULL);
|
|
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 |
NMDeviceTun * self = NM_DEVICE_TUN(object);
|
|
Packit Service |
a1bd4f |
NMDeviceTunPrivate *priv = NM_DEVICE_TUN_GET_PRIVATE(self);
|
|
Packit Service |
a1bd4f |
const char * s;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_OWNER:
|
|
Packit Service |
a1bd4f |
g_value_set_int64(value,
|
|
Packit Service |
a1bd4f |
priv->props.owner_valid ? (gint64) priv->props.owner : (gint64) -1);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_GROUP:
|
|
Packit Service |
a1bd4f |
g_value_set_int64(value,
|
|
Packit Service |
a1bd4f |
priv->props.group_valid ? (gint64) priv->props.group : (gint64) -1);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_MODE:
|
|
Packit Service |
a1bd4f |
switch (priv->props.type) {
|
|
Packit Service |
a1bd4f |
case IFF_TUN:
|
|
Packit Service |
a1bd4f |
s = "tun";
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case IFF_TAP:
|
|
Packit Service |
a1bd4f |
s = "tap";
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
s = NULL;
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
g_value_set_static_string(value, s);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_NO_PI:
|
|
Packit Service |
a1bd4f |
g_value_set_boolean(value, !priv->props.pi);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_VNET_HDR:
|
|
Packit Service |
a1bd4f |
g_value_set_boolean(value, priv->props.vnet_hdr);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_MULTI_QUEUE:
|
|
Packit Service |
a1bd4f |
g_value_set_boolean(value, priv->props.multi_queue);
|
|
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_tun_init(NMDeviceTun *self)
|
|
Packit Service |
a1bd4f |
{}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMDBusInterfaceInfoExtended interface_info_device_tun = {
|
|
Packit Service |
a1bd4f |
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT(
|
|
Packit Service |
a1bd4f |
NM_DBUS_INTERFACE_DEVICE_TUN,
|
|
Packit Service |
a1bd4f |
.signals = NM_DEFINE_GDBUS_SIGNAL_INFOS(&nm_signal_info_property_changed_legacy, ),
|
|
Packit Service |
a1bd4f |
.properties = NM_DEFINE_GDBUS_PROPERTY_INFOS(
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Owner", "x", NM_DEVICE_TUN_OWNER),
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Group", "x", NM_DEVICE_TUN_GROUP),
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("Mode", "s", NM_DEVICE_TUN_MODE),
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("NoPi", "b", NM_DEVICE_TUN_NO_PI),
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("VnetHdr",
|
|
Packit Service |
a1bd4f |
"b",
|
|
Packit Service |
a1bd4f |
NM_DEVICE_TUN_VNET_HDR),
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("MultiQueue",
|
|
Packit Service |
a1bd4f |
"b",
|
|
Packit Service |
a1bd4f |
NM_DEVICE_TUN_MULTI_QUEUE),
|
|
Packit Service |
a1bd4f |
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L("HwAddress",
|
|
Packit Service |
a1bd4f |
"s",
|
|
Packit Service |
a1bd4f |
NM_DEVICE_HW_ADDRESS), ), ),
|
|
Packit Service |
a1bd4f |
.legacy_property_changed = TRUE,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nm_device_tun_class_init(NMDeviceTunClass *klass)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GObjectClass * object_class = G_OBJECT_CLASS(klass);
|
|
Packit Service |
a1bd4f |
NMDBusObjectClass *dbus_object_class = NM_DBUS_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 |
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_tun);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
device_class->connection_type_supported = NM_SETTING_TUN_SETTING_NAME;
|
|
Packit Service |
a1bd4f |
device_class->connection_type_check_compatible = NM_SETTING_TUN_SETTING_NAME;
|
|
Packit Service |
a1bd4f |
device_class->link_types = NM_DEVICE_DEFINE_LINK_TYPES(NM_LINK_TYPE_TUN);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
device_class->link_changed = link_changed;
|
|
Packit Service |
a1bd4f |
device_class->complete_connection = complete_connection;
|
|
Packit Service |
a1bd4f |
device_class->check_connection_compatible = check_connection_compatible;
|
|
Packit Service |
a1bd4f |
device_class->create_and_realize = create_and_realize;
|
|
Packit Service |
a1bd4f |
device_class->get_generic_capabilities = get_generic_capabilities;
|
|
Packit Service |
a1bd4f |
device_class->unrealize_notify = unrealize_notify;
|
|
Packit Service |
a1bd4f |
device_class->update_connection = update_connection;
|
|
Packit Service |
a1bd4f |
device_class->act_stage1_prepare = act_stage1_prepare;
|
|
Packit Service |
a1bd4f |
device_class->get_configured_mtu = nm_device_get_configured_mtu_for_wired;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_OWNER] = g_param_spec_int64(NM_DEVICE_TUN_OWNER,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
G_MAXUINT32,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_GROUP] = g_param_spec_int64(NM_DEVICE_TUN_GROUP,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
G_MAXUINT32,
|
|
Packit Service |
a1bd4f |
-1,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_MODE] = g_param_spec_string(NM_DEVICE_TUN_MODE,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_NO_PI] = g_param_spec_boolean(NM_DEVICE_TUN_NO_PI,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
FALSE,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_VNET_HDR] = g_param_spec_boolean(NM_DEVICE_TUN_VNET_HDR,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
FALSE,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_MULTI_QUEUE] =
|
|
Packit Service |
a1bd4f |
g_param_spec_boolean(NM_DEVICE_TUN_MULTI_QUEUE,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
FALSE,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NM_TYPE_TUN_DEVICE_FACTORY (nm_tun_device_factory_get_type())
|
|
Packit Service |
a1bd4f |
#define NM_TUN_DEVICE_FACTORY(obj) \
|
|
Packit Service |
a1bd4f |
(G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_TUN_DEVICE_FACTORY, NMTunDeviceFactory))
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMDevice *
|
|
Packit Service |
a1bd4f |
create_device(NMDeviceFactory * factory,
|
|
Packit Service |
a1bd4f |
const char * iface,
|
|
Packit Service |
a1bd4f |
const NMPlatformLink *plink,
|
|
Packit Service |
a1bd4f |
NMConnection * connection,
|
|
Packit Service |
a1bd4f |
gboolean * out_ignore)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(!plink || plink->type == NM_LINK_TYPE_TUN, NULL);
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(!connection
|
|
Packit Service |
a1bd4f |
|| nm_streq0(nm_connection_get_connection_type(connection),
|
|
Packit Service |
a1bd4f |
NM_SETTING_TUN_SETTING_NAME),
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return g_object_new(NM_TYPE_DEVICE_TUN,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_IFACE,
|
|
Packit Service |
a1bd4f |
iface,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_TYPE_DESC,
|
|
Packit Service |
a1bd4f |
"Tun",
|
|
Packit Service |
a1bd4f |
NM_DEVICE_DEVICE_TYPE,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_TYPE_TUN,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_LINK_TYPE,
|
|
Packit Service |
a1bd4f |
(guint) NM_LINK_TYPE_TUN,
|
|
Packit Service |
a1bd4f |
NULL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_DEVICE_FACTORY_DEFINE_INTERNAL(
|
|
Packit Service |
a1bd4f |
TUN,
|
|
Packit Service |
a1bd4f |
Tun,
|
|
Packit Service |
a1bd4f |
tun,
|
|
Packit Service |
a1bd4f |
NM_DEVICE_FACTORY_DECLARE_LINK_TYPES(NM_LINK_TYPE_TUN)
|
|
Packit Service |
a1bd4f |
NM_DEVICE_FACTORY_DECLARE_SETTING_TYPES(NM_SETTING_TUN_SETTING_NAME),
|
|
Packit Service |
a1bd4f |
factory_class->create_device = create_device;);
|