5 * Copyright (C) 2012-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
31 #include <connman/ipconfig.h>
32 #include <connman/storage.h>
34 #include <gdhcp/gdhcp.h>
40 /* Transmission params in msec, RFC 3315 chapter 5.5 */
41 #define INF_MAX_DELAY (1 * 1000)
42 #define INF_TIMEOUT (1 * 1000)
43 #define INF_MAX_RT (120 * 1000)
44 #define SOL_MAX_DELAY (1 * 1000)
45 #define SOL_TIMEOUT (1 * 1000)
46 #define SOL_MAX_RT (120 * 1000)
47 #define REQ_TIMEOUT (1 * 1000)
48 #define REQ_MAX_RT (30 * 1000)
50 #define REN_TIMEOUT (10 * 1000)
51 #define REN_MAX_RT (600 * 1000)
52 #define REB_TIMEOUT (10 * 1000)
53 #define REB_MAX_RT (600 * 1000)
54 #define CNF_MAX_DELAY (1 * 1000)
55 #define CNF_TIMEOUT (1 * 1000)
56 #define CNF_MAX_RT (4 * 1000)
57 #define CNF_MAX_RD (10 * 1000)
58 #define DEC_TIMEOUT (1 * 1000)
67 struct connman_dhcpv6 {
68 struct connman_network *network;
74 GDHCPClient *dhcp_client;
76 guint timeout; /* operation timeout in msec */
77 guint MRD; /* max operation timeout in msec */
78 guint RT; /* in msec */
79 bool use_ta; /* set to TRUE if IPv6 privacy is enabled */
80 GSList *prefixes; /* network prefixes from radvd or dhcpv6 pd */
81 int request_count; /* how many times REQUEST have been sent */
82 bool stateless; /* TRUE if stateless DHCPv6 is used */
83 bool started; /* TRUE if we have DHCPv6 started */
86 static GHashTable *network_table;
87 static GHashTable *network_pd_table;
89 static int dhcpv6_request(struct connman_dhcpv6 *dhcp, bool add_addresses);
90 static int dhcpv6_pd_request(struct connman_dhcpv6 *dhcp);
91 static gboolean start_solicitation(gpointer user_data);
92 static int dhcpv6_renew(struct connman_dhcpv6 *dhcp);
93 static int dhcpv6_rebind(struct connman_dhcpv6 *dhcp);
95 static void clear_timer(struct connman_dhcpv6 *dhcp)
97 if (dhcp->timeout > 0) {
98 g_source_remove(dhcp->timeout);
103 g_source_remove(dhcp->MRD);
108 static inline guint get_random(void)
112 __connman_util_get_random(&val);
114 /* Make sure the value is always positive so strip MSB */
115 return ((uint32_t)val) >> 1;
118 static guint compute_random(guint val)
120 return val - val / 10 +
121 (get_random() % (2 * 1000)) * val / 10 / 1000;
124 /* Calculate a random delay, RFC 3315 chapter 14 */
125 /* RT and MRT are milliseconds */
126 static guint calc_delay(guint RT, guint MRT)
128 if (MRT && (RT > MRT / 2))
129 RT = compute_random(MRT);
131 RT += compute_random(RT);
136 static guint initial_rt(guint timeout)
138 return compute_random(timeout);
141 static void free_prefix(gpointer data)
146 static void dhcpv6_free(struct connman_dhcpv6 *dhcp)
148 g_strfreev(dhcp->nameservers);
149 g_strfreev(dhcp->timeservers);
151 dhcp->nameservers = NULL;
152 dhcp->timeservers = NULL;
153 dhcp->started = false;
155 g_slist_free_full(dhcp->prefixes, free_prefix);
158 static bool compare_string_arrays(char **array_a, char **array_b)
162 if (!array_a || !array_b)
165 if (g_strv_length(array_a) != g_strv_length(array_b))
168 for (i = 0; array_a[i] && array_b[i]; i++)
169 if (g_strcmp0(array_a[i], array_b[i]) != 0)
175 static void dhcpv6_debug(const char *str, void *data)
177 connman_info("%s: %s\n", (const char *) data, str);
180 static gchar *convert_to_hex(unsigned char *buf, int len)
182 gchar *ret = g_try_malloc(len * 2 + 1);
185 for (i = 0; ret && i < len; i++)
186 g_snprintf(ret + i * 2, 3, "%02x", buf[i]);
192 * DUID should not change over time so save it to file.
193 * See RFC 3315 chapter 9 for details.
195 static int set_duid(struct connman_service *service,
196 struct connman_network *network,
197 GDHCPClient *dhcp_client, int index)
205 ident = __connman_service_get_ident(service);
207 keyfile = connman_storage_load_service(ident);
211 hex_duid = g_key_file_get_string(keyfile, ident, "IPv6.DHCP.DUID",
214 unsigned int i, j = 0, hex;
215 size_t hex_duid_len = strlen(hex_duid);
217 duid = g_try_malloc0(hex_duid_len / 2);
219 g_key_file_free(keyfile);
224 for (i = 0; i < hex_duid_len; i += 2) {
225 sscanf(hex_duid + i, "%02x", &hex);
229 duid_len = hex_duid_len / 2;
232 int type = __connman_ipconfig_get_type_from_index(index);
234 ret = g_dhcpv6_create_duid(G_DHCPV6_DUID_LLT, index, type,
237 g_key_file_free(keyfile);
241 hex_duid = convert_to_hex(duid, duid_len);
243 g_key_file_free(keyfile);
247 g_key_file_set_string(keyfile, ident, "IPv6.DHCP.DUID",
250 __connman_storage_save_service(keyfile, ident);
254 g_key_file_free(keyfile);
256 g_dhcpv6_client_set_duid(dhcp_client, duid, duid_len);
261 static void clear_callbacks(GDHCPClient *dhcp_client)
263 g_dhcp_client_register_event(dhcp_client,
264 G_DHCP_CLIENT_EVENT_SOLICITATION,
267 g_dhcp_client_register_event(dhcp_client,
268 G_DHCP_CLIENT_EVENT_ADVERTISE,
271 g_dhcp_client_register_event(dhcp_client,
272 G_DHCP_CLIENT_EVENT_REQUEST,
275 g_dhcp_client_register_event(dhcp_client,
276 G_DHCP_CLIENT_EVENT_CONFIRM,
279 g_dhcp_client_register_event(dhcp_client,
280 G_DHCP_CLIENT_EVENT_RENEW,
283 g_dhcp_client_register_event(dhcp_client,
284 G_DHCP_CLIENT_EVENT_REBIND,
287 g_dhcp_client_register_event(dhcp_client,
288 G_DHCP_CLIENT_EVENT_RELEASE,
291 g_dhcp_client_register_event(dhcp_client,
292 G_DHCP_CLIENT_EVENT_DECLINE,
295 g_dhcp_client_register_event(dhcp_client,
296 G_DHCP_CLIENT_EVENT_INFORMATION_REQ,
300 static void info_req_cb(GDHCPClient *dhcp_client, gpointer user_data)
302 struct connman_dhcpv6 *dhcp = user_data;
303 struct connman_service *service;
305 GList *option, *list;
306 char **nameservers, **timeservers;
308 DBG("dhcpv6 information-request %p", dhcp);
310 service = connman_service_lookup_from_network(dhcp->network);
312 connman_error("Can not lookup service");
316 g_dhcpv6_client_clear_retransmit(dhcp_client);
318 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DNS_SERVERS);
319 entries = g_list_length(option);
321 nameservers = g_try_new0(char *, entries + 1);
323 for (i = 0, list = option; list; list = list->next, i++)
324 nameservers[i] = g_strdup(list->data);
327 if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
328 if (dhcp->nameservers) {
329 for (i = 0; dhcp->nameservers[i]; i++)
330 #if defined TIZEN_EXT
332 __connman_service_nameserver_remove(service,
333 dhcp->nameservers[i], false,
334 CONNMAN_IPCONFIG_TYPE_IPV6);
336 __connman_service_nameserver_remove(service,
337 dhcp->nameservers[i],
340 #if defined TIZEN_EXT
343 g_strfreev(dhcp->nameservers);
346 dhcp->nameservers = nameservers;
348 for (i = 0; dhcp->nameservers &&
349 dhcp->nameservers[i]; i++)
350 #if defined TIZEN_EXT
352 __connman_service_nameserver_append(service,
353 dhcp->nameservers[i], false,
354 CONNMAN_IPCONFIG_TYPE_IPV6);
356 __connman_service_nameserver_append(service,
357 dhcp->nameservers[i],
360 #if defined TIZEN_EXT
364 g_strfreev(nameservers);
367 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_SNTP_SERVERS);
368 entries = g_list_length(option);
370 timeservers = g_try_new0(char *, entries + 1);
372 for (i = 0, list = option; list; list = list->next, i++)
373 timeservers[i] = g_strdup(list->data);
376 if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
377 if (dhcp->timeservers) {
378 for (i = 0; dhcp->timeservers[i]; i++)
379 __connman_service_timeserver_remove(service,
380 dhcp->timeservers[i]);
381 g_strfreev(dhcp->timeservers);
384 dhcp->timeservers = timeservers;
386 for (i = 0; dhcp->timeservers &&
387 dhcp->timeservers[i]; i++)
388 __connman_service_timeserver_append(service,
389 dhcp->timeservers[i]);
391 g_strfreev(timeservers);
394 if (dhcp->callback) {
395 uint16_t status = g_dhcpv6_client_get_status(dhcp_client);
396 dhcp->callback(dhcp->network, status == 0 ?
397 CONNMAN_DHCPV6_STATUS_SUCCEED :
398 CONNMAN_DHCPV6_STATUS_FAIL,
403 static int dhcpv6_info_request(struct connman_dhcpv6 *dhcp)
405 struct connman_service *service;
406 GDHCPClient *dhcp_client;
407 GDHCPClientError error;
410 DBG("dhcp %p", dhcp);
412 index = connman_network_get_index(dhcp->network);
414 dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
415 if (error != G_DHCP_CLIENT_ERROR_NONE) {
420 #if !defined TIZEN_EXT
421 if (getenv("CONNMAN_DHCPV6_DEBUG"))
423 g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6");
425 service = connman_service_lookup_from_network(dhcp->network);
428 g_dhcp_client_unref(dhcp_client);
432 ret = set_duid(service, dhcp->network, dhcp_client, index);
435 g_dhcp_client_unref(dhcp_client);
439 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
440 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
441 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
442 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
444 g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
445 G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
447 g_dhcp_client_register_event(dhcp_client,
448 G_DHCP_CLIENT_EVENT_INFORMATION_REQ, info_req_cb, dhcp);
450 dhcp->dhcp_client = dhcp_client;
452 return g_dhcp_client_start(dhcp_client, NULL);
455 static int check_ipv6_addr_prefix(GSList *prefixes, char *address)
457 struct in6_addr addr_prefix, addr;
461 for (list = prefixes; list; list = list->next) {
462 char *prefix = list->data;
463 const char *slash = g_strrstr(prefix, "/");
464 const unsigned char bits[] = { 0x00, 0xFE, 0xFC, 0xF8,
465 0xF0, 0xE0, 0xC0, 0x80 };
466 int left, count, i, plen;
471 prefix = g_strndup(prefix, slash - prefix);
472 len = strtol(slash + 1, NULL, 10);
473 if (len < 3 || len > 128)
482 inet_pton(AF_INET6, prefix, &addr_prefix);
483 inet_pton(AF_INET6, address, &addr);
485 memset(&addr_prefix.s6_addr[i], 0, count);
486 memset(&addr.s6_addr[i], 0, count);
489 addr_prefix.s6_addr[i - 1] &= bits[left];
490 addr.s6_addr[i - 1] &= bits[left];
495 if (memcmp(&addr_prefix, &addr, 16) == 0) {
504 static int set_other_addresses(GDHCPClient *dhcp_client,
505 struct connman_dhcpv6 *dhcp)
507 struct connman_service *service;
509 GList *option, *list;
510 char **nameservers, **timeservers;
512 service = connman_service_lookup_from_network(dhcp->network);
514 connman_error("Can not lookup service");
519 * Check domains before nameservers so that the nameserver append
520 * function will update domain list in service.c
522 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DOMAIN_LIST);
523 entries = g_list_length(option);
525 char **domains = g_try_new0(char *, entries + 1);
527 for (i = 0, list = option; list;
528 list = list->next, i++)
529 domains[i] = g_strdup(list->data);
530 __connman_service_set_search_domains(service, domains);
535 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_DNS_SERVERS);
536 entries = g_list_length(option);
538 nameservers = g_try_new0(char *, entries + 1);
540 for (i = 0, list = option; list; list = list->next, i++)
541 nameservers[i] = g_strdup(list->data);
544 if (!compare_string_arrays(nameservers, dhcp->nameservers)) {
545 if (dhcp->nameservers) {
546 for (i = 0; dhcp->nameservers[i]; i++)
547 #if defined TIZEN_EXT
549 __connman_service_nameserver_remove(service,
550 dhcp->nameservers[i],
551 false, CONNMAN_IPCONFIG_TYPE_IPV6);
553 __connman_service_nameserver_remove(service,
554 dhcp->nameservers[i],
557 #if defined TIZEN_EXT
560 g_strfreev(dhcp->nameservers);
563 dhcp->nameservers = nameservers;
565 for (i = 0; dhcp->nameservers &&
566 dhcp->nameservers[i]; i++)
567 #if defined TIZEN_EXT
569 __connman_service_nameserver_append(service,
570 dhcp->nameservers[i],
571 false, CONNMAN_IPCONFIG_TYPE_IPV6);
573 __connman_service_nameserver_append(service,
574 dhcp->nameservers[i],
577 #if defined TIZEN_EXT
581 g_strfreev(nameservers);
584 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_SNTP_SERVERS);
585 entries = g_list_length(option);
587 timeservers = g_try_new0(char *, entries + 1);
589 for (i = 0, list = option; list; list = list->next, i++)
590 timeservers[i] = g_strdup(list->data);
593 if (!compare_string_arrays(timeservers, dhcp->timeservers)) {
594 if (dhcp->timeservers) {
595 for (i = 0; dhcp->timeservers[i]; i++)
596 __connman_service_timeserver_remove(service,
597 dhcp->timeservers[i]);
598 g_strfreev(dhcp->timeservers);
601 dhcp->timeservers = timeservers;
603 for (i = 0; dhcp->timeservers &&
604 dhcp->timeservers[i]; i++)
605 __connman_service_timeserver_append(service,
606 dhcp->timeservers[i]);
608 g_strfreev(timeservers);
613 static GSList *copy_prefixes(GSList *prefixes)
615 GSList *list, *copy = NULL;
617 for (list = prefixes; list; list = list->next)
618 copy = g_slist_prepend(copy, g_strdup(list->data));
624 * Helper struct for doing DAD (duplicate address detection).
625 * It is refcounted and freed after all reply's to neighbor
626 * discovery request are received.
632 GDHCPClient *dhcp_client;
633 struct connman_ipconfig *ipconfig;
641 static void free_own_address(struct own_address *data)
643 g_dhcp_client_unref(data->dhcp_client);
644 __connman_ipconfig_unref(data->ipconfig);
645 g_slist_free_full(data->prefixes, free_prefix);
646 g_slist_free_full(data->dad_failed, g_free);
647 g_slist_free_full(data->dad_succeed, g_free);
652 static struct own_address *ref_own_address(struct own_address *address)
654 DBG("%p ref %d", address, address->refcount + 1);
656 __sync_fetch_and_add(&address->refcount, 1);
661 static void unref_own_address(struct own_address *address)
666 DBG("%p ref %d", address, address->refcount - 1);
668 if (__sync_fetch_and_sub(&address->refcount, 1) != 1)
671 free_own_address(address);
674 static void set_address(int ifindex, struct connman_ipconfig *ipconfig,
675 GSList *prefixes, char *address)
677 const char *c_address;
679 c_address = __connman_ipconfig_get_local(ipconfig);
681 if (address && ((c_address && g_strcmp0(address, c_address) != 0) ||
685 /* Is this prefix part of the subnet we are suppose to use? */
686 prefix_len = check_ipv6_addr_prefix(prefixes, address);
688 __connman_ipconfig_address_remove(ipconfig);
689 __connman_ipconfig_set_local(ipconfig, address);
690 __connman_ipconfig_set_prefixlen(ipconfig, prefix_len);
692 DBG("new address %s/%d", address, prefix_len);
694 __connman_ipconfig_set_dhcp_address(ipconfig, address);
695 __connman_service_save(
696 __connman_service_lookup_from_index(ifindex));
702 * Helper struct that is used when waiting a reply to DECLINE message.
704 struct decline_cb_data {
705 GDHCPClient *dhcp_client;
711 static void decline_reply_callback(struct decline_cb_data *data)
713 struct connman_network *network;
714 struct connman_service *service;
716 service = __connman_service_lookup_from_index(data->ifindex);
717 network = __connman_service_get_network(service);
720 data->callback(network, CONNMAN_DHCPV6_STATUS_RESTART, NULL);
722 g_dhcp_client_unref(data->dhcp_client);
725 static gboolean decline_timeout(gpointer user_data)
727 struct decline_cb_data *data = user_data;
729 DBG("ifindex %d", data->ifindex);
732 * We ignore all DECLINE replies that are received after the timeout
734 g_dhcp_client_register_event(data->dhcp_client,
735 G_DHCP_CLIENT_EVENT_DECLINE,
738 decline_reply_callback(data);
745 static void decline_cb(GDHCPClient *dhcp_client, gpointer user_data)
747 struct decline_cb_data *data = user_data;
749 DBG("ifindex %d", data->ifindex);
751 g_dhcpv6_client_clear_retransmit(dhcp_client);
754 g_source_remove(data->timeout);
756 decline_reply_callback(data);
761 static int dhcpv6_decline(GDHCPClient *dhcp_client, int ifindex,
762 dhcpv6_cb callback, GSList *failed)
764 struct decline_cb_data *data;
768 DBG("dhcp_client %p", dhcp_client);
770 g_dhcp_client_clear_requests(dhcp_client);
772 g_dhcpv6_client_clear_send(dhcp_client, G_DHCPV6_ORO);
774 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
775 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
777 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_NA);
779 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_TA);
781 code = G_DHCPV6_IA_TA;
785 code = G_DHCPV6_IA_NA;
787 g_dhcpv6_client_clear_send(dhcp_client, code);
789 g_dhcpv6_client_set_ias(dhcp_client, ifindex, code, NULL, NULL,
792 clear_callbacks(dhcp_client);
794 data = g_try_new(struct decline_cb_data, 1);
798 data->ifindex = ifindex;
799 data->callback = callback;
800 data->dhcp_client = g_dhcp_client_ref(dhcp_client);
801 data->timeout = g_timeout_add(DEC_TIMEOUT, decline_timeout, data);
803 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_DECLINE,
806 return g_dhcp_client_start(dhcp_client, NULL);
809 static void dad_reply(struct nd_neighbor_advert *reply,
810 unsigned int length, struct in6_addr *addr, void *user_data)
812 struct own_address *data = user_data;
814 char address[INET6_ADDRSTRLEN];
815 enum __connman_dhcpv6_status status = CONNMAN_DHCPV6_STATUS_FAIL;
817 inet_ntop(AF_INET6, addr, address, INET6_ADDRSTRLEN);
819 DBG("user %p reply %p len %d address %s index %d data %p", user_data,
820 reply, length, address, data->ifindex, data);
824 DBG("DAD succeed for %s", address);
826 DBG("DAD cannot be done for %s", address);
828 data->dad_succeed = g_slist_prepend(data->dad_succeed,
832 DBG("DAD failed for %s", address);
834 data->dad_failed = g_slist_prepend(data->dad_failed,
839 * If refcount == 1 then we got the final reply and can continue.
841 if (data->refcount > 1)
844 for (list = data->dad_succeed; list; list = list->next)
845 set_address(data->ifindex, data->ipconfig, data->prefixes,
848 if (data->dad_failed) {
849 dhcpv6_decline(data->dhcp_client, data->ifindex,
850 data->callback, data->dad_failed);
852 if (data->dad_succeed)
853 status = CONNMAN_DHCPV6_STATUS_SUCCEED;
855 if (data->callback) {
856 struct connman_network *network;
857 struct connman_service *service;
859 service = __connman_service_lookup_from_index(
861 network = __connman_service_get_network(service);
863 data->callback(network, status, NULL);
867 unref_own_address(data);
871 * Is the kernel configured to do DAD? If 0, then do not do DAD.
872 * See also RFC 4862 chapter 5.4 about DupAddrDetectTransmits
874 static int dad_transmits(int ifindex)
876 char name[IF_NAMESIZE];
881 if (!if_indextoname(ifindex, name))
884 path = g_strdup_printf("/proc/sys/net/ipv6/conf/%s/dad_transmits",
890 f = fopen(path, "r");
895 if (fscanf(f, "%d", &value) < 0)
904 static void do_dad(GDHCPClient *dhcp_client, struct connman_dhcpv6 *dhcp)
906 struct connman_service *service;
907 struct connman_ipconfig *ipconfig;
909 GList *option, *list;
910 struct own_address *user_data;
912 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_NA);
914 option = g_dhcp_client_get_option(dhcp_client, G_DHCPV6_IA_TA);
917 * Even if we didn't had any addresses, just try to set
920 set_other_addresses(dhcp_client, dhcp);
923 DBG("Skip DAD as no addresses found in reply");
925 dhcp->callback(dhcp->network,
926 CONNMAN_DHCPV6_STATUS_SUCCEED, NULL);
931 ifindex = connman_network_get_index(dhcp->network);
933 DBG("index %d", ifindex);
935 service = connman_service_lookup_from_network(dhcp->network);
937 connman_error("Can not lookup service for index %d", ifindex);
941 ipconfig = __connman_service_get_ip6config(service);
943 connman_error("Could not lookup ip6config for index %d",
948 if (!dad_transmits(ifindex)) {
949 DBG("Skip DAD because of kernel configuration");
951 for (list = option; list; list = list->next)
952 set_address(ifindex, ipconfig, dhcp->prefixes,
956 dhcp->callback(dhcp->network,
957 CONNMAN_DHCPV6_STATUS_SUCCEED, NULL);
962 if (g_list_length(option) == 0) {
963 DBG("No addresses when doing DAD");
965 dhcp->callback(dhcp->network,
966 CONNMAN_DHCPV6_STATUS_SUCCEED, NULL);
971 user_data = g_try_new0(struct own_address, 1);
975 user_data->refcount = 0;
976 user_data->ifindex = ifindex;
977 user_data->dhcp_client = g_dhcp_client_ref(dhcp_client);
978 user_data->ipconfig = __connman_ipconfig_ref(ipconfig);
979 user_data->prefixes = copy_prefixes(dhcp->prefixes);
980 user_data->callback = dhcp->callback;
983 * We send one neighbor discovery request / address
984 * and after all checks are done, then report the status
988 for (list = option; list; list = list->next) {
989 char *address = option->data;
990 struct in6_addr addr;
993 ref_own_address(user_data);
995 if (inet_pton(AF_INET6, address, &addr) < 0) {
996 DBG("Invalid IPv6 address %s %d/%s", address,
997 -errno, strerror(errno));
1001 DBG("user %p address %s client %p ipconfig %p prefixes %p",
1003 user_data->dhcp_client, user_data->ipconfig,
1004 user_data->prefixes);
1006 ret = __connman_inet_ipv6_do_dad(ifindex, 1000,
1011 DBG("Could not send neighbor solicitation for %s",
1013 dad_reply(NULL, -1, &addr, user_data);
1015 DBG("Sent neighbor solicitation %d bytes", ret);
1022 unref_own_address(user_data);
1026 dhcp->callback(dhcp->network, CONNMAN_DHCPV6_STATUS_FAIL,
1030 static gboolean timeout_request_resend(gpointer user_data)
1032 struct connman_dhcpv6 *dhcp = user_data;
1034 if (dhcp->request_count >= REQ_MAX_RC) {
1035 DBG("max request retry attempts %d", dhcp->request_count);
1036 dhcp->request_count = 0;
1038 dhcp->callback(dhcp->network,
1039 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1043 dhcp->request_count++;
1045 dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
1046 DBG("request resend RT timeout %d msec", dhcp->RT);
1047 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request_resend, dhcp);
1049 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1051 g_dhcp_client_start(dhcp->dhcp_client, NULL);
1056 static gboolean request_resend(gpointer user_data)
1058 struct connman_dhcpv6 *dhcp = user_data;
1060 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1062 dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
1063 DBG("request resend RT timeout %d msec", dhcp->RT);
1064 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request_resend, dhcp);
1066 dhcpv6_request(dhcp, true);
1071 static void do_resend_request(struct connman_dhcpv6 *dhcp)
1073 if (dhcp->request_count >= REQ_MAX_RC) {
1074 DBG("max request retry attempts %d", dhcp->request_count);
1075 dhcp->request_count = 0;
1077 dhcp->callback(dhcp->network,
1078 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1082 dhcp->request_count++;
1084 dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
1085 DBG("resending request after %d msec", dhcp->RT);
1086 dhcp->timeout = g_timeout_add(dhcp->RT, request_resend, dhcp);
1089 static void re_cb(enum request_type req_type, GDHCPClient *dhcp_client,
1092 struct connman_dhcpv6 *dhcp = user_data;
1097 status = g_dhcpv6_client_get_status(dhcp_client);
1099 DBG("dhcpv6 cb msg %p status %d", dhcp, status);
1102 * RFC 3315, 18.1.8 handle the resend if error
1104 if (status == G_DHCPV6_ERROR_BINDING) {
1105 dhcpv6_request(dhcp, false);
1106 } else if (status == G_DHCPV6_ERROR_MCAST) {
1109 dhcpv6_request(dhcp, true);
1112 dhcpv6_rebind(dhcp);
1118 } else if (status == G_DHCPV6_ERROR_LINK) {
1119 if (req_type == REQ_REQUEST) {
1120 g_dhcp_client_unref(dhcp->dhcp_client);
1121 start_solicitation(dhcp);
1124 dhcp->callback(dhcp->network,
1125 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1127 } else if (status == G_DHCPV6_ERROR_FAILURE) {
1128 if (req_type == REQ_REQUEST) {
1129 /* Rate limit the resend of request message */
1130 do_resend_request(dhcp);
1133 dhcp->callback(dhcp->network,
1134 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1139 * If we did not got any addresses, then re-send
1144 option = g_dhcp_client_get_option(dhcp->dhcp_client,
1147 option = g_dhcp_client_get_option(dhcp->dhcp_client,
1152 do_resend_request(dhcp);
1155 dhcpv6_rebind(dhcp);
1165 if (status == G_DHCPV6_ERROR_SUCCESS)
1166 do_dad(dhcp_client, dhcp);
1167 else if (dhcp->callback)
1168 dhcp->callback(dhcp->network,
1169 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1173 static void rebind_cb(GDHCPClient *dhcp_client, gpointer user_data)
1177 g_dhcpv6_client_reset_request(dhcp_client);
1178 g_dhcpv6_client_clear_retransmit(dhcp_client);
1180 re_cb(REQ_REBIND, dhcp_client, user_data);
1183 static int dhcpv6_rebind(struct connman_dhcpv6 *dhcp)
1185 GDHCPClient *dhcp_client;
1187 DBG("dhcp %p", dhcp);
1189 dhcp_client = dhcp->dhcp_client;
1191 g_dhcp_client_clear_requests(dhcp_client);
1193 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
1194 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
1195 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
1196 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
1198 g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
1199 G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
1201 g_dhcpv6_client_set_ia(dhcp_client,
1202 connman_network_get_index(dhcp->network),
1203 dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
1204 NULL, NULL, TRUE, NULL);
1206 clear_callbacks(dhcp_client);
1208 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REBIND,
1211 dhcp->dhcp_client = dhcp_client;
1213 return g_dhcp_client_start(dhcp_client, NULL);
1216 static gboolean dhcpv6_restart(gpointer user_data)
1218 struct connman_dhcpv6 *dhcp = user_data;
1221 dhcp->callback(dhcp->network, CONNMAN_DHCPV6_STATUS_FAIL,
1228 * Check if we need to restart the solicitation procedure. This
1229 * is done if all the addresses have expired. RFC 3315, 18.1.4
1231 static int check_restart(struct connman_dhcpv6 *dhcp)
1233 time_t current, expired;
1235 g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, NULL, NULL,
1237 current = time(NULL);
1239 if (current >= expired) {
1240 DBG("expired by %d secs", (int)(current - expired));
1242 g_timeout_add(0, dhcpv6_restart, dhcp);
1250 static gboolean timeout_rebind(gpointer user_data)
1252 struct connman_dhcpv6 *dhcp = user_data;
1254 if (check_restart(dhcp) < 0)
1257 dhcp->RT = calc_delay(dhcp->RT, REB_MAX_RT);
1259 DBG("rebind RT timeout %d msec", dhcp->RT);
1261 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_rebind, dhcp);
1263 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1265 g_dhcp_client_start(dhcp->dhcp_client, NULL);
1270 static gboolean start_rebind(gpointer user_data)
1272 struct connman_dhcpv6 *dhcp = user_data;
1274 if (check_restart(dhcp) < 0)
1277 dhcp->RT = initial_rt(REB_TIMEOUT);
1279 DBG("rebind initial RT timeout %d msec", dhcp->RT);
1281 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_rebind, dhcp);
1283 dhcpv6_rebind(dhcp);
1288 static void request_cb(GDHCPClient *dhcp_client, gpointer user_data)
1292 g_dhcpv6_client_reset_request(dhcp_client);
1293 g_dhcpv6_client_clear_retransmit(dhcp_client);
1295 re_cb(REQ_REQUEST, dhcp_client, user_data);
1298 static int dhcpv6_request(struct connman_dhcpv6 *dhcp,
1301 GDHCPClient *dhcp_client;
1304 DBG("dhcp %p add %d", dhcp, add_addresses);
1306 dhcp_client = dhcp->dhcp_client;
1308 g_dhcp_client_clear_requests(dhcp_client);
1310 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
1311 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
1312 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
1313 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
1314 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
1316 g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
1317 G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
1319 g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
1320 g_dhcpv6_client_set_ia(dhcp_client,
1321 connman_network_get_index(dhcp->network),
1322 dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
1323 &T1, &T2, add_addresses, NULL);
1325 clear_callbacks(dhcp_client);
1327 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REQUEST,
1330 dhcp->dhcp_client = dhcp_client;
1332 return g_dhcp_client_start(dhcp_client, NULL);
1335 static gboolean timeout_request(gpointer user_data)
1337 struct connman_dhcpv6 *dhcp = user_data;
1339 if (dhcp->request_count >= REQ_MAX_RC) {
1340 DBG("max request retry attempts %d", dhcp->request_count);
1341 dhcp->request_count = 0;
1343 dhcp->callback(dhcp->network,
1344 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1348 dhcp->request_count++;
1350 dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
1351 DBG("request RT timeout %d msec", dhcp->RT);
1352 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request, dhcp);
1354 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1356 g_dhcp_client_start(dhcp->dhcp_client, NULL);
1361 static void renew_cb(GDHCPClient *dhcp_client, gpointer user_data)
1365 g_dhcpv6_client_reset_request(dhcp_client);
1366 g_dhcpv6_client_clear_retransmit(dhcp_client);
1368 re_cb(REQ_RENEW, dhcp_client, user_data);
1371 static int dhcpv6_renew(struct connman_dhcpv6 *dhcp)
1373 GDHCPClient *dhcp_client;
1376 DBG("dhcp %p", dhcp);
1378 dhcp_client = dhcp->dhcp_client;
1380 g_dhcp_client_clear_requests(dhcp_client);
1382 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
1383 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
1384 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
1385 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
1386 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
1388 g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
1389 G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
1391 g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
1392 g_dhcpv6_client_set_ia(dhcp_client,
1393 connman_network_get_index(dhcp->network),
1394 dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
1395 &T1, &T2, TRUE, NULL);
1397 clear_callbacks(dhcp_client);
1399 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RENEW,
1402 dhcp->dhcp_client = dhcp_client;
1404 return g_dhcp_client_start(dhcp_client, NULL);
1407 static gboolean timeout_renew(gpointer user_data)
1409 struct connman_dhcpv6 *dhcp = user_data;
1410 time_t last_rebind, current;
1413 if (check_restart(dhcp) < 0)
1416 g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, NULL, &T2,
1417 &last_rebind, NULL);
1418 current = time(NULL);
1419 if ((unsigned)current >= (unsigned)last_rebind + T2) {
1421 * Do rebind instead if past T2
1427 dhcp->RT = calc_delay(dhcp->RT, REN_MAX_RT);
1429 DBG("renew RT timeout %d msec", dhcp->RT);
1431 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);
1433 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1435 g_dhcp_client_start(dhcp->dhcp_client, NULL);
1440 static gboolean start_renew(gpointer user_data)
1442 struct connman_dhcpv6 *dhcp = user_data;
1444 dhcp->RT = initial_rt(REN_TIMEOUT);
1446 DBG("renew initial RT timeout %d msec", dhcp->RT);
1448 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);
1455 int __connman_dhcpv6_start_renew(struct connman_network *network,
1458 struct connman_dhcpv6 *dhcp;
1459 uint32_t T1, T2, delta;
1460 time_t started, current, expired;
1462 dhcp = g_hash_table_lookup(network_table, network);
1466 DBG("network %p dhcp %p", network, dhcp);
1470 g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, &T1, &T2,
1471 &started, &expired);
1473 current = time(NULL);
1475 DBG("T1 %u T2 %u expires %lu current %lu started %lu", T1, T2,
1476 (unsigned long)expired, current, started);
1478 if (T1 == 0xffffffff)
1479 /* RFC 3315, 22.4 */
1484 * Client can choose the timeout.
1486 T1 = (expired - started) / 2;
1487 T2 = (expired - started) / 10 * 8;
1490 dhcp->callback = callback;
1492 /* RFC 3315, 18.1.4, start solicit if expired */
1493 if (check_restart(dhcp) < 0)
1496 if (T2 != 0xffffffff && T2 > 0) {
1497 if ((unsigned)current >= (unsigned)started + T2) {
1498 /* RFC 3315, chapter 18.1.3, start rebind */
1499 DBG("start rebind immediately");
1501 dhcp->timeout = g_timeout_add_seconds(0, start_rebind,
1504 } else if ((unsigned)current < (unsigned)started + T1) {
1505 delta = started + T1 - current;
1506 DBG("renew after %d secs", delta);
1508 dhcp->timeout = g_timeout_add_seconds(delta,
1511 delta = started + T2 - current;
1512 DBG("rebind after %d secs", delta);
1514 dhcp->timeout = g_timeout_add_seconds(delta,
1515 start_rebind, dhcp);
1522 static void release_cb(GDHCPClient *dhcp_client, gpointer user_data)
1527 int __connman_dhcpv6_start_release(struct connman_network *network,
1530 struct connman_dhcpv6 *dhcp;
1531 GDHCPClient *dhcp_client;
1534 return 0; /* we are already released */
1536 dhcp = g_hash_table_lookup(network_table, network);
1540 DBG("network %p dhcp %p client %p stateless %d", network, dhcp,
1541 dhcp->dhcp_client, dhcp->stateless);
1543 if (dhcp->stateless)
1548 dhcp_client = dhcp->dhcp_client;
1551 * We had started the DHCPv6 handshaking i.e., we have called
1552 * __connman_dhcpv6_start() but it has not yet sent
1553 * a solicitation message to server. This means that we do not
1554 * have DHCPv6 configured yet so we can just quit here.
1556 DBG("DHCPv6 was not started");
1560 g_dhcp_client_clear_requests(dhcp_client);
1561 g_dhcp_client_clear_values(dhcp_client);
1563 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
1564 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
1566 g_dhcpv6_client_set_ia(dhcp_client,
1567 connman_network_get_index(dhcp->network),
1568 dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
1569 NULL, NULL, TRUE, NULL);
1571 clear_callbacks(dhcp_client);
1574 * Although we register a callback here we are really not interested in
1575 * the answer because it might take too long time and network code
1576 * might be in the middle of the disconnect.
1577 * So we just inform the server that we are done with the addresses
1578 * but ignore the reply from server. This is allowed by RFC 3315
1581 g_dhcp_client_register_event(dhcp_client,
1582 G_DHCP_CLIENT_EVENT_RELEASE,
1585 dhcp->dhcp_client = dhcp_client;
1587 return g_dhcp_client_start(dhcp_client, NULL);
1590 static int dhcpv6_release(struct connman_dhcpv6 *dhcp)
1592 DBG("dhcp %p", dhcp);
1598 if (!dhcp->dhcp_client)
1601 g_dhcp_client_stop(dhcp->dhcp_client);
1602 g_dhcp_client_unref(dhcp->dhcp_client);
1604 dhcp->dhcp_client = NULL;
1609 static void remove_network(gpointer user_data)
1611 struct connman_dhcpv6 *dhcp = user_data;
1613 DBG("dhcp %p", dhcp);
1615 dhcpv6_release(dhcp);
1620 static gboolean timeout_info_req(gpointer user_data)
1622 struct connman_dhcpv6 *dhcp = user_data;
1624 dhcp->RT = calc_delay(dhcp->RT, INF_MAX_RT);
1626 DBG("info RT timeout %d msec", dhcp->RT);
1628 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_info_req, dhcp);
1630 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1632 g_dhcp_client_start(dhcp->dhcp_client, NULL);
1637 static gboolean start_info_req(gpointer user_data)
1639 struct connman_dhcpv6 *dhcp = user_data;
1641 /* Set the retransmission timeout, RFC 3315 chapter 14 */
1642 dhcp->RT = initial_rt(INF_TIMEOUT);
1644 DBG("info initial RT timeout %d msec", dhcp->RT);
1646 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_info_req, dhcp);
1648 dhcpv6_info_request(dhcp);
1653 int __connman_dhcpv6_start_info(struct connman_network *network,
1656 struct connman_dhcpv6 *dhcp;
1662 if (network_table) {
1663 dhcp = g_hash_table_lookup(network_table, network);
1664 if (dhcp && dhcp->started)
1668 dhcp = g_try_new0(struct connman_dhcpv6, 1);
1672 dhcp->network = network;
1673 dhcp->callback = callback;
1674 dhcp->stateless = true;
1675 dhcp->started = true;
1677 connman_network_ref(network);
1679 DBG("replace network %p dhcp %p", network, dhcp);
1681 g_hash_table_replace(network_table, network, dhcp);
1683 /* Initial timeout, RFC 3315, 18.1.5 */
1684 __connman_util_get_random(&rand);
1685 delay = rand % 1000;
1687 dhcp->timeout = g_timeout_add(delay, start_info_req, dhcp);
1692 static void advertise_cb(GDHCPClient *dhcp_client, gpointer user_data)
1694 struct connman_dhcpv6 *dhcp = user_data;
1696 DBG("dhcpv6 advertise msg %p", dhcp);
1700 g_dhcpv6_client_clear_retransmit(dhcp_client);
1702 if (g_dhcpv6_client_get_status(dhcp_client) != 0) {
1704 dhcp->callback(dhcp->network,
1705 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1709 dhcp->RT = initial_rt(REQ_TIMEOUT);
1710 DBG("request initial RT timeout %d msec", dhcp->RT);
1711 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_request, dhcp);
1713 dhcp->request_count = 1;
1715 dhcpv6_request(dhcp, true);
1718 static void solicitation_cb(GDHCPClient *dhcp_client, gpointer user_data)
1720 /* We get here if server supports rapid commit */
1721 struct connman_dhcpv6 *dhcp = user_data;
1723 DBG("dhcpv6 solicitation msg %p", dhcp);
1727 g_dhcpv6_client_clear_retransmit(dhcp_client);
1729 if (g_dhcpv6_client_get_status(dhcp_client) != 0) {
1731 dhcp->callback(dhcp->network,
1732 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
1736 do_dad(dhcp_client, dhcp);
1739 static gboolean timeout_solicitation(gpointer user_data)
1741 struct connman_dhcpv6 *dhcp = user_data;
1743 dhcp->RT = calc_delay(dhcp->RT, SOL_MAX_RT);
1745 DBG("solicit RT timeout %d msec", dhcp->RT);
1747 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);
1749 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
1751 g_dhcp_client_start(dhcp->dhcp_client, NULL);
1756 static int dhcpv6_solicitation(struct connman_dhcpv6 *dhcp)
1758 struct connman_service *service;
1759 struct connman_ipconfig *ipconfig_ipv6;
1760 GDHCPClient *dhcp_client;
1761 GDHCPClientError error;
1764 DBG("dhcp %p", dhcp);
1766 index = connman_network_get_index(dhcp->network);
1768 dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
1769 if (error != G_DHCP_CLIENT_ERROR_NONE) {
1774 #if !defined TIZEN_EXT
1775 if (getenv("CONNMAN_DHCPV6_DEBUG"))
1777 g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6");
1779 service = connman_service_lookup_from_network(dhcp->network);
1782 g_dhcp_client_unref(dhcp_client);
1786 ret = set_duid(service, dhcp->network, dhcp_client, index);
1789 g_dhcp_client_unref(dhcp_client);
1793 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
1794 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_RAPID_COMMIT);
1795 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
1796 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DOMAIN_LIST);
1797 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
1799 g_dhcpv6_client_set_oro(dhcp_client, 3, G_DHCPV6_DNS_SERVERS,
1800 G_DHCPV6_DOMAIN_LIST, G_DHCPV6_SNTP_SERVERS);
1802 ipconfig_ipv6 = __connman_service_get_ip6config(service);
1803 dhcp->use_ta = __connman_ipconfig_ipv6_privacy_enabled(ipconfig_ipv6);
1805 g_dhcpv6_client_set_ia(dhcp_client, index,
1806 dhcp->use_ta ? G_DHCPV6_IA_TA : G_DHCPV6_IA_NA,
1807 NULL, NULL, FALSE, NULL);
1809 clear_callbacks(dhcp_client);
1811 g_dhcp_client_register_event(dhcp_client,
1812 G_DHCP_CLIENT_EVENT_SOLICITATION,
1813 solicitation_cb, dhcp);
1815 g_dhcp_client_register_event(dhcp_client,
1816 G_DHCP_CLIENT_EVENT_ADVERTISE,
1817 advertise_cb, dhcp);
1819 dhcp->dhcp_client = dhcp_client;
1821 return g_dhcp_client_start(dhcp_client, NULL);
1824 static gboolean start_solicitation(gpointer user_data)
1826 struct connman_dhcpv6 *dhcp = user_data;
1828 /* Set the retransmission timeout, RFC 3315 chapter 14 */
1829 dhcp->RT = initial_rt(SOL_TIMEOUT);
1831 DBG("solicit initial RT timeout %d msec", dhcp->RT);
1833 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);
1835 dhcpv6_solicitation(dhcp);
1840 int __connman_dhcpv6_start(struct connman_network *network,
1841 GSList *prefixes, dhcpv6_cb callback)
1843 struct connman_service *service;
1844 struct connman_dhcpv6 *dhcp;
1850 if (network_table) {
1851 dhcp = g_hash_table_lookup(network_table, network);
1852 if (dhcp && dhcp->started)
1856 service = connman_service_lookup_from_network(network);
1860 dhcp = g_try_new0(struct connman_dhcpv6, 1);
1864 dhcp->network = network;
1865 dhcp->callback = callback;
1866 dhcp->prefixes = prefixes;
1867 dhcp->started = true;
1869 connman_network_ref(network);
1871 DBG("replace network %p dhcp %p", network, dhcp);
1873 g_hash_table_replace(network_table, network, dhcp);
1875 /* Initial timeout, RFC 3315, 17.1.2 */
1876 __connman_util_get_random(&rand);
1877 delay = rand % 1000;
1880 * Start from scratch.
1881 * RFC 3315, chapter 17.1.2 Solicitation message
1883 * Note that we do not send CONFIRM message here as it does
1884 * not make much sense because we do not save expiration time
1885 * so we cannot really know how long the saved address is valid
1886 * anyway. The reply to CONFIRM message does not send
1887 * expiration times back to us. Because of this we need to
1888 * start using SOLICITATION anyway.
1890 dhcp->timeout = g_timeout_add(delay, start_solicitation, dhcp);
1895 void __connman_dhcpv6_stop(struct connman_network *network)
1902 if (g_hash_table_remove(network_table, network))
1903 connman_network_unref(network);
1906 static int save_prefixes(struct connman_ipconfig *ipconfig,
1910 int i = 0, count = g_slist_length(prefixes);
1916 array = g_try_new0(char *, count + 1);
1920 for (list = prefixes; list; list = list->next) {
1921 char *elem, addr_str[INET6_ADDRSTRLEN];
1922 GDHCPIAPrefix *prefix = list->data;
1924 elem = g_strdup_printf("%s/%d", inet_ntop(AF_INET6,
1925 &prefix->prefix, addr_str, INET6_ADDRSTRLEN),
1935 __connman_ipconfig_set_dhcpv6_prefixes(ipconfig, array);
1939 static GSList *load_prefixes(struct connman_ipconfig *ipconfig)
1942 GSList *list = NULL;
1943 char **array = __connman_ipconfig_get_dhcpv6_prefixes(ipconfig);
1948 for (i = 0; array[i]; i++) {
1949 GDHCPIAPrefix *prefix;
1951 char *ptr, **elems = g_strsplit(array[i], "/", 0);
1956 value = strtol(elems[1], &ptr, 10);
1957 if (ptr != elems[1] && *ptr == '\0' && value <= 128) {
1958 struct in6_addr addr;
1960 if (inet_pton(AF_INET6, elems[0], &addr) == 1) {
1961 prefix = g_try_new0(GDHCPIAPrefix, 1);
1966 memcpy(&prefix->prefix, &addr,
1967 sizeof(struct in6_addr));
1968 prefix->prefixlen = value;
1970 list = g_slist_prepend(list, prefix);
1980 static GDHCPIAPrefix *copy_prefix(gpointer data)
1982 GDHCPIAPrefix *copy, *prefix = data;
1984 copy = g_try_new(GDHCPIAPrefix, 1);
1988 memcpy(copy, prefix, sizeof(GDHCPIAPrefix));
1993 static GSList *copy_and_convert_prefixes(GList *prefixes)
1995 GSList *copy = NULL;
1998 for (list = prefixes; list; list = list->next)
1999 copy = g_slist_prepend(copy, copy_prefix(list->data));
2004 static int set_prefixes(GDHCPClient *dhcp_client, struct connman_dhcpv6 *dhcp)
2007 g_slist_free_full(dhcp->prefixes, free_prefix);
2010 copy_and_convert_prefixes(g_dhcp_client_get_option(dhcp_client,
2013 DBG("Got %d prefix", g_slist_length(dhcp->prefixes));
2015 if (dhcp->callback) {
2016 uint16_t status = g_dhcpv6_client_get_status(dhcp_client);
2017 if (status == G_DHCPV6_ERROR_NO_PREFIX)
2018 dhcp->callback(dhcp->network,
2019 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
2021 struct connman_service *service;
2022 struct connman_ipconfig *ipconfig;
2023 int ifindex = connman_network_get_index(dhcp->network);
2025 service = __connman_service_lookup_from_index(ifindex);
2027 ipconfig = __connman_service_get_ip6config(
2029 save_prefixes(ipconfig, dhcp->prefixes);
2030 __connman_service_save(service);
2033 dhcp->callback(dhcp->network,
2034 CONNMAN_DHCPV6_STATUS_SUCCEED, dhcp->prefixes);
2037 g_slist_free_full(dhcp->prefixes, free_prefix);
2038 dhcp->prefixes = NULL;
2044 static void re_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2046 struct connman_dhcpv6 *dhcp = user_data;
2050 status = g_dhcpv6_client_get_status(dhcp_client);
2052 DBG("dhcpv6 cb msg %p status %d", dhcp, status);
2054 if (status == G_DHCPV6_ERROR_BINDING) {
2055 /* RFC 3315, 18.1.8 */
2056 dhcpv6_pd_request(dhcp);
2058 ret = set_prefixes(dhcp_client, dhcp);
2061 dhcp->callback(dhcp->network,
2062 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
2068 static void rebind_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2072 g_dhcpv6_client_clear_retransmit(dhcp_client);
2074 re_pd_cb(dhcp_client, user_data);
2077 static GDHCPClient *create_pd_client(struct connman_dhcpv6 *dhcp, int *err)
2079 GDHCPClient *dhcp_client;
2080 GDHCPClientError error;
2081 struct connman_service *service;
2085 index = connman_network_get_index(dhcp->network);
2087 dhcp_client = g_dhcp_client_new(G_DHCP_IPV6, index, &error);
2088 if (error != G_DHCP_CLIENT_ERROR_NONE) {
2093 #if !defined TIZEN_EXT
2094 if (getenv("CONNMAN_DHCPV6_DEBUG"))
2096 g_dhcp_client_set_debug(dhcp_client, dhcpv6_debug, "DHCPv6:PD");
2098 service = connman_service_lookup_from_network(dhcp->network);
2100 g_dhcp_client_unref(dhcp_client);
2105 ret = set_duid(service, dhcp->network, dhcp_client, index);
2107 g_dhcp_client_unref(dhcp_client);
2112 g_dhcpv6_client_create_iaid(dhcp_client, index, (unsigned char *)&iaid);
2113 g_dhcpv6_client_set_iaid(dhcp_client, iaid);
2118 static int dhcpv6_pd_rebind(struct connman_dhcpv6 *dhcp)
2120 GDHCPClient *dhcp_client;
2123 DBG("dhcp %p", dhcp);
2125 if (!dhcp->dhcp_client) {
2127 * We skipped the solicitation phase
2131 dhcp->dhcp_client = create_pd_client(dhcp, &err);
2132 if (!dhcp->dhcp_client) {
2138 dhcp_client = dhcp->dhcp_client;
2140 g_dhcp_client_clear_requests(dhcp_client);
2142 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
2143 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
2144 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
2146 g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
2147 g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
2149 clear_callbacks(dhcp_client);
2151 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REBIND,
2152 rebind_pd_cb, dhcp);
2154 return g_dhcp_client_start(dhcp_client, NULL);
2157 static void renew_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2161 g_dhcpv6_client_clear_retransmit(dhcp_client);
2163 re_pd_cb(dhcp_client, user_data);
2166 static int dhcpv6_pd_renew(struct connman_dhcpv6 *dhcp)
2168 GDHCPClient *dhcp_client;
2171 DBG("dhcp %p", dhcp);
2173 dhcp_client = dhcp->dhcp_client;
2175 g_dhcp_client_clear_requests(dhcp_client);
2177 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
2178 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
2179 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
2180 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
2182 g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
2183 g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
2185 clear_callbacks(dhcp_client);
2187 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RENEW,
2190 return g_dhcp_client_start(dhcp_client, NULL);
2194 * Check if we need to restart the solicitation procedure. This
2195 * is done if all the prefixes have expired.
2197 static int check_pd_restart(struct connman_dhcpv6 *dhcp)
2199 time_t current, expired;
2201 g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, NULL, NULL,
2203 current = time(NULL);
2205 if (current > expired) {
2206 DBG("expired by %d secs", (int)(current - expired));
2208 g_timeout_add(0, dhcpv6_restart, dhcp);
2216 static gboolean timeout_pd_rebind(gpointer user_data)
2218 struct connman_dhcpv6 *dhcp = user_data;
2220 if (check_pd_restart(dhcp) < 0)
2223 dhcp->RT = calc_delay(dhcp->RT, REB_MAX_RT);
2225 DBG("rebind RT timeout %d msec", dhcp->RT);
2227 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_rebind, dhcp);
2229 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
2231 g_dhcp_client_start(dhcp->dhcp_client, NULL);
2236 static gboolean start_pd_rebind(gpointer user_data)
2238 struct connman_dhcpv6 *dhcp = user_data;
2240 if (check_pd_restart(dhcp) < 0)
2243 dhcp->RT = initial_rt(REB_TIMEOUT);
2245 DBG("rebind initial RT timeout %d msec", dhcp->RT);
2247 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_rebind, dhcp);
2249 dhcpv6_pd_rebind(dhcp);
2254 static gboolean timeout_pd_rebind_confirm(gpointer user_data)
2256 struct connman_dhcpv6 *dhcp = user_data;
2258 dhcp->RT = calc_delay(dhcp->RT, CNF_MAX_RT);
2260 DBG("rebind with confirm RT timeout %d msec", dhcp->RT);
2262 dhcp->timeout = g_timeout_add(dhcp->RT,
2263 timeout_pd_rebind_confirm, dhcp);
2265 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
2267 g_dhcp_client_start(dhcp->dhcp_client, NULL);
2272 static gboolean timeout_pd_max_confirm(gpointer user_data)
2274 struct connman_dhcpv6 *dhcp = user_data;
2280 DBG("rebind with confirm max retransmit duration timeout");
2282 g_dhcpv6_client_clear_retransmit(dhcp->dhcp_client);
2285 dhcp->callback(dhcp->network,
2286 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
2291 static gboolean start_pd_rebind_with_confirm(gpointer user_data)
2293 struct connman_dhcpv6 *dhcp = user_data;
2295 dhcp->RT = initial_rt(CNF_TIMEOUT);
2297 DBG("rebind with confirm initial RT timeout %d msec", dhcp->RT);
2299 dhcp->timeout = g_timeout_add(dhcp->RT,
2300 timeout_pd_rebind_confirm, dhcp);
2301 dhcp->MRD = g_timeout_add(CNF_MAX_RD, timeout_pd_max_confirm, dhcp);
2303 dhcpv6_pd_rebind(dhcp);
2308 static gboolean timeout_pd_renew(gpointer user_data)
2310 struct connman_dhcpv6 *dhcp = user_data;
2312 if (check_pd_restart(dhcp) < 0)
2315 dhcp->RT = calc_delay(dhcp->RT, REN_MAX_RT);
2317 DBG("renew RT timeout %d msec", dhcp->RT);
2319 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_renew, dhcp);
2321 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
2323 g_dhcp_client_start(dhcp->dhcp_client, NULL);
2328 static gboolean start_pd_renew(gpointer user_data)
2330 struct connman_dhcpv6 *dhcp = user_data;
2332 dhcp->RT = initial_rt(REN_TIMEOUT);
2334 DBG("renew initial RT timeout %d msec", dhcp->RT);
2336 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_renew, dhcp);
2338 dhcpv6_pd_renew(dhcp);
2343 int __connman_dhcpv6_start_pd_renew(struct connman_network *network,
2346 struct connman_dhcpv6 *dhcp;
2348 time_t started, current, expired;
2350 dhcp = g_hash_table_lookup(network_pd_table, network);
2354 DBG("network %p dhcp %p", network, dhcp);
2358 g_dhcpv6_client_get_timeouts(dhcp->dhcp_client, &T1, &T2,
2359 &started, &expired);
2361 current = time(NULL);
2363 DBG("T1 %u T2 %u expires %lu current %lu started %lu", T1, T2,
2364 expired, current, started);
2366 if (T1 == 0xffffffff)
2367 /* RFC 3633, ch 9 */
2372 * Client can choose the timeout.
2376 dhcp->callback = callback;
2378 /* RFC 3315, 18.1.4, start solicit if expired */
2379 if (check_pd_restart(dhcp) < 0)
2382 if (T2 != 0xffffffff && T2 > 0) {
2383 if ((unsigned)current >= (unsigned)started + T2) {
2384 /* RFC 3315, chapter 18.1.3, start rebind */
2385 DBG("rebind after %d secs", T2);
2387 dhcp->timeout = g_timeout_add_seconds(T2,
2391 } else if ((unsigned)current < (unsigned)started + T1) {
2392 DBG("renew after %d secs", T1);
2394 dhcp->timeout = g_timeout_add_seconds(T1,
2398 DBG("rebind after %d secs", T2 - T1);
2400 dhcp->timeout = g_timeout_add_seconds(T2 - T1,
2409 static void release_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2414 int __connman_dhcpv6_start_pd_release(struct connman_network *network,
2417 struct connman_dhcpv6 *dhcp;
2418 GDHCPClient *dhcp_client;
2422 return 0; /* we are already released */
2424 dhcp = g_hash_table_lookup(network_pd_table, network);
2428 DBG("network %p dhcp %p client %p", network, dhcp, dhcp->dhcp_client);
2432 dhcp_client = dhcp->dhcp_client;
2434 DBG("DHCPv6 PD was not started");
2438 g_dhcp_client_clear_requests(dhcp_client);
2439 g_dhcp_client_clear_values(dhcp_client);
2441 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
2442 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
2444 g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
2445 g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
2447 clear_callbacks(dhcp_client);
2449 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_RELEASE,
2450 release_pd_cb, dhcp);
2452 dhcp->dhcp_client = dhcp_client;
2454 return g_dhcp_client_start(dhcp_client, NULL);
2457 static gboolean timeout_pd_request(gpointer user_data)
2459 struct connman_dhcpv6 *dhcp = user_data;
2461 if (dhcp->request_count >= REQ_MAX_RC) {
2462 DBG("max request retry attempts %d", dhcp->request_count);
2463 dhcp->request_count = 0;
2465 dhcp->callback(dhcp->network,
2466 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
2470 dhcp->request_count++;
2472 dhcp->RT = calc_delay(dhcp->RT, REQ_MAX_RT);
2473 DBG("request RT timeout %d msec", dhcp->RT);
2474 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_request, dhcp);
2476 g_dhcpv6_client_set_retransmit(dhcp->dhcp_client);
2478 g_dhcp_client_start(dhcp->dhcp_client, NULL);
2483 static void request_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2485 struct connman_dhcpv6 *dhcp = user_data;
2490 g_dhcpv6_client_clear_retransmit(dhcp_client);
2492 status = g_dhcpv6_client_get_status(dhcp_client);
2494 DBG("dhcpv6 pd cb msg %p status %d", dhcp, status);
2496 if (status == G_DHCPV6_ERROR_BINDING) {
2497 /* RFC 3315, 18.1.8 */
2498 dhcpv6_pd_request(dhcp);
2500 set_prefixes(dhcp_client, dhcp);
2504 static int dhcpv6_pd_request(struct connman_dhcpv6 *dhcp)
2506 GDHCPClient *dhcp_client;
2507 uint32_t T1 = 0, T2 = 0;
2509 DBG("dhcp %p", dhcp);
2511 dhcp_client = dhcp->dhcp_client;
2513 g_dhcp_client_clear_requests(dhcp_client);
2515 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
2516 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SERVERID);
2517 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_DNS_SERVERS);
2518 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_SNTP_SERVERS);
2520 g_dhcpv6_client_get_timeouts(dhcp_client, &T1, &T2, NULL, NULL);
2521 g_dhcpv6_client_set_pd(dhcp_client, &T1, &T2, dhcp->prefixes);
2523 clear_callbacks(dhcp_client);
2525 g_dhcp_client_register_event(dhcp_client, G_DHCP_CLIENT_EVENT_REQUEST,
2526 request_pd_cb, dhcp);
2528 return g_dhcp_client_start(dhcp_client, NULL);
2531 static void advertise_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2533 struct connman_dhcpv6 *dhcp = user_data;
2535 DBG("dhcpv6 advertise pd msg %p", dhcp);
2539 g_dhcpv6_client_clear_retransmit(dhcp_client);
2541 if (g_dhcpv6_client_get_status(dhcp_client) != 0) {
2543 dhcp->callback(dhcp->network,
2544 CONNMAN_DHCPV6_STATUS_FAIL, NULL);
2548 dhcp->RT = initial_rt(REQ_TIMEOUT);
2549 DBG("request initial RT timeout %d msec", dhcp->RT);
2550 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_pd_request, dhcp);
2552 dhcp->request_count = 1;
2554 dhcpv6_pd_request(dhcp);
2557 static void solicitation_pd_cb(GDHCPClient *dhcp_client, gpointer user_data)
2560 * This callback is here so that g_dhcp_client_start()
2561 * will enter the proper L3 mode.
2563 DBG("DHCPv6 %p solicitation msg received, ignoring it", user_data);
2566 static int dhcpv6_pd_solicitation(struct connman_dhcpv6 *dhcp)
2568 GDHCPClient *dhcp_client;
2571 DBG("dhcp %p", dhcp);
2573 dhcp_client = create_pd_client(dhcp, &ret);
2579 g_dhcp_client_set_request(dhcp_client, G_DHCPV6_CLIENTID);
2581 g_dhcpv6_client_set_pd(dhcp_client, NULL, NULL, NULL);
2583 clear_callbacks(dhcp_client);
2585 g_dhcp_client_register_event(dhcp_client,
2586 G_DHCP_CLIENT_EVENT_ADVERTISE,
2587 advertise_pd_cb, dhcp);
2589 g_dhcp_client_register_event(dhcp_client,
2590 G_DHCP_CLIENT_EVENT_SOLICITATION,
2591 solicitation_pd_cb, dhcp);
2593 dhcp->dhcp_client = dhcp_client;
2595 return g_dhcp_client_start(dhcp_client, NULL);
2598 static gboolean start_pd_solicitation(gpointer user_data)
2600 struct connman_dhcpv6 *dhcp = user_data;
2602 /* Set the retransmission timeout, RFC 3315 chapter 14 */
2603 dhcp->RT = initial_rt(SOL_TIMEOUT);
2605 DBG("solicit initial RT timeout %d msec", dhcp->RT);
2607 dhcp->timeout = g_timeout_add(dhcp->RT, timeout_solicitation, dhcp);
2609 dhcpv6_pd_solicitation(dhcp);
2614 int __connman_dhcpv6_start_pd(int index, GSList *prefixes, dhcpv6_cb callback)
2616 struct connman_service *service;
2617 struct connman_network *network;
2618 struct connman_dhcpv6 *dhcp;
2623 DBG("index %d", index);
2625 service = __connman_service_lookup_from_index(index);
2629 network = __connman_service_get_network(service);
2633 if (network_pd_table) {
2634 dhcp = g_hash_table_lookup(network_pd_table, network);
2635 if (dhcp && dhcp->started)
2639 dhcp = g_try_new0(struct connman_dhcpv6, 1);
2643 dhcp->network = network;
2644 dhcp->callback = callback;
2645 dhcp->started = true;
2649 * Try to load the earlier prefixes if caller did not supply
2650 * any that we could use.
2652 struct connman_ipconfig *ipconfig;
2653 ipconfig = __connman_service_get_ip6config(service);
2655 dhcp->prefixes = load_prefixes(ipconfig);
2657 dhcp->prefixes = prefixes;
2659 connman_network_ref(network);
2661 DBG("replace network %p dhcp %p", network, dhcp);
2663 g_hash_table_replace(network_pd_table, network, dhcp);
2665 if (!dhcp->prefixes) {
2667 * Refresh start, try to get prefixes.
2669 start_pd_solicitation(dhcp);
2672 * We used to have prefixes, try to use them again.
2673 * We need to use timeouts from confirm msg, RFC 3633, ch 12.1
2675 start_pd_rebind_with_confirm(dhcp);
2681 void __connman_dhcpv6_stop_pd(int index)
2683 struct connman_service *service;
2684 struct connman_network *network;
2689 DBG("index %d", index);
2691 if (!network_pd_table)
2694 service = __connman_service_lookup_from_index(index);
2698 network = __connman_service_get_network(service);
2702 __connman_dhcpv6_start_pd_release(network, NULL);
2704 if (g_hash_table_remove(network_pd_table, network))
2705 connman_network_unref(network);
2708 int __connman_dhcpv6_init(void)
2712 network_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2713 NULL, remove_network);
2715 network_pd_table = g_hash_table_new_full(g_direct_hash, g_direct_equal,
2716 NULL, remove_network);
2721 void __connman_dhcpv6_cleanup(void)
2725 g_hash_table_destroy(network_table);
2726 network_table = NULL;
2728 g_hash_table_destroy(network_pd_table);
2729 network_pd_table = NULL;