#include <config.h>
#endif
+#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "connman.h"
#include <connman/log.h>
#include <connman/ipconfig.h>
+#include "gweb/gweb.h"
static int tunnel_created;
static int tunnel_pending;
static char *tunnel_ip_address;
+static GWeb *web;
+static guint web_request_id;
+
+#define STATUS_URL "http://ipv6.connman.net/online/status.html"
#define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
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));
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,
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;
return ret;
}
+static gboolean unref_web(gpointer user_data)
+{
+ g_web_unref(web);
+ return FALSE;
+}
+
+static gboolean web_result(GWebResult *result, gpointer user_data)
+{
+ guint16 status;
+
+ if (web_request_id == 0)
+ return FALSE;
+
+ status = g_web_result_get_status(result);
+
+ DBG("status %u", status);
+
+ if (status >= 400 && status < 500)
+ tunnel_destroy();
+ else
+ tunnel_pending = 0;
+
+ web_request_id = 0;
+
+ g_timeout_add_seconds(1, unref_web, NULL);
+
+ return FALSE;
+}
+
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("");
if (ret)
goto error;
- tunnel_pending = 0;
+ 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(if_index);
+ if (web == NULL)
+ goto error;
+
+ g_web_set_accept(web, NULL);
+ g_web_set_user_agent(web, "ConnMan/%s", VERSION);
+ g_web_set_close_connection(web, TRUE);
+
+ web_request_id = g_web_request_get(web, STATUS_URL, web_result, NULL);
+
return 0;
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.
{
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;
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;
if (tunnel_created)
tunnel_destroy();
}
+
+int __connman_6to4_check(struct connman_ipconfig *ip4config)
+{
+ const char *address;
+
+ if (ip4config == NULL || tunnel_created == 0 ||
+ tunnel_pending == 1)
+ return -1;
+
+ DBG("tunnel ip address %s", tunnel_ip_address);
+
+ address = __connman_ipconfig_get_local(ip4config);
+ if (address == NULL)
+ return -1;
+
+ if (g_strcmp0(address, tunnel_ip_address) == 0)
+ return 1;
+
+ return 0;
+}