Example #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;
}
Example #2
0
File: wispr.c Project: igaw/connman
int __connman_wispr_start(struct connman_service *service,
					enum connman_ipconfig_type type)
{
	struct connman_wispr_portal_context *wp_context = NULL;
	struct connman_wispr_portal *wispr_portal = NULL;
	int index;

	DBG("service %p", service);

	if (!wispr_portal_list)
		return -EINVAL;

	index = __connman_service_get_index(service);
	if (index < 0)
		return -EINVAL;

	wispr_portal = g_hash_table_lookup(wispr_portal_list,
					GINT_TO_POINTER(index));
	if (!wispr_portal) {
		wispr_portal = g_try_new0(struct connman_wispr_portal, 1);
		if (!wispr_portal)
			return -ENOMEM;

		g_hash_table_replace(wispr_portal_list,
					GINT_TO_POINTER(index), wispr_portal);
	}
Example #3
0
int __connman_wpad_start(struct connman_service *service)
{
	struct connman_wpad *wpad;
	const char *domainname;
	char **nameservers;
	int index;
	int i;

	DBG("service %p", service);

	if (!wpad_list)
		return -EINVAL;

	index = __connman_service_get_index(service);
	if (index < 0)
		return -EINVAL;

	domainname = connman_service_get_domainname(service);
	if (!domainname)
		return -EINVAL;

	nameservers = connman_service_get_nameservers(service);
	if (!nameservers)
		return -EINVAL;

	wpad = g_try_new0(struct connman_wpad, 1);
	if (!wpad) {
		g_strfreev(nameservers);
		return -ENOMEM;
	}

	wpad->service = service;
	wpad->resolv = g_resolv_new(index);
	if (!wpad->resolv) {
		g_strfreev(nameservers);
		g_free(wpad);
		return -ENOMEM;
	}

	if (getenv("CONNMAN_RESOLV_DEBUG"))
		g_resolv_set_debug(wpad->resolv, resolv_debug, "RESOLV");

	for (i = 0; nameservers[i]; i++)
		g_resolv_add_nameserver(wpad->resolv, nameservers[i], 53, 0);

	g_strfreev(nameservers);

	wpad->hostname = g_strdup_printf("wpad.%s", domainname);

	DBG("hostname %s", wpad->hostname);

	g_resolv_lookup_hostname(wpad->resolv, wpad->hostname,
							wpad_result, wpad);

	connman_service_ref(service);
	g_hash_table_replace(wpad_list, GINT_TO_POINTER(index), wpad);

	return 0;
}
Example #4
0
void __connman_wpad_stop(struct connman_service *service)
{
	int index;

	DBG("service %p", service);

	if (!wpad_list)
		return;

	index = __connman_service_get_index(service);
	if (index < 0)
		return;

	if (g_hash_table_remove(wpad_list, GINT_TO_POINTER(index)))
		connman_service_unref(service);
}
Example #5
0
static int timeserver_start(struct connman_service *service)
{
	char **nameservers;
	int i;

	DBG("service %p", service);

	i = __connman_service_get_index(service);
	if (i < 0)
		return -EINVAL;

	nameservers = connman_service_get_nameservers(service);
	if (!nameservers)
		return -EINVAL;

	/* Stop an already ongoing resolution, if there is one */
	if (resolv && resolv_id > 0)
		g_resolv_cancel_lookup(resolv, resolv_id);

	/* get rid of the old resolver */
	if (resolv) {
		g_resolv_unref(resolv);
		resolv = NULL;
	}

	resolv = g_resolv_new(i);
	if (!resolv) {
		g_strfreev(nameservers);
		return -ENOMEM;
	}

	if (getenv("CONNMAN_RESOLV_DEBUG"))
		g_resolv_set_debug(resolv, resolv_debug, "RESOLV");

	for (i = 0; nameservers[i]; i++)
		g_resolv_add_nameserver(resolv, nameservers[i], 53, 0);

	g_strfreev(nameservers);

	return __connman_timeserver_sync(service);
}
Example #6
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;
}
Example #7
0
int __connman_connection_gateway_add(struct connman_service *service,
					const char *gateway,
					enum connman_ipconfig_type type,
					const char *peer)
{
	struct gateway_data *active_gateway = NULL;
	struct gateway_data *new_gateway = NULL;
	enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
		type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
	enum connman_service_type service_type =
					connman_service_get_type(service);
	int index;

	index = __connman_service_get_index(service);

	/*
	 * If gateway is NULL, it's a point to point link and the default
	 * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
	 * interface
	 */
	if (!gateway && type == CONNMAN_IPCONFIG_TYPE_IPV4)
		gateway = "0.0.0.0";

	if (!gateway && type == CONNMAN_IPCONFIG_TYPE_IPV6)
		gateway = "::";

	DBG("service %p index %d gateway %s vpn ip %s type %d",
		service, index, gateway, peer, type);

	new_gateway = add_gateway(service, index, gateway, type);
	if (!new_gateway)
		return -EINVAL;

	active_gateway = find_active_gateway();

	DBG("active %p index %d new %p", active_gateway,
		active_gateway ? active_gateway->index : -1, new_gateway);

	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
				new_gateway->ipv4_gateway) {
		add_host_route(AF_INET, index, gateway, service_type);
		__connman_service_nameserver_add_routes(service,
					new_gateway->ipv4_gateway->gateway);
		type4 = CONNMAN_IPCONFIG_TYPE_IPV4;
	}

	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
				new_gateway->ipv6_gateway) {
		add_host_route(AF_INET6, index, gateway, service_type);
		__connman_service_nameserver_add_routes(service,
					new_gateway->ipv6_gateway->gateway);
		type6 = CONNMAN_IPCONFIG_TYPE_IPV6;
	}

	if (service_type == CONNMAN_SERVICE_TYPE_VPN) {

		set_vpn_routes(new_gateway, service, gateway, type, peer,
							active_gateway);

	} else {
		if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
					new_gateway->ipv4_gateway)
			new_gateway->ipv4_gateway->vpn = false;

		if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
					new_gateway->ipv6_gateway)
			new_gateway->ipv6_gateway->vpn = false;
	}

	if (!active_gateway) {
		set_default_gateway(new_gateway, type);
		goto done;
	}

	if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
				new_gateway->ipv4_gateway &&
				new_gateway->ipv4_gateway->vpn) {
		if (!__connman_service_is_split_routing(new_gateway->service))
			connman_inet_clear_gateway_address(
					active_gateway->index,
					active_gateway->ipv4_gateway->gateway);
	}

	if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
				new_gateway->ipv6_gateway &&
				new_gateway->ipv6_gateway->vpn) {
		if (!__connman_service_is_split_routing(new_gateway->service))
			connman_inet_clear_ipv6_gateway_address(
					active_gateway->index,
					active_gateway->ipv6_gateway->gateway);
	}

