Blame clients/tui/nmt-page-bridge.c

Packit Service a1bd4f
/* SPDX-License-Identifier: GPL-2.0+ */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2013 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * SECTION:nmt-page-bridge
Packit 5756e2
 * @short_description: The editor page for Bridge connections
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#include "nm-default.h"
Packit 5756e2
Packit 5756e2
#include "nmt-page-bridge.h"
Packit 5756e2
Packit 5756e2
#include "nmt-address-list.h"
Packit 5756e2
#include "nmt-slave-list.h"
Packit 5756e2
Packit Service a1bd4f
G_DEFINE_TYPE(NmtPageBridge, nmt_page_bridge, NMT_TYPE_EDITOR_PAGE_DEVICE)
Packit 5756e2
Packit Service a1bd4f
#define NMT_PAGE_BRIDGE_GET_PRIVATE(o) \
Packit Service a1bd4f
    (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_PAGE_BRIDGE, NmtPageBridgePrivate))
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NmtSlaveList *slaves;
Packit 5756e2
} NmtPageBridgePrivate;
Packit 5756e2
Packit 5756e2
NmtEditorPage *
Packit Service a1bd4f
nmt_page_bridge_new(NMConnection *conn, NmtDeviceEntry *deventry)
Packit 5756e2
{
Packit Service a1bd4f
    return g_object_new(NMT_TYPE_PAGE_BRIDGE, "connection", conn, "device-entry", deventry, NULL);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_bridge_init(NmtPageBridge *bridge)
Packit Service a1bd4f
{}
Packit 5756e2
Packit 5756e2
static gboolean
Packit Service a1bd4f
bridge_connection_type_filter(GType connection_type, gpointer user_data)
Packit 5756e2
{
Packit Service a1bd4f
    return (connection_type == NM_TYPE_SETTING_WIRED || connection_type == NM_TYPE_SETTING_WIRELESS
Packit Service a1bd4f
            || connection_type == NM_TYPE_SETTING_VLAN);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_bridge_constructed(GObject *object)
Packit 5756e2
{
Packit Service a1bd4f
    NmtPageBridge *       bridge = NMT_PAGE_BRIDGE(object);
Packit Service a1bd4f
    NmtPageBridgePrivate *priv   = NMT_PAGE_BRIDGE_GET_PRIVATE(bridge);
Packit Service a1bd4f
    NmtEditorSection *    section;
Packit Service a1bd4f
    NmtEditorGrid *       grid;
Packit Service a1bd4f
    NMSettingBridge *     s_bridge;
Packit Service a1bd4f
    NmtNewtWidget *       widget, *label, *stp;
Packit Service a1bd4f
    NMConnection *        conn;
Packit Service a1bd4f
Packit Service a1bd4f
    conn     = nmt_editor_page_get_connection(NMT_EDITOR_PAGE(bridge));
Packit Service a1bd4f
    s_bridge = nm_connection_get_setting_bridge(conn);
Packit Service a1bd4f
    if (!s_bridge) {
Packit Service a1bd4f
        nm_connection_add_setting(conn, nm_setting_bridge_new());
Packit Service a1bd4f
        s_bridge = nm_connection_get_setting_bridge(conn);
Packit Service a1bd4f
    }
Packit Service a1bd4f
Packit Service a1bd4f
    section = nmt_editor_section_new(_("BRIDGE"), NULL, TRUE);
Packit Service a1bd4f
    grid    = nmt_editor_section_get_body(section);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_separator_new();
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Slaves"), widget, NULL);
Packit Service a1bd4f
    nmt_editor_grid_set_row_flags(grid, widget, NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_slave_list_new(conn, bridge_connection_type_filter, bridge);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, NULL, widget, NULL);
Packit Service a1bd4f
    priv->slaves = NMT_SLAVE_LIST(widget);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_numeric_new(10, 0, 1000000);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_AGEING_TIME,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    label = nmt_newt_label_new(_("seconds"));
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Aging time"), widget, label);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_checkbox_new(_("Enable IGMP snooping"));
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_MULTICAST_SNOOPING,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "active",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, NULL, widget, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = stp = nmt_newt_checkbox_new(_("Enable STP (Spanning Tree Protocol)"));
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_STP,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "active",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, NULL, widget, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_numeric_new(10, 0, G_MAXINT);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_PRIORITY,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_STP,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "sensitive",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Priority"), widget, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_numeric_new(10, 2, 30);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_FORWARD_DELAY,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_STP,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "sensitive",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    label = nmt_newt_label_new(_("seconds"));
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Forward delay"), widget, label);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_numeric_new(10, 1, 10);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_HELLO_TIME,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_STP,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "sensitive",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    label = nmt_newt_label_new(_("seconds"));
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Hello time"), widget, label);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_numeric_new(10, 6, 40);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_MAX_AGE,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_STP,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "sensitive",
Packit Service a1bd4f
                           G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    label = nmt_newt_label_new(_("seconds"));
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Max age"), widget, label);
Packit Service a1bd4f
Packit Service a1bd4f
    widget = nmt_newt_entry_numeric_new(10, 0, 65535);
Packit Service a1bd4f
    g_object_bind_property(s_bridge,
Packit Service a1bd4f
                           NM_SETTING_BRIDGE_GROUP_FORWARD_MASK,
Packit Service a1bd4f
                           widget,
Packit Service a1bd4f
                           "text",
Packit Service a1bd4f
                           G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
Packit Service a1bd4f
    nmt_editor_grid_append(grid, _("Group forward mask"), widget, NULL);
Packit Service a1bd4f
Packit Service a1bd4f
    nmt_editor_page_add_section(NMT_EDITOR_PAGE(bridge), section);
Packit Service a1bd4f
Packit Service a1bd4f
    G_OBJECT_CLASS(nmt_page_bridge_parent_class)->constructed(object);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_bridge_saved(NmtEditorPage *editor_page)
Packit 5756e2
{
Packit Service a1bd4f
    NmtPageBridgePrivate *priv = NMT_PAGE_BRIDGE_GET_PRIVATE(editor_page);
Packit 5756e2
Packit Service a1bd4f
    nmt_edit_connection_list_recommit(NMT_EDIT_CONNECTION_LIST(priv->slaves));
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_page_bridge_class_init(NmtPageBridgeClass *bridge_class)
Packit 5756e2
{
Packit Service a1bd4f
    GObjectClass *      object_class      = G_OBJECT_CLASS(bridge_class);
Packit Service a1bd4f
    NmtEditorPageClass *editor_page_class = NMT_EDITOR_PAGE_CLASS(bridge_class);
Packit 5756e2
Packit Service a1bd4f
    object_class->constructed = nmt_page_bridge_constructed;
Packit Service a1bd4f
    editor_page_class->saved  = nmt_page_bridge_saved;
Packit 5756e2
}