From f489d213f2a3df13c1144a568fc106efe4cf1f62 Mon Sep 17 00:00:00 2001 From: Jan Vaclav Date: Wed, 2 Apr 2025 13:12:52 +0200 Subject: [PATCH] nmtui: add page for configuring loopback interface --- NEWS | 1 + po/POTFILES.in | 1 + src/libnm-core-impl/nm-connection.c | 2 + src/nmtui/meson.build | 1 + src/nmtui/nm-editor-utils.c | 8 +++ src/nmtui/nmt-connect-connection-list.c | 1 + src/nmtui/nmt-editor.c | 3 ++ src/nmtui/nmt-page-loopback.c | 69 +++++++++++++++++++++++++ src/nmtui/nmt-page-loopback.h | 33 ++++++++++++ 9 files changed, 119 insertions(+) create mode 100644 src/nmtui/nmt-page-loopback.c create mode 100644 src/nmtui/nmt-page-loopback.h diff --git a/NEWS b/NEWS index f08d3187c..0691d7bd3 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE! * Add a new "prefix-delegation" setting containing a "subnet-id" property that specifies the subnet to choose on the downstream interface when using IPv6 prefix delegation. +* Add support for configuring the loopback interface in nmtui. ============================================= NetworkManager-1.52 diff --git a/po/POTFILES.in b/po/POTFILES.in index 4889935a2..d93d6b273 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -180,6 +180,7 @@ src/nmtui/nmt-page-infiniband.c src/nmtui/nmt-page-ip-tunnel.c src/nmtui/nmt-page-ip4.c src/nmtui/nmt-page-ip6.c +src/nmtui/nmt-page-loopback.c src/nmtui/nmt-page-macsec.c src/nmtui/nmt-page-ppp.c src/nmtui/nmt-page-team-port.c diff --git a/src/libnm-core-impl/nm-connection.c b/src/libnm-core-impl/nm-connection.c index 61a20a13e..0fbadfb85 100644 --- a/src/libnm-core-impl/nm-connection.c +++ b/src/libnm-core-impl/nm-connection.c @@ -3359,6 +3359,8 @@ nm_connection_get_virtual_device_description(NMConnection *connection) display_type = _("TUN/TAP"); else if (nm_streq(type, NM_SETTING_VETH_SETTING_NAME)) display_type = _("Veth"); + else if (nm_streq(type, NM_SETTING_LOOPBACK_SETTING_NAME)) + display_type = _("Loopback"); if (!iface || !display_type) return NULL; diff --git a/src/nmtui/meson.build b/src/nmtui/meson.build index eecfaa992..40bb40b9d 100644 --- a/src/nmtui/meson.build +++ b/src/nmtui/meson.build @@ -28,6 +28,7 @@ executable( 'nmt-page-ip4.c', 'nmt-page-ip6.c', 'nmt-page-ip-tunnel.c', + 'nmt-page-loopback.c', 'nmt-page-macsec.c', 'nmt-page-ppp.c', 'nmt-page-team.c', diff --git a/src/nmtui/nm-editor-utils.c b/src/nmtui/nm-editor-utils.c index 73fad6d1a..7997a8cec 100644 --- a/src/nmtui/nm-editor-utils.c +++ b/src/nmtui/nm-editor-utils.c @@ -156,6 +156,14 @@ nm_editor_utils_get_connection_type_list(void) item->id_format = _("Veth connection %d"); g_ptr_array_add(array, item); + item = g_new0(NMEditorConnectionTypeDataReal, 1); + item->data.name = _("Loopback"); + item->data.setting_type = NM_TYPE_SETTING_LOOPBACK; + item->data.device_type = NM_TYPE_DEVICE_LOOPBACK; + item->data.virtual = TRUE; + item->id_format = _("Loopback connection %d"); + g_ptr_array_add(array, item); + item = g_new0(NMEditorConnectionTypeDataReal, 1); item->data.name = _("Wi-Fi"); item->data.setting_type = NM_TYPE_SETTING_WIRELESS; diff --git a/src/nmtui/nmt-connect-connection-list.c b/src/nmtui/nmt-connect-connection-list.c index 1fd44b295..8e7dc807d 100644 --- a/src/nmtui/nmt-connect-connection-list.c +++ b/src/nmtui/nmt-connect-connection-list.c @@ -95,6 +95,7 @@ static const char *device_sort_order[] = {"NMDeviceEthernet", "NMDeviceVeth", "NMDeviceInfiniband", "NMDeviceWifi", + "NMDeviceLoopback", NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VETH_SETTING_NAME, NM_SETTING_BOND_SETTING_NAME, diff --git a/src/nmtui/nmt-editor.c b/src/nmtui/nmt-editor.c index 6205736a7..02b0b0701 100644 --- a/src/nmtui/nmt-editor.c +++ b/src/nmtui/nmt-editor.c @@ -35,6 +35,7 @@ #include "nmt-page-ip-tunnel.h" #include "nmt-page-ip4.h" #include "nmt-page-ip6.h" +#include "nmt-page-loopback.h" #include "nmt-page-macsec.h" #include "nmt-page-ppp.h" #include "nmt-page-team.h" @@ -376,6 +377,8 @@ nmt_editor_constructed(GObject *object) page = nmt_page_vlan_new(priv->edit_connection, deventry); else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_WIRED_SETTING_NAME)) page = nmt_page_ethernet_new(priv->edit_connection, deventry); + else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_LOOPBACK_SETTING_NAME)) + page = nmt_page_loopback_new(priv->edit_connection, deventry); else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_WIRELESS_SETTING_NAME)) page = nmt_page_wifi_new(priv->edit_connection, deventry); else if (nm_connection_is_type(priv->edit_connection, NM_SETTING_IP_TUNNEL_SETTING_NAME)) diff --git a/src/nmtui/nmt-page-loopback.c b/src/nmtui/nmt-page-loopback.c new file mode 100644 index 000000000..a47648745 --- /dev/null +++ b/src/nmtui/nmt-page-loopback.c @@ -0,0 +1,69 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025 Red Hat, Inc. + */ +/** + * SECTION:nmt-page-loopback + * @short_description: The editor page for the loopback interface + */ + +#include "libnm-client-aux-extern/nm-default-client.h" + +#include + +#include "nmt-page-loopback.h" + +#include "libnm-core-aux-intern/nm-libnm-core-utils.h" +#include "nmt-device-entry.h" +#include "nmt-mtu-entry.h" + +G_DEFINE_TYPE(NmtPageLoopback, nmt_page_loopback, NMT_TYPE_EDITOR_PAGE_DEVICE) + +#define NMT_PAGE_LOOPBACK_GET_PRIVATE(o) \ + _NM_GET_PRIVATE(self, NmtPageLoopback, NMT_IS_PAGE_LOOPBACK) + +static void +nmt_page_loopback_init(NmtPageLoopback *loopback) +{} + +NmtEditorPage * +nmt_page_loopback_new(NMConnection *conn, NmtDeviceEntry *deventry) +{ + return g_object_new(NMT_TYPE_PAGE_LOOPBACK, "connection", conn, "device-entry", deventry, NULL); +} + +static void +nmt_page_loopback_constructed(GObject *object) +{ + NmtPageLoopback *loopback = NMT_PAGE_LOOPBACK(object); + NmtEditorSection *section; + NmtEditorGrid *grid; + NMSettingLoopback *s_loopback; + NmtNewtWidget *widget; + NMConnection *conn; + + conn = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(loopback)); + s_loopback = _nm_connection_ensure_setting(conn, NM_TYPE_SETTING_LOOPBACK); + + section = nmt_editor_section_new(_("LOOPBACK"), NULL, FALSE); + grid = nmt_editor_section_get_body(section); + + widget = nmt_mtu_entry_new(); + g_object_bind_property(s_loopback, + NM_SETTING_LOOPBACK_MTU, + widget, + "mtu", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + nmt_editor_grid_append(grid, _("MTU"), widget, NULL); + + nmt_editor_page_add_section(NMT_EDITOR_PAGE(loopback), section); + + G_OBJECT_CLASS(nmt_page_loopback_parent_class)->constructed(object); +} + +static void +nmt_page_loopback_class_init(NmtPageLoopbackClass *loopback_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS(loopback_class); + object_class->constructed = nmt_page_loopback_constructed; +} diff --git a/src/nmtui/nmt-page-loopback.h b/src/nmtui/nmt-page-loopback.h new file mode 100644 index 000000000..03c76287c --- /dev/null +++ b/src/nmtui/nmt-page-loopback.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025 Red Hat, Inc. + */ + +#ifndef NMT_PAGE_LOOPBACK_H +#define NMT_PAGE_LOOPBACK_H + +#include "nmt-editor-page-device.h" + +#define NMT_TYPE_PAGE_LOOPBACK (nmt_page_loopback_get_type()) +#define NMT_PAGE_LOOPBACK(obj) \ + (_NM_G_TYPE_CHECK_INSTANCE_CAST((obj), NMT_TYPE_PAGE_LOOPBACK, NmtPageLoopback)) +#define NMT_PAGE_LOOPBACK_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), NMT_TYPE_PAGE_LOOPBACK, NmtPageLoopbackClass)) +#define NMT_IS_PAGE_LOOPBACK(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NMT_TYPE_PAGE_LOOPBACK)) +#define NMT_IS_PAGE_LOOPBACK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NMT_TYPE_PAGE_LOOPBACK)) +#define NMT_PAGE_LOOPBACK_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), NMT_TYPE_PAGE_LOOPBACK, NmtPageLoopbackClass)) + +typedef struct { + NmtEditorPageDevice parent; +} NmtPageLoopback; + +typedef struct { + NmtEditorPageDeviceClass parent; +} NmtPageLoopbackClass; + +GType nmt_page_loopback_get_type(void); + +NmtEditorPage *nmt_page_loopback_new(NMConnection *conn, NmtDeviceEntry *deventry); + +#endif /* NMT_PAGE_LOOPBACK_H */