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/+/1165?usp=email
to review the following change.
Change subject: socks: factor out socks_proxy_recv_char()
......................................................................
socks: factor out socks_proxy_recv_char()
This is basically identical code duplicated three
times.
Change-Id: I6e848df8104b6e3a6e2c3245ece91a20e473fb40
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/socks.c
1 file changed, 51 insertions(+), 121 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/1165/1
diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c
index 481d3fb..1102421 100644
--- a/src/openvpn/socks.c
+++ b/src/openvpn/socks.c
@@ -81,6 +81,54 @@
}
static bool
+socks_proxy_recv_char(char *c, const char *name, socket_descriptor_t sd,
+ struct event_timeout *server_poll_timeout,
+ volatile int *signal_received)
+{
+ fd_set reads;
+ FD_ZERO(&reads);
+ openvpn_fd_set(sd, &reads);
+
+ struct timeval tv;
+ tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout);
+ tv.tv_usec = 0;
+
+ const int status = select(sd + 1, &reads, NULL, NULL, &tv);
+
+ get_signal(signal_received);
+ if (*signal_received)
+ {
+ return false;
+ }
+
+ /* timeout? */
+ if (status == 0)
+ {
+ msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read timeout expired",
name);
+ return false;
+ }
+
+ /* error */
+ if (status < 0)
+ {
+ msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read failed on select()",
name);
+ return false;
+ }
+
+ /* read single char */
+ const ssize_t size = recv(sd, c, 1, MSG_NOSIGNAL);
+
+ /* error? */
+ if (size != 1)
+ {
+ msg(D_LINK_ERRORS | M_ERRNO, "%s: TCP port read failed on recv()",
name);
+ return false;
+ }
+
+ return true;
+}
+
+static bool
socks_username_password_auth(struct socks_proxy_info *p, socket_descriptor_t
sd,
struct event_timeout *server_poll_timeout,
volatile int *signal_received)
@@ -121,52 +169,12 @@
while (len < 2)
{
- int status;
- ssize_t size;
- fd_set reads;
- struct timeval tv;
char c;
- FD_ZERO(&reads);
- openvpn_fd_set(sd, &reads);
- tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout);
- tv.tv_usec = 0;
-
- status = select(sd + 1, &reads, NULL, NULL, &tv);
-
- get_signal(signal_received);
- if (*signal_received)
+ if (!socks_proxy_recv_char(&c, __func__, sd, server_poll_timeout,
signal_received))
{
goto cleanup;
}
-
- /* timeout? */
- if (status == 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO,
- "socks_username_password_auth: TCP port read timeout expired");
- goto cleanup;
- }
-
- /* error */
- if (status < 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO,
- "socks_username_password_auth: TCP port read failed on
select()");
- goto cleanup;
- }
-
- /* read single char */
- size = recv(sd, &c, 1, MSG_NOSIGNAL);
-
- /* error? */
- if (size != 1)
- {
- msg(D_LINK_ERRORS | M_ERRNO,
- "socks_username_password_auth: TCP port read failed on
recv()");
- goto cleanup;
- }
-
/* store char in buffer */
buf[len++] = c;
}
@@ -208,49 +216,12 @@
while (len < 2)
{
- int status;
- ssize_t size;
- fd_set reads;
- struct timeval tv;
char c;
- FD_ZERO(&reads);
- openvpn_fd_set(sd, &reads);
- tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout);
- tv.tv_usec = 0;
-
- status = select(sd + 1, &reads, NULL, NULL, &tv);
-
- get_signal(signal_received);
- if (*signal_received)
+ if (!socks_proxy_recv_char(&c, __func__, sd, server_poll_timeout,
signal_received))
{
return false;
}
-
- /* timeout? */
- if (status == 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read
timeout expired");
- return false;
- }
-
- /* error */
- if (status < 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read
failed on select()");
- return false;
- }
-
- /* read single char */
- size = recv(sd, &c, 1, MSG_NOSIGNAL);
-
- /* error? */
- if (size != 1)
- {
- msg(D_LINK_ERRORS | M_ERRNO, "socks_handshake: TCP port read
failed on recv()");
- return false;
- }
-
/* store char in buffer */
buf[len++] = c;
}
@@ -317,54 +288,13 @@
while (len < 4 + alen + 2)
{
- int status;
- ssize_t size;
- fd_set reads;
- struct timeval tv;
char c;
- FD_ZERO(&reads);
- openvpn_fd_set(sd, &reads);
- tv.tv_sec = get_server_poll_remaining_time(server_poll_timeout);
- tv.tv_usec = 0;
-
- status = select(sd + 1, &reads, NULL, NULL, &tv);
-
- get_signal(signal_received);
- if (*signal_received)
+ if (!socks_proxy_recv_char(&c, __func__, sd, server_poll_timeout,
signal_received))
{
return false;
}
- /* timeout? */
- if (status == 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read
timeout expired");
- return false;
- }
-
- /* error */
- if (status < 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read
failed on select()");
- return false;
- }
-
- /* read single char */
- size = recv(sd, &c, 1, MSG_NOSIGNAL);
-
- /* error? */
- if (size < 0)
- {
- msg(D_LINK_ERRORS | M_ERRNO, "recv_socks_reply: TCP port read
failed on recv()");
- return false;
- }
- else if (size == 0)
- {
- msg(D_LINK_ERRORS, "ERROR: recv_socks_reply: empty response from
socks server");
- return false;
- }
-
if (len == 3)
{
atyp = c;
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1165?usp=email
To unsubscribe, or for help writing mail filters, visit
http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6e848df8104b6e3a6e2c3245ece91a20e473fb40
Gerrit-Change-Number: 1165
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel