static GSList *
SCPluginIfnet_get_connections (NMSystemConfigInterface * config)
{
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);
	GSList *connections = NULL;
	GHashTableIter iter;
	gpointer key, value;

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%d) ... get_connections.",
		      GPOINTER_TO_UINT (config));
	if (priv->unmanaged_well_known) {
		PLUGIN_PRINT (IFNET_PLUGIN_NAME,
			      "(%d) ... get_connections (managed=false): return empty list.",
			      GPOINTER_TO_UINT (config));
		return NULL;
	}

	g_hash_table_iter_init (&iter, priv->config_connections);
	while (g_hash_table_iter_next (&iter, &key, &value))
		if (is_managed ((gchar *) key))
			connections = g_slist_prepend (connections, value);
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%d) connections count: %d",
		      GPOINTER_TO_UINT (config), g_slist_length (connections));
	return connections;
}
static void
check_unmanaged (gpointer key, gpointer data, gpointer user_data)
{
	GSList **list = (GSList **) user_data;
	gchar *conn_name = (gchar *) key;
	const char *unmanaged_spec;
	GSList *iter;

	if (is_managed (conn_name))
		return;
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Checking unmanaged: %s", conn_name);
	unmanaged_spec = ifnet_get_data (conn_name, "mac");
	if (!unmanaged_spec)
		return;

	/* Just return if the unmanaged spec is already in the list */
	for (iter = *list; iter; iter = g_slist_next (iter)) {
		if (!strcmp ((char *) iter->data, unmanaged_spec))
			return;
	}

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Add unmanaged: %s", unmanaged_spec);
	*list =
	    g_slist_prepend (*list, g_strdup_printf ("mac:%s", unmanaged_spec));
}
Exemplo n.º 3
0
static void
udev_device_added (SCPluginIfupdown *self, GUdevDevice *device)
{
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self);
	const char *iface, *path;
	NMIfupdownConnection *exported;

	iface = g_udev_device_get_name (device);
	path = g_udev_device_get_sysfs_path (device);
	if (!iface || !path)
		return;

	PLUGIN_PRINT("SCPlugin-Ifupdown",
	             "devices added (path: %s, iface: %s)", path, iface);

	/* if we have a configured connection for this particular iface
	 * we want to either unmanage the device or lock it
	 */
	exported = (NMIfupdownConnection *) g_hash_table_lookup (priv->iface_connections, iface);
	if (!exported && !g_hash_table_lookup (priv->well_known_interfaces, iface)) {
		PLUGIN_PRINT("SCPlugin-Ifupdown",
			"device added (path: %s, iface: %s): no ifupdown configuration found.", path, iface);
		return;
	}

	g_hash_table_insert (priv->well_known_ifaces, g_strdup (iface), g_object_ref (device));

	if (exported)
		bind_device_to_connection (self, device, exported);

	if (ALWAYS_UNMANAGE || priv->unmanage_well_known)
		g_signal_emit_by_name (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
}
Exemplo n.º 4
0
static NMIfcfgConnection *
_internal_new_connection (SCPluginIfcfg *self,
                          const char *path,
                          NMConnection *source,
                          GError **error)
{
    SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (self);
    NMIfcfgConnection *connection;
    const char *cid;
    GError *local = NULL;
    gboolean ignore_error = FALSE;

    if (!source) {
        PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "parsing %s ... ", path);
    }

    connection = nm_ifcfg_connection_new (path, source, &local, &ignore_error);
    if (!connection) {
        if (!ignore_error) {
            PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    error: %s",
                          (local && local->message) ? local->message : "(unknown)");
        }
        g_propagate_error (error, local);
        return NULL;
    }

    cid = nm_connection_get_id (NM_CONNECTION (connection));
    g_assert (cid);

    g_hash_table_insert (priv->connections,
                         (gpointer) nm_ifcfg_connection_get_path (connection),
                         connection);
    PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "    read connection '%s'", cid);

    if (nm_ifcfg_connection_get_unmanaged_spec (connection)) {
        PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "Ignoring connection '%s' and its "
                      "device due to NM_CONTROLLED/BRIDGE/VLAN.", cid);
    } else {
        /* Wait for the connection to become unmanaged once it knows the
         * hardware IDs of its device, if/when the device gets plugged in.
         */
        g_signal_connect (G_OBJECT (connection), "notify::" NM_IFCFG_CONNECTION_UNMANAGED,
                          G_CALLBACK (connection_unmanaged_changed), self);
    }

    /* watch changes of ifcfg hardlinks */
    g_signal_connect (G_OBJECT (connection), "ifcfg-changed",
                      G_CALLBACK (connection_ifcfg_changed), self);

    return connection;
}
Exemplo n.º 5
0
/*
 * Return a list of device specifications which NetworkManager should not
 * manage.  Returned list will be freed by the system settings service, and
 * each element must be allocated using g_malloc() or its variants.
 */
