From: "ordex (Code Review)" Date: Wed, 15 Nov 2023 13:45:13 +0000 References: Reply-To: a@...2181..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <13d3eb64cbd8db5e2a30be372713eb8710bfa4ea-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="g9BEIKiCE1g="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: allow user to specify 'local' multiple times in config files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --g9BEIKiCE1g= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=3Demail to review the following change. Change subject: allow user to specify 'local' multiple times in config files ...................................................................... allow user to specify 'local' multiple times in config files It is now possible to specify 'local' multiple times in a server config to let it listen on multiple sockets (address:port) of the same protocol. Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764 Signed-off-by: Antonio Quartulli --- M src/openvpn/init.c M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/socket.c 4 files changed, 171 insertions(+), 39 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/436/1 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index f8dd01f..659c9e3 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -745,7 +745,7 @@ init_connection_list(c); - c->c1.link_sockets_num =3D 1; + c->c1.link_sockets_num =3D c->options.ce.local_list->len; do_link_socket_addr_new(c); @@ -3821,8 +3821,8 @@ /* init each socket with its specific port */ link_socket_init_phase1(c->c2.link_sockets[i], - c->options.ce.local, - c->options.ce.local_port, + c->options.ce.local_list->array[i]->local, + c->options.ce.local_list->array[i]->port, c->options.ce.remote, c->options.ce.remote_port, c->c1.dns_cache, @@ -3836,7 +3836,7 @@ #ifdef ENABLE_DEBUG c->options.gremlin, #endif - c->options.ce.bind_local, + c->options.ce.local_list->array[i]->bind_l= ocal, c->options.ce.remote_float, &c->c1.link_socket_addrs[i], c->options.ipchange, @@ -4978,6 +4978,7 @@ if (dest->mode =3D=3D CM_CHILD_UDP) { ASSERT(!dest->c2.link_sockets); + ASSERT(dest->options.ce.local_list); /* inherit buffers */ dest->c2.buffers =3D src->c2.buffers; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index b88fea9..9611423 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -124,7 +124,13 @@ "--version : Show copyright and version information.\n" "\n" "Tunnel Options:\n" - "--local host : Local host name or ip address. Implies --bind.\n" + "--local host|* [port] : Local host name or ip address and port. '*' c= an be used\n" + " as hostname and means 'any host' (openvpn wil= l listen on\n" + " what is returned by the OS). Implies --bind.\= n" + " 0.0.0.0 or :: can be used to specifically ope= n a socket\n" + " listening on any IPv4 or IPv6 address respect= ively.\n" + " The user can specify multiple --local entries= to have\n" + " a server listen on multiple sockets at the sa= me time.\n" "--remote host [port] : Remote host name or ip address.\n" "--remote-random : If multiple --remote options specified, choose one = randomly.\n" "--remote-random-hostname : Add a random string to remote DNS name.\n" @@ -982,8 +988,9 @@ const int i) { setenv_str_i(es, "proto", proto2ascii(e->proto, e->af, false), i); - setenv_str_i(es, "local", e->local, i); - setenv_str_i(es, "local_port", e->local_port, i); + /* expected to befor single socket contexts only */ + setenv_str_i(es, "local", e->local_list->array[0]->local, i); + setenv_str_i(es, "local_port", e->local_list->array[0]->port, i); setenv_str_i(es, "remote", e->remote, i); setenv_str_i(es, "remote_port", e->remote_port, i); @@ -1701,8 +1708,12 @@ show_connection_entry(const struct connection_entry *o) { msg(D_SHOW_PARMS, " proto =3D %s", proto2ascii(o->proto, o->af, false= )); - SHOW_STR(local); - SHOW_STR(local_port); + msg(D_SHOW_PARMS, " Local Sockets:"); + for (int i =3D 0; i < o->local_list->len; i++) + { + msg(D_SHOW_PARMS, " [%s]:%s", o->local_list->array[i]->local, + o->local_list->array[i]->port); + } SHOW_STR(remote); SHOW_STR(remote_port); SHOW_BOOL(remote_float); @@ -2151,6 +2162,37 @@ #endif /* ifdef ENABLE_MANAGEMENT */ +static struct local_list * +alloc_local_list_if_undef(struct connection_entry *ce, struct gc_arena *gc) +{ + if (!ce->local_list) + { + ALLOC_OBJ_CLEAR_GC(ce->local_list, struct local_list, gc); + } + return ce->local_list; +} + +static struct local_entry * +alloc_local_entry(struct connection_entry *ce, const int msglevel, + struct gc_arena *gc) +{ + struct local_list *l =3D alloc_local_list_if_undef(ce, gc); + struct local_entry *e; + + if (l->len >=3D CONNECTION_LIST_SIZE) + { + msg(msglevel, "Maximum number of 'local' options (%d) exceeded", + CONNECTION_LIST_SIZE); + + return NULL; + } + + ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc); + l->array[l->len++] =3D e; + + return e; +} + static struct connection_list * alloc_connection_list_if_undef(struct options *options) { @@ -2343,6 +2385,15 @@ "--proto tcp-server or --proto tcp-client"); } + /* + * Sanity check on daemon mode + */ + + if (ce->remote && ce->local_list->len > 1) + { + msg(M_USAGE, "multiple --local do not make sense in Client mode"); + } + if (options->lladdr && dev !=3D DEV_TYPE_TAP) { msg(M_USAGE, "--lladdr can only be used in --dev tap mode"); @@ -2368,13 +2419,6 @@ * Sanity check on --local, --remote, and --ifconfig */ - if (proto_is_net(ce->proto) - && string_defined_equal(ce->local, ce->remote) - && string_defined_equal(ce->local_port, ce->remote_port)) - { - msg(M_USAGE, "--remote and --local addresses are the same"); - } - if (string_defined_equal(ce->remote, options->ifconfig_local) || string_defined_equal(ce->remote, options->ifconfig_remote_netma= sk)) { @@ -2383,13 +2427,6 @@ "addresses"); } - if (string_defined_equal(ce->local, options->ifconfig_local) - || string_defined_equal(ce->local, options->ifconfig_remote_netmas= k)) - { - msg(M_USAGE, - "--local addresses must be distinct from --ifconfig addresses"= ); - } - if (string_defined_equal(options->ifconfig_local, options->ifconfig_remote_netmask)) { @@ -2402,12 +2439,6 @@ msg(M_USAGE, "--bind and --nobind can't be used together"); } - if (ce->local && !ce->bind_local) - { - msg(M_USAGE, - "--local and --nobind don't make sense when used together"); - } - if (ce->local_port_defined && !ce->bind_local) { msg(M_USAGE, @@ -2419,6 +2450,29 @@ msg(M_USAGE, "--nobind doesn't make sense unless used with --remot= e"); } + for (int i =3D 0; i < ce->local_list->len; i++) + { + struct local_entry *le =3D ce->local_list->array[i]; + + if (proto_is_net(ce->proto) + && string_defined_equal(le->local, ce->remote) + && string_defined_equal(le->port, ce->remote_port)) + { + msg(M_USAGE, "--remote and a --local addresses are the same"); + } + + if (string_defined_equal(le->local, options->ifconfig_local) + || string_defined_equal(le->local, options->ifconfig_remote_ne= tmask)) + { + msg(M_USAGE, "--local addresses must be distinct from --ifconf= ig addresses"); + } + + if (le->local && !ce->bind_local) + { + msg(M_USAGE, "--local and --nobind don't make sense when used = together"); + } + } + /* * Check for consistency of management options */ @@ -3112,7 +3166,7 @@ } /* an option is present that requires local bind to enabled */ - bool need_bind =3D ce->local || ce->local_port_defined || ce->bind_def= ined; + bool need_bind =3D ce->local_port_defined || ce->bind_defined; /* socks proxy is enabled */ bool uses_socks =3D ce->proto =3D=3D PROTO_UDP && ce->socks_proxy_serv= er; @@ -3125,6 +3179,11 @@ ce->bind_local =3D false; } + if (ce->proto =3D=3D PROTO_UDP && ce->socks_proxy_server && !ce->local= _list && !ce->local_port_defined && !ce->bind_defined) + { + ce->bind_local =3D false; + } + if (!ce->bind_local) { ce->local_port =3D NULL; @@ -3245,6 +3304,16 @@ } } +static void +options_postprocess_mutate_le(struct options *o, struct local_entry *le) +{ + /* use the global port if none is specified */ + if (!le->port) + { + le->port =3D o->ce.local_port; + } +} + #ifdef _WIN32 /* If iservice is in use, we need def1 method for redirect-gateway */ static void @@ -3691,6 +3760,29 @@ options_postprocess_mutate_ce(o, o->connection_list->array[i]); } + if (o->ce.local_list) + { + for (i =3D 0; i < o->ce.local_list->len; i++) + { + options_postprocess_mutate_le(o, o->ce.local_list->array[i]); + } + } + else + { + /* if no 'local' directive was specified, convert the global port + * setting to a listen entry */ + struct local_entry *e =3D alloc_local_entry(&o->ce, M_USAGE, &o->g= c); + ASSERT(e); + e->port =3D o->ce.local_port; + e->bind_local =3D o->ce.bind_local; + } + + /* use the same listen list for every outgoing connection */ + for (i =3D 0; i < o->connection_list->len; ++i) + { + o->connection_list->array[i]->local_list =3D o->ce.local_list; + } + if (o->tls_server) { /* Check that DH file is specified, or explicitly disabled */ @@ -6072,10 +6164,29 @@ VERIFY_PERMISSION(OPT_P_UP); options->ifconfig_nowarn =3D true; } - else if (streq(p[0], "local") && p[1] && !p[2]) + else if (streq(p[0], "local") && p[1] && !p[3]) { + struct local_entry *e; + VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); - options->ce.local =3D p[1]; + + e =3D alloc_local_entry(&options->ce, M_USAGE, &options->gc); + ASSERT(e); + + /* '*' is treated as 'ask the system to get some socket', + * therefore force binding on a particular address only when + * actually specified. */ + if (strcmp(p[1], "*") !=3D 0) + { + e->local =3D p[1]; + e->bind_local =3D true; + } + + if (p[2]) + { + e->port =3D p[2]; + e->bind_local =3D true; + } } else if (streq(p[0], "remote-random") && !p[1]) { diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 5a37316..747ed56 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -94,14 +94,21 @@ #error "At least one of OpenSSL or mbed TLS needs to be defined." #endif +struct local_entry +{ + const char *local; + const char *port; + bool bind_local; +}; + struct connection_entry { + struct local_list *local_list; int proto; sa_family_t af; const char *local_port; bool local_port_defined; const char *remote_port; - const char *local; const char *remote; bool remote_float; bool bind_defined; @@ -179,6 +186,12 @@ #define CONNECTION_LIST_SIZE 64 +struct local_list +{ + int len; + struct local_entry *array[CONNECTION_LIST_SIZE]; +}; + struct connection_list { int capacity; diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 17bd263..5d9e111 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -342,7 +342,7 @@ void do_preresolve(struct context *c) { - int i; + int i, j; struct connection_list *l =3D c->options.connection_list; const unsigned int preresolve_flags =3D GETADDR_RESOLVE |GETADDR_UPDATE_MANAGEMENT_STATE @@ -416,12 +416,19 @@ } } - if (ce->bind_local) + flags |=3D GETADDR_PASSIVE; + flags &=3D ~GETADDR_RANDOMIZE; + + for (j =3D 0; j < ce->local_list->len; j++) { - flags |=3D GETADDR_PASSIVE; - flags &=3D ~GETADDR_RANDOMIZE; - status =3D do_preresolve_host(c, ce->local, ce->local_port, - ce->af, flags); + struct local_entry *le =3D ce->local_list->array[j]; + + if (!le->local) + { + continue; + } + + status =3D do_preresolve_host(c, le->local, le->port, ce->af, = flags); if (status !=3D 0) { goto err; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/436?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20adde09529e2764 Gerrit-Change-Number: 436 Gerrit-PatchSet: 1 Gerrit-Owner: ordex Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --g9BEIKiCE1g= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

ordex would like plaisthos and flichtenheld to review t= his change.

Vi= ew Change

allow user to specify 'local' multiple times in confi=
g files

It is now possible to specify 'local' multiple times= in a server
config to let it listen on multiple sockets (address:port) = of
the same protocol.

Change-Id: I4d1c96662c5a8c750d883e3b20adde0= 9529e2764
Signed-off-by: Antonio Quartulli <a@...2181...>
---M src/openvpn/init.c
M src/openvpn/options.c
M src/openvpn/options.= h
M src/openvpn/socket.c
4 files changed, 171 insertions(+), 39 delet= ions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chan=
ges/36/436/1
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index f8dd01f..659c9e3 100644
--- a/src/open= vpn/init.c
+++ b/src/openvpn/init.c
@@ -745= ,7 +745,7 @@

init_connection_list(c)= ;

- = c->c1.link_sockets_num =3D 1;
+ c->c1.link_sockets_num =3D c->options.ce.local_lis= t->len;

do_link_socket_addr_new(c= );

@@ -3821,8 +3821,8 @@
=
/* init each socket with its specific port */
link_socket_init_phase1(c->c2.link_sockets[i],
- = c->options.ce.local,
- c->options.ce.local_port,
+ = c->options.ce.local_list->array[i]->local,
+ c-&= gt;options.ce.local_list->array[i]->port,

= c->options.ce.remote,
= c->options.ce.remote_port,
= c->c1.dns_cache,
@@ -3836,7 +38= 36,7 @@
#ifdef ENABLE_DEBUG
= c->options.gremlin,
#endif- = c->options.ce.bind_local,
+ c->options.ce.local_list->a= rray[i]->bind_local,
c-= >options.ce.remote_float,
= &c->c1.link_socket_addrs[i],
= c->options.ipchange,
@@ -4978,6 +4978,7 @@<= /span>
if (dest->mode =3D=3D CM_CHILD_UDP)
{

ASSERT(!dest->c2.link_sockets);<= br>+ ASSERT(dest->opt= ions.ce.local_list);

/* inherit = buffers */
dest->c2.buffers =3D src->c2.buff= ers;
diff --git a/src/openvpn/options.c b/src/openvpn/optio= ns.c
index b88fea9..9611423 100644
--- a/sr= c/openvpn/options.c
+++ b/src/openvpn/options.c
<= span>@@ -124,7 +124,13 @@

"--version : Show= copyright and version information.\n"
"\n&q= uot;
"Tunnel Options:\n"
- "--local host : Local host na= me or ip address. Implies --bind.\n"
+ "--local host|* [port] : Local host name or = ip address and port. '*' can be used\n"
+ " as host= name and means 'any host' (openvpn will listen on\n"+ " = what is returned by the OS). Implies --bind.\n"
+ " 0.0= .0.0 or :: can be used to specifically open a socket\n"
+ " = listening on any IPv4 or IPv6 address respectively.\n"

+ " T= he user can specify multiple --local entries to have\n"

+ " = a server listen on multiple sockets at the same time.\n"
"--remote host [port] : Remote host name or ip address.\n"= ;
"--remote-random : If multiple --remote options= specified, choose one randomly.\n"
"--remot= e-random-hostname : Add a random string to remote DNS name.\n"<= br>@@ -982,8 +988,9 @@
const= int i)
{
setenv_str_i(es, "prot= o", proto2ascii(e->proto, e->af, false), i);
- setenv_str_i(es, "local", e= ->local, i);
- se= tenv_str_i(es, "local_port", e->local_port, i);
+ /* expected to befor single so= cket contexts only */
+ setenv_str_i(es, "local", e->local_list->array[0]->= ;local, i);
+ sete= nv_str_i(es, "local_port", e->local_list->array[0]->port= , i);
setenv_str_i(es, "remote", e->remot= e, i);
setenv_str_i(es, "remote_port", e->= ;remote_port, i);

@@ -1701,8 +1708,12 @@<= /span>
show_connection_entry(const struct connection_entry *o)
{
msg(D_SHOW_PARMS, " proto =3D %= s", proto2ascii(o->proto, o->af, false));
- SHOW_STR(local);
- SHOW_STR(local_port);
+ msg(D_SHOW_PARMS, " Local S= ockets:");
+ = for (int i =3D 0; i < o->local_list->len; i++)
+ {
+ msg(D_SHOW_PARMS, " [%s]:%s", o-= >local_list->array[i]->local,
+ o->local_list->array[i]->port);

+ }
= SHOW_STR(remote);
SHOW_STR(remote_port); SHOW_BOOL(remote_float);
@@ -2151,6 +2162,37 @@=

#endif /* ifdef ENABLE_MANAGEMENT */

+stat= ic struct local_list *
+{
+ if (!ce->local_list)
=
+ {
+ ALLOC_OBJ_CLEAR_GC(ce->local_= list, struct local_list, gc);
+ }
+ = return ce->local_list;
+}
+
<= span style=3D"color: hsl(120, 100%, 40%);">+static struct local_entry *
+alloc_local_entry(struc= t connection_entry *ce, const int msglevel,
+ struct gc_arena *gc)
+{
+ struct local_list *l =3D alloc_local_list_if_u= ndef(ce, gc);
+ st= ruct local_entry *e;
= +
+ if (l->len = >=3D CONNECTION_LIST_SIZE)
+ {
+ = msg(msglevel, "Maximum number of 'local' options (%d) exce= eded",
+ = CONNECTION_LIST_SIZE);
+
+ retu= rn NULL;
+ }
+
+ ALLOC_OBJ_CLEAR_GC(e, struct local_entry= , gc);
+ l->arr= ay[l->len++] =3D e;
+ return e;

+}
+
static struct connecti= on_list *
alloc_connection_list_if_undef(struct options *o= ptions)
{
@@ -2343,6 +2385,15 @@ "--proto tcp-server or --proto tcp-client");<= /span>
}

+ /*
+ * Sanity check on daemon mode
+ */
+
+ if (= ce->remote && ce->local_list->len > 1)
+ {
+ msg(M_USAGE, "multiple --local do not= make sense in Client mode");
+ }
= +
if (options->lladdr && dev !=3D DEV_TYPE_= TAP)
{
msg(M_USAGE, "--l= laddr can only be used in --dev tap mode");
@@ -2368,1= 3 +2419,6 @@
* Sanity check on --local, --remote, and= --ifconfig
*/

- if (proto_is_net(ce->proto)<= br>- && string_def= ined_equal(ce->local, ce->remote)
- && string_defined_equal(ce->local_port= , ce->remote_port))
= - {
- msg(M_U= SAGE, "--remote and --local addresses are the same");
<= span style=3D"color: hsl(0, 100%, 40%);">- }

-
if (string_defined_equal(ce= ->remote, options->ifconfig_local)
|| string= _defined_equal(ce->remote, options->ifconfig_remote_netmask))<= br> {
@@ -2383,13 +2427,6 @@
= "addresses");
}

- if (string_defined_= equal(ce->local, options->ifconfig_local)
- || string_defined_equal(ce->local, opt= ions->ifconfig_remote_netmask))
- {
- = msg(M_USAGE,
- = "--local addresses must be distinct from --ifconfig addresses&= quot;);
- }-
if (stri= ng_defined_equal(options->ifconfig_local,
= options->ifconfig_remote_netmask))
= {
@@ -2402,12 +2439,6 @@
msg(M_USA= GE, "--bind and --nobind can't be used together");
= }

- if (ce->local && !ce->bind_local)
- {

- msg(M_USAGE,
- "--local and --nobind don't make= sense when used together");
- }
-
if (ce->local_port_defined && !ce->bind_loc= al)
{
msg(M_USAGE,
= @@ -2419,6 +2450,29 @@
msg(M_USAGE, "--= nobind doesn't make sense unless used with --remote");
<= span> }


+ for (int i =3D 0; i < ce->local_list->len; i++)

+ {
+ struct local_entry *le =3D ce-= >local_list->array[i];
+
+ if= (proto_is_net(ce->proto)
+ && string_defined_equal(le->local, ce->r= emote)
+ &= amp;& string_defined_equal(le->port, ce->remote_port))
= + {
+ msg(M_USAGE, "--remote = and a --local addresses are the same");
+ }
+
+ = if (string_defined_equal(le->local, options->ifconfig_local)
+ || string_de= fined_equal(le->local, options->ifconfig_remote_netmask))
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ msg(M_USAGE, "--local ad= dresses must be distinct from --ifconfig addresses");
+ }
+
+ if (le->local && !ce->bind_local)+ {
+ msg(M_USAGE, "--local = and --nobind don't make sense when used together");
+ }
+ }
+
/*
* Check for= consistency of management options
*/
@@ -3112,7 +3166,7 @@
}

<= span> /* an option is present that requires local bind to enabled */
- bool need_bind =3D c= e->local || ce->local_port_defined || ce->bind_defined;
= + bool need_bind =3D ce->= local_port_defined || ce->bind_defined;

/* socks proxy is enabled */
bool uses_socks = =3D ce->proto =3D=3D PROTO_UDP && ce->socks_proxy_server;
@@ -3125,6 +3179,11 @@
ce->bind_lo= cal =3D false;
}

+ if (ce->proto =3D=3D PROTO_UDP &= amp;& ce->socks_proxy_server && !ce->local_list &&= ; !ce->local_port_defined && !ce->bind_defined)
+ {

+ ce->bind_local =3D false;
= + }
+
if (!ce->bind_local= )
{
ce->local_port =3D NUL= L;
@@ -3245,6 +3304,16 @@
}
= }

+static void
+o= ptions_postprocess_mutate_le(struct options *o, struct local_entry *le)
+{
+ /* use the global port if none is spe= cified */
+ if (!l= e->port)
+ {
+ le->port = =3D o->ce.local_port;
+ }
+}<= br>+
#ifdef _W= IN32
/* If iservice is in use, we need def1 method for red= irect-gateway */
static void
@@ -3691,6 +3= 760,29 @@
options_postprocess_mutate_ce(o, o->c= onnection_list->array[i]);
}

