5 * Copyright (C) 2007-2010 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
27 #include <net/if_arp.h>
28 #include <linux/if_link.h>
33 #define IFF_LOWER_UP 0x10000
40 struct connman_ipconfig {
43 enum connman_ipconfig_type type;
45 struct connman_ipconfig *origin;
47 const struct connman_ipconfig_ops *ops;
50 enum connman_ipconfig_method method;
51 struct connman_ipaddress *address;
52 struct connman_ipaddress *system;
54 struct connman_ipconfig *ipv6;
57 struct connman_ipdevice {
80 struct connman_ipconfig *config;
82 struct connman_ipconfig_driver *driver;
83 struct connman_ipconfig *driver_config;
86 static GHashTable *ipdevice_hash = NULL;
87 static GList *ipconfig_list = NULL;
89 struct connman_ipaddress *connman_ipaddress_alloc(int family)
91 struct connman_ipaddress *ipaddress;
93 ipaddress = g_try_new0(struct connman_ipaddress, 1);
94 if (ipaddress == NULL)
97 ipaddress->family = family;
98 ipaddress->prefixlen = 0;
99 ipaddress->local = NULL;
100 ipaddress->peer = NULL;
101 ipaddress->broadcast = NULL;
102 ipaddress->gateway = NULL;
107 void connman_ipaddress_free(struct connman_ipaddress *ipaddress)
109 if (ipaddress == NULL)
112 g_free(ipaddress->broadcast);
113 g_free(ipaddress->peer);
114 g_free(ipaddress->local);
115 g_free(ipaddress->gateway);
119 unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask)
121 unsigned char bits = 0;
122 in_addr_t mask = inet_network(netmask);
123 in_addr_t host = ~mask;
125 /* a valid netmask must be 2^n - 1 */
126 if ((host & (host + 1)) != 0)
129 for (; mask; mask <<= 1)
135 static gboolean check_ipv6_address(const char *address)
137 unsigned char buf[sizeof(struct in6_addr)];
140 err = inet_pton(AF_INET6, address, buf);
147 int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
148 const char *address, const char *gateway,
149 unsigned char prefix_length)
151 if (ipaddress == NULL)
154 if (check_ipv6_address(address) == FALSE)
157 if (check_ipv6_address(gateway) == FALSE)
160 DBG("prefix_len %d address %s gateway %s",
161 prefix_length, address, gateway);
163 ipaddress->prefixlen = prefix_length;
165 g_free(ipaddress->local);
166 ipaddress->local = g_strdup(address);
168 g_free(ipaddress->gateway);
169 ipaddress->gateway = g_strdup(gateway);
174 void connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress,
175 const char *address, const char *netmask, const char *gateway)
177 if (ipaddress == NULL)
181 ipaddress->prefixlen =
182 __connman_ipconfig_netmask_prefix_len(netmask);
184 ipaddress->prefixlen = 32;
186 g_free(ipaddress->local);
187 ipaddress->local = g_strdup(address);
189 g_free(ipaddress->gateway);
190 ipaddress->gateway = g_strdup(gateway);
193 void connman_ipaddress_clear(struct connman_ipaddress *ipaddress)
195 if (ipaddress == NULL)
198 ipaddress->prefixlen = 0;
200 g_free(ipaddress->local);
201 ipaddress->local = NULL;
203 g_free(ipaddress->peer);
204 ipaddress->peer = NULL;
206 g_free(ipaddress->broadcast);
207 ipaddress->broadcast = NULL;
209 g_free(ipaddress->gateway);
210 ipaddress->gateway = NULL;
213 void connman_ipaddress_copy(struct connman_ipaddress *ipaddress,
214 struct connman_ipaddress *source)
216 if (ipaddress == NULL || source == NULL)
219 ipaddress->family = source->family;
220 ipaddress->prefixlen = source->prefixlen;
222 g_free(ipaddress->local);
223 ipaddress->local = g_strdup(source->local);
225 g_free(ipaddress->peer);
226 ipaddress->peer = g_strdup(source->peer);
228 g_free(ipaddress->broadcast);
229 ipaddress->broadcast = g_strdup(source->broadcast);
231 g_free(ipaddress->gateway);
232 ipaddress->gateway = g_strdup(source->gateway);
235 static void free_address_list(struct connman_ipdevice *ipdevice)
239 for (list = ipdevice->address_list; list; list = list->next) {
240 struct connman_ipaddress *ipaddress = list->data;
242 connman_ipaddress_free(ipaddress);
246 g_slist_free(ipdevice->address_list);
247 ipdevice->address_list = NULL;
250 static struct connman_ipaddress *find_ipaddress(struct connman_ipdevice *ipdevice,
251 unsigned char prefixlen, const char *local)
255 for (list = ipdevice->address_list; list; list = list->next) {
256 struct connman_ipaddress *ipaddress = list->data;
258 if (g_strcmp0(ipaddress->local, local) == 0 &&
259 ipaddress->prefixlen == prefixlen)
266 static const char *type2str(unsigned short type)
271 case ARPHRD_LOOPBACK:
284 static const char *scope2str(unsigned char scope)
296 static void free_ipdevice(gpointer data)
298 struct connman_ipdevice *ipdevice = data;
300 connman_info("%s {remove} index %d", ipdevice->ifname,
303 if (ipdevice->config != NULL)
304 connman_ipconfig_unref(ipdevice->config);
306 free_address_list(ipdevice);
307 g_free(ipdevice->ipv4_gateway);
308 g_free(ipdevice->ipv6_gateway);
309 g_free(ipdevice->proxy);
310 g_free(ipdevice->pac);
312 g_free(ipdevice->address);
313 g_free(ipdevice->ifname);
317 static GSList *driver_list = NULL;
319 static gint compare_priority(gconstpointer a, gconstpointer b)
321 const struct connman_ipconfig_driver *driver1 = a;
322 const struct connman_ipconfig_driver *driver2 = b;
324 return driver2->priority - driver1->priority;
328 * connman_ipconfig_driver_register:
329 * @driver: IP configuration driver
331 * Register a new IP configuration driver
333 * Returns: %0 on success
335 int connman_ipconfig_driver_register(struct connman_ipconfig_driver *driver)
337 DBG("driver %p name %s", driver, driver->name);
339 driver_list = g_slist_insert_sorted(driver_list, driver,
346 * connman_ipconfig_driver_unregister:
347 * @driver: IP configuration driver
349 * Remove a previously registered IP configuration driver.
351 void connman_ipconfig_driver_unregister(struct connman_ipconfig_driver *driver)
353 DBG("driver %p name %s", driver, driver->name);
355 driver_list = g_slist_remove(driver_list, driver);
358 static void __connman_ipconfig_lower_up(struct connman_ipdevice *ipdevice)
362 DBG("ipconfig %p", ipdevice->config);
364 if (ipdevice->config == NULL)
367 switch (ipdevice->config->method) {
368 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
369 case CONNMAN_IPCONFIG_METHOD_OFF:
370 case CONNMAN_IPCONFIG_METHOD_FIXED:
371 case CONNMAN_IPCONFIG_METHOD_MANUAL:
373 case CONNMAN_IPCONFIG_METHOD_DHCP:
377 if (ipdevice->driver != NULL)
380 ipdevice->driver_config = connman_ipconfig_clone(ipdevice->config);
381 if (ipdevice->driver_config == NULL)
384 for (list = driver_list; list; list = list->next) {
385 struct connman_ipconfig_driver *driver = list->data;
387 if (driver->request(ipdevice->driver_config) == 0) {
388 ipdevice->driver = driver;
393 if (ipdevice->driver == NULL) {
394 connman_ipconfig_unref(ipdevice->driver_config);
395 ipdevice->driver_config = NULL;
399 static void __connman_ipconfig_lower_down(struct connman_ipdevice *ipdevice)
401 DBG("ipconfig %p", ipdevice->config);
403 if (ipdevice->config == NULL)
406 if (ipdevice->driver == NULL)
409 ipdevice->driver->release(ipdevice->driver_config);
411 ipdevice->driver = NULL;
413 connman_ipconfig_unref(ipdevice->driver_config);
414 ipdevice->driver_config = NULL;
416 connman_inet_clear_address(ipdevice->index, ipdevice->config->address);
417 connman_inet_clear_ipv6_address(ipdevice->index,
418 ipdevice->driver_config->address->local,
419 ipdevice->driver_config->address->prefixlen);
422 static void update_stats(struct connman_ipdevice *ipdevice,
423 struct rtnl_link_stats *stats)
425 if (stats->rx_packets == 0 && stats->tx_packets == 0)
428 connman_info("%s {RX} %u packets %u bytes", ipdevice->ifname,
429 stats->rx_packets, stats->rx_bytes);
430 connman_info("%s {TX} %u packets %u bytes", ipdevice->ifname,
431 stats->tx_packets, stats->tx_bytes);
433 if (ipdevice->config == NULL)
436 ipdevice->rx_packets = stats->rx_packets;
437 ipdevice->tx_packets = stats->tx_packets;
438 ipdevice->rx_bytes = stats->rx_bytes;
439 ipdevice->tx_bytes = stats->tx_bytes;
440 ipdevice->rx_errors = stats->rx_errors;
441 ipdevice->tx_errors = stats->tx_errors;
442 ipdevice->rx_dropped = stats->rx_dropped;
443 ipdevice->tx_dropped = stats->tx_dropped;
445 __connman_service_notify(ipdevice->config,
446 ipdevice->rx_packets, ipdevice->tx_packets,
447 ipdevice->rx_bytes, ipdevice->tx_bytes,
448 ipdevice->rx_errors, ipdevice->tx_errors,
449 ipdevice->rx_dropped, ipdevice->tx_dropped);
452 void __connman_ipconfig_newlink(int index, unsigned short type,
453 unsigned int flags, const char *address,
455 struct rtnl_link_stats *stats)
457 struct connman_ipdevice *ipdevice;
460 gboolean up = FALSE, down = FALSE;
461 gboolean lower_up = FALSE, lower_down = FALSE;
463 DBG("index %d", index);
465 if (type == ARPHRD_LOOPBACK)
468 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
469 if (ipdevice != NULL)
472 ipdevice = g_try_new0(struct connman_ipdevice, 1);
473 if (ipdevice == NULL)
476 ipdevice->index = index;
477 ipdevice->ifname = connman_inet_ifname(index);
478 ipdevice->type = type;
480 ipdevice->address = g_strdup(address);
482 g_hash_table_insert(ipdevice_hash, GINT_TO_POINTER(index), ipdevice);
484 connman_info("%s {create} index %d type %d <%s>", ipdevice->ifname,
485 index, type, type2str(type));
490 update_stats(ipdevice, stats);
492 if (flags == ipdevice->flags)
495 if ((ipdevice->flags & IFF_UP) != (flags & IFF_UP)) {
502 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) !=
503 (flags & (IFF_RUNNING | IFF_LOWER_UP))) {
504 if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
505 (IFF_RUNNING | IFF_LOWER_UP))
507 else if ((flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
511 ipdevice->flags = flags;
513 str = g_string_new(NULL);
518 g_string_append(str, "UP");
520 g_string_append(str, "DOWN");
522 if (flags & IFF_RUNNING)
523 g_string_append(str, ",RUNNING");
525 if (flags & IFF_LOWER_UP)
526 g_string_append(str, ",LOWER_UP");
528 connman_info("%s {update} flags %u <%s>", ipdevice->ifname,
531 g_string_free(str, TRUE);
533 for (list = g_list_first(ipconfig_list); list;
534 list = g_list_next(list)) {
535 struct connman_ipconfig *ipconfig = list->data;
537 if (index != ipconfig->index)
540 if (ipconfig->ops == NULL)
543 if (up == TRUE && ipconfig->ops->up)
544 ipconfig->ops->up(ipconfig);
545 if (lower_up == TRUE && ipconfig->ops->lower_up)
546 ipconfig->ops->lower_up(ipconfig);
548 if (lower_down == TRUE && ipconfig->ops->lower_down)
549 ipconfig->ops->lower_down(ipconfig);
550 if (down == TRUE && ipconfig->ops->down)
551 ipconfig->ops->down(ipconfig);
555 __connman_ipconfig_lower_up(ipdevice);
557 __connman_ipconfig_lower_down(ipdevice);
560 void __connman_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
562 struct connman_ipdevice *ipdevice;
565 DBG("index %d", index);
567 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
568 if (ipdevice == NULL)
571 update_stats(ipdevice, stats);
573 for (list = g_list_first(ipconfig_list); list;
574 list = g_list_next(list)) {
575 struct connman_ipconfig *ipconfig = list->data;
577 if (index != ipconfig->index)
580 ipconfig->index = -1;
582 if (ipconfig->ops == NULL)
585 if (ipconfig->ops->lower_down)
586 ipconfig->ops->lower_down(ipconfig);
587 if (ipconfig->ops->down)
588 ipconfig->ops->down(ipconfig);
591 __connman_ipconfig_lower_down(ipdevice);
593 g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
596 void __connman_ipconfig_newaddr(int index, int family, const char *label,
597 unsigned char prefixlen, const char *address)
599 struct connman_ipdevice *ipdevice;
600 struct connman_ipaddress *ipaddress;
603 DBG("index %d", index);
605 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
606 if (ipdevice == NULL)
609 ipaddress = connman_ipaddress_alloc(family);
610 if (ipaddress == NULL)
613 ipaddress->prefixlen = prefixlen;
614 ipaddress->local = g_strdup(address);
616 ipdevice->address_list = g_slist_append(ipdevice->address_list,
619 connman_info("%s {add} address %s/%u label %s", ipdevice->ifname,
620 address, prefixlen, label);
622 if (ipdevice->config != NULL) {
623 if (family == AF_INET6 && ipdevice->config->ipv6 != NULL)
624 connman_ipaddress_copy(ipdevice->config->ipv6->system,
627 connman_ipaddress_copy(ipdevice->config->system,
631 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
634 if (g_slist_length(ipdevice->address_list) > 1)
637 for (list = g_list_first(ipconfig_list); list;
638 list = g_list_next(list)) {
639 struct connman_ipconfig *ipconfig = list->data;
641 if (index != ipconfig->index)
644 if (ipconfig->ops == NULL)
647 if (ipconfig->ops->ip_bound)
648 ipconfig->ops->ip_bound(ipconfig);
652 void __connman_ipconfig_deladdr(int index, int family, const char *label,
653 unsigned char prefixlen, const char *address)
655 struct connman_ipdevice *ipdevice;
656 struct connman_ipaddress *ipaddress;
659 DBG("index %d", index);
661 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
662 if (ipdevice == NULL)
665 ipaddress = find_ipaddress(ipdevice, prefixlen, address);
666 if (ipaddress == NULL)
669 ipdevice->address_list = g_slist_remove(ipdevice->address_list,
672 connman_ipaddress_free(ipaddress);
674 connman_info("%s {del} address %s/%u label %s", ipdevice->ifname,
675 address, prefixlen, label);
677 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) != (IFF_RUNNING | IFF_LOWER_UP))
680 if (g_slist_length(ipdevice->address_list) > 0)
683 for (list = g_list_first(ipconfig_list); list;
684 list = g_list_next(list)) {
685 struct connman_ipconfig *ipconfig = list->data;
687 if (index != ipconfig->index)
690 if (ipconfig->ops == NULL)
693 if (ipconfig->ops->ip_release)
694 ipconfig->ops->ip_release(ipconfig);
698 void __connman_ipconfig_newroute(int index, int family, unsigned char scope,
699 const char *dst, const char *gateway)
701 struct connman_ipdevice *ipdevice;
703 DBG("index %d", index);
705 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
706 if (ipdevice == NULL)
709 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
713 if (family == AF_INET6) {
714 g_free(ipdevice->ipv6_gateway);
715 ipdevice->ipv6_gateway = g_strdup(gateway);
717 g_free(ipdevice->ipv4_gateway);
718 ipdevice->ipv4_gateway = g_strdup(gateway);
721 if (ipdevice->config != NULL &&
722 ipdevice->config->system != NULL) {
723 g_free(ipdevice->config->system->gateway);
724 ipdevice->config->system->gateway = g_strdup(gateway);
727 for (list = ipdevice->address_list; list; list = list->next) {
728 struct connman_ipaddress *ipaddress = list->data;
730 g_free(ipaddress->gateway);
731 ipaddress->gateway = g_strdup(gateway);
734 for (config_list = g_list_first(ipconfig_list); config_list;
735 config_list = g_list_next(config_list)) {
736 struct connman_ipconfig *ipconfig = config_list->data;
738 if (index != ipconfig->index)
741 if (ipconfig->ops == NULL)
744 if (ipconfig->ops->ip_bound)
745 ipconfig->ops->ip_bound(ipconfig);
749 connman_info("%s {add} route %s gw %s scope %u <%s>",
750 ipdevice->ifname, dst, gateway,
751 scope, scope2str(scope));
754 void __connman_ipconfig_delroute(int index, int family, unsigned char scope,
755 const char *dst, const char *gateway)
757 struct connman_ipdevice *ipdevice;
759 DBG("index %d", index);
761 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
762 if (ipdevice == NULL)
765 if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
769 if (family == AF_INET6) {
770 g_free(ipdevice->ipv6_gateway);
771 ipdevice->ipv6_gateway = NULL;
773 g_free(ipdevice->ipv4_gateway);
774 ipdevice->ipv4_gateway = NULL;
777 if (ipdevice->config != NULL &&
778 ipdevice->config->system != NULL) {
779 g_free(ipdevice->config->system->gateway);
780 ipdevice->config->system->gateway = NULL;
783 for (list = ipdevice->address_list; list; list = list->next) {
784 struct connman_ipaddress *ipaddress = list->data;
786 g_free(ipaddress->gateway);
787 ipaddress->gateway = NULL;
790 for (config_list = g_list_first(ipconfig_list); config_list;
791 config_list = g_list_next(config_list)) {
792 struct connman_ipconfig *ipconfig = config_list->data;
794 if (index != ipconfig->index)
797 if (ipconfig->ops == NULL)
800 if (ipconfig->ops->ip_release)
801 ipconfig->ops->ip_release(ipconfig);
805 connman_info("%s {del} route %s gw %s scope %u <%s>",
806 ipdevice->ifname, dst, gateway,
807 scope, scope2str(scope));
810 void __connman_ipconfig_foreach(void (*function) (int index, void *user_data),
815 keys = g_hash_table_get_keys(ipdevice_hash);
819 for (list = g_list_first(keys); list; list = g_list_next(list)) {
820 int index = GPOINTER_TO_INT(list->data);
822 function(index, user_data);
828 unsigned short __connman_ipconfig_get_type(int index)
830 struct connman_ipdevice *ipdevice;
832 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
833 if (ipdevice == NULL)
836 return ipdevice->type;
839 unsigned int __connman_ipconfig_get_flags(int index)
841 struct connman_ipdevice *ipdevice;
843 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
844 if (ipdevice == NULL)
847 return ipdevice->flags;
850 const char *__connman_ipconfig_get_gateway(int index)
852 struct connman_ipdevice *ipdevice;
854 ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
855 if (ipdevice == NULL)
858 if (ipdevice->ipv4_gateway != NULL)
859 return ipdevice->ipv4_gateway;
861 if (ipdevice->config != NULL &&
862 ipdevice->config->address != NULL)
863 return ipdevice->config->address->gateway;
868 void __connman_ipconfig_set_index(struct connman_ipconfig *ipconfig, int index)
870 ipconfig->index = index;
872 if (ipconfig->ipv6 != NULL)
873 ipconfig->ipv6->index = index;
876 static struct connman_ipconfig *create_ipv6config(int index)
878 struct connman_ipconfig *ipv6config;
880 DBG("index %d", index);
882 ipv6config = g_try_new0(struct connman_ipconfig, 1);
883 if (ipv6config == NULL)
886 ipv6config->index = index;
887 ipv6config->type = CONNMAN_IPCONFIG_TYPE_IPV6;
888 ipv6config->method = CONNMAN_IPCONFIG_METHOD_OFF;
890 ipv6config->address = connman_ipaddress_alloc(AF_INET6);
891 if (ipv6config->address == NULL) {
896 ipv6config->system = connman_ipaddress_alloc(AF_INET6);
898 ipv6config->ipv6 = NULL;
900 DBG("ipconfig %p", ipv6config);
906 * connman_ipconfig_create:
908 * Allocate a new ipconfig structure.
910 * Returns: a newly-allocated #connman_ipconfig structure
912 struct connman_ipconfig *connman_ipconfig_create(int index)
914 struct connman_ipconfig *ipconfig;
916 DBG("index %d", index);
918 ipconfig = g_try_new0(struct connman_ipconfig, 1);
919 if (ipconfig == NULL)
922 ipconfig->refcount = 1;
924 ipconfig->index = index;
925 ipconfig->type = CONNMAN_IPCONFIG_TYPE_IPV4;
927 ipconfig->address = connman_ipaddress_alloc(AF_INET);
928 if (ipconfig->address == NULL) {
933 ipconfig->system = connman_ipaddress_alloc(AF_INET);
935 ipconfig->ipv6 = create_ipv6config(index);
937 DBG("ipconfig %p", ipconfig);
943 * connman_ipconfig_clone:
945 * Clone an ipconfig structure and create new reference.
947 * Returns: a newly-allocated #connman_ipconfig structure
949 struct connman_ipconfig *connman_ipconfig_clone(struct connman_ipconfig *ipconfig)
951 struct connman_ipconfig *ipconfig_clone;
953 DBG("ipconfig %p", ipconfig);
955 ipconfig_clone = g_try_new0(struct connman_ipconfig, 1);
956 if (ipconfig_clone == NULL)
959 ipconfig_clone->refcount = 1;
961 ipconfig_clone->origin = connman_ipconfig_ref(ipconfig);
963 ipconfig_clone->index = -1;
965 return ipconfig_clone;
969 * connman_ipconfig_ref:
970 * @ipconfig: ipconfig structure
972 * Increase reference counter of ipconfig
974 struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig)
976 g_atomic_int_inc(&ipconfig->refcount);
981 static void free_ipv6config(struct connman_ipconfig *ipconfig)
983 if (ipconfig == NULL)
986 connman_ipconfig_set_ops(ipconfig, NULL);
987 connman_ipaddress_free(ipconfig->system);
988 connman_ipaddress_free(ipconfig->address);
989 g_free(ipconfig->ipv6);
993 * connman_ipconfig_unref:
994 * @ipconfig: ipconfig structure
996 * Decrease reference counter of ipconfig
998 void connman_ipconfig_unref(struct connman_ipconfig *ipconfig)
1000 if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) {
1001 __connman_ipconfig_disable(ipconfig);
1003 connman_ipconfig_set_ops(ipconfig, NULL);
1005 if (ipconfig->origin != NULL) {
1006 connman_ipconfig_unref(ipconfig->origin);
1007 ipconfig->origin = NULL;
1010 connman_ipaddress_free(ipconfig->system);
1011 connman_ipaddress_free(ipconfig->address);
1012 free_ipv6config(ipconfig->ipv6);
1018 * connman_ipconfig_get_data:
1019 * @ipconfig: ipconfig structure
1021 * Get private data pointer
1023 void *connman_ipconfig_get_data(struct connman_ipconfig *ipconfig)
1025 return ipconfig->ops_data;
1029 * connman_ipconfig_set_data:
1030 * @ipconfig: ipconfig structure
1031 * @data: data pointer
1033 * Set private data pointer
1035 void connman_ipconfig_set_data(struct connman_ipconfig *ipconfig, void *data)
1037 ipconfig->ops_data = data;
1041 * connman_ipconfig_get_index:
1042 * @ipconfig: ipconfig structure
1044 * Get interface index
1046 int connman_ipconfig_get_index(struct connman_ipconfig *ipconfig)
1048 if (ipconfig == NULL)
1051 if (ipconfig->origin != NULL)
1052 return ipconfig->origin->index;
1054 return ipconfig->index;
1058 * connman_ipconfig_get_ifname:
1059 * @ipconfig: ipconfig structure
1061 * Get interface name
1063 const char *connman_ipconfig_get_ifname(struct connman_ipconfig *ipconfig)
1065 struct connman_ipdevice *ipdevice;
1067 if (ipconfig == NULL)
1070 if (ipconfig->index < 0)
1073 ipdevice = g_hash_table_lookup(ipdevice_hash,
1074 GINT_TO_POINTER(ipconfig->index));
1075 if (ipdevice == NULL)
1078 return ipdevice->ifname;
1082 * connman_ipconfig_set_ops:
1083 * @ipconfig: ipconfig structure
1084 * @ops: operation callbacks
1086 * Set the operation callbacks
1088 void connman_ipconfig_set_ops(struct connman_ipconfig *ipconfig,
1089 const struct connman_ipconfig_ops *ops)
1091 ipconfig->ops = ops;
1094 struct connman_ipconfig *connman_ipconfig_get_ipv6config(
1095 struct connman_ipconfig *ipconfig)
1097 if (ipconfig == NULL)
1100 return ipconfig->ipv6;
1104 * connman_ipconfig_set_method:
1105 * @ipconfig: ipconfig structure
1106 * @method: configuration method
1108 * Set the configuration method
1110 int connman_ipconfig_set_method(struct connman_ipconfig *ipconfig,
1111 enum connman_ipconfig_method method)
1113 ipconfig->method = method;
1118 enum connman_ipconfig_method __connman_ipconfig_get_method(struct connman_ipconfig *ipconfig)
1120 if (ipconfig == NULL)
1121 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1123 return ipconfig->method;
1127 * connman_ipconfig_bind:
1128 * @ipconfig: ipconfig structure
1129 * @ipaddress: ipaddress structure
1131 * Bind IP address details to configuration
1133 void connman_ipconfig_bind(struct connman_ipconfig *ipconfig,
1134 struct connman_ipaddress *ipaddress)
1136 struct connman_ipconfig *origin;
1138 origin = ipconfig->origin ? ipconfig->origin : ipconfig;
1140 connman_ipaddress_copy(origin->address, ipaddress);
1142 connman_inet_set_address(origin->index, origin->address);
1145 void __connman_ipconfig_set_element_ipv6_gateway(
1146 struct connman_ipconfig *ipconfig,
1147 struct connman_element *element)
1149 element->ipv6.gateway = ipconfig->ipv6->address->gateway;
1153 * FIXME: The element soulution should be removed in the future
1154 * Set IPv4 and IPv6 gateway
1156 int __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig,
1157 struct connman_element *parent)
1159 struct connman_element *connection;
1161 connection = connman_element_create(NULL);
1163 DBG("ipconfig %p", ipconfig);
1165 connection->type = CONNMAN_ELEMENT_TYPE_CONNECTION;
1166 connection->index = ipconfig->index;
1167 connection->ipv4.gateway = ipconfig->address->gateway;
1168 connection->ipv6.gateway = ipconfig->ipv6->address->gateway;
1170 if (connman_element_register(connection, parent) < 0)
1171 connman_element_unref(connection);
1176 int __connman_ipconfig_set_address(struct connman_ipconfig *ipconfig)
1180 switch (ipconfig->method) {
1181 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1182 case CONNMAN_IPCONFIG_METHOD_OFF:
1183 case CONNMAN_IPCONFIG_METHOD_FIXED:
1184 case CONNMAN_IPCONFIG_METHOD_DHCP:
1186 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1187 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1188 return connman_inet_set_address(ipconfig->index,
1190 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1191 return connman_inet_set_ipv6_address(
1192 ipconfig->index, ipconfig->address);
1198 int __connman_ipconfig_clear_address(struct connman_ipconfig *ipconfig)
1202 if (ipconfig == NULL)
1205 DBG("method %d", ipconfig->method);
1207 switch (ipconfig->method) {
1208 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1209 case CONNMAN_IPCONFIG_METHOD_OFF:
1210 case CONNMAN_IPCONFIG_METHOD_FIXED:
1211 case CONNMAN_IPCONFIG_METHOD_DHCP:
1213 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1214 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1215 return connman_inet_clear_address(ipconfig->index,
1217 else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
1218 return connman_inet_clear_ipv6_address(
1220 ipconfig->address->local,
1221 ipconfig->address->prefixlen);
1227 int __connman_ipconfig_set_proxy_autoconfig(struct connman_ipconfig *ipconfig,
1230 struct connman_ipdevice *ipdevice;
1232 DBG("ipconfig %p", ipconfig);
1234 if (ipconfig == NULL || ipconfig->index < 0)
1237 ipdevice = g_hash_table_lookup(ipdevice_hash,
1238 GINT_TO_POINTER(ipconfig->index));
1239 if (ipdevice == NULL)
1242 g_free(ipdevice->pac);
1243 ipdevice->pac = g_strdup(url);
1248 const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipconfig)
1250 struct connman_ipdevice *ipdevice;
1252 DBG("ipconfig %p", ipconfig);
1254 if (ipconfig == NULL || ipconfig->index < 0)
1257 ipdevice = g_hash_table_lookup(ipdevice_hash,
1258 GINT_TO_POINTER(ipconfig->index));
1259 if (ipdevice == NULL)
1262 return ipdevice->pac;
1265 int __connman_ipconfig_enable(struct connman_ipconfig *ipconfig)
1267 struct connman_ipdevice *ipdevice;
1268 gboolean up = FALSE, down = FALSE;
1269 gboolean lower_up = FALSE, lower_down = FALSE;
1271 DBG("ipconfig %p", ipconfig);
1273 if (ipconfig == NULL || ipconfig->index < 0)
1276 ipdevice = g_hash_table_lookup(ipdevice_hash,
1277 GINT_TO_POINTER(ipconfig->index));
1278 if (ipdevice == NULL)
1281 if (ipdevice->config == ipconfig)
1284 if (ipdevice->config != NULL) {
1285 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1287 connman_ipaddress_clear(ipdevice->config->system);
1289 connman_ipconfig_unref(ipdevice->config);
1292 ipdevice->config = connman_ipconfig_ref(ipconfig);
1294 ipconfig_list = g_list_append(ipconfig_list, ipconfig);
1296 if (ipdevice->flags & IFF_UP)
1301 if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) ==
1302 (IFF_RUNNING | IFF_LOWER_UP))
1304 else if ((ipdevice->flags & (IFF_RUNNING | IFF_LOWER_UP)) == 0)
1307 if (up == TRUE && ipconfig->ops->up)
1308 ipconfig->ops->up(ipconfig);
1309 if (lower_up == TRUE && ipconfig->ops->lower_up)
1310 ipconfig->ops->lower_up(ipconfig);
1312 if (lower_down == TRUE && ipconfig->ops->lower_down)
1313 ipconfig->ops->lower_down(ipconfig);
1314 if (down == TRUE && ipconfig->ops->down)
1315 ipconfig->ops->down(ipconfig);
1320 int __connman_ipconfig_disable(struct connman_ipconfig *ipconfig)
1322 struct connman_ipdevice *ipdevice;
1324 DBG("ipconfig %p", ipconfig);
1326 if (ipconfig == NULL || ipconfig->index < 0)
1329 ipdevice = g_hash_table_lookup(ipdevice_hash,
1330 GINT_TO_POINTER(ipconfig->index));
1331 if (ipdevice == NULL)
1334 if (ipdevice->config == NULL || ipdevice->config != ipconfig)
1337 ipconfig_list = g_list_remove(ipconfig_list, ipconfig);
1339 connman_ipaddress_clear(ipdevice->config->system);
1340 connman_ipaddress_clear(ipdevice->config->ipv6->system);
1342 connman_ipconfig_unref(ipdevice->config);
1343 ipdevice->config = NULL;
1348 const char *__connman_ipconfig_method2string(enum connman_ipconfig_method method)
1351 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1353 case CONNMAN_IPCONFIG_METHOD_OFF:
1355 case CONNMAN_IPCONFIG_METHOD_FIXED:
1357 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1359 case CONNMAN_IPCONFIG_METHOD_DHCP:
1366 enum connman_ipconfig_method __connman_ipconfig_string2method(const char *method)
1368 if (g_strcmp0(method, "off") == 0)
1369 return CONNMAN_IPCONFIG_METHOD_OFF;
1370 else if (g_strcmp0(method, "fixed") == 0)
1371 return CONNMAN_IPCONFIG_METHOD_FIXED;
1372 else if (g_strcmp0(method, "manual") == 0)
1373 return CONNMAN_IPCONFIG_METHOD_MANUAL;
1374 else if (g_strcmp0(method, "dhcp") == 0)
1375 return CONNMAN_IPCONFIG_METHOD_DHCP;
1377 return CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1380 void __connman_ipconfig_append_ipv4(struct connman_ipconfig *ipconfig,
1381 DBusMessageIter *iter)
1387 str = __connman_ipconfig_method2string(ipconfig->method);
1391 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1393 if (ipconfig->system == NULL)
1396 if (ipconfig->system->local != NULL) {
1398 struct in_addr netmask;
1401 connman_dbus_dict_append_basic(iter, "Address",
1402 DBUS_TYPE_STRING, &ipconfig->system->local);
1404 addr = 0xffffffff << (32 - ipconfig->system->prefixlen);
1405 netmask.s_addr = htonl(addr);
1406 mask = inet_ntoa(netmask);
1407 connman_dbus_dict_append_basic(iter, "Netmask",
1408 DBUS_TYPE_STRING, &mask);
1411 if (ipconfig->system->gateway != NULL)
1412 connman_dbus_dict_append_basic(iter, "Gateway",
1413 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1416 void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
1417 DBusMessageIter *iter)
1423 str = __connman_ipconfig_method2string(ipconfig->method);
1427 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1429 if (ipconfig->system == NULL)
1432 if (ipconfig->system->local != NULL) {
1433 connman_dbus_dict_append_basic(iter, "Address",
1434 DBUS_TYPE_STRING, &ipconfig->system->local);
1435 connman_dbus_dict_append_basic(iter, "PrefixLength",
1437 &ipconfig->system->prefixlen);
1440 if (ipconfig->system->gateway != NULL)
1441 connman_dbus_dict_append_basic(iter, "Gateway",
1442 DBUS_TYPE_STRING, &ipconfig->system->gateway);
1445 void __connman_ipconfig_append_ipv6config(struct connman_ipconfig *ipconfig,
1446 DBusMessageIter *iter)
1452 str = __connman_ipconfig_method2string(ipconfig->method);
1456 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1458 switch (ipconfig->method) {
1459 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1460 case CONNMAN_IPCONFIG_METHOD_OFF:
1461 case CONNMAN_IPCONFIG_METHOD_DHCP:
1463 case CONNMAN_IPCONFIG_METHOD_FIXED:
1464 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1468 if (ipconfig->address == NULL)
1471 if (ipconfig->address->local != NULL) {
1472 connman_dbus_dict_append_basic(iter, "Address",
1473 DBUS_TYPE_STRING, &ipconfig->address->local);
1474 connman_dbus_dict_append_basic(iter, "PrefixLength",
1476 &ipconfig->address->prefixlen);
1479 if (ipconfig->address->gateway != NULL)
1480 connman_dbus_dict_append_basic(iter, "Gateway",
1481 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1484 void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
1485 DBusMessageIter *iter)
1491 str = __connman_ipconfig_method2string(ipconfig->method);
1495 connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
1497 switch (ipconfig->method) {
1498 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1499 case CONNMAN_IPCONFIG_METHOD_OFF:
1500 case CONNMAN_IPCONFIG_METHOD_FIXED:
1501 case CONNMAN_IPCONFIG_METHOD_DHCP:
1503 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1507 if (ipconfig->address == NULL)
1510 if (ipconfig->address->local != NULL) {
1512 struct in_addr netmask;
1515 connman_dbus_dict_append_basic(iter, "Address",
1516 DBUS_TYPE_STRING, &ipconfig->address->local);
1518 addr = 0xffffffff << (32 - ipconfig->address->prefixlen);
1519 netmask.s_addr = htonl(addr);
1520 mask = inet_ntoa(netmask);
1521 connman_dbus_dict_append_basic(iter, "Netmask",
1522 DBUS_TYPE_STRING, &mask);
1525 if (ipconfig->address->gateway != NULL)
1526 connman_dbus_dict_append_basic(iter, "Gateway",
1527 DBUS_TYPE_STRING, &ipconfig->address->gateway);
1530 int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
1531 enum connman_ipconfig_type type, DBusMessageIter *array)
1533 enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
1534 const char *address = NULL, *netmask = NULL, *gateway = NULL,
1535 *prefix_length_string = NULL;
1536 int prefix_length = 0;
1537 DBusMessageIter dict;
1539 DBG("ipconfig %p type %d", ipconfig, type);
1541 if (type != CONNMAN_IPCONFIG_TYPE_IPV4 &&
1542 type != CONNMAN_IPCONFIG_TYPE_IPV6)
1545 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
1548 dbus_message_iter_recurse(array, &dict);
1550 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1551 DBusMessageIter entry;
1555 dbus_message_iter_recurse(&dict, &entry);
1557 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1560 dbus_message_iter_get_basic(&entry, &key);
1561 dbus_message_iter_next(&entry);
1563 type = dbus_message_iter_get_arg_type(&entry);
1565 if (g_str_equal(key, "Method") == TRUE) {
1568 if (type != DBUS_TYPE_STRING)
1571 dbus_message_iter_get_basic(&entry, &str);
1572 method = __connman_ipconfig_string2method(str);
1573 } else if (g_str_equal(key, "Address") == TRUE) {
1574 if (type != DBUS_TYPE_STRING)
1577 dbus_message_iter_get_basic(&entry, &address);
1578 } else if (g_str_equal(key, "PrefixLength") == TRUE) {
1579 if (type != DBUS_TYPE_STRING)
1582 dbus_message_iter_get_basic(&entry,
1583 &prefix_length_string);
1585 prefix_length = atoi(prefix_length_string);
1586 if (prefix_length < 0 || prefix_length > 128)
1589 } else if (g_str_equal(key, "Netmask") == TRUE) {
1590 if (type != DBUS_TYPE_STRING)
1593 dbus_message_iter_get_basic(&entry, &netmask);
1594 } else if (g_str_equal(key, "Gateway") == TRUE) {
1595 if (type != DBUS_TYPE_STRING)
1598 dbus_message_iter_get_basic(&entry, &gateway);
1600 dbus_message_iter_next(&dict);
1603 DBG("method %d address %s netmask %s gateway %s prefix_length %d",
1604 method, address, netmask, gateway, prefix_length);
1607 case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
1608 case CONNMAN_IPCONFIG_METHOD_OFF:
1609 case CONNMAN_IPCONFIG_METHOD_FIXED:
1612 case CONNMAN_IPCONFIG_METHOD_MANUAL:
1613 if (address == NULL)
1616 ipconfig->method = method;
1618 if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
1619 connman_ipaddress_set_ipv4(ipconfig->address,
1620 address, netmask, gateway);
1622 return connman_ipaddress_set_ipv6(
1623 ipconfig->address, address,
1624 gateway, prefix_length);
1627 case CONNMAN_IPCONFIG_METHOD_DHCP:
1628 if (ipconfig->method == method)
1631 ipconfig->method = method;
1638 void __connman_ipconfig_append_proxy(struct connman_ipconfig *ipconfig,
1639 DBusMessageIter *iter)
1641 struct connman_ipdevice *ipdevice;
1642 const char *method = "direct";
1644 ipdevice = g_hash_table_lookup(ipdevice_hash,
1645 GINT_TO_POINTER(ipconfig->index));
1646 if (ipdevice == NULL)
1649 if (ipdevice->pac == NULL)
1652 method = "auto-config";
1654 connman_dbus_dict_append_basic(iter, "URL",
1655 DBUS_TYPE_STRING, &ipdevice->pac);
1658 connman_dbus_dict_append_basic(iter, "Method",
1659 DBUS_TYPE_STRING, &method);
1662 void __connman_ipconfig_append_proxyconfig(struct connman_ipconfig *ipconfig,
1663 DBusMessageIter *iter)
1665 struct connman_ipdevice *ipdevice;
1666 const char *method = "auto";
1668 ipdevice = g_hash_table_lookup(ipdevice_hash,
1669 GINT_TO_POINTER(ipconfig->index));
1670 if (ipdevice == NULL)
1673 if (ipdevice->proxy == NULL)
1676 method = ipdevice->proxy;
1679 connman_dbus_dict_append_basic(iter, "Method",
1680 DBUS_TYPE_STRING, &method);
1683 int __connman_ipconfig_set_proxyconfig(struct connman_ipconfig *ipconfig,
1684 DBusMessageIter *array)
1686 struct connman_ipdevice *ipdevice;
1687 DBusMessageIter dict;
1690 DBG("ipconfig %p", ipconfig);
1692 ipdevice = g_hash_table_lookup(ipdevice_hash,
1693 GINT_TO_POINTER(ipconfig->index));
1694 if (ipdevice == NULL)
1697 if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
1700 dbus_message_iter_recurse(array, &dict);
1702 while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
1703 DBusMessageIter entry;
1707 dbus_message_iter_recurse(&dict, &entry);
1709 if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
1712 dbus_message_iter_get_basic(&entry, &key);
1713 dbus_message_iter_next(&entry);
1715 type = dbus_message_iter_get_arg_type(&entry);
1717 if (g_str_equal(key, "Method") == TRUE) {
1718 if (type != DBUS_TYPE_STRING)
1721 dbus_message_iter_get_basic(&entry, &method);
1722 if (strlen(method) == 0)
1726 dbus_message_iter_next(&dict);
1729 DBG("method %s", method);
1734 if (g_str_equal(method, "auto") == FALSE &&
1735 g_str_equal(method, "direct") == FALSE)
1738 g_free(ipdevice->proxy);
1739 ipdevice->proxy = g_strdup(method);
1744 void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
1745 DBusMessageIter *iter)
1747 struct connman_ipdevice *ipdevice;
1748 const char *method = "auto";
1750 connman_dbus_dict_append_basic(iter, "Method",
1751 DBUS_TYPE_STRING, &method);
1753 ipdevice = g_hash_table_lookup(ipdevice_hash,
1754 GINT_TO_POINTER(ipconfig->index));
1755 if (ipdevice == NULL)
1758 if (ipdevice->ifname != NULL)
1759 connman_dbus_dict_append_basic(iter, "Interface",
1760 DBUS_TYPE_STRING, &ipdevice->ifname);
1762 if (ipdevice->address != NULL)
1763 connman_dbus_dict_append_basic(iter, "Address",
1764 DBUS_TYPE_STRING, &ipdevice->address);
1766 if (ipdevice->mtu > 0)
1767 connman_dbus_dict_append_basic(iter, "MTU",
1768 DBUS_TYPE_UINT16, &ipdevice->mtu);
1771 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
1772 GKeyFile *keyfile, const char *identifier, const char *prefix)
1777 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1779 key = g_strdup_printf("%smethod", prefix);
1780 method = g_key_file_get_string(keyfile, identifier, key, NULL);
1781 if (method == NULL) {
1782 if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
1783 ipconfig->method = CONNMAN_IPCONFIG_METHOD_DHCP;
1785 ipconfig->method = CONNMAN_IPCONFIG_METHOD_OFF;
1787 ipconfig->method = __connman_ipconfig_string2method(method);
1790 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1791 ipconfig->address->prefixlen = g_key_file_get_integer(
1792 keyfile, identifier, key, NULL);
1795 key = g_strdup_printf("%slocal_address", prefix);
1796 ipconfig->address->local = g_key_file_get_string(
1797 keyfile, identifier, key, NULL);
1800 key = g_strdup_printf("%speer_address", prefix);
1801 ipconfig->address->peer = g_key_file_get_string(
1802 keyfile, identifier, key, NULL);
1805 key = g_strdup_printf("%sbroadcast_address", prefix);
1806 ipconfig->address->broadcast = g_key_file_get_string(
1807 keyfile, identifier, key, NULL);
1810 key = g_strdup_printf("%sgateway", prefix);
1811 ipconfig->address->gateway = g_key_file_get_string(
1812 keyfile, identifier, key, NULL);
1818 int __connman_ipconfig_save(struct connman_ipconfig *ipconfig,
1819 GKeyFile *keyfile, const char *identifier, const char *prefix)
1824 DBG("ipconfig %p identifier %s", ipconfig, identifier);
1826 method = __connman_ipconfig_method2string(ipconfig->method);
1828 key = g_strdup_printf("%smethod", prefix);
1829 g_key_file_set_string(keyfile, identifier, key, method);
1832 key = g_strdup_printf("%snetmask_prefixlen", prefix);
1833 g_key_file_set_integer(keyfile, identifier,
1834 key, ipconfig->address->prefixlen);
1837 key = g_strdup_printf("%slocal_address", prefix);
1838 if (ipconfig->address->local != NULL)
1839 g_key_file_set_string(keyfile, identifier,
1840 key, ipconfig->address->local);
1843 key = g_strdup_printf("%speer_address", prefix);
1844 if (ipconfig->address->peer != NULL)
1845 g_key_file_set_string(keyfile, identifier,
1846 key, ipconfig->address->peer);
1849 key = g_strdup_printf("%sbroadcast_address", prefix);
1850 if (ipconfig->address->broadcast != NULL)
1851 g_key_file_set_string(keyfile, identifier,
1852 key, ipconfig->address->broadcast);
1855 key = g_strdup_printf("%sgateway", prefix);
1856 if (ipconfig->address->gateway != NULL)
1857 g_key_file_set_string(keyfile, identifier,
1858 key, ipconfig->address->gateway);
1864 int __connman_ipconfig_init(void)
1868 ipdevice_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1869 NULL, free_ipdevice);
1874 void __connman_ipconfig_cleanup(void)
1878 g_hash_table_destroy(ipdevice_hash);
1879 ipdevice_hash = NULL;