|
Packit Service |
a1bd4f |
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2018 Javier Arteaga <jarteaga@jbeta.is>
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-device-wireguard.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-object-private.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PUBLIC_KEY, PROP_LISTEN_PORT, PROP_FWMARK, );
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
typedef struct {
|
|
Packit Service |
a1bd4f |
GBytes *public_key;
|
|
Packit Service |
a1bd4f |
guint32 fwmark;
|
|
Packit Service |
a1bd4f |
guint16 listen_port;
|
|
Packit |
5756e2 |
} NMDeviceWireGuardPrivate;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct _NMDeviceWireGuard {
|
|
Packit Service |
a1bd4f |
NMDevice parent;
|
|
Packit Service |
a1bd4f |
NMDeviceWireGuardPrivate _priv;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct _NMDeviceWireGuardClass {
|
|
Packit Service |
a1bd4f |
NMDeviceClass parent;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_DEFINE_TYPE(NMDeviceWireGuard, nm_device_wireguard, NM_TYPE_DEVICE)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NM_DEVICE_WIREGUARD_GET_PRIVATE(self) \
|
|
Packit Service |
a1bd4f |
_NM_GET_PRIVATE(self, NMDeviceWireGuard, NM_IS_DEVICE_WIREGUARD, NMObject, NMDevice)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_device_wireguard_get_public_key:
|
|
Packit |
5756e2 |
* @device: a #NMDeviceWireGuard
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Gets the public key for this interface
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: (transfer none): the #GBytes containing the 32-byte public key
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Since: 1.14
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
GBytes *
|
|
Packit Service |
a1bd4f |
nm_device_wireguard_get_public_key(NMDeviceWireGuard *device)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_DEVICE_WIREGUARD(device), NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return NM_DEVICE_WIREGUARD_GET_PRIVATE(device)->public_key;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_device_wireguard_get_listen_port:
|
|
Packit |
5756e2 |
* @device: a #NMDeviceWireGuard
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Gets the local UDP port this interface listens on
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: UDP listen port
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Since: 1.14
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
guint16
|
|
Packit Service |
a1bd4f |
nm_device_wireguard_get_listen_port(NMDeviceWireGuard *device)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_DEVICE_WIREGUARD(device), 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return NM_DEVICE_WIREGUARD_GET_PRIVATE(device)->listen_port;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/**
|
|
Packit |
5756e2 |
* nm_device_wireguard_get_fwmark:
|
|
Packit |
5756e2 |
* @device: a #NMDeviceWireGuard
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Gets the fwmark (firewall mark) for this interface.
|
|
Packit |
5756e2 |
* It can be used to set routing policy for outgoing encrypted packets.
|
|
Packit |
5756e2 |
* See: ip-rule(8)
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Returns: 0 if fwmark not in use, 32-bit fwmark value otherwise
|
|
Packit |
5756e2 |
*
|
|
Packit |
5756e2 |
* Since: 1.14
|
|
Packit |
5756e2 |
**/
|
|
Packit |
5756e2 |
guint32
|
|
Packit Service |
a1bd4f |
nm_device_wireguard_get_fwmark(NMDeviceWireGuard *device)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_return_val_if_fail(NM_IS_DEVICE_WIREGUARD(device), 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return NM_DEVICE_WIREGUARD_GET_PRIVATE(device)->fwmark;
|
|
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 |
NMDeviceWireGuard *device = NM_DEVICE_WIREGUARD(object);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (prop_id) {
|
|
Packit Service |
a1bd4f |
case PROP_PUBLIC_KEY:
|
|
Packit Service |
a1bd4f |
g_value_set_boxed(value, nm_device_wireguard_get_public_key(device));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_LISTEN_PORT:
|
|
Packit Service |
a1bd4f |
g_value_set_uint(value, nm_device_wireguard_get_listen_port(device));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case PROP_FWMARK:
|
|
Packit Service |
a1bd4f |
g_value_set_uint(value, nm_device_wireguard_get_fwmark(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 |
static void
|
|
Packit Service |
a1bd4f |
nm_device_wireguard_init(NMDeviceWireGuard *device)
|
|
Packit Service |
a1bd4f |
{}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
finalize(GObject *object)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE(object);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_bytes_unref(priv->public_key);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
G_OBJECT_CLASS(nm_device_wireguard_parent_class)->finalize(object);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wireguard = NML_DBUS_META_IFACE_INIT_PROP(
|
|
Packit Service |
a1bd4f |
NM_DBUS_INTERFACE_DEVICE_WIREGUARD,
|
|
Packit Service |
a1bd4f |
nm_device_wireguard_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_U("FwMark", PROP_FWMARK, NMDeviceWireGuard, _priv.fwmark),
|
|
Packit Service |
a1bd4f |
NML_DBUS_META_PROPERTY_INIT_Q("ListenPort",
|
|
Packit Service |
a1bd4f |
PROP_LISTEN_PORT,
|
|
Packit Service |
a1bd4f |
NMDeviceWireGuard,
|
|
Packit Service |
a1bd4f |
_priv.listen_port),
|
|
Packit Service |
a1bd4f |
NML_DBUS_META_PROPERTY_INIT_AY("PublicKey",
|
|
Packit Service |
a1bd4f |
PROP_PUBLIC_KEY,
|
|
Packit Service |
a1bd4f |
NMDeviceWireGuard,
|
|
Packit Service |
a1bd4f |
_priv.public_key), ), );
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
nm_device_wireguard_class_init(NMDeviceWireGuardClass *wireguard_class)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
GObjectClass *object_class = G_OBJECT_CLASS(wireguard_class);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
object_class->get_property = get_property;
|
|
Packit Service |
a1bd4f |
object_class->finalize = finalize;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/**
|
|
Packit Service |
a1bd4f |
* NMDeviceWireGuard:public-key:
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* 32-byte public key, derived from the current private key.
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Since: 1.14
|
|
Packit Service |
a1bd4f |
**/
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_PUBLIC_KEY] = g_param_spec_boxed(NM_DEVICE_WIREGUARD_PUBLIC_KEY,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
G_TYPE_BYTES,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/**
|
|
Packit Service |
a1bd4f |
* NMDeviceWireGuard:listen-port:
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Local UDP listen port.
|
|
Packit Service |
a1bd4f |
* Set to 0 to allow a random port to be chosen (default).
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Since: 1.14
|
|
Packit Service |
a1bd4f |
**/
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_LISTEN_PORT] = g_param_spec_uint(NM_DEVICE_WIREGUARD_LISTEN_PORT,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
G_MAXUINT16,
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/**
|
|
Packit Service |
a1bd4f |
* NMDeviceWireGuard:fwmark:
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Optional firewall mark - see ip-rule(8).
|
|
Packit Service |
a1bd4f |
* Used when setting routing policy for outgoing encrypted packets.
|
|
Packit Service |
a1bd4f |
* Set to 0 to disable the mark (default).
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* Since: 1.14
|
|
Packit Service |
a1bd4f |
**/
|
|
Packit Service |
a1bd4f |
obj_properties[PROP_FWMARK] = g_param_spec_uint(NM_DEVICE_WIREGUARD_FWMARK,
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
"",
|
|
Packit Service |
a1bd4f |
0,
|
|
Packit Service |
a1bd4f |
G_MAXUINT32,
|
|
Packit Service |
a1bd4f |
0,
|
|
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_wireguard);
|
|
Packit |
5756e2 |
}
|