Skip to contentSkip to conversation

Change in openvpn[master]: proxy: factor out send code common with socks proxy

Openvpn-devel In review flichtenheld (Code Review) 2 participants 7 messages Oct 15, 2025 – Oct 16, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1760526572000.Ieb18101dcf8143efdae1c39bde356e7166cbefa5@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email

to review the following change.

Change subject: proxy: factor out send code common with socks proxy
......................................................................

proxy: factor out send code common with socks proxy

Change-Id Ieb18101dcf8143efdae1c39bde356e7166cbefa5

---
M src/openvpn/proxy.c
M src/openvpn/proxy.h
M src/openvpn/socks.c

3 files changed, 12 insertions(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1279/1

src/openvpn/proxy.c +6 -6
index 4205991..6402469 100644
@@ -184,13 +184,13 @@
     return true;
 }
 
-static bool
-send_line(socket_descriptor_t sd, const char *buf)
+bool
+proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len)
 {
-    const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL);
-    if (size != (ssize_t)strlen(buf))
+    const ssize_t size = openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL);
+    if (size != (ssize_t)buf_len)
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()");
+        msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()");
         return false;
     }
     return true;
@@ -204,7 +204,7 @@
     struct buffer buf = alloc_buf(strlen(src) + 3);
     ASSERT(buf_write(&buf, src, strlen(src)));
     ASSERT(buf_write(&buf, "\r\n", 3));
-    ret = send_line(sd, BSTR(&buf));
+    ret = proxy_send(sd, BSTR(&buf), BLEN(&buf));
     free_buf(&buf);
     return ret;
 }
src/openvpn/proxy.h +2 -0
index 3bfa687..d14725c 100644
@@ -83,6 +83,8 @@
 bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
                      struct timeval *timeout, volatile int *signal_received);
 
+bool proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len);
+
 bool establish_http_proxy_passthru(struct http_proxy_info *p,
                                    socket_descriptor_t sd, /* already open to proxy */
                                    const char *host,       /* openvpn server remote */
src/openvpn/socks.c +4 -18
index 9dc013e..7ecf01a 100644
@@ -123,12 +123,8 @@
                         creds.username, (int)strlen(creds.password), creds.password);
     ASSERT(sret >= 0 && sret <= sizeof(to_send));
 
-    ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
-
-    if (size != (ssize_t)strlen(to_send))
+    if (!proxy_send(sd, to_send, strlen(to_send)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO,
-            "socks_username_password_auth: TCP port write failed on send()");
         goto cleanup;
     }
 
@@ -166,7 +162,6 @@
 {
     uint8_t buf[2];
     int len = 0;
-    ssize_t size;
 
     /* VER = 5, NMETHODS = 1, METHODS = [0 (no auth)] */
     uint8_t method_sel[3] = { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
     {
         method_sel[2] = 0x02; /* METHODS = [2 (plain login)] */
     }
-    size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
-    if (size != sizeof(method_sel))
+    if (!proxy_send(sd, method_sel, sizeof(method_sel)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()");
         return false;
     }
 
@@ -380,18 +373,11 @@
     buf[5 + len] = (char)(port >> 8);
     buf[5 + len + 1] = (char)(port & 0xff);
 
+    if (!proxy_send(sd, buf, 5 + len + 2))
     {
-        size_t send_len = 5 + len + 2;
-        const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL);
-        if (size != (ssize_t)send_len)
-        {
-            msg(D_LINK_ERRORS | M_ERRNO,
-                "establish_socks_proxy_passthru: TCP port write failed on send()");
-            goto error;
-        }
+        goto error;
     }
 
-
     /* receive reply from Socks proxy and discard */
     if (!recv_socks_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received))
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email

to look at the new patch set (#2).

Change subject: proxy: factor out send code common with socks proxy
......................................................................

proxy: factor out send code common with socks proxy

Change-Id Ieb18101dcf8143efdae1c39bde356e7166cbefa5

---
M src/openvpn/proxy.c
M src/openvpn/proxy.h
M src/openvpn/socks.c

3 files changed, 14 insertions(+), 26 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1279/2

src/openvpn/proxy.c +8 -8
index 4205991..ff6ea5a 100644
@@ -184,13 +184,13 @@
     return true;
 }
 
-static bool
-send_line(socket_descriptor_t sd, const char *buf)
+bool
+proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len)
 {
-    const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL);
-    if (size != (ssize_t)strlen(buf))
+    const ssize_t size = openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL);
+    if (size != (ssize_t)buf_len)
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()");
+        msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()");
         return false;
     }
     return true;
