From: "cron2 (Code Review)" Date: Mon, 24 Mar 2025 15:26:14 +0000 References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="r/jU4OHWjzM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Make 'lport 0' no longer sufficient to do '--bind'. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --r/jU4OHWjzM= 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/+/916?usp=3Demail to review the following change. Change subject: Make 'lport 0' no longer sufficient to do '--bind'. ...................................................................... Make 'lport 0' no longer sufficient to do '--bind'. 'lport ' used to trigger 'do socket bind', which is not useful in itself for the 'lport 0' case (port 0 -> OS assigns a random port, as it is done for unbound sockets) unless also binding to a particular local IP address ('--local 192.0.2.1'). The trigger for 'lport has been used, do socket bind' is ce.local_port_defined -> change the code to test for "0", and only set this for non-0 ports (NOTE: this is a string match, so if you really really want the old "lport 0" behaviour, using "lport 00" still does that...). The ce.local_port value is still set, so '--lport 0' together with '--local 192.0.2.1' will give you a random port number bound to that IP address - without 'lport 0' it would default to 1194 or the value of '--port' (if not using '--rport'). Summary: socket bind is now only done if one of these is set - --port with not "0" - --bind (default on the client is "--nobind") - --local
Change-Id: I1976307a7643c82f31d55ca32c79cbe64b6fffc6 Signed-off-by: Gert Doering --- M doc/man-sections/link-options.rst M src/openvpn/options.c 2 files changed, 9 insertions(+), 2 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/16/916/1 diff --git a/doc/man-sections/link-options.rst b/doc/man-sections/link-opti= ons.rst index d48021e..287473e 100644 --- a/doc/man-sections/link-options.rst +++ b/doc/man-sections/link-options.rst @@ -122,7 +122,9 @@ --lport port Set default TCP/UDP port number. Cannot be used together with - ``--nobind`` option. + ``--nobind`` option. A port number of ``0`` is only honoured to + achieve "bind() to a random assigned port number" if a bind-to IP + address is specified with ``--local``. --mark value Mark encrypted packets being sent with ``value``. The mark value can be diff --git a/src/openvpn/options.c b/src/openvpn/options.c index ab56609..99dd60a 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -6710,7 +6710,12 @@ else if (streq(p[0], "lport") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); - options->ce.local_port_defined =3D true; + + /* only trigger bind() if port is not 0 (or --local is used) */ + if (!streq(p[1], "0")) + { + options->ce.local_port_defined =3D true; + } options->ce.local_port =3D p[1]; } else if (streq(p[0], "rport") && p[1] && !p[2]) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/916?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: I1976307a7643c82f31d55ca32c79cbe64b6fffc6 Gerrit-Change-Number: 916 Gerrit-PatchSet: 1 Gerrit-Owner: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --r/jU4OHWjzM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

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

Vi= ew Change

Make 'lport 0' no longer sufficient to do '--bind=
'.

'lport <anything>' used to trigger 'do sock= et bind', which is not
useful in itself for the 'lport 0' ca= se (port 0 -> OS assigns a
random port, as it is done for unbound soc= kets) unless also binding
to a particular local IP address ('--local= 192.0.2.1').

The trigger for 'lport has been used, do socke= t bind' is
ce.local_port_defined -> change the code to test for &= quot;0", and
only set this for non-0 ports (NOTE: this is a string = match,
so if you really really want the old "lport 0" behaviou= r, using
"lport 00" still does that...).

The ce.local_p= ort value is still set, so '--lport 0' together
with '--loca= l 192.0.2.1' will give you a random port number
bound to that IP add= ress - without 'lport 0' it would default
to 1194 or the value o= f '--port' (if not using '--rport').

Summary: socke= t bind is now only done if one of these is set
- --port <port> w= ith <port> not "0"
- --bind (default on the client is= "--nobind")
- --local <address>

Change-Id: I19= 76307a7643c82f31d55ca32c79cbe64b6fffc6
Signed-off-by: Gert Doering <g= ert@...1296...>
---
M doc/man-sections/link-options.rst
M src/o= penvpn/options.c
2 files changed, 9 insertions(+), 2 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/16/916/1
diff --git a/doc/man-sections/link-options.rst b/doc/man-sections/li=
nk-options.rst
index d48021e..287473e 100644
--- a/doc/man-sections/link-options.rst
+++ b/doc/man-sec= tions/link-options.rst
@@ -122,7 +122,9 @@
=
--lport port
Set default TCP/UDP port= number. Cannot be used together with
- ``--nobind`` option.
+ ``--nobind`` option. A port number of ``0`` is only h= onoured to
+ achieve= "bind() to a random assigned port number" if a bind-to IP=
+ address is specified wit= h ``--local``.

--mark value
Mark encrypted packets being sent with ``value``. The mark value can= be
diff --git a/src/openvpn/options.c b/src/openvpn/option= s.c
index ab56609..99dd60a 100644
--- a/src= /openvpn/options.c
+++ b/src/openvpn/options.c
@@ -6710,7 +6710,12 @@
else if (streq(p[0], "= lport") && p[1] && !p[2])
{
VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);

- options->ce.loc= al_port_defined =3D true;
+
+ /* on= ly trigger bind() if port is not 0 (or --local is used) */
+ if (!streq(p[1], "0&quo= t;))
+ {
+ options->c= e.local_port_defined =3D true;
+ }
options->ce.local_port =3D= p[1];
}
else if (streq(p[0], &qu= ot;rport") && p[1] && !p[2])

To view, visit change 916. To unsubscribe, or for help writing mail f= ilters, visit settings.<= /p>

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1976307a7643c82f31d55ca32c7= 9cbe64b6fffc6
Gerrit-Change-Number: 916
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <gert@...1296...>
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
--r/jU4OHWjzM=--