Ejemplo n.º 1
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, 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);
}
Ejemplo n.º 2
0
static int dhcp_request(struct connman_dhcp *dhcp)
{
	struct connman_service *service;
	struct connman_ipconfig *ipconfig;
	GDHCPClient *dhcp_client;
	GDHCPClientError error;
	const char *hostname;
	int index;

	DBG("dhcp %p", dhcp);

	index = connman_network_get_index(dhcp->network);

	dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
	if (error != G_DHCP_CLIENT_ERROR_NONE)
		return -EINVAL;

	if (getenv("CONNMAN_DHCP_DEBUG"))
		g_dhcp_client_set_debug(dhcp_client, dhcp_debug, "DHCP");

	hostname = connman_utsname_get_hostname();
	if (hostname != NULL)
		g_dhcp_client_set_send(dhcp_client, G_DHCP_HOST_NAME, hostname);

	g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
	g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
	g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
	g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
	g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
	g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
	g_dhcp_client_set_request(dhcp_client, 252);

	g_dhcp_client_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
						lease_available_cb, dhcp);

	g_dhcp_client_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
						ipv4ll_available_cb, dhcp);

	g_dhcp_client_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);

	g_dhcp_client_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);

	g_dhcp_client_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);

	dhcp->dhcp_client = dhcp_client;

	service = __connman_service_lookup_from_network(dhcp->network);
	ipconfig = __connman_service_get_ip4config(service);

	return g_dhcp_client_start(dhcp_client,
				__connman_ipconfig_get_dhcp_address(ipconfig));
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
static gboolean dhcp_retry_cb(gpointer user_data)
{
	struct connman_dhcp *dhcp = user_data;

	dhcp->timeout = 0;

	g_dhcp_client_start(dhcp->dhcp_client,
			__connman_ipconfig_get_dhcp_address(dhcp->ipconfig));

	return FALSE;
}
Ejemplo n.º 5
0
int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
			struct connman_network *network, dhcp_cb callback,
			gpointer user_data)
{
	const char *last_addr = NULL;
	struct connman_dhcp *dhcp;
	int err;

	DBG("");

	if (network) {
		struct connman_service *service;

		service = connman_service_lookup_from_network(network);
		if (!service)
			return -EINVAL;
	}

	last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);

	dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
	if (!dhcp) {

		dhcp = g_try_new0(struct connman_dhcp, 1);
		if (!dhcp)
			return -ENOMEM;

		dhcp->ipconfig = ipconfig;
		__connman_ipconfig_ref(ipconfig);

		if (network) {
			dhcp->network = network;
			connman_network_ref(network);
		}

		err = dhcp_initialize(dhcp);

		if (err < 0) {
			if (network)
				connman_network_unref(network);
			g_free(dhcp);
			return err;
		}

		g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
	}