Commit 789f8c73 authored by Thomas Graf's avatar Thomas Graf Committed by Dan Williams

cli: add bridge support

parent c091415b
......@@ -43,6 +43,7 @@
#include <nm-device-olpc-mesh.h>
#include <nm-device-infiniband.h>
#include <nm-device-bond.h>
#include <nm-device-bridge.h>
#include <nm-device-vlan.h>
#include <nm-remote-settings.h>
#include <nm-vpn-connection.h>
......@@ -94,6 +95,8 @@ static NmcOutputField nmc_fields_settings_names[] = {
SETTING_FIELD (NM_SETTING_BOND_SETTING_NAME, 0), /* 17 */
SETTING_FIELD (NM_SETTING_VLAN_SETTING_NAME, 0), /* 18 */
SETTING_FIELD (NM_SETTING_ADSL_SETTING_NAME, 0), /* 19 */
SETTING_FIELD (NM_SETTING_BRIDGE_SETTING_NAME, 0), /* 20 */
SETTING_FIELD (NM_SETTING_BRIDGE_PORT_SETTING_NAME, 0), /* 21 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_SETTINGS_NAMES_ALL_X NM_SETTING_CONNECTION_SETTING_NAME","\
......@@ -114,7 +117,9 @@ static NmcOutputField nmc_fields_settings_names[] = {
NM_SETTING_VPN_SETTING_NAME","\
NM_SETTING_INFINIBAND_SETTING_NAME","\
NM_SETTING_BOND_SETTING_NAME","\
NM_SETTING_VLAN_SETTING_NAME
NM_SETTING_VLAN_SETTING_NAME","\
NM_SETTING_BRIDGE_SETTING_NAME","\
NM_SETTING_BRIDGE_PORT_SETTING_NAME
#if WITH_WIMAX
#define NMC_FIELDS_SETTINGS_NAMES_ALL NMC_FIELDS_SETTINGS_NAMES_ALL_X","\
NM_SETTING_WIMAX_SETTING_NAME
......@@ -452,6 +457,24 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
continue;
}
}
if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[20].name)) {
NMSettingBridge *s_bridge = nm_connection_get_setting_bridge (connection);
if (s_bridge) {
setting_bridge_details (s_bridge, nmc);
was_output = TRUE;
continue;
}
}
if (!strcasecmp (nmc_fields_settings_names[section_idx].name, nmc_fields_settings_names[21].name)) {
NMSettingBridgePort *s_bridge_port = nm_connection_get_setting_bridge_port (connection);
if (s_bridge_port) {
setting_bridge_port_details (s_bridge_port, nmc);
was_output = TRUE;
continue;
}
}
}
if (print_settings_array)
......@@ -1739,7 +1762,8 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
con_type = nm_setting_connection_get_connection_type (s_con);
if ( nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)
|| nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
|| nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)
|| nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
is_virtual = TRUE;
device_found = find_device_for_connection (nmc, connection, iface, ap, nsp, &device, &spec_object, &error);
......
......@@ -41,6 +41,7 @@
#endif
#include <nm-device-infiniband.h>
#include <nm-device-bond.h>
#include <nm-device-bridge.h>
#include <nm-device-vlan.h>
#include <nm-utils.h>
#include <nm-setting-ip4-config.h>
......@@ -307,6 +308,8 @@ device_type_to_string (NMDevice *device)
return NM_SETTING_BOND_SETTING_NAME;
case NM_DEVICE_TYPE_VLAN:
return NM_SETTING_VLAN_SETTING_NAME;
case NM_DEVICE_TYPE_BRIDGE:
return NM_SETTING_BRIDGE_SETTING_NAME;
default:
return _("Unknown");
}
......@@ -590,6 +593,8 @@ show_device_info (gpointer data, gpointer user_data)
hwaddr = nm_device_bond_get_hw_address (NM_DEVICE_BOND (device));
else if (NM_IS_DEVICE_VLAN (device))
hwaddr = nm_device_vlan_get_hw_address (NM_DEVICE_VLAN (device));
else if (NM_IS_DEVICE_BRIDGE (device))
hwaddr = nm_device_bridge_get_hw_address (NM_DEVICE_BRIDGE (device));
state_str = g_strdup_printf ("%d (%s)", state, nmc_device_state_to_string (state));
reason_str = g_strdup_printf ("%d (%s)", reason, nmc_device_reason_to_string (reason));
......
......@@ -518,6 +518,42 @@ static NmcOutputField nmc_fields_setting_vlan[] = {
NM_SETTING_VLAN_EGRESS_PRIORITY_MAP
#define NMC_FIELDS_SETTING_VLAN_COMMON NMC_FIELDS_SETTING_VLAN_ALL
/* Available fields for NM_SETTING_BRIDGE_SETTING_NAME */
static NmcOutputField nmc_fields_setting_bridge[] = {
SETTING_FIELD ("name", 8), /* 0 */
SETTING_FIELD (NM_SETTING_BRIDGE_INTERFACE_NAME, 15), /* 1 */
SETTING_FIELD (NM_SETTING_BRIDGE_STP, 5), /* 2 */
SETTING_FIELD (NM_SETTING_BRIDGE_PRIORITY, 6), /* 3 */
SETTING_FIELD (NM_SETTING_BRIDGE_FORWARD_DELAY, 6), /* 4 */
SETTING_FIELD (NM_SETTING_BRIDGE_HELLO_TIME, 6), /* 5 */
SETTING_FIELD (NM_SETTING_BRIDGE_MAX_AGE, 6), /* 6 */
SETTING_FIELD (NM_SETTING_BRIDGE_AGEING_TIME, 6), /* 7 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_SETTING_BRIDGE_ALL "name"","\
NM_SETTING_BRIDGE_INTERFACE_NAME","\
NM_SETTING_BRIDGE_STP","\
NM_SETTING_BRIDGE_PRIORITY","\
NM_SETTING_BRIDGE_FORWARD_DELAY","\
NM_SETTING_BRIDGE_HELLO_TIME","\
NM_SETTING_BRIDGE_MAX_AGE","\
NM_SETTING_BRIDGE_AGEING_TIME
#define NMC_FIELDS_SETTING_BRIDGE_COMMON NMC_FIELDS_SETTING_BRIDGE_ALL
/* Available fields for NM_SETTING_BRIDGE_PORT_SETTING_NAME */
static NmcOutputField nmc_fields_setting_bridge_port[] = {
SETTING_FIELD ("name", 8), /* 0 */
SETTING_FIELD (NM_SETTING_BRIDGE_PORT_PRIORITY, 10), /* 1 */
SETTING_FIELD (NM_SETTING_BRIDGE_PORT_PATH_COST, 12), /* 2 */
SETTING_FIELD (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE, 15), /* 3 */
{NULL, NULL, 0, NULL, 0}
};
#define NMC_FIELDS_SETTING_BRIDGE_PORT_ALL "name"","\
NM_SETTING_BRIDGE_PORT_PRIORITY","\
NM_SETTING_BRIDGE_PORT_PATH_COST","\
NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE
#define NMC_FIELDS_SETTING_BRIDGE_PORT_COMMON NMC_FIELDS_SETTING_BRIDGE_PORT_ALL
static char *
wep_key_type_to_string (NMWepKeyType type)
......@@ -1812,3 +1848,67 @@ setting_adsl_details (NMSettingAdsl *s_adsl, NmCli *nmc)
return TRUE;
}
gboolean
setting_bridge_details (NMSettingBridge *s_bridge, NmCli *nmc)
{
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (s_bridge), FALSE);
nmc->allowed_fields = nmc_fields_setting_bridge;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_BRIDGE_ALL, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */
nmc->allowed_fields[0].value = NM_SETTING_BRIDGE_SETTING_NAME;
nmc->allowed_fields[1].value = nm_setting_bridge_get_interface_name (s_bridge);
nmc->allowed_fields[2].value = nm_setting_bridge_get_stp (s_bridge) ? _("yes") : _("no");
nmc->allowed_fields[3].value = g_strdup_printf ("%u", nm_setting_bridge_get_priority (s_bridge));
nmc->allowed_fields[4].value = g_strdup_printf ("%u", nm_setting_bridge_get_forward_delay (s_bridge));
nmc->allowed_fields[5].value = g_strdup_printf ("%u", nm_setting_bridge_get_hello_time (s_bridge));
nmc->allowed_fields[6].value = g_strdup_printf ("%u", nm_setting_bridge_get_max_age (s_bridge));
nmc->allowed_fields[7].value = g_strdup_printf ("%u", nm_setting_bridge_get_ageing_time (s_bridge));
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
/* free values */
g_free ((char*) nmc->allowed_fields[3].value);
g_free ((char*) nmc->allowed_fields[4].value);
g_free ((char*) nmc->allowed_fields[5].value);
g_free ((char*) nmc->allowed_fields[6].value);
g_free ((char*) nmc->allowed_fields[7].value);
return TRUE;
}
gboolean
setting_bridge_port_details (NMSettingBridgePort *s_bridge_port, NmCli *nmc)
{
guint32 mode_flag = (nmc->print_output == NMC_PRINT_PRETTY) ? NMC_PF_FLAG_PRETTY : (nmc->print_output == NMC_PRINT_TERSE) ? NMC_PF_FLAG_TERSE : 0;
guint32 multiline_flag = nmc->multiline_output ? NMC_PF_FLAG_MULTILINE : 0;
guint32 escape_flag = nmc->escape_values ? NMC_PF_FLAG_ESCAPE : 0;
g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (s_bridge_port), FALSE);
nmc->allowed_fields = nmc_fields_setting_bridge_port;
nmc->print_fields.indices = parse_output_fields (NMC_FIELDS_SETTING_BRIDGE_PORT_ALL, nmc->allowed_fields, NULL);
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_FIELD_NAMES;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print field names */
nmc->allowed_fields[0].value = NM_SETTING_BRIDGE_PORT_SETTING_NAME;
nmc->allowed_fields[1].value = g_strdup_printf ("%u", nm_setting_bridge_port_get_priority (s_bridge_port));
nmc->allowed_fields[2].value = g_strdup_printf ("%u", nm_setting_bridge_port_get_path_cost (s_bridge_port));
nmc->allowed_fields[3].value = nm_setting_bridge_port_get_hairpin_mode (s_bridge_port) ? _("yes") : _("no");
nmc->print_fields.flags = multiline_flag | mode_flag | escape_flag | NMC_PF_FLAG_SECTION_PREFIX;
print_fields (nmc->print_fields, nmc->allowed_fields); /* Print values */
g_free ((char*) nmc->allowed_fields[1].value);
g_free ((char*) nmc->allowed_fields[2].value);
return TRUE;
}
......@@ -39,6 +39,8 @@
#include <nm-setting-wimax.h>
#include <nm-setting-infiniband.h>
#include <nm-setting-bond.h>
#include <nm-setting-bridge.h>
#include <nm-setting-bridge-port.h>
#include <nm-setting-vlan.h>
#include "nmcli.h"
......@@ -65,5 +67,7 @@ gboolean setting_infiniband_details (NMSettingInfiniband *s_infiniband, NmCli *n
gboolean setting_bond_details (NMSettingBond *s_bond, NmCli *nmc);
gboolean setting_vlan_details (NMSettingVlan *s_vlan, NmCli *nmc);
gboolean setting_adsl_details (NMSettingAdsl *s_adsl, NmCli *nmc);
gboolean setting_bridge_details (NMSettingBridge *s_bridge, NmCli *nmc);
gboolean setting_bridge_port_details (NMSettingBridgePort *s_bridge_port, NmCli *nmc);
#endif /* NMC_SETTINGS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment