#include "connman.h"
struct connman_ipconfig {
- gint refcount;
+ int refcount;
int index;
enum connman_ipconfig_type type;
struct connman_ipaddress *system;
int ipv6_privacy_config;
+ char *last_dhcp_address;
};
struct connman_ipdevice {
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;
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)
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;
*/
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;
}
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);
}
/**
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;
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;
}
{
char *method;
char *key;
+ char *str;
DBG("ipconfig %p identifier %s", ipconfig, identifier);
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;
}
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;
}