summaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorJames Yonan <james@openvpn.net>2010-07-12 01:55:54 +0000
committerJames Yonan <james@openvpn.net>2010-07-12 01:55:54 +0000
commitf9b2ada0eece06158cc3ce6f6348bd431dfd7f0a (patch)
treeef5688a70b5d9f3d892f73091b20961160f1ad7f /socket.c
parent9c110e877c76bf44b7b327a1cb795c8422380b0f (diff)
downloadopenvpn-f9b2ada0eece06158cc3ce6f6348bd431dfd7f0a.tar.gz
openvpn-f9b2ada0eece06158cc3ce6f6348bd431dfd7f0a.tar.xz
openvpn-f9b2ada0eece06158cc3ce6f6348bd431dfd7f0a.zip
Implemented multi-address DNS expansion on the network field of route
commands. When only a single IP address is desired from a multi-address DNS expansion, use the first address rather than a random selection. Version 2.1.1l git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@6291 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/socket.c b/socket.c
index cf4ddb6..6f488e9 100644
--- a/socket.c
+++ b/socket.c
@@ -89,12 +89,26 @@ getaddr (unsigned int flags,
bool *succeeded,
volatile int *signal_received)
{
+ return getaddr_multi (flags, hostname, resolve_retry_seconds, succeeded, signal_received, NULL);
+}
+
+in_addr_t
+getaddr_multi (unsigned int flags,
+ const char *hostname,
+ int resolve_retry_seconds,
+ bool *succeeded,
+ volatile int *signal_received,
+ struct resolve_list *reslist)
+{
struct in_addr ia;
int status;
int sigrec = 0;
int msglevel = (flags & GETADDR_FATAL) ? M_FATAL : D_RESOLVE_ERRORS;
struct gc_arena gc = gc_new ();
+ if (reslist)
+ reslist->len = 0;
+
if (flags & GETADDR_RANDOMIZE)
hostname = hostname_randomize(hostname, &gc);
@@ -212,12 +226,28 @@ getaddr (unsigned int flags,
++n;
ASSERT (n >= 2);
- msg (D_RESOLVE_ERRORS, "RESOLVE: NOTE: %s resolves to %d addresses, choosing one by random",
+ msg (D_RESOLVE_ERRORS, "RESOLVE: NOTE: %s resolves to %d addresses",
hostname,
n);
/* choose address randomly, for basic load-balancing capability */
- ia.s_addr = *(in_addr_t *) (h->h_addr_list[get_random () % n]);
+ /*ia.s_addr = *(in_addr_t *) (h->h_addr_list[get_random () % n]);*
+
+ /* choose first address */
+ ia.s_addr = *(in_addr_t *) (h->h_addr_list[0]);
+
+ if (reslist)
+ {
+ int i;
+ for (i = 0; i < n && i < SIZE(reslist->data); ++i)
+ {
+ in_addr_t a = *(in_addr_t *) (h->h_addr_list[i]);
+ if (flags & GETADDR_HOST_ORDER)
+ a = ntohl(a);
+ reslist->data[i] = a;
+ }
+ reslist->len = i;
+ }
}
}