[Openvpn-devel,1/3] Log the actual management interface port in use

Message ID 20220630190549.16675-1-selva.nair@gmail.com
State Accepted
Headers show
Series [Openvpn-devel,1/3] Log the actual management interface port in use | expand

Commit Message

Selva Nair June 30, 2022, 7:05 p.m. UTC
From: Selva Nair <selva.nair@gmail.com>

When the port is specified as zero, log the actual port
bound to, instead of 0.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
---
 src/openvpn/manage.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Gert Doering July 14, 2022, 6:49 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

This looks like a useful addition, and it actually works :-)

$ openvpn --verb 4 --dev tun --management :: 0 --management-hold
..
2022-07-14 20:43:01 us=644866 setsockopt(IPV6_V6ONLY=0)
2022-07-14 20:43:01 us=644907 MANAGEMENT: TCP Socket listening on [AF_INET6][undef]:59291
2022-07-14 20:43:01 us=644918 Need hold release from management interface, waiting...

of course it also works for legacy IP...

2022-07-14 20:43:39 us=245584 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:63545

Tested on FreeBSD and on OpenSolaris (because that's always the oddball
"it is a real unix, but more pain than the rest" OS).

Your patch has been applied to the master branch.

commit 298f3bedbc42578d39055990669f7dda0f787d68
Author: Selva Nair
Date:   Thu Jun 30 15:05:47 2022 -0400

     Log the actual management interface port in use

     Signed-off-by: Selva Nair <selva.nair@gmail.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20220630190549.16675-1-selva.nair@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24617.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 50f162a3..21c7ccdd 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -1830,8 +1830,22 @@  man_listen(struct management *man)
         }
         else
 #endif
-        msg(D_MANAGEMENT, "MANAGEMENT: TCP Socket listening on %s",
-            print_sockaddr(man->settings.local->ai_addr, &gc));
+        {
+            const struct sockaddr *man_addr = man->settings.local->ai_addr;
+            struct sockaddr_storage addr;
+            socklen_t addrlen = sizeof(addr);
+            if (!getsockname(man->connection.sd_top, (struct sockaddr *) &addr, &addrlen))
+            {
+                man_addr = (struct sockaddr *) &addr;
+            }
+            else
+            {
+                msg(M_WARN|M_ERRNO,
+                    "Failed to get the management socket address");
+            }
+            msg(D_MANAGEMENT, "MANAGEMENT: TCP Socket listening on %s",
+                print_sockaddr(man_addr, &gc));
+        }
     }
 
 #ifdef _WIN32