Skip to contentSkip to conversation

Make --nobind default for --pull

PATCH Superseded Arne Schwabe 3 participants 11 messages Dec 2, 2021 – Dec 6, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 Changes.rst           |  3 ++-
 src/openvpn/options.c | 11 ++++-------
 2 files changed, 6 insertions(+), 8 deletions(-)
Changes.rst +2 -1
index c1a04deed..95bebc4ab 100644
@@ -120,7 +120,8 @@ PF (Packet Filtering) support has been removed
 User-visible Changes
 --------------------
 - CHACHA20-POLY1305 is included in the default of ``--data-ciphers`` when available.
-- Option ``--prng`` is ignored as we rely on the SSL library radnom generator.
+- Option ``--prng`` is ignored as we rely on the SSL library random number generator.
+- Option ``--nobind`` is default when ``--client`` or ``--pull`` is used in the configuration
 
 Overview of changes in 2.5
 ==========================
src/openvpn/options.c +4 -7
index 312efb36c..3aaad7bc8 100644
@@ -2859,14 +2859,11 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
         }
     }
 
-    if (ce->proto == PROTO_TCP_CLIENT && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
-    {
-        ce->bind_local = false;
-    }
 
-    if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
+    bool need_bind = ce->local || ce->local_port_defined || ce->bind_defined;
+    bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
+
+    if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
     {
         ce->bind_local = false;
     }
Signature · 1 line
2.33.0
#1 lore raw
Quoted 7 lines

Arne Schwabe <[email protected]...> hat am 02.12.2021 13:54 geschrieben:

src/openvpn/options.c +0 -5
-    if (ce->proto == PROTO_TCP_CLIENT && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
-    {
-        ce->bind_local = false;
-    }

src/openvpn/options.c options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) · line 2869

Quoted 10 lines
src/openvpn/options.c +4 -2
 
-    if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
+    bool need_bind = ce->local || ce->local_port_defined || ce->bind_defined;
+    bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
+
+    if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
     {
         ce->bind_local = false;
     }

The refactoring makes it very hard to see what the actual change is. Maybe it would be better to split this in two commits?

The only actual change in behavior is the "|| o->pull", right?

Regards,
Frank

--
Frank Lichtenheld

#2 lore raw

Am 03.12.21 um 17:18 schrieb Frank Lichtenheld:

Quoted 18 lines
Quoted 7 lines

Arne Schwabe <[email protected]...> hat am 02.12.2021 13:54 geschrieben:

src/openvpn/options.c +0 -5
-    if (ce->proto == PROTO_TCP_CLIENT && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
-    {
-        ce->bind_local = false;
-    }

src/openvpn/options.c options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) · line 2869

Quoted 10 lines
src/openvpn/options.c +4 -2
 
-    if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
+    bool need_bind = ce->local || ce->local_port_defined || ce->bind_defined;
+    bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
+
+    if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
      {
          ce->bind_local = false;
      }
Quoted 4 lines

The refactoring makes it very hard to see what the actual change is. Maybe it would be better to split this in two commits?

The only actual change in behavior is the "|| o->pull", right?

Yes. But should I really split up this 5 line patch into two patches? That feels a bit excessive.

Arne

#3 lore raw

Hi,

Quoted 6 lines · Arne Schwabe
Quoted 3 lines

The refactoring makes it very hard to see what the actual change is. Maybe it would be better to split this in two commits?

The only actual change in behavior is the "|| o->pull", right?

Yes. But should I really split up this 5 line patch into two patches? That feels a bit excessive.

I'm fine with a single patch here.

I need to think a bit more into "what conditions is this checking, exactly, and why?" - but with refactoring, I'd have to do that thinking twice :-)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#4 lore raw
Quoted 12 lines

Gert Doering <[email protected]...> hat am 05.12.2021 11:19 geschrieben:

Hi,

Quoted 4 lines · Arne Schwabe
Quoted 3 lines

The refactoring makes it very hard to see what the actual change is. Maybe it would be better to split this in two commits?

The only actual change in behavior is the "|| o->pull", right?

Quoted 7 lines
Quoted 2 lines

Yes. But should I really split up this 5 line patch into two patches? That feels a bit excessive.

I'm fine with a single patch here.

I need to think a bit more into "what conditions is this checking, exactly, and why?" - but with refactoring, I'd have to do that thinking twice :-)

I disagree. If you had one patch that does refactoring but does not intend any functional change, and one patch that just adds "|| o->pull", the general understanding of each patch would require much less time and thinking. Mostly it would be much easier to match the change with the intent communicated by the commit message. Which for me was the hardest part, here.

Regards,
Frank

--
Frank Lichtenheld

#5 lore raw

Hi,

Quoted 6 lines · Frank Lichtenheld
Quoted 2 lines

I need to think a bit more into "what conditions is this checking, exactly, and why?" - but with refactoring, I'd have to do that thinking twice :-)

I disagree. If you had one patch that does refactoring but does not intend any functional change, and one patch that just adds "|| o->pull", the general understanding of each patch would require much less time and thinking.

True, but the second patch would not be correct, then :-) - as it actually adds more conditions than just "o->pull". The original code does not check for socks.

I am not exactly happy with the *new* code, as it is still too convoluted for my coffee level ("if (!bind_needed && conditions) set bind_local=false", what are these conditions? why?) but I do not think an intermediate patch will make these particular conditional contortions easier...

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#6 lore raw

Am 05.12.2021 um 12:40 schrieb Gert Doering:

Quoted 11 lines

Hi,

Quoted 5 lines · Frank Lichtenheld
Quoted 2 lines

I need to think a bit more into "what conditions is this checking, exactly, and why?" - but with refactoring, I'd have to do that thinking twice :-)

I disagree. If you had one patch that does refactoring but does not intend any functional change, and one patch that just adds "|| o->pull", the general understanding of each patch would require much less time and thinking.

True, but the second patch would not be correct, then :-) - as it actually adds more conditions than just "o->pull". The original code does not check for socks.

The original code checks for socks. That is not changed.  The orignal code basically has two ifs that checks for the code that is !bind_need and the particular condition (socks or tcp-client)

Quoted 4 lines

I am not exactly happy with the *new* code, as it is still too convoluted for my coffee level ("if (!bind_needed && conditions) set bind_local=false", what are these conditions? why?)

I can add more comments to the code. bind_needed is basically if the options have a condition that forces binding anyway.

Quoted 3 lines

but I do not think an intermediate
patch will make these particular conditional contortions easier...

#7 lore raw

Hi,

Quoted 3 lines · Arne Schwabe

The original code checks for socks. That is not changed.  The orignal code basically has two ifs that checks for the code that is !bind_need and the particular condition (socks or tcp-client)

You're right. As I said, that mass if conditions, half of them negated, exceeded my coffee level...

Quoted 5 lines
Quoted 2 lines

for my coffee level ("if (!bind_needed && conditions) set bind_local=false", what are these conditions? why?)

I can add more comments to the code. bind_needed is basically if the options have a condition that forces binding anyway.

I think that would be good.

thanks :)

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#8 lore raw

PATCH v2 1/1 Make --nobind default for --pull

In reply to Arne Schwabe

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

---
 Changes.rst           |  3 ++-
 src/openvpn/options.c | 16 +++++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)
Changes.rst +2 -1
index e83dda023..b7d7f2054 100644
@@ -120,7 +120,8 @@ PF (Packet Filtering) support has been removed
 User-visible Changes
 --------------------
 - CHACHA20-POLY1305 is included in the default of ``--data-ciphers`` when available.
-- Option ``--prng`` is ignored as we rely on the SSL library radnom generator.
+- Option ``--prng`` is ignored as we rely on the SSL library random number generator.
+- Option ``--nobind`` is default when ``--client`` or ``--pull`` is used in the configuration
 
 Overview of changes in 2.5
 ==========================
src/openvpn/options.c +9 -7
index 312efb36c..39cf3e99a 100644
@@ -2859,14 +2859,16 @@ options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce)
         }
     }
 
-    if (ce->proto == PROTO_TCP_CLIENT && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
-    {
-        ce->bind_local = false;
-    }
+    /* an option is present that requires local bind to enabled */
+    bool need_bind = ce->local || ce->local_port_defined || ce->bind_defined;
+
+    /* socks proxy is enabled */
+    bool uses_socks = ce->proto == PROTO_UDP && ce->socks_proxy_server;
 
-    if (ce->proto == PROTO_UDP && ce->socks_proxy_server && !ce->local
-        && !ce->local_port_defined && !ce->bind_defined)
+    /* If binding is not forced by an explicit options and we have (at least)
+     * one of --tcp-client, --pull (or --client), or socks we do not bind
+     * locally to have "normal" IP client behaviour of a random source port */
+    if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
     {
         ce->bind_local = false;
     }
Signature · 1 line
2.33.0
Acked-by on v2 1/1
#9 lore raw
Quoted 3 lines

Arne Schwabe <[email protected]...> hat am 06.12.2021 02:00 geschrieben:

Patch v2: add more commments

I feel they help a lot :)

Quoted 1 line

+ /* If binding is not forced by an explicit options and we have (at least)

typo: "options" should be "option". Or "an" is wrong.

src/openvpn/options.c options_postprocess_mutate_ce(struct options *o, struct connection_entry *ce) · line 2874

Quoted 6 lines
src/openvpn/options.c +3 -0
+     * one of --tcp-client, --pull (or --client), or socks we do not bind
+     * locally to have "normal" IP client behaviour of a random source port */
+    if (!need_bind && (ce->proto == PROTO_TCP_CLIENT || uses_socks || o->pull))
     {
         ce->bind_local = false;
     }

Regards,
Frank

--
Frank Lichtenheld

#10 lore raw
In reply to Arne Schwabe

Your patch has been applied to the master branch. Thanks for the extra comments, with these, I can understand what's going on without maximum coffee level :-)

Tested locally (my t_client tests all set --nobind, so this was not spectacularily enlightening... ran a few cases manually to see what would happen. Does the job. --bind still binds, --lport still binds, "default --client" does not bind).

Comment adjusted as instructed ("an explicit option", no "s").

commit de02c828f5aa3fbaca78918d4392b48b47547770 (master)

Author: Arne Schwabe
Date:   Mon Dec 6 02:00:07 2021 +0100
     Make --nobind default for --pull

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg23303.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering