[PATCH 1/4] IFUPDOWN managed/unmanaged device mode - implement device tracking
- From: Alexander Sack <asac jwsdot com>
- To: NetworkManager List <networkmanager-list gnome org>
- Subject: [PATCH 1/4] IFUPDOWN managed/unmanaged device mode - implement device tracking
- Date: Wed, 8 Oct 2008 13:21:30 +0200
Add support to track network devices that have a configuration
with a matching interface.name in /etc/network/interfaces
=== modified file 'ChangeLog'
--- a/ChangeLog 2008-10-07 20:40:57 +0000
+++ b/ChangeLog 2008-10-07 20:42:06 +0000
@@ -1,9 +1,31 @@
2008-10-07 Alexander Sack <asac ubuntu com>
+ Add support to track network devices that have a configuration
+ with a matching interface.name in /etc/network/interfaces
+
+ * system-settings/plugins/ifupdown/plugin.c
+ - (typedef struct SCPluginIfupdownPrivate): add hash table
+ to track |well_known_udis|
+ - (get_iface_for_udi): helper function to get interface.name
+ for a udi
+ - (hal_device_added_cb, hal_device_removed_cb): callbacks
+ that add and remove devices to and from the well_known_udis
+ set depending on whether their |interface.name| matches
+ any interface definition in /etc/network/interfaces
+ - (SCPluginIfupdown_init): connect callbacks from above with
+ hal_mgr and setup well_known_udis hashtable
+ - (GObject__dispose): destroy well_known_udis hashtable
+ - (hal_device_added_cb2): implement wrapper callback with GFunc
+ signature. user_data is supposed to be a triple (hal_mgr,
+ config and devtype)
+ - (SCPluginIfupdown_init): bootstrap wired and wifi devices for
+ startup and call hal_device_added_cb2
+
+2008-10-07 Alexander Sack <asac ubuntu com>
Remove implementation for not used NMSystemConfigInterface callback functions
in ifupdown plugin
* system-settings/plugins/ifupdown/plugin.c
- (SCPluginIfupdown_unmanaged_devices_changed) removed
- (SCPluginIfupdown_connection_added) removed
=== modified file 'system-settings/plugins/ifupdown/plugin.c'
--- a/system-settings/plugins/ifupdown/plugin.c 2008-10-07 20:40:57 +0000
+++ b/system-settings/plugins/ifupdown/plugin.c 2008-10-07 20:42:06 +0000
@@ -55,16 +55,18 @@
typedef struct {
DBusGConnection *g_connection;
NMSystemConfigHalManager *hal_mgr;
GHashTable *iface_connections;
gchar* hostname;
+ GHashTable *well_known_udis;
+
gulong inotify_event_id;
int inotify_system_hostname_wd;
} SCPluginIfupdownPrivate;
static void
system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
G_DEFINE_TYPE_EXTENDED (SCPluginIfupdown, sc_plugin_ifupdown, G_TYPE_OBJECT, 0,
@@ -154,31 +156,136 @@ sc_plugin_ifupdown_class_init (SCPluginI
NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES,
NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES);
g_object_class_override_property (object_class,
NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME,
NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
}
+static gchar*
+get_iface_for_udi (DBusGConnection *g_connection,
+ const gchar* udi,
+ GError **error)
+{
+ DBusGProxy *dev_proxy;
+ char *iface = NULL;
+ dev_proxy = dbus_g_proxy_new_for_name (g_connection,
+ "org.freedesktop.Hal",
+ udi,
+ "org.freedesktop.Hal.Device");
+ if (!dev_proxy)
+ return NULL;
+
+ if (dbus_g_proxy_call_with_timeout (dev_proxy,
+ "GetPropertyString", 10000, error,
+ G_TYPE_STRING, "net.interface", G_TYPE_INVALID,
+ G_TYPE_STRING, &iface, G_TYPE_INVALID)) {
+ g_object_unref (dev_proxy);
+ return iface;
+ }
+ g_object_unref (dev_proxy);
+ return NULL;
+}
+
+static void
+hal_device_added_cb (NMSystemConfigHalManager *hal_mgr,
+ const gchar* udi,
+ NMDeviceType devtype,
+ NMSystemConfigInterface *config)
+{
+ SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
+ gchar *iface;
+ GError *error = NULL;
+ gpointer exported_iface_connection;
+ NMConnection *iface_connection = NULL;
+
+ iface = get_iface_for_udi (priv->g_connection,
+ udi,
+ &error);
+
+ PLUGIN_PRINT("SCPlugin-Ifupdown",
+ "devices added (udi: %s, iface: %s)", udi, iface);
+
+ if(!iface)
+ return;
+
+ exported_iface_connection =
+ NM_EXPORTED_CONNECTION (g_hash_table_lookup (priv->iface_connections, iface));
+ /* if we have a configured connection for this particular iface
+ * we want to either unmanage the device or lock it
+ */
+ if(!exported_iface_connection)
+ return;
+
+ iface_connection = nm_exported_connection_get_connection (exported_iface_connection);
+
+ if(!iface_connection)
+ return;
+
+ g_hash_table_insert (priv->well_known_udis, (gpointer)udi, "nothing");
+}
+
+static void
+hal_device_removed_cb (NMSystemConfigHalManager *hal_mgr,
+ const gchar* udi,
+ NMDeviceType devtype,
+ NMSystemConfigInterface *config)
+{
+ SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
+
+ PLUGIN_PRINT("SCPlugin-Ifupdown",
+ "devices removed (udi: %s)", udi);
+
+ g_hash_table_remove (priv->well_known_udis, udi);
+}
+
+static void
+hal_device_added_cb2 (gpointer data,
+ gpointer user_data)
+{
+ NMSystemConfigHalManager *hal_mgr = ((gpointer*)user_data)[0];
+ NMSystemConfigInterface *config = ((gpointer*)user_data)[1];
+ NMDeviceType devtype = GPOINTER_TO_INT(((gpointer*)user_data)[2]);
+ const gchar *udi = data;
+
+ hal_device_added_cb (hal_mgr,
+ udi,
+ devtype,
+ config);
+}
+
static void
SCPluginIfupdown_init (NMSystemConfigInterface *config,
NMSystemConfigHalManager *hal_manager)
{
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
GHashTable *auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal);
if_block *block = NULL;
NMInotifyHelper *inotify_helper;
if(!priv->iface_connections)
priv->iface_connections = g_hash_table_new (g_str_hash, g_str_equal);
+ if(!priv->well_known_udis)
+ priv->well_known_udis = g_hash_table_new (g_str_hash, g_str_equal);
+
PLUGIN_PRINT("SCPlugin-Ifupdown", "init!");
priv->hal_mgr = g_object_ref (hal_manager);
+ g_signal_connect (G_OBJECT(hal_manager),
+ "device-added",
+ G_CALLBACK(hal_device_added_cb),
+ config);
+
+ g_signal_connect (G_OBJECT(hal_manager),
+ "device-removed",
+ G_CALLBACK(hal_device_removed_cb),
+ config);
+
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);
@@ -221,16 +328,42 @@ SCPluginIfupdown_init (NMSystemConfigInt
g_object_set (setting,
"autoconnect", TRUE,
NULL);
PLUGIN_PRINT("SCPlugin-Ifupdown", "autoconnect");
}
key_it = key_it -> next;
}
}
+
+ {
+ /* init well_known_udis */
+ GSList *wired_devices = nm_system_config_hal_manager_get_devices_of_type (hal_manager, NM_DEVICE_TYPE_ETHERNET);
+ GSList *wifi_devices = nm_system_config_hal_manager_get_devices_of_type (hal_manager, NM_DEVICE_TYPE_WIFI);
+ gpointer *user_data;
+
+ /* 3g in /etc/network/interfaces? no clue if thats mappable
+
+ GSList *gsm_devices = nm_system_config_hal_manager_get_devices_of_type (hal_manager, NM_DEVICE_TYPE_GSM);
+ GSList *cdma_devices = nm_system_config_hal_manager_get_devices_of_type (hal_manager, NM_DEVICE_TYPE_CDMA);
+ */
+
+ user_data = g_new0 (gpointer, 3);
+ user_data[0] = hal_manager;
+ user_data[1] = config;
+ user_data[2] = GINT_TO_POINTER (NM_DEVICE_TYPE_ETHERNET);
+
+ g_slist_foreach (wired_devices, hal_device_added_cb2, user_data);
+
+ user_data[0] = hal_manager;
+ user_data[1] = config;
+ user_data[2] = GINT_TO_POINTER (NM_DEVICE_TYPE_ETHERNET);
+ g_slist_foreach (wifi_devices, hal_device_added_cb2, user_data);
+ }
+
g_hash_table_unref(auto_ifaces);
PLUGIN_PRINT("SCPlugin-Ifupdown", "end _init.");
}
/* Returns the plugins currently known list of connections. The returned
* list is freed by the system settings service.
*/
@@ -398,16 +531,19 @@ GObject__dispose (GObject *object)
SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (plugin);
NMInotifyHelper *inotify_helper = nm_inotify_helper_get ();
g_signal_handler_disconnect (inotify_helper, priv->inotify_event_id);
if (priv->inotify_system_hostname_wd >= 0)
nm_inotify_helper_remove_watch (inotify_helper, priv->inotify_system_hostname_wd);
+ if (priv->well_known_udis)
+ g_hash_table_destroy(priv->well_known_udis);
+
g_object_unref (priv->hal_mgr);
G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->dispose (object);
}
static void
GObject__finalize (GObject *object)
{
G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->finalize (object);
- Alexander
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]