dnsproxy: Remove pending requests before destroying the channel
[framework/connectivity/connman.git] / src / 6to4.c
index 3877bfb..2d54f6d 100644 (file)
@@ -24,6 +24,7 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -48,7 +49,7 @@ static char *tunnel_ip_address;
 static GWeb *web;
 static guint web_request_id;
 
-#define STATUS_URL "http://ipv6.google.com/"
+#define STATUS_URL "http://ipv6.connman.net/online/status.html"
 
 #define NLMSG_TAIL(nmsg) \
        ((struct rtattr *) (((void *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
@@ -117,7 +118,7 @@ static int rtnl_open(struct rtnl_handle *rth)
 
        memset(rth, 0, sizeof(*rth));
 
-       rth->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+       rth->fd = socket(AF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
        if (rth->fd < 0) {
                connman_error("Can not open netlink socket: %s",
                                                strerror(errno));
@@ -212,7 +213,7 @@ static int tunnel_create(struct in_addr *addr)
 
        strncpy(ifr.ifr_name, "sit0", IFNAMSIZ);
        ifr.ifr_ifru.ifru_data = (void *)&p;
-       fd = socket(AF_INET, SOCK_DGRAM, 0);
+       fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
        ret = ioctl(fd, SIOCADDTUNNEL, &ifr);
        if (ret)
                connman_error("add tunnel %s failed: %s", ifr.ifr_name,
@@ -244,7 +245,7 @@ static void tunnel_destroy()
 
        strncpy(ifr.ifr_name, "tun6to4", IFNAMSIZ);
        ifr.ifr_ifru.ifru_data = (void *)&p;
-       fd = socket(AF_INET, SOCK_DGRAM, 0);
+       fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
        if (fd < 0) {
                connman_error("socket failed: %s", strerror(errno));
                return;
@@ -395,8 +396,8 @@ static gboolean web_result(GWebResult *result, gpointer user_data)
 static int init_6to4(struct in_addr *ip4addr)
 {
        unsigned int a, b, c, d;
+       int ret, if_index;
        in_addr_t addr;
-       int ret;
 
        DBG("");
 
@@ -425,9 +426,13 @@ static int init_6to4(struct in_addr *ip4addr)
        if (ret)
                goto error;
 
+       if_index = connman_inet_ifindex("tun6to4");
+       if (if_index < 0)
+               goto error;
+
        /* We try to verify that connectivity through tunnel works ok.
         */
-       web = g_web_new(0);
+       web = g_web_new(if_index);
        if (web == NULL)
                goto error;
 
@@ -444,12 +449,13 @@ error:
        return -1;
 }
 
-static void receive_rs_reply(struct nd_router_advert *reply, void *user_data)
+static void receive_rs_reply(struct nd_router_advert *reply,
+                       unsigned int length, void *user_data)
 {
        char *address = user_data;
        struct in_addr ip4addr;
 
-       DBG("reply %p address %s", reply, address);
+       DBG("reply %p len %d address %s", reply, length, address);
 
        /* We try to create tunnel if autoconfiguration did not work i.e.,
         * we did not receive any reply to router solicitation message.
@@ -464,7 +470,7 @@ int __connman_6to4_probe(struct connman_service *service)
 {
        struct connman_ipconfig *ip4config, *ip6config;
        enum connman_ipconfig_method method;
-       unsigned int a, b, c, d;
+       unsigned int a, b;
        struct in_addr ip4addr;
        in_addr_t addr;
        const char *address;
@@ -502,15 +508,13 @@ int __connman_6to4_probe(struct connman_service *service)
 
        a = (addr & 0xff000000) >> 24;
        b = (addr & 0x00ff0000) >> 16;
-       c = (addr & 0x0000ff00) >> 8;
-       d = addr & 0x000000ff;
 
        /* 6to4 tunnel is only usable if we have a public IPv4 address */
        if (a == 10 || (a == 192 && b == 168) ||
                                        (a == 172 && (b >= 16 && b <= 31)))
                return -1;
 
-       index = connman_ipconfig_get_index(ip4config);
+       index = __connman_ipconfig_get_index(ip4config);
        ip_address = g_strdup(address);
        tunnel_pending = 1;