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 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, 0);
189 if (dhcp->callback && callback)
190 dhcp->callback(dhcp->ipconfig, dhcp->network,
191 false, dhcp->user_data);
194 static void dhcp_valid(struct connman_dhcp *dhcp)
197 dhcp->callback(dhcp->ipconfig, dhcp->network,
198 true, dhcp->user_data);
201 static void dhcp_debug(const char *str, void *data)
203 connman_info("%s: %s", (const char *) data, str);
206 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data);
207 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data);
209 static int ipv4ll_start_client(struct connman_dhcp *dhcp)
211 GDHCPClient *ipv4ll_client;
212 GDHCPClientError error;
213 const char *hostname;
217 #if defined TIZEN_EXT
218 DBG("dhcp %p", dhcp);
221 if (dhcp->ipv4ll_client)
224 index = __connman_ipconfig_get_index(dhcp->ipconfig);
226 ipv4ll_client = g_dhcp_client_new(G_DHCP_IPV4LL, index, &error);
227 if (error != G_DHCP_CLIENT_ERROR_NONE)
230 #if !defined TIZEN_EXT
231 if (getenv("CONNMAN_DHCP_DEBUG")) {
233 dhcp->ipv4ll_debug_prefix = g_strdup_printf("IPv4LL index %d",
235 g_dhcp_client_set_debug(ipv4ll_client, dhcp_debug,
236 dhcp->ipv4ll_debug_prefix);
237 #if !defined TIZEN_EXT
241 g_dhcp_client_set_id(ipv4ll_client);
244 hostname = connman_utsname_get_hostname();
246 g_dhcp_client_set_send(ipv4ll_client,
247 G_DHCP_HOST_NAME, hostname);
250 g_dhcp_client_register_event(ipv4ll_client,
251 G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);
253 g_dhcp_client_register_event(ipv4ll_client,
254 G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
255 ipv4ll_available_cb, dhcp);
257 dhcp->ipv4ll_client = ipv4ll_client;
259 err = g_dhcp_client_start(dhcp->ipv4ll_client, NULL);
261 ipv4ll_stop_client(dhcp);
265 dhcp->ipv4ll_running = true;
269 static gboolean dhcp_retry_cb(gpointer user_data)
271 struct connman_dhcp *dhcp = user_data;
275 #if defined TIZEN_EXT
276 DBG("dhcp %p", dhcp);
277 DBG("dhcp->timeout %d", dhcp->timeout);
279 g_dhcp_client_start(dhcp->dhcp_client,
280 __connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
285 static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
287 struct connman_dhcp *dhcp = user_data;
290 DBG("No lease available ipv4ll %d client %p", dhcp->ipv4ll_running,
291 dhcp->ipv4ll_client);
293 #if defined TIZEN_EXT
295 connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
297 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
298 __connman_network_enable_ipconfig(dhcp->network, dhcp->ipconfig);
299 __connman_network_notify_dhcp_changed(DHCP_FAIL,
300 g_dhcp_client_get_interface(dhcp_client));
305 if (connman_setting_get_bool("EnableAutoIp") == false) {
306 DBG("link-local address autoconfiguration is disabled.");
309 DBG("[DHCP-C] auto ip is not used, set dhcp-fail error and disconnect");
310 __connman_network_notify_dhcp_changed(DHCP_FAIL,
311 g_dhcp_client_get_interface(dhcp_client));
312 connman_network_set_error(dhcp->network, CONNMAN_NETWORK_ERROR_DHCP_FAIL);
317 if (dhcp->timeout > 0)
318 g_source_remove(dhcp->timeout);
320 dhcp->timeout = g_timeout_add_seconds(RATE_LIMIT_INTERVAL,
323 if (dhcp->ipv4ll_running)
326 err = ipv4ll_start_client(dhcp);
328 DBG("Cannot start ipv4ll client (%d/%s)", err, strerror(-err));
330 /* Only notify upper layer if we have a problem */
331 dhcp_invalidate(dhcp, !dhcp->ipv4ll_running);
334 static void lease_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
336 struct connman_dhcp *dhcp = user_data;
340 /* Upper layer will decide what to do, e.g. nothing or retry. */
341 dhcp_invalidate(dhcp, true);
344 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
346 struct connman_dhcp *dhcp = user_data;
350 ipv4ll_stop_client(dhcp);
353 * Since we lost our IPv4LL configuration we might as notify
356 dhcp_invalidate(dhcp, true);
359 static bool compare_string_arrays(char **array_a, char **array_b)
363 if (!array_a || !array_b)
366 if (g_strv_length(array_a) != g_strv_length(array_b))
369 for (i = 0; array_a[i] &&
371 if (g_strcmp0(array_a[i], array_b[i]) != 0)
378 static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
379 struct connman_dhcp *dhcp)
381 char **nameservers, **timeservers, *pac = NULL;
382 struct connman_service *service;
383 GList *list, *option = NULL;
390 service = connman_service_lookup_from_network(dhcp->network);
392 connman_error("Can not lookup service");
396 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_MTU);
397 if (option && option->data) {
400 mtu = atoi(option->data);
402 if (mtu >= IPV6_MIN_MTU && mtu <= ETH_DATA_LEN) {
403 index = __connman_ipconfig_get_index(dhcp->ipconfig);
404 err = connman_inet_set_mtu(index, mtu);
406 DBG("MTU %d index %d err %d", mtu, index, err);
410 option = g_dhcp_client_get_option(dhcp_client, 252);
412 pac = g_strdup(option->data);
414 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
415 ns_entries = g_list_length(option);
416 nameservers = g_try_new0(char *, ns_entries + 1);
418 for (i = 0, list = option;list; list = list->next, i++)
419 nameservers[i] = g_strdup(list->data);
420 nameservers[ns_entries] = NULL;
423 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
425 __connman_service_set_domainname(service, option->data);
427 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
429 __connman_service_set_hostname(service, option->data);
431 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER);
432 ns_entries = g_list_length(option);
433 timeservers = g_try_new0(char *, ns_entries + 1);
435 for (i = 0, list = option; list; list = list->next, i++)
436 timeservers[i] = g_strdup(list->data);
437 timeservers[ns_entries] = NULL;
440 if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
441 if (dhcp->nameservers) {
442 #if defined TIZEN_EXT
443 for (i = 0; dhcp->nameservers[i] != NULL; i++) {
444 __connman_service_nameserver_remove(service,
445 dhcp->nameservers[i], false,
446 CONNMAN_IPCONFIG_TYPE_IPV4);
449 for (i = 0; dhcp->nameservers[i]; i++) {
450 __connman_service_nameserver_remove(service,
451 dhcp->nameservers[i], false);
454 g_strfreev(dhcp->nameservers);
457 dhcp->nameservers = nameservers;
459 for (i = 0; dhcp->nameservers && dhcp->nameservers[i]; i++) {
460 #if defined TIZEN_EXT
461 __connman_service_nameserver_append(service,
462 dhcp->nameservers[i], false,
463 CONNMAN_IPCONFIG_TYPE_IPV4);
465 __connman_service_nameserver_append(service,
466 dhcp->nameservers[i], false);
470 g_strfreev(nameservers);
473 if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
474 if (dhcp->timeservers) {
475 for (i = 0; dhcp->timeservers[i]; i++) {
476 __connman_service_timeserver_remove(service,
477 dhcp->timeservers[i]);
479 g_strfreev(dhcp->timeservers);
482 dhcp->timeservers = timeservers;
484 for (i = 0; dhcp->timeservers && dhcp->timeservers[i]; i++) {
485 __connman_service_timeserver_append(service,
486 dhcp->timeservers[i]);
489 g_strfreev(timeservers);
492 if (g_strcmp0(pac, dhcp->pac) != 0) {
496 __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig,
500 if (connman_setting_get_bool("Enable6to4"))
501 __connman_6to4_probe(service);
506 static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
508 struct connman_dhcp *dhcp = user_data;
509 GList *option = NULL;
510 enum connman_ipconfig_method old_method;
511 char *address, *netmask = NULL, *gateway = NULL;
512 const char *c_address, *c_gateway;
513 unsigned char prefixlen, c_prefixlen;
514 bool ip_change = false;
516 DBG("Lease available");
518 if (dhcp->ipv4ll_client) {
519 ipv4ll_stop_client(dhcp);
520 dhcp_invalidate(dhcp, false);
523 c_address = __connman_ipconfig_get_local(dhcp->ipconfig);
524 c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig);
525 c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig);
527 address = g_dhcp_client_get_address(dhcp_client);
529 __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
530 DBG("last address %s", address);
532 #if defined TIZEN_EXT
533 int dhcp_lease_duration = g_dhcp_client_get_dhcp_lease_duration(dhcp_client);
536 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
538 netmask = g_strdup(option->data);
540 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
542 gateway = g_strdup(option->data);
544 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
545 if (prefixlen == 255)
546 connman_warn("netmask: %s is invalid", netmask);
548 DBG("c_address %s", c_address);
550 if (g_strcmp0(address, c_address)) {
553 /* Remove old ip address */
554 __connman_ipconfig_address_remove(dhcp->ipconfig);
557 if (g_strcmp0(gateway, c_gateway)) {
560 /* Remove gateway ip address */
561 __connman_ipconfig_gateway_remove(dhcp->ipconfig);
563 } else if (prefixlen != c_prefixlen)
566 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
567 __connman_ipconfig_set_method(dhcp->ipconfig,
568 CONNMAN_IPCONFIG_METHOD_DHCP);
570 #if defined TIZEN_EXT
571 __connman_ipconfig_set_dhcp_lease_duration(dhcp->ipconfig, dhcp_lease_duration);
572 __connman_network_notify_dhcp_changed(DHCP_SUCCESS,
573 g_dhcp_client_get_interface(dhcp_client));
577 * Notify IPv4.Configuration's method moved back to DHCP.
579 * This is the case ConnMan initially set an address by using
580 * IPv4LL because DHCP failed but now we got an address from DHCP.
582 if (old_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
583 struct connman_service *service =
584 connman_service_lookup_from_network(dhcp->network);
587 __connman_service_notify_ipv4_configuration(service);
590 #if defined TIZEN_EXT
591 if (connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
594 connman_service_notify_reconnection(
595 connman_service_lookup_from_network(dhcp->network));
597 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
602 __connman_ipconfig_set_local(dhcp->ipconfig, address);
603 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
604 __connman_ipconfig_set_gateway(dhcp->ipconfig, gateway);
607 if (!apply_lease_available_on_network(dhcp_client, dhcp))
619 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
621 struct connman_dhcp *dhcp = user_data;
622 enum connman_ipconfig_method old_method;
623 char *address, *netmask;
624 unsigned char prefixlen;
626 DBG("IPV4LL available");
628 address = g_dhcp_client_get_address(ipv4ll_client);
629 netmask = g_dhcp_client_get_netmask(ipv4ll_client);
631 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
633 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
634 __connman_ipconfig_set_method(dhcp->ipconfig,
635 CONNMAN_IPCONFIG_METHOD_AUTO);
638 * Notify IPv4.Configuration's method is AUTO now.
640 * This is the case DHCP failed thus ConnMan used IPv4LL to get an
641 * address. Set IPv4.Configuration method to AUTO allows user to
642 * ask for a DHCP address by setting the method again to DHCP.
644 if (old_method == CONNMAN_IPCONFIG_METHOD_DHCP) {
645 struct connman_service *service =
646 connman_service_lookup_from_network(dhcp->network);
649 __connman_service_notify_ipv4_configuration(service);
652 __connman_ipconfig_set_local(dhcp->ipconfig, address);
653 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
654 __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
661 #if defined TIZEN_EXT
662 __connman_network_notify_dhcp_changed(DHCP_FAIL,
663 g_dhcp_client_get_interface(ipv4ll_client));
667 static int dhcp_initialize(struct connman_dhcp *dhcp)
669 GDHCPClient *dhcp_client;
670 GDHCPClientError error;
672 const char *vendor_class_id;
674 DBG("dhcp %p", dhcp);
676 index = __connman_ipconfig_get_index(dhcp->ipconfig);
678 dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
679 if (error != G_DHCP_CLIENT_ERROR_NONE)
680 #if defined TIZEN_EXT
682 DBG("failed g_dhcp_client_new(%d), index(%d)", error, index);
685 #if defined TIZEN_EXT
689 #if !defined TIZEN_EXT
690 if (getenv("CONNMAN_DHCP_DEBUG")) {
692 dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
694 g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
695 dhcp->dhcp_debug_prefix);
696 #if !defined TIZEN_EXT
700 g_dhcp_client_set_id(dhcp_client);
703 struct connman_service *service;
704 const char *hostname;
706 service = connman_service_lookup_from_network(dhcp->network);
708 hostname = __connman_service_get_hostname(service);
710 hostname = connman_utsname_get_hostname();
713 g_dhcp_client_set_send(dhcp_client,
714 G_DHCP_HOST_NAME, hostname);
716 g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
717 g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
718 g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
719 g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
720 g_dhcp_client_set_request(dhcp_client, 252);
721 g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU);
724 g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
725 g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
727 vendor_class_id = connman_setting_get_string("VendorClassID");
729 g_dhcp_client_set_send(dhcp_client, G_DHCP_VENDOR_CLASS_ID,
732 g_dhcp_client_register_event(dhcp_client,
733 G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
734 lease_available_cb, dhcp);
736 g_dhcp_client_register_event(dhcp_client,
737 G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);
739 g_dhcp_client_register_event(dhcp_client,
740 G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
742 dhcp->dhcp_client = dhcp_client;
747 static int dhcp_release(struct connman_dhcp *dhcp)
749 DBG("dhcp %p", dhcp);
751 if (dhcp->timeout > 0) {
752 g_source_remove(dhcp->timeout);
756 if (dhcp->dhcp_client) {
757 g_dhcp_client_stop(dhcp->dhcp_client);
758 g_dhcp_client_unref(dhcp->dhcp_client);
761 dhcp->dhcp_client = NULL;
763 g_free(dhcp->dhcp_debug_prefix);
764 dhcp->dhcp_debug_prefix = NULL;
766 ipv4ll_stop_client(dhcp);
771 char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig)
773 struct connman_dhcp *dhcp;
775 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
779 return g_dhcp_client_get_server_address(dhcp->dhcp_client);
782 #if defined TIZEN_EXT_WIFI_MESH
783 int __connman_mesh_dhcp_start(struct connman_ipconfig *ipconfig,
784 dhcp_cb callback, gpointer user_data)
786 struct connman_dhcp *dhcp;
791 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
794 dhcp = g_try_new0(struct connman_dhcp, 1);
798 dhcp->ipconfig = ipconfig;
799 __connman_ipconfig_ref(ipconfig);
801 err = dhcp_initialize(dhcp);
808 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
811 dhcp->callback = callback;
812 dhcp->user_data = user_data;
813 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
817 int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
818 struct connman_network *network, dhcp_cb callback,
821 #if !defined TIZEN_EXT
822 const char *last_addr = NULL;
824 struct connman_dhcp *dhcp;
830 struct connman_service *service;
832 service = connman_service_lookup_from_network(network);
837 #if !defined TIZEN_EXT
838 last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
841 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
844 dhcp = g_try_new0(struct connman_dhcp, 1);
848 dhcp->ipconfig = ipconfig;
849 __connman_ipconfig_ref(ipconfig);
852 dhcp->network = network;
853 connman_network_ref(network);
856 err = dhcp_initialize(dhcp);
860 connman_network_unref(network);
865 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
868 dhcp->callback = callback;
869 dhcp->user_data = user_data;
871 #if defined TIZEN_EXT
872 __connman_network_notify_dhcp_changed(DHCP_STARTED,
873 g_dhcp_client_get_interface(dhcp->dhcp_client));
875 if (network && connman_network_get_bool(network, "WiFi.RoamingDHCP")) {
876 const char *last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
878 DBG("Start DHCP with last address request");
879 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
881 DBG("Start DHCP with DHCPDISCOVER request");
882 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
885 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
889 void __connman_dhcp_stop(struct connman_ipconfig *ipconfig)
891 struct connman_dhcp *dhcp;
893 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
898 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
900 g_hash_table_remove(ipconfig_table, ipconfig);
901 __connman_ipconfig_unref(ipconfig);
903 connman_network_unref(dhcp->network);
905 dhcp_invalidate(dhcp, false);
910 void __connman_dhcp_decline(struct connman_ipconfig *ipconfig)
912 struct connman_dhcp *dhcp;
916 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
921 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
923 address = __connman_ipconfig_get_local(ipconfig);
927 if (inet_pton(AF_INET, address, &addr) != 1)
928 connman_error("Could not convert address %s", address);
930 g_dhcp_client_decline(dhcp->dhcp_client, htonl(addr.s_addr));
934 int __connman_dhcp_init(void)
938 ipconfig_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
944 void __connman_dhcp_cleanup(void)
948 g_hash_table_destroy(ipconfig_table);
949 ipconfig_table = NULL;