diff options
author | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2020-11-12 21:58:13 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-11-27 10:12:36 +0100 |
commit | cd0cf9229d49a05c4e8afbb9b87b5d621c23ea00 (patch) | |
tree | 58c45b04d3d46f1da748db2712f1814f7d720058 /libnm | |
parent | de1d849f173dfa8d271720b396cb27e570ede7e9 (diff) | |
download | NetworkManager-cd0cf9229d49a05c4e8afbb9b87b5d621c23ea00.tar.gz |
veth: add support to configure veth interfaces
NetworkManager is now able to configure veth interfaces throught the
NMSettingVeth. Veth interfaces only have "peer" property.
In order to support Veth interfaces in NetworkManager the design need
to pass the following requirements:
* Veth setting only has "peer" attribute.
* Ethernet profiles must be applicable to Veth interfaces.
* When creating a veth interface, the peer will be managed by
NetworkManager but will not have a profile.
* Veth connection can reapply only if the peer has not been modified.
* In order to modify the veth peer, NetworkManager must deactivate the
connection and create a new one with peer modified.
In general, it should support the basis of veth interfaces but without
breaking any existing feature or use case. The users that are using veth
interfaces as ethernet should not notice anything changed unless they
specified the veth peer setting.
Creating a Veth interface in NetworkManager is useful even without the
support for namespaces for some use cases, e.g "connecting one side of
the veth to an OVS bridge and the other side to a Linux bridge" this is
done when using OVN kubernetes [1][2]. In addition, it would provide
persistent configuration and rollback support for Veth interfaces.
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1885605
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1894139
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Diffstat (limited to 'libnm')
-rw-r--r-- | libnm/NetworkManager.h | 1 | ||||
-rw-r--r-- | libnm/libnm.ver | 4 | ||||
-rw-r--r-- | libnm/meson.build | 2 | ||||
-rw-r--r-- | libnm/nm-autoptr.h | 2 | ||||
-rw-r--r-- | libnm/nm-device-ethernet.c | 16 | ||||
-rw-r--r-- | libnm/nm-device-veth.c | 129 | ||||
-rw-r--r-- | libnm/nm-device-veth.h | 41 | ||||
-rw-r--r-- | libnm/nm-types.h | 1 |
8 files changed, 187 insertions, 9 deletions
diff --git a/libnm/NetworkManager.h b/libnm/NetworkManager.h index 6864f7e84c..c94f093e66 100644 --- a/libnm/NetworkManager.h +++ b/libnm/NetworkManager.h @@ -88,6 +88,7 @@ #include "nm-setting-team-port.h" #include "nm-setting-tun.h" #include "nm-setting-user.h" +#include "nm-setting-veth.h" #include "nm-setting-vlan.h" #include "nm-setting-vpn.h" #include "nm-setting-vrf.h" diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 100b9b93ee..c61792c749 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1758,6 +1758,7 @@ global: libnm_1_30_0 { global: + nm_device_veth_get_type; nm_keyfile_handler_data_fail_with_error; nm_keyfile_handler_data_get_context; nm_keyfile_handler_data_warn_get; @@ -1778,5 +1779,8 @@ global: nm_setting_ovs_external_ids_get_type; nm_setting_ovs_external_ids_new; nm_setting_ovs_external_ids_set_data; + nm_setting_veth_get_peer; + nm_setting_veth_get_type; + nm_setting_veth_new; nm_utils_print; } libnm_1_28_0; diff --git a/libnm/meson.build b/libnm/meson.build index 5808837459..abdcc1d325 100644 --- a/libnm/meson.build +++ b/libnm/meson.build @@ -40,6 +40,7 @@ libnm_headers = files( 'nm-device-ppp.h', 'nm-device-team.h', 'nm-device-tun.h', + 'nm-device-veth.h', 'nm-device-vlan.h', 'nm-device-vrf.h', 'nm-device-vxlan.h', @@ -106,6 +107,7 @@ libnm_sources = files( 'nm-device-ppp.c', 'nm-device-team.c', 'nm-device-tun.c', + 'nm-device-veth.c', 'nm-device-vlan.c', 'nm-device-vrf.c', 'nm-device-vxlan.c', diff --git a/libnm/nm-autoptr.h b/libnm/nm-autoptr.h index 93be5464b9..ca70a6ca49 100644 --- a/libnm/nm-autoptr.h +++ b/libnm/nm-autoptr.h @@ -53,6 +53,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceOvsPort, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDevicePpp, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceTeam, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceTun, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceVeth, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceVlan, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceVxlan, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMDeviceWifi, g_object_unref) @@ -98,6 +99,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingTeam, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingTeamPort, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingTun, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingUser, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingVeth, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingVlan, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingVpn, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(NMSettingVxlan, g_object_unref) diff --git a/libnm/nm-device-ethernet.c b/libnm/nm-device-ethernet.c index 8f44b4ad48..bf4a36fee0 100644 --- a/libnm/nm-device-ethernet.c +++ b/libnm/nm-device-ethernet.c @@ -12,8 +12,10 @@ #include "nm-setting-connection.h" #include "nm-setting-wired.h" #include "nm-setting-pppoe.h" +#include "nm-setting-veth.h" #include "nm-utils.h" #include "nm-object-private.h" +#include "nm-device-veth.h" /*****************************************************************************/ @@ -173,9 +175,12 @@ connection_compatible(NMDevice *device, NMConnection *connection, GError **error ->connection_compatible(device, connection, error)) return FALSE; - if (nm_connection_is_type(connection, NM_SETTING_PPPOE_SETTING_NAME)) { + if (nm_connection_is_type(connection, NM_SETTING_PPPOE_SETTING_NAME) + || nm_connection_is_type(connection, NM_SETTING_WIRED_SETTING_NAME) + || (nm_connection_is_type(connection, NM_SETTING_VETH_SETTING_NAME) + && NM_IS_DEVICE_VETH(device))) { /* NOP */ - } else if (!nm_connection_is_type(connection, NM_SETTING_WIRED_SETTING_NAME)) { + } else { g_set_error_literal(error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, @@ -307,13 +312,6 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) } } -/* TODO: implemented Veth. */ -const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_veth = NML_DBUS_META_IFACE_INIT( - NM_DBUS_INTERFACE_DEVICE_VETH, - NULL, - NML_DBUS_META_INTERFACE_PRIO_NONE, - NML_DBUS_META_IFACE_DBUS_PROPERTIES(NML_DBUS_META_PROPERTY_INIT_TODO("Peer", "o"), ), ); - const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_wired = NML_DBUS_META_IFACE_INIT_PROP( NM_DBUS_INTERFACE_DEVICE_WIRED, nm_device_ethernet_get_type, diff --git a/libnm/nm-device-veth.c b/libnm/nm-device-veth.c new file mode 100644 index 0000000000..ba51ae6455 --- /dev/null +++ b/libnm/nm-device-veth.c @@ -0,0 +1,129 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* + * Copyright (C) 2020 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include "nm-device-veth.h" + +#include "nm-setting-connection.h" +#include "nm-setting-veth.h" +#include "nm-setting-wired.h" +#include "nm-utils.h" +#include "nm-device-ethernet.h" +#include "nm-object-private.h" + +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_PEER, ); + +typedef struct { + char *peer; +} NMDeviceVethPrivate; + +struct _NMDeviceVeth { + NMDeviceEthernet parent; + NMDeviceVethPrivate _priv; +}; + +struct _NMDeviceVethClass { + NMDeviceEthernetClass parent; +}; + +G_DEFINE_TYPE(NMDeviceVeth, nm_device_veth, NM_TYPE_DEVICE_ETHERNET) + +#define NM_DEVICE_VETH_GET_PRIVATE(self) \ + _NM_GET_PRIVATE(self, NMDeviceVeth, NM_IS_DEVICE_VETH, NMObject, NMDevice) + +/*****************************************************************************/ + +/** + * nm_device_veth_get_peer: + * @device: a #NMDeviceVeth + * + * Returns: the device's peer name + * + * Since: 1.30 + **/ +const char * +nm_device_veth_get_peer(NMDeviceVeth *device) +{ + g_return_val_if_fail(NM_IS_DEVICE_VETH(device), NULL); + + return _nml_coerce_property_str_not_empty(NM_DEVICE_VETH_GET_PRIVATE(device)->peer); +} + +static GType +get_setting_type(NMDevice *device) +{ + return NM_TYPE_SETTING_VETH; +} + +/*****************************************************************************/ + +static void +get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NMDeviceVeth *device = NM_DEVICE_VETH(object); + + switch (prop_id) { + case PROP_PEER: + g_value_set_string(value, nm_device_veth_get_peer(device)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + break; + } +} + +static void +nm_device_veth_init(NMDeviceVeth *device) +{} + +static void +finalize(GObject *object) +{ + NMDeviceVethPrivate *priv = NM_DEVICE_VETH_GET_PRIVATE(object); + + g_free(priv->peer); + + G_OBJECT_CLASS(nm_device_veth_parent_class)->finalize(object); +} + +const NMLDBusMetaIface _nml_dbus_meta_iface_nm_device_veth = NML_DBUS_META_IFACE_INIT_PROP( + NM_DBUS_INTERFACE_DEVICE_VETH, + nm_device_veth_get_type, + NML_DBUS_META_INTERFACE_PRIO_INSTANTIATE_20, + NML_DBUS_META_IFACE_DBUS_PROPERTIES( + NML_DBUS_META_PROPERTY_INIT_S("peer", PROP_PEER, NMDeviceVeth, _priv.peer), ), ); + +static void +nm_device_veth_class_init(NMDeviceVethClass *klass) +{ + GObjectClass * object_class = G_OBJECT_CLASS(klass); + NMObjectClass *nm_object_class = NM_OBJECT_CLASS(klass); + NMDeviceClass *device_class = NM_DEVICE_CLASS(klass); + + object_class->get_property = get_property; + object_class->finalize = finalize; + + _NM_OBJECT_CLASS_INIT_PRIV_PTR_DIRECT(nm_object_class, NMDeviceVeth); + + device_class->get_setting_type = get_setting_type; + + /** + * NMDeviceVeth:peer: + * + * The device's peer name. + * + * Since: 1.30 + **/ + obj_properties[PROP_PEER] = g_param_spec_string(NM_DEVICE_VETH_PEER, + "", + "", + NULL, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + _nml_dbus_meta_class_init_with_properties(object_class, &_nml_dbus_meta_iface_nm_device_veth); +} diff --git a/libnm/nm-device-veth.h b/libnm/nm-device-veth.h new file mode 100644 index 0000000000..eb03d28055 --- /dev/null +++ b/libnm/nm-device-veth.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +/* + * Copyright (C) 2020 Red Hat, Inc. + */ + +#ifndef __NM_DEVICE_VETH_H__ +#define __NM_DEVICE_VETH_H__ + +#if !defined(__NETWORKMANAGER_H_INSIDE__) && !defined(NETWORKMANAGER_COMPILATION) + #error "Only <NetworkManager.h> can be included directly." +#endif + +#include "nm-device.h" + +G_BEGIN_DECLS + +#define NM_TYPE_DEVICE_VETH (nm_device_veth_get_type()) +#define NM_DEVICE_VETH(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_DEVICE_VETH, NMDeviceVeth)) +#define NM_DEVICE_VETH_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NM_TYPE_DEVICE_VETH, NMDeviceVethClass)) +#define NM_IS_DEVICE_VETH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NM_TYPE_DEVICE_VETH)) +#define NM_IS_DEVICE_VETH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_DEVICE_VETH)) +#define NM_DEVICE_VETH_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NM_TYPE_DEVICE_VETH, NMDeviceVethClass)) + +#define NM_DEVICE_VETH_PEER "peer" + +/** + * NMDeviceVeth: + */ +typedef struct _NMDeviceVethClass NMDeviceVethClass; + +NM_AVAILABLE_IN_1_30 +GType nm_device_veth_get_type(void); + +NM_AVAILABLE_IN_1_30 +const char *nm_device_veth_get_peer(NMDeviceVeth *device); + +G_END_DECLS + +#endif /* __NM_DEVICE_VETH_H__ */ diff --git a/libnm/nm-types.h b/libnm/nm-types.h index 765d7cdae6..3445418cde 100644 --- a/libnm/nm-types.h +++ b/libnm/nm-types.h @@ -36,6 +36,7 @@ typedef struct _NMDeviceOvsPort NMDeviceOvsPort; typedef struct _NMDevicePpp NMDevicePpp; typedef struct _NMDeviceTeam NMDeviceTeam; typedef struct _NMDeviceTun NMDeviceTun; +typedef struct _NMDeviceVeth NMDeviceVeth; typedef struct _NMDeviceVlan NMDeviceVlan; typedef struct _NMDeviceVrf NMDeviceVrf; typedef struct _NMDeviceVxlan NMDeviceVxlan; |