예제 #1
0
파일: dhcp.c 프로젝트: Pillar1989/connman
/**
 * dhcp_invalidate: Invalidate an existing DHCP lease
 * @dhcp: pointer to the DHCP lease to invalidate.
 * @callback: flag indicating whether or not to invoke the client callback
 *            if present.
 *
 * Invalidates an existing DHCP lease, optionally invoking the client
 * callback. The caller may wish to avoid the client callback invocation
 * when the invocation of that callback might otherwise unnecessarily upset
 * service state due to the IP configuration change implied by this
 * invalidation.
 */
static void dhcp_invalidate(struct connman_dhcp *dhcp, bool callback)
{
	DBG("dhcp %p callback %u", dhcp, callback);

	if (!dhcp)
		return;

	__connman_6to4_remove(dhcp->ipconfig);

	if (!apply_dhcp_invalidate_on_network(dhcp))
		return;

	__connman_ipconfig_set_dhcp_address(dhcp->ipconfig,
				__connman_ipconfig_get_local(dhcp->ipconfig));
	DBG("last address %s",
			__connman_ipconfig_get_dhcp_address(dhcp->ipconfig));

	__connman_ipconfig_address_remove(dhcp->ipconfig);

	__connman_ipconfig_set_local(dhcp->ipconfig, NULL);
	__connman_ipconfig_set_broadcast(dhcp->ipconfig, NULL);
	__connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
	__connman_ipconfig_set_prefixlen(dhcp->ipconfig, 0);

	if (dhcp->callback && callback)
		dhcp->callback(dhcp->ipconfig, dhcp->network,
						false, dhcp->user_data);
}
예제 #2
0
/**
 * dhcp_invalidate: Invalidate an existing DHCP lease
 * @dhcp: pointer to the DHCP lease to invalidate.
 * @callback: flag indicating whether or not to invoke the client callback
 *            if present.
 *
 * Invalidates an existing DHCP lease, optionally invoking the client
 * callback. The caller may wish to avoid the client callback invocation
 * when the invocation of that callback might otherwise unnecessarily upset
 * service state due to the IP configuration change implied by this
 * invalidation.
 */
static void dhcp_invalidate(struct connman_dhcp *dhcp, connman_bool_t callback)
{
	struct connman_service *service;
	struct connman_ipconfig *ipconfig;
	int i;

	DBG("dhcp %p callback %u", dhcp, callback);

	if (dhcp == NULL)
		return;

	service = connman_service_lookup_from_network(dhcp->network);
	if (service == NULL)
		goto out;

	ipconfig = __connman_service_get_ip4config(service);
	if (ipconfig == NULL)
		goto out;

	__connman_6to4_remove(ipconfig);

	__connman_service_set_domainname(service, NULL);
	__connman_service_set_pac(service, NULL);

	if (dhcp->timeservers != NULL) {
		for (i = 0; dhcp->timeservers[i] != NULL; i++) {
			__connman_service_timeserver_remove(service,
							dhcp->timeservers[i]);
		}
	}

	if (dhcp->nameservers != NULL) {
		for (i = 0; dhcp->nameservers[i] != NULL; i++) {
			__connman_service_nameserver_remove(service,
						dhcp->nameservers[i], FALSE);
		}
	}

	__connman_ipconfig_set_dhcp_address(ipconfig,
				__connman_ipconfig_get_local(ipconfig));
	DBG("last address %s", __connman_ipconfig_get_dhcp_address(ipconfig));

	__connman_ipconfig_address_remove(ipconfig);

	__connman_ipconfig_set_local(ipconfig, NULL);
	__connman_ipconfig_set_broadcast(ipconfig, NULL);
	__connman_ipconfig_set_gateway(ipconfig, NULL);
	__connman_ipconfig_set_prefixlen(ipconfig, 0);

	if (dhcp->callback != NULL && callback)
		dhcp->callback(dhcp->network, FALSE, NULL);

out:
	dhcp_free(dhcp);
}
int connman_network_set_ipaddress(struct connman_network *network,
					struct connman_ipaddress *ipaddress)
{
	struct connman_service *service;
	struct connman_ipconfig *ipconfig = NULL;

	DBG("network %p", network);

	service = __connman_service_lookup_from_network(network);
	if (service == NULL)
		return -EINVAL;

	ipconfig = __connman_service_get_ipconfig(service, ipaddress->family);
	if (ipconfig == NULL)
		return -EINVAL;

	__connman_ipconfig_set_local(ipconfig, ipaddress->local);
	__connman_ipconfig_set_peer(ipconfig, ipaddress->peer);
	__connman_ipconfig_set_broadcast(ipconfig, ipaddress->broadcast);
	__connman_ipconfig_set_prefixlen(ipconfig, ipaddress->prefixlen);
	__connman_ipconfig_set_gateway(ipconfig, ipaddress->gateway);

	return 0;
}