]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Print remote IPv4 address on a dual-stack v6 socket in IPv4 format
authorGert Doering <gert@greenie.muc.de>
Mon, 29 Dec 2014 17:48:45 +0000 (18:48 +0100)
committerGert Doering <gert@greenie.muc.de>
Sun, 15 Feb 2015 22:04:12 +0000 (23:04 +0100)
Previously, the code would print IPv4-mapped format ("::ffff:1.2.3.4"),
which is technically correct but adds no extra value, and is confusingly
different from the output if using a v4 socket.  Print "1.2.3.4" instead,
whatever socket type is used.

Affects client IP address in log file, status output (mroute_addr_print_ex),
and environment (setenv_sockaddr).

The fact that a dual-stack socket was used is still visible in the initial
peer connect message in the log:
  '... Peer Connection Initiated with [AF_INET6]::ffff:1.1.3.4:53779'

Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <1419875325-96015-1-git-send-email-gert@greenie.muc.de>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9363

src/openvpn/mroute.c
src/openvpn/socket.c

index ba4ef46f639a32a5d6b52e0a40a14e9e2fb60b4e..972f1dd5e454a360a44b7066ac1e0d1ee57e4ef5 100644 (file)
@@ -426,8 +426,16 @@ mroute_addr_print_ex (const struct mroute_addr *ma,
          break;
        case MR_ADDR_IPV6:
          {
-           buf_printf (&out, "%s",
-                 print_in6_addr( *(struct in6_addr*)&maddr.addr, 0, gc)); 
+           if ( IN6_IS_ADDR_V4MAPPED( (struct in6_addr*)&maddr.addr ) )
+             {
+               buf_printf (&out, "%s",
+                    print_in_addr_t( *(in_addr_t*)(&maddr.addr[12]), IA_NET_ORDER, gc));
+             }
+           else
+             {
+               buf_printf (&out, "%s",
+                     print_in6_addr( *(struct in6_addr*)&maddr.addr, 0, gc));
+             }
            if (maddr.type & MR_WITH_NETBITS)
              {
                buf_printf (&out, "/%d", maddr.netbits);
index 331a9d9f7bd699d451059955e3f776cd67f5ae1a..f5c740d8e5a60482d89705a2f595b0ad7f9d1703 100644 (file)
@@ -2573,9 +2573,19 @@ setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openv
        }
       break;
     case AF_INET6:
-      openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip6", name_prefix);
-      getnameinfo(&addr->addr.sa, sizeof (struct sockaddr_in6),
-                 buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
+      if ( IN6_IS_ADDR_V4MAPPED( &addr->addr.in6.sin6_addr ))
+       {
+         struct in_addr ia;
+         ia.s_addr = *(in_addr_t *)&addr->addr.in6.sin6_addr.s6_addr[12] ;
+         openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip", name_prefix);
+         openvpn_snprintf (buf, sizeof(buf), "%s", inet_ntoa(ia) );
+       }
+      else
+        {
+         openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip6", name_prefix);
+         getnameinfo(&addr->addr.sa, sizeof (struct sockaddr_in6),
+                     buf, sizeof(buf), NULL, 0, NI_NUMERICHOST);
+       }
       setenv_str (es, name_buf, buf);
 
       if ((flags & SA_IP_PORT) && addr->addr.in6.sin6_port)