core: use ifindex instead of interface name in a lot of places

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.
This commit is contained in:
Dan Williams 2010-04-21 14:58:25 -07:00
parent 9fee99e123
commit 34793c1fb1
17 changed files with 168 additions and 224 deletions

View file

@ -15,8 +15,8 @@ VOID:POINTER,POINTER
VOID:STRING,STRING,STRING,UINT VOID:STRING,STRING,STRING,UINT
VOID:OBJECT,UINT,UINT VOID:OBJECT,UINT,UINT
VOID:STRING,INT VOID:STRING,INT
VOID:STRING,UINT VOID:INT,UINT
VOID:STRING,UINT,BOOLEAN VOID:INT,UINT,BOOLEAN
VOID:OBJECT,OBJECT,ENUM VOID:OBJECT,OBJECT,ENUM
VOID:POINTER,STRING VOID:POINTER,STRING
VOID:STRING,BOXED VOID:STRING,BOXED

View file

@ -42,7 +42,7 @@
typedef struct { typedef struct {
NMNetlinkMonitor *monitor; NMNetlinkMonitor *monitor;
GHashTable *devices_by_iface, *devices_by_index; GHashTable *devices;
struct nl_handle *nlh; struct nl_handle *nlh;
struct nl_cache *addr_cache, *route_cache; struct nl_cache *addr_cache, *route_cache;
@ -68,7 +68,7 @@ typedef struct {
typedef struct { typedef struct {
NMIP6Manager *manager; NMIP6Manager *manager;
char *iface; char *iface;
int index; int ifindex;
char *accept_ra_path; char *accept_ra_path;
gboolean accept_ra_save_valid; gboolean accept_ra_save_valid;
@ -120,10 +120,9 @@ nm_ip6_manager_init (NMIP6Manager *manager)
{ {
NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager); NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
priv->devices_by_iface = g_hash_table_new_full (g_str_hash, g_str_equal, priv->devices = g_hash_table_new_full (g_direct_hash, g_direct_equal,
NULL, NULL,
(GDestroyNotify) nm_ip6_device_destroy); (GDestroyNotify) nm_ip6_device_destroy);
priv->devices_by_index = g_hash_table_new (NULL, NULL);
priv->monitor = nm_netlink_monitor_get (); priv->monitor = nm_netlink_monitor_get ();
nm_netlink_monitor_subscribe (priv->monitor, RTNLGRP_IPV6_IFADDR, NULL); 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); NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (object);
g_hash_table_destroy (priv->devices_by_iface); g_hash_table_destroy (priv->devices);
g_hash_table_destroy (priv->devices_by_index);
g_object_unref (priv->monitor); g_object_unref (priv->monitor);
nl_cache_free (priv->addr_cache); nl_cache_free (priv->addr_cache);
nl_cache_free (priv->route_cache); nl_cache_free (priv->route_cache);
@ -170,8 +168,8 @@ nm_ip6_manager_class_init (NMIP6ManagerClass *manager_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMIP6ManagerClass, addrconf_complete), G_STRUCT_OFFSET (NMIP6ManagerClass, addrconf_complete),
NULL, NULL, NULL, NULL,
_nm_marshal_VOID__STRING_UINT_BOOLEAN, _nm_marshal_VOID__INT_UINT_BOOLEAN,
G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_BOOLEAN); G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_UINT, G_TYPE_BOOLEAN);
signals[CONFIG_CHANGED] = signals[CONFIG_CHANGED] =
g_signal_new ("config-changed", g_signal_new ("config-changed",
@ -179,8 +177,8 @@ nm_ip6_manager_class_init (NMIP6ManagerClass *manager_class)
G_SIGNAL_RUN_FIRST, G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NMIP6ManagerClass, config_changed), G_STRUCT_OFFSET (NMIP6ManagerClass, config_changed),
NULL, NULL, NULL, NULL,
_nm_marshal_VOID__STRING_UINT, _nm_marshal_VOID__INT_UINT,
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_UINT); G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_UINT);
} }
static void static void
@ -217,7 +215,7 @@ nm_ip6_manager_new (void)
manager = g_object_new (NM_TYPE_IP6_MANAGER, NULL); manager = g_object_new (NM_TYPE_IP6_MANAGER, NULL);
priv = NM_IP6_MANAGER_GET_PRIVATE (manager); 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"); nm_log_err (LOGD_IP6, "not enough memory to initialize IP6 manager tables");
g_object_unref (manager); g_object_unref (manager);
manager = NULL; manager = NULL;
@ -231,8 +229,7 @@ nm_ip6_manager_get_device (NMIP6Manager *manager, int ifindex)
{ {
NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager); NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
return g_hash_table_lookup (priv->devices_by_index, return g_hash_table_lookup (priv->devices, GINT_TO_POINTER (ifindex));
GINT_TO_POINTER (ifindex));
} }
typedef struct { typedef struct {
@ -246,25 +243,22 @@ finish_addrconf (gpointer user_data)
CallbackInfo *info = user_data; CallbackInfo *info = user_data;
NMIP6Device *device = info->device; NMIP6Device *device = info->device;
NMIP6Manager *manager = device->manager; NMIP6Manager *manager = device->manager;
char *iface_copy; int ifindex;
device->finish_addrconf_id = 0; device->finish_addrconf_id = 0;
device->addrconf_complete = TRUE; device->addrconf_complete = TRUE;
ifindex = device->ifindex;
if (device->state >= device->target_state) { if (device->state >= device->target_state) {
g_signal_emit (manager, signals[ADDRCONF_COMPLETE], 0, g_signal_emit (manager, signals[ADDRCONF_COMPLETE], 0,
device->iface, info->dhcp_opts, TRUE); ifindex, info->dhcp_opts, TRUE);
} else { } else {
nm_log_info (LOGD_IP6, "(%s): IP6 addrconf timed out or failed.", nm_log_info (LOGD_IP6, "(%s): IP6 addrconf timed out or failed.",
device->iface); device->iface);
iface_copy = g_strdup (device->iface); nm_ip6_manager_cancel_addrconf (manager, ifindex);
nm_ip6_manager_cancel_addrconf (manager, device->iface);
g_signal_emit (manager, signals[ADDRCONF_COMPLETE], 0, g_signal_emit (manager, signals[ADDRCONF_COMPLETE], 0,
iface_copy, info->dhcp_opts, FALSE); ifindex, info->dhcp_opts, FALSE);
g_free (iface_copy);
} }
return FALSE; return FALSE;
@ -278,7 +272,7 @@ emit_config_changed (gpointer user_data)
NMIP6Manager *manager = device->manager; NMIP6Manager *manager = device->manager;
device->config_changed_id = 0; 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; 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); for (rtnladdr = (struct rtnl_addr *)nl_cache_get_first (priv->addr_cache);
rtnladdr; rtnladdr;
rtnladdr = (struct rtnl_addr *)nl_cache_get_next ((struct nl_object *)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; continue;
nladdr = rtnl_addr_get_local (rtnladdr); nladdr = rtnl_addr_get_local (rtnladdr);
@ -686,33 +680,36 @@ netlink_notification (NMNetlinkMonitor *monitor, struct nl_msg *msg, gpointer us
} }
static NMIP6Device * 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); NMIP6ManagerPrivate *priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
NMIP6Device *device; NMIP6Device *device;
GError *error = NULL; GError *error = NULL;
char *contents = NULL; char *contents = NULL;
g_return_val_if_fail (ifindex > 0, NULL);
device = g_slice_new0 (NMIP6Device); device = g_slice_new0 (NMIP6Device);
if (!device) { 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; return NULL;
} }
device->iface = g_strdup (iface); device->ifindex = ifindex;
device->iface = g_strdup (nm_netlink_index_to_iface (ifindex));
if (!device->iface) { if (!device->iface) {
nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 addrconf object " nm_log_err (LOGD_IP6, "(%d): could not find interface name from index.",
"property 'iface'.", ifindex);
iface);
goto error; 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) { if (!device->accept_ra_path) {
nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 addrconf object " nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 addrconf object "
"property 'accept_ra_path'.", "property 'accept_ra_path'.",
iface); device->iface);
goto error; 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)); 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, GINT_TO_POINTER (device->ifindex), device);
g_hash_table_replace (priv->devices_by_index, GINT_TO_POINTER (device->index), device);
/* Grab the original value of "accept_ra" so we can restore it when the /* Grab the original value of "accept_ra" so we can restore it when the
* device is taken down. * device is taken down.
*/ */
if (!g_file_get_contents (device->accept_ra_path, &contents, NULL, &error)) { if (!g_file_get_contents (device->accept_ra_path, &contents, NULL, &error)) {
nm_log_warn (LOGD_IP6, "(%s): error reading %s: (%d) %s", 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->code : -1,
error && error->message ? error->message : "(unknown)"); error && error->message ? error->message : "(unknown)");
g_clear_error (&error); g_clear_error (&error);
@ -753,7 +749,7 @@ error:
void void
nm_ip6_manager_prepare_interface (NMIP6Manager *manager, nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
const char *iface, int ifindex,
NMSettingIP6Config *s_ip6) NMSettingIP6Config *s_ip6)
{ {
NMIP6ManagerPrivate *priv; NMIP6ManagerPrivate *priv;
@ -761,11 +757,11 @@ nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
const char *method = NULL; const char *method = NULL;
g_return_if_fail (NM_IS_IP6_MANAGER (manager)); 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); priv = NM_IP6_MANAGER_GET_PRIVATE (manager);
device = nm_ip6_device_new (manager, iface); device = nm_ip6_device_new (manager, ifindex);
if (s_ip6) if (s_ip6)
method = nm_setting_ip6_config_get_method (s_ip6); method = nm_setting_ip6_config_get_method (s_ip6);
@ -778,9 +774,9 @@ nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
else else
device->target_state = NM_IP6_DEVICE_GOT_ADDRESS; device->target_state = NM_IP6_DEVICE_GOT_ADDRESS;
g_return_if_fail (strchr (iface, '/') == NULL && g_return_if_fail ( strchr (device->iface, '/') == NULL
strcmp (iface, "all") != 0 && && strcmp (device->iface, "all") != 0
strcmp (iface, "default") != 0); && strcmp (device->iface, "default") != 0);
/* Turn router advertisement acceptance on or off... */ /* Turn router advertisement acceptance on or off... */
nm_utils_do_sysctl (device->accept_ra_path, nm_utils_do_sysctl (device->accept_ra_path,
@ -788,22 +784,21 @@ nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
} }
void void
nm_ip6_manager_begin_addrconf (NMIP6Manager *manager, nm_ip6_manager_begin_addrconf (NMIP6Manager *manager, int ifindex)
const char *iface)
{ {
NMIP6ManagerPrivate *priv; NMIP6ManagerPrivate *priv;
NMIP6Device *device; NMIP6Device *device;
CallbackInfo *info; CallbackInfo *info;
g_return_if_fail (NM_IS_IP6_MANAGER (manager)); 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); 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); 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->addrconf_complete = FALSE;
device->ra_flags = 0; device->ra_flags = 0;
@ -825,27 +820,17 @@ nm_ip6_manager_begin_addrconf (NMIP6Manager *manager,
} }
void void
nm_ip6_manager_cancel_addrconf (NMIP6Manager *manager, nm_ip6_manager_cancel_addrconf (NMIP6Manager *manager, int ifindex)
const char *iface)
{ {
NMIP6ManagerPrivate *priv;
NMIP6Device *device;
g_return_if_fail (NM_IS_IP6_MANAGER (manager)); 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); g_hash_table_remove (NM_IP6_MANAGER_GET_PRIVATE (manager)->devices,
GINT_TO_POINTER (ifindex));
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);
}
} }
NMIP6Config * NMIP6Config *
nm_ip6_manager_get_ip6_config (NMIP6Manager *manager, nm_ip6_manager_get_ip6_config (NMIP6Manager *manager, int ifindex)
const char *iface)
{ {
NMIP6ManagerPrivate *priv; NMIP6ManagerPrivate *priv;
NMIP6Device *device; NMIP6Device *device;
@ -862,20 +847,21 @@ nm_ip6_manager_get_ip6_config (NMIP6Manager *manager,
int i; int i;
g_return_val_if_fail (NM_IS_IP6_MANAGER (manager), NULL); 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); 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) { if (!device) {
nm_log_warn (LOGD_IP6, "(%s): addrconf not started.", iface); nm_log_warn (LOGD_IP6, "(%d): addrconf not started.", ifindex);
return NULL; return NULL;
} }
config = nm_ip6_config_new (); config = nm_ip6_config_new ();
if (!config) { if (!config) {
nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 config object.", nm_log_err (LOGD_IP6, "(%s): out of memory creating IP6 config object.",
iface); device->iface);
return NULL; 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); for (rtnladdr = (struct rtnl_addr *)nl_cache_get_first (priv->addr_cache);
rtnladdr; rtnladdr;
rtnladdr = (struct rtnl_addr *)nl_cache_get_next ((struct nl_object *)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; continue;
nladdr = rtnl_addr_get_local (rtnladdr); 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); for (rtnlroute = (struct rtnl_route *)nl_cache_get_first (priv->route_cache);
rtnlroute; rtnlroute;
rtnlroute = (struct rtnl_route *)nl_cache_get_next ((struct nl_object *)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; continue;
nldest = rtnl_route_get_dst (rtnlroute); nldest = rtnl_route_get_dst (rtnlroute);

View file

@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 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 #ifndef NM_IP6_MANAGER_H
@ -54,7 +54,7 @@ typedef struct {
* that the initial configuration is complete. * that the initial configuration is complete.
*/ */
void (*addrconf_complete) (NMIP6Manager *manager, void (*addrconf_complete) (NMIP6Manager *manager,
char *iface, guint32 ifindex,
guint dhcp_opts, guint dhcp_opts,
gboolean success); gboolean success);
@ -63,22 +63,22 @@ typedef struct {
* of the interface has changed. * of the interface has changed.
*/ */
void (*config_changed) (NMIP6Manager *manager, void (*config_changed) (NMIP6Manager *manager,
char *iface, guint32 ifindex,
guint dhcp_opts); guint dhcp_opts);
} NMIP6ManagerClass; } NMIP6ManagerClass;
GType nm_ip6_manager_get_type (void); GType nm_ip6_manager_get_type (void);
NMIP6Manager *nm_ip6_manager_get (void); NMIP6Manager *nm_ip6_manager_get (void);
void nm_ip6_manager_prepare_interface (NMIP6Manager *manager, void nm_ip6_manager_prepare_interface (NMIP6Manager *manager,
const char *iface, int ifindex,
NMSettingIP6Config *s_ip6); NMSettingIP6Config *s_ip6);
void nm_ip6_manager_begin_addrconf (NMIP6Manager *manager, void nm_ip6_manager_begin_addrconf (NMIP6Manager *manager,
const char *iface); int ifindex);
void nm_ip6_manager_cancel_addrconf (NMIP6Manager *manager, void nm_ip6_manager_cancel_addrconf (NMIP6Manager *manager,
const char *iface); int ifindex);
NMIP6Config * nm_ip6_manager_get_ip6_config (NMIP6Manager *manager, NMIP6Config * nm_ip6_manager_get_ip6_config (NMIP6Manager *manager,
const char *iface); int ifindex);
#endif /* NM_IP6_MANAGER_H */ #endif /* NM_IP6_MANAGER_H */

View file

@ -106,7 +106,6 @@ typedef struct {
struct ether_addr hw_addr; struct ether_addr hw_addr;
gboolean carrier; gboolean carrier;
guint32 ifindex;
NMNetlinkMonitor * monitor; NMNetlinkMonitor * monitor;
gulong link_connected_id; gulong link_connected_id;
@ -134,7 +133,6 @@ enum {
PROP_HW_ADDRESS, PROP_HW_ADDRESS,
PROP_SPEED, PROP_SPEED,
PROP_CARRIER, PROP_CARRIER,
PROP_IFINDEX,
LAST_PROP LAST_PROP
}; };
@ -247,11 +245,10 @@ carrier_on (NMNetlinkMonitor *monitor,
{ {
NMDevice *device = NM_DEVICE (user_data); NMDevice *device = NM_DEVICE (user_data);
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device); NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
guint32 caps; guint32 caps;
/* Make sure signal is for us */ /* Make sure signal is for us */
if (idx == priv->ifindex) { if (idx == nm_device_get_ifindex (device)) {
/* Ignore spurious netlink messages */ /* Ignore spurious netlink messages */
caps = nm_device_get_capabilities (device); caps = nm_device_get_capabilities (device);
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT)) if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
@ -268,11 +265,10 @@ carrier_off (NMNetlinkMonitor *monitor,
{ {
NMDevice *device = NM_DEVICE (user_data); NMDevice *device = NM_DEVICE (user_data);
NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device); NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
guint32 caps; guint32 caps;
/* Make sure signal is for us */ /* Make sure signal is for us */
if (idx == priv->ifindex) { if (idx == nm_device_get_ifindex (device)) {
NMDeviceState state; NMDeviceState state;
gboolean defer = FALSE; gboolean defer = FALSE;
@ -313,7 +309,8 @@ constructor (GType type,
priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self); priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
nm_log_dbg (LOGD_HW | LOGD_OLPC_MESH, "(%s): kernel ifindex %d", 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); caps = nm_device_get_capabilities (self);
if (caps & NM_DEVICE_CAP_CARRIER_DETECT) { if (caps & NM_DEVICE_CAP_CARRIER_DETECT) {
@ -332,7 +329,7 @@ constructor (GType type,
/* Get initial link state */ /* Get initial link state */
if (!nm_netlink_monitor_get_flags_sync (priv->monitor, if (!nm_netlink_monitor_get_flags_sync (priv->monitor,
priv->ifindex, nm_device_get_ifindex (NM_DEVICE (self)),
&ifflags, &ifflags,
&error)) { &error)) {
nm_log_warn (LOGD_HW | LOGD_ETHER, nm_log_warn (LOGD_HW | LOGD_ETHER,
@ -427,8 +424,7 @@ real_hw_take_down (NMDevice *dev)
NMDevice * NMDevice *
nm_device_ethernet_new (const char *udi, nm_device_ethernet_new (const char *udi,
const char *iface, const char *iface,
const char *driver, const char *driver)
guint32 ifindex)
{ {
g_return_val_if_fail (udi != NULL, NULL); g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != 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_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface, NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver, NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_ETHERNET_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet", NM_DEVICE_INTERFACE_TYPE_DESC, "Ethernet",
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET, NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_ETHERNET,
NULL); 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)); 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 */ /* Returns speed in Mb/s */
static guint32 static guint32
nm_device_ethernet_get_speed (NMDeviceEthernet *self) nm_device_ethernet_get_speed (NMDeviceEthernet *self)
@ -1619,7 +1606,7 @@ ip4_match_config (NMDevice *self, NMConnection *connection)
int ifindex; int ifindex;
AddrData check_data; 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); s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
g_assert (s_con); g_assert (s_con);
@ -1791,9 +1778,6 @@ get_property (GObject *object, guint prop_id,
case PROP_CARRIER: case PROP_CARRIER:
g_value_set_boolean (value, priv->carrier); g_value_set_boolean (value, priv->carrier);
break; break;
case PROP_IFINDEX:
g_value_set_uint (value, priv->ifindex);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -1804,13 +1788,7 @@ static void
set_property (GObject *object, guint prop_id, set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec) const GValue *value, GParamSpec *pspec)
{ {
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object);
switch (prop_id) { switch (prop_id) {
case PROP_IFINDEX:
/* construct-only */
priv->ifindex = g_value_get_uint (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -1877,14 +1855,6 @@ nm_device_ethernet_class_init (NMDeviceEthernetClass *klass)
FALSE, FALSE,
G_PARAM_READABLE)); 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 */
signals[PROPERTIES_CHANGED] = signals[PROPERTIES_CHANGED] =
nm_properties_changed_signal_new (object_class, nm_properties_changed_signal_new (object_class,

View file

@ -39,7 +39,6 @@ G_BEGIN_DECLS
#define NM_DEVICE_ETHERNET_HW_ADDRESS "hw-address" #define NM_DEVICE_ETHERNET_HW_ADDRESS "hw-address"
#define NM_DEVICE_ETHERNET_SPEED "speed" #define NM_DEVICE_ETHERNET_SPEED "speed"
#define NM_DEVICE_ETHERNET_CARRIER "carrier" #define NM_DEVICE_ETHERNET_CARRIER "carrier"
#define NM_DEVICE_ETHERNET_IFINDEX "ifindex"
typedef struct { typedef struct {
NMDevice parent; NMDevice parent;
@ -58,14 +57,11 @@ GType nm_device_ethernet_get_type (void);
NMDevice *nm_device_ethernet_new (const char *udi, NMDevice *nm_device_ethernet_new (const char *udi,
const char *iface, const char *iface,
const char *driver, const char *driver);
guint32 ifindex);
void nm_device_ethernet_get_address (NMDeviceEthernet *dev, void nm_device_ethernet_get_address (NMDeviceEthernet *dev,
struct ether_addr *addr); struct ether_addr *addr);
guint32 nm_device_ethernet_get_ifindex (NMDeviceEthernet *dev);
G_END_DECLS G_END_DECLS
#endif /* NM_DEVICE_ETHERNET_H */ #endif /* NM_DEVICE_ETHERNET_H */

View file

@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* Copyright (C) 2007 - 2008 Novell, Inc. * Copyright (C) 2007 - 2008 Novell, Inc.
* Copyright (C) 2007 - 2008 Red Hat, Inc. * Copyright (C) 2007 - 2010 Red Hat, Inc.
*/ */
#include "nm-marshal.h" #include "nm-marshal.h"
@ -186,6 +186,14 @@ nm_device_interface_init (gpointer g_iface)
RFKILL_TYPE_UNKNOWN, RFKILL_TYPE_UNKNOWN,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | NM_PROPERTY_PARAM_NO_EXPORT)); 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 */ /* Signals */
g_signal_new ("state-changed", g_signal_new ("state-changed",
iface_type, iface_type,

View file

@ -57,8 +57,9 @@ typedef enum
#define NM_DEVICE_INTERFACE_STATE "state" #define NM_DEVICE_INTERFACE_STATE "state"
#define NM_DEVICE_INTERFACE_DEVICE_TYPE "device-type" /* ugh */ #define NM_DEVICE_INTERFACE_DEVICE_TYPE "device-type" /* ugh */
#define NM_DEVICE_INTERFACE_MANAGED "managed" #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_RFKILL_TYPE "rfkill-type" /* Internal only */
#define NM_DEVICE_INTERFACE_IFINDEX "ifindex" /* Internal only */
typedef enum { typedef enum {
NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000, NM_DEVICE_INTERFACE_PROP_FIRST = 0x1000,
@ -77,6 +78,7 @@ typedef enum {
NM_DEVICE_INTERFACE_PROP_MANAGED, NM_DEVICE_INTERFACE_PROP_MANAGED,
NM_DEVICE_INTERFACE_PROP_TYPE_DESC, NM_DEVICE_INTERFACE_PROP_TYPE_DESC,
NM_DEVICE_INTERFACE_PROP_RFKILL_TYPE, NM_DEVICE_INTERFACE_PROP_RFKILL_TYPE,
NM_DEVICE_INTERFACE_PROP_IFINDEX,
} NMDeviceInterfaceProp; } NMDeviceInterfaceProp;

View file

@ -69,7 +69,6 @@ enum {
PROP_HW_ADDRESS, PROP_HW_ADDRESS,
PROP_COMPANION, PROP_COMPANION,
PROP_ACTIVE_CHANNEL, PROP_ACTIVE_CHANNEL,
PROP_IFINDEX,
LAST_PROP LAST_PROP
}; };
@ -98,7 +97,6 @@ struct _NMDeviceOlpcMeshPrivate
gboolean dispose_has_run; gboolean dispose_has_run;
struct ether_addr hw_addr; struct ether_addr hw_addr;
guint32 ifindex;
GByteArray * ssid; GByteArray * ssid;
@ -263,7 +261,8 @@ constructor (GType type,
priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
nm_log_dbg (LOGD_HW | LOGD_OLPC_MESH, "(%s): kernel ifindex %d", 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)); iface = nm_device_get_iface (NM_DEVICE (self));
fd = socket (PF_INET, SOCK_DGRAM, 0); fd = socket (PF_INET, SOCK_DGRAM, 0);
@ -539,15 +538,6 @@ nm_device_olpc_mesh_set_ssid (NMDeviceOlpcMesh *self, const GByteArray * ssid)
close (sk); 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 static void
@ -701,9 +691,6 @@ get_property (GObject *object, guint prop_id,
case PROP_ACTIVE_CHANNEL: case PROP_ACTIVE_CHANNEL:
g_value_set_uint (value, nm_device_olpc_mesh_get_channel (device)); g_value_set_uint (value, nm_device_olpc_mesh_get_channel (device));
break; break;
case PROP_IFINDEX:
g_value_set_uint (value, nm_device_olpc_mesh_get_ifindex (device));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -714,13 +701,7 @@ static void
set_property (GObject *object, guint prop_id, set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec) const GValue *value, GParamSpec *pspec)
{ {
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
switch (prop_id) { switch (prop_id) {
case PROP_IFINDEX:
/* construct-only */
priv->ifindex = g_value_get_uint (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -780,13 +761,6 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
0, G_MAXUINT32, 0, 0, G_MAXUINT32, 0,
G_PARAM_READABLE)); 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] = signals[PROPERTIES_CHANGED] =
nm_properties_changed_signal_new (object_class, nm_properties_changed_signal_new (object_class,
G_STRUCT_OFFSET (NMDeviceOlpcMeshClass, properties_changed)); G_STRUCT_OFFSET (NMDeviceOlpcMeshClass, properties_changed));
@ -986,8 +960,7 @@ state_changed_cb (NMDevice *device, NMDeviceState state, gpointer user_data)
NMDevice * NMDevice *
nm_device_olpc_mesh_new (const char *udi, nm_device_olpc_mesh_new (const char *udi,
const char *iface, const char *iface,
const char *driver, const char *driver)
guint32 ifindex)
{ {
GObject *obj; GObject *obj;
@ -999,7 +972,6 @@ nm_device_olpc_mesh_new (const char *udi,
NM_DEVICE_INTERFACE_UDI, udi, NM_DEVICE_INTERFACE_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface, NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver, NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_OLPC_MESH_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 OLPC Mesh", NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 OLPC Mesh",
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_OLPC_MESH, NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_OLPC_MESH,
NULL); NULL);

View file

@ -46,7 +46,6 @@ G_BEGIN_DECLS
#define NM_DEVICE_OLPC_MESH_COMPANION "companion" #define NM_DEVICE_OLPC_MESH_COMPANION "companion"
#define NM_DEVICE_OLPC_MESH_BITRATE "bitrate" #define NM_DEVICE_OLPC_MESH_BITRATE "bitrate"
#define NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL "active-channel" #define NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL "active-channel"
#define NM_DEVICE_OLPC_MESH_IFINDEX "ifindex"
#ifndef NM_DEVICE_OLPC_MESH_DEFINED #ifndef NM_DEVICE_OLPC_MESH_DEFINED
#define 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, NMDevice *nm_device_olpc_mesh_new (const char *udi,
const char *iface, const char *iface,
const char *driver, const char *driver);
guint32 ifindex);
guint32 nm_device_olpc_mesh_get_ifindex (NMDeviceOlpcMesh *self);
G_END_DECLS G_END_DECLS

View file

@ -82,7 +82,6 @@ enum {
PROP_BITRATE, PROP_BITRATE,
PROP_ACTIVE_ACCESS_POINT, PROP_ACTIVE_ACCESS_POINT,
PROP_CAPABILITIES, PROP_CAPABILITIES,
PROP_IFINDEX,
PROP_SCANNING, PROP_SCANNING,
PROP_IPW_RFKILL_STATE, PROP_IPW_RFKILL_STATE,
@ -144,7 +143,6 @@ struct _NMDeviceWifiPrivate {
gboolean disposed; gboolean disposed;
struct ether_addr hw_addr; struct ether_addr hw_addr;
guint32 ifindex;
/* Legacy rfkill for ipw2x00; will be fixed with 2.6.33 kernel */ /* Legacy rfkill for ipw2x00; will be fixed with 2.6.33 kernel */
char * ipw_rfkill_path; char * ipw_rfkill_path;
@ -579,7 +577,8 @@ constructor (GType type,
priv = NM_DEVICE_WIFI_GET_PRIVATE (self); priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
nm_log_dbg (LOGD_HW | LOGD_WIFI, "(%s): kernel ifindex %d", 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)); memset (&range, 0, sizeof (struct iw_range));
success = wireless_get_range (NM_DEVICE_WIFI (object), &range, &response_len); success = wireless_get_range (NM_DEVICE_WIFI (object), &range, &response_len);
@ -3462,14 +3461,6 @@ device_state_changed (NMDevice *device,
remove_all_aps (self); 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 * NMAccessPoint *
nm_device_wifi_get_activation_ap (NMDeviceWifi *self) nm_device_wifi_get_activation_ap (NMDeviceWifi *self)
{ {
@ -3563,8 +3554,7 @@ real_set_enabled (NMDeviceInterface *device, gboolean enabled)
NMDevice * NMDevice *
nm_device_wifi_new (const char *udi, nm_device_wifi_new (const char *udi,
const char *iface, const char *iface,
const char *driver, const char *driver)
guint32 ifindex)
{ {
g_return_val_if_fail (udi != NULL, NULL); g_return_val_if_fail (udi != NULL, NULL);
g_return_val_if_fail (iface != 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_UDI, udi,
NM_DEVICE_INTERFACE_IFACE, iface, NM_DEVICE_INTERFACE_IFACE, iface,
NM_DEVICE_INTERFACE_DRIVER, driver, NM_DEVICE_INTERFACE_DRIVER, driver,
NM_DEVICE_WIFI_IFINDEX, ifindex,
NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 WiFi", NM_DEVICE_INTERFACE_TYPE_DESC, "802.11 WiFi",
NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI, NM_DEVICE_INTERFACE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI,
NM_DEVICE_INTERFACE_RFKILL_TYPE, RFKILL_TYPE_WLAN, NM_DEVICE_INTERFACE_RFKILL_TYPE, RFKILL_TYPE_WLAN,
@ -3675,9 +3664,6 @@ get_property (GObject *object, guint prop_id,
else else
g_value_set_boxed (value, "/"); g_value_set_boxed (value, "/");
break; break;
case PROP_IFINDEX:
g_value_set_uint (value, nm_device_wifi_get_ifindex (device));
break;
case PROP_SCANNING: case PROP_SCANNING:
g_value_set_boolean (value, nm_supplicant_interface_get_scanning (priv->supplicant.iface)); g_value_set_boolean (value, nm_supplicant_interface_get_scanning (priv->supplicant.iface));
break; break;
@ -3697,10 +3683,6 @@ set_property (GObject *object, guint prop_id,
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (object);
switch (prop_id) { switch (prop_id) {
case PROP_IFINDEX:
/* construct-only */
priv->ifindex = g_value_get_uint (value);
break;
case PROP_IPW_RFKILL_STATE: case PROP_IPW_RFKILL_STATE:
/* construct only */ /* construct only */
priv->ipw_rfkill_state = g_value_get_uint (value); 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, 0, G_MAXUINT32, NM_WIFI_DEVICE_CAP_NONE,
G_PARAM_READABLE)); 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_object_class_install_property (object_class, PROP_SCANNING,
g_param_spec_boolean (NM_DEVICE_WIFI_SCANNING, g_param_spec_boolean (NM_DEVICE_WIFI_SCANNING,
"Scanning", "Scanning",

View file

@ -47,7 +47,6 @@ G_BEGIN_DECLS
#define NM_DEVICE_WIFI_BITRATE "bitrate" #define NM_DEVICE_WIFI_BITRATE "bitrate"
#define NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT "active-access-point" #define NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT "active-access-point"
#define NM_DEVICE_WIFI_CAPABILITIES "wireless-capabilities" #define NM_DEVICE_WIFI_CAPABILITIES "wireless-capabilities"
#define NM_DEVICE_WIFI_IFINDEX "ifindex"
#define NM_DEVICE_WIFI_SCANNING "scanning" #define NM_DEVICE_WIFI_SCANNING "scanning"
#define NM_DEVICE_WIFI_IPW_RFKILL_STATE "ipw-rfkill-state" #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, NMDevice *nm_device_wifi_new (const char *udi,
const char *iface, const char *iface,
const char *driver, const char *driver);
guint32 ifindex);
void nm_device_wifi_get_address (NMDeviceWifi *dev, void nm_device_wifi_get_address (NMDeviceWifi *dev,
struct ether_addr *addr); 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); 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); RfKillState nm_device_wifi_get_ipw_rfkill_state (NMDeviceWifi *self);
G_END_DECLS G_END_DECLS

View file

@ -83,7 +83,9 @@ typedef struct {
char * udi; char * udi;
char * path; char * path;
char * iface; /* may change, could be renamed by user */ char * iface; /* may change, could be renamed by user */
int ifindex;
char * ip_iface; char * ip_iface;
int ip_ifindex;
NMDeviceType type; NMDeviceType type;
char * type_desc; char * type_desc;
guint32 capabilities; guint32 capabilities;
@ -304,6 +306,13 @@ nm_device_get_iface (NMDevice *self)
return NM_DEVICE_GET_PRIVATE (self)->iface; 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 * const char *
nm_device_get_ip_iface (NMDevice *self) 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; 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 void
nm_device_set_ip_iface (NMDevice *self, const char *iface) nm_device_set_ip_iface (NMDevice *self, const char *iface)
{ {
NMDevicePrivate *priv;
g_return_if_fail (NM_IS_DEVICE (self)); g_return_if_fail (NM_IS_DEVICE (self));
g_free (NM_DEVICE_GET_PRIVATE (self)->ip_iface); priv = NM_DEVICE_GET_PRIVATE (self);
NM_DEVICE_GET_PRIVATE (self)->ip_iface = iface ? g_strdup (iface) : NULL; 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 static void
ip6_addrconf_complete (NMIP6Manager *ip6_manager, ip6_addrconf_complete (NMIP6Manager *ip6_manager,
const char *iface, int ifindex,
guint dhcp_opts, guint dhcp_opts,
gboolean success, gboolean success,
gpointer user_data) gpointer user_data)
@ -558,7 +589,7 @@ ip6_addrconf_complete (NMIP6Manager *ip6_manager,
NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
NMDeviceState state; NMDeviceState state;
if (strcmp (nm_device_get_ip_iface (self), iface) != 0) if (ifindex != nm_device_get_ip_ifindex (self))
return; return;
req = nm_device_get_act_request (self); req = nm_device_get_act_request (self);
if (!req) if (!req)
@ -614,13 +645,13 @@ ip6_addrconf_complete (NMIP6Manager *ip6_manager,
static void static void
ip6_config_changed (NMIP6Manager *ip6_manager, ip6_config_changed (NMIP6Manager *ip6_manager,
const char *iface, int ifindex,
guint dhcp_opts, guint dhcp_opts,
gpointer user_data) gpointer user_data)
{ {
NMDevice *self = NM_DEVICE (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; return;
if (!nm_device_get_act_request (self)) if (!nm_device_get_act_request (self))
return; return;
@ -675,7 +706,9 @@ addrconf6_setup (NMDevice *self)
ip_iface = nm_device_get_ip_iface (self); ip_iface = nm_device_get_ip_iface (self);
s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG); 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 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)) { if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) {
priv->ip6_waiting_for_config = TRUE; 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; ret = NM_ACT_STAGE_RETURN_POSTPONE;
} else if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_DHCP)) } else if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_DHCP))
ret = dhcp6_start (self, connection, IP6_DHCP_OPT_MANAGED, reason); 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); s_ip6 = (NMSettingIP6Config *) nm_connection_get_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
if (ip6_method_matches (connection, NM_SETTING_IP6_CONFIG_METHOD_AUTO)) { 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) { if (*config) {
/* Merge user-defined overrides into the IP6Config to be applied */ /* Merge user-defined overrides into the IP6Config to be applied */
nm_utils_merge_ip6_config (*config, s_ip6); nm_utils_merge_ip6_config (*config, s_ip6);
@ -3089,7 +3123,14 @@ set_property (GObject *object, guint prop_id,
break; break;
case NM_DEVICE_INTERFACE_PROP_IFACE: case NM_DEVICE_INTERFACE_PROP_IFACE:
g_free (priv->iface); g_free (priv->iface);
priv->ifindex = 0;
priv->iface = g_value_dup_string (value); 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; break;
case NM_DEVICE_INTERFACE_PROP_DRIVER: case NM_DEVICE_INTERFACE_PROP_DRIVER:
priv->driver = g_strdup (g_value_get_string (value)); 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: case NM_DEVICE_INTERFACE_PROP_IFACE:
g_value_set_string (value, priv->iface); g_value_set_string (value, priv->iface);
break; break;
case NM_DEVICE_INTERFACE_PROP_IFINDEX:
g_value_set_int (value, priv->ifindex);
break;
case NM_DEVICE_INTERFACE_PROP_DRIVER: case NM_DEVICE_INTERFACE_PROP_DRIVER:
g_value_set_string (value, priv->driver); g_value_set_string (value, priv->driver);
break; break;
@ -3235,6 +3279,10 @@ nm_device_class_init (NMDeviceClass *klass)
NM_DEVICE_INTERFACE_PROP_IFACE, NM_DEVICE_INTERFACE_PROP_IFACE,
NM_DEVICE_INTERFACE_IFACE); 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, g_object_class_override_property (object_class,
NM_DEVICE_INTERFACE_PROP_DRIVER, NM_DEVICE_INTERFACE_PROP_DRIVER,
NM_DEVICE_INTERFACE_DRIVER); NM_DEVICE_INTERFACE_DRIVER);

View 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_udi (NMDevice *dev);
const char * nm_device_get_iface (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); 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_driver (NMDevice *dev);
const char * nm_device_get_type_desc (NMDevice *dev); const char * nm_device_get_type_desc (NMDevice *dev);

View file

@ -1523,7 +1523,8 @@ add_device (NMManager *self, NMDevice *device)
driver = nm_device_get_driver (device); driver = nm_device_get_driver (device);
if (!driver) if (!driver)
driver = "unknown"; 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++); path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
nm_device_set_path (device, path); nm_device_set_path (device, path);
@ -1794,20 +1795,11 @@ find_device_by_ifindex (NMManager *self, guint32 ifindex)
GSList *iter; GSList *iter;
for (iter = priv->devices; iter; iter = g_slist_next (iter)) { for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
NMDevice *device = NM_DEVICE (iter->data); NMDevice *candidate = NM_DEVICE (iter->data);
gint candidate_idx = 0;
if (NM_IS_DEVICE_ETHERNET (device)) if (ifindex == nm_device_get_ifindex (candidate))
candidate_idx = nm_device_ethernet_get_ifindex (NM_DEVICE_ETHERNET (device)); return candidate;
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));
if (candidate_idx == ifindex)
return device;
} }
return NULL; return NULL;
} }

View file

@ -743,7 +743,8 @@ nm_netlink_index_to_rtnl_link (int idx)
NMNetlinkMonitorPrivate *priv; NMNetlinkMonitorPrivate *priv;
struct rtnl_link *ret = NULL; struct rtnl_link *ret = NULL;
g_return_val_if_fail (idx >= 0, NULL); if (idx <= 0)
return NULL;
self = nm_netlink_monitor_get (); self = nm_netlink_monitor_get ();
priv = NM_NETLINK_MONITOR_GET_PRIVATE (self); priv = NM_NETLINK_MONITOR_GET_PRIVATE (self);

View file

@ -986,7 +986,7 @@ foreach_route (void (*callback)(struct nl_object *, gpointer),
nlh = nm_netlink_get_default_handle (); nlh = nm_netlink_get_default_handle ();
route_cache = rtnl_route_alloc_cache (nlh); 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_foreach (route_cache, callback, user_data);
nl_cache_free (route_cache); nl_cache_free (route_cache);
} }

View file

@ -384,11 +384,11 @@ device_creator (NMUdevManager *manager,
} }
if (is_olpc_mesh (udev_device)) /* must be before is_wireless */ 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)) 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 else
device = (GObject *) nm_device_ethernet_new (path, ifname, driver, ifindex); device = (GObject *) nm_device_ethernet_new (path, ifname, driver);
out: out:
if (grandparent) if (grandparent)