core: use ifindex instead of interface name in a lot of places
authorDan Williams <dcbw@redhat.com>
Wed, 21 Apr 2010 21:58:25 +0000 (14:58 -0700)
committerDan Williams <dcbw@redhat.com>
Wed, 21 Apr 2010 21:58:25 +0000 (14:58 -0700)
Where we can do so, let's use ifindex since that's actually unique
and doesn't change when the interface name changes.  We already use
ifindex in a bunch of places, and netlink *only* uses ifindex, so
this will make it easier later when we move over to ifindexes fully.

17 files changed:
marshallers/nm-marshal.list
src/ip6-manager/nm-ip6-manager.c
src/ip6-manager/nm-ip6-manager.h
src/nm-device-ethernet.c
src/nm-device-ethernet.h
src/nm-device-interface.c
src/nm-device-interface.h
src/nm-device-olpc-mesh.c
src/nm-device-olpc-mesh.h
src/nm-device-wifi.c
src/nm-device-wifi.h
src/nm-device.c
src/nm-device.h
src/nm-manager.c
src/nm-netlink-monitor.c
src/nm-system.c
src/nm-udev-manager.c

index e19f8be..359fbed 100644 (file)
@@ -15,8 +15,8 @@ VOID:POINTER,POINTER
 VOID:STRING,STRING,STRING,UINT
 VOID:OBJECT,UINT,UINT
 VOID:STRING,INT
-VOID:STRING,UINT
-VOID:STRING,UINT,BOOLEAN
+VOID:INT,UINT
+VOID:INT,UINT,BOOLEAN
 VOID:OBJECT,OBJECT,ENUM
 VOID:POINTER,STRING
 VOID:STRING,BOXED
index 50905c3..ddecf07 100644 (file)
@@ -42,7 +42,7 @@
 
 typedef struct {
        NMNetlinkMonitor *monitor;
-       GHashTable *devices_by_iface, *devices_by_index;
+       GHashTable *devices;
 
        struct nl_handle *nlh;
        struct nl_cache *addr_cache, *route_cache;
@@ -68,7 +68,7 @@ typedef struct {
 typedef struct {
        NMIP6Manager *manager;
        char *iface;
-       int index;
+       int ifindex;
 
        char *accept_ra_path;
        gboolean accept_ra_save_valid;
@@ -120,10 +120,9 @@ nm_ip6_manager_init (NMIP6Manager *manager)
 {
        NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
 
-       priv->devices_by_iface = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                                                                       NULL,
-                                                                                                       (GDestroyNotify) nm_ip6_device_destroy);
-       priv->devices_by_index = g_hash_table_new (NULL, NULL);
+       priv->devices = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+                                              NULL,
+                                              (GDestroyNotify) nm_ip6_device_destroy);
 
        priv->monitor = nm_netlink_monitor_get ();
        nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_IPV6_IFADDR, NULL);
@@ -144,8 +143,7 @@ finalize (GObject *object)
 {
        NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (object);
 
-       g_hash_table_destroy (priv->devices_by_iface);
-       g_hash_table_destroy (priv->devices_by_index);
+       g_hash_table_destroy (priv->devices);
        g_object_unref (priv->monitor);
        nl_cache_free (priv->addr_cache);
        nl_cache_free (priv->route_cache);
@@ -170,8 +168,8 @@ nm_ip6_manager_class_init (NMIP6ManagerClass *manager_class)
                                          G_SIGNAL_RUN_FIRST,
                                          G_STRUCT_OFFSET (NMIP6ManagerClass, addrconf_complete),
                                          NULL, NULL,
-                                         _nm_marshal_VOID__STRING_UINT_BOOLEAN,
-                                         G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_BOOLEAN);
+                                         _nm_marshal_VOID__INT_UINT_BOOLEAN,
+                                         G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_UINT, G_TYPE_BOOLEAN);
 
        signals[CONFIG_CHANGED] =
                g_signal_new ("config-changed",
@@ -179,8 +177,8 @@ nm_ip6_manager_class_init (NMIP6ManagerClass *manager_class)
                                          G_SIGNAL_RUN_FIRST,
                                          G_STRUCT_OFFSET (NMIP6ManagerClass, config_changed),
                                          NULL, NULL,
-                                         _nm_marshal_VOID__STRING_UINT,
-                                         G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_UINT);
+                                         _nm_marshal_VOID__INT_UINT,
+                                         G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_UINT);
 }
 
 static void
@@ -217,7 +215,7 @@ nm_ip6_manager_new (void)
        manager = g_object_new (NM_TYPE_IP6_MANAGER, NULL);
        priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
 
-       if (!priv->devices_by_iface || !priv->devices_by_index) {
+       if (!priv->devices) {
                nm_log_err (LOGD_IP6, "not enough memory to initialize IP6 manager tables");
                g_object_unref (manager);
                manager = NULL;
@@ -231,8 +229,7 @@ nm_ip6_manager_get_device (NMIP6Manager *manager, int ifindex)
 {
        NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
 
-       return g_hash_table_lookup (priv->devices_by_index,
-                                                               GINT_TO_POINTER (ifindex));
+       return g_hash_table_lookup (priv->devices, GINT_TO_POINTER (ifindex));
 }
 
 typedef struct {
@@ -246,25 +243,22 @@ finish_addrconf (gpointer user_data)
        CallbackInfo *info = user_data;
        NMIP6Device *device = info->device;
        NMIP6Manager *manager = device->manager;
-       char *iface_copy;
+       int ifindex;
 
        device->finish_addrconf_id = 0;
        device->addrconf_complete = TRUE;
+       ifindex = device->ifindex;
 
        if (device->state >= device->target_state) {
                g_signal_emit (manager, signals[ADDRCONF_COMPLETE], 0,
-                                          device->iface, info->dhcp_opts, TRUE);
+                                          ifindex, info->dhcp_opts, TRUE);
        } else {
                nm_log_info (LOGD_IP6, "(%s): IP6 addrconf timed out or failed.",
                                     device->iface);
 
-               iface_copy = g_strdup (device->iface);
-
-               nm_ip6_manager_cancel_addrconf (manager, device->iface);
+               nm_ip6_manager_cancel_addrconf (manager, ifindex);
                g_signal_emit (manager, signals[ADDRCONF_COMPLETE], 0,
-                                          iface_copy, info->dhcp_opts, FALSE);
-
-               g_free (iface_copy);
+                                          ifindex, info->dhcp_opts, FALSE);
        }
 
        return FALSE;
@@ -278,7 +272,7 @@ emit_config_changed (gpointer user_data)
        NMIP6Manager *manager = device->manager;
 
        device->config_changed_id = 0;
-       g_signal_emit (manager, signals[CONFIG_CHANGED], 0, device->iface, info->dhcp_opts);
+       g_signal_emit (manager, signals[CONFIG_CHANGED], 0, device->ifindex, info->dhcp_opts);
        return FALSE;
 }
 