done:
	if (type4 == CONNMAN_IPCONFIG_TYPE_IPV4)
		__connman_service_ipconfig_indicate_state(service,
						CONNMAN_SERVICE_STATE_READY,
						CONNMAN_IPCONFIG_TYPE_IPV4);

	if (type6 == CONNMAN_IPCONFIG_TYPE_IPV6)
		__connman_service_ipconfig_indicate_state(service,
						CONNMAN_SERVICE_STATE_READY,
						CONNMAN_IPCONFIG_TYPE_IPV6);
	return 0;
}
Example #8
0
static void unset_default_gateway(struct gateway_data *data,
				enum connman_ipconfig_type type)
{
	int index;
	bool do_ipv4 = false, do_ipv6 = false;

	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
		do_ipv4 = true;
	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
		do_ipv6 = true;
	else
		do_ipv4 = do_ipv6 = true;

	DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway,
						data->ipv6_gateway);

	if (do_ipv4 && data->ipv4_gateway &&
					data->ipv4_gateway->vpn) {
		connman_inet_clear_gateway_interface(data->index);
		data->ipv4_gateway->active = false;

		DBG("unset %p index %d vpn %s index %d phy %s",
			data, data->index, data->ipv4_gateway->vpn_ip,
			data->ipv4_gateway->vpn_phy_index,
			data->ipv4_gateway->vpn_phy_ip);

		return;
	}

	if (do_ipv6 && data->ipv6_gateway &&
					data->ipv6_gateway->vpn) {
		connman_inet_clear_ipv6_gateway_interface(data->index);
		data->ipv6_gateway->active = false;

		DBG("unset %p index %d vpn %s index %d phy %s",
			data, data->index, data->ipv6_gateway->vpn_ip,
			data->ipv6_gateway->vpn_phy_index,
			data->ipv6_gateway->vpn_phy_ip);

		return;
	}

	index = __connman_service_get_index(data->service);

	if (do_ipv4 && data->ipv4_gateway &&
			g_strcmp0(data->ipv4_gateway->gateway,
							"0.0.0.0") == 0) {
		connman_inet_clear_gateway_interface(index);
		return;
	}

	if (do_ipv6 && data->ipv6_gateway &&
			g_strcmp0(data->ipv6_gateway->gateway,
							"::") == 0) {
		connman_inet_clear_ipv6_gateway_interface(index);
		return;
	}

	if (do_ipv6 && data->ipv6_gateway)
		connman_inet_clear_ipv6_gateway_address(index,
						data->ipv6_gateway->gateway);

	if (do_ipv4 && data->ipv4_gateway)
		connman_inet_clear_gateway_address(index,
						data->ipv4_gateway->gateway);
}
Example #9
0
static void set_default_gateway(struct gateway_data *data,
				enum connman_ipconfig_type type)
{
	int index;
	int status4 = 0, status6 = 0;
	bool do_ipv4 = false, do_ipv6 = false;

