X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fipconfig.c;h=e26f209f131e31e0cec1796f12bd0e805548c6df;hb=5ed7094e4994d03c7606f25881918565c81d1c24;hp=9f73b6568e78d0f9ef5900b95887a46c028b619d;hpb=3ce93388b0f7a092f5855ac37db8fb30cf0c453e;p=framework%2Fconnectivity%2Fconnman.git diff --git a/src/ipconfig.c b/src/ipconfig.c index 9f73b65..e26f209 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -40,7 +40,7 @@ #include "connman.h" struct connman_ipconfig { - gint refcount; + int refcount; int index; enum connman_ipconfig_type type; @@ -54,6 +54,7 @@ struct connman_ipconfig { struct connman_ipaddress *system; int ipv6_privacy_config; + char *last_dhcp_address; }; struct connman_ipdevice { @@ -451,6 +452,60 @@ static void set_ipv6_privacy(gchar *ifname, int value) fclose(f); } +static int get_rp_filter() +{ + FILE *f; + int value = -EINVAL, tmp; + + f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r"); + + if (f != NULL) { + if (fscanf(f, "%d", &tmp) == 1) + value = tmp; + fclose(f); + } + + return value; +} + +static void set_rp_filter(int value) +{ + FILE *f; + + f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r+"); + + if (f == NULL) + return; + + fprintf(f, "%d", value); + + fclose(f); +} + +int __connman_ipconfig_set_rp_filter() +{ + int value; + + value = get_rp_filter(); + + if (value < 0) + return value; + + set_rp_filter(2); + + connman_info("rp_filter set to 2 (loose mode routing), " + "old value was %d", value); + + return value; +} + +void __connman_ipconfig_unset_rp_filter(int old_value) +{ + set_rp_filter(old_value); + + connman_info("rp_filter restored to %d", old_value); +} + static void free_ipdevice(gpointer data) { struct connman_ipdevice *ipdevice = data; @@ -650,6 +705,13 @@ update: ipconfig->ops->down(ipconfig); } +#if defined TIZEN_EXT + if (g_strcmp0(ipdevice->address, address) != 0) { + g_free(ipdevice->address); + ipdevice->address = g_strdup(address); + } +#endif + if (lower_up) __connman_ipconfig_lower_up(ipdevice); if (lower_down) @@ -1119,16 +1181,27 @@ void __connman_ipconfig_set_gateway(struct connman_ipconfig *ipconfig, const cha ipconfig->address->gateway = g_strdup(gateway); } +#if defined TIZEN_EXT +/* + * Description: __connman_service_lookup_from_index cannot find correct service + */ +int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig, struct connman_service *service) +#else int __connman_ipconfig_gateway_add(struct connman_ipconfig *ipconfig) +#endif { +#if !defined TIZEN_EXT struct connman_service *service; +#endif DBG(""); if (ipconfig->address == NULL) return -EINVAL; +#if !defined TIZEN_EXT service = __connman_service_lookup_from_index(ipconfig->index); +#endif if (service == NULL) return -EINVAL; @@ -1252,10 +1325,9 @@ struct connman_ipconfig *connman_ipconfig_create(int index, */ struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig) { - DBG("ipconfig %p refcount %d", ipconfig, - g_atomic_int_get(&ipconfig->refcount) + 1); + DBG("ipconfig %p refcount %d", ipconfig, ipconfig->refcount + 1); - g_atomic_int_inc(&ipconfig->refcount); + __sync_fetch_and_add(&ipconfig->refcount, 1); return ipconfig; } @@ -1271,23 +1343,25 @@ void connman_ipconfig_unref(struct connman_ipconfig *ipconfig) if (ipconfig == NULL) return; - DBG("ipconfig %p refcount %d", ipconfig, - g_atomic_int_get(&ipconfig->refcount) - 1); + DBG("ipconfig %p refcount %d", ipconfig, ipconfig->refcount - 1); - if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) { - __connman_ipconfig_disable(ipconfig); + if (__sync_fetch_and_sub(&ipconfig->refcount, 1) != 1) + return; - connman_ipconfig_set_ops(ipconfig, NULL); + if (__connman_ipconfig_disable(ipconfig) < 0) + ipconfig_list = g_list_remove(ipconfig_list, ipconfig); - if (ipconfig->origin != NULL) { - connman_ipconfig_unref(ipconfig->origin); - ipconfig->origin = NULL; - } + connman_ipconfig_set_ops(ipconfig, NULL); - connman_ipaddress_free(ipconfig->system); - connman_ipaddress_free(ipconfig->address); - g_free(ipconfig); + if (ipconfig->origin != NULL) { + connman_ipconfig_unref(ipconfig->origin); + ipconfig->origin = NULL; } + + connman_ipaddress_free(ipconfig->system); + connman_ipaddress_free(ipconfig->address); + g_free(ipconfig->last_dhcp_address); + g_free(ipconfig); } /** @@ -1518,6 +1592,24 @@ const char *__connman_ipconfig_get_proxy_autoconfig(struct connman_ipconfig *ipc return ipdevice->pac; } +void __connman_ipconfig_set_dhcp_address(struct connman_ipconfig *ipconfig, + const char *address) +{ + if (ipconfig == NULL) + return; + + g_free(ipconfig->last_dhcp_address); + ipconfig->last_dhcp_address = g_strdup(address); +} + +char *__connman_ipconfig_get_dhcp_address(struct connman_ipconfig *ipconfig) +{ + if (ipconfig == NULL) + return NULL; + + return ipconfig->last_dhcp_address; +} + static void disable_ipv6(struct connman_ipconfig *ipconfig) { struct connman_ipdevice *ipdevice; @@ -1890,10 +1982,10 @@ void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig, switch (ipconfig->method) { case CONNMAN_IPCONFIG_METHOD_UNKNOWN: case CONNMAN_IPCONFIG_METHOD_OFF: - case CONNMAN_IPCONFIG_METHOD_FIXED: case CONNMAN_IPCONFIG_METHOD_DHCP: case CONNMAN_IPCONFIG_METHOD_AUTO: return; + case CONNMAN_IPCONFIG_METHOD_FIXED: case CONNMAN_IPCONFIG_METHOD_MANUAL: break; } @@ -2080,6 +2172,7 @@ int __connman_ipconfig_load(struct connman_ipconfig *ipconfig, { char *method; char *key; + char *str; DBG("ipconfig %p identifier %s", ipconfig, identifier); @@ -2140,6 +2233,14 @@ int __connman_ipconfig_load(struct connman_ipconfig *ipconfig, keyfile, identifier, key, NULL); g_free(key); + key = g_strdup_printf("%sDHCP.LastAddress", prefix); + str = g_key_file_get_string(keyfile, identifier, key, NULL); + if (str != NULL) { + g_free(ipconfig->last_dhcp_address); + ipconfig->last_dhcp_address = str; + } + g_free(key); + return 0; } @@ -2169,9 +2270,18 @@ int __connman_ipconfig_save(struct connman_ipconfig *ipconfig, case CONNMAN_IPCONFIG_METHOD_FIXED: case CONNMAN_IPCONFIG_METHOD_MANUAL: break; + case CONNMAN_IPCONFIG_METHOD_DHCP: + key = g_strdup_printf("%sDHCP.LastAddress", prefix); + if (ipconfig->last_dhcp_address != NULL && + strlen(ipconfig->last_dhcp_address) > 0) + g_key_file_set_string(keyfile, identifier, key, + ipconfig->last_dhcp_address); + else + g_key_file_remove_key(keyfile, identifier, key, NULL); + g_free(key); + /* fall through */ case CONNMAN_IPCONFIG_METHOD_UNKNOWN: case CONNMAN_IPCONFIG_METHOD_OFF: - case CONNMAN_IPCONFIG_METHOD_DHCP: case CONNMAN_IPCONFIG_METHOD_AUTO: return 0; }