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); }
static void ipv4ll_stop_client(struct connman_dhcp *dhcp) { if (!dhcp->ipv4ll_client) return; g_dhcp_client_stop(dhcp->ipv4ll_client); g_dhcp_client_unref(dhcp->ipv4ll_client); dhcp->ipv4ll_client = NULL; ipv4ll_running = false; g_free(dhcp->ipv4ll_debug_prefix); dhcp->ipv4ll_debug_prefix = NULL; }
static int dhcp_release(struct connman_dhcp *dhcp) { DBG("dhcp %p", dhcp); if (dhcp->dhcp_client == NULL) return 0; g_dhcp_client_stop(dhcp->dhcp_client); g_dhcp_client_unref(dhcp->dhcp_client); dhcp->dhcp_client = NULL; return 0; }
static int dhcp_release(struct connman_dhcp *dhcp) { DBG("dhcp %p", dhcp); if (dhcp->timeout > 0) { g_source_remove(dhcp->timeout); dhcp->timeout = 0; } if (dhcp->dhcp_client) { g_dhcp_client_stop(dhcp->dhcp_client); g_dhcp_client_unref(dhcp->dhcp_client); } dhcp->dhcp_client = NULL; g_free(dhcp->dhcp_debug_prefix); dhcp->dhcp_debug_prefix = NULL; ipv4ll_stop_client(dhcp); return 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); }
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; }