	if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
		do_ipv4 = true;
	else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
		do_ipv6 = true;
	else
		do_ipv4 = do_ipv6 = true;

	DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway,
						data->ipv6_gateway);

	if (do_ipv4 && data->ipv4_gateway &&
					data->ipv4_gateway->vpn) {
		connman_inet_set_gateway_interface(data->index);
		data->ipv4_gateway->active = true;

		DBG("set %p index %d vpn %s index %d phy %s",
			data, data->index, data->ipv4_gateway->vpn_ip,
			data->ipv4_gateway->vpn_phy_index,
			data->ipv4_gateway->vpn_phy_ip);

		__connman_service_indicate_default(data->service);

		return;
	}

	if (do_ipv6 && data->ipv6_gateway &&
					data->ipv6_gateway->vpn) {
		connman_inet_set_ipv6_gateway_interface(data->index);
		data->ipv6_gateway->active = true;

		DBG("set %p index %d vpn %s index %d phy %s",
			data, data->index, data->ipv6_gateway->vpn_ip,
			data->ipv6_gateway->vpn_phy_index,
			data->ipv6_gateway->vpn_phy_ip);

		__connman_service_indicate_default(data->service);

		return;
	}

	index = __connman_service_get_index(data->service);

	if (do_ipv4 && data->ipv4_gateway &&
			g_strcmp0(data->ipv4_gateway->gateway,
							"0.0.0.0") == 0) {
		if (connman_inet_set_gateway_interface(index) < 0)
			return;
		goto done;
	}

	if (do_ipv6 && data->ipv6_gateway &&
			g_strcmp0(data->ipv6_gateway->gateway,
							"::") == 0) {
		if (connman_inet_set_ipv6_gateway_interface(index) < 0)
			return;
		goto done;
	}

	if (do_ipv6 && data->ipv6_gateway)
		status6 = __connman_inet_add_default_to_table(RT_TABLE_MAIN,
					index, data->ipv6_gateway->gateway);

	if (do_ipv4 && data->ipv4_gateway)
		status4 = __connman_inet_add_default_to_table(RT_TABLE_MAIN,
					index, data->ipv4_gateway->gateway);

	if (status4 < 0 || status6 < 0)
		return;

done:
	__connman_service_indicate_default(data->service);
}