Browse code

add flag to print addresses in a consistent format during float

Introduce the MAPF_SHOW_FAMILY flag to prepend the address family to the
address when printing an mroute_addr object, similar to
print_sockaddr_ex(). This ensures that when logging a float operation,
both the old and new addresses are printed in the same format:
$proto:[$family]$address:$port.

Note: when using this flag with an IPv4-mapped IPv6 address, the output
will appear as: [AF_INET6]a.b.c.d

Change-Id: I43cd3d564d8c6ad4e41de5a38130d90cb6778395
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250725194147.17517-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32345.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Ralf Lici authored on 2025/07/26 04:41:39
Showing 3 changed files
... ...
@@ -415,6 +415,10 @@ mroute_addr_print_ex(const struct mroute_addr *ma,
415 415
                 {
416 416
                     buf_printf(&out, "%s:", proto2ascii(maddr.proto, AF_INET, false));
417 417
                 }
418
+                if (flags & MAPF_SHOW_FAMILY)
419
+                {
420
+                    buf_printf(&out, "[AF_INET]");
421
+                }
418 422
                 buf_printf(&out, "%s", print_in_addr_t(ntohl(maddr.v4.addr),
419 423
                                                        (flags & MAPF_IA_EMPTY_IF_UNDEF) ? IA_EMPTY_IF_UNDEF : 0, gc));
420 424
                 if (maddr.type & MR_WITH_NETBITS)
... ...
@@ -442,6 +446,10 @@ mroute_addr_print_ex(const struct mroute_addr *ma,
442 442
                 {
443 443
                     buf_printf(&out, "%s:", proto2ascii(maddr.proto, AF_INET6, false));
444 444
                 }
445
+                if (flags & MAPF_SHOW_FAMILY)
446
+                {
447
+                    buf_printf(&out, "[AF_INET6]");
448
+                }
445 449
                 if (IN6_IS_ADDR_V4MAPPED( &maddr.v6.addr ) )
446 450
                 {
447 451
                     buf_printf(&out, "%s", print_in_addr_t(maddr.v4mappedv6.addr,
... ...
@@ -150,6 +150,7 @@ const char *mroute_addr_print(const struct mroute_addr *ma,
150 150
 #define MAPF_SUBNET            (1<<0)
151 151
 #define MAPF_IA_EMPTY_IF_UNDEF (1<<1)
152 152
 #define MAPF_SHOW_ARP          (1<<2)
153
+#define MAPF_SHOW_FAMILY       (1<<3)
153 154
 const char *mroute_addr_print_ex(const struct mroute_addr *ma,
154 155
                                  const unsigned int flags,
155 156
                                  struct gc_arena *gc);
... ...
@@ -3275,8 +3275,8 @@ multi_process_float(struct multi_context *m, struct multi_instance *mi,
3275 3275
     msg(D_MULTI_MEDIUM, "peer %" PRIu32 " (%s) floated from %s to %s",
3276 3276
         mi->context.c2.tls_multi->peer_id,
3277 3277
         tls_common_name(mi->context.c2.tls_multi, false),
3278
-        mroute_addr_print(&mi->real, &gc),
3279
-        print_link_socket_actual(&m->top.c2.from, &gc));
3278
+        mroute_addr_print_ex(&mi->real, MAPF_SHOW_FAMILY, &gc),
3279
+        mroute_addr_print_ex(&real, MAPF_SHOW_FAMILY, &gc));
3280 3280
 
3281 3281
     /* remove old address from hash table before changing address */
3282 3282
     ASSERT(hash_remove(m->hash, &mi->real));