5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
6 * Copyright (C) 2011 BMW Car IT GmbH. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 struct gateway_config {
48 struct connman_service *service;
50 struct gateway_config *ipv4_gateway;
51 struct gateway_config *ipv6_gateway;
54 static GHashTable *gateway_hash = NULL;
56 static struct gateway_config *find_gateway(int index, const char *gateway)
64 g_hash_table_iter_init(&iter, gateway_hash);
66 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
67 struct gateway_data *data = value;
69 if (data->ipv4_gateway != NULL && data->index == index &&
70 g_str_equal(data->ipv4_gateway->gateway,
72 return data->ipv4_gateway;
74 if (data->ipv6_gateway != NULL && data->index == index &&
75 g_str_equal(data->ipv6_gateway->gateway,
77 return data->ipv6_gateway;
83 static int del_routes(struct gateway_data *data,
84 enum connman_ipconfig_type type)
86 int status4 = 0, status6 = 0;
87 int do_ipv4 = FALSE, do_ipv6 = FALSE;
89 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
91 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
94 do_ipv4 = do_ipv6 = TRUE;
96 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL) {
97 if (data->ipv4_gateway->vpn == TRUE) {
98 if (data->ipv4_gateway->vpn_phy_index >= 0)
99 connman_inet_del_host_route(
100 data->ipv4_gateway->vpn_phy_index,
101 data->ipv4_gateway->gateway);
103 status4 = connman_inet_clear_gateway_address(
105 data->ipv4_gateway->vpn_ip);
107 } else if (g_strcmp0(data->ipv4_gateway->gateway,
109 status4 = connman_inet_clear_gateway_interface(
112 connman_inet_del_host_route(data->index,
113 data->ipv4_gateway->gateway);
114 status4 = connman_inet_clear_gateway_address(
116 data->ipv4_gateway->gateway);
120 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL) {
121 if (data->ipv6_gateway->vpn == TRUE) {
122 if (data->ipv6_gateway->vpn_phy_index >= 0)
123 connman_inet_del_host_route(
124 data->ipv6_gateway->vpn_phy_index,
125 data->ipv6_gateway->gateway);
127 status6 = connman_inet_clear_ipv6_gateway_address(
129 data->ipv6_gateway->vpn_ip);
131 } else if (g_strcmp0(data->ipv6_gateway->gateway, "::") == 0) {
132 status6 = connman_inet_clear_ipv6_gateway_interface(
135 connman_inet_del_ipv6_host_route(data->index,
136 data->ipv6_gateway->gateway);
137 status6 = connman_inet_clear_ipv6_gateway_address(
139 data->ipv6_gateway->gateway);
143 return (status4 < 0 ? status4 : status6);
146 static int disable_gateway(struct gateway_data *data,
147 enum connman_ipconfig_type type)
149 gboolean active = FALSE;
151 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
152 if (data->ipv4_gateway != NULL)
153 active = data->ipv4_gateway->active;
154 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
155 if (data->ipv6_gateway != NULL)
156 active = data->ipv6_gateway->active;
160 DBG("type %d active %d", type, active);
163 return del_routes(data, type);
168 static struct gateway_data *add_gateway(struct connman_service *service,
169 int index, const char *gateway,
170 enum connman_ipconfig_type type)
172 struct gateway_data *data, *old;
173 struct gateway_config *config;
175 if (gateway == NULL || strlen(gateway) == 0)
178 data = g_try_new0(struct gateway_data, 1);
184 config = g_try_new0(struct gateway_config, 1);
185 if (config == NULL) {
190 config->gateway = g_strdup(gateway);
191 config->vpn_ip = NULL;
192 config->vpn_phy_ip = NULL;
194 config->vpn_phy_index = -1;
195 config->active = FALSE;
197 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
198 data->ipv4_gateway = config;
199 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
200 data->ipv6_gateway = config;
202 g_free(config->gateway);
208 data->service = service;
210 data->order = __connman_service_get_order(service);
213 * If the service is already in the hash, then we
214 * must not replace it blindly but disable the gateway
215 * of the type we are replacing and take the other type
216 * from old gateway settings.
218 old = g_hash_table_lookup(gateway_hash, service);
220 DBG("Replacing gw %p ipv4 %p ipv6 %p", old,
221 old->ipv4_gateway, old->ipv6_gateway);
222 disable_gateway(old, type);
223 if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
224 data->ipv6_gateway = old->ipv6_gateway;
225 old->ipv6_gateway = NULL;
226 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) {
227 data->ipv4_gateway = old->ipv4_gateway;
228 old->ipv4_gateway = NULL;
232 * Only take a ref if we are adding new stuff to hash.
234 connman_service_ref(service);
237 g_hash_table_replace(gateway_hash, service, data);
242 static void connection_newgateway(int index, const char *gateway)
244 struct gateway_config *config;
246 DBG("index %d gateway %s", index, gateway);
248 config = find_gateway(index, gateway);
252 config->active = TRUE;
255 static void set_default_gateway(struct gateway_data *data,
256 enum connman_ipconfig_type type)
259 int status4 = 0, status6 = 0;
260 int do_ipv4 = FALSE, do_ipv6 = FALSE;
262 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
264 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
267 do_ipv4 = do_ipv6 = TRUE;
269 DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway,
272 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL &&
273 data->ipv4_gateway->vpn == TRUE) {
274 connman_inet_set_gateway_address(data->index,
275 data->ipv4_gateway->vpn_ip);
276 connman_inet_add_host_route(data->ipv4_gateway->vpn_phy_index,
277 data->ipv4_gateway->vpn_ip,
278 data->ipv4_gateway->vpn_phy_ip);
279 data->ipv4_gateway->active = TRUE;
281 DBG("set %p index %d vpn %s index %d phy %s",
282 data, data->index, data->ipv4_gateway->vpn_ip,
283 data->ipv4_gateway->vpn_phy_index,
284 data->ipv4_gateway->vpn_phy_ip);
286 __connman_service_indicate_default(data->service);
291 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL &&
292 data->ipv6_gateway->vpn == TRUE) {
293 connman_inet_set_ipv6_gateway_address(data->index,
294 data->ipv6_gateway->vpn_ip);
295 connman_inet_add_ipv6_host_route(
296 data->ipv6_gateway->vpn_phy_index,
297 data->ipv6_gateway->vpn_ip,
298 data->ipv6_gateway->vpn_phy_ip);
299 data->ipv6_gateway->active = TRUE;
301 DBG("set %p index %d vpn %s index %d phy %s",
302 data, data->index, data->ipv6_gateway->vpn_ip,
303 data->ipv6_gateway->vpn_phy_index,
304 data->ipv6_gateway->vpn_phy_ip);
306 __connman_service_indicate_default(data->service);
311 index = __connman_service_get_index(data->service);
313 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL &&
314 g_strcmp0(data->ipv4_gateway->gateway,
316 if (connman_inet_set_gateway_interface(index) < 0)
321 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL &&
322 g_strcmp0(data->ipv6_gateway->gateway,
324 if (connman_inet_set_ipv6_gateway_interface(index) < 0)
329 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL)
330 status6 = connman_inet_set_ipv6_gateway_address(index,
331 data->ipv6_gateway->gateway);
333 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL)
334 status4 = connman_inet_set_gateway_address(index,
335 data->ipv4_gateway->gateway);
337 if (status4 < 0 || status6 < 0)
341 __connman_service_indicate_default(data->service);
344 static void unset_default_gateway(struct gateway_data *data,
345 enum connman_ipconfig_type type)
348 int do_ipv4 = FALSE, do_ipv6 = FALSE;
350 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
352 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
355 do_ipv4 = do_ipv6 = TRUE;
357 DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway,
360 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL &&
361 data->ipv4_gateway->vpn == TRUE) {
362 connman_inet_del_host_route(data->index,
363 data->ipv4_gateway->vpn_ip);
364 connman_inet_clear_gateway_address(data->index,
365 data->ipv4_gateway->vpn_ip);
366 data->ipv4_gateway->active = FALSE;
368 DBG("unset %p index %d vpn %s index %d phy %s",
369 data, data->index, data->ipv4_gateway->vpn_ip,
370 data->ipv4_gateway->vpn_phy_index,
371 data->ipv4_gateway->vpn_phy_ip);
376 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL &&
377 data->ipv6_gateway->vpn == TRUE) {
378 connman_inet_del_ipv6_host_route(data->index,
379 data->ipv6_gateway->vpn_ip);
380 connman_inet_clear_ipv6_gateway_address(data->index,
381 data->ipv6_gateway->vpn_ip);
382 data->ipv6_gateway->active = FALSE;
384 DBG("unset %p index %d vpn %s index %d phy %s",
385 data, data->index, data->ipv6_gateway->vpn_ip,
386 data->ipv6_gateway->vpn_phy_index,
387 data->ipv6_gateway->vpn_phy_ip);
392 index = __connman_service_get_index(data->service);
394 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL &&
395 g_strcmp0(data->ipv4_gateway->gateway,
397 connman_inet_clear_gateway_interface(index);
401 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL &&
402 g_strcmp0(data->ipv6_gateway->gateway,
404 connman_inet_clear_ipv6_gateway_interface(index);
408 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL)
409 connman_inet_clear_ipv6_gateway_address(index,
410 data->ipv6_gateway->gateway);
412 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL)
413 connman_inet_clear_gateway_address(index,
414 data->ipv4_gateway->gateway);
417 static struct gateway_data *find_default_gateway(void)
419 struct gateway_data *found = NULL;
420 unsigned int order = 0;
424 g_hash_table_iter_init(&iter, gateway_hash);
426 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
427 struct gateway_data *data = value;
429 if (found == NULL || data->order > order) {
433 DBG("default %p order %d", found, order);
440 static void remove_gateway(gpointer user_data)
442 struct gateway_data *data = user_data;
444 DBG("gateway ipv4 %p ipv6 %p", data->ipv4_gateway, data->ipv6_gateway);
446 if (data->ipv4_gateway != NULL) {
447 g_free(data->ipv4_gateway->gateway);
448 g_free(data->ipv4_gateway->vpn_ip);
449 g_free(data->ipv4_gateway->vpn_phy_ip);
450 g_free(data->ipv4_gateway);
453 if (data->ipv6_gateway != NULL) {
454 g_free(data->ipv6_gateway->gateway);
455 g_free(data->ipv6_gateway->vpn_ip);
456 g_free(data->ipv6_gateway->vpn_phy_ip);
457 g_free(data->ipv6_gateway);
463 static void connection_delgateway(int index, const char *gateway)
465 struct gateway_config *config;
466 struct gateway_data *data;
468 DBG("index %d gateway %s", index, gateway);
470 config = find_gateway(index, gateway);
472 config->active = FALSE;
474 data = find_default_gateway();
476 set_default_gateway(data, CONNMAN_IPCONFIG_TYPE_ALL);
479 static struct connman_rtnl connection_rtnl = {
480 .name = "connection",
481 .newgateway = connection_newgateway,
482 .delgateway = connection_delgateway,
485 static struct gateway_data *find_active_gateway(void)
492 g_hash_table_iter_init(&iter, gateway_hash);
494 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
495 struct gateway_data *data = value;
497 if (data->ipv4_gateway != NULL &&
498 data->ipv4_gateway->active == TRUE)
501 if (data->ipv6_gateway != NULL &&
502 data->ipv6_gateway->active == TRUE)
509 static void update_order(void)
516 g_hash_table_iter_init(&iter, gateway_hash);
518 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
519 struct gateway_data *data = value;
521 data->order = __connman_service_get_order(data->service);
525 void __connman_connection_gateway_activate(struct connman_service *service,
526 enum connman_ipconfig_type type)
528 struct gateway_data *data = NULL;
530 data = g_hash_table_lookup(gateway_hash, service);
534 DBG("gateway %p/%p type %d", data->ipv4_gateway,
535 data->ipv6_gateway, type);
537 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
538 data->ipv4_gateway->active = TRUE;
539 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
540 data->ipv6_gateway->active = TRUE;
543 int __connman_connection_gateway_add(struct connman_service *service,
545 enum connman_ipconfig_type type,
548 struct gateway_data *active_gateway = NULL;
549 struct gateway_data *new_gateway = NULL;
550 enum connman_ipconfig_type type4 = CONNMAN_IPCONFIG_TYPE_UNKNOWN,
551 type6 = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
554 index = __connman_service_get_index(service);
557 * If gateway is NULL, it's a point to point link and the default
558 * gateway for ipv4 is 0.0.0.0 and for ipv6 is ::, meaning the
561 if (gateway == NULL && type == CONNMAN_IPCONFIG_TYPE_IPV4)
564 if (gateway == NULL && type == CONNMAN_IPCONFIG_TYPE_IPV6)
567 DBG("service %p index %d gateway %s vpn ip %s type %d",
568 service, index, gateway, peer, type);
570 active_gateway = find_active_gateway();
571 new_gateway = add_gateway(service, index, gateway, type);
572 if (new_gateway == NULL)
575 DBG("active %p index %d new %p", active_gateway,
576 active_gateway ? active_gateway->index : -1, new_gateway);
578 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
579 new_gateway->ipv6_gateway != NULL &&
580 g_strcmp0(new_gateway->ipv6_gateway->gateway,
582 connman_inet_add_ipv6_host_route(index,
583 new_gateway->ipv6_gateway->gateway,
586 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
587 new_gateway->ipv4_gateway != NULL &&
588 g_strcmp0(new_gateway->ipv4_gateway->gateway,
590 connman_inet_add_host_route(index,
591 new_gateway->ipv4_gateway->gateway,
594 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
595 new_gateway->ipv4_gateway != NULL) {
596 __connman_service_nameserver_add_routes(service,
597 new_gateway->ipv4_gateway->gateway);
598 type4 = CONNMAN_IPCONFIG_TYPE_IPV4;
601 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
602 new_gateway->ipv6_gateway != NULL) {
603 __connman_service_nameserver_add_routes(service,
604 new_gateway->ipv6_gateway->gateway);
605 type6 = CONNMAN_IPCONFIG_TYPE_IPV6;
608 if (connman_service_get_type(service) == CONNMAN_SERVICE_TYPE_VPN) {
609 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
610 new_gateway->ipv4_gateway != NULL) {
611 new_gateway->ipv4_gateway->vpn = TRUE;
613 new_gateway->ipv4_gateway->vpn_ip =
615 else if (gateway != NULL)
616 new_gateway->ipv4_gateway->vpn_ip =
618 if (active_gateway) {
619 const char *new_ipv4_gateway;
622 active_gateway->ipv4_gateway->gateway;
623 if (new_ipv4_gateway != NULL &&
624 g_strcmp0(new_ipv4_gateway,
626 new_gateway->ipv4_gateway->vpn_phy_ip =
627 g_strdup(new_ipv4_gateway);
629 new_gateway->ipv4_gateway->vpn_phy_index =
630 active_gateway->index;
633 DBG("vpn %s phy %s index %d",
634 new_gateway->ipv4_gateway->vpn_ip,
635 new_gateway->ipv4_gateway->vpn_phy_ip,
636 new_gateway->ipv4_gateway->vpn_phy_index);
638 } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
639 new_gateway->ipv6_gateway != NULL) {
640 new_gateway->ipv6_gateway->vpn = TRUE;
642 new_gateway->ipv6_gateway->vpn_ip =
644 else if (gateway != NULL)
645 new_gateway->ipv6_gateway->vpn_ip =
647 if (active_gateway) {
648 const char *new_ipv6_gateway;
651 active_gateway->ipv6_gateway->gateway;
652 if (new_ipv6_gateway != NULL &&
653 g_strcmp0(new_ipv6_gateway, "::") != 0)
654 new_gateway->ipv6_gateway->vpn_phy_ip =
655 g_strdup(new_ipv6_gateway);
657 new_gateway->ipv6_gateway->vpn_phy_index =
658 active_gateway->index;
661 DBG("vpn %s phy %s index %d",
662 new_gateway->ipv6_gateway->vpn_ip,
663 new_gateway->ipv6_gateway->vpn_phy_ip,
664 new_gateway->ipv6_gateway->vpn_phy_index);
667 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
668 new_gateway->ipv4_gateway != NULL)
669 new_gateway->ipv4_gateway->vpn = FALSE;
671 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
672 new_gateway->ipv6_gateway != NULL)
673 new_gateway->ipv6_gateway->vpn = FALSE;
676 if (active_gateway == NULL) {
677 set_default_gateway(new_gateway, type);
681 if (type == CONNMAN_IPCONFIG_TYPE_IPV4 &&
682 new_gateway->ipv4_gateway != NULL &&
683 new_gateway->ipv4_gateway->vpn == TRUE) {
684 connman_inet_add_host_route(active_gateway->index,
685 new_gateway->ipv4_gateway->gateway,
686 active_gateway->ipv4_gateway->gateway);
687 connman_inet_clear_gateway_address(active_gateway->index,
688 active_gateway->ipv4_gateway->gateway);
691 if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
692 new_gateway->ipv6_gateway != NULL &&
693 new_gateway->ipv6_gateway->vpn == TRUE) {
694 connman_inet_add_ipv6_host_route(active_gateway->index,
695 new_gateway->ipv6_gateway->gateway,
696 active_gateway->ipv6_gateway->gateway);
697 connman_inet_clear_ipv6_gateway_address(active_gateway->index,
698 active_gateway->ipv6_gateway->gateway);
702 if (type4 == CONNMAN_IPCONFIG_TYPE_IPV4)
703 __connman_service_ipconfig_indicate_state(service,
704 CONNMAN_SERVICE_STATE_READY,
705 CONNMAN_IPCONFIG_TYPE_IPV4);
707 if (type6 == CONNMAN_IPCONFIG_TYPE_IPV6)
708 __connman_service_ipconfig_indicate_state(service,
709 CONNMAN_SERVICE_STATE_READY,
710 CONNMAN_IPCONFIG_TYPE_IPV6);
714 void __connman_connection_gateway_remove(struct connman_service *service,
715 enum connman_ipconfig_type type)
717 struct gateway_data *data = NULL;
718 gboolean set_default4 = FALSE, set_default6 = FALSE;
719 int do_ipv4 = FALSE, do_ipv6 = FALSE;
722 DBG("service %p type %d", service, type);
724 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
726 else if (type == CONNMAN_IPCONFIG_TYPE_IPV6)
729 do_ipv4 = do_ipv6 = TRUE;
731 __connman_service_nameserver_del_routes(service);
733 data = g_hash_table_lookup(gateway_hash, service);
737 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL)
738 set_default4 = data->ipv4_gateway->vpn;
740 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL)
741 set_default6 = data->ipv6_gateway->vpn;
743 DBG("ipv4 gateway %s ipv6 gateway %s vpn %d/%d",
744 data->ipv4_gateway ? data->ipv4_gateway->gateway : "<null>",
745 data->ipv6_gateway ? data->ipv6_gateway->gateway : "<null>",
746 set_default4, set_default6);
748 if (do_ipv4 == TRUE && data->ipv4_gateway != NULL &&
749 data->ipv4_gateway->vpn == TRUE && data->index >= 0)
750 connman_inet_del_host_route(data->index,
751 data->ipv4_gateway->gateway);
753 if (do_ipv6 == TRUE && data->ipv6_gateway != NULL &&
754 data->ipv6_gateway->vpn == TRUE && data->index >= 0)
755 connman_inet_del_ipv6_host_route(data->index,
756 data->ipv6_gateway->gateway);
758 __connman_service_nameserver_del_routes(service);
760 err = disable_gateway(data, type);
763 * We remove the service from the hash only if all the gateway
764 * settings are to be removed.
766 if (do_ipv4 == do_ipv6 ||
767 (data->ipv4_gateway != NULL && data->ipv6_gateway == NULL
768 && do_ipv4 == TRUE) ||
769 (data->ipv6_gateway != NULL && data->ipv4_gateway == NULL
772 connman_service_unref(service);
773 g_hash_table_remove(gateway_hash, service);
775 DBG("Not yet removing gw ipv4 %p/%d ipv6 %p/%d",
776 data->ipv4_gateway, do_ipv4,
777 data->ipv6_gateway, do_ipv6);
779 /* with vpn this will be called after the network was deleted,
780 * we need to call set_default here because we will not recieve any
781 * gateway delete notification.
782 * We hit the same issue if remove_gateway() fails.
784 if (set_default4 || set_default6 || err < 0) {
785 data = find_default_gateway();
787 set_default_gateway(data, type);
791 gboolean __connman_connection_update_gateway(void)
793 struct gateway_data *active_gateway, *default_gateway;
794 gboolean updated = FALSE;
796 if (gateway_hash == NULL)
799 active_gateway = find_active_gateway();
803 default_gateway = find_default_gateway();
805 DBG("active %p default %p", active_gateway, default_gateway);
807 if (active_gateway && active_gateway != default_gateway) {
810 if (active_gateway->ipv4_gateway)
811 unset_default_gateway(active_gateway,
812 CONNMAN_IPCONFIG_TYPE_IPV4);
814 if (active_gateway->ipv6_gateway)
815 unset_default_gateway(active_gateway,
816 CONNMAN_IPCONFIG_TYPE_IPV6);
818 if (default_gateway) {
819 if (default_gateway->ipv4_gateway)
820 set_default_gateway(default_gateway,
821 CONNMAN_IPCONFIG_TYPE_IPV4);
823 if (default_gateway->ipv6_gateway)
824 set_default_gateway(default_gateway,
825 CONNMAN_IPCONFIG_TYPE_IPV6);
832 int __connman_connection_init(void)
838 gateway_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
839 NULL, remove_gateway);
841 err = connman_rtnl_register(&connection_rtnl);
843 connman_error("Failed to setup RTNL gateway driver");
848 void __connman_connection_cleanup(void)
855 connman_rtnl_unregister(&connection_rtnl);
857 g_hash_table_iter_init(&iter, gateway_hash);
859 while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
860 struct gateway_data *data = value;
862 disable_gateway(data, CONNMAN_IPCONFIG_TYPE_ALL);
865 g_hash_table_destroy(gateway_hash);