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")) {
296 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
297 __connman_network_enable_ipconfig(dhcp->network, dhcp->ipconfig);
298 __connman_network_notify_dhcp_changed("DHCP_FAIL", &lease_time);
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", &lease_time);
309 connman_network_set_error(dhcp->network, CONNMAN_NETWORK_ERROR_DHCP_FAIL);
314 if (dhcp->timeout > 0)
315 g_source_remove(dhcp->timeout);
317 dhcp->timeout = g_timeout_add_seconds(RATE_LIMIT_INTERVAL,
320 if (dhcp->ipv4ll_running)
323 err = ipv4ll_start_client(dhcp);
325 DBG("Cannot start ipv4ll client (%d/%s)", err, strerror(-err));
327 /* Only notify upper layer if we have a problem */
328 dhcp_invalidate(dhcp, !dhcp->ipv4ll_running);
331 static void lease_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
333 struct connman_dhcp *dhcp = user_data;
337 /* Upper layer will decide what to do, e.g. nothing or retry. */
338 dhcp_invalidate(dhcp, true);
341 static void ipv4ll_lost_cb(GDHCPClient *dhcp_client, gpointer user_data)
343 struct connman_dhcp *dhcp = user_data;
347 ipv4ll_stop_client(dhcp);
350 * Since we lost our IPv4LL configuration we might as notify
353 dhcp_invalidate(dhcp, true);
356 static bool compare_string_arrays(char **array_a, char **array_b)
360 if (!array_a || !array_b)
363 if (g_strv_length(array_a) != g_strv_length(array_b))
366 for (i = 0; array_a[i] &&
368 if (g_strcmp0(array_a[i], array_b[i]) != 0)
375 static bool apply_lease_available_on_network(GDHCPClient *dhcp_client,
376 struct connman_dhcp *dhcp)
378 char **nameservers, **timeservers, *pac = NULL;
379 struct connman_service *service;
380 GList *list, *option = NULL;
387 service = connman_service_lookup_from_network(dhcp->network);
389 connman_error("Can not lookup service");
393 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_MTU);
394 if (option && option->data) {
397 mtu = atoi(option->data);
399 if (mtu >= IPV6_MIN_MTU && mtu <= ETH_DATA_LEN) {
400 index = __connman_ipconfig_get_index(dhcp->ipconfig);
401 err = connman_inet_set_mtu(index, mtu);
403 DBG("MTU %d index %d err %d", mtu, index, err);
407 option = g_dhcp_client_get_option(dhcp_client, 252);
409 pac = g_strdup(option->data);
411 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DNS_SERVER);
412 ns_entries = g_list_length(option);
413 nameservers = g_try_new0(char *, ns_entries + 1);
415 for (i = 0, list = option;list; list = list->next, i++)
416 nameservers[i] = g_strdup(list->data);
417 nameservers[ns_entries] = NULL;
420 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_DOMAIN_NAME);
422 __connman_service_set_domainname(service, option->data);
424 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_HOST_NAME);
426 __connman_service_set_hostname(service, option->data);
428 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_NTP_SERVER);
429 ns_entries = g_list_length(option);
430 timeservers = g_try_new0(char *, ns_entries + 1);
432 for (i = 0, list = option; list; list = list->next, i++)
433 timeservers[i] = g_strdup(list->data);
434 timeservers[ns_entries] = NULL;
437 if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
438 if (dhcp->nameservers) {
439 #if defined TIZEN_EXT
440 for (i = 0; dhcp->nameservers[i] != NULL; i++) {
441 __connman_service_nameserver_remove(service,
442 dhcp->nameservers[i], false,
443 CONNMAN_IPCONFIG_TYPE_IPV4);
446 for (i = 0; dhcp->nameservers[i]; i++) {
447 __connman_service_nameserver_remove(service,
448 dhcp->nameservers[i], false);
451 g_strfreev(dhcp->nameservers);
454 dhcp->nameservers = nameservers;
456 for (i = 0; dhcp->nameservers && dhcp->nameservers[i]; i++) {
457 #if defined TIZEN_EXT
458 __connman_service_nameserver_append(service,
459 dhcp->nameservers[i], false,
460 CONNMAN_IPCONFIG_TYPE_IPV4);
462 __connman_service_nameserver_append(service,
463 dhcp->nameservers[i], false);
467 g_strfreev(nameservers);
470 if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
471 if (dhcp->timeservers) {
472 for (i = 0; dhcp->timeservers[i]; i++) {
473 __connman_service_timeserver_remove(service,
474 dhcp->timeservers[i]);
476 g_strfreev(dhcp->timeservers);
479 dhcp->timeservers = timeservers;
481 for (i = 0; dhcp->timeservers && dhcp->timeservers[i]; i++) {
482 __connman_service_timeserver_append(service,
483 dhcp->timeservers[i]);
486 g_strfreev(timeservers);
489 if (g_strcmp0(pac, dhcp->pac) != 0) {
493 __connman_ipconfig_set_proxy_autoconfig(dhcp->ipconfig,
497 if (connman_setting_get_bool("Enable6to4"))
498 __connman_6to4_probe(service);
503 static void lease_available_cb(GDHCPClient *dhcp_client, gpointer user_data)
505 struct connman_dhcp *dhcp = user_data;
506 GList *option = NULL;
507 enum connman_ipconfig_method old_method;
508 char *address, *netmask = NULL, *gateway = NULL;
509 const char *c_address, *c_gateway;
510 unsigned char prefixlen, c_prefixlen;
511 bool ip_change = false;
513 DBG("Lease available");
515 if (dhcp->ipv4ll_client) {
516 ipv4ll_stop_client(dhcp);
517 dhcp_invalidate(dhcp, false);
520 c_address = __connman_ipconfig_get_local(dhcp->ipconfig);
521 c_gateway = __connman_ipconfig_get_gateway(dhcp->ipconfig);
522 c_prefixlen = __connman_ipconfig_get_prefixlen(dhcp->ipconfig);
524 address = g_dhcp_client_get_address(dhcp_client);
526 __connman_ipconfig_set_dhcp_address(dhcp->ipconfig, address);
527 DBG("last address %s", address);
529 #if defined TIZEN_EXT
530 int dhcp_lease_duration = g_dhcp_client_get_dhcp_lease_duration(dhcp_client);
533 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_SUBNET);
535 netmask = g_strdup(option->data);
537 option = g_dhcp_client_get_option(dhcp_client, G_DHCP_ROUTER);
539 gateway = g_strdup(option->data);
541 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
542 if (prefixlen == 255)
543 connman_warn("netmask: %s is invalid", netmask);
545 DBG("c_address %s", c_address);
547 if (g_strcmp0(address, c_address)) {
550 /* Remove old ip address */
551 __connman_ipconfig_address_remove(dhcp->ipconfig);
554 if (g_strcmp0(gateway, c_gateway)) {
557 /* Remove gateway ip address */
558 __connman_ipconfig_gateway_remove(dhcp->ipconfig);
560 } else if (prefixlen != c_prefixlen)
563 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
564 __connman_ipconfig_set_method(dhcp->ipconfig,
565 CONNMAN_IPCONFIG_METHOD_DHCP);
567 #if defined TIZEN_EXT
568 __connman_ipconfig_set_dhcp_lease_duration(dhcp->ipconfig, dhcp_lease_duration);
569 __connman_network_notify_dhcp_changed(DHCP_SUCCESS, &dhcp_lease_duration);
573 * Notify IPv4.Configuration's method moved back to DHCP.
575 * This is the case ConnMan initially set an address by using
576 * IPv4LL because DHCP failed but now we got an address from DHCP.
578 if (old_method == CONNMAN_IPCONFIG_METHOD_AUTO) {
579 struct connman_service *service =
580 connman_service_lookup_from_network(dhcp->network);
583 __connman_service_notify_ipv4_configuration(service);
586 #if defined TIZEN_EXT
587 if (connman_network_get_bool(dhcp->network, "WiFi.RoamingDHCP")) {
590 connman_service_notify_reconnection(
591 connman_service_lookup_from_network(dhcp->network));
593 connman_network_set_bool(dhcp->network, "WiFi.RoamingDHCP", false);
598 __connman_ipconfig_set_local(dhcp->ipconfig, address);
599 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
600 __connman_ipconfig_set_gateway(dhcp->ipconfig, gateway);
603 if (!apply_lease_available_on_network(dhcp_client, dhcp))
615 static void ipv4ll_available_cb(GDHCPClient *ipv4ll_client, gpointer user_data)
617 struct connman_dhcp *dhcp = user_data;
618 enum connman_ipconfig_method old_method;
619 char *address, *netmask;
620 unsigned char prefixlen;
622 DBG("IPV4LL available");
624 address = g_dhcp_client_get_address(ipv4ll_client);
625 netmask = g_dhcp_client_get_netmask(ipv4ll_client);
627 prefixlen = connman_ipaddress_calc_netmask_len(netmask);
629 old_method = __connman_ipconfig_get_method(dhcp->ipconfig);
630 __connman_ipconfig_set_method(dhcp->ipconfig,
631 CONNMAN_IPCONFIG_METHOD_AUTO);
634 * Notify IPv4.Configuration's method is AUTO now.
636 * This is the case DHCP failed thus ConnMan used IPv4LL to get an
637 * address. Set IPv4.Configuration method to AUTO allows user to
638 * ask for a DHCP address by setting the method again to DHCP.
640 if (old_method == CONNMAN_IPCONFIG_METHOD_DHCP) {
641 struct connman_service *service =
642 connman_service_lookup_from_network(dhcp->network);
645 __connman_service_notify_ipv4_configuration(service);
648 __connman_ipconfig_set_local(dhcp->ipconfig, address);
649 __connman_ipconfig_set_prefixlen(dhcp->ipconfig, prefixlen);
650 __connman_ipconfig_set_gateway(dhcp->ipconfig, NULL);
658 static int dhcp_initialize(struct connman_dhcp *dhcp)
660 GDHCPClient *dhcp_client;
661 GDHCPClientError error;
663 const char *vendor_class_id;
665 DBG("dhcp %p", dhcp);
667 index = __connman_ipconfig_get_index(dhcp->ipconfig);
669 dhcp_client = g_dhcp_client_new(G_DHCP_IPV4, index, &error);
670 if (error != G_DHCP_CLIENT_ERROR_NONE)
671 #if defined TIZEN_EXT
673 DBG("failed g_dhcp_client_new(%d), index(%d)", error, index);
676 #if defined TIZEN_EXT
680 #if !defined TIZEN_EXT
681 if (getenv("CONNMAN_DHCP_DEBUG")) {
683 dhcp->dhcp_debug_prefix = g_strdup_printf("DHCP index %d",
685 g_dhcp_client_set_debug(dhcp_client, dhcp_debug,
686 dhcp->dhcp_debug_prefix);
687 #if !defined TIZEN_EXT
691 g_dhcp_client_set_id(dhcp_client);
694 struct connman_service *service;
695 const char *hostname;
697 service = connman_service_lookup_from_network(dhcp->network);
699 hostname = __connman_service_get_hostname(service);
701 hostname = connman_utsname_get_hostname();
704 g_dhcp_client_set_send(dhcp_client,
705 G_DHCP_HOST_NAME, hostname);
707 g_dhcp_client_set_request(dhcp_client, G_DHCP_HOST_NAME);
708 g_dhcp_client_set_request(dhcp_client, G_DHCP_DNS_SERVER);
709 g_dhcp_client_set_request(dhcp_client, G_DHCP_DOMAIN_NAME);
710 g_dhcp_client_set_request(dhcp_client, G_DHCP_NTP_SERVER);
711 g_dhcp_client_set_request(dhcp_client, 252);
712 g_dhcp_client_set_request(dhcp_client, G_DHCP_MTU);
715 g_dhcp_client_set_request(dhcp_client, G_DHCP_ROUTER);
716 g_dhcp_client_set_request(dhcp_client, G_DHCP_SUBNET);
718 vendor_class_id = connman_setting_get_string("VendorClassID");
720 g_dhcp_client_set_send(dhcp_client, G_DHCP_VENDOR_CLASS_ID,
723 g_dhcp_client_register_event(dhcp_client,
724 G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
725 lease_available_cb, dhcp);
727 g_dhcp_client_register_event(dhcp_client,
728 G_DHCP_CLIENT_EVENT_LEASE_LOST, lease_lost_cb, dhcp);
730 g_dhcp_client_register_event(dhcp_client,
731 G_DHCP_CLIENT_EVENT_NO_LEASE, no_lease_cb, dhcp);
733 dhcp->dhcp_client = dhcp_client;
738 static int dhcp_release(struct connman_dhcp *dhcp)
740 DBG("dhcp %p", dhcp);
742 if (dhcp->timeout > 0) {
743 g_source_remove(dhcp->timeout);
747 if (dhcp->dhcp_client) {
748 g_dhcp_client_stop(dhcp->dhcp_client);
749 g_dhcp_client_unref(dhcp->dhcp_client);
752 dhcp->dhcp_client = NULL;
754 g_free(dhcp->dhcp_debug_prefix);
755 dhcp->dhcp_debug_prefix = NULL;
757 ipv4ll_stop_client(dhcp);
762 char *__connman_dhcp_get_server_address(struct connman_ipconfig *ipconfig)
764 struct connman_dhcp *dhcp;
766 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
770 return g_dhcp_client_get_server_address(dhcp->dhcp_client);
773 #if defined TIZEN_EXT_WIFI_MESH
774 int __connman_mesh_dhcp_start(struct connman_ipconfig *ipconfig,
775 dhcp_cb callback, gpointer user_data)
777 struct connman_dhcp *dhcp;
782 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
785 dhcp = g_try_new0(struct connman_dhcp, 1);
789 dhcp->ipconfig = ipconfig;
790 __connman_ipconfig_ref(ipconfig);
792 err = dhcp_initialize(dhcp);
799 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
802 dhcp->callback = callback;
803 dhcp->user_data = user_data;
804 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
808 int __connman_dhcp_start(struct connman_ipconfig *ipconfig,
809 struct connman_network *network, dhcp_cb callback,
812 #if !defined TIZEN_EXT
813 const char *last_addr = NULL;
815 struct connman_dhcp *dhcp;
821 struct connman_service *service;
823 service = connman_service_lookup_from_network(network);
828 #if !defined TIZEN_EXT
829 last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
832 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
835 dhcp = g_try_new0(struct connman_dhcp, 1);
839 dhcp->ipconfig = ipconfig;
840 __connman_ipconfig_ref(ipconfig);
843 dhcp->network = network;
844 connman_network_ref(network);
847 err = dhcp_initialize(dhcp);
851 connman_network_unref(network);
856 g_hash_table_insert(ipconfig_table, ipconfig, dhcp);
859 dhcp->callback = callback;
860 dhcp->user_data = user_data;
862 #if defined TIZEN_EXT
863 if (network && connman_network_get_bool(network, "WiFi.RoamingDHCP")) {
864 const char *last_addr = __connman_ipconfig_get_dhcp_address(ipconfig);
866 DBG("Start DHCP with last address request");
867 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
869 DBG("Start DHCP with DHCPDISCOVER request");
870 return g_dhcp_client_start(dhcp->dhcp_client, NULL);
873 return g_dhcp_client_start(dhcp->dhcp_client, last_addr);
877 void __connman_dhcp_stop(struct connman_ipconfig *ipconfig)
879 struct connman_dhcp *dhcp;
881 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
886 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
888 g_hash_table_remove(ipconfig_table, ipconfig);
889 __connman_ipconfig_unref(ipconfig);
891 connman_network_unref(dhcp->network);
893 dhcp_invalidate(dhcp, false);
898 void __connman_dhcp_decline(struct connman_ipconfig *ipconfig)
900 struct connman_dhcp *dhcp;
904 DBG("ipconfig_table %p ipconfig %p", ipconfig_table, ipconfig);
909 dhcp = g_hash_table_lookup(ipconfig_table, ipconfig);
911 address = __connman_ipconfig_get_local(ipconfig);
915 if (inet_pton(AF_INET, address, &addr) != 1)
916 connman_error("Could not convert address %s", address);
918 g_dhcp_client_decline(dhcp->dhcp_client, htonl(addr.s_addr));
922 int __connman_dhcp_init(void)
926 ipconfig_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
932 void __connman_dhcp_cleanup(void)
936 g_hash_table_destroy(ipconfig_table);
937 ipconfig_table = NULL;