static GSList*
SCPluginIfupdown_get_unmanaged_specs (NMSystemConfigInterface *config)
{
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
	GSList *specs = NULL;
	GHashTableIter iter;
	gpointer value;

	if (!ALWAYS_UNMANAGE && !priv->unmanage_well_known)
		return NULL;

	PLUGIN_PRINT("Ifupdown", "get unmanaged devices count: %d",
	             g_hash_table_size (priv->well_known_ifaces));

	g_hash_table_iter_init (&iter, priv->well_known_ifaces);
	while (g_hash_table_iter_next (&iter, NULL, &value)) {
		GUdevDevice *device = G_UDEV_DEVICE (value);
		const char *address;

		address = g_udev_device_get_sysfs_attr (device, "address");
		if (address)
			specs = g_slist_append (specs, g_strdup_printf ("mac:%s", address));
	}
	return specs;
}
static GFileMonitor *
monitor_file_changes (const char *filename,
		      FileChangedFn callback, gpointer user_data)
{
	GFile *file;
	GFileMonitor *monitor;
	FileMonitorInfo *info;
	GError **error = NULL;

	if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
		return NULL;
	file = g_file_new_for_path (filename);
	monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, error);
	g_object_unref (file);

	if (monitor) {
		info = g_new0 (FileMonitorInfo, 1);
		info->callback = callback;
		info->user_data = user_data;
		g_object_weak_ref (G_OBJECT (monitor), (GWeakNotify) g_free,
				   info);
		g_signal_connect (monitor, "changed", G_CALLBACK (file_changed),
				  info);
		PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Monitoring %s", filename);

	} else
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Monitoring %s failed, error: %s", filename,
			     error == NULL ? "nothing" : (*error)->message);

	return monitor;
}
static void
update_system_hostname (gpointer config)
{
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Updating hostname");

	if (priv->hostname)
		g_free (priv->hostname);
	priv->hostname = read_hostname (IFNET_SYSTEM_HOSTNAME_FILE);

	g_object_notify (G_OBJECT (config),
			 NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Hostname updated to: %s",
		      priv->hostname);
}
Exemplo n.º 8
0
static void
bind_device_to_connection (SCPluginIfupdown *self,
                           GUdevDevice *device,
                           NMIfupdownConnection *exported)
{
	GByteArray *mac_address;
	NMSetting *s_wired = NULL;
	NMSetting *s_wifi = NULL;
	const char *iface, *address;
	struct ether_addr *tmp_mac;

	iface = g_udev_device_get_name (device);
	if (!iface) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get ifname for device.");
		return;
	}

	address = g_udev_device_get_sysfs_attr (device, "address");
	if (!address || !strlen (address)) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface);
		return;
	}

	tmp_mac = ether_aton (address);
	if (!tmp_mac) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to parse MAC address '%s' for %s",
		             address, iface);
		return;
	}

	mac_address = g_byte_array_sized_new (ETH_ALEN);
	g_byte_array_append (mac_address, &(tmp_mac->ether_addr_octet[0]), ETH_ALEN);

	s_wired = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRED);
	s_wifi = nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_WIRELESS);
	if (s_wired) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
		g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
	} else if (s_wifi) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
		g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
	}
	g_byte_array_free (mac_address, TRUE);

	nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL);
}    
Exemplo n.º 9
0
static void
bind_device_to_connection (SCPluginIfupdown *self,
                           GUdevDevice *device,
                           NMIfupdownConnection *exported)
{
	GByteArray *mac_address;
	NMSettingWired *s_wired;
	NMSettingWireless *s_wifi;
	const char *iface, *address;

	iface = g_udev_device_get_name (device);
	if (!iface) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get ifname for device.");
		return;
	}

	address = g_udev_device_get_sysfs_attr (device, "address");
	if (!address || !strlen (address)) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to get MAC address for %s", iface);
		return;
	}

	mac_address = nm_utils_hwaddr_atoba (address, ARPHRD_ETHER);
	if (!mac_address) {
		PLUGIN_WARN ("SCPluginIfupdown", "failed to parse MAC address '%s' for %s",
		             address, iface);
		return;
	}

	s_wired = nm_connection_get_setting_wired (NM_CONNECTION (exported));
	s_wifi = nm_connection_get_setting_wireless (NM_CONNECTION (exported));
	if (s_wired) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
		g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
	} else if (s_wifi) {
		PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
		g_object_set (s_wifi, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
	}
	g_byte_array_free (mac_address, TRUE);

	nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL);
}    
static GSList *
get_unmanaged_specs (NMSystemConfigInterface * config)
{
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);
	GSList *list = NULL;

	g_return_val_if_fail (priv->config_connections != NULL, NULL);
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "getting unmanaged specs...");
	g_hash_table_foreach (priv->config_connections, check_unmanaged, &list);
	return list;
}
Exemplo n.º 11
0
static void
read_connections (NMSystemConfigInterface *config)
{
	SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
	GDir *dir;
	GError *error = NULL;
	const char *item;

	dir = g_dir_open (KEYFILE_DIR, 0, &error);
	if (!dir) {
		PLUGIN_WARN (KEYFILE_PLUGIN_NAME, "Cannot read directory '%s': (%d) %s",
		             KEYFILE_DIR,
		             error ? error->code : -1,
		             error && error->message ? error->message : "(unknown)");
		g_clear_error (&error);
		return;
	}

	while ((item = g_dir_read_name (dir))) {
		NMSettingsConnection *connection;
		char *full_path;

		if (nm_keyfile_plugin_utils_should_ignore_file (item))
			continue;

		full_path = g_build_filename (KEYFILE_DIR, item, NULL);
		PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "parsing %s ... ", item);

		connection = _internal_new_connection (self, full_path, NULL, &error);
		if (connection) {
			PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "    read connection '%s'",
			              nm_connection_get_id (NM_CONNECTION (connection)));
		} else {
			PLUGIN_PRINT (KEYFILE_PLUGIN_NAME, "    error: %s",
				          (error && error->message) ? error->message : "(unknown)");
		}
		g_clear_error (&error);
		g_free (full_path);
	}
	g_dir_close (dir);
}
Exemplo n.º 12
0
/* Returns the plugins currently known list of connections.  The returned
 * list is freed by the system settings service.
 */
