]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Set IPV6_V6ONLY on listener sockets bound to IPv6 addresses.
authorNick Mathewson <nickm@torproject.org>
Tue, 31 Jan 2012 21:09:49 +0000 (16:09 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 31 Jan 2012 21:09:49 +0000 (16:09 -0500)
If we don't do this, [::] can be interpreted to mean all v4 and all
v6 addresses.  Found by dcf.  Fixes bug 4760.  See RFC 3493 section
5.3 for more info.

changes/bug4760 [new file with mode: 0644]
src/or/connection.c

diff --git a/changes/bug4760 b/changes/bug4760
new file mode 100644 (file)
index 0000000..ea8d16e
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes:
+    - When binding to an IPv6 address, set the IPV6_V6ONLY socket
+      option, so that the IP stack doesn't decide to use it for IPv4
+      too. Fixes bug 4760; bugfix on 0.2.3.9-alpha.
index bf65e8e81bb0ee3017276b1592ce7af887b116af..06a75626567c0754c6276416e17336ba14750dcb 100644 (file)
@@ -902,6 +902,25 @@ connection_listener_new(const struct sockaddr *listensockaddr,
 
     make_socket_reuseable(s);
 
+#ifdef IPV6_V6ONLY
+    if (listensockaddr->sa_family == AF_INET6) {
+#ifdef _WIN32
+      /* In Redmond, this kind of thing passes for standards-conformance. */
+      DWORD one = 1;
+#else
+      int one = 1;
+#endif
+      /* We need to set IPV6_V6ONLY so that this socket can't get used for
+       * IPv4 connections. */
+      if (setsockopt(s,IPPROTO_IPV6, IPV6_V6ONLY, (void*)&one, sizeof(one))<0) {
+        int e = tor_socket_errno(s);
+        log_warn(LD_NET, "Error setting IPV6_V6ONLY flag: %s",
+                 tor_socket_strerror(e));
+        /* Keep going; probably not harmful. */
+      }
+    }
+#endif
+
     if (bind(s,listensockaddr,socklen) < 0) {
       const char *helpfulhint = "";
       int e = tor_socket_errno(s);