summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@nokia.com>2011-01-10 18:03:30 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2011-01-10 18:47:36 +0100
commitd62262f1bb76502d7b6a208f33ba3c53615e2f4e (patch)
treeb00dc563990ff400c93c20b7458c465076c131ad /src
parent74db14161672af1133d4413d12737e0daa228339 (diff)
downloadconnman-d62262f1bb76502d7b6a208f33ba3c53615e2f4e.tar.gz
connman-d62262f1bb76502d7b6a208f33ba3c53615e2f4e.tar.bz2
connman-d62262f1bb76502d7b6a208f33ba3c53615e2f4e.zip
ipconfig: Set ipconfig method correctly for IPv4 and IPv6 config
Diffstat (limited to 'src')
-rw-r--r--src/ipconfig.c77
1 files changed, 75 insertions, 2 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c
index f1533e0a..8ef564e6 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -23,6 +23,7 @@
#include <config.h>
#endif
+#include <stdio.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <linux/if_link.h>
@@ -291,6 +292,35 @@ static const char *scope2str(unsigned char scope)
return "";
}
+static void set_ipv6_state(gchar *ifname, gboolean enable)
+{
+ gchar *path;
+ FILE *f;
+
+ if (ifname == NULL)
+ path = g_strdup("/proc/sys/net/ipv6/conf/all/disable_ipv6");
+ else
+ path = g_strdup_printf(
+ "/proc/sys/net/ipv6/conf/%s/disable_ipv6", ifname);
+
+ if (path == NULL)
+ return;
+
+ f = fopen(path, "r+");
+
+ g_free(path);
+
+ if (f == NULL)
+ return;
+
+ if (enable == FALSE)
+ fprintf(f, "1");
+ else
+ fprintf(f, "0");
+
+ fclose(f);
+}
+
static void free_ipdevice(gpointer data)
{
struct connman_ipdevice *ipdevice = data;
@@ -1512,6 +1542,34 @@ void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
DBUS_TYPE_STRING, &ipconfig->address->gateway);
}
+static void disable_ipv6(struct connman_ipconfig *ipconfig)
+{
+ struct connman_ipdevice *ipdevice;
+
+ DBG("");
+
+ ipdevice = g_hash_table_lookup(ipdevice_hash,
+ GINT_TO_POINTER(ipconfig->index));
+ if (ipdevice == NULL)
+ return;
+
+ set_ipv6_state(ipdevice->ifname, FALSE);
+}
+
+static void enable_ipv6(struct connman_ipconfig *ipconfig)
+{
+ struct connman_ipdevice *ipdevice;
+
+ DBG("");
+
+ ipdevice = g_hash_table_lookup(ipdevice_hash,
+ GINT_TO_POINTER(ipconfig->index));
+ if (ipdevice == NULL)
+ return;
+
+ set_ipv6_state(ipdevice->ifname, TRUE);
+}
+
int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
DBusMessageIter *array)
{
@@ -1586,11 +1644,23 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
switch (method) {
case CONNMAN_IPCONFIG_METHOD_UNKNOWN:
- case CONNMAN_IPCONFIG_METHOD_OFF:
case CONNMAN_IPCONFIG_METHOD_FIXED:
- case CONNMAN_IPCONFIG_METHOD_AUTO:
return -EINVAL;
+ case CONNMAN_IPCONFIG_METHOD_OFF:
+ ipconfig->method = method;
+ if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ disable_ipv6(ipconfig);
+ break;
+
+ case CONNMAN_IPCONFIG_METHOD_AUTO:
+ if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
+ return -EINVAL;
+
+ ipconfig->method = method;
+ enable_ipv6(ipconfig);
+ break;
+
case CONNMAN_IPCONFIG_METHOD_MANUAL:
if (address == NULL)
return -EINVAL;
@@ -1607,6 +1677,9 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
break;
case CONNMAN_IPCONFIG_METHOD_DHCP:
+ if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ return -EOPNOTSUPP;
+
ipconfig->method = method;
break;
}