|
Packit Service |
b23acc |
// SPDX-License-Identifier: GPL-2.0+
|
|
Packit Service |
b23acc |
/*
|
|
Packit Service |
b23acc |
* Copyright (C) 2013 Red Hat, Inc.
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
/**
|
|
Packit Service |
b23acc |
* SECTION:nmt-page-ip4
|
|
Packit Service |
b23acc |
* @short_description: The editor page for IP4 configuration
|
|
Packit Service |
b23acc |
*/
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-default.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include <stdlib.h>
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nmt-page-ip4.h"
|
|
Packit Service |
b23acc |
#include "nmt-ip-entry.h"
|
|
Packit Service |
b23acc |
#include "nmt-address-list.h"
|
|
Packit Service |
b23acc |
#include "nmt-route-editor.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
#include "nm-editor-bindings.h"
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
G_DEFINE_TYPE (NmtPageIP4, nmt_page_ip4, NMT_TYPE_EDITOR_PAGE)
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static NmtNewtPopupEntry ip4methods[] = {
|
|
Packit Service |
b23acc |
{ N_("Disabled"), NM_SETTING_IP4_CONFIG_METHOD_DISABLED },
|
|
Packit Service |
b23acc |
{ N_("Automatic"), NM_SETTING_IP4_CONFIG_METHOD_AUTO },
|
|
Packit Service |
b23acc |
{ N_("Link-Local"), NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL },
|
|
Packit Service |
b23acc |
{ N_("Manual"), NM_SETTING_IP4_CONFIG_METHOD_MANUAL },
|
|
Packit Service |
b23acc |
{ N_("Shared"), NM_SETTING_IP4_CONFIG_METHOD_SHARED },
|
|
Packit Service |
b23acc |
{ NULL, NULL }
|
|
Packit Service |
b23acc |
};
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
NmtEditorPage *
|
|
Packit Service |
b23acc |
nmt_page_ip4_new (NMConnection *conn)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
return g_object_new (NMT_TYPE_PAGE_IP4,
|
|
Packit Service |
b23acc |
"connection", conn,
|
|
Packit Service |
b23acc |
NULL);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
nmt_page_ip4_init (NmtPageIP4 *ip4)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
edit_routes (NmtNewtButton *button,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
NMSetting *s_ip4 = user_data;
|
|
Packit Service |
b23acc |
NmtNewtForm *form;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
form = nmt_route_editor_new (s_ip4);
|
|
Packit Service |
b23acc |
nmt_newt_form_run_sync (form);
|
|
Packit Service |
b23acc |
g_object_unref (form);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static gboolean
|
|
Packit Service |
b23acc |
ip4_routes_transform_to_description (GBinding *binding,
|
|
Packit Service |
b23acc |
const GValue *source_value,
|
|
Packit Service |
b23acc |
GValue *target_value,
|
|
Packit Service |
b23acc |
gpointer user_data)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
GPtrArray *routes;
|
|
Packit Service |
b23acc |
char *text;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
routes = g_value_get_boxed (source_value);
|
|
Packit Service |
b23acc |
if (!routes || !routes->len)
|
|
Packit Service |
b23acc |
text = g_strdup (_("(No custom routes)"));
|
|
Packit Service |
b23acc |
else {
|
|
Packit Service |
b23acc |
text = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE,
|
|
Packit Service |
b23acc |
"One custom route",
|
|
Packit Service |
b23acc |
"%d custom routes",
|
|
Packit Service |
b23acc |
routes->len),
|
|
Packit Service |
b23acc |
routes->len);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
g_value_take_string (target_value, text);
|
|
Packit Service |
b23acc |
return TRUE;
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
nmt_page_ip4_constructed (GObject *object)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
NmtPageIP4 *ip4 = NMT_PAGE_IP4 (object);
|
|
Packit Service |
b23acc |
gboolean show_by_default;
|
|
Packit Service |
b23acc |
NmtEditorSection *section;
|
|
Packit Service |
b23acc |
NmtEditorGrid *grid;
|
|
Packit Service |
b23acc |
NMSettingIPConfig *s_ip4;
|
|
Packit Service |
b23acc |
NmtNewtWidget *widget, *button;
|
|
Packit Service |
b23acc |
NMConnection *conn;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip4));
|
|
Packit Service |
b23acc |
s_ip4 = nm_connection_get_setting_ip4_config (conn);
|
|
Packit Service |
b23acc |
if (!s_ip4) {
|
|
Packit Service |
b23acc |
s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
|
|
Packit Service |
b23acc |
g_object_set (G_OBJECT (s_ip4),
|
|
Packit Service |
b23acc |
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
Packit Service |
b23acc |
NULL);
|
|
Packit Service |
b23acc |
nm_connection_add_setting (conn, (NMSetting *) s_ip4);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_newt_popup_new (ip4methods);
|
|
Packit Service |
b23acc |
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_METHOD,
|
|
Packit Service |
b23acc |
widget, "active-id",
|
|
Packit Service |
b23acc |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
if (!g_strcmp0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
|
|
Packit Service |
b23acc |
show_by_default = TRUE;
|
|
Packit Service |
b23acc |
else if (nm_setting_ip_config_get_num_addresses (s_ip4))
|
|
Packit Service |
b23acc |
show_by_default = TRUE;
|
|
Packit Service |
b23acc |
else
|
|
Packit Service |
b23acc |
show_by_default = FALSE;
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
section = nmt_editor_section_new (_("IPv4 CONFIGURATION"), widget, show_by_default);
|
|
Packit Service |
b23acc |
grid = nmt_editor_section_get_body (section);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4_WITH_PREFIX);
|
|
Packit Service |
b23acc |
nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET,
|
|
Packit Service |
b23acc |
s_ip4, NM_SETTING_IP_CONFIG_ADDRESSES,
|
|
Packit Service |
b23acc |
widget, "strings",
|
|
Packit Service |
b23acc |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, _("Addresses"), widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_ip_entry_new (25, AF_INET, FALSE, TRUE);
|
|
Packit Service |
b23acc |
nm_editor_bind_ip_gateway_to_string (AF_INET,
|
|
Packit Service |
b23acc |
s_ip4,
|
|
Packit Service |
b23acc |
widget, "text", "sensitive",
|
|
Packit Service |
b23acc |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, _("Gateway"), widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4);
|
|
Packit Service |
b23acc |
nm_editor_bind_ip_addresses_to_strv (AF_INET,
|
|
Packit Service |
b23acc |
s_ip4, NM_SETTING_IP_CONFIG_DNS,
|
|
Packit Service |
b23acc |
widget, "strings",
|
|
Packit Service |
b23acc |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, _("DNS servers"), widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_address_list_new (NMT_ADDRESS_LIST_HOSTNAME);
|
|
Packit Service |
b23acc |
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_DNS_SEARCH,
|
|
Packit Service |
b23acc |
widget, "strings",
|
|
Packit Service |
b23acc |
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, _("Search domains"), widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = g_object_new (NMT_TYPE_NEWT_LABEL,
|
|
Packit Service |
b23acc |
"text", "",
|
|
Packit Service |
b23acc |
"style", NMT_NEWT_LABEL_PLAIN,
|
|
Packit Service |
b23acc |
NULL);
|
|
Packit Service |
b23acc |
g_object_bind_property_full (s_ip4, NM_SETTING_IP_CONFIG_ROUTES,
|
|
Packit Service |
b23acc |
widget, "text",
|
|
Packit Service |
b23acc |
G_BINDING_SYNC_CREATE,
|
|
Packit Service |
b23acc |
ip4_routes_transform_to_description,
|
|
Packit Service |
b23acc |
NULL, NULL, NULL);
|
|
Packit Service |
b23acc |
button = nmt_newt_button_new (_("Edit..."));
|
|
Packit Service |
b23acc |
g_signal_connect (button, "clicked", G_CALLBACK (edit_routes), s_ip4);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, _("Routing"), widget, button);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_newt_checkbox_new (_("Never use this network for default route"));
|
|
Packit Service |
b23acc |
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_NEVER_DEFAULT,
|
|
Packit Service |
b23acc |
widget, "active",
|
|
Packit Service |
b23acc |
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, NULL, widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_newt_checkbox_new (_("Ignore automatically obtained routes"));
|
|
Packit Service |
b23acc |
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES,
|
|
Packit Service |
b23acc |
widget, "active",
|
|
Packit Service |
b23acc |
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, NULL, widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_newt_checkbox_new (_("Ignore automatically obtained DNS parameters"));
|
|
Packit Service |
b23acc |
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS,
|
|
Packit Service |
b23acc |
widget, "active",
|
|
Packit Service |
b23acc |
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, NULL, widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
widget = nmt_newt_checkbox_new (_("Require IPv4 addressing for this connection"));
|
|
Packit Service |
b23acc |
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_MAY_FAIL,
|
|
Packit Service |
b23acc |
widget, "active",
|
|
Packit Service |
b23acc |
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL |
|
|
Packit Service |
b23acc |
G_BINDING_INVERT_BOOLEAN);
|
|
Packit Service |
b23acc |
nmt_editor_grid_append (grid, NULL, widget, NULL);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip4), section);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
G_OBJECT_CLASS (nmt_page_ip4_parent_class)->constructed (object);
|
|
Packit Service |
b23acc |
}
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
static void
|
|
Packit Service |
b23acc |
nmt_page_ip4_class_init (NmtPageIP4Class *ip4_class)
|
|
Packit Service |
b23acc |
{
|
|
Packit Service |
b23acc |
GObjectClass *object_class = G_OBJECT_CLASS (ip4_class);
|
|
Packit Service |
b23acc |
|
|
Packit Service |
b23acc |
object_class->constructed = nmt_page_ip4_constructed;
|
|
Packit Service |
b23acc |
}
|