5 * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <net/ethernet.h>
32 #define IPV6_MIN_MTU 1280
35 #include <connman/ipconfig.h>
36 #include <include/setting.h>
38 #include <gdhcp/gdhcp.h>
44 #define RATE_LIMIT_INTERVAL 60 /* delay between successive attempts */
47 #define DHCP_SUCCESS "DHCP_SUCCESS"
48 #define DHCP_FAIL "DHCP_FAIL"
49 #define DHCP_STARTED "DHCP_STARTED"
53 struct connman_ipconfig *ipconfig;
54 struct connman_network *network;
64 GDHCPClient *ipv4ll_client;
65 GDHCPClient *dhcp_client;
66 char *ipv4ll_debug_prefix;
67 char *dhcp_debug_prefix;
72 static GHashTable *ipconfig_table;
74 static void dhcp_free(struct connman_dhcp *dhcp)
77 DBG("dhcp_free [%p]", dhcp);
79 g_strfreev(dhcp->nameservers);
80 g_strfreev(dhcp->timeservers);
83 dhcp->nameservers = NULL;
84 dhcp->timeservers = NULL;
93 static void ipv4ll_stop_client(struct connman_dhcp *dhcp)
96 DBG("dhcp [%p] ipv4ll_client [%p]", dhcp, dhcp->ipv4ll_client);
98 if (!dhcp->ipv4ll_client)
101 g_dhcp_client_stop(dhcp->ipv4ll_client);
102 g_dhcp_client_unref(dhcp->ipv4ll_client);
103 dhcp->ipv4ll_client = NULL;
104 dhcp->ipv4ll_running = false;
106 g_free(dhcp->ipv4ll_debug_prefix);
107 dhcp->ipv4ll_debug_prefix = NULL;
110 static bool apply_dhcp_invalidate_on_network(struct connman_dhcp *dhcp)
112 struct connman_service *service;
118 service = connman_service_lookup_from_network(dhcp->network);
120 connman_error("Can not lookup service");
124 __connman_service_set_domainname(service, NULL);
125 __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig, NULL);
127 if (dhcp->timeservers) {
128 for (i = 0; dhcp->timeservers[i]; i++) {
129 __connman_service_timeserver_remove(service,
130 dhcp->timeservers[i]);
132 g_strfreev(dhcp->timeservers);
133 dhcp->timeservers = NULL;
135 if (dhcp->nameservers) {
136 for (i = 0; dhcp->nameservers[i]; i++) {
137 #if defined TIZEN_EXT
138 __connman_service_nameserver_remove(service,
139 dhcp->nameservers[i], false,
140 CONNMAN_IPCONFIG_TYPE_IPV4);
142 __connman_service_nameserver_remove(service,
143 dhcp->nameservers[i], false);
146 g_strfreev(dhcp->nameservers);
147 dhcp->nameservers = NULL;
154 * dhcp_invalidate: Invalidate an existing DHCP lease
155 * @dhcp: pointer to the DHCP lease to invalidate.
156 * @callback: flag indicating whether or not to invoke the client callback
159 * Invalidates an existing DHCP lease, optionally invoking the client
160 * callback. The caller may wish to avoid the client callback invocation
161 * when the invocation of that callback might otherwise unnecessarily upset
162 * service state due to the IP configuration change implied by this
165 static void dhcp_invalidate(struct connman_dhcp *dhcp, bool callback)
167 DBG("dhcp %p callback %u", dhcp, callback);
172 __connman_6to4_remove(dhcp->ipconfig);
174 if (!apply_dhcp_invalidate_on_network(dhcp))
177 __connman_ipconfig_set_dhcp_address(dhcp->ipconfig,
178 __connman_ipconfig_get_local(dhcp->ipconfig));
179 DBG("last address %s",
180 __connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
182 __connman_ipconfig_address_remove(dhcp->ipconfig);
184 __connman_ipconfig_set_local(dhcp->ipconfig, NULL);
185 __connman_ipconfig_set_broadcast(dhcp->ipconfig, NULL);
186 __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
187 #if defined TIZEN_EXT
188 __connman_ipconfig_set_dhcp_vsie(dhcp->ipconfig, NULL);
190 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, 0);
192 if (dhcp->callback && callback)
193 dhcp->callback(dhcp->ipconfig, dhcp->network,
194 false, dhcp->user_data);
197 static void dhcp_valid(struct connman_dhcp *dhcp)
200 dhcp->callback(dhcp->ipconfig, dhcp->network,
201 true, dhcp->user_data);
204 static void dhcp_debug(const char *str, void *data)
206 connman_info("%s: %s", (const char *) data, str);
209 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data);
210 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data);
212 static int ipv4ll_start_client(struct connman_dhcp *dhcp)
214 GDHCPClient *ipv4ll_client;
215 GDHCPClientError error;
216 const char *hostname;
220 #if defined TIZEN_EXT
221 DBG("dhcp %p", dhcp);
224 if (dhcp->ipv4ll_client)
227 index = __connman_ipconfig_get_index(dhcp->ipconfig);
229 ipv4ll_client = g_dhcp_client_new(G_DHCP_IPV4LL, index, &error);
230 if (error != G_DHCP_CLIENT_ERROR_NONE)
233 #if !defined TIZEN_EXT
234 if (getenv("CONNMAN_DHCP_DEBUG")) {
236 dhcp->ipv4ll_debug_prefix = g_strdup_printf("IPv4LL index %d",
238 g_dhcp_client_set_debug(ipv4ll_client, dhcp_debug,
239 dhcp->ipv4ll_debug_prefix);
240 #if !defined TIZEN_EXT
244 g_dhcp_client_set_id(ipv4ll_client);
247 hostname = connman_utsname_get_hostname();
249 g_dhcp_client_set_send(ipv4ll_client,
250 G_DHCP_HOST_NAME, hostname);
253 g_dhcp_client_register_event(ipv4ll_client,
254 G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);
256 g_dhcp_client_register_event(ipv4ll_client,
257 G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
258 ipv4ll_available_cb, dhcp);
260 dhcp->ipv4ll_client = ipv4ll_client;
262 err = g_dhcp_client_start(dhcp->ipv4ll_client, NULL);
264 ipv4ll_stop_client(dhcp);
268 dhcp->ipv4ll_running = true;
272 static gboolean dhcp_retry_cb(gpointer user_data)
274 struct connman_dhcp *dhcp = user_data;
278 #if defined TIZEN_EXT
279 DBG("dhcp %p", dhcp);
280 DBG("dhcp->timeout %d", dhcp->timeout);
282 g_dhcp_client_start(dhcp->dhcp_client,
283 __connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
288 static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
290 struct connman_dhcp *dhcp = user_data;
293 DBG("No lease available ipv4ll %d client %p", dhcp->ipv4ll_running,
294 dhcp->ipv4ll_client);
296 #if defined TIZEN_EXT
298 connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
300 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
301 __connman_network_enable_ipconfig(dhcp->network, dhcp->ipconfig);
302 __connman_network_notify_dhcp_changed(DHCP_FAIL,
303 g_dhcp_client_get_interface(dhcp_client));
308 if (connman_setting_get_bool("EnableAutoIp") == false) {
309 DBG("link-local address autoconfiguration is disabled.");
312 DBG("[DHCP-C] auto ip is not used, set dhcp-fail error and disconnect");
313 __connman_network_notify_dhcp_changed(DHCP_FAIL,
314 g_dhcp_client_get_interface(dhcp_client));
315 connman_network_set_error(dhcp->network, CONNMAN_NETWORK_ERROR_DHCP_FAIL);
320 if (dhcp->timeout > 0)
321 g_source_remove(dhcp->timeout);
323 dhcp->timeout = g_timeout_add_seconds(RATE_LIMIT_INTERVAL,
326 if (dhcp->ipv4ll_running)
329 err = ipv4ll_start_client(dhcp);
331 DBG("Cannot start ipv4ll client (%d/%s)", err, strerror(-err));
333 /* Only notify upper layer if we have a problem */
334 dhcp_invalidate(dhcp, !dhcp->ipv4ll_running);
337 static void lease_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
339 struct connman_dhcp *dhcp = user_data;
343 /* Upper layer will decide what to do, e.g. nothing or retry. */
344 dhcp_invalidate(dhcp, true);
347 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
349 struct connman_dhcp *dhcp = user_data;
353 ipv4ll_stop_client(dhcp);
356 * Since we lost our IPv4LL configuration we might as notify
359 dhcp_invalidate(dhcp, true);
362 static bool compare_string_arrays(char **array_a, char **array_b)
366 if (!array_a || !array_b)
369 if (g_strv_length(array_a) != g_strv_length(array_b))
372 for (i = 0; array_a[i] &&
374 if (g_strcmp0(array_a[i], array_b[i]) != 0)
381 static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
382 struct connman_dhcp *dhcp)
384 char **nameservers, **timeservers, *pac = NULL;
385 struct connman_service *service;
386 GList *list, *option = NULL;
393 service = connman_service_lookup_from_network(dhcp->network);
395 connman_error("Can not lookup service");
399 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_MTU);
400 if (option && option->data) {
403 mtu = atoi(option->data);
405 if (mtu >= IPV6_MIN_MTU && mtu <= ETH_DATA_LEN) {
406 index = __connman_ipconfig_get_index(dhcp->ipconfig);
407 err = connman_inet_set_mtu(index, mtu);
409 DBG("MTU %d index %d err %d", mtu, index, err);
413 option = g_dhcp_client_get_option(dhcp_client, 252);
415 pac = g_strdup(option->data);
417 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
418 ns_entries = g_list_length(option);
419 nameservers = g_try_new0(char *, ns_entries + 1);
421 for (i = 0, list = option;list; list = list->next, i++)
422 nameservers[i] = g_strdup(list->data);
423 nameservers[ns_entries] = NULL;
426 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
428 __connman_service_set_domainname(service, option->data);
430 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
432 __connman_service_set_hostname(service, option->data);
434 #if defined TIZEN_EXT
435 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_VENDOR_SPECIFIC_IE);
437 __connman_ipconfig_set_dhcp_vsie(dhcp->ipconfig, option->data);
440 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER);
441 ns_entries = g_list_length(option);
442 timeservers = g_try_new0(char *, ns_entries + 1);
444 for (i = 0, list = option; list; list = list->next, i++)
445 timeservers[i] = g_strdup(list->data);
446 timeservers[ns_entries] = NULL;
449 if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
450 if (dhcp->nameservers) {
451 #if defined TIZEN_EXT
452 for (i = 0; dhcp->nameservers[i] != NULL; i++) {
453 __connman_service_nameserver_remove(service,
454 dhcp->nameservers[i], false,
455 CONNMAN_IPCONFIG_TYPE_IPV4);
458 for (i = 0; dhcp->nameservers[i]; i++) {
459 __connman_service_nameserver_remove(service,
460 dhcp->nameservers[i], false);
463 g_strfreev(dhcp->nameservers);
466 dhcp->nameservers = nameservers;
468 for (i = 0; dhcp->nameservers && dhcp->nameservers[i]; i++) {
469 #if defined TIZEN_EXT
470 __connman_service_nameserver_append(service,
471 dhcp->nameservers[i], false,
472 CONNMAN_IPCONFIG_TYPE_IPV4);
474 __connman_service_nameserver_append(service,
475 dhcp->nameservers[i], false);
479 g_strfreev(nameservers);
482 if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
483 if (dhcp->timeservers) {
484 for (i = 0; dhcp->timeservers[i]; i++) {
485 __connman_service_timeserver_remove(service,
486 dhcp->timeservers[i]);
488 g_strfreev(dhcp->timeservers);
491 dhcp->timeservers = timeservers;
493 for (i = 0; dhcp->timeservers && dhcp->timeservers[i]; i++) {
494 __connman_service_timeserver_append(service,
495 dhcp->timeservers[i]);
498 g_strfreev(timeservers);
501 if (g_strcmp0(pac, dhcp->pac) != 0) {
505 __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig,
509 if (connman_setting_get_bool("Enable6to4"))
510 __connman_6to4_probe(service);
515 static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
517 struct connman_dhcp *dhcp = user_data;
518 GList *option = NULL;
519 enum connman_ipconfig_method old_method;
520 char *address, *netmask = NULL, *gateway = NULL;
521 const char *c_address, *c_gateway;
522 unsigned char prefixlen, c_prefixlen;
523 bool ip_change = false;
525 DBG("Lease available");
527 if (dhcp->ipv4ll_client) {
528 ipv4ll_stop_client(dhcp);
529 dhcp_invalidate(dhcp, false);
532 c_address = __connman_ipconfig_get_local(dhcp->ipconfig);
533 c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig);
534 c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig);
536 address = g_dhcp_client_get_address(dhcp_client);
538 __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
539 DBG("last address %s", address);
541 #if defined TIZEN_EXT
542 int dhcp_lease_duration = g_dhcp_client_get_dhcp_lease_duration(dhcp_client);
545 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
547 netmask = g_strdup(option->data);
549 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
551 gateway = g_strdup(option->data);
553 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
554 if (prefixlen == 255)
555 connman_warn("netmask: %s is invalid", netmask);
557 DBG("c_address %s", c_address);
559 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
561 if (g_strcmp0(address, c_address)) {
564 if (old_method == CONNMAN_IPCONFIG_METHOD_AUTO ||
565 old_method == CONNMAN_IPCONFIG_METHOD_DHCP) {
570 /* Remove old ip address */
571 __connman_ipconfig_address_remove(dhcp->ipconfig);
574 if (g_strcmp0(gateway, c_gateway)) {
577 /* Remove gateway ip address */
578 __connman_ipconfig_gateway_remove(dhcp->ipconfig);
580 } else if (prefixlen != c_prefixlen)
583 __connman_ipconfig_set_method(dhcp->ipconfig,
584 CONNMAN_IPCONFIG_METHOD_DHCP);
586 #if defined TIZEN_EXT
587 __connman_ipconfig_set_dhcp_lease_duration(dhcp->ipconfig, dhcp_lease_duration);
588 __connman_network_notify_dhcp_changed(DHCP_SUCCESS,
589 g_dhcp_client_get_interface(dhcp_client));
593 * Notify IPv4.Configuration's method moved back to DHCP.
595 * This is the case ConnMan initially set an address by using
596 * IPv4LL because DHCP failed but now we got an address from DHCP.
598 if (old_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
599 struct connman_service *service =
600 connman_service_lookup_from_network(dhcp->network);
603 __connman_service_notify_ipv4_configuration(service);
606 #if defined TIZEN_EXT
607 if (connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
610 connman_service_notify_reconnection_roaming(
611 connman_service_lookup_from_network(dhcp->network));
613 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
618 __connman_ipconfig_set_local(dhcp->ipconfig, address);
619 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
620 __connman_ipconfig_set_gateway(dhcp->ipconfig, gateway);
623 if (!apply_lease_available_on_network(dhcp_client, dhcp))
635 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
637 struct connman_dhcp *dhcp = user_data;
638 enum connman_ipconfig_method old_method;
639 char *address, *netmask;
640 unsigned char prefixlen;
642 DBG("IPV4LL available");
644 address = g_dhcp_client_get_address(ipv4ll_client);
645 netmask = g_dhcp_client_get_netmask(ipv4ll_client);
647 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
649 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
650 __connman_ipconfig_set_method(dhcp->ipconfig,
651 CONNMAN_IPCONFIG_METHOD_AUTO);
654 * Notify IPv4.Configuration's method is AUTO now.
656 * This is the case DHCP failed thus ConnMan used IPv4LL to get an
657 * address. Set IPv4.Configuration method to AUTO allows user to
658 * ask for a DHCP address by setting the method again to DHCP.
660 if (old_method == CONNMAN_IPCONFIG_METHOD_DHCP) {
661 struct connman_service *service =
662 connman_service_lookup_from_network(dhcp->network);
665 __connman_service_notify_ipv4_configuration(service);
668 __connman_ipconfig_set_local(dhcp->ipconfig, address);
669 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
670 __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
677 #if defined TIZEN_EXT
678 __connman_network_notify_dhcp_changed(DHCP_FAIL,
679 g_dhcp_client_get_interface(ipv4ll_client));
683 static int dhcp_initialize(struct connman_dhcp *dhcp)
685 GDHCPClient *dhcp_client;
686 GDHCPClientError error;
688 const char *vendor_class_id;
690 DBG("dhcp %p", dhcp);
692 index = __connman_ipconfig_get_index(dhcp->ipconfig);
694 dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
695 if (error != G_DHCP_CLIENT_ERROR_NONE)
696 #if defined TIZEN_EXT
698 DBG("failed g_dhcp_client_new(%d), index(%d)", error, index);
701 #if defined TIZEN_EXT
705 #if !defined TIZEN_EXT
706 if (getenv("CONNMAN_DHCP_DEBUG")) {
708 dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
710 g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
711 dhcp->dhcp_debug_prefix);
712 #if !defined TIZEN_EXT
716 g_dhcp_client_set_id(dhcp_client);
719 struct connman_service *service;
720 const char *hostname;
722 service = connman_service_lookup_from_network(dhcp->network);
724 hostname = __connman_service_get_hostname(service);
726 hostname = connman_utsname_get_hostname();
729 g_dhcp_client_set_send(dhcp_client,
730 G_DHCP_HOST_NAME, hostname);
732 g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
733 g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
734 g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
735 g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
736 #if defined TIZEN_EXT
737 g_dhcp_client_set_request(dhcp_client, G_DHCP_VENDOR_SPECIFIC_IE);
739 g_dhcp_client_set_request(dhcp_client, 252);
740 g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU);
743 g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
744 g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
746 vendor_class_id = connman_setting_get_string("VendorClassID");
748 g_dhcp_client_set_send(dhcp_client, G_DHCP_VENDOR_CLASS_ID,
751 g_dhcp_client_register_event(dhcp_client,
752 G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
753 lease_available_cb, dhcp);
755 g_dhcp_client_register_event(dhcp_client,
756 G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);
758 g_dhcp_client_register_event(dhcp_client,
759 G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
761 dhcp->dhcp_client = dhcp_client;
766 static int dhcp_release(struct connman_dhcp *dhcp)
768 DBG("dhcp %p", dhcp);
770 if (dhcp->timeout > 0) {
771 g_source_remove(dhcp->timeout);
775 if (dhcp->dhcp_client) {
776 g_dhcp_client_stop(dhcp->dhcp_client);
777 g_dhcp_client_unref(dhcp->dhcp_client);
780 dhcp->dhcp_client = NULL;
782 g_free(dhcp->dhcp_debug_prefix);
783 dhcp->dhcp_debug_prefix = NULL;
785 ipv4ll_stop_client(dhcp);
790 char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig)
792 struct connman_dhcp *dhcp;
794 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
798 return g_dhcp_client_get_server_address(dhcp->dhcp_client);
801 #if defined TIZEN_EXT_WIFI_MESH
802 int __connman_mesh_dhcp_start(struct connman_ipconfig *ipconfig,
803 dhcp_cb callback, gpointer user_data)
805 struct connman_dhcp *dhcp;
810 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
813 dhcp = g_try_new0(struct connman_dhcp, 1);
817 dhcp->ipconfig = ipconfig;
818 __connman_ipconfig_ref(ipconfig);
820 err = dhcp_initialize(dhcp);
827 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
830 dhcp->callback = callback;
831 dhcp->user_data = user_data;
832 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
836 int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
837 struct connman_network *network, dhcp_cb callback,
840 #if !defined TIZEN_EXT
841 const char *last_addr = NULL;
843 struct connman_dhcp *dhcp;
849 struct connman_service *service;
851 service = connman_service_lookup_from_network(network);
856 #if !defined TIZEN_EXT
857 last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
860 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
863 dhcp = g_try_new0(struct connman_dhcp, 1);
867 dhcp->ipconfig = ipconfig;
868 __connman_ipconfig_ref(ipconfig);
871 dhcp->network = network;
872 connman_network_ref(network);
875 err = dhcp_initialize(dhcp);
879 connman_network_unref(network);
884 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
887 dhcp->callback = callback;
888 dhcp->user_data = user_data;
890 #if defined TIZEN_EXT
891 __connman_network_notify_dhcp_changed(DHCP_STARTED,
892 g_dhcp_client_get_interface(dhcp->dhcp_client));
894 if (network && connman_network_get_bool(network, "WiFi.RoamingDHCP")) {
895 const char *last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
897 DBG("Start DHCP with last address request");
898 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
900 DBG("Start DHCP with DHCPDISCOVER request");
901 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
904 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
908 void __connman_dhcp_stop(struct connman_ipconfig *ipconfig)
910 struct connman_dhcp *dhcp;
912 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
917 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
919 g_hash_table_remove(ipconfig_table, ipconfig);
920 __connman_ipconfig_unref(ipconfig);
922 connman_network_unref(dhcp->network);
924 dhcp_invalidate(dhcp, false);
929 void __connman_dhcp_decline(struct connman_ipconfig *ipconfig)
931 struct connman_dhcp *dhcp;
935 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
940 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
942 address = __connman_ipconfig_get_local(ipconfig);
946 if (inet_pton(AF_INET, address, &addr) != 1)
947 connman_error("Could not convert address %s", address);
949 g_dhcp_client_decline(dhcp->dhcp_client, htonl(addr.s_addr));
953 int __connman_dhcp_init(void)
957 ipconfig_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
963 void __connman_dhcp_cleanup(void)
967 g_hash_table_destroy(ipconfig_table);
968 ipconfig_table = NULL;