@@ -359,7 +353,7 @@ nm_ip6_device_sync_from_netlink (NMIP6Device *device, gboolean config_changed)
        for (rtnladdr = (struct rtnl_addr *)nl_cache_get_first (priv->addr_cache);
                 rtnladdr;
                 rtnladdr = (struct rtnl_addr *)nl_cache_get_next ((struct nl_object *)rtnladdr)) {
-               if (rtnl_addr_get_ifindex (rtnladdr) != device->index)
+               if (rtnl_addr_get_ifindex (rtnladdr) != device->ifindex)
                        continue;
 
                nladdr = rtnl_addr_get_local (rtnladdr);
@@ -686,33 +680,36 @@ netlink_notification (NMNetlinkMonitor *monitor, struct nl_msg *msg, gpointer us
 }
 
 static NMIP6Device *
-nm_ip6_device_new (NMIP6Manager *manager, const char *iface)
+nm_ip6_device_new (NMIP6Manager *manager, int ifindex)
 {
        NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
        NMIP6Device *device;
        GError *error = NULL;
        char *contents = NULL;
 
+       g_return_val_if_fail (ifindex > 0, NULL);
+
        device = g_slice_new0 (NMIP6Device);
        if (!device) {
-               nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 addrconf object.", iface);
+               nm_log_err (LOGD_IP6, "(%d): out of memory creating IP6 addrconf object.",
+                           ifindex);
                return NULL;
        }
 
-       device->iface = g_strdup (iface);
+       device->ifindex = ifindex;
+       device->iface = g_strdup (nm_netlink_index_to_iface (ifindex));
        if (!device->iface) {
-               nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 addrconf object "
-                           "property 'iface'.",
-                           iface);
+               nm_log_err (LOGD_IP6, "(%d): could not find interface name from index.",
+                           ifindex);
                goto error;
        }
-       device->index = nm_netlink_iface_to_index (iface);
 
-       device->accept_ra_path = g_strdup_printf ("/proc/sys/net/ipv6/conf/%s/accept_ra", iface);
+       device->accept_ra_path = g_strdup_printf ("/proc/sys/net/ipv6/conf/%s/accept_ra",
+                                                 device->iface);
        if (!device->accept_ra_path) {
                nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 addrconf object "
                            "property 'accept_ra_path'.",
-                           iface);
+                           device->iface);
                goto error;
        }
 
@@ -720,15 +717,14 @@ nm_ip6_device_new (NMIP6Manager *manager, const char *iface)
 
        device->rdnss_servers = g_array_new (FALSE, FALSE, sizeof (NMIP6RDNSS));
 
