aboutsummaryrefslogtreecommitdiff
path: root/socket.c
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2008-06-11 10:48:50 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2008-06-11 10:48:50 +0000
commit4e9a51d78ffa0696cf7d14ff0292ca8863689f70 (patch)
tree0509760011393888bddef1bfc0330d6a5b670671 /socket.c
parentUpdated version to 2.1_rc7e. (diff)
downloadopenvpn-4e9a51d78ffa0696cf7d14ff0292ca8863689f70.tar.xz
Merged connection profiles from
http://svn.openvpn.net/projects/openvpn/test/conn git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2993 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c111
1 files changed, 11 insertions, 100 deletions
diff --git a/socket.c b/socket.c
index 3338990..881d130 100644
--- a/socket.c
+++ b/socket.c
@@ -403,77 +403,6 @@ link_socket_update_buffer_sizes (struct link_socket *ls, int rcvbuf, int sndbuf)
}
/*
- * Remote list code allows clients to specify a list of
- * potential remote server addresses.
- */
-
-static void
-remote_list_next (struct remote_list *l)
-{
- if (l)
- {
- if (l->no_advance && l->current >= 0)
- {
- l->no_advance = false;
- }
- else
- {
- int i;
- if (++l->current >= l->len)
- l->current = 0;
-
- dmsg (D_REMOTE_LIST, "REMOTE_LIST len=%d current=%d",
- l->len, l->current);
- for (i = 0; i < l->len; ++i)
- {
- dmsg (D_REMOTE_LIST, "[%d] %s:%d",
- i,
- l->array[i].hostname,
- l->array[i].port);
- }
- }
- }
-}
-
-void
-remote_list_randomize (struct remote_list *l)
-{
- int i;
- if (l)
- {
- for (i = 0; i < l->len; ++i)
- {
- const int j = get_random () % l->len;
- if (i != j)
- {
- struct remote_entry tmp;
- tmp = l->array[i];
- l->array[i] = l->array[j];
- l->array[j] = tmp;
- }
- }
- }
-}
-
-static const char *
-remote_list_host (const struct remote_list *rl)
-{
- if (rl)
- return rl->array[rl->current].hostname;
- else
- return NULL;
-}
-
-static int
-remote_list_port (const struct remote_list *rl)
-{
- if (rl)
- return rl->array[rl->current].port;
- else
- return 0;
-}
-
-/*
* SOCKET INITALIZATION CODE.
* Create a TCP/UDP socket
*/
@@ -813,7 +742,7 @@ socket_connect (socket_descriptor_t *sd,
struct openvpn_sockaddr *local,
bool bind_local,
struct openvpn_sockaddr *remote,
- struct remote_list *remote_list,
+ const bool connection_profiles_defined,
const char *remote_dynamic,
bool *remote_changed,
const int connect_retry_seconds,
@@ -865,7 +794,7 @@ socket_connect (socket_descriptor_t *sd,
openvpn_close_socket (*sd);
*sd = SOCKET_UNDEFINED;
- if (connect_retry_max > 0 && ++retry >= connect_retry_max)
+ if ((connect_retry_max > 0 && ++retry >= connect_retry_max) || connection_profiles_defined)
{
*signal_received = SIGUSR1;
goto done;
@@ -877,14 +806,6 @@ socket_connect (socket_descriptor_t *sd,
if (*signal_received)
goto done;
- if (remote_list)
- {
- remote_list_next (remote_list);
- remote_dynamic = remote_list_host (remote_list);
- remote->sa.sin_port = htons (remote_list_port (remote_list));
- *remote_changed = true;
- }
-
*sd = create_socket_tcp ();
if (bind_local)
socket_bind (*sd, local, "TCP Client");
@@ -996,7 +917,7 @@ resolve_remote (struct link_socket *sock,
int retry = 0;
bool status = false;
- if (remote_list_len (sock->remote_list) > 1 && sock->resolve_retry_seconds == RESOLV_RETRY_INFINITE)
+ if (sock->connection_profiles_defined && sock->resolve_retry_seconds == RESOLV_RETRY_INFINITE)
{
if (phase == 2)
flags |= (GETADDR_TRY_ONCE | GETADDR_FATAL);
@@ -1099,9 +1020,11 @@ link_socket_new (void)
/* bind socket if necessary */
void
link_socket_init_phase1 (struct link_socket *sock,
+ const bool connection_profiles_defined,
const char *local_host,
- struct remote_list *remote_list,
int local_port,
+ const char *remote_host,
+ int remote_port,
int proto,
int mode,
const struct link_socket *accept_from,
@@ -1129,18 +1052,14 @@ link_socket_init_phase1 (struct link_socket *sock,
int sndbuf,
unsigned int sockflags)
{
- const char *remote_host;
- int remote_port;
-
ASSERT (sock);
- sock->remote_list = remote_list;
- remote_list_next (remote_list);
- remote_host = remote_list_host (remote_list);
- remote_port = remote_list_port (remote_list);
+ sock->connection_profiles_defined = connection_profiles_defined;
sock->local_host = local_host;
sock->local_port = local_port;
+ sock->remote_host = remote_host;
+ sock->remote_port = remote_port;
#ifdef ENABLE_HTTP_PROXY
sock->http_proxy = http_proxy;
@@ -1198,10 +1117,6 @@ link_socket_init_phase1 (struct link_socket *sock,
/* the OpenVPN server we will use the proxy to connect to */
sock->proxy_dest_host = remote_host;
sock->proxy_dest_port = remote_port;
-
- /* this is needed so that connection retries will go to the proxy server,
- not the remote OpenVPN address */
- sock->remote_list = NULL;
}
#endif
#ifdef ENABLE_SOCKS
@@ -1218,10 +1133,6 @@ link_socket_init_phase1 (struct link_socket *sock,
/* the OpenVPN server we will use the proxy to connect to */
sock->proxy_dest_host = remote_host;
sock->proxy_dest_port = remote_port;
-
- /* this is needed so that connection retries will go to the proxy server,
- not the remote OpenVPN address */
- sock->remote_list = NULL;
}
#endif
else
@@ -1357,7 +1268,7 @@ link_socket_init_phase2 (struct link_socket *sock,
&sock->info.lsa->local,
sock->bind_local,
&sock->info.lsa->actual.dest,
- sock->remote_list,
+ sock->connection_profiles_defined,
remote_dynamic,
&remote_changed,
sock->connect_retry_seconds,
@@ -1405,7 +1316,7 @@ link_socket_init_phase2 (struct link_socket *sock,
&sock->info.lsa->local,
sock->bind_local,
&sock->info.lsa->actual.dest,
- NULL,
+ sock->connection_profiles_defined,
remote_dynamic,
&remote_changed,
sock->connect_retry_seconds,