nmtui: add page for configuring loopback interface

This commit is contained in:
Jan Vaclav
2025-04-02 13:12:52 +02:00
parent b571e2be5a
commit f489d213f2
9 changed files with 119 additions and 0 deletions

1
NEWS
View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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',

View File

@@ -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;

View File

@@ -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,

View File

@@ -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))

View File

@@ -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 <linux/if_ether.h>
#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;
}

View File

@@ -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 */