Exemple #1
0
static struct service_entry *create_service_entry(struct connman_service *service,
					const char *name,
					enum connman_service_state state)
{
	struct service_entry *entry;
	enum connman_service_type type;
	int idx;

	entry = g_try_new0(struct service_entry, 1);
	if (entry == NULL)
		return entry;

	entry->reason = CONNMAN_SESSION_REASON_UNKNOWN;
	entry->state = state;
	if (name != NULL)
		entry->name = name;
	else
		entry->name = "";
	entry->service = service;

	idx = __connman_service_get_index(entry->service);
	entry->ifname = connman_inet_ifname(idx);
	if (entry->ifname == NULL)
		entry->ifname = g_strdup("");

	type = connman_service_get_type(entry->service);
	entry->bearer = service2bearer(type);

	return entry;
}
Exemple #2
0
static void add_nat_rules(struct connman_session *session)
{
    struct connman_ipconfig *ipconfig;
    const char *addr;
    char *ifname;
    int index, id, err;

    if (!session->fw)
        return;

    DBG("");

    ipconfig = __connman_service_get_ip4config(session->service);
    index = __connman_ipconfig_get_index(ipconfig);
    ifname = connman_inet_ifname(index);
    addr = __connman_ipconfig_get_local(ipconfig);

    id = __connman_firewall_add_rule(session->fw, "nat", "POSTROUTING",
                                     "-o %s -j SNAT --to-source %s",
                                     ifname, addr);
    g_free(ifname);
    if (id < 0) {
        DBG("failed to add SNAT rule");
        return;
    }

    err = __connman_firewall_enable_rule(session->fw, id);
    if (err < 0) {
        DBG("could not enable SNAT rule");
        __connman_firewall_remove_rule(session->fw, id);
        return;
    }

    session->snat_id = id;
}
Exemple #3
0
void __vpn_ipconfig_newlink(int index, unsigned short type,
                            unsigned int flags,
                            const char *address,
                            unsigned short mtu,
                            struct rtnl_link_stats64 *stats)
{
    struct vpn_ipdevice *ipdevice;
    GString *str;

    if (type == ARPHRD_LOOPBACK)
        return;

    ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
    if (ipdevice)
        goto update;

    ipdevice = g_try_new0(struct vpn_ipdevice, 1);
    if (!ipdevice)
        return;

    ipdevice->index = index;
    ipdevice->ifname = connman_inet_ifname(index);
    ipdevice->type = type;

    ipdevice->address = g_strdup(address);

    g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);

    DBG("%s {create} index %d type %d <%s>", ipdevice->ifname,
        index, type, type2str(type));

update:
    ipdevice->mtu = mtu;

    if (flags == ipdevice->flags)
        return;

    ipdevice->flags = flags;

    str = g_string_new(NULL);
    if (!str)
        return;

    if (flags & IFF_UP)
        g_string_append(str, "UP");
    else
        g_string_append(str, "DOWN");

    if (flags & IFF_RUNNING)
        g_string_append(str, ",RUNNING");

    if (flags & IFF_LOWER_UP)
        g_string_append(str, ",LOWER_UP");

    DBG("%s {update} flags %u <%s>", ipdevice->ifname,
        flags, str->str);

    g_string_free(str, TRUE);
}
Exemple #4
0
int supplicant_start(struct connman_device *device)
{
	struct supplicant_task *task;
	int err;

	_DBG_SUPPLICANT("device %p", device);

	task = g_try_new0(struct supplicant_task, 1);
	if (task == NULL)
		return -ENOMEM;

	task->ifindex = connman_device_get_index(device);
	task->ifname = connman_inet_ifname(task->ifindex);

	if (task->ifname == NULL) {
		err = -ENOMEM;
		goto failed;
	}

	task->mac80211 = connman_inet_is_mac80211(task->ifindex);
	if (task->mac80211 == FALSE)
		connman_warn("Enabling quirks for unsupported driver");

	task->range = g_try_malloc0(sizeof(struct iw_range));
	if (task->range == NULL) {
		err = -ENOMEM;
		goto failed;
	}

	err = get_range(task);
	if (err < 0)
		goto failed;

	task->device = connman_device_ref(device);

	task->created = FALSE;
	task->scanning = FALSE;
	task->state = WPA_INVALID;
	task->disconnecting = FALSE;
	task->pending_network = NULL;

	task_list = g_slist_append(task_list, task);

	return create_interface(task);

failed:
	g_free(task->range);
	g_free(task->ifname);
	g_free(task);

	return err;
}
Exemple #5
0
static int get_bssid(struct connman_device *device,
				unsigned char *bssid, unsigned int *bssid_len)
{
	struct iwreq wrq;
	char *ifname;
	int ifindex;
	int fd, err;

	ifindex = connman_device_get_index(device);
	if (ifindex < 0)
		return -EINVAL;

	ifname = connman_inet_ifname(ifindex);
	if (ifname == NULL)
		return -EINVAL;

	fd = socket(PF_INET, SOCK_DGRAM, 0);
	if (fd < 0) {
		g_free(ifname);
		return -EINVAL;
	}

	memset(&wrq, 0, sizeof(wrq));
	strncpy(wrq.ifr_name, ifname, IFNAMSIZ);

	err = ioctl(fd, SIOCGIWAP, &wrq);

	g_free(ifname);
	close(fd);

	if (err < 0)
		return -EIO;

	memcpy(bssid, wrq.u.ap_addr.sa_data, ETH_ALEN);
	*bssid_len = ETH_ALEN;

	return 0;
}
Exemple #6
0
static void add_nat_rules(struct connman_session *session)
{
	struct connman_ipconfig *ipconfig;
	struct fw_snat *fw_snat;
	const char *addr;
	int index, err;
	char *ifname;

	if (!session->service)
		return;

	ipconfig = __connman_service_get_ip4config(session->service);
	index = __connman_ipconfig_get_index(ipconfig);
	ifname = connman_inet_ifname(index);
	addr = __connman_ipconfig_get_local(ipconfig);

	if (!addr)
		return;

	g_free(session->addr);
	session->addr = g_strdup(addr);

	session->snat_enabled = true;
	fw_snat = fw_snat_lookup(index, session->addr);
	if (fw_snat) {
		fw_snat_ref(session, fw_snat);
		return;
	}

	err = fw_snat_create(session, index, ifname, addr);
	if (err < 0) {
		DBG("failed to add SNAT rule");
		session->snat_enabled = false;
	}

	g_free(ifname);
}
Exemple #7
0
struct connman_device *connman_device_create_from_index(int index)
{
	enum connman_device_type type;
	struct connman_device *device;
	char *devname, *ident = NULL;
	char *addr = NULL, *name = NULL;