@@ -201,10 +201,10 @@
 {
     bool ret;
 
-    struct buffer buf = alloc_buf(strlen(src) + 3);
+    struct buffer buf = alloc_buf(strlen(src) + 2);
     ASSERT(buf_write(&buf, src, strlen(src)));
-    ASSERT(buf_write(&buf, "\r\n", 3));
-    ret = send_line(sd, BSTR(&buf));
+    ASSERT(buf_write(&buf, "\r\n", 2));
+    ret = proxy_send(sd, BSTR(&buf), BLEN(&buf));
     free_buf(&buf);
     return ret;
 }
src/openvpn/proxy.h +2 -0
index 3bfa687..d14725c 100644
@@ -83,6 +83,8 @@
 bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
                      struct timeval *timeout, volatile int *signal_received);
 
+bool proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len);
+
 bool establish_http_proxy_passthru(struct http_proxy_info *p,
                                    socket_descriptor_t sd, /* already open to proxy */
                                    const char *host,       /* openvpn server remote */
src/openvpn/socks.c +4 -18
index 9dc013e..7ecf01a 100644
@@ -123,12 +123,8 @@
                         creds.username, (int)strlen(creds.password), creds.password);
     ASSERT(sret >= 0 && sret <= sizeof(to_send));
 
-    ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
-
-    if (size != (ssize_t)strlen(to_send))
+    if (!proxy_send(sd, to_send, strlen(to_send)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO,
-            "socks_username_password_auth: TCP port write failed on send()");
         goto cleanup;
     }
 
@@ -166,7 +162,6 @@
 {
     uint8_t buf[2];
     int len = 0;
-    ssize_t size;
 
     /* VER = 5, NMETHODS = 1, METHODS = [0 (no auth)] */
     uint8_t method_sel[3] = { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
     {
         method_sel[2] = 0x02; /* METHODS = [2 (plain login)] */
     }
-    size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
-    if (size != sizeof(method_sel))
+    if (!proxy_send(sd, method_sel, sizeof(method_sel)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()");
         return false;
     }
 
@@ -380,18 +373,11 @@
     buf[5 + len] = (char)(port >> 8);
     buf[5 + len + 1] = (char)(port & 0xff);
 
+    if (!proxy_send(sd, buf, 5 + len + 2))
     {
-        size_t send_len = 5 + len + 2;
-        const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL);
-        if (size != (ssize_t)send_len)
-        {
-            msg(D_LINK_ERRORS | M_ERRNO,
-                "establish_socks_proxy_passthru: TCP port write failed on send()");
-            goto error;
-        }
+        goto error;
     }
 
-
     /* receive reply from Socks proxy and discard */
     if (!recv_socks_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received))
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email )

Change subject: proxy: factor out send code common with socks proxy
......................................................................

Patch Set 2: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 16 Oct 2025 10:37:13 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#4 lore raw

PATCH v2 1/1 proxy: factor out send code common with socks proxy

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

Change-Id Ieb18101dcf8143efdae1c39bde356e7166cbefa5

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/proxy.c +8 -8
index 4205991..ff6ea5a 100644
@@ -184,13 +184,13 @@
     return true;
 }
 
-static bool
-send_line(socket_descriptor_t sd, const char *buf)
+bool
+proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len)
 {
-    const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL);
-    if (size != (ssize_t)strlen(buf))
+    const ssize_t size = openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL);
+    if (size != (ssize_t)buf_len)
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()");
+        msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()");
         return false;
     }
     return true;
@@ -201,10 +201,10 @@
 {
     bool ret;
 
-    struct buffer buf = alloc_buf(strlen(src) + 3);
+    struct buffer buf = alloc_buf(strlen(src) + 2);
     ASSERT(buf_write(&buf, src, strlen(src)));
-    ASSERT(buf_write(&buf, "\r\n", 3));
-    ret = send_line(sd, BSTR(&buf));
+    ASSERT(buf_write(&buf, "\r\n", 2));
+    ret = proxy_send(sd, BSTR(&buf), BLEN(&buf));
     free_buf(&buf);
     return ret;
 }
src/openvpn/proxy.h +2 -0
index 3bfa687..d14725c 100644
@@ -83,6 +83,8 @@
 bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
                      struct timeval *timeout, volatile int *signal_received);
 
+bool proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len);
+
 bool establish_http_proxy_passthru(struct http_proxy_info *p,
                                    socket_descriptor_t sd, /* already open to proxy */
                                    const char *host,       /* openvpn server remote */
src/openvpn/socks.c +4 -18
index 9dc013e..7ecf01a 100644
@@ -123,12 +123,8 @@
                         creds.username, (int)strlen(creds.password), creds.password);
     ASSERT(sret >= 0 && sret <= sizeof(to_send));
 
-    ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
-
-    if (size != (ssize_t)strlen(to_send))
+    if (!proxy_send(sd, to_send, strlen(to_send)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO,
-            "socks_username_password_auth: TCP port write failed on send()");
         goto cleanup;
     }
 
