Exemplo n.º 1
0
static int dhcpv6_rebind(struct connman_dhcpv6 *dhcp)
{
    GDHCPClient *dhcp_client;

    DBG("dhcp %p", dhcp);

    dhcp_client = dhcp->dhcp_client;

    g_dhcp_client_clear_requests(dhcp_client);

    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_dhcpv6_client_set_ia(dhcp_client,
                           connman_network_get_index(dhcp->network),
                           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_REBIND,
                                 rebind_cb, dhcp);

    dhcp->dhcp_client = dhcp_client;

    return g_dhcp_client_start(dhcp_client, NULL);
}
Exemplo n.º 2
0
static int dhcpv6_renew(struct connman_dhcpv6 *dhcp)
{
    GDHCPClient *dhcp_client;
    uint32_t T1, T2;

    DBG("dhcp %p", dhcp);

    dhcp_client = dhcp->dhcp_client;

    g_dhcp_client_clear_requests(dhcp_client);

    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
    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_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL, NULL);
    g_dhcpv6_client_set_ia(dhcp_client,
                           connman_network_get_index(dhcp->network),
                           dhcp->use_ta == TRUE ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
                           &T1, &T2, TRUE);

    clear_callbacks(dhcp_client);

    g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RENEW,
                                 renew_cb, dhcp);

    dhcp->dhcp_client = dhcp_client;

    return g_dhcp_client_start(dhcp_client, NULL);
}
Exemplo n.º 3
0
int __connman_dhcpv6_start_release(struct connman_network *network,
                                   dhcp_cb callback)
{
    struct connman_dhcpv6 *dhcp;
    GDHCPClient *dhcp_client;

    if (network_table == NULL)
        return 0;   /* we are already released */

    dhcp = g_hash_table_lookup(network_table, network);
    if (dhcp == NULL)
        return -ENOENT;

    DBG("network %p dhcp %p client %p stateless %d", network, dhcp,
        dhcp->dhcp_client, dhcp->stateless);

    if (dhcp->stateless == TRUE)
        return -EINVAL;

    clear_timer(dhcp);

    dhcp_client = dhcp->dhcp_client;
    if (dhcp_client == NULL) {
        /*
         * We had started the DHCPv6 handshaking i.e., we have called
         * __connman_dhcpv6_start() but it has not yet sent
         * a solicitation message to server. This means that we do not
         * have DHCPv6 configured yet so we can just quit here.
         */
        DBG("DHCPv6 was not started");
        return 0;
    }

    g_dhcp_client_clear_requests(dhcp_client);
    g_dhcp_client_clear_values(dhcp_client);

    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
    g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);

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

    clear_callbacks(dhcp_client);

    /*
     * We do not register callback here because the answer might take too
     * long time and network code might be in the middle of the disconnect.
     * So we just inform the server that we are done with the addresses
     * but ignore the reply from server. This is allowed by RFC 3315
     * chapter 18.1.6.
     */

    dhcp->dhcp_client = dhcp_client;

    return g_dhcp_client_start(dhcp_client, NULL);
}
Exemplo n.º 4
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));
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
static gboolean timeout_info_req(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    dhcp->RT = calc_delay(dhcp->RT, INF_MAX_RT);

    DBG("info RT timeout %d msec", dhcp->RT);

    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_info_req, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Exemplo n.º 8
0
static gboolean timeout_solicitation(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    dhcp->RT = calc_delay(dhcp->RT, SOL_MAX_RT);

    DBG("solicit RT timeout %d msec", dhcp->RT);

    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
static gboolean timeout_renew(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    if (check_restart(dhcp) < 0)
        return FALSE;

    dhcp->RT = calc_delay(dhcp->RT, REN_MAX_RT);

    DBG("renew RT timeout %d msec", dhcp->RT);

    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Exemplo n.º 11
0
static gboolean timeout_request(gpointer user_data)
{
    struct connman_dhcpv6 *dhcp = user_data;

    if (dhcp->request_count >= REQ_MAX_RC) {
        DBG("max request retry attempts %d", dhcp->request_count);
        dhcp->request_count = 0;
        if (dhcp->callback != NULL)
            dhcp->callback(dhcp->network, FALSE);
        return FALSE;
    }

    dhcp->request_count++;

    dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
    DBG("request RT timeout %d msec", dhcp->RT);
    dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request, dhcp);

    g_dhcp_client_start(dhcp->dhcp_client, NULL);

    return FALSE;
}
Exemplo n.º 12
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);
}
Exemplo n.º 13
0
int main(int argc, char *argv[])
{
	struct sigaction sa;
	GDHCPClientError error;
	GDHCPClient *dhcp_client;
	int index;

	if (argc < 2) {
		printf("Usage: dhcp-test <interface index>\n");
		exit(0);
	}

	index = atoi(argv[1]);

	printf("Create DHCP client for interface %d\n", index);

	dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
	if (dhcp_client == NULL) {
		handle_error(error);
		exit(0);
	}

	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_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
						lease_available_cb, NULL);

	g_dhcp_client_register_event(dhcp_client,
			G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, NULL);

	main_loop = g_main_loop_new(NULL, FALSE);

	printf("Start DHCP operation\n");

	timer = g_timer_new();

	g_dhcp_client_start(dhcp_client, NULL);

	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = sig_term;
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);

	g_main_loop_run(main_loop);

	g_timer_destroy(timer);

	g_dhcp_client_unref(dhcp_client);

	g_main_loop_unref(main_loop);

	return 0;
}