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
... | ... |
@@ -426,8 +426,16 @@ mroute_addr_print_ex (const struct mroute_addr *ma, |
426 | 426 |
break; |
427 | 427 |
case MR_ADDR_IPV6: |
428 | 428 |
{ |
429 |
- buf_printf (&out, "%s", |
|
430 |
- print_in6_addr( *(struct in6_addr*)&maddr.addr, 0, gc)); |
|
429 |
+ if ( IN6_IS_ADDR_V4MAPPED( (struct in6_addr*)&maddr.addr ) ) |
|
430 |
+ { |
|
431 |
+ buf_printf (&out, "%s", |
|
432 |
+ print_in_addr_t( *(in_addr_t*)(&maddr.addr[12]), IA_NET_ORDER, gc)); |
|
433 |
+ } |
|
434 |
+ else |
|
435 |
+ { |
|
436 |
+ buf_printf (&out, "%s", |
|
437 |
+ print_in6_addr( *(struct in6_addr*)&maddr.addr, 0, gc)); |
|
438 |
+ } |
|
431 | 439 |
if (maddr.type & MR_WITH_NETBITS) |
432 | 440 |
{ |
433 | 441 |
buf_printf (&out, "/%d", maddr.netbits); |
... | ... |
@@ -2573,9 +2573,19 @@ setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openv |
2573 | 2573 |
} |
2574 | 2574 |
break; |
2575 | 2575 |
case AF_INET6: |
2576 |
- openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip6", name_prefix); |
|
2577 |
- getnameinfo(&addr->addr.sa, sizeof (struct sockaddr_in6), |
|
2578 |
- buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); |
|
2576 |
+ if ( IN6_IS_ADDR_V4MAPPED( &addr->addr.in6.sin6_addr )) |
|
2577 |
+ { |
|
2578 |
+ struct in_addr ia; |
|
2579 |
+ ia.s_addr = *(in_addr_t *)&addr->addr.in6.sin6_addr.s6_addr[12] ; |
|
2580 |
+ openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip", name_prefix); |
|
2581 |
+ openvpn_snprintf (buf, sizeof(buf), "%s", inet_ntoa(ia) ); |
|
2582 |
+ } |
|
2583 |
+ else |
|
2584 |
+ { |
|
2585 |
+ openvpn_snprintf (name_buf, sizeof (name_buf), "%s_ip6", name_prefix); |
|
2586 |
+ getnameinfo(&addr->addr.sa, sizeof (struct sockaddr_in6), |
|
2587 |
+ buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); |
|
2588 |
+ } |
|
2579 | 2589 |
setenv_str (es, name_buf, buf); |
2580 | 2590 |
|
2581 | 2591 |
if ((flags & SA_IP_PORT) && addr->addr.in6.sin6_port) |