+ if (o->ce.local_l= ist)
+ {+ for (i =3D 0; i < = o->ce.local_list->len; i++)
+ {
+ options_postprocess_mutate_le(o, o->ce.local_list->ar= ray[i]);
+ }
+ }
+ else

+ {
+ /* if no 'local' directive was specified, co= nvert the global port
+ * setting to a listen entry */
+ struct local_entry *e =3D alloc_local_entry(&= amp;o->ce, M_USAGE, &o->gc);
+ ASSERT(e);
+ e->port =3D o->ce.local_port;
+ e->bind_local =3D o-&g= t;ce.bind_local;
+ = }
+
+ /* use the same listen list for = every outgoing connection */
+ for (i =3D 0; i < o->connection_list->len; ++i)

+ {
+ o->connection_list->array= [i]->local_list =3D o->ce.local_list;
+ }
+
if (o->tls_server)
= {
/* Check that DH file is specified, or explicitl= y disabled */
@@ -6072,10 +6164,29 @@
= VERIFY_PERMISSION(OPT_P_UP);
options->ifcon= fig_nowarn =3D true;
}
- else if (streq(p[0], "local") &&= ; p[1] && !p[2])
+ else if (streq(p[0], "local") && p[1] &&= !p[3])
{
+ struct local_entry *e;
+
VERIFY_PERMISSION(OPT_P_GEN= ERAL|OPT_P_CONNECTION);
- options->ce.local =3D p[1];
+
+ e =3D alloc_local_entry(&options->ce, M_USAGE, &option= s->gc);
+ A= SSERT(e);
++ /* '*' is tre= ated as 'ask the system to get some socket',
+ * therefore force binding on a p= articular address only when
+ * actually specified. */
+ if (strcmp(p[1], "*") !=3D 0)
+ {
+ e->local =3D p[1];
+ e->bin= d_local =3D true;
+ = }
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (p[2])

+ {
+ e->port =3D p[2];+ e->bind_local= =3D true;
+ }=
}
else if (streq(p[0], "rem= ote-random") && !p[1])
{
= diff --git a/src/openvpn/options.h b/src/openvpn/options.h
= index 5a37316..747ed56 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h
@@ -94,14 +94,21= @@
#error "At least one of OpenSSL or mbed TLS needs= to be defined."
#endif

<= span style=3D"color: hsl(120, 100%, 40%);">+struct local_entry

+{
+ const char *local;
+ const char *port;
+ bool bind_local;
+};
+
struct connection_entry
{<= /span>
+ struct local_lis= t *local_list;
int proto;
sa_fami= ly_t af;
const char *local_port;
= bool local_port_defined;
const char *remote_port;

- const char *local;
const char *remote;
bool remote_floa= t;
bool bind_defined;
@@ -179,6 +186,1= 2 @@

#define CONNECTION_LIST_SIZE 64

+struc= t local_list
+{
+ int len;
+ struct local_entry *array[CO= NNECTION_LIST_SIZE];

= +};
+
struct connection_list

{
int capaci= ty;
diff --git a/src/openvpn/socket.c b/src/openvpn/socket.= c
index 17bd263..5d9e111 100644
--- a/src/o= penvpn/socket.c
+++ b/src/openvpn/socket.c
= @@ -342,7 +342,7 @@
void
do_preresolve(st= ruct context *c)
{
- int i;
+ int i, j;
struct connection_list *l =3D c->= ;options.connection_list;
const unsigned int preresolv= e_flags =3D GETADDR_RESOLVE
= |GETADDR_UPDATE_MANAGEMENT_STATE
@@ -416,12 +41= 6,19 @@
}
}
- if (c= e->bind_local)
+ = flags |=3D GETADDR_PASSIVE;
+ flags &=3D ~GETADDR_RANDOMIZE;
+
+ for (j =3D 0; j < ce->local_list->len; j= ++)
{
- flags |=3D GETADDR_PASSIVE;
- flags &=3D ~GETADDR_RANDOMIZE;
- status =3D = do_preresolve_host(c, ce->local, ce->local_port,
- ce= ->af, flags);
+ = struct local_entry *le =3D ce->local_list->array[j];<= br>+
+ if (!le->local)
+ {

+ continue;
+ }

+
+ status =3D do_preresolve_host(c, le->local, l= e->port, ce->af, flags);
if (status !=3D= 0)
{
goto er= r;

To view, visit change 436. To unsubscribe= , or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4d1c96662c5a8c750d883e3b20a= dde09529e2764
Gerrit-Change-Number: 436
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <a@...2181...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--g9BEIKiCE1g=--