示例#1
0
static int append_resolver(const char *interface, const char *domain,
				const char *server, unsigned int lifetime,
							unsigned int flags)
{
	struct entry_data *entry;

	DBG("interface %s domain %s server %s lifetime %d flags %d",
				interface, domain, server, lifetime, flags);

	if (server == NULL && domain == NULL)
		return -EINVAL;

	entry = g_try_new0(struct entry_data, 1);
	if (entry == NULL)
		return -ENOMEM;

	entry->interface = g_strdup(interface);
	entry->domain = g_strdup(domain);
	entry->server = g_strdup(server);
	entry->flags = flags;
	if (lifetime)
		entry->timeout = g_timeout_add_seconds(lifetime,
						resolver_expire_cb, entry);

	entry_list = g_slist_append(entry_list, entry);

	if (dnsproxy_enabled == TRUE)
		__connman_dnsproxy_append(interface, domain, server);
	else
		__connman_resolvfile_append(interface, domain, server);

	return 0;
}
示例#2
0
文件: resolver.c 项目: intgr/connman
static int append_resolver(const char *interface, const char *domain,
				const char *server, unsigned int lifetime,
							unsigned int flags)
{
	struct entry_data *entry;
	unsigned int interval;

	DBG("interface %s domain %s server %s lifetime %d flags %d",
				interface, domain, server, lifetime, flags);

	if (server == NULL && domain == NULL)
		return -EINVAL;

	entry = g_try_new0(struct entry_data, 1);
	if (entry == NULL)
		return -ENOMEM;

	entry->interface = g_strdup(interface);
	entry->domain = g_strdup(domain);
	entry->server = g_strdup(server);
	entry->flags = flags;
	entry->lifetime = lifetime;

	if (server != NULL)
		entry->family = connman_inet_check_ipaddress(server);

	if (lifetime) {
		int index;
		interval = lifetime * RESOLVER_LIFETIME_REFRESH_THRESHOLD;

		DBG("RDNSS start interface %s domain %s "
				"server %s lifetime threshold %d",
				interface, domain, server, interval);

		entry->timeout = g_timeout_add_seconds(interval,
				resolver_refresh_cb, entry);

		/*
		 * We update the service only for those nameservers
		 * that are automagically added via netlink (lifetime > 0)
		 */
		index = connman_inet_ifindex(interface);
		if (server != NULL && index >= 0) {
			struct connman_service *service;
			service = __connman_service_lookup_from_index(index);
			if (service != NULL)
				__connman_service_nameserver_append(service,
								server, TRUE);
		}
	}
	entry_list = g_slist_append(entry_list, entry);

	if (dnsproxy_enabled == TRUE)
		__connman_dnsproxy_append(interface, domain, server);
	else
		__connman_resolvfile_append(interface, domain, server);

	return 0;
}
示例#3
0
static int append_resolver(const char *interface, const char *domain,
				const char *server, unsigned int lifetime,
							unsigned int flags)
{
	struct entry_data *entry;

	DBG("interface %s domain %s server %s lifetime %d flags %d",
				interface, domain, server, lifetime, flags);

	if (server == NULL && domain == NULL)
		return -EINVAL;

	entry = g_try_new0(struct entry_data, 1);
	if (entry == NULL)
		return -ENOMEM;

	entry->interface = g_strdup(interface);
	entry->domain = g_strdup(domain);
	entry->server = g_strdup(server);
	entry->flags = flags;
	if (lifetime) {
		int index;
		entry->timeout = g_timeout_add_seconds(lifetime,
						resolver_expire_cb, entry);

		/*
		 * We update the service only for those nameservers
		 * that are automagically added via netlink (lifetime > 0)
		 */
		index = connman_inet_ifindex(interface);
		if (index >= 0) {
			struct connman_service *service;
			service = __connman_service_lookup_from_index(index);
			if (service != NULL)
				__connman_service_nameserver_append(service,
								server, TRUE);
		}
	}
	entry_list = g_slist_append(entry_list, entry);

	if (dnsproxy_enabled == TRUE)
		__connman_dnsproxy_append(interface, domain, server);
	else
		__connman_resolvfile_append(interface, domain, server);

	return 0;
}
示例#4
0
文件: resolver.c 项目: intgr/connman
int __connman_resolver_redo_servers(const char *interface)
{
	GSList *list;

	if (dnsproxy_enabled == FALSE)
		return 0;

	DBG("interface %s", interface);

	if (interface == NULL)
		return -EINVAL;

	for (list = entry_list; list; list = list->next) {
		struct entry_data *entry = list->data;

		if (entry->timeout == 0 ||
				g_strcmp0(entry->interface, interface) != 0)
			continue;

		/*
		 * This function must only check IPv6 server addresses so
		 * do not remove IPv4 name servers unnecessarily.
		 */
		if (entry->family != AF_INET6)
			continue;

		/*
		 * We remove the server, and then re-create so that it will
		 * use proper source addresses when sending DNS queries.
		 */
		__connman_dnsproxy_remove(entry->interface, entry->domain,
					entry->server);
		/*
		 * Remove also the resolver timer for the old server entry.
		 * A new timer will be set for the new server entry
		 * when the next Router Advertisement message arrives
		 * with RDNSS/DNSSL settings.
		 */
		g_source_remove(entry->timeout);
		entry->timeout = 0;

		__connman_dnsproxy_append(entry->interface, entry->domain,
					entry->server);
	}

	return 0;
}