-       g_hash_table_replace (priv->devices_by_iface, device->iface, device);
-       g_hash_table_replace (priv->devices_by_index, GINT_TO_POINTER (device->index), device);
+       g_hash_table_replace (priv->devices, GINT_TO_POINTER (device->ifindex), device);
 
        /* Grab the original value of "accept_ra" so we can restore it when the
         * device is taken down.
         */
        if (!g_file_get_contents (device->accept_ra_path, &contents, NULL, &error)) {
                nm_log_warn (LOGD_IP6, "(%s): error reading %s: (%d) %s",
-                            iface, device->accept_ra_path,
+                            device->iface, device->accept_ra_path,
                             error ? error->code : -1,
                             error && error->message ? error->message : "(unknown)");
                g_clear_error (&error);
@@ -753,7 +749,7 @@ error:
 
 void
 nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
-                                                                 const char *iface,
+                                                                 int ifindex,
                                                                  NMSettingIP6Config *s_ip6)
 {
        NMIP6ManagerPrivate *priv;
@@ -761,11 +757,11 @@ nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
        const char *method = NULL;
 
        g_return_if_fail (NM_IS_IP6_MANAGER (manager));
-       g_return_if_fail (iface != NULL);
+       g_return_if_fail (ifindex > 0);
 
        priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
 
-       device = nm_ip6_device_new (manager, iface);
+       device = nm_ip6_device_new (manager, ifindex);
 
        if (s_ip6)
                method = nm_setting_ip6_config_get_method (s_ip6);
@@ -778,9 +774,9 @@ nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
        else
                device->target_state = NM_IP6_DEVICE_GOT_ADDRESS;
 
-       g_return_if_fail (strchr (iface, '/') == NULL &&
-                                         strcmp (iface, "all") != 0 &&
-                                         strcmp (iface, "default") != 0);
+       g_return_if_fail (   strchr (device->iface, '/') == NULL
+                         && strcmp (device->iface, "all") != 0
+                         && strcmp (device->iface, "default") != 0);
 
        /* Turn router advertisement acceptance on or off... */
        nm_utils_do_sysctl (device->accept_ra_path,
@@ -788,22 +784,21 @@ nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
 }
 
 void
-nm_ip6_manager_begin_addrconf (NMIP6Manager *manager,
-                                                          const char *iface)
+nm_ip6_manager_begin_addrconf (NMIP6Manager *manager, int ifindex)
 {
        NMIP6ManagerPrivate *priv;
        NMIP6Device *device;
        CallbackInfo *info;
 
        g_return_if_fail (NM_IS_IP6_MANAGER (manager));
-       g_return_if_fail (iface != NULL);
+       g_return_if_fail (ifindex > 0);
 
        priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
 
-       device = (NMIP6Device *) g_hash_table_lookup (priv->devices_by_iface, iface);
+       device = (NMIP6Device *) g_hash_table_lookup (priv->devices, GINT_TO_POINTER (ifindex));
        g_return_if_fail (device != NULL);
 
-       nm_log_info (LOGD_IP6, "Activation (%s) Beginning IP6 addrconf.", iface);
+       nm_log_info (LOGD_IP6, "Activation (%s) Beginning IP6 addrconf.", device->iface);
 
        device->addrconf_complete = FALSE;
        device->ra_flags = 0;
@@ -825,27 +820,17 @@ nm_ip6_manager_begin_addrconf (NMIP6Manager *manager,
 }
 
 void
-nm_ip6_manager_cancel_addrconf (NMIP6Manager *manager,
-                                                               const char *iface)
+nm_ip6_manager_cancel_addrconf (NMIP6Manager *manager, int ifindex)
 {
-       NMIP6ManagerPrivate *priv;
-       NMIP6Device *device;
-
        g_return_if_fail (NM_IS_IP6_MANAGER (manager));
-       g_return_if_fail (iface != NULL);
+       g_return_if_fail (ifindex > 0);
 
-       priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
-
-       device = g_hash_table_lookup (priv->devices_by_iface, iface);
-       if (device) {
-               g_hash_table_remove (priv->devices_by_index, GINT_TO_POINTER (device->index));
-               g_hash_table_remove (priv->devices_by_iface, iface);
-       }
+       g_hash_table_remove (NM_IP6_MANAGER_GET_PRIVATE (manager)->devices,
+                            GINT_TO_POINTER (ifindex));
 }
 
 NMIP6Config *
-nm_ip6_manager_get_ip6_config (NMIP6Manager *manager,
-                                                          const char *iface)
+nm_ip6_manager_get_ip6_config (NMIP6Manager *manager, int ifindex)
 {
        NMIP6ManagerPrivate *priv;
        NMIP6Device *device;
@@ -862,20 +847,21 @@ nm_ip6_manager_get_ip6_config (NMIP6Manager *manager,
        int i;
 
        g_return_val_if_fail (NM_IS_IP6_MANAGER (manager), NULL);
-       g_return_val_if_fail (iface != NULL, NULL);
+       g_return_val_if_fail (ifindex > 0, NULL);
 
        priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
 
-       device = (NMIP6Device *) g_hash_table_lookup (priv->devices_by_iface, iface);
+       device = (NMIP6Device *) g_hash_table_lookup (priv->devices,
+                                                     GINT_TO_POINTER (ifindex));
        if (!device) {
-               nm_log_warn (LOGD_IP6, "(%s): addrconf not started.", iface);
+               nm_log_warn (LOGD_IP6, "(%d): addrconf not started.", ifindex);
                return NULL;
        }
 
        config = nm_ip6_config_new ();
        if (!config) {
                nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 config object.",
-                           iface);
+                           device->iface);
                return NULL;
        }
 
@@ -883,7 +869,7 @@ nm_ip6_manager_get_ip6_config (NMIP6Manager *manager,
        for (rtnladdr = (struct rtnl_addr *)nl_cache_get_first (priv->addr_cache);
                 rtnladdr;
                 rtnladdr = (struct rtnl_addr *)nl_cache_get_next ((struct nl_object *)rtnladdr)) {
-               if (rtnl_addr_get_ifindex (rtnladdr) != device->index)
+               if (rtnl_addr_get_ifindex (rtnladdr) != device->ifindex)
                        continue;
 
                nladdr = rtnl_addr_get_local (rtnladdr);
@@ -901,7 +887,7 @@ nm_ip6_manager_get_ip6_config (NMIP6Manager *manager,
        for (rtnlroute = (struct rtnl_route *)nl_cache_get_first (priv->route_cache);
                 rtnlroute;
                 rtnlroute = (struct rtnl_route *)nl_cache_get_next ((struct nl_object *)rtnlroute)) {
-               if (rtnl_route_get_oif (rtnlroute) != device->index)
+               if (rtnl_route_get_oif (rtnlroute) != device->ifindex)
                        continue;
 
                nldest = rtnl_route_get_dst (rtnlroute);
index d0cf4b0..db92066 100644 (file)
@@ -15,7 +15,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright (C) 2009 Red Hat, Inc.
+ * Copyright (C) 2009 - 2010 Red Hat, Inc.
  */
 
 #ifndef NM_IP6_MANAGER_H
@@ -54,7 +54,7 @@ typedef struct {
         * that the initial configuration is complete.
         */
        void (*addrconf_complete) (NMIP6Manager *manager,
-                                  char *iface,
+                                  guint32 ifindex,
                                   guint dhcp_opts,
                                   gboolean success);
 
@@ -63,22 +63,22 @@ typedef struct {
         * of the interface has changed.
         */
        void (*config_changed)    (NMIP6Manager *manager,
-                                  char *iface,
+                                  guint32 ifindex,
                                   guint dhcp_opts);
 } NMIP6ManagerClass;
 
 GType nm_ip6_manager_get_type (void);
 
-NMIP6Manager *nm_ip6_manager_get                  (void);
-void          nm_ip6_manager_prepare_interface    (NMIP6Manager *manager,
-                                                                                                  const char *iface,
-                                                                                                  NMSettingIP6Config *s_ip6);
-void          nm_ip6_manager_begin_addrconf       (NMIP6Manager *manager,
-                                                                                                  const char *iface);
-void          nm_ip6_manager_cancel_addrconf      (NMIP6Manager *manager,
-                                                                                                  const char *iface);
+NMIP6Manager *nm_ip6_manager_get               (void);
+void          nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
+                                                int ifindex,
+                                                NMSettingIP6Config *s_ip6);
+void          nm_ip6_manager_begin_addrconf    (NMIP6Manager *manager,
+                                                int ifindex);
+void          nm_ip6_manager_cancel_addrconf   (NMIP6Manager *manager,
+                                                int ifindex);
 
-NMIP6Config * nm_ip6_manager_get_ip6_config       (NMIP6Manager *manager,
-                                                                                                  const char *iface);
+NMIP6Config * nm_ip6_manager_get_ip6_config    (NMIP6Manager *manager,
+                                                int ifindex);
 
 #endif /* NM_IP6_MANAGER_H */
index 202584b..be6d4e2 100644 (file)
@@ -106,7 +106,6 @@ typedef struct {
 
        struct ether_addr       hw_addr;
        gboolean                        carrier;
-       guint32                         ifindex;
 
        NMNetlinkMonitor *  monitor;
        gulong              link_connected_id;
@@ -134,7 +133,6 @@ enum {
        PROP_HW_ADDRESS,
        PROP_SPEED,
        PROP_CARRIER,
-       PROP_IFINDEX,
 
        LAST_PROP
 };
@@ -247,11 +245,10 @@ carrier_on (NMNetlinkMonitor *monitor,
 {
        NMDevice *device = NM_DEVICE (user_data);
        NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
-       NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
        guint32 caps;
 
        /* Make sure signal is for us */
-       if (idx == priv->ifindex) {
+       if (idx == nm_device_get_ifindex (device)) {
                /* Ignore spurious netlink messages */
                caps = nm_device_get_capabilities (device);
                if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
@@ -268,11 +265,10 @@ carrier_off (NMNetlinkMonitor *monitor,
 {
        NMDevice *device = NM_DEVICE (user_data);
        NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
-       NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
        guint32 caps;
 
        /* Make sure signal is for us */
-       if (idx == priv->ifindex) {
+       if (idx == nm_device_get_ifindex (device)) {
                NMDeviceState state;
                gboolean defer = FALSE;
 
@@ -313,7 +309,8 @@ constructor (GType type,
        priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
 
        nm_log_dbg (LOGD_HW | LOGD_OLPC_MESH, "(%s): kernel ifindex %d",
-                   nm_device_get_iface (NM_DEVICE (self)), priv->ifindex);
+                   nm_device_get_iface (NM_DEVICE (self)),
+                   nm_device_get_ifindex (NM_DEVICE (self)));
 
        caps = nm_device_get_capabilities (self);
        if (caps & NM_DEVICE_CAP_CARRIER_DETECT) {
@@ -332,7 +329,7 @@ constructor (GType type,
 
                /* Get initial link state */
                if (!nm_netlink_monitor_get_flags_sync (priv->monitor,
-                                                       priv->ifindex,
+                                                       nm_device_get_ifindex (NM_DEVICE (self)),
                                                        &ifflags,
                                                        &error)) {
                        nm_log_warn (LOGD_HW | LOGD_ETHER,
@@ -427,8 +424,7 @@ real_hw_take_down (NMDevice *dev)
 NMDevice *
 nm_device_ethernet_new (const char *udi,
                                                const char *iface,
-                                               const char *driver,
-                                               guint32 ifindex)
+                                               const char *driver)
 {
        g_return_val_if_fail (udi != NULL, NULL);
        g_return_val_if_fail (iface != NULL, NULL);
@@ -438,7 +434,6 @@ nm_device_ethernet_new (const char *udi,
                                          NM_DEVICE_INTERFACE_UDI, udi,
                                          NM_DEVICE_INTERFACE_IFACE, iface,
                                          NM_DEVICE_INTERFACE_DRIVER, driver,
-                                         NM_DEVICE_ETHERNET_IFINDEX, ifindex,
                                          NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet",
                                          NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
                                          NULL);
@@ -460,14 +455,6 @@ nm_device_ethernet_get_address (NMDeviceEthernet *self, struct ether_addr *addr)
        memcpy (addr, &(NM_DEVICE_ETHERNET_GET_PRIVATE (self)->hw_addr), sizeof (struct ether_addr));
 }
 
-guint32
-nm_device_ethernet_get_ifindex (NMDeviceEthernet *self)
-{
-       g_return_val_if_fail (self != NULL, FALSE);
-
-       return NM_DEVICE_ETHERNET_GET_PRIVATE (self)->ifindex;
-}
-
 /* Returns speed in Mb/s */
 static guint32
 nm_device_ethernet_get_speed (NMDeviceEthernet *self)
@@ -1619,7 +1606,7 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
        int ifindex;
        AddrData check_data;
 
-       ifindex = nm_device_ethernet_get_ifindex (NM_DEVICE_ETHERNET (self));
+       ifindex = nm_device_get_ifindex (self);
 
        s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
        g_assert (s_con);
@@ -1791,9 +1778,6 @@ get_property (GObject *object, guint prop_id,
        case PROP_CARRIER:
                g_value_set_boolean (value, priv->carrier);
                break;
-       case PROP_IFINDEX:
-               g_value_set_uint (value, priv->ifindex);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -1804,13 +1788,7 @@ static void
 set_property (GObject *object, guint prop_id,
                          const GValue *value, GParamSpec *pspec)
 {
-       NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object);
-
        switch (prop_id) {
-       case PROP_IFINDEX:
-               /* construct-only */
-               priv->ifindex = g_value_get_uint (value);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -1877,14 +1855,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
                                                           FALSE,
                                                           G_PARAM_READABLE));
 
-       g_object_class_install_property
-               (object_class, PROP_IFINDEX,
-                g_param_spec_uint (NM_DEVICE_ETHERNET_IFINDEX,
-                                                  "Ifindex",
-                                                  "Interface index",
-                                                  0, G_MAXUINT32, 0,
-                                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
-
        /* Signals */
        signals[PROPERTIES_CHANGED] = 
                nm_properties_changed_signal_new (object_class,
index 643572f..7bb3db0 100644 (file)
@@ -39,7 +39,6 @@ G_BEGIN_DECLS
 #define NM_DEVICE_ETHERNET_HW_ADDRESS "hw-address"
 #define NM_DEVICE_ETHERNET_SPEED "speed"
 #define NM_DEVICE_ETHERNET_CARRIER "carrier"
-#define NM_DEVICE_ETHERNET_IFINDEX "ifindex"
 
 typedef struct {
        NMDevice parent;
@@ -58,14 +57,11 @@ GType nm_device_ethernet_get_type (void);
 
 NMDevice *nm_device_ethernet_new (const char *udi,
                                   const char *iface,
-                                  const char *driver,
-                                  guint32 ifindex);
+                                  const char *driver);
 
 void nm_device_ethernet_get_address (NMDeviceEthernet *dev,
                                      struct ether_addr *addr);
 
-guint32 nm_device_ethernet_get_ifindex (NMDeviceEthernet *dev);
-
 G_END_DECLS
 
 #endif /* NM_DEVICE_ETHERNET_H */
index 4040626..85f58d5 100644 (file)
@@ -16,7 +16,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Copyright (C) 2007 - 2008 Novell, Inc.
- * Copyright (C) 2007 - 2008 Red Hat, Inc.
+ * Copyright (C) 2007 - 2010 Red Hat, Inc.
  */
 
 #include "nm-marshal.h"
@@ -186,6 +186,14 @@ nm_device_interface_init (gpointer g_iface)
                                         RFKILL_TYPE_UNKNOWN,
                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
 
+       g_object_interface_install_property
+               (g_iface,
+                g_param_spec_int (NM_DEVICE_INTERFACE_IFINDEX,
+                                                       "Ifindex",
+                                                       "Ifindex",
+                                                       0, G_MAXINT, 0,
+                                                       G_PARAM_READABLE | NM_PROPERTY_PARAM_NO_EXPORT));
+
        /* Signals */
        g_signal_new ("state-changed",
                                  iface_type,
index adbafca..ec27f6e 100644 (file)
@@ -57,8 +57,9 @@ typedef enum
 #define NM_DEVICE_INTERFACE_STATE        "state"
 #define NM_DEVICE_INTERFACE_DEVICE_TYPE  "device-type" /* ugh */
 #define NM_DEVICE_INTERFACE_MANAGED      "managed"
-#define NM_DEVICE_INTERFACE_TYPE_DESC    "type-desc"  /* Internal only */
+#define NM_DEVICE_INTERFACE_TYPE_DESC    "type-desc"    /* Internal only */
 #define NM_DEVICE_INTERFACE_RFKILL_TYPE  "rfkill-type"  /* Internal only */
+#define NM_DEVICE_INTERFACE_IFINDEX      "ifindex"      /* Internal only */
 
 typedef enum {
        NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000,
@@ -77,6 +78,7 @@ typedef enum {
        NM_DEVICE_INTERFACE_PROP_MANAGED,
        NM_DEVICE_INTERFACE_PROP_TYPE_DESC,
        NM_DEVICE_INTERFACE_PROP_RFKILL_TYPE,
+       NM_DEVICE_INTERFACE_PROP_IFINDEX,
 } NMDeviceInterfaceProp;
 
 
index 2093a8e..f73108a 100644 (file)
@@ -69,7 +69,6 @@ enum {
        PROP_HW_ADDRESS,
        PROP_COMPANION,
        PROP_ACTIVE_CHANNEL,
-       PROP_IFINDEX,
 
        LAST_PROP
 };
@@ -98,7 +97,6 @@ struct _NMDeviceOlpcMeshPrivate
        gboolean          dispose_has_run;
 
        struct ether_addr hw_addr;
-       guint32           ifindex;
 
        GByteArray *      ssid;
 
@@ -263,7 +261,8 @@ constructor (GType type,
        priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
 
        nm_log_dbg (LOGD_HW | LOGD_OLPC_MESH, "(%s): kernel ifindex %d",
-                   nm_device_get_iface (NM_DEVICE (self)), priv->ifindex);
+                   nm_device_get_iface (NM_DEVICE (self)),
+                   nm_device_get_ifindex (NM_DEVICE (self)));
 
        iface = nm_device_get_iface (NM_DEVICE (self));
        fd = socket (PF_INET, SOCK_DGRAM, 0);
@@ -539,15 +538,6 @@ nm_device_olpc_mesh_set_ssid (NMDeviceOlpcMesh *self, const GByteArray * ssid)
        close (sk);
 }
 
-
-guint32
-nm_device_olpc_mesh_get_ifindex (NMDeviceOlpcMesh *self)
-{
-       g_return_val_if_fail (self != NULL, FALSE);
-
-       return NM_DEVICE_OLPC_MESH_GET_PRIVATE (self)->ifindex;
-}
-
 /****************************************************************************/
 
 static void
@@ -701,9 +691,6 @@ get_property (GObject *object, guint prop_id,
        case PROP_ACTIVE_CHANNEL:
                g_value_set_uint (value, nm_device_olpc_mesh_get_channel (device));
                break;
-       case PROP_IFINDEX:
-               g_value_set_uint (value, nm_device_olpc_mesh_get_ifindex (device));
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -714,13 +701,7 @@ static void
 set_property (GObject *object, guint prop_id,
               const GValue *value, GParamSpec *pspec)
 {
-       NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
-
        switch (prop_id) {
-       case PROP_IFINDEX:
-               /* construct-only */
-               priv->ifindex = g_value_get_uint (value);
-               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -780,13 +761,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
                                   0, G_MAXUINT32, 0,
                                   G_PARAM_READABLE));
 
-       g_object_class_install_property (object_class, PROP_IFINDEX,
-               g_param_spec_uint (NM_DEVICE_OLPC_MESH_IFINDEX,
-                                  "Ifindex",
-                                  "Interface index",
-                                  0, G_MAXUINT32, 0,
-                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
        signals[PROPERTIES_CHANGED] =
                nm_properties_changed_signal_new (object_class,
                                                  G_STRUCT_OFFSET (NMDeviceOlpcMeshClass, properties_changed));
@@ -986,8 +960,7 @@ state_changed_cb (NMDevice *device, NMDeviceState state, gpointer user_data)
 NMDevice *
 nm_device_olpc_mesh_new (const char *udi,
                          const char *iface,
-                         const char *driver,
-                         guint32 ifindex)
+                         const char *driver)
 {
        GObject *obj;
 
@@ -999,7 +972,6 @@ nm_device_olpc_mesh_new (const char *udi,
                            NM_DEVICE_INTERFACE_UDI, udi,
                            NM_DEVICE_INTERFACE_IFACE, iface,
                            NM_DEVICE_INTERFACE_DRIVER, driver,
-                           NM_DEVICE_OLPC_MESH_IFINDEX, ifindex,
                            NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 OLPC Mesh",
                            NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_OLPC_MESH,
                            NULL);
index adf3d2d..bcc03e5 100644 (file)
@@ -46,7 +46,6 @@ G_BEGIN_DECLS
 #define NM_DEVICE_OLPC_MESH_COMPANION      "companion"
 #define NM_DEVICE_OLPC_MESH_BITRATE        "bitrate"
 #define NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL "active-channel"
-#define NM_DEVICE_OLPC_MESH_IFINDEX        "ifindex"
 
 #ifndef NM_DEVICE_OLPC_MESH_DEFINED
 #define NM_DEVICE_OLPC_MESH_DEFINED
@@ -75,10 +74,7 @@ GType nm_device_olpc_mesh_get_type (void);
 
 NMDevice *nm_device_olpc_mesh_new (const char *udi,
                                    const char *iface,
-                                   const char *driver,
-                                   guint32 ifindex);
-
-guint32 nm_device_olpc_mesh_get_ifindex (NMDeviceOlpcMesh *self);
+                                   const char *driver);
 
 G_END_DECLS
 
index cccaf11..b598f2b 100644 (file)
@@ -82,7 +82,6 @@ enum {
        PROP_BITRATE,
        PROP_ACTIVE_ACCESS_POINT,
        PROP_CAPABILITIES,
-       PROP_IFINDEX,
        PROP_SCANNING,
        PROP_IPW_RFKILL_STATE,
 
@@ -144,7 +143,6 @@ struct _NMDeviceWifiPrivate {
        gboolean          disposed;
 
        struct ether_addr hw_addr;
-       guint32           ifindex;
 
        /* Legacy rfkill for ipw2x00; will be fixed with 2.6.33 kernel */
        char *            ipw_rfkill_path;
@@ -579,7 +577,8 @@ constructor (GType type,
        priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
 
        nm_log_dbg (LOGD_HW | LOGD_WIFI, "(%s): kernel ifindex %d",
-                   nm_device_get_iface (NM_DEVICE (self)), priv->ifindex);
+                   nm_device_get_iface (NM_DEVICE (self)),
+                   nm_device_get_ifindex (NM_DEVICE (self)));
 
        memset (&range, 0, sizeof (struct iw_range));
        success = wireless_get_range (NM_DEVICE_WIFI (object), &range, &response_len);
@@ -3462,14 +3461,6 @@ device_state_changed (NMDevice *device,
                remove_all_aps (self);
 }
 
-guint32
-nm_device_wifi_get_ifindex (NMDeviceWifi *self)
-{
-       g_return_val_if_fail (self != NULL, FALSE);
-
-       return NM_DEVICE_WIFI_GET_PRIVATE (self)->ifindex;
-}
-
 NMAccessPoint *
 nm_device_wifi_get_activation_ap (NMDeviceWifi *self)
 {
@@ -3563,8 +3554,7 @@ real_set_enabled (NMDeviceInterface *device, gboolean enabled)
 NMDevice *
 nm_device_wifi_new (const char *udi,
                     const char *iface,
-                    const char *driver,
-                    guint32 ifindex)
+                    const char *driver)
 {
        g_return_val_if_fail (udi != NULL, NULL);
        g_return_val_if_fail (iface != NULL, NULL);
@@ -3574,7 +3564,6 @@ nm_device_wifi_new (const char *udi,
                                          NM_DEVICE_INTERFACE_UDI, udi,
                                          NM_DEVICE_INTERFACE_IFACE, iface,
                                          NM_DEVICE_INTERFACE_DRIVER, driver,
-                                         NM_DEVICE_WIFI_IFINDEX, ifindex,
                                          NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 WiFi",
                                          NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI,
                                          NM_DEVICE_INTERFACE_RFKILL_TYPE, RFKILL_TYPE_WLAN,
@@ -3675,9 +3664,6 @@ get_property (GObject *object, guint prop_id,
                else
                        g_value_set_boxed (value, "/");
                break;
-       case PROP_IFINDEX:
-               g_value_set_uint (value, nm_device_wifi_get_ifindex (device));
-               break;
        case PROP_SCANNING:
                g_value_set_boolean (value, nm_supplicant_interface_get_scanning (priv->supplicant.iface));
                break;
@@ -3697,10 +3683,6 @@ set_property (GObject *object, guint prop_id,
        NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
 
        switch (prop_id) {
-       case PROP_IFINDEX:
-               /* construct-only */
-               priv->ifindex = g_value_get_uint (value);
-               break;
        case PROP_IPW_RFKILL_STATE:
                /* construct only */
                priv->ipw_rfkill_state = g_value_get_uint (value);
@@ -3788,13 +3770,6 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
                                   0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE,
                                   G_PARAM_READABLE));
 
-       g_object_class_install_property (object_class, PROP_IFINDEX,
-               g_param_spec_uint (NM_DEVICE_WIFI_IFINDEX,
-                                  "Ifindex",
-                                  "Interface index",
-                                  0, G_MAXUINT32, 0,
-                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT));
-
        g_object_class_install_property (object_class, PROP_SCANNING,
                g_param_spec_boolean (NM_DEVICE_WIFI_SCANNING,
                                   "Scanning",
index 45b573a..11ac885 100644 (file)
@@ -47,7 +47,6 @@ G_BEGIN_DECLS
 #define NM_DEVICE_WIFI_BITRATE             "bitrate"
 #define NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT "active-access-point"
 #define NM_DEVICE_WIFI_CAPABILITIES        "wireless-capabilities"
-#define NM_DEVICE_WIFI_IFINDEX             "ifindex"
 #define NM_DEVICE_WIFI_SCANNING            "scanning"
 #define NM_DEVICE_WIFI_IPW_RFKILL_STATE    "ipw-rfkill-state"
 
@@ -84,8 +83,7 @@ GType nm_device_wifi_get_type (void);
 
 NMDevice *nm_device_wifi_new (const char *udi,
                               const char *iface,
-                              const char *driver,
-                              guint32 ifindex);
+                              const char *driver);
 
 void nm_device_wifi_get_address (NMDeviceWifi *dev,
                                                                   struct ether_addr *addr);
@@ -102,8 +100,6 @@ NM80211Mode nm_device_wifi_get_mode (NMDeviceWifi *self);
 
 NMAccessPoint * nm_device_wifi_get_activation_ap (NMDeviceWifi *self);
 
-guint32 nm_device_wifi_get_ifindex (NMDeviceWifi *self);
-
 RfKillState nm_device_wifi_get_ipw_rfkill_state (NMDeviceWifi *self);
 
 G_END_DECLS
index db0ad91..b285baa 100644 (file)
@@ -83,7 +83,9 @@ typedef struct {
        char *        udi;
        char *        path;
        char *        iface;   /* may change, could be renamed by user */
+       int           ifindex;
        char *        ip_iface;
+       int           ip_ifindex;
        NMDeviceType  type;
        char *        type_desc;
        guint32       capabilities;
@@ -304,6 +306,13 @@ nm_device_get_iface (NMDevice *self)
        return NM_DEVICE_GET_PRIVATE (self)->iface;
 }
 
+int
+nm_device_get_ifindex (NMDevice *self)
+{
+       g_return_val_if_fail (self != NULL, 0);
+
+       return NM_DEVICE_GET_PRIVATE (self)->ifindex;
+}
 
 const char *
 nm_device_get_ip_iface (NMDevice *self)
@@ -317,14 +326,36 @@ nm_device_get_ip_iface (NMDevice *self)
        return priv->ip_iface ? priv->ip_iface : priv->iface;
 }
 
+int
+nm_device_get_ip_ifindex (NMDevice *self)
+{
+       NMDevicePrivate *priv;
+
+       g_return_val_if_fail (self != NULL, 0);
+
+       priv = NM_DEVICE_GET_PRIVATE (self);
+       /* If it's not set, default to iface */
+       return priv->ip_iface ? priv->ip_ifindex : priv->ifindex;
+}
 
 void
 nm_device_set_ip_iface (NMDevice *self, const char *iface)
 {
+       NMDevicePrivate *priv;
+
        g_return_if_fail (NM_IS_DEVICE (self));
 
-       g_free (NM_DEVICE_GET_PRIVATE (self)->ip_iface);
-       NM_DEVICE_GET_PRIVATE (self)->ip_iface = iface ? g_strdup (iface) : NULL;
+       priv = NM_DEVICE_GET_PRIVATE (self);
+       g_free (priv->ip_iface);
+       priv->ip_ifindex = 0;
+
+       priv->ip_iface = g_strdup (iface);
+       if (priv->ip_iface) {
+               priv->ip_ifindex = nm_netlink_iface_to_index (priv->ip_iface);
+               if (!priv->ip_ifindex) {
+                       nm_log_warn (LOGD_HW, "(%s): failed to look up interface index", iface);
+               }
+       }
 }
 
 
@@ -545,7 +576,7 @@ activation_source_schedule (NMDevice *self, GSourceFunc func, int family)
 
 static void
 ip6_addrconf_complete (NMIP6Manager *ip6_manager,
-                       const char *iface,
+                       int ifindex,
                        guint dhcp_opts,
                        gboolean success,
                        gpointer user_data)
@@ -558,7 +589,7 @@ ip6_addrconf_complete (NMIP6Manager *ip6_manager,
        NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
        NMDeviceState state;
 
-       if (strcmp (nm_device_get_ip_iface (self), iface) != 0)
+       if (ifindex != nm_device_get_ip_ifindex (self))
                return;
        req = nm_device_get_act_request (self);
        if (!req)
@@ -614,13 +645,13 @@ ip6_addrconf_complete (NMIP6Manager *ip6_manager,
 
 static void
 ip6_config_changed (NMIP6Manager *ip6_manager,
-                    const char *iface,
+                    int ifindex,
                     guint dhcp_opts,
                     gpointer user_data)
 {
        NMDevice *self = NM_DEVICE (user_data);
 
-       if (strcmp (nm_device_get_ip_iface (self), iface) != 0)
+       if (ifindex != nm_device_get_ip_ifindex (self))
                return;
        if (!nm_device_get_act_request (self))
                return;
@@ -675,7 +706,9 @@ addrconf6_setup (NMDevice *self)
 
        ip_iface = nm_device_get_ip_iface (self);
        s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
-       nm_ip6_manager_prepare_interface (priv->ip6_manager, ip_iface, s_ip6);
+       nm_ip6_manager_prepare_interface (priv->ip6_manager,
+                                         nm_device_get_ip_ifindex (self),
+                                         s_ip6);
 }
 
 static void
@@ -1481,7 +1514,7 @@ real_act_stage3_ip6_config_start (NMDevice *self, NMDeviceStateReason *reason)
 
        if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) {
                priv->ip6_waiting_for_config = TRUE;
-               nm_ip6_manager_begin_addrconf (priv->ip6_manager, ip_iface);
+               nm_ip6_manager_begin_addrconf (priv->ip6_manager, nm_device_get_ip_ifindex (self));
                ret = NM_ACT_STAGE_RETURN_POSTPONE;
        } else if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_DHCP))
                ret = dhcp6_start (self, connection, IP6_DHCP_OPT_MANAGED, reason);
@@ -1867,7 +1900,8 @@ real_act_stage4_get_ip6_config (NMDevice *self,
        s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
 
        if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) {
-               *config = nm_ip6_manager_get_ip6_config (priv->ip6_manager, ip_iface);
+               *config = nm_ip6_manager_get_ip6_config (priv->ip6_manager,
+                                                        nm_device_get_ip_ifindex (self));
                if (*config) {
                        /* Merge user-defined overrides into the IP6Config to be applied */
                        nm_utils_merge_ip6_config (*config, s_ip6);
@@ -3089,7 +3123,14 @@ set_property (GObject *object, guint prop_id,
                break;
        case NM_DEVICE_INTERFACE_PROP_IFACE:
                g_free (priv->iface);
+               priv->ifindex = 0;
                priv->iface = g_value_dup_string (value);
+               if (priv->iface) {
+                       priv->ifindex = nm_netlink_iface_to_index (priv->iface);
+                       if (priv->ifindex < 0) {
+                               nm_log_warn (LOGD_HW, "(%s): failed to look up interface index", priv->iface);
+                       }
+               }
                break;
        case NM_DEVICE_INTERFACE_PROP_DRIVER:
                priv->driver = g_strdup (g_value_get_string (value));
@@ -3137,6 +3178,9 @@ get_property (GObject *object, guint prop_id,
        case NM_DEVICE_INTERFACE_PROP_IFACE:
                g_value_set_string (value, priv->iface);
                break;
+       case NM_DEVICE_INTERFACE_PROP_IFINDEX:
+               g_value_set_int (value, priv->ifindex);
+               break;
        case NM_DEVICE_INTERFACE_PROP_DRIVER:
                g_value_set_string (value, priv->driver);
                break;
@@ -3236,6 +3280,10 @@ nm_device_class_init (NMDeviceClass *klass)
                                                                          NM_DEVICE_INTERFACE_IFACE);
 
        g_object_class_override_property (object_class,
+                                         NM_DEVICE_INTERFACE_PROP_IFINDEX,
+                                         NM_DEVICE_INTERFACE_IFINDEX);
+
+       g_object_class_override_property (object_class,
                                                                          NM_DEVICE_INTERFACE_PROP_DRIVER,
                                                                          NM_DEVICE_INTERFACE_DRIVER);
 
index 5fcde5c..ffeca42 100644 (file)
@@ -128,7 +128,9 @@ void            nm_device_set_path (NMDevice *dev, const char *path);
 
 const char *   nm_device_get_udi               (NMDevice *dev);
 const char *   nm_device_get_iface             (NMDevice *dev);
+int             nm_device_get_ifindex  (NMDevice *dev);
 const char *   nm_device_get_ip_iface  (NMDevice *dev);
+int             nm_device_get_ip_ifindex(NMDevice *dev);
 const char *   nm_device_get_driver    (NMDevice *dev);
 const char *   nm_device_get_type_desc (NMDevice *dev);
 
index a24606a..e42452c 100644 (file)
@@ -1523,7 +1523,8 @@ add_device (NMManager *self, NMDevice *device)
        driver = nm_device_get_driver (device);
        if (!driver)
                driver = "unknown";
-       nm_log_info (LOGD_HW, "(%s): new %s device (driver: '%s')", iface, type_desc, driver);
+       nm_log_info (LOGD_HW, "(%s): new %s device (driver: '%s' ifindex: %d)",
+                    iface, type_desc, driver, nm_device_get_ifindex (device));
 
        path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
        nm_device_set_path (device, path);
@@ -1794,20 +1795,11 @@ find_device_by_ifindex (NMManager *self, guint32 ifindex)
        GSList *iter;
 
        for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
-               NMDevice *device = NM_DEVICE (iter->data);
-               gint candidate_idx = 0;
-
-               if (NM_IS_DEVICE_ETHERNET (device))
-                       candidate_idx = nm_device_ethernet_get_ifindex (NM_DEVICE_ETHERNET (device));
-               else if (NM_IS_DEVICE_WIFI (device))
-                       candidate_idx = nm_device_wifi_get_ifindex (NM_DEVICE_WIFI (device));
-               else if (NM_IS_DEVICE_OLPC_MESH (device))
-                       candidate_idx = nm_device_olpc_mesh_get_ifindex (NM_DEVICE_OLPC_MESH (device));
+               NMDevice *candidate = NM_DEVICE (iter->data);
 
-               if (candidate_idx == ifindex)
-                       return device;
+               if (ifindex == nm_device_get_ifindex (candidate))
+                       return candidate;
        }
-
        return NULL;
 }
 
index 6fb13ef..10bf239 100644 (file)
@@ -743,7 +743,8 @@ nm_netlink_index_to_rtnl_link (int idx)
        NMNetlinkMonitorPrivate *priv;
        struct rtnl_link *ret = NULL;
 
-       g_return_val_if_fail (idx >= 0, NULL);
+       if (idx <= 0)
+               return NULL;
 
        self = nm_netlink_monitor_get ();
        priv = NM_NETLINK_MONITOR_GET_PRIVATE (self);
index 0d38ea6..2e03c41 100644 (file)
@@ -986,7 +986,7 @@ foreach_route (void (*callback)(struct nl_object *, gpointer),
 
        nlh = nm_netlink_get_default_handle ();
        route_cache = rtnl_route_alloc_cache (nlh);
-       nl_cache_mngt_provide (route_cache);
+       g_assert (route_cache);
        nl_cache_foreach (route_cache, callback, user_data);
        nl_cache_free (route_cache);
 }
index 0ced962..3481d88 100644 (file)
@@ -384,11 +384,11 @@ device_creator (NMUdevManager *manager,
        }
 
        if (is_olpc_mesh (udev_device)) /* must be before is_wireless */
-               device = (GObject *) nm_device_olpc_mesh_new (path, ifname, driver, ifindex);
+               device = (GObject *) nm_device_olpc_mesh_new (path, ifname, driver);
        else if (is_wireless (udev_device))
-               device = (GObject *) nm_device_wifi_new (path, ifname, driver, ifindex);
+               device = (GObject *) nm_device_wifi_new (path, ifname, driver);
        else
-               device = (GObject *) nm_device_ethernet_new (path, ifname, driver, ifindex);
+               device = (GObject *) nm_device_ethernet_new (path, ifname, driver);
 
 out:
        if (grandparent)