	if (index < 0)
		return NULL;

	devname = connman_inet_ifname(index);
	if (devname == NULL)
		return NULL;

	if (__connman_device_isfiltered(devname) == TRUE) {
		connman_info("Ignoring interface %s (filtered)", devname);
		g_free(devname);
		return NULL;
	}

	type = __connman_rtnl_get_device_type(index);

	switch (type) {
	case CONNMAN_DEVICE_TYPE_UNKNOWN:
		connman_info("Ignoring interface %s (type unknown)", devname);
		g_free(devname);
		return NULL;
	case CONNMAN_DEVICE_TYPE_ETHERNET:
	case CONNMAN_DEVICE_TYPE_GADGET:
	case CONNMAN_DEVICE_TYPE_WIFI:
	case CONNMAN_DEVICE_TYPE_CELLULAR:
	case CONNMAN_DEVICE_TYPE_QMI:
	case CONNMAN_DEVICE_TYPE_MK3:
		name = index2ident(index, "");
		addr = index2addr(index);
		break;
	case CONNMAN_DEVICE_TYPE_BLUETOOTH:

	case CONNMAN_DEVICE_TYPE_GPS:
	case CONNMAN_DEVICE_TYPE_VENDOR:
		name = g_strdup(devname);
		break;
	}

	device = connman_device_create(name, type);
	if (device == NULL)
		goto done;

	switch (type) {
	case CONNMAN_DEVICE_TYPE_UNKNOWN:
	case CONNMAN_DEVICE_TYPE_VENDOR:
	case CONNMAN_DEVICE_TYPE_GPS:
		break;
	case CONNMAN_DEVICE_TYPE_ETHERNET:
	case CONNMAN_DEVICE_TYPE_GADGET:
		ident = index2ident(index, NULL);
		break;
	case CONNMAN_DEVICE_TYPE_WIFI:
		ident = index2ident(index, NULL);
		break;
	case CONNMAN_DEVICE_TYPE_BLUETOOTH:
		break;
	case CONNMAN_DEVICE_TYPE_CELLULAR:
		ident = index2ident(index, NULL);
		break;
	case CONNMAN_DEVICE_TYPE_QMI:
	case CONNMAN_DEVICE_TYPE_MK3:
		ident = index2ident(index, NULL);
		break;
	}

	connman_device_set_index(device, index);
	connman_device_set_interface(device, devname);

	if (ident != NULL) {
		connman_device_set_ident(device, ident);
		g_free(ident);
	}

	connman_device_set_string(device, "Address", addr);

done:
	g_free(devname);
	g_free(name);
	g_free(addr);

