X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=vpn%2Fvpn-ipconfig.c;h=c4fa54823e11acaff7ba29d3a2374d531581fe03;hb=5a253ba10bddf14fdc5e598aa8e6621ab21a40f8;hp=cb5167f0676d6e92e75b9e222ccbe4df60995510;hpb=4ba04eb6172f898402e0aa66f0dc8f564a12279f;p=platform%2Fupstream%2Fconnman.git diff --git a/vpn/vpn-ipconfig.c b/vpn/vpn-ipconfig.c old mode 100644 new mode 100755 index cb5167f..c4fa548 --- a/vpn/vpn-ipconfig.c +++ b/vpn/vpn-ipconfig.c @@ -47,7 +47,7 @@ struct vpn_ipconfig { int refcount; int index; int family; - connman_bool_t enabled; + bool enabled; struct connman_ipaddress *address; struct connman_ipaddress *system; }; @@ -69,32 +69,18 @@ struct vpn_ipdevice { static GHashTable *ipdevice_hash = NULL; -unsigned char __vpn_ipconfig_netmask_prefix_len(const char *netmask) +struct connman_ipaddress * +__vpn_ipconfig_get_address(struct vpn_ipconfig *ipconfig) { - unsigned char bits; - in_addr_t mask; - in_addr_t host; - - if (netmask == NULL) - return 32; - - mask = inet_network(netmask); - host = ~mask; - - /* a valid netmask must be 2^n - 1 */ - if ((host & (host + 1)) != 0) - return -1; - - bits = 0; - for (; mask; mask <<= 1) - ++bits; + if (!ipconfig) + return NULL; - return bits; + return ipconfig->address; } const char *__vpn_ipconfig_get_peer(struct vpn_ipconfig *ipconfig) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return NULL; return ipconfig->address->peer; @@ -105,7 +91,7 @@ unsigned short __vpn_ipconfig_get_type_from_index(int index) struct vpn_ipdevice *ipdevice; ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index)); - if (ipdevice == NULL) + if (!ipdevice) return ARPHRD_VOID; return ipdevice->type; @@ -116,19 +102,19 @@ unsigned int __vpn_ipconfig_get_flags_from_index(int index) struct vpn_ipdevice *ipdevice; ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index)); - if (ipdevice == NULL) + if (!ipdevice) return 0; return ipdevice->flags; } -void __vpn_ipconfig_foreach(void (*function) (int index, +void vpn_ipconfig_foreach(void (*function) (int index, void *user_data), void *user_data) { GList *list, *keys; keys = g_hash_table_get_keys(ipdevice_hash); - if (keys == NULL) + if (!keys) return; for (list = g_list_first(keys); list; list = g_list_next(list)) { @@ -143,7 +129,7 @@ void __vpn_ipconfig_foreach(void (*function) (int index, void __vpn_ipconfig_set_local(struct vpn_ipconfig *ipconfig, const char *address) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return; g_free(ipconfig->address->local); @@ -152,7 +138,7 @@ void __vpn_ipconfig_set_local(struct vpn_ipconfig *ipconfig, const char *__vpn_ipconfig_get_local(struct vpn_ipconfig *ipconfig) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return NULL; return ipconfig->address->local; @@ -161,7 +147,7 @@ const char *__vpn_ipconfig_get_local(struct vpn_ipconfig *ipconfig) void __vpn_ipconfig_set_peer(struct vpn_ipconfig *ipconfig, const char *address) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return; g_free(ipconfig->address->peer); @@ -171,7 +157,7 @@ void __vpn_ipconfig_set_peer(struct vpn_ipconfig *ipconfig, void __vpn_ipconfig_set_broadcast(struct vpn_ipconfig *ipconfig, const char *broadcast) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return; g_free(ipconfig->address->broadcast); @@ -183,7 +169,7 @@ void __vpn_ipconfig_set_gateway(struct vpn_ipconfig *ipconfig, { DBG(""); - if (ipconfig->address == NULL) + if (!ipconfig->address) return; g_free(ipconfig->address->gateway); ipconfig->address->gateway = g_strdup(gateway); @@ -192,7 +178,7 @@ void __vpn_ipconfig_set_gateway(struct vpn_ipconfig *ipconfig, const char * __vpn_ipconfig_get_gateway(struct vpn_ipconfig *ipconfig) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return NULL; return ipconfig->address->gateway; @@ -201,7 +187,7 @@ __vpn_ipconfig_get_gateway(struct vpn_ipconfig *ipconfig) void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig, unsigned char prefixlen) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return; ipconfig->address->prefixlen = prefixlen; @@ -210,7 +196,7 @@ void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig, unsigned char __vpn_ipconfig_get_prefixlen(struct vpn_ipconfig *ipconfig) { - if (ipconfig->address == NULL) + if (!ipconfig->address) return 0; return ipconfig->address->prefixlen; @@ -220,7 +206,7 @@ int __vpn_ipconfig_address_add(struct vpn_ipconfig *ipconfig, int family) { DBG("ipconfig %p family %d", ipconfig, family); - if (ipconfig == NULL) + if (!ipconfig) return -EINVAL; if (family == AF_INET) @@ -237,7 +223,7 @@ int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family) { DBG("ipconfig %p family %d", ipconfig, family); - if (ipconfig == NULL || ipconfig->address == NULL) + if (!ipconfig || !ipconfig->address) return -EINVAL; DBG("family %d gw %s peer %s", family, @@ -257,6 +243,23 @@ int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family) return 0; } +void __vpn_ipconfig_unref_debug(struct vpn_ipconfig *ipconfig, + const char *file, int line, const char *caller) +{ + if (!ipconfig) + return; + + DBG("%p ref %d by %s:%d:%s()", ipconfig, ipconfig->refcount - 1, + file, line, caller); + + if (__sync_fetch_and_sub(&ipconfig->refcount, 1) != 1) + return; + + connman_ipaddress_free(ipconfig->system); + connman_ipaddress_free(ipconfig->address); + g_free(ipconfig); +} + static struct vpn_ipconfig *create_ipv6config(int index) { struct vpn_ipconfig *ipv6config; @@ -264,17 +267,17 @@ static struct vpn_ipconfig *create_ipv6config(int index) DBG("index %d", index); ipv6config = g_try_new0(struct vpn_ipconfig, 1); - if (ipv6config == NULL) + if (!ipv6config) return NULL; ipv6config->refcount = 1; ipv6config->index = index; - ipv6config->enabled = FALSE; + ipv6config->enabled = false; ipv6config->family = AF_INET6; ipv6config->address = connman_ipaddress_alloc(AF_INET6); - if (ipv6config->address == NULL) { + if (!ipv6config->address) { g_free(ipv6config); return NULL; } @@ -296,17 +299,17 @@ struct vpn_ipconfig *__vpn_ipconfig_create(int index, int family) DBG("index %d", index); ipconfig = g_try_new0(struct vpn_ipconfig, 1); - if (ipconfig == NULL) + if (!ipconfig) return NULL; ipconfig->refcount = 1; ipconfig->index = index; - ipconfig->enabled = FALSE; + ipconfig->enabled = false; ipconfig->family = family; ipconfig->address = connman_ipaddress_alloc(AF_INET); - if (ipconfig->address == NULL) { + if (!ipconfig->address) { g_free(ipconfig); return NULL; } @@ -354,11 +357,11 @@ void __vpn_ipconfig_newlink(int index, unsigned short type, return; ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index)); - if (ipdevice != NULL) + if (ipdevice) goto update; ipdevice = g_try_new0(struct vpn_ipdevice, 1); - if (ipdevice == NULL) + if (!ipdevice) return; ipdevice->index = index; @@ -381,7 +384,7 @@ update: ipdevice->flags = flags; str = g_string_new(NULL); - if (str == NULL) + if (!str) return; if (flags & IFF_UP) @@ -408,7 +411,7 @@ void __vpn_ipconfig_dellink(int index, struct rtnl_link_stats *stats) DBG("index %d", index); ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index)); - if (ipdevice == NULL) + if (!ipdevice) return; g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));