[Openvpn-devel] Support IPv6 towards port-share proxy receiver

Message ID dcc7e538-2035-4697-b306-10eb470632f3@gmx.de
State Accepted
Headers show
Series [Openvpn-devel] Support IPv6 towards port-share proxy receiver | expand

Commit Message

corubba Dec. 14, 2024, 7:56 p.m. UTC
While port-share already supports IPv6 connections from clients, it only
supported IPv4 connections towards the proxy receiver. The used
common/shared OpenVPN machinery is already IPv6-ready, so all needed was
to use properly-sized `sockaddr` structs and removing hardcoded IPv4
restrictions.

Signed-off-by: corubba <corubba@gmx.de>
---
 src/openvpn/ps.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

--
2.47.1

Comments

Gert Doering Dec. 25, 2024, 4:07 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

This is a nice min-feature, to improve on IPv6 support in OpenVPN - thanks.

I have stared at the code ("looks reasonable") and then actually set up
a port-share test setup, with a v6-only lighttpd behind an OpenVPN port-share,
and "it just works"

    Dec 25 16:59:53 TCP connection established with [AF_INET6]2001:608:4::ce:c0f:54067
    Dec 25 16:59:53 TCPv6_SERVER link remote: [AF_INET6]2001:608:4::ce:c0f:54067
    Dec 25 16:59:53 2001:608:4::ce:c0f Non-OpenVPN client protocol detected

.. it doesn't show the target here, but the connection arrives, and is
also documented properly in the "[dir]"

# ls -l
-rw-r----- 1 root root   34 Dec 25 17:00 '[AF_INET6]::1:33956'
# cat *
[AF_INET6]2001:608:4::ce:c0f:54067

(the [AF_INET6] blob looks a bit confusing, but I guess this is the
way it has always been for the port-share status files - port numbers are
ugly as well, but indeed, this is a long-standing itch in our printing
routines)

I have adjusted From: and Signed-Off-By: of this patch to match the
later "v2" patches in the other series - full names are important for
us for correct attribution.

Your patch has been applied to the master branch.

commit 993449a3b6c0ae57c47844c9c19ea54633cbd914
Author: Corubba Smith
Date:   Sat Dec 14 20:56:56 2024 +0100

     Support IPv6 towards port-share proxy receiver

     Signed-off-by: Corubba Smith <corubba@gmx.de>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <dcc7e538-2035-4697-b306-10eb470632f3@gmx.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30115.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c
index 06bf91a8..d12ac9e6 100644
--- a/src/openvpn/ps.c
+++ b/src/openvpn/ps.c
@@ -414,7 +414,7 @@  proxy_connection_io_requeue(struct proxy_connection *pc, const int rwflags_new,
 static bool
 proxy_entry_new(struct proxy_connection **list,
                 struct event_set *es,
-                const struct sockaddr_in server_addr,
+                const struct openvpn_sockaddr server_addr,
                 const socket_descriptor_t sd_client,
                 struct buffer *initial_data,
                 const char *journal_dir)
@@ -425,12 +425,12 @@  proxy_entry_new(struct proxy_connection **list,
     struct proxy_connection *cp;

     /* connect to port share server */
-    if ((sd_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
+    if ((sd_server = socket(server_addr.addr.sa.sa_family, SOCK_STREAM, IPPROTO_TCP)) < 0)
     {
         msg(M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket");
         return false;
     }
-    status = openvpn_connect(sd_server, (const struct sockaddr *)  &server_addr, 5, NULL);
+    status = openvpn_connect(sd_server, &server_addr.addr.sa, 5, NULL);
     if (status)
     {
         msg(M_WARN, "PORT SHARE PROXY: connect to port-share server failed");
@@ -492,7 +492,7 @@  static bool
 control_message_from_parent(const socket_descriptor_t sd_control,
                             struct proxy_connection **list,
                             struct event_set *es,
-                            const struct sockaddr_in server_addr,
+                            const struct openvpn_sockaddr server_addr,
                             const int max_initial_buf,
                             const char *journal_dir)
 {
@@ -740,7 +740,7 @@  bad:
  * This is the main function for the port share proxy background process.
  */
 static void
-port_share_proxy(const struct sockaddr_in hostaddr,
+port_share_proxy(const struct openvpn_sockaddr hostaddr,
                  const socket_descriptor_t sd_control,
                  const int max_initial_buf,
                  const char *journal_dir)
@@ -822,7 +822,7 @@  port_share_open(const char *host,
 {
     pid_t pid;
     socket_descriptor_t fd[2];
-    struct sockaddr_in hostaddr;
+    struct openvpn_sockaddr hostaddr;
     struct port_share *ps;
     int status;
     struct addrinfo *ai;
@@ -836,11 +836,20 @@  port_share_open(const char *host,
      */

     status = openvpn_getaddrinfo(GETADDR_RESOLVE|GETADDR_FATAL,
-                                 host, port,  0, NULL, AF_INET, &ai);
+                                 host, port,  0, NULL, AF_UNSPEC, &ai);
     ASSERT(status==0);
-    hostaddr = *((struct sockaddr_in *) ai->ai_addr);
+    ASSERT(sizeof(hostaddr.addr) >= ai->ai_addrlen);
+    memcpy(&hostaddr.addr.sa, ai->ai_addr, ai->ai_addrlen);
     freeaddrinfo(ai);

+    if (msg_test(D_PS_PROXY_DEBUG))
+    {
+        struct gc_arena gc = gc_new();
+        dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: receiver will be %s",
+             print_openvpn_sockaddr(&hostaddr, &gc));
+        gc_free(&gc);
+    }
+
     /*
      * Make a socket for foreground and background processes
      * to communicate.