#include <config.h>
#endif
+#include <errno.h>
#include <stdio.h>
#include <net/if.h>
#include <net/if_arp.h>
#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 {
unsigned char buf[sizeof(struct in6_addr)];
int err;
+ if (address == NULL)
+ return FALSE;
+
err = inet_pton(AF_INET6, address, buf);
if (err > 0)
return TRUE;
}
int connman_ipaddress_set_ipv6(struct connman_ipaddress *ipaddress,
- const char *address, const char *gateway,
- unsigned char prefix_length)
+ const char *address,
+ unsigned char prefix_length,
+ const char *gateway)
{
if (ipaddress == NULL)
return -EINVAL;
return NULL;
}
+const char *__connman_ipconfig_type2string(enum connman_ipconfig_type type)
+{
+ switch (type) {
+ case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+ return "unknown";
+ case CONNMAN_IPCONFIG_TYPE_IPV4:
+ return "IPv4";
+ case CONNMAN_IPCONFIG_TYPE_IPV6:
+ return "IPv6";
+ }
+
+ return NULL;
+}
+
static const char *type2str(unsigned short type)
{
switch (type) {
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)
{
struct connman_ipdevice *ipdevice;
struct connman_ipaddress *ipaddress;
+ enum connman_ipconfig_type type;
GList *list;
DBG("index %d", index);
return;
}
+ if (family == AF_INET)
+ type = CONNMAN_IPCONFIG_TYPE_IPV4;
+ else if (family == AF_INET6)
+ type = CONNMAN_IPCONFIG_TYPE_IPV6;
+ else
+ return;
+
ipdevice->address_list = g_slist_append(ipdevice->address_list,
ipaddress);
if (index != ipconfig->index)
continue;
+ if (type != ipconfig->type)
+ continue;
+
if (ipconfig->ops == NULL)
continue;
{
struct connman_ipdevice *ipdevice;
struct connman_ipaddress *ipaddress;
+ enum connman_ipconfig_type type;
GList *list;
DBG("index %d", index);
if (ipaddress == NULL)
return;
+ if (family == AF_INET)
+ type = CONNMAN_IPCONFIG_TYPE_IPV4;
+ else if (family == AF_INET6)
+ type = CONNMAN_IPCONFIG_TYPE_IPV6;
+ else
+ return;
+
ipdevice->address_list = g_slist_remove(ipdevice->address_list,
ipaddress);
if (index != ipconfig->index)
continue;
+ if (type != ipconfig->type)
+ continue;
+
if (ipconfig->ops == NULL)
continue;
if (ipdevice == NULL)
return;
- if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
+ if (scope == 0 && (g_strcmp0(dst, "0.0.0.0") == 0 ||
+ g_strcmp0(dst, "::") == 0)) {
GSList *list;
GList *config_list;
+ enum connman_ipconfig_type type;
if (family == AF_INET6) {
+ type = CONNMAN_IPCONFIG_TYPE_IPV6;
g_free(ipdevice->ipv6_gateway);
ipdevice->ipv6_gateway = g_strdup(gateway);
ipdevice->config_ipv6->system->gateway =
g_strdup(gateway);
}
- } else {
+ } else if (family == AF_INET) {
+ type = CONNMAN_IPCONFIG_TYPE_IPV4;
g_free(ipdevice->ipv4_gateway);
ipdevice->ipv4_gateway = g_strdup(gateway);
ipdevice->config_ipv4->system->gateway =
g_strdup(gateway);
}
- }
+ } else
+ return;
for (list = ipdevice->address_list; list; list = list->next) {
struct connman_ipaddress *ipaddress = list->data;
if (index != ipconfig->index)
continue;
+ if (type != ipconfig->type)
+ continue;
+
if (ipconfig->ops == NULL)
continue;
if (ipdevice == NULL)
return;
- if (scope == 0 && g_strcmp0(dst, "0.0.0.0") == 0) {
+ if (scope == 0 && (g_strcmp0(dst, "0.0.0.0") == 0 ||
+ g_strcmp0(dst, "::") == 0)) {
GSList *list;
GList *config_list;
+ enum connman_ipconfig_type type;
if (family == AF_INET6) {
+ type = CONNMAN_IPCONFIG_TYPE_IPV6;
g_free(ipdevice->ipv6_gateway);
ipdevice->ipv6_gateway = NULL;
g_free(ipdevice->config_ipv6->system->gateway);
ipdevice->config_ipv6->system->gateway = NULL;
}
- } else {
+ } else if (family == AF_INET) {
+ type = CONNMAN_IPCONFIG_TYPE_IPV4;
g_free(ipdevice->ipv4_gateway);
ipdevice->ipv4_gateway = NULL;
g_free(ipdevice->config_ipv4->system->gateway);
ipdevice->config_ipv4->system->gateway = NULL;
}
- }
+ } else
+ return;
for (list = ipdevice->address_list; list; list = list->next) {
struct connman_ipaddress *ipaddress = list->data;
if (index != ipconfig->index)
continue;
+ if (type != ipconfig->type)
+ continue;
+
if (ipconfig->ops == NULL)
continue;
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;
- __connman_connection_gateway_remove(service);
+ __connman_connection_gateway_remove(service, ipconfig->type);
- if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6) {
- return __connman_connection_gateway_add(service, NULL,
- ipconfig->address->gateway,
- ipconfig->address->peer);
- } else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+ DBG("type %d gw %s peer %s", ipconfig->type,
+ ipconfig->address->gateway, ipconfig->address->peer);
+
+ if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6 ||
+ ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
return __connman_connection_gateway_add(service,
ipconfig->address->gateway,
- NULL, ipconfig->address->peer);
- }
+ ipconfig->type,
+ ipconfig->address->peer);
return 0;
}
service = __connman_service_lookup_from_index(ipconfig->index);
if (service != NULL)
- __connman_connection_gateway_remove(service);
+ __connman_connection_gateway_remove(service, ipconfig->type);
}
unsigned char __connman_ipconfig_get_prefixlen(struct connman_ipconfig *ipconfig)
*/
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);
}
/**
int __connman_ipconfig_address_remove(struct connman_ipconfig *ipconfig)
{
+ int err;
+
+ DBG("");
+
+ if (ipconfig == NULL)
+ return 0;
+
+ DBG("method %d", ipconfig->method);
+
+ switch (ipconfig->method) {
+ case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ break;
+ case CONNMAN_IPCONFIG_METHOD_FIXED:
+ case CONNMAN_IPCONFIG_METHOD_DHCP:
+ case CONNMAN_IPCONFIG_METHOD_MANUAL:
+ err = __connman_ipconfig_address_unset(ipconfig);
+ connman_ipaddress_clear(ipconfig->address);
+
+ return err;
+ }
+
+ return 0;
+}
+
+int __connman_ipconfig_address_unset(struct connman_ipconfig *ipconfig)
+{
+ int err;
+
DBG("");
if (ipconfig == NULL)
case CONNMAN_IPCONFIG_METHOD_DHCP:
case CONNMAN_IPCONFIG_METHOD_MANUAL:
if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV4)
- return connman_inet_clear_address(ipconfig->index,
+ err = connman_inet_clear_address(ipconfig->index,
ipconfig->address);
else if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
- return connman_inet_clear_ipv6_address(
+ err = connman_inet_clear_ipv6_address(
ipconfig->index,
ipconfig->address->local,
ipconfig->address->prefixlen);
+ else
+ err = -EINVAL;
+
+ return err;
}
return 0;
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;
set_ipv6_state(ipdevice->ifname, TRUE);
}
+void __connman_ipconfig_enable_ipv6(struct connman_ipconfig *ipconfig)
+{
+ if (ipconfig == NULL || ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
+ return;
+
+ enable_ipv6(ipconfig);
+}
+
void __connman_ipconfig_disable_ipv6(struct connman_ipconfig *ipconfig)
{
if (ipconfig == NULL || ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
}
void __connman_ipconfig_append_ipv6(struct connman_ipconfig *ipconfig,
- DBusMessageIter *iter)
+ DBusMessageIter *iter,
+ struct connman_ipconfig *ipconfig_ipv4)
{
const char *str, *privacy;
if (str == NULL)
return;
+ if (ipconfig_ipv4 != NULL &&
+ ipconfig->method == CONNMAN_IPCONFIG_METHOD_AUTO) {
+ if (__connman_6to4_check(ipconfig_ipv4) == 1)
+ str = "6to4";
+ }
+
connman_dbus_dict_append_basic(iter, "Method", DBUS_TYPE_STRING, &str);
if (ipconfig->system == NULL)
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;
}
else
return connman_ipaddress_set_ipv6(
ipconfig->address, address,
- gateway, prefix_length);
+ prefix_length, gateway);
break;
case CONNMAN_IPCONFIG_METHOD_DHCP:
{
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;
}