	return device;
}
Exemple #8
0
static void append_notify(DBusMessageIter *dict,
                          struct connman_session *session)
{
    struct session_info *info = session->info;
    struct session_info *info_last = session->info_last;
    struct connman_service *service;
    enum connman_service_type type;
    const char *name, *bearer;
    char *ifname;
    int idx;

    if (session->append_all || info->state != info_last->state) {
        const char *state = state2string(info->state);

        connman_dbus_dict_append_basic(dict, "State",
                                       DBUS_TYPE_STRING,
                                       &state);
        info_last->state = info->state;
    }

    if (session->append_all || session->service != session->service_last) {
        if (session->service) {
            service = session->service;
            name = __connman_service_get_name(service);
            idx = __connman_service_get_index(service);

            ifname = connman_inet_ifname(idx);
            if (!ifname)
                ifname = g_strdup("");

            type = connman_service_get_type(service);
            bearer = service2bearer(type);
        } else {
            service = NULL;
            name = "";
            ifname = g_strdup("");
            bearer = "";
        }

        connman_dbus_dict_append_basic(dict, "Name",
                                       DBUS_TYPE_STRING,
                                       &name);

        connman_dbus_dict_append_dict(dict, "IPv4",
                                      append_ipconfig_ipv4,
                                      service);

        connman_dbus_dict_append_dict(dict, "IPv6",
                                      append_ipconfig_ipv6,
                                      service);

        connman_dbus_dict_append_basic(dict, "Interface",
                                       DBUS_TYPE_STRING,
                                       &ifname);

        connman_dbus_dict_append_basic(dict, "Bearer",
                                       DBUS_TYPE_STRING,
                                       &bearer);

        g_free(ifname);

        session->service_last = session->service;
    }

    if (session->append_all ||
            info->config.type != info_last->config.type) {
        const char *type = type2string(info->config.type);

        connman_dbus_dict_append_basic(dict, "ConnectionType",
                                       DBUS_TYPE_STRING,
                                       &type);
        info_last->config.type = info->config.type;
    }

    if (session->append_all ||
            info->config.allowed_bearers != info_last->config.allowed_bearers) {
        connman_dbus_dict_append_array(dict, "AllowedBearers",
                                       DBUS_TYPE_STRING,
                                       append_allowed_bearers,
                                       info);
        info_last->config.allowed_bearers = info->config.allowed_bearers;
    }

    session->append_all = false;
}
Exemple #9
0
static void read_uevent(struct interface_data *interface)
{
	char *filename, *name, line[128];
	bool found_devtype;
	FILE *f;

	name = connman_inet_ifname(interface->index);

	if (ether_blacklisted(name)) {
		interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
		interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
	} else {
		interface->service_type = CONNMAN_SERVICE_TYPE_ETHERNET;
		interface->device_type = CONNMAN_DEVICE_TYPE_ETHERNET;
	}

	filename = g_strdup_printf("/sys/class/net/%s/uevent", name);

	f = fopen(filename, "re");

	g_free(filename);

	if (!f) {
		interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
		interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
		goto out;
	}

	found_devtype = false;
	while (fgets(line, sizeof(line), f)) {
		char *pos;

		pos = strchr(line, '\n');
		if (!pos)
			continue;
		pos[0] = '\0';

		if (strncmp(line, "DEVTYPE=", 8) != 0)
			continue;

		found_devtype = true;

		if (strcmp(line + 8, "wlan") == 0) {
			interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
			interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;
		} else if (strcmp(line + 8, "wwan") == 0) {
			interface->service_type = CONNMAN_SERVICE_TYPE_CELLULAR;
			interface->device_type = CONNMAN_DEVICE_TYPE_CELLULAR;
		} else if (strcmp(line + 8, "bluetooth") == 0) {
			interface->service_type = CONNMAN_SERVICE_TYPE_BLUETOOTH;
			interface->device_type = CONNMAN_DEVICE_TYPE_BLUETOOTH;
		} else if (strcmp(line + 8, "gadget") == 0) {
			interface->service_type = CONNMAN_SERVICE_TYPE_GADGET;
			interface->device_type = CONNMAN_DEVICE_TYPE_GADGET;

		} else {
			interface->service_type = CONNMAN_SERVICE_TYPE_UNKNOWN;
			interface->device_type = CONNMAN_DEVICE_TYPE_UNKNOWN;
		}
	}

	fclose(f);

	if (found_devtype)
		goto out;

	/* We haven't got a DEVTYPE, let's check if it's a wireless device */
	if (wext_interface(name)) {
		interface->service_type = CONNMAN_SERVICE_TYPE_WIFI;
		interface->device_type = CONNMAN_DEVICE_TYPE_WIFI;

		connman_error("%s runs an unsupported 802.11 driver", name);
	}

out:
	g_free(name);
}