[PATCH 6/6] bridge: nmcli support



---
 cli/src/connections.c |   17 +++++++++++++++--
 cli/src/devices.c     |    5 +++++
 cli/src/settings.c    |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 cli/src/settings.h    |    2 ++
 4 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/cli/src/connections.c b/cli/src/connections.c
index 2b4eb01..1c6fe53 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -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,7 @@ 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 */
 	{NULL, NULL, 0, NULL, 0}
 };
 #define NMC_FIELDS_SETTINGS_NAMES_ALL_X  NM_SETTING_CONNECTION_SETTING_NAME","\
@@ -114,7 +116,8 @@ 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
 #if WITH_WIMAX
 #define NMC_FIELDS_SETTINGS_NAMES_ALL    NMC_FIELDS_SETTINGS_NAMES_ALL_X","\
                                          NM_SETTING_WIMAX_SETTING_NAME
@@ -450,6 +453,15 @@ 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 (print_settings_array)
@@ -1731,7 +1743,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);
diff --git a/cli/src/devices.c b/cli/src/devices.c
index 4d5c79e..25f3ff9 100644
--- a/cli/src/devices.c
+++ b/cli/src/devices.c
@@ -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>
@@ -283,6 +284,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");
 	}
@@ -564,6 +567,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));
diff --git a/cli/src/settings.c b/cli/src/settings.c
index 13d76e1..351a00d 100644
--- a/cli/src/settings.c
+++ b/cli/src/settings.c
@@ -508,6 +508,18 @@ 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_OPTIONS, 30),                     /* 2 */
+	{NULL, NULL, 0, NULL, 0}
+};
+#define NMC_FIELDS_SETTING_BRIDGE_ALL    "name"","\
+                                         NM_SETTING_BRIDGE_INTERFACE_NAME","\
+                                         NM_SETTING_BRIDGE_OPTIONS
+#define NMC_FIELDS_SETTING_BRIDGE_COMMON NMC_FIELDS_SETTING_BRIDGE_ALL
+
 
 static char *
 wep_key_type_to_string (NMWepKeyType type)
@@ -1764,3 +1776,39 @@ setting_adsl_details (NMSettingAdsl *s_adsl, NmCli *nmc)
 	return TRUE;
 }
 
+gboolean
+setting_bridge_details (NMSettingBridge *s_bridge, NmCli *nmc)
+{
+	GString *bridge_options_s;
+	int i;
+	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 */
+
+	bridge_options_s = g_string_new (NULL);
+	for (i = 0; i < nm_setting_bridge_get_num_options (s_bridge); i++) {
+		const char *key, *value;
+
+		nm_setting_bridge_get_option (s_bridge, i, &key, &value);
+		g_string_append_printf (bridge_options_s, "%s=%s,", key, value);
+	}
+	g_string_truncate (bridge_options_s, bridge_options_s->len-1);  /* chop off trailing ',' */
+
+	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 = bridge_options_s->str;
+
+	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_string_free (bridge_options_s, TRUE);
+
+	return TRUE;
+}
diff --git a/cli/src/settings.h b/cli/src/settings.h
index 3309bd0..41abe76 100644
--- a/cli/src/settings.h
+++ b/cli/src/settings.h
@@ -39,6 +39,7 @@
 #include <nm-setting-wimax.h>
 #include <nm-setting-infiniband.h>
 #include <nm-setting-bond.h>
+#include <nm-setting-bridge.h>
 #include <nm-setting-vlan.h>
 
 #include "nmcli.h"
@@ -65,5 +66,6 @@ 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);
 
 #endif /* NMC_SETTINGS_H */
-- 
1.7.7.6



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]