Esempio n. 1
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));
}
Esempio n. 2
0
static int ipv4ll_start_client(struct connman_dhcp *dhcp)
{
	GDHCPClient *ipv4ll_client;
	GDHCPClientError error;
	const char *hostname;
	int index;
	int err;

	if (dhcp->ipv4ll_client)
		return -EALREADY;

	index = __connman_ipconfig_get_index(dhcp->ipconfig);

	ipv4ll_client = g_dhcp_client_new(G_DHCP_IPV4LL, index, &error);
	if (error != G_DHCP_CLIENT_ERROR_NONE)
		return -EINVAL;

	if (getenv("CONNMAN_DHCP_DEBUG")) {
		dhcp->ipv4ll_debug_prefix = g_strdup_printf("IPv4LL index %d",
							index);
		g_dhcp_client_set_debug(ipv4ll_client, dhcp_debug,
					dhcp->ipv4ll_debug_prefix);
	}

	g_dhcp_client_set_id(ipv4ll_client);

	if (dhcp->network) {
		hostname = connman_utsname_get_hostname();
		if (hostname)
			g_dhcp_client_set_send(ipv4ll_client,
						G_DHCP_HOST_NAME, hostname);
	}

	g_dhcp_client_register_event(ipv4ll_client,
			G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);

	g_dhcp_client_register_event(ipv4ll_client,
			G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
						ipv4ll_available_cb, dhcp);

	dhcp->ipv4ll_client = ipv4ll_client;

	err = g_dhcp_client_start(dhcp->ipv4ll_client, NULL);
	if (err < 0) {
		ipv4ll_stop_client(dhcp);
		return err;
	}

	ipv4ll_running = true;
	return 0;
}
Esempio n. 3
0
static int dhcpv6_info_request(struct connman_dhcpv6 *dhcp)
{
    struct connman_service *service;
    GDHCPClient *dhcp_client;
    GDHCPClientError error;
    int index, ret;

    DBG("dhcp %p", dhcp);

    index = connman_network_get_index(dhcp->network);

    dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
    if (error != G_DHCP_CLIENT_ERROR_NONE) {
        clear_timer(dhcp);
        return -EINVAL;
    }

    if (getenv("CONNMAN_DHCPV6_DEBUG"))
        g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6");

    service = connman_service_lookup_from_network(dhcp->network);
    if (service == NULL) {
        clear_timer(dhcp);
        g_dhcp_client_unref(dhcp_client);
        return -EINVAL;
    }

    ret = set_duid(service, dhcp->network, dhcp_client, index);
    if (ret < 0) {
        clear_timer(dhcp);
        g_dhcp_client_unref(dhcp_client);
        return ret;
    }

    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);

    g_dhcpv6_client_set_oro(dhcp_client, 2, G_DHCPV6_DNS_SERVERS,
                            G_DHCPV6_SNTP_SERVERS);

    g_dhcp_client_register_event(dhcp_client,
                                 G_DHCP_CLIENT_EVENT_INFORMATION_REQ, info_req_cb, dhcp);

    dhcp->dhcp_client = dhcp_client;

    return g_dhcp_client_start(dhcp_client, NULL);
}
Esempio n. 4
0
static int dhcp_initialize(struct connman_dhcp *dhcp)
{
	GDHCPClient *dhcp_client;
	GDHCPClientError error;
	int index;

	DBG("dhcp %p", dhcp);

	index = __connman_ipconfig_get_index(dhcp->ipconfig);

	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")) {
		dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
							index);
		g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
					dhcp->dhcp_debug_prefix);
	}

	g_dhcp_client_set_id(dhcp_client);

	if (dhcp->network) {
		struct connman_service *service;
		const char *hostname;

		service = connman_service_lookup_from_network(dhcp->network);

		hostname = __connman_service_get_hostname(service);
		if (!hostname)
			hostname = connman_utsname_get_hostname();

		if (hostname)
			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_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, 252);
		g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU);
	}

	g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
	g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);

	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_LEASE_LOST, lease_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;

	return 0;
}
Esempio n. 5
0
static int dhcpv6_solicitation(struct connman_dhcpv6 *dhcp)
{
    struct connman_service *service;
    struct connman_ipconfig *ipconfig_ipv6;
    GDHCPClient *dhcp_client;
    GDHCPClientError error;
    int index, ret;

    DBG("dhcp %p", dhcp);

    index = connman_network_get_index(dhcp->network);

    dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
    if (error != G_DHCP_CLIENT_ERROR_NONE) {
        clear_timer(dhcp);
        return -EINVAL;
    }

    if (getenv("CONNMAN_DHCPV6_DEBUG"))
        g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6");

    service = connman_service_lookup_from_network(dhcp->network);
    if (service == NULL) {
        clear_timer(dhcp);
        g_dhcp_client_unref(dhcp_client);
        return -EINVAL;
    }

    ret = set_duid(service, dhcp->network, dhcp_client, index);
    if (ret < 0) {
        clear_timer(dhcp);
        g_dhcp_client_unref(dhcp_client);
        return ret;
    }

    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_RAPID_COMMIT);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);

    g_dhcpv6_client_set_oro(dhcp_client, 2, G_DHCPV6_DNS_SERVERS,
                            G_DHCPV6_SNTP_SERVERS);

    ipconfig_ipv6 = __connman_service_get_ip6config(service);
    dhcp->use_ta = __connman_ipconfig_ipv6_privacy_enabled(ipconfig_ipv6);

    g_dhcpv6_client_set_ia(dhcp_client, index,
                           dhcp->use_ta == TRUE ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
                           NULL, NULL, FALSE);

    clear_callbacks(dhcp_client);

    g_dhcp_client_register_event(dhcp_client,
                                 G_DHCP_CLIENT_EVENT_SOLICITATION,
                                 solicitation_cb, dhcp);

    g_dhcp_client_register_event(dhcp_client,
                                 G_DHCP_CLIENT_EVENT_ADVERTISE,
                                 advertise_cb, dhcp);

    dhcp->dhcp_client = dhcp_client;

    return g_dhcp_client_start(dhcp_client, NULL);
}