@@ -166,7 +162,6 @@
 {
     uint8_t buf[2];
     int len = 0;
-    ssize_t size;
 
     /* VER = 5, NMETHODS = 1, METHODS = [0 (no auth)] */
     uint8_t method_sel[3] = { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
     {
         method_sel[2] = 0x02; /* METHODS = [2 (plain login)] */
     }
-    size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
-    if (size != sizeof(method_sel))
+    if (!proxy_send(sd, method_sel, sizeof(method_sel)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()");
         return false;
     }
 
@@ -380,18 +373,11 @@
     buf[5 + len] = (char)(port >> 8);
     buf[5 + len + 1] = (char)(port & 0xff);
 
+    if (!proxy_send(sd, buf, 5 + len + 2))
     {
-        size_t send_len = 5 + len + 2;
-        const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL);
-        if (size != (ssize_t)send_len)
-        {
-            msg(D_LINK_ERRORS | M_ERRNO,
-                "establish_socks_proxy_passthru: TCP port write failed on send()");
-            goto error;
-        }
+        goto error;
     }
 
-
     /* receive reply from Socks proxy and discard */
     if (!recv_socks_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received))
     {
#5 lore raw

[Openvpn-devel] [PATCH applied] Re: proxy: factor out send code common with socks proxy

Change looks good (stare-at-code), client/server tests on linux excercising all the proxies also works fine. BB all green.

Your patch has been applied to the master branch.

commit 23d70b08a94b150f5df76449e2acbf7a1160146a

Author: Frank Lichtenheld
Date:   Thu Oct 16 12:37:22 2025 +0200
     proxy: factor out send code common with socks proxy

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279
     Message-Id: <[email protected]...>
     URL: https://sourceforge.net/p/openvpn/mailman/message/59247465/
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#6 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#3) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: proxy: factor out send code common with socks proxy
......................................................................

proxy: factor out send code common with socks proxy

Change-Id Ieb18101dcf8143efdae1c39bde356e7166cbefa5

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59247465/

---
M src/openvpn/proxy.c
M src/openvpn/proxy.h
M src/openvpn/socks.c

3 files changed, 14 insertions(+), 26 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/79/1279/3

src/openvpn/proxy.c +8 -8
index 4205991..ff6ea5a 100644
@@ -184,13 +184,13 @@
     return true;
 }
 
-static bool
-send_line(socket_descriptor_t sd, const char *buf)
+bool
+proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len)
 {
-    const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL);
-    if (size != (ssize_t)strlen(buf))
+    const ssize_t size = openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL);
+    if (size != (ssize_t)buf_len)
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()");
+        msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()");
         return false;
     }
     return true;
@@ -201,10 +201,10 @@
 {
     bool ret;
 
-    struct buffer buf = alloc_buf(strlen(src) + 3);
+    struct buffer buf = alloc_buf(strlen(src) + 2);
     ASSERT(buf_write(&buf, src, strlen(src)));
-    ASSERT(buf_write(&buf, "\r\n", 3));
-    ret = send_line(sd, BSTR(&buf));
+    ASSERT(buf_write(&buf, "\r\n", 2));
+    ret = proxy_send(sd, BSTR(&buf), BLEN(&buf));
     free_buf(&buf);
     return ret;
 }
src/openvpn/proxy.h +2 -0
index 3bfa687..d14725c 100644
@@ -83,6 +83,8 @@
 bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
                      struct timeval *timeout, volatile int *signal_received);
 
+bool proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len);
+
 bool establish_http_proxy_passthru(struct http_proxy_info *p,
                                    socket_descriptor_t sd, /* already open to proxy */
                                    const char *host,       /* openvpn server remote */
src/openvpn/socks.c +4 -18
index 9dc013e..7ecf01a 100644
@@ -123,12 +123,8 @@
                         creds.username, (int)strlen(creds.password), creds.password);
     ASSERT(sret >= 0 && sret <= sizeof(to_send));
 
-    ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
-
-    if (size != (ssize_t)strlen(to_send))
+    if (!proxy_send(sd, to_send, strlen(to_send)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO,
-            "socks_username_password_auth: TCP port write failed on send()");
         goto cleanup;
     }
 
