[PATCH 2/2] ifupdown: Allow to mark bridge ports as unmanaged



See attached patch
-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
From e793f03ae85dd14e7b4b07a5929938b5800bb3bf Mon Sep 17 00:00:00 2001
From: Michael Biebl <biebl debian org>
Date: Mon, 6 Dec 2010 19:03:09 +0100
Subject: [PATCH 2/2] ifupdown: Allow to mark bridge ports as unmanaged
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Parse bridge configurations in /etc/network/interfaces and add
interfaces defined via bridge_ports to well_known_interfaces. This
allows to mark those interfaces as unmanaged if managed=false.
The "all" keyword and regexes are not supported and simply skipped.

Example:
iface br0 inet manual
	bridge_ports eth0 eth1 (â?? eth0/1 will be marked as unmanaged)

See also:
http://manpages.ubuntu.com/manpages/maverick/man5/bridge-utils-interfaces.5.html

Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=530335
---
 system-settings/plugins/ifupdown/plugin.c |   43 ++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/system-settings/plugins/ifupdown/plugin.c b/system-settings/plugins/ifupdown/plugin.c
index 7daa06a..476cf95 100644
--- a/system-settings/plugins/ifupdown/plugin.c
+++ b/system-settings/plugins/ifupdown/plugin.c
@@ -362,9 +362,49 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config)
 	while (block) {
 		if(!strcmp ("auto", block->type) || !strcmp ("allow-hotplug", block->type))
 			g_hash_table_insert (auto_ifaces, block->name, GUINT_TO_POINTER (1));
-		else if (!strcmp ("iface", block->type) && strcmp ("lo", block->name)) {
+		else if (!strcmp ("iface", block->type)) {
 			NMIfupdownConnection *exported;
 
+			/* Bridge configuration */
+			if(!strncmp ("br", block->name, 2)) {
+				/* Try to find bridge ports */
+				const char *ports = ifparser_getkey (block, "bridge_ports");
+				if (ports) {
+					PLUGIN_PRINT("SCPlugin-Ifupdown", "found bridge ports %s for %s", ports, block->name);
+					char **port_ifaces = g_strsplit_set (ports, " \t", -1);
+
+					int i;
+					int state = 0;
+					for (i = 0; i < g_strv_length (port_ifaces); i++) {
+						char *token = port_ifaces[i];
+						/* Skip crazy stuff like regex or all */
+						if (!strcmp ("all", token)) {
+							continue;
+						}
+						/* Small SM to skip everything inside regex */
+						if (!strcmp ("regex", token)) {
+							state++;
+							continue;
+						}
+						if (!strcmp ("noregex", token)) {
+							state--;
+							continue;
+						}
+						if (state == 0 && strlen (token) > 0) {
+							PLUGIN_PRINT("SCPlugin-Ifupdown", "adding bridge port %s to well_known_interfaces", token);
+							g_hash_table_insert (priv->well_known_interfaces, g_strdup (token), "known");
+						}
+					}
+					g_strfreev (port_ifaces);
+				}
+				goto next;
+			}
+
+			/* Skip loopback configuration */
+			if(!strcmp ("lo", block->name)) {
+				goto next;
+			}
+
 			/* Remove any connection for this block that was previously found */
 			exported = g_hash_table_lookup (priv->iface_connections, block->name);
 			if (exported) {
@@ -387,6 +427,7 @@ SCPluginIfupdown_init (NMSystemConfigInterface *config)
 			g_hash_table_insert (priv->well_known_interfaces, block->name, "known");
 			PLUGIN_PRINT("SCPlugin-Ifupdown", "adding mapping %s to well_known_interfaces", block->name);
 		}
+	next:
 		block = block->next;
 	}
 
-- 
1.7.2.3

Attachment: signature.asc
Description: OpenPGP digital signature



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