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"
51 struct connman_ipconfig *ipconfig;
52 struct connman_network *network;
62 GDHCPClient *ipv4ll_client;
63 GDHCPClient *dhcp_client;
64 char *ipv4ll_debug_prefix;
65 char *dhcp_debug_prefix;
70 static GHashTable *ipconfig_table;
72 static void dhcp_free(struct connman_dhcp *dhcp)
75 DBG("dhcp_free [%p]", dhcp);
77 g_strfreev(dhcp->nameservers);
78 g_strfreev(dhcp->timeservers);
81 dhcp->nameservers = NULL;
82 dhcp->timeservers = NULL;
91 static void ipv4ll_stop_client(struct connman_dhcp *dhcp)
94 DBG("dhcp [%p] ipv4ll_client [%p]", dhcp, dhcp->ipv4ll_client);
96 if (!dhcp->ipv4ll_client)
99 g_dhcp_client_stop(dhcp->ipv4ll_client);
100 g_dhcp_client_unref(dhcp->ipv4ll_client);
101 dhcp->ipv4ll_client = NULL;
102 dhcp->ipv4ll_running = false;
104 g_free(dhcp->ipv4ll_debug_prefix);
105 dhcp->ipv4ll_debug_prefix = NULL;
108 static bool apply_dhcp_invalidate_on_network(struct connman_dhcp *dhcp)
110 struct connman_service *service;
116 service = connman_service_lookup_from_network(dhcp->network);
118 connman_error("Can not lookup service");
122 __connman_service_set_domainname(service, NULL);
123 __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig, NULL);
125 if (dhcp->timeservers) {
126 for (i = 0; dhcp->timeservers[i]; i++) {
127 __connman_service_timeserver_remove(service,
128 dhcp->timeservers[i]);
130 g_strfreev(dhcp->timeservers);
131 dhcp->timeservers = NULL;
133 if (dhcp->nameservers) {
134 for (i = 0; dhcp->nameservers[i]; i++) {
135 #if defined TIZEN_EXT
136 __connman_service_nameserver_remove(service,
137 dhcp->nameservers[i], false,
138 CONNMAN_IPCONFIG_TYPE_IPV4);
140 __connman_service_nameserver_remove(service,
141 dhcp->nameservers[i], false);
144 g_strfreev(dhcp->nameservers);
145 dhcp->nameservers = NULL;
152 * dhcp_invalidate: Invalidate an existing DHCP lease
153 * @dhcp: pointer to the DHCP lease to invalidate.
154 * @callback: flag indicating whether or not to invoke the client callback
157 * Invalidates an existing DHCP lease, optionally invoking the client
158 * callback. The caller may wish to avoid the client callback invocation
159 * when the invocation of that callback might otherwise unnecessarily upset
160 * service state due to the IP configuration change implied by this
163 static void dhcp_invalidate(struct connman_dhcp *dhcp, bool callback)
165 DBG("dhcp %p callback %u", dhcp, callback);
170 __connman_6to4_remove(dhcp->ipconfig);
172 if (!apply_dhcp_invalidate_on_network(dhcp))
175 __connman_ipconfig_set_dhcp_address(dhcp->ipconfig,
176 __connman_ipconfig_get_local(dhcp->ipconfig));
177 DBG("last address %s",
178 __connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
180 __connman_ipconfig_address_remove(dhcp->ipconfig);
182 __connman_ipconfig_set_local(dhcp->ipconfig, NULL);
183 __connman_ipconfig_set_broadcast(dhcp->ipconfig, NULL);
184 __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
185 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, 0);
187 if (dhcp->callback && callback)
188 dhcp->callback(dhcp->ipconfig, dhcp->network,
189 false, dhcp->user_data);
192 static void dhcp_valid(struct connman_dhcp *dhcp)
195 dhcp->callback(dhcp->ipconfig, dhcp->network,
196 true, dhcp->user_data);
199 static void dhcp_debug(const char *str, void *data)
201 connman_info("%s: %s", (const char *) data, str);
204 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data);
205 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data);
207 static int ipv4ll_start_client(struct connman_dhcp *dhcp)
209 GDHCPClient *ipv4ll_client;
210 GDHCPClientError error;
211 const char *hostname;
215 #if defined TIZEN_EXT
216 DBG("dhcp %p", dhcp);
219 if (dhcp->ipv4ll_client)
222 index = __connman_ipconfig_get_index(dhcp->ipconfig);
224 ipv4ll_client = g_dhcp_client_new(G_DHCP_IPV4LL, index, &error);
225 if (error != G_DHCP_CLIENT_ERROR_NONE)
228 #if !defined TIZEN_EXT
229 if (getenv("CONNMAN_DHCP_DEBUG")) {
231 dhcp->ipv4ll_debug_prefix = g_strdup_printf("IPv4LL index %d",
233 g_dhcp_client_set_debug(ipv4ll_client, dhcp_debug,
234 dhcp->ipv4ll_debug_prefix);
235 #if !defined TIZEN_EXT
239 g_dhcp_client_set_id(ipv4ll_client);
242 hostname = connman_utsname_get_hostname();
244 g_dhcp_client_set_send(ipv4ll_client,
245 G_DHCP_HOST_NAME, hostname);
248 g_dhcp_client_register_event(ipv4ll_client,
249 G_DHCP_CLIENT_EVENT_IPV4LL_LOST, ipv4ll_lost_cb, dhcp);
251 g_dhcp_client_register_event(ipv4ll_client,
252 G_DHCP_CLIENT_EVENT_IPV4LL_AVAILABLE,
253 ipv4ll_available_cb, dhcp);
255 dhcp->ipv4ll_client = ipv4ll_client;
257 err = g_dhcp_client_start(dhcp->ipv4ll_client, NULL);
259 ipv4ll_stop_client(dhcp);
263 dhcp->ipv4ll_running = true;
267 static gboolean dhcp_retry_cb(gpointer user_data)
269 struct connman_dhcp *dhcp = user_data;
273 #if defined TIZEN_EXT
274 DBG("dhcp %p", dhcp);
275 DBG("dhcp->timeout %d", dhcp->timeout);
277 g_dhcp_client_start(dhcp->dhcp_client,
278 __connman_ipconfig_get_dhcp_address(dhcp->ipconfig));
283 static void no_lease_cb(GDHCPClient *dhcp_client, gpointer user_data)
285 struct connman_dhcp *dhcp = user_data;
288 DBG("No lease available ipv4ll %d client %p", dhcp->ipv4ll_running,
289 dhcp->ipv4ll_client);
291 #if defined TIZEN_EXT
293 connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
295 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
296 __connman_network_enable_ipconfig(dhcp->network, dhcp->ipconfig);
297 __connman_network_notify_dhcp_changed("DHCP_FAIL",
298 g_dhcp_client_get_interface(dhcp_client));
303 if (connman_setting_get_bool("EnableAutoIp") == false) {
304 DBG("link-local address autoconfiguration is disabled.");
307 DBG("[DHCP-C] auto ip is not used, set dhcp-fail error and disconnect");
308 __connman_network_notify_dhcp_changed("DHCP_FAIL",
309 g_dhcp_client_get_interface(dhcp_client));
310 connman_network_set_error(dhcp->network, CONNMAN_NETWORK_ERROR_DHCP_FAIL);
315 if (dhcp->timeout > 0)
316 g_source_remove(dhcp->timeout);
318 dhcp->timeout = g_timeout_add_seconds(RATE_LIMIT_INTERVAL,
321 if (dhcp->ipv4ll_running)
324 err = ipv4ll_start_client(dhcp);
326 DBG("Cannot start ipv4ll client (%d/%s)", err, strerror(-err));
328 /* Only notify upper layer if we have a problem */
329 dhcp_invalidate(dhcp, !dhcp->ipv4ll_running);
332 static void lease_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
334 struct connman_dhcp *dhcp = user_data;
338 /* Upper layer will decide what to do, e.g. nothing or retry. */
339 dhcp_invalidate(dhcp, true);
342 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
344 struct connman_dhcp *dhcp = user_data;
348 ipv4ll_stop_client(dhcp);
351 * Since we lost our IPv4LL configuration we might as notify
354 dhcp_invalidate(dhcp, true);
357 static bool compare_string_arrays(char **array_a, char **array_b)
361 if (!array_a || !array_b)
364 if (g_strv_length(array_a) != g_strv_length(array_b))
367 for (i = 0; array_a[i] &&
369 if (g_strcmp0(array_a[i], array_b[i]) != 0)
376 static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
377 struct connman_dhcp *dhcp)
379 char **nameservers, **timeservers, *pac = NULL;
380 struct connman_service *service;
381 GList *list, *option = NULL;
388 service = connman_service_lookup_from_network(dhcp->network);
390 connman_error("Can not lookup service");
394 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_MTU);
395 if (option && option->data) {
398 mtu = atoi(option->data);
400 if (mtu >= IPV6_MIN_MTU && mtu <= ETH_DATA_LEN) {
401 index = __connman_ipconfig_get_index(dhcp->ipconfig);
402 err = connman_inet_set_mtu(index, mtu);
404 DBG("MTU %d index %d err %d", mtu, index, err);
408 option = g_dhcp_client_get_option(dhcp_client, 252);
410 pac = g_strdup(option->data);
412 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
413 ns_entries = g_list_length(option);
414 nameservers = g_try_new0(char *, ns_entries + 1);
416 for (i = 0, list = option;list; list = list->next, i++)
417 nameservers[i] = g_strdup(list->data);
418 nameservers[ns_entries] = NULL;
421 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
423 __connman_service_set_domainname(service, option->data);
425 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
427 __connman_service_set_hostname(service, option->data);
429 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER);
430 ns_entries = g_list_length(option);
431 timeservers = g_try_new0(char *, ns_entries + 1);
433 for (i = 0, list = option; list; list = list->next, i++)
434 timeservers[i] = g_strdup(list->data);
435 timeservers[ns_entries] = NULL;
438 if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
439 if (dhcp->nameservers) {
440 #if defined TIZEN_EXT
441 for (i = 0; dhcp->nameservers[i] != NULL; i++) {
442 __connman_service_nameserver_remove(service,
443 dhcp->nameservers[i], false,
444 CONNMAN_IPCONFIG_TYPE_IPV4);
447 for (i = 0; dhcp->nameservers[i]; i++) {
448 __connman_service_nameserver_remove(service,
449 dhcp->nameservers[i], false);
452 g_strfreev(dhcp->nameservers);
455 dhcp->nameservers = nameservers;
457 for (i = 0; dhcp->nameservers && dhcp->nameservers[i]; i++) {
458 #if defined TIZEN_EXT
459 __connman_service_nameserver_append(service,
460 dhcp->nameservers[i], false,
461 CONNMAN_IPCONFIG_TYPE_IPV4);
463 __connman_service_nameserver_append(service,
464 dhcp->nameservers[i], false);
468 g_strfreev(nameservers);
471 if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
472 if (dhcp->timeservers) {
473 for (i = 0; dhcp->timeservers[i]; i++) {
474 __connman_service_timeserver_remove(service,
475 dhcp->timeservers[i]);
477 g_strfreev(dhcp->timeservers);
480 dhcp->timeservers = timeservers;
482 for (i = 0; dhcp->timeservers && dhcp->timeservers[i]; i++) {
483 __connman_service_timeserver_append(service,
484 dhcp->timeservers[i]);
487 g_strfreev(timeservers);
490 if (g_strcmp0(pac, dhcp->pac) != 0) {
494 __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig,
498 if (connman_setting_get_bool("Enable6to4"))
499 __connman_6to4_probe(service);
504 static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
506 struct connman_dhcp *dhcp = user_data;
507 GList *option = NULL;
508 enum connman_ipconfig_method old_method;
509 char *address, *netmask = NULL, *gateway = NULL;
510 const char *c_address, *c_gateway;
511 unsigned char prefixlen, c_prefixlen;
512 bool ip_change = false;
514 DBG("Lease available");
516 if (dhcp->ipv4ll_client) {
517 ipv4ll_stop_client(dhcp);
518 dhcp_invalidate(dhcp, false);
521 c_address = __connman_ipconfig_get_local(dhcp->ipconfig);
522 c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig);
523 c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig);
525 address = g_dhcp_client_get_address(dhcp_client);
527 __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
528 DBG("last address %s", address);
530 #if defined TIZEN_EXT
531 int dhcp_lease_duration = g_dhcp_client_get_dhcp_lease_duration(dhcp_client);
534 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
536 netmask = g_strdup(option->data);
538 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
540 gateway = g_strdup(option->data);
542 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
543 if (prefixlen == 255)
544 connman_warn("netmask: %s is invalid", netmask);
546 DBG("c_address %s", c_address);
548 if (g_strcmp0(address, c_address)) {
551 /* Remove old ip address */
552 __connman_ipconfig_address_remove(dhcp->ipconfig);
555 if (g_strcmp0(gateway, c_gateway)) {
558 /* Remove gateway ip address */
559 __connman_ipconfig_gateway_remove(dhcp->ipconfig);
561 } else if (prefixlen != c_prefixlen)
564 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
565 __connman_ipconfig_set_method(dhcp->ipconfig,
566 CONNMAN_IPCONFIG_METHOD_DHCP);
568 #if defined TIZEN_EXT
569 __connman_ipconfig_set_dhcp_lease_duration(dhcp->ipconfig, dhcp_lease_duration);
570 __connman_network_notify_dhcp_changed(DHCP_SUCCESS,
571 g_dhcp_client_get_interface(dhcp_client));
575 * Notify IPv4.Configuration's method moved back to DHCP.
577 * This is the case ConnMan initially set an address by using
578 * IPv4LL because DHCP failed but now we got an address from DHCP.
580 if (old_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
581 struct connman_service *service =
582 connman_service_lookup_from_network(dhcp->network);
585 __connman_service_notify_ipv4_configuration(service);
588 #if defined TIZEN_EXT
589 if (connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
592 connman_service_notify_reconnection(
593 connman_service_lookup_from_network(dhcp->network));
595 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
600 __connman_ipconfig_set_local(dhcp->ipconfig, address);
601 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
602 __connman_ipconfig_set_gateway(dhcp->ipconfig, gateway);
605 if (!apply_lease_available_on_network(dhcp_client, dhcp))
617 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
619 struct connman_dhcp *dhcp = user_data;
620 enum connman_ipconfig_method old_method;
621 char *address, *netmask;
622 unsigned char prefixlen;
624 DBG("IPV4LL available");
626 address = g_dhcp_client_get_address(ipv4ll_client);
627 netmask = g_dhcp_client_get_netmask(ipv4ll_client);
629 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
631 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
632 __connman_ipconfig_set_method(dhcp->ipconfig,
633 CONNMAN_IPCONFIG_METHOD_AUTO);
636 * Notify IPv4.Configuration's method is AUTO now.
638 * This is the case DHCP failed thus ConnMan used IPv4LL to get an
639 * address. Set IPv4.Configuration method to AUTO allows user to
640 * ask for a DHCP address by setting the method again to DHCP.
642 if (old_method == CONNMAN_IPCONFIG_METHOD_DHCP) {
643 struct connman_service *service =
644 connman_service_lookup_from_network(dhcp->network);
647 __connman_service_notify_ipv4_configuration(service);
650 __connman_ipconfig_set_local(dhcp->ipconfig, address);
651 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
652 __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
659 #if defined TIZEN_EXT
660 __connman_network_notify_dhcp_changed("DHCP_FAIL",
661 g_dhcp_client_get_interface(ipv4ll_client));
665 static int dhcp_initialize(struct connman_dhcp *dhcp)
667 GDHCPClient *dhcp_client;
668 GDHCPClientError error;
670 const char *vendor_class_id;
672 DBG("dhcp %p", dhcp);
674 index = __connman_ipconfig_get_index(dhcp->ipconfig);
676 dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
677 if (error != G_DHCP_CLIENT_ERROR_NONE)
678 #if defined TIZEN_EXT
680 DBG("failed g_dhcp_client_new(%d), index(%d)", error, index);
683 #if defined TIZEN_EXT
687 #if !defined TIZEN_EXT
688 if (getenv("CONNMAN_DHCP_DEBUG")) {
690 dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
692 g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
693 dhcp->dhcp_debug_prefix);
694 #if !defined TIZEN_EXT
698 g_dhcp_client_set_id(dhcp_client);
701 struct connman_service *service;
702 const char *hostname;
704 service = connman_service_lookup_from_network(dhcp->network);
706 hostname = __connman_service_get_hostname(service);
708 hostname = connman_utsname_get_hostname();
711 g_dhcp_client_set_send(dhcp_client,
712 G_DHCP_HOST_NAME, hostname);
714 g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
715 g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
716 g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
717 g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
718 g_dhcp_client_set_request(dhcp_client, 252);
719 g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU);
722 g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
723 g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
725 vendor_class_id = connman_setting_get_string("VendorClassID");
727 g_dhcp_client_set_send(dhcp_client, G_DHCP_VENDOR_CLASS_ID,
730 g_dhcp_client_register_event(dhcp_client,
731 G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
732 lease_available_cb, dhcp);
734 g_dhcp_client_register_event(dhcp_client,
735 G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);
737 g_dhcp_client_register_event(dhcp_client,
738 G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
740 dhcp->dhcp_client = dhcp_client;
745 static int dhcp_release(struct connman_dhcp *dhcp)
747 DBG("dhcp %p", dhcp);
749 if (dhcp->timeout > 0) {
750 g_source_remove(dhcp->timeout);
754 if (dhcp->dhcp_client) {
755 g_dhcp_client_stop(dhcp->dhcp_client);
756 g_dhcp_client_unref(dhcp->dhcp_client);
759 dhcp->dhcp_client = NULL;
761 g_free(dhcp->dhcp_debug_prefix);
762 dhcp->dhcp_debug_prefix = NULL;
764 ipv4ll_stop_client(dhcp);
769 char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig)
771 struct connman_dhcp *dhcp;
773 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
777 return g_dhcp_client_get_server_address(dhcp->dhcp_client);
780 #if defined TIZEN_EXT_WIFI_MESH
781 int __connman_mesh_dhcp_start(struct connman_ipconfig *ipconfig,
782 dhcp_cb callback, gpointer user_data)
784 struct connman_dhcp *dhcp;
789 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
792 dhcp = g_try_new0(struct connman_dhcp, 1);
796 dhcp->ipconfig = ipconfig;
797 __connman_ipconfig_ref(ipconfig);
799 err = dhcp_initialize(dhcp);
806 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
809 dhcp->callback = callback;
810 dhcp->user_data = user_data;
811 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
815 int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
816 struct connman_network *network, dhcp_cb callback,
819 #if !defined TIZEN_EXT
820 const char *last_addr = NULL;
822 struct connman_dhcp *dhcp;
828 struct connman_service *service;
830 service = connman_service_lookup_from_network(network);
835 #if !defined TIZEN_EXT
836 last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
839 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
842 dhcp = g_try_new0(struct connman_dhcp, 1);
846 dhcp->ipconfig = ipconfig;
847 __connman_ipconfig_ref(ipconfig);
850 dhcp->network = network;
851 connman_network_ref(network);
854 err = dhcp_initialize(dhcp);
858 connman_network_unref(network);
863 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
866 dhcp->callback = callback;
867 dhcp->user_data = user_data;
869 #if defined TIZEN_EXT
870 __connman_network_notify_dhcp_changed("DHCP_STARTED",
871 g_dhcp_client_get_interface(dhcp->dhcp_client));
873 if (network && connman_network_get_bool(network, "WiFi.RoamingDHCP")) {
874 const char *last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
876 DBG("Start DHCP with last address request");
877 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
879 DBG("Start DHCP with DHCPDISCOVER request");
880 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
883 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
887 void __connman_dhcp_stop(struct connman_ipconfig *ipconfig)
889 struct connman_dhcp *dhcp;
891 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
896 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
898 g_hash_table_remove(ipconfig_table, ipconfig);
899 __connman_ipconfig_unref(ipconfig);
901 connman_network_unref(dhcp->network);
903 dhcp_invalidate(dhcp, false);
908 void __connman_dhcp_decline(struct connman_ipconfig *ipconfig)
910 struct connman_dhcp *dhcp;
914 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
919 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
921 address = __connman_ipconfig_get_local(ipconfig);
925 if (inet_pton(AF_INET, address, &addr) != 1)
926 connman_error("Could not convert address %s", address);
928 g_dhcp_client_decline(dhcp->dhcp_client, htonl(addr.s_addr));
932 int __connman_dhcp_init(void)
936 ipconfig_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
942 void __connman_dhcp_cleanup(void)
946 g_hash_table_destroy(ipconfig_table);
947 ipconfig_table = NULL;