@@ -166,7 +162,6 @@
 {
     uint8_t buf[2];
     int len = 0;
-    ssize_t size;
 
     /* VER = 5, NMETHODS = 1, METHODS = [0 (no auth)] */
     uint8_t method_sel[3] = { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
     {
         method_sel[2] = 0x02; /* METHODS = [2 (plain login)] */
     }
-    size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
-    if (size != sizeof(method_sel))
+    if (!proxy_send(sd, method_sel, sizeof(method_sel)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()");
         return false;
     }
 
@@ -380,18 +373,11 @@
     buf[5 + len] = (char)(port >> 8);
     buf[5 + len + 1] = (char)(port & 0xff);
 
+    if (!proxy_send(sd, buf, 5 + len + 2))
     {
-        size_t send_len = 5 + len + 2;
-        const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL);
-        if (size != (ssize_t)send_len)
-        {
-            msg(D_LINK_ERRORS | M_ERRNO,
-                "establish_socks_proxy_passthru: TCP port write failed on send()");
-            goto error;
-        }
+        goto error;
     }
 
-
     /* receive reply from Socks proxy and discard */
     if (!recv_socks_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received))
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#7 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email )

Change subject: proxy: factor out send code common with socks proxy
......................................................................

proxy: factor out send code common with socks proxy

Change-Id Ieb18101dcf8143efdae1c39bde356e7166cbefa5

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1279
Message-Id: <[email protected]...>
URL: https://sourceforge.net/p/openvpn/mailman/message/59247465/

---
M src/openvpn/proxy.c
M src/openvpn/proxy.h
M src/openvpn/socks.c

3 files changed, 14 insertions(+), 26 deletions(-)
src/openvpn/proxy.c +8 -8
index 4205991..ff6ea5a 100644
@@ -184,13 +184,13 @@
     return true;
 }
 
-static bool
-send_line(socket_descriptor_t sd, const char *buf)
+bool
+proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len)
 {
-    const ssize_t size = openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL);
-    if (size != (ssize_t)strlen(buf))
+    const ssize_t size = openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL);
+    if (size != (ssize_t)buf_len)
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "send_line: TCP port write failed on send()");
+        msg(D_LINK_ERRORS | M_ERRNO, "proxy_send: TCP port write failed on send()");
         return false;
     }
     return true;
@@ -201,10 +201,10 @@
 {
     bool ret;
 
-    struct buffer buf = alloc_buf(strlen(src) + 3);
+    struct buffer buf = alloc_buf(strlen(src) + 2);
     ASSERT(buf_write(&buf, src, strlen(src)));
-    ASSERT(buf_write(&buf, "\r\n", 3));
-    ret = send_line(sd, BSTR(&buf));
+    ASSERT(buf_write(&buf, "\r\n", 2));
+    ret = proxy_send(sd, BSTR(&buf), BLEN(&buf));
     free_buf(&buf);
     return ret;
 }
src/openvpn/proxy.h +2 -0
index 3bfa687..d14725c 100644
@@ -83,6 +83,8 @@
 bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
                      struct timeval *timeout, volatile int *signal_received);
 
+bool proxy_send(socket_descriptor_t sd, const void *buf, size_t buf_len);
+
 bool establish_http_proxy_passthru(struct http_proxy_info *p,
                                    socket_descriptor_t sd, /* already open to proxy */
                                    const char *host,       /* openvpn server remote */
src/openvpn/socks.c +4 -18
index 9dc013e..7ecf01a 100644
@@ -123,12 +123,8 @@
                         creds.username, (int)strlen(creds.password), creds.password);
     ASSERT(sret >= 0 && sret <= sizeof(to_send));
 
-    ssize_t size = openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGNAL);
-
-    if (size != (ssize_t)strlen(to_send))
+    if (!proxy_send(sd, to_send, strlen(to_send)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO,
-            "socks_username_password_auth: TCP port write failed on send()");
         goto cleanup;
     }
 
@@ -166,7 +162,6 @@
 {
     uint8_t buf[2];
     int len = 0;
-    ssize_t size;
 
     /* VER = 5, NMETHODS = 1, METHODS = [0 (no auth)] */
     uint8_t method_sel[3] = { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
     {
         method_sel[2] = 0x02; /* METHODS = [2 (plain login)] */
     }
-    size = openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
-    if (size != sizeof(method_sel))
+    if (!proxy_send(sd, method_sel, sizeof(method_sel)))
     {
-        msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write failed on send()");
         return false;
     }
 
@@ -380,18 +373,11 @@
     buf[5 + len] = (char)(port >> 8);
     buf[5 + len + 1] = (char)(port & 0xff);
 
+    if (!proxy_send(sd, buf, 5 + len + 2))
     {
-        size_t send_len = 5 + len + 2;
-        const ssize_t size = openvpn_send(sd, buf, send_len, MSG_NOSIGNAL);
-        if (size != (ssize_t)send_len)
-        {
-            msg(D_LINK_ERRORS | M_ERRNO,
-                "establish_socks_proxy_passthru: TCP port write failed on send()");
-            goto error;
-        }
+        goto error;
     }
 
-
     /* receive reply from Socks proxy and discard */
     if (!recv_socks_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received))
     {

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1279?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>