Use always the interface index and only when interface name
is needed, then fetch the name. This minimizes races when
interface name changes because of udev rules.
Upstream commit Id:
bcb7f23f1e9afb2cf8f27368f9da418b49db9adc
Change-Id: I5f128f2d7c118ec90381388dc313b91ff4e4c8f9
Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
struct interface_data {
int index;
struct interface_data {
int index;
char *ident;
enum connman_service_type service_type;
enum connman_device_type device_type;
char *ident;
enum connman_service_type service_type;
enum connman_device_type device_type;
interface->index, interface->ident);
g_free(interface->ident);
interface->index, interface->ident);
g_free(interface->ident);
- g_free(interface->name);
static void read_uevent(struct interface_data *interface)
{
static void read_uevent(struct interface_data *interface)
{
- char *filename, line[128];
+ char *filename, *name, line[128];
connman_bool_t found_devtype;
FILE *f;
connman_bool_t found_devtype;
FILE *f;
- if (ether_blacklisted(interface->name) == TRUE) {
+ name = connman_inet_ifname(interface->index);
+
+ if (ether_blacklisted(name) == TRUE) {
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
} else {
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
} else {
interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
}
interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
}
- filename = g_strdup_printf("/sys/class/net/%s/uevent",
- interface->name);
+ filename = g_strdup_printf("/sys/class/net/%s/uevent", name);
f = fopen(filename, "re");
f = fopen(filename, "re");
if (!f) {
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
if (!f) {
interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
fclose(f);
if (found_devtype)
fclose(f);
if (found_devtype)
/* We haven't got a DEVTYPE, let's check if it's a wireless device */
/* We haven't got a DEVTYPE, let's check if it's a wireless device */
- if (wext_interface(interface->name)) {
+ if (wext_interface(name)) {
interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
- connman_error("%s runs an unsupported 802.11 driver",
- interface->name);
+ connman_error("%s runs an unsupported 802.11 driver", name);
}
enum connman_device_type __connman_rtnl_get_device_type(int index)
}
enum connman_device_type __connman_rtnl_get_device_type(int index)
if (interface == NULL) {
interface = g_new0(struct interface_data, 1);
interface->index = index;
if (interface == NULL) {
interface = g_new0(struct interface_data, 1);
interface->index = index;
- interface->name = g_strdup(ifname);
interface->ident = g_strdup(ident);
g_hash_table_insert(interface_list,
interface->ident = g_strdup(ident);
g_hash_table_insert(interface_list,