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); }
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); }
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); }
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 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)); }
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; }
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; }