Skip to content

Displaying IPv6 addresses with port number in logs #968

@kabassanov

Description

@kabassanov

Hi,

There is some old code in openvpn stripping tcp/udp ports from ipv6 addresses because "v6addr:port" is too ambiguous. But there is an ipv6 address notation for this, we can simply use [ ] to delimit ipv6 address. So something like this should be enough:

+++ ../openvpn-2.6.14/src/openvpn/mroute.c      2026-01-28 11:51:12.878773385 +0100
@@ -430,9 +430,6 @@ mroute_addr_print_ex(const struct mroute
                 {
                     buf_printf(&out, "%s", print_in_addr_t(maddr.v4mappedv6.addr,
                                                            IA_NET_ORDER, gc));
-                    /* we only print port numbers for v4mapped v6 as of
-                     * today, because "v6addr:port" is too ambiguous
-                     */
                     if (maddr.type & MR_WITH_PORT)
                     {
                         buf_printf(&out, ":%d", ntohs(maddr.v6.port));
@@ -440,7 +437,11 @@ mroute_addr_print_ex(const struct mroute
                 }
                 else
                 {
-                    buf_printf(&out, "%s", print_in6_addr(maddr.v6.addr, 0, gc));
+                    buf_printf(&out, "[%s]", print_in6_addr(maddr.v6.addr, 0, gc));
+                    if (maddr.type & MR_WITH_PORT)
+                    {
+                        buf_printf(&out, ":%d", ntohs(maddr.v6.port));
+                    }
                 }
                 if (maddr.type & MR_WITH_NETBITS)
                 {

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions