From: "flichtenheld (Code Review)"
Date: Wed, 15 Oct 2025 16:21:22 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID: <1f7a4a87df3a55c4706369c8fe5a7d6c175cfab4-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="svwG9CxyvZw="; charset=UTF-8
Subject: [Openvpn-devel] [S] Change in openvpn[master]: proxy: factor out
send code common with socks proxy
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos
Cc: openvpn-devel
--svwG9CxyvZw=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
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=3Demail
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
Signed-off-by: Frank Lichtenheld
---
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
diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
index 4205991..ff6ea5a 100644
--- a/src/openvpn/proxy.c
+++ b/src/openvpn/proxy.c
@@ -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 =3D openvpn_send(sd, buf, strlen(buf), MSG_NOSIGNAL=
);
- if (size !=3D (ssize_t)strlen(buf))
+ const ssize_t size =3D openvpn_send(sd, buf, buf_len, MSG_NOSIGNAL);
+ if (size !=3D (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 =3D alloc_buf(strlen(src) + 3);
+ struct buffer buf =3D alloc_buf(strlen(src) + 2);
ASSERT(buf_write(&buf, src, strlen(src)));
- ASSERT(buf_write(&buf, "\r\n", 3));
- ret =3D send_line(sd, BSTR(&buf));
+ ASSERT(buf_write(&buf, "\r\n", 2));
+ ret =3D proxy_send(sd, BSTR(&buf), BLEN(&buf));
free_buf(&buf);
return ret;
}
diff --git a/src/openvpn/proxy.h b/src/openvpn/proxy.h
index 3bfa687..d14725c 100644
--- a/src/openvpn/proxy.h
+++ b/src/openvpn/proxy.h
@@ -83,6 +83,8 @@
bool proxy_recv_char(uint8_t *c, const char *name, socket_descriptor_t sd,
struct timeval *timeout, volatile int *signal_receive=
d);
+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 serv=
er remote */
diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c
index 9dc013e..7ecf01a 100644
--- a/src/openvpn/socks.c
+++ b/src/openvpn/socks.c
@@ -123,12 +123,8 @@
creds.username, (int)strlen(creds.password), creds=
.password);
ASSERT(sret >=3D 0 && sret <=3D sizeof(to_send));
- ssize_t size =3D openvpn_send(sd, to_send, strlen(to_send), MSG_NOSIGN=
AL);
-
- if (size !=3D (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 =3D 0;
- ssize_t size;
/* VER =3D 5, NMETHODS =3D 1, METHODS =3D [0 (no auth)] */
uint8_t method_sel[3] =3D { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
{
method_sel[2] =3D 0x02; /* METHODS =3D [2 (plain login)] */
}
- size =3D openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL=
);
- if (size !=3D sizeof(method_sel))
+ if (!proxy_send(sd, method_sel, sizeof(method_sel)))
{
- msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port write fail=
ed on send()");
return false;
}
@@ -380,18 +373,11 @@
buf[5 + len] =3D (char)(port >> 8);
buf[5 + len + 1] =3D (char)(port & 0xff);
+ if (!proxy_send(sd, buf, 5 + len + 2))
{
- size_t send_len =3D 5 + len + 2;
- const ssize_t size =3D openvpn_send(sd, buf, send_len, MSG_NOSIGNA=
L);
- if (size !=3D (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=3Demail
To unsubscribe, or for help writing mail filters, visit http://gerrit.openv=
pn.net/settings?usp=3Demail
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
--svwG9CxyvZw=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: plaisthos.
flichtenheld uploaded patch set #2 to this change.
<=
p>View C=
hange
proxy: factor out send code common with socks pr=
oxy
Change-Id: Ieb18101dcf8143efdae1c39bde356e7166cbefa5
Signed-o=
ff-by: Frank Lichtenheld <frank@...2641...>
---
M src/openvpn/p=
roxy.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
diff --=
git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
index 42059=
91..ff6ea5a 100644
--- a/src/openvpn/proxy.c
+++ b/src/openvpn/proxy.c
@@ -184,13 +184,13 @@
return true;
}
-static bool
-send_line(socket_descriptor_t sd, const cha=
r *buf)
+bool<=
br>+proxy_send(socket_descripto=
r_t sd, const void *buf, size_t buf_len)
{
- const ssize_t size =3D openvpn_se=
nd(sd, buf, strlen(buf), MSG_NOSIGNAL);
- if (size !=3D (ssize_t)strlen(buf))
+ const ssize_t size =3D openvpn_se=
nd(sd, buf, buf_len, MSG_NOSIGNAL);
+ if (size !=3D (ssize_t)buf_len)
{<=
/span>
- msg(D_LINK_ERR=
ORS | M_ERRNO, "send_line: TCP port write failed on send()");
+ msg(D_LINK_ERRO=
RS | M_ERRNO, "proxy_send: TCP port write failed on send()");
return false;
}
=
return true;
@@ -201,10 +201,10 @@
{<=
/span>
bool ret;
- struct buffer buf =3D alloc_buf(strlen(src) =
+ 3);
+ struct buf=
fer buf =3D alloc_buf(strlen(src) + 2);
ASSERT(buf_wri=
te(&buf, src, strlen(src)));
- ASSERT(buf_write(&buf, "\r\n", 3));
=
- ret =3D send_line(sd, BSTR(&=
amp;buf));
+ ASSER=
T(buf_write(&buf, "\r\n", 2));
+ ret =3D proxy_send(sd, BSTR(&buf), BLEN(&a=
mp;buf));
free_buf(&buf);
ret=
urn ret;
}
diff --git a/src/openvpn/proxy.=
h b/src/openvpn/proxy.h
index 3bfa687..d14725c 100644
--- a/src/openvpn/proxy.h
+++ b/src/openvpn/prox=
y.h
@@ -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);<=
/span>
+bo=
ol 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 t=
o proxy */
const char *=
host, /* openvpn server remote */
diff --git a/src/op=
envpn/socks.c b/src/openvpn/socks.c
index 9dc013e..7ecf01a =
100644
--- a/src/openvpn/socks.c
+++ b/src/=
openvpn/socks.c
@@ -123,12 +123,8 @@
=
creds.username, (int)strlen(creds.password), creds.passw=
ord);
ASSERT(sret >=3D 0 && sret <=3D si=
zeof(to_send));
- ssize_t size =3D openvpn_send(sd, to_send, strlen(to_send),=
MSG_NOSIGNAL);
-
- if (size !=3D (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;
}
<=
span>
@@ -166,7 +162,6 @@
{
uint8_t buf[2];
int len =3D 0;
- ssize_t size;
=
span>
/* VER =3D 5, NMETHODS =3D 1, METHODS =3D [0 (no auth)]=
*/
uint8_t method_sel[3] =3D { 0x05, 0x01, 0x00 };
@@ -174,10 +169,8 @@
{
=
method_sel[2] =3D 0x02; /* METHODS =3D [2 (plain login)] */<=
br> }
- si=
ze =3D openvpn_send(sd, method_sel, sizeof(method_sel), MSG_NOSIGNAL);
- if (size !=3D sizeof(m=
ethod_sel))
+ if (=
!proxy_send(sd, method_sel, sizeof(method_sel)))
{
- msg(D_LINK_ERRORS=
| M_ERRNO, "socks_handshake: TCP port write failed on send()");<=
/span>
return false;
}
@@ -380,18 +373,11 @@
buf[5 + len=
] =3D (char)(port >> 8);
buf[5 + len + 1] =3D (c=
har)(port & 0xff);
+ if (!proxy_send(sd, buf, 5 + len + 2))
<=
span> {
- si=
ze_t send_len =3D 5 + len + 2;
- const ssize_t size =3D openvpn_send(sd, buf, send_len, MSG=
_NOSIGNAL);
- if=
(size !=3D (ssize_t)send_len)
- {
- =
msg(D_LINK_ERRORS | M_ERRNO,
- "establish_socks_proxy_passthru: TCP p=
ort write failed on send()");
- goto error;
- }
+ goto error;
}
-
/* receiv=
e reply from Socks proxy and discard */
if (!recv_sock=
s_reply(sd, NULL, server_poll_timeout, &sig_info->signal_received))<=
/span>
{
To view, visit <=
a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1279?usp=3Demail">change 12=
79. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb18101dcf8143efdae1c39bde3=
56e7166cbefa5
Gerrit-Change-Number: 1279
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...=
.>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
=
--svwG9CxyvZw=--