Browse code

Make --nobind default for --pull

Currently we default to local binding with udp. But the majority of
configuration files actually uses --nobind in the configuration to
change the default for --client. And client protocols should normally
use a random source port. This changes the default. Local binding with
--client can still be done using --bind.

This commit refactors the current code to be more easy to add to understand
and adds the the o->pull condition as additional option to opt into setting
local binding to false.

Patch v2: add more commments

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20211206010007.3072528-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg23303.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Arne Schwabe authored on 2021/12/06 10:00:07
Showing 2 changed files
... ...
@@ -120,7 +120,8 @@ PF (Packet Filtering) support has been removed
120 120
 User-visible Changes
121 121
 --------------------
122 122
 - CHACHA20-POLY1305 is included in the default of ``--data-ciphers`` when available.
123
-- Option ``--prng`` is ignored as we rely on the SSL library radnom generator.
123
+- Option ``--prng`` is ignored as we rely on the SSL library random number generator.
124
+- Option ``--nobind`` is default when ``--client`` or ``--pull`` is used in the configuration
124 125
 
125 126
 Overview of changes in 2.5
126 127
 ==========================
... ...
@@ -2859,14 +2859,16 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
2859 2859
         }
2860 2860
     }
2861 2861
 
2862
-    if (ce->proto == PROTO_TCP_CLIENT && !ce->local
2863
-        && !ce->local_port_defined && !ce->bind_defined)
2864
-    {
2865
-        ce->bind_local = false;
2866
-    }
2862
+    /* an option is present that requires local bind to enabled */
2863
+    bool need_bind = ce->local || ce->local_port_defined || ce->bind_defined;
2864
+
2865
+    /* socks proxy is enabled */
2866
+    bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
2867 2867
 
2868
-    if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local
2869
-        && !ce->local_port_defined && !ce->bind_defined)
2868
+    /* If binding is not forced by an explicit option and we have (at least)
2869
+     * one of --tcp-client, --pull (or --client), or socks we do not bind
2870
+     * locally to have "normal" IP client behaviour of a random source port */
2871
+    if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
2870 2872
     {
2871 2873
         ce->bind_local = false;
2872 2874
     }