Re: [PATCH 4/4] IFUPDOWN managed/unmanaged device mode - implement managed mode
- From: Alexander Sack <asac canonical com>
- To: NetworkManager List <networkmanager-list gnome org>
- Subject: Re: [PATCH 4/4] IFUPDOWN managed/unmanaged device mode - implement managed mode
- Date: Wed, 8 Oct 2008 13:26:35 +0200
Implement managed mode. We bind devices configured in /etc/network/interfaces
to their connections by updating wired/wireless setting with the
mac address of the device.
=== modified file 'ChangeLog'
--- a/ChangeLog 2008-10-07 20:50:35 +0000
+++ b/ChangeLog 2008-10-07 20:52:59 +0000
@@ -1,10 +1,25 @@
2008-10-07 Alexander Sack <asac ubuntu com>
+ Implement managed mode. We bind devices configured in /etc/network/interfaces
+ to their connections by updating wired/wireless setting with the
+ mac address of the device.
+ * system-settings/plugins/ifupdown/plugin.c
+ - (get_net_address_for_udi): implement function to retrieve MAC
+ address of udi from hal in GByteArray format
+ - (bind_device_to_connection): bind mac address of device to
+ wired/wireless system connection
+ - (hal_device_added_cb): call bind_device_to_connection for
+ system connections with a matching interface.name
+ - (hal_device_added_cb): ensure that all code paths
+ properly free the "iface" string.
+
+2008-10-07 Alexander Sack <asac ubuntu com>
+
Parse nm-system-settings.conf and allow admins to either use managed and unmanaged
mode of the ifupdown systen config plugin.
* system-settings/plugins/ifupdown/plugin.c
- (SCPluginIfupdown_init): parse nm-system-settings.conf keyfile and set
private unmanage_well_known state field accordingly
=== modified file 'system-settings/plugins/ifupdown/plugin.c'
--- a/system-settings/plugins/ifupdown/plugin.c 2008-10-07 20:50:35 +0000
+++ b/system-settings/plugins/ifupdown/plugin.c 2008-10-07 20:52:59 +0000
@@ -19,16 +19,19 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2007,2008 Canonical Ltd.
*/
#include <string.h>
#include <sys/inotify.h>
+#include <net/ethernet.h>
+#include <netinet/ether.h>
+
#include <gmodule.h>
#include <glib-object.h>
#include <glib/gi18n.h>
#include <glib/gslist.h>
#include <nm-setting-connection.h>
#include "interface_parser.h"
@@ -167,16 +170,51 @@ 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 GByteArray*
+get_net_address_for_udi (DBusGConnection *g_connection,
+ const gchar* udi,
+ GError **error)
+{
+ DBusGProxy *dev_proxy;
+ char *address = NULL;
+ GByteArray *mac_address = 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.address", G_TYPE_INVALID,
+ G_TYPE_STRING, &address, G_TYPE_INVALID)) {
+ goto out;
+ }
+
+ if (address && strlen (address)) {
+ struct ether_addr *dev_mac;
+ mac_address = g_byte_array_new();
+ dev_mac = ether_aton (address);
+ g_byte_array_append (mac_address, dev_mac->ether_addr_octet, ETH_ALEN);
+ }
+
+ out:
+ g_free(address);
+ g_object_unref (dev_proxy);
+ return mac_address;
+}
+
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,
@@ -193,54 +231,102 @@ get_iface_for_udi (DBusGConnection *g_co
g_object_unref (dev_proxy);
return iface;
}
g_object_unref (dev_proxy);
return NULL;
}
static void
+bind_device_to_connection (NMSystemConfigInterface *config,
+ DBusGConnection *g_connection,
+ const gchar* udi,
+ NMExportedConnection *exported_iface_connection)
+{
+ GByteArray *mac_address;
+ GError *error = NULL;
+ NMConnection *iface_connection;
+ NMSetting *wired_setting = NULL;
+ NMSetting *wireless_setting = NULL;
+
+ iface_connection = nm_exported_connection_get_connection (exported_iface_connection);
+ if (!iface_connection) {
+ nm_warning ("no device locking possible. NMExportedConnection doesnt have a real connection.");
+ return;
+ }
+
+ mac_address = get_net_address_for_udi (g_connection, udi, &error);
+
+ if(error) {
+ PLUGIN_PRINT ("SCPluginIfupdown", "getting mac address for managed device"
+ "failed: %s (%d)", error->message, error->code);
+ return;
+ }
+
+ wired_setting = nm_connection_get_setting (iface_connection,
+ NM_TYPE_SETTING_WIRED);
+ wireless_setting = nm_connection_get_setting (iface_connection,
+ NM_TYPE_SETTING_WIRELESS);
+ if (wired_setting) {
+ PLUGIN_PRINT ("SCPluginIfupdown", "locking wired connection setting");
+ g_object_set (wired_setting, NM_SETTING_WIRED_MAC_ADDRESS, mac_address, NULL);
+ } else if (wireless_setting) {
+ PLUGIN_PRINT ("SCPluginIfupdown", "locking wireless connection setting");
+ g_object_set (wireless_setting, NM_SETTING_WIRELESS_MAC_ADDRESS, mac_address, NULL);
+ }
+
+ if(mac_address)
+ g_byte_array_free (mac_address, TRUE);
+}
+
+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;
+ gchar *iface = NULL;
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;
+ goto out;
iface_connection = nm_exported_connection_get_connection (exported_iface_connection);
if(!iface_connection)
- return;
+ goto out;
g_hash_table_insert (priv->well_known_udis, (gpointer)udi, "nothing");
if (ALWAYS_UNMANAGE || priv->unmanage_well_known)
g_signal_emit_by_name (G_OBJECT(config), "unmanaged-devices-changed");
+ else
+ bind_device_to_connection (config, priv->g_connection, udi, exported_iface_connection);
+
+ out:
+ g_free (iface);
}
static void
hal_device_removed_cb (NMSystemConfigHalManager *hal_mgr,
const gchar* udi,
NMDeviceType devtype,
NMSystemConfigInterface *config)
{
- Alexander
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]