static GSList*
SCPluginIfupdown_get_connections (NMSystemConfigInterface *config)
{
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
	GSList *connections = NULL;
	GHashTableIter iter;
	gpointer value;

	PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections.", GPOINTER_TO_UINT(config));

	if(priv->unmanage_well_known) {
		PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) ... get_connections (managed=false): return empty list.", GPOINTER_TO_UINT(config));
		return NULL;
	}

	g_hash_table_iter_init (&iter, priv->iface_connections);
	while (g_hash_table_iter_next (&iter, NULL, &value))
		connections = g_slist_prepend (connections, value);

	PLUGIN_PRINT("SCPlugin-Ifupdown", "(%d) connections count: %d", GPOINTER_TO_UINT(config), g_slist_length(connections));
	return connections;
}
static void
SCPluginIfnet_init (NMSystemConfigInterface * config)
{
	SCPluginIfnet *self = SC_PLUGIN_IFNET (config);
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self);

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Initializing!");
	if (!priv->config_connections)
		priv->config_connections =
		    g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
					   g_object_unref);
	priv->unmanaged_well_known = !is_managed_plugin ();
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "management mode: %s",
		      priv->unmanaged_well_known ? "unmanaged" : "managed");
	// GFileMonitor setup
	setup_monitors (NULL, config);
	reload_connections (config);
	/* Now if we're running in managed mode, let NM know there are new connections */
	if (!priv->unmanaged_well_known) {
		GHashTableIter iter;
		gpointer key;
		gpointer value;

		g_hash_table_iter_init (&iter, priv->config_connections);
		while (g_hash_table_iter_next (&iter, &key, &value)) {
			if (is_managed ((gchar *) key))
				g_signal_emit_by_name
				    (self,
				     NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
				     NM_EXPORTED_CONNECTION (value));
		}
	}
	/* Read hostname */
	update_system_hostname (self);

	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Initialzation complete!");
}
static void
update_old_connection (gchar * conn_name,
		       NMIfnetConnection * old_conn,
		       NMIfnetConnection * new_conn,
		       SCPluginIfnetPrivate * priv)
{
	GError **error = NULL;

	if (!nm_sysconfig_connection_update (NM_SYSCONFIG_CONNECTION (old_conn),
					     NM_CONNECTION (new_conn), TRUE,
					     error)) {
		PLUGIN_WARN (IFNET_PLUGIN_NAME, "error updating: %s",
			     (error
			      && (*error)) ? (*error)->message : "(unknown)");
	} else
		PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Connection %s updated",
			      conn_name);
	g_object_unref (new_conn);
}
static void
write_system_hostname (NMSystemConfigInterface * config,
		       const gchar * newhostname)
{
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (config);

	g_return_if_fail (newhostname);
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Write system hostname: %s",
		      newhostname);
	if (write_hostname (newhostname, IFNET_SYSTEM_HOSTNAME_FILE)) {
		if (priv->hostname)
			g_free (priv->hostname);
		priv->hostname = g_strdup (newhostname);
		g_object_notify (G_OBJECT (config),
				 NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
	} else
		PLUGIN_WARN (IFNET_PLUGIN_NAME,
			     "Write system hostname: %s failed", newhostname);
}
Exemplo n.º 16
0
static void
udev_device_changed (SCPluginIfupdown *self, GUdevDevice *device)
{
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self);
	const char *iface, *path;

	iface = g_udev_device_get_name (device);
	path = g_udev_device_get_sysfs_path (device);
	if (!iface || !path)
		return;

	PLUGIN_PRINT("SCPlugin-Ifupdown", "device changed (path: %s, iface: %s)", path, iface);

	if (!g_hash_table_lookup (priv->kernel_ifaces, iface))
		return;

	if (ALWAYS_UNMANAGE || priv->unmanage_well_known)
		g_signal_emit_by_name (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
}
Exemplo n.º 17
0
static void
write_system_hostname(NMSystemConfigInterface *config,
				  const char *newhostname)
{
	GError *error = NULL;
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
	PLUGIN_PRINT ("SCPlugin-Ifupdown", "write_system_hostname: %s", newhostname);

	g_return_if_fail (newhostname);

	if(!g_file_set_contents ( IFUPDOWN_SYSTEM_HOSTNAME_FILE,
						 newhostname,
						 -1,
						 &error)) {
		nm_log_warn (LOGD_SETTINGS, "update_system_hostname() - couldn't write hostname (%s) to "
				  IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)",
				  newhostname, error->code, error->message);	
	} else {
		priv->hostname = g_strdup (newhostname);
	}
	g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
}
Exemplo n.º 18
0
static void
update_system_hostname(NMInotifyHelper *inotify_helper,
                       struct inotify_event *evt,
                       const char *path,
                       NMSystemConfigInterface *config)
{
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
	gchar *hostname_file = NULL;
	gsize hostname_file_len = 0;
	GError *error = NULL;

	PLUGIN_PRINT ("SCPlugin-Ifupdown", "update_system_hostname");

	if (evt && evt->wd != priv->inotify_system_hostname_wd)
		return;

	if(!g_file_get_contents ( IFUPDOWN_SYSTEM_HOSTNAME_FILE,
						 &hostname_file,
						 &hostname_file_len,
						 &error)) {
		nm_log_warn (LOGD_SETTINGS, "update_system_hostname() - couldn't read "
				  IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)",
				  error->code, error->message);
		return;
	}

	g_free(priv->hostname);
	priv->hostname = g_strstrip(hostname_file);

	/* We shouldn't return a zero-length hostname, but NULL */
	if (priv->hostname && !strlen (priv->hostname)) {
		g_free (priv->hostname);
		priv->hostname = NULL;
	}

	g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
}
Exemplo n.º 19
0
static void
SCPluginIfupdown_init (NMSystemConfigInterface *config)
{
	SCPluginIfupdown *self = SC_PLUGIN_IFUPDOWN (config);
	SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (self);
	GHashTable *auto_ifaces;
	if_block *block = NULL;
	NMInotifyHelper *inotify_helper;
	GKeyFile* keyfile;
	GError *error = NULL;
	GList *keys, *iter;
	const char *subsys[2] = { "net", NULL };

	auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal);

	if(!priv->iface_connections)
		priv->iface_connections = g_hash_table_new (g_str_hash, g_str_equal);

	if(!priv->well_known_ifaces)
		priv->well_known_ifaces = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);

	if(!priv->well_known_interfaces)
		priv->well_known_interfaces = g_hash_table_new (g_str_hash, g_str_equal);

	PLUGIN_PRINT("SCPlugin-Ifupdown", "init!");

	priv->client = g_udev_client_new (subsys);
	if (!priv->client) {
		PLUGIN_WARN ("SCPlugin-Ifupdown", "    error initializing libgudev");
	} else
		g_signal_connect (priv->client, "uevent", G_CALLBACK (handle_uevent), self);

	priv->unmanage_well_known = IFUPDOWN_UNMANAGE_WELL_KNOWN_DEFAULT;
 
	inotify_helper = nm_inotify_helper_get ();
	priv->inotify_event_id = g_signal_connect (inotify_helper,
	                                           "event",
	                                           G_CALLBACK (update_system_hostname),
	                                           config);

	priv->inotify_system_hostname_wd =
		nm_inotify_helper_add_watch (inotify_helper, IFUPDOWN_SYSTEM_HOSTNAME_FILE);

	update_system_hostname (inotify_helper, NULL, NULL, config);

	/* Read in all the interfaces */
	ifparser_init (ENI_INTERFACES_FILE, 0);
	block = ifparser_getfirst ();
	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)) {
			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) {
					int i;
					int state = 0;
					char **port_ifaces;

					PLUGIN_PRINT("SCPlugin-Ifupdown", "found bridge ports %s for %s", ports, block->name);

					port_ifaces = g_strsplit_set (ports, " \t", -1);
					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) {
				PLUGIN_PRINT("SCPlugin-Ifupdown", "deleting %s from iface_connections", block->name);
				nm_settings_connection_delete (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL);
				g_hash_table_remove (priv->iface_connections, block->name);
			}

			/* add the new connection */
			exported = nm_ifupdown_connection_new (block);
			if (exported) {
				PLUGIN_PRINT("SCPlugin-Ifupdown", "adding %s to iface_connections", block->name);
				g_hash_table_insert (priv->iface_connections, block->name, exported);
			}
			PLUGIN_PRINT("SCPlugin-Ifupdown", "adding iface %s to well_known_interfaces", block->name);
			g_hash_table_insert (priv->well_known_interfaces, block->name, "known");
		} else if (!strcmp ("mapping", block->type)) {
			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;
	}

	/* Make 'auto' interfaces autoconnect=TRUE */
	keys = g_hash_table_get_keys (priv->iface_connections);
	for (iter = keys; iter; iter = g_list_next (iter)) {
		NMIfupdownConnection *exported;
		NMSetting *setting;

		if (!g_hash_table_lookup (auto_ifaces, iter->data))
			continue;

		exported = g_hash_table_lookup (priv->iface_connections, iter->data);
		setting = NM_SETTING (nm_connection_get_setting (NM_CONNECTION (exported), NM_TYPE_SETTING_CONNECTION));
		g_object_set (setting, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NULL);

		nm_settings_connection_commit_changes (NM_SETTINGS_CONNECTION (exported), ignore_cb, NULL);

		PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect");
	}
	g_list_free (keys);
	g_hash_table_destroy (auto_ifaces);

	/* Find the config file */
	if (g_file_test (IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE, G_FILE_TEST_EXISTS))
		priv->conf_file = IFUPDOWN_SYSTEM_SETTINGS_KEY_FILE;
	else
		priv->conf_file = IFUPDOWN_OLD_SYSTEM_SETTINGS_KEY_FILE;

	keyfile = g_key_file_new ();
	if (!g_key_file_load_from_file (keyfile,
	                                priv->conf_file,
	                                G_KEY_FILE_NONE,
	                                &error)) {
		nm_log_info (LOGD_SETTINGS, "loading system config file (%s) caused error: (%d) %s",
		         priv->conf_file,
		         error ? error->code : -1,
		         error && error->message ? error->message : "(unknown)");
	} else {
		gboolean manage_well_known;
		error = NULL;

		manage_well_known = g_key_file_get_boolean (keyfile,
		                                            IFUPDOWN_KEY_FILE_GROUP,
		                                            IFUPDOWN_KEY_FILE_KEY_MANAGED,
		                                            &error);
		if (error) {
			nm_log_info (LOGD_SETTINGS, "getting keyfile key '%s' in group '%s' failed: (%d) %s",
			         IFUPDOWN_KEY_FILE_GROUP,
			         IFUPDOWN_KEY_FILE_KEY_MANAGED,
			         error ? error->code : -1,
			         error && error->message ? error->message : "(unknown)");
		} else
			priv->unmanage_well_known = !manage_well_known;
	}
	PLUGIN_PRINT ("SCPluginIfupdown", "management mode: %s", priv->unmanage_well_known ? "unmanaged" : "managed");
	if (keyfile)
		g_key_file_free (keyfile);

	/* Add well-known interfaces */
	keys = g_udev_client_query_by_subsystem (priv->client, "net");
	for (iter = keys; iter; iter = g_list_next (iter)) {
		udev_device_added (self, G_UDEV_DEVICE (iter->data));
		g_object_unref (G_UDEV_DEVICE (iter->data));
	}
	g_list_free (keys);

	/* Now if we're running in managed mode, let NM know there are new connections */
	if (!priv->unmanage_well_known) {
		GList *con_list = g_hash_table_get_values (priv->iface_connections);
		GList *cl_iter;

		for (cl_iter = con_list; cl_iter; cl_iter = g_list_next (cl_iter)) {
			g_signal_emit_by_name (self,
			                       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
			                       NM_SETTINGS_CONNECTION (cl_iter->data));
		}
		g_list_free (con_list);
	}

	PLUGIN_PRINT("SCPlugin-Ifupdown", "end _init.");
}
static void
reload_connections (gpointer config)
{
	SCPluginIfnet *self = SC_PLUGIN_IFNET (config);
	SCPluginIfnetPrivate *priv = SC_PLUGIN_IFNET_GET_PRIVATE (self);
	GList *conn_names = NULL, *n_iter = NULL;

	/* save names for removing unused connections */
	GHashTable *new_conn_names = NULL;
	GHashTableIter iter;
	gpointer key;
	gpointer value;

	if (priv->unmanaged_well_known)
		return;

	if (!reload_parsers ())
		return;
	PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Loading connections");
	conn_names = ifnet_get_connection_names ();
	new_conn_names =
	    g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	for (n_iter = conn_names; n_iter; n_iter = g_list_next (n_iter)) {
		NMIfnetConnection *exported;
		NMIfnetConnection *old;
		gchar *conn_name = g_strdup (n_iter->data);

		/* add the new connection */
		exported = nm_ifnet_connection_new (conn_name);
		if (!exported) {
			g_free (conn_name);
			continue;
		}
		g_signal_connect (G_OBJECT (exported), "ifnet_setup_monitors",
				  G_CALLBACK (setup_monitors), config);
		g_signal_connect (G_OBJECT (exported), "ifnet_cancel_monitors",
				  G_CALLBACK (cancel_monitors), config);
		old = g_hash_table_lookup (priv->config_connections, conn_name);
		if (old && exported) {
			gchar *auto_refresh =
			    ifnet_get_global_setting (IFNET_KEY_FILE_GROUP,
						      "auto_refresh");

			if (auto_refresh && is_true (auto_refresh)) {
				if (!nm_connection_compare (NM_CONNECTION (old),
							    NM_CONNECTION
							    (exported),
							    NM_SETTING_COMPARE_FLAG_EXACT))
				{
					PLUGIN_PRINT (IFNET_PLUGIN_NAME,
						      "Auto refreshing %s",
						      conn_name);
					g_signal_emit_by_name (old,
							       NM_SETTINGS_CONNECTION_INTERFACE_REMOVED);
					g_hash_table_remove
					    (priv->config_connections,
					     conn_name);
					g_hash_table_insert
					    (priv->config_connections,
					     g_strdup (conn_name), exported);
					if (is_managed (conn_name))
						g_signal_emit_by_name (self,
								       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
								       exported);
				}
			} else
				update_old_connection (conn_name, old,
						       exported, priv);
			g_signal_emit_by_name (self,
					       NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
		} else if (exported) {
			g_hash_table_insert (priv->config_connections,
					     g_strdup (conn_name), exported);
			if (is_managed (conn_name))
				g_signal_emit_by_name (self,
						       NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED,
						       exported);
		}
		g_hash_table_insert (new_conn_names, conn_name, conn_name);
	}
	/* remove unused connections */
	g_hash_table_iter_init (&iter, priv->config_connections);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		if (!g_hash_table_lookup (new_conn_names, key)) {
			g_signal_emit_by_name (value,
					       NM_SETTINGS_CONNECTION_INTERFACE_REMOVED);
			g_hash_table_remove (priv->config_connections, key);
		}
	}
	g_hash_table_remove_all (new_conn_names);
	g_hash_table_destroy (new_conn_names);
	g_list_free (conn_names);
}