[Openvpn-devel,3/3] Log address of management client on accept

Message ID 20220630190549.16675-3-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, 9:05 a.m. UTC
From: Selva Nair <selva.nair@gmail.com>

Currently when we are listening on the management
interface, the local address/port is logged as that of
the connecting client.

Fix it.

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

Comments

Gert Doering July 14, 2022, 8:55 a.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Silly code, this...

Before:

2022-07-14 20:50:12 us=826150 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:0

After:

2022-07-14 20:51:18 us=100211 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:49334
2022-07-14 20:51:22 us=443453 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:50184

.. and also dual-stacked...

2022-07-14 20:52:03 us=916048 MANAGEMENT: Client connected from [AF_INET6]::1:29800
2022-07-14 20:52:09 us=636212 MANAGEMENT: Client connected from [AF_INET6]::ffff:127.0.0.1:30335

(Yeah, that one could be printed more pretty... we might have a _ex() thingie
for it... but it's already much more useful than before)

New code looks good, and does what it promises.

Your patch has been applied to the master branch.

commit dd98c38b31c02cbca7f88ed0a709e68f24361195
Author: Selva Nair
Date:   Thu Jun 30 15:05:49 2022 -0400

     Log address of management client on accept

     Signed-off-by: Selva Nair <selva.nair@gmail.com>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20220630190549.16675-3-selva.nair@gmail.com>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24619.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 548d3b9a..7947c906 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -1685,9 +1685,27 @@  man_new_connection_post(struct management *man, const char *description)
     }
     else
 #endif
-    msg(D_MANAGEMENT, "MANAGEMENT: %s %s",
-        description,
-        print_sockaddr(man->settings.local->ai_addr, &gc));
+    if (man->settings.flags & MF_CONNECT_AS_CLIENT)
+    {
+        msg(D_MANAGEMENT, "MANAGEMENT: %s %s",
+            description,
+            print_sockaddr(man->settings.local->ai_addr, &gc));
+    }
+    else
+    {
+        struct sockaddr_storage addr;
+        socklen_t addrlen = sizeof(addr);
+        if (!getpeername(man->connection.sd_cli, (struct sockaddr *) &addr,
+                         &addrlen))
+        {
+            msg(D_MANAGEMENT, "MANAGEMENT: %s %s", description,
+                print_sockaddr((struct sockaddr *) &addr, &gc));
+        }
+        else
+        {
+            msg(D_MANAGEMENT, "MANAGEMENT: %s %s", description, "unknown");
+        }
+    }
 
     buffer_list_reset(man->connection.out);