Skip to contentSkip to conversation

Fix server directive for /31 subnet

PATCH In review Tom Yan 3 participants 12 messages Nov 13, 2019 – Jun 23, 2020

lore
Share & tools
lore

Tom Yan

author
#0 lore raw

PATCH 1/1 Fix server directive for /31 subnet

As /31 subnet now works (as we stop setting broadcast address), the server directives can be fixed for it as well. Also stop repeating code for tap and tun + subnet.

---
 src/openvpn/helper.c | 90 ++++++++++++++++++--------------------------
 1 file changed, 37 insertions(+), 53 deletions(-)
src/openvpn/helper.c +37 -53
index ff9df506..608f886f 100644
@@ -286,13 +286,13 @@ helper_client_server(struct options *o)
                 print_netmask(IFCONFIG_POOL_MIN_NETBITS, &gc));
         }
 
-        if (dev == DEV_TYPE_TUN)
+        if (dev == DEV_TYPE_TUN && (topology == TOP_NET30 || topology == TOP_P2P))
         {
             int pool_end_reserve = 4;
 
             if (netbits > 29)
             {
-                msg(M_USAGE, "--server directive when used with --dev tun must define a subnet of %s or lower",
+                msg(M_USAGE, "subnet must be %s or lower",
                     print_netmask(29, &gc));
             }
 
@@ -304,85 +304,69 @@ helper_client_server(struct options *o)
             o->mode = MODE_SERVER;
             o->tls_server = true;
 
-            if (topology == TOP_NET30 || topology == TOP_P2P)
+            o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
+            o->ifconfig_remote_netmask = print_in_addr_t(o->server_network + 2, 0, &o->gc);
+
+            if (!(o->server_flags & SF_NOPOOL))
             {
-                o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
-                o->ifconfig_remote_netmask = print_in_addr_t(o->server_network + 2, 0, &o->gc);
-
-                if (!(o->server_flags & SF_NOPOOL))
-                {
-                    o->ifconfig_pool_defined = true;
-                    o->ifconfig_pool_start = o->server_network + 4;
-                    o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve;
-                    ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
-                }
-
-                helper_add_route(o->server_network, o->server_netmask, o);
-                if (o->enable_c2c)
-                {
-                    push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
-                }
-                else if (topology == TOP_NET30)
-                {
-                    push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
-                }
+                o->ifconfig_pool_defined = true;
+                o->ifconfig_pool_start = o->server_network + 4;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve;
+                ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
-            else if (topology == TOP_SUBNET)
+
+            helper_add_route(o->server_network, o->server_netmask, o);
+            if (o->enable_c2c)
             {
-                o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
-                o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
-
-                if (!(o->server_flags & SF_NOPOOL))
-                {
-                    o->ifconfig_pool_defined = true;
-                    o->ifconfig_pool_start = o->server_network + 2;
-                    o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2;
-                    ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
-                }
-                o->ifconfig_pool_netmask = o->server_netmask;
-
-                push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
-                if (!o->route_default_gateway)
-                {
-                    o->route_default_gateway = print_in_addr_t(o->server_network + 2, 0, &o->gc);
-                }
+                push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
             }
-            else
+            else if (topology == TOP_NET30)
             {
-                ASSERT(0);
+                push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
             }
-
-            push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
         }
-        else if (dev == DEV_TYPE_TAP)
+        else if (dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && topology == TOP_SUBNET))
         {
-            if (netbits > 30)
+            int ptp = 1;
+
+            if (netbits > 31)
             {
-                msg(M_USAGE, "--server directive when used with --dev tap must define a subnet of %s or lower",
-                    print_netmask(30, &gc));
+                msg(M_USAGE, "subnet must be %s or lower",
+                    print_netmask(31, &gc));
             }
 
+            if (netbits == 31)
+              ptp = 0;
+
             o->mode = MODE_SERVER;
             o->tls_server = true;
-            o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
+
+            o->ifconfig_local = print_in_addr_t(o->server_network + ptp, 0, &o->gc);
             o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
 
             if (!(o->server_flags & SF_NOPOOL))
             {
                 o->ifconfig_pool_defined = true;
-                o->ifconfig_pool_start = o->server_network + 2;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 1;
+                o->ifconfig_pool_start = o->server_network + ptp + 1;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
 
-            push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
+            push_option(o, print_opt_route_gateway(o->server_network + ptp, &o->gc), M_USAGE);
+            if (dev == DEV_TYPE_TUN && !o->route_default_gateway)
+            {
+                o->route_default_gateway = print_in_addr_t(o->server_network + ptp + 1, 0, &o->gc);
+            }
         }
         else
         {
             ASSERT(0);
         }
 
+        if (dev == DEV_TYPE_TUN)
+            push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
+
         /* set push-ifconfig-constraint directive */
         if ((dev == DEV_TYPE_TAP || topology == TOP_SUBNET))
         {
Signature · 1 line
2.24.0
author
#1 lore raw

For the record, as I don't see why o->ifconfig_pool_end was (o->server_network | ~o->server_netmask) - 2 for tun + subnet while it was (o->server_network | ~o->server_netmask) - 1 for tap, I assume the former is a typo.

By the way, why does o->ifconfig_pool_netmask need to be set even when nopool is set?

Quoted 150 lines · Tom Yan

As /31 subnet now works (as we stop setting broadcast address), the server directives can be fixed for it as well. Also stop repeating code for tap and tun + subnet.

---
 src/openvpn/helper.c | 90 ++++++++++++++++++--------------------------
 1 file changed, 37 insertions(+), 53 deletions(-)
src/openvpn/helper.c +37 -54
index ff9df506..608f886f 100644
@@ -286,13 +286,13 @@ helper_client_server(struct options *o)
                 print_netmask(IFCONFIG_POOL_MIN_NETBITS, &gc));
         }
 
-        if (dev == DEV_TYPE_TUN)
+        if (dev == DEV_TYPE_TUN && (topology == TOP_NET30 || topology == TOP_P2P))
         {
             int pool_end_reserve = 4;
 
             if (netbits > 29)
             {
-                msg(M_USAGE, "--server directive when used with --dev tun must define a subnet of %s or lower",
+                msg(M_USAGE, "subnet must be %s or lower",
                     print_netmask(29, &gc));
             }
 
@@ -304,85 +304,69 @@ helper_client_server(struct options *o)
             o->mode = MODE_SERVER;
             o->tls_server = true;
 
-            if (topology == TOP_NET30 || topology == TOP_P2P)
+            o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
+            o->ifconfig_remote_netmask = print_in_addr_t(o->server_network + 2, 0, &o->gc);
+
+            if (!(o->server_flags & SF_NOPOOL))
             {
-                o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
-                o->ifconfig_remote_netmask = print_in_addr_t(o->server_network + 2, 0, &o->gc);
-
-                if (!(o->server_flags & SF_NOPOOL))
-                {
-                    o->ifconfig_pool_defined = true;
-                    o->ifconfig_pool_start = o->server_network + 4;
-                    o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve;
-                    ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
-                }
-
-                helper_add_route(o->server_network, o->server_netmask, o);
-                if (o->enable_c2c)
-                {
-                    push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
-                }
-                else if (topology == TOP_NET30)
-                {
-                    push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
-                }
+                o->ifconfig_pool_defined = true;
+                o->ifconfig_pool_start = o->server_network + 4;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve;
+                ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
-            else if (topology == TOP_SUBNET)
+
+            helper_add_route(o->server_network, o->server_netmask, o);
+            if (o->enable_c2c)
             {
-                o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
-                o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
-
-                if (!(o->server_flags & SF_NOPOOL))
-                {
-                    o->ifconfig_pool_defined = true;
-                    o->ifconfig_pool_start = o->server_network + 2;
-                    o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2;
-                    ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
-                }
-                o->ifconfig_pool_netmask = o->server_netmask;
-
-                push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
-                if (!o->route_default_gateway)
-                {
-                    o->route_default_gateway = print_in_addr_t(o->server_network + 2, 0, &o->gc);
-                }
+                push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
             }
-            else
+            else if (topology == TOP_NET30)
             {
-                ASSERT(0);
+                push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
             }
-
-            push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
         }
-        else if (dev == DEV_TYPE_TAP)
+        else if (dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && topology == TOP_SUBNET))
         {
-            if (netbits > 30)
+            int ptp = 1;
+
+            if (netbits > 31)
             {
-                msg(M_USAGE, "--server directive when used with --dev tap must define a subnet of %s or lower",
-                    print_netmask(30, &gc));
+                msg(M_USAGE, "subnet must be %s or lower",
+                    print_netmask(31, &gc));
             }
 
+            if (netbits == 31)
+              ptp = 0;
+
             o->mode = MODE_SERVER;
             o->tls_server = true;
-            o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
+
+            o->ifconfig_local = print_in_addr_t(o->server_network + ptp, 0, &o->gc);
             o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
 
             if (!(o->server_flags & SF_NOPOOL))
             {
                 o->ifconfig_pool_defined = true;
-                o->ifconfig_pool_start = o->server_network + 2;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 1;
+                o->ifconfig_pool_start = o->server_network + ptp + 1;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
 
-            push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
+            push_option(o, print_opt_route_gateway(o->server_network + ptp, &o->gc), M_USAGE);
+            if (dev == DEV_TYPE_TUN && !o->route_default_gateway)
+            {
+                o->route_default_gateway = print_in_addr_t(o->server_network + ptp + 1, 0, &o->gc);
+            }
         }
         else
         {
             ASSERT(0);
         }
 
+        if (dev == DEV_TYPE_TUN)
+            push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
+
         /* set push-ifconfig-constraint directive */
         if ((dev == DEV_TYPE_TAP || topology == TOP_SUBNET))
         {
--

2.24.0

#2 lore raw

Hi,

Quoted 4 lines · Tom Yan

For the record, as I don't see why o->ifconfig_pool_end was (o->server_network | ~o->server_netmask) - 2 for tun + subnet while it was (o->server_network | ~o->server_netmask) - 1 for tap, I assume the former is a typo.

It might be related to the way the windows tap6 driver always needs a gateway address even in tun mode (and uses the last address from the subnet for this). There's very few typos in OpenVPN code regarding *this* type of math, and way more "just funny platforms and old lore".

Quoted 2 lines

By the way, why does o->ifconfig_pool_netmask need to be set even when nopool is set?

Not sure. This code has been rewritten a number of times over the years, so maybe the assignment slipped outside of an if() block...

Things like this can (and should) all be fixed, but please do not lump them together with a functional change in one big patch.

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]...
#3 lore raw

Hi,

Quoted 8 lines · Gert Doering
Quoted 2 lines

By the way, why does o->ifconfig_pool_netmask need to be set even when nopool is set?

Not sure. This code has been rewritten a number of times over the years, so maybe the assignment slipped outside of an if() block...

Things like this can (and should) all be fixed, but please do not lump them together with a functional change in one big patch.

I agree with Gert here. If you are finding inconsistencies across the code and want to fix them, please do so in small separate patches (related fixes can and should obviously go together).

It'll make them easier to be reviewed and merged ;-)

On top of that, a fix might be worth backporting to an older release, while a functional change would normally just go to master.

Thanks a lot for your contribution though!

Cheers,

Signature · 1 line
Antonio Quartulli
author
#11 lore raw
In reply to Gert Doering
Quoted 7 lines · Gert Doering

Hi,

It might be related to the way the windows tap6 driver always needs a gateway address even in tun mode (and uses the last address from the subnet for this). There's very few typos in OpenVPN code regarding *this* type of math, and way more "just funny platforms and old lore".

The reason I think it is a typo is because the pool start is network address + 2 (i.e. I think it's a copy-and-paste kind of typo). AFAIK, the gateway address issue is addressed in commit 4cc6a25 by using the pool start for that. (The commit message stated that using the address of the server does not work for Windows.)

In any case, should I just keep it as-is just to be "conservative"?

Quoted 2 lines

Not sure. This code has been rewritten a number of times over the years, so maybe the assignment slipped outside of an if() block...

Again, should I keep it as-is, or "try it and see"?

Quoted 2 lines

Things like this can (and should) all be fixed, but please do not lump them together with a functional change in one big patch.

No problem, I can split it and resend.

Quoted 9 lines

gert
--
"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]...

author
#4 lore raw

PATCH v2 1/4 Avoid repeating code for tap and tun+subnet in server directive

In reply to Antonio Quartulli

It also avoids limitation (i.e. netbits <= 29) that does not apply to the subnet topology.

---
 src/openvpn/helper.c | 74 ++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 47 deletions(-)
src/openvpn/helper.c +27 -47
index ff9df506..470b9120 100644
@@ -286,13 +286,13 @@ helper_client_server(struct options *o)
                 print_netmask(IFCONFIG_POOL_MIN_NETBITS, &gc));
         }
 
-        if (dev == DEV_TYPE_TUN)
+        if (dev == DEV_TYPE_TUN && (topology == TOP_NET30 || topology == TOP_P2P))
         {
             int pool_end_reserve = 4;
 
             if (netbits > 29)
             {
-                msg(M_USAGE, "--server directive when used with --dev tun must define a subnet of %s or lower",
+                msg(M_USAGE, "subnet must be %s or lower",
                     print_netmask(29, &gc));
             }
 
@@ -304,66 +304,39 @@ helper_client_server(struct options *o)
             o->mode = MODE_SERVER;
             o->tls_server = true;
 
-            if (topology == TOP_NET30 || topology == TOP_P2P)
+            o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
+            o->ifconfig_remote_netmask = print_in_addr_t(o->server_network + 2, 0, &o->gc);
+
+            if (!(o->server_flags & SF_NOPOOL))
             {
-                o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
-                o->ifconfig_remote_netmask = print_in_addr_t(o->server_network + 2, 0, &o->gc);
-
-                if (!(o->server_flags & SF_NOPOOL))
-                {
-                    o->ifconfig_pool_defined = true;
-                    o->ifconfig_pool_start = o->server_network + 4;
-                    o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve;
-                    ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
-                }
-
-                helper_add_route(o->server_network, o->server_netmask, o);
-                if (o->enable_c2c)
-                {
-                    push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
-                }
-                else if (topology == TOP_NET30)
-                {
-                    push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
-                }
+                o->ifconfig_pool_defined = true;
+                o->ifconfig_pool_start = o->server_network + 4;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - pool_end_reserve;
+                ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
-            else if (topology == TOP_SUBNET)
+
+            helper_add_route(o->server_network, o->server_netmask, o);
+            if (o->enable_c2c)
             {
-                o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
-                o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
-
-                if (!(o->server_flags & SF_NOPOOL))
-                {
-                    o->ifconfig_pool_defined = true;
-                    o->ifconfig_pool_start = o->server_network + 2;
-                    o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2;
-                    ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
-                }
-                o->ifconfig_pool_netmask = o->server_netmask;
-
-                push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
-                if (!o->route_default_gateway)
-                {
-                    o->route_default_gateway = print_in_addr_t(o->server_network + 2, 0, &o->gc);
-                }
+                push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
             }
-            else
+            else if (topology == TOP_NET30)
             {
-                ASSERT(0);
+                push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
             }
 
-            push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
         }
-        else if (dev == DEV_TYPE_TAP)
+        else if (dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && topology == TOP_SUBNET))
         {
             if (netbits > 30)
             {
-                msg(M_USAGE, "--server directive when used with --dev tap must define a subnet of %s or lower",
+                msg(M_USAGE, "subnet must be %s or lower",
                     print_netmask(30, &gc));
             }
 
             o->mode = MODE_SERVER;
             o->tls_server = true;
+
             o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
             o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
 
@@ -371,18 +344,25 @@ helper_client_server(struct options *o)
             {
                 o->ifconfig_pool_defined = true;
                 o->ifconfig_pool_start = o->server_network + 2;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 1;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
 
             push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
+            if (dev == DEV_TYPE_TUN && !o->route_default_gateway)
+            {
+                o->route_default_gateway = print_in_addr_t(o->server_network + 2, 0, &o->gc);
+            }
         }
         else
         {
             ASSERT(0);
         }
 
+        if (dev == DEV_TYPE_TUN)
+            push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
+
         /* set push-ifconfig-constraint directive */
         if ((dev == DEV_TYPE_TAP || topology == TOP_SUBNET))
         {
Signature · 1 line
2.24.0
author
#5 lore raw

PATCH v2 2/4 Fix server directive for /31 subnet

In reply to Antonio Quartulli

As /31 subnet now works (as we stop setting broadcast address), the server directives can be fixed for it as well.

---
 src/openvpn/helper.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
src/openvpn/helper.c +12 -7
index 470b9120..5b2ca0cc 100644
@@ -328,31 +328,36 @@ helper_client_server(struct options *o)
         }
         else if (dev == DEV_TYPE_TAP || (dev == DEV_TYPE_TUN && topology == TOP_SUBNET))
         {
-            if (netbits > 30)
+            int ptp = 1;
+
+            if (netbits > 31)
             {
                 msg(M_USAGE, "subnet must be %s or lower",
-                    print_netmask(30, &gc));
+                    print_netmask(31, &gc));
             }
 
+            if (netbits == 31)
+                ptp = 0;
+
             o->mode = MODE_SERVER;
             o->tls_server = true;
 
-            o->ifconfig_local = print_in_addr_t(o->server_network + 1, 0, &o->gc);
+            o->ifconfig_local = print_in_addr_t(o->server_network + ptp, 0, &o->gc);
             o->ifconfig_remote_netmask = print_in_addr_t(o->server_netmask, 0, &o->gc);
 
             if (!(o->server_flags & SF_NOPOOL))
             {
                 o->ifconfig_pool_defined = true;
-                o->ifconfig_pool_start = o->server_network + 2;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - 2;
+                o->ifconfig_pool_start = o->server_network + ptp + 1;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp * 2;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
 
-            push_option(o, print_opt_route_gateway(o->server_network + 1, &o->gc), M_USAGE);
+            push_option(o, print_opt_route_gateway(o->server_network + ptp, &o->gc), M_USAGE);
             if (dev == DEV_TYPE_TUN && !o->route_default_gateway)
             {
-                o->route_default_gateway = print_in_addr_t(o->server_network + 2, 0, &o->gc);
+                o->route_default_gateway = print_in_addr_t(o->server_network + ptp + 1, 0, &o->gc);
             }
         }
         else
Signature · 1 line
2.24.0
author
#6 lore raw

PATCH v2 3/4 Avoid reserving one more address at pool end

In reply to Antonio Quartulli

It appears to be a copy-and-paste kind of typo (pool start is network address + 2).

---
 src/openvpn/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/helper.c +1 -1
index 5b2ca0cc..6e2f0891 100644
@@ -349,7 +349,7 @@ helper_client_server(struct options *o)
             {
                 o->ifconfig_pool_defined = true;
                 o->ifconfig_pool_start = o->server_network + ptp + 1;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp * 2;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
Signature · 1 line
2.24.0
author
#9 lore raw

PATCH v2 4/4 Do not set pool netmask when nopool is set

In reply to Antonio Quartulli

The setting probably just slipped out of the if-block over rewrites.

---
 src/openvpn/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/helper.c +1 -1
index 6e2f0891..a36bc63a 100644
@@ -351,8 +351,8 @@ helper_client_server(struct options *o)
                 o->ifconfig_pool_start = o->server_network + ptp + 1;
                 o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
+                o->ifconfig_pool_netmask = o->server_netmask;
             }
-            o->ifconfig_pool_netmask = o->server_netmask;
 
             push_option(o, print_opt_route_gateway(o->server_network + ptp, &o->gc), M_USAGE);
             if (dev == DEV_TYPE_TUN && !o->route_default_gateway)
Signature · 1 line
2.24.0
author
#7 lore raw

Re: [Openvpn-devel] [PATCH v2 3/4] Avoid reserving one more address at pool end

In reply to Tom Yan

If it isn't a typo, I wonder if it is the equivalence of pool_end_reserve. As with the subnet topology, each client takes up 1 address in contrast to 4 with net30.

So perhaps the question is, what's the purpose of pool_end_reserve?

Quoted 22 lines · Tom Yan

It appears to be a copy-and-paste kind of typo (pool start is network address + 2).

---
 src/openvpn/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/helper.c +1 -2
index 5b2ca0cc..6e2f0891 100644
@@ -349,7 +349,7 @@ helper_client_server(struct options *o)
             {
                 o->ifconfig_pool_defined = true;
                 o->ifconfig_pool_start = o->server_network + ptp + 1;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp * 2;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
--

2.24.0

author
#8 lore raw

Re: [Openvpn-devel] [PATCH v2 3/4] Avoid reserving one more address at pool end

So a recent question on the openvpn-users caused me to have found that, this "reserve-one-more-address" is seemingly related to Windows / --ip-win32. Commit 251cc8f made a "correction" to the manual/documentation which sort of implied that the address is reserved as the default address chosen by --ip-win32 dynamic as DHCP server (when dev is a tun).

But the thing is, the choice can be made by user with an extra parameter (offset) that does not affect the --ifconfig-pool set by --server. So as far as I can see here, it *implies* that the server directive shouldn't be used with --ip-win32 dynamic offset. (This is pretty nasty to me, although it might practically be convenient to the "default lovers").

I am not sure what to do with this. Personally I prefer ditching the reservation and simply note that --ip-win32 dynamic shouldn't be used with --server, for simplicity and consistency. (In addition to the consistency of whether --server can be used with --ip-win32 dynamic, x.x.x.254 may actually be used in a tap set-up, rendering commit 251cc8f "wrong".

Quoted 30 lines · Tom Yan

If it isn't a typo, I wonder if it is the equivalence of pool_end_reserve. As with the subnet topology, each client takes up 1 address in contrast to 4 with net30.

So perhaps the question is, what's the purpose of pool_end_reserve?

Quoted 22 lines · Tom Yan

It appears to be a copy-and-paste kind of typo (pool start is network address + 2).

---
 src/openvpn/helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/helper.c +1 -2
index 5b2ca0cc..6e2f0891 100644
@@ -349,7 +349,7 @@ helper_client_server(struct options *o)
             {
                 o->ifconfig_pool_defined = true;
                 o->ifconfig_pool_start = o->server_network + ptp + 1;
-                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp * 2;
+                o->ifconfig_pool_end = (o->server_network | ~o->server_netmask) - ptp;
                 ifconfig_pool_verify_range(M_USAGE, o->ifconfig_pool_start, o->ifconfig_pool_end);
             }
             o->ifconfig_pool_netmask = o->server_netmask;
--

2.24.0

#10 lore raw

Re: [Openvpn-devel] [PATCH v2 4/4] Do not set pool netmask when nopool is set

In reply to Tom Yan

Hi,

Quoted 1 line · Tom Yan

The setting probably just slipped out of the if-block over rewrites.

Possibly... so it makes sense to clean this up.

Can you please re-send the patch to change *both* places where this occurs, helper.c line 348 and helper.c line 391? Seems a bit weird to just change one occurance.

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]...