If IPv6 pool specification sets pool start to ::0 address, increment.
PATCH 1/1 If IPv6 pool specification sets pool start to ::0 address, increment.
The first IPv6 address in a subnet is not usable (IPv6 anycast address), but our pool code ignored this.
Instead of assigning an unusable address or erroring out, just log the fact, and increment the pool start to <pool_base>::1
NOTE: this is a bit simplistic. A pool that is larger than /96 and has non-0 bits in the "uppermost bits" will still get the increment as we only look at the lowermost 32 bits.
NOTE2: if the pool is specified with "--server-ipv6 $base/$bits", this is a non-issue, as the address for the pool start will be incremented anyway.
Reported-by: NicolaF_ in Trac
Trac: #1282
--- doc/man-sections/server-options.rst | 3 ++- src/openvpn/pool.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
doc/man-sections/server-options.rst +2 -1
@@ -204,7 +204,8 @@ fast hardware. SSL/TLS authentication must be used in this mode. ifconfig-ipv6-pool ipv6addr/bits The pool starts at ``ipv6addr`` and matches the offset determined from - the start of the IPv4 pool. + the start of the IPv4 pool. If the host part of the given IPv6 + address is ``0``, the pool starts at ``ipv6addr`` +1. --ifconfig-pool-persist args Persist/unpersist ifconfig-pool data to ``file``, at ``seconds``
src/openvpn/pool.c +15 -0
@@ -224,6 +224,21 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, } pool->ipv6.base = ipv6_base; + +/* if a pool starts at ::0, that first IPv6 address is not usable +* first clients (subnet anycast address). Start with 1, then. +* NOTE: this will also fire for something like +* ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64 +* as we only look at the rightmost 32 bits. So be it... +*/ +if (base ==0 ) + { +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: incrementing pool start " +"to avoid ::0 assignment" ); + base++; + pool->ipv6.base.s6_addr[15 ]++; + } + pool_ipv6_size = ipv6_netbits >=112 ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ;
Signature · 1 line
2.26.2
Hi,
Quoted 5 lines · Gert Doering
index
1f74ac57..2814ff46100644src/openvpn/pool.c +0
-0@@ -224,6 +224,21 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, }
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 234
Quoted 10 lines
src/openvpn/pool.c +8
-0pool->ipv6.base = ipv6_base; + +/* if a pool starts at ::0, that first IPv6 address is not usable +* first clients (subnet anycast address). Start with 1, then. +* NOTE: this will also fire for something like +* ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64 +* as we only look at the rightmost 32 bits. So be it... +*/ +if (base ==0 )
why not memcmp'ing ipv6.base with in6addr_any (defined in netinet/in.h)? This way you get rid of the first NOTE (unless this header is linux specific..).
Regards,
Signature · 1 line
Antonio Quartulli
Hi,
Quoted 10 lines · Antonio Quartulli
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 234
Quoted 9 lines
pool->ipv6.base = ipv6_base;src/openvpn/pool.c +8
-0+ +/* if a pool starts at ::0, that first IPv6 address is not usable +* first clients (subnet anycast address). Start with 1, then. +* NOTE: this will also fire for something like +* ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64 +* as we only look at the rightmost 32 bits. So be it... +*/ +if (base ==0 )
Quoted 3 lines
why not memcmp'ing ipv6.base with
in6addr_any(defined innetinet/in.h)? This way you get rid of the first NOTE (unless this header is linux specific..).
because ipv6.base is not "all zero"... it's "the IPv6 address that the pool starts on", host + network part...
If you have pools like this:
--ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64
--ifconfig-ipv6-pool 2001:db8:0:1:1234::0/112
what would "comparing with in6addr_any" achieve? "ipv6.base" is 2001:db8:0:1:1234::0 in both cases.
Now, "base" is "an integer that contains the lower 32 bit of the host part" - which is 0, for both these cases.
To fix this "totally perfect" we'd need to move "base" to 64 bit integer, and then figure out how to do that portably across supported 32 bit platforms (including MSVC) (or work with 2x 32 bit 'base_low', 'base_hi', or do "full 128 bit on 16 uint8_t" stuff...).
Yes, this can be done, but I was way too lazy and went for a less intrusive fix instead...
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]...Hi,
Quoted 42 lines · Gert Doering
The first IPv6 address in a subnet is not usable (IPv6 anycast address), but our pool code ignored this.
Instead of assigning an unusable address or erroring out, just log the fact, and increment the pool start to <pool_base>::1
NOTE: this is a bit simplistic. A pool that is larger than /96 and has non-0 bits in the "uppermost bits" will still get the increment as we only look at the lowermost 32 bits.
NOTE2: if the pool is specified with "--server-ipv6 $base/$bits", this is a non-issue, as the address for the pool start will be incremented anyway.
Reported-by:
NicolaF_in Trac
Trac: #1282Signed-off-by Gert Doering <[email protected]...>--- doc/man-sections/server-options.rst | 3 ++- src/openvpn/pool.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)doc/man-sections/server-options.rst +2
-1@@ -204,7 +204,8 @@ fast hardware. SSL/TLS authentication must be used in this mode. ifconfig-ipv6-pool ipv6addr/bits The pool starts at ``ipv6addr`` and matches the offset determined from - the start of the IPv4 pool. + the start of the IPv4 pool. If the host part of the given IPv6 + address is ``0``, the pool starts at ``ipv6addr`` +1. --ifconfig-pool-persist args Persist/unpersist ifconfig-pool data to ``file``, at ``seconds``src/openvpn/pool.c +0
-0
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 228
Quoted 5 lines
src/openvpn/pool.c +2
-0@@ -224,6 +224,21 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, } pool->ipv6.base = ipv6_base; + +/* if a pool starts at ::0, that first IPv6 address is not usable
can we reword a bit this comment? I.e.: "if the starting address of a pool has the host part all zero, that first ...."
The "starts at ::0" confused me as if we were targeting pools starting at [::].
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 232
Quoted 4 lines
src/openvpn/pool.c +4
-0+* first clients (subnet anycast address). Start with 1, then. +* NOTE: this will also fire for something like +* ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64 +* as we only look at the rightmost 32 bits. So be it...
wouldn't this test miserably fail when the host part is smaller than 32? like for a 2001:db8:0:1:1234::0/124?
Regards,
Quoted 13 lines
src/openvpn/pool.c +9
-0+*/ +if (base ==0 ) + { +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: incrementing pool start " +"to avoid ::0 assignment" ); + base++; + pool->ipv6.base.s6_addr[15 ]++; + } + pool_ipv6_size = ipv6_netbits >=112 ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ;
Signature · 1 line
Antonio Quartulli
Hi,
Quoted 11 lines · Antonio Quartulli
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 228
Quoted 5 lines
} pool->ipv6.base = ipv6_base;src/openvpn/pool.c +2
-0+ +/* if a pool starts at ::0, that first IPv6 address is not usable can we reword a bit this comment? I.e.: "if the starting address of a pool has the host part all zero, that first ...."
The "starts at ::0" confused me as if we were targeting pools starting at [::].
Okay. I did not want to make this comment too long, but it seems more verbosity is needed. I'll send a v2
Quoted 7 lines
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 232
Quoted 4 lines
src/openvpn/pool.c +4
-0+* first clients (subnet anycast address). Start with 1, then. +* NOTE: this will also fire for something like +* ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64 +* as we only look at the rightmost 32 bits. So be it... wouldn't this test miserably fail when the host part is smaller than 32? like for a 2001:db8:0:1:1234::0/124?
We look at "base", which is only the host part, but "at most 32 bits of the host part".
(This is *your* code...!)
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]...Hi,
Quoted 4 lines · Gert Doering
We look at "base", which is only the host part, but "at most 32 bits of the host part".
(This is *your* code...!)
(self-shaming dance mode=ON)
Riiight, then drop this comment. The patch looks good, except for the comment that needs more verbosity.
Quoted 3 lines
gert
Signature · 1 line
Antonio Quartulli
PATCH v2 1/1 If IPv6 pool specification sets pool start to ::0 address, increment.
In reply to Gert DoeringThe first IPv6 address in a subnet is not usable (IPv6 anycast address), but our pool code ignored this.
Instead of assigning an unusable address or erroring out, just log the fact, and increment the pool start to <pool_base>::1
NOTE: this is a bit simplistic. A pool that is larger than /96 and has non-0 bits in the "uppermost bits" will still get the increment as we only look at the lowermost 32 bits.
NOTE2: if the pool is specified with "--server-ipv6 $base/$bits", this is a non-issue, as the address for the pool start will be incremented anyway.
v2: make comment more explicit about "we're only talking about the
host part here" and "base sees only only 32 bit of the host part"
Reported-by: NicolaF_ in Trac
Trac: #1282
--- doc/man-sections/server-options.rst | 3 ++- src/openvpn/pool.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-)
doc/man-sections/server-options.rst +2 -1
@@ -204,7 +204,8 @@ fast hardware. SSL/TLS authentication must be used in this mode. ifconfig-ipv6-pool ipv6addr/bits The pool starts at ``ipv6addr`` and matches the offset determined from - the start of the IPv4 pool. + the start of the IPv4 pool. If the host part of the given IPv6 + address is ``0``, the pool starts at ``ipv6addr`` +1. --ifconfig-pool-persist args Persist/unpersist ifconfig-pool data to ``file``, at ``seconds``
src/openvpn/pool.c +18 -0
@@ -224,6 +224,24 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, } pool->ipv6.base = ipv6_base; + +/* if a pool starts at a base address that has all-zero in the +* host part, that first IPv6 address must not be assigned to +* clients because it is not usable (subnet anycast address). +* Start with 1, then. +* +* NOTE: this will also (mis-)fire for something like +* ifconfig-ipv6-pool 2001:db8:0:1:1234::0/64 +* as we only check the rightmost 32 bits of the host part. So be it. +*/ +if (base ==0 ) + { +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: incrementing pool start " +"to avoid ::0 assignment" ); + base++; + pool->ipv6.base.s6_addr[15 ]++; + } + pool_ipv6_size = ipv6_netbits >=112 ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ;
Signature · 1 line
2.26.2
Hi,
Quoted 14 lines · Gert Doering
The first IPv6 address in a subnet is not usable (IPv6 anycast address), but our pool code ignored this.
Instead of assigning an unusable address or erroring out, just log the fact, and increment the pool start to <pool_base>::1
NOTE: this is a bit simplistic. A pool that is larger than /96 and has non-0 bits in the "uppermost bits" will still get the increment as we only look at the lowermost 32 bits.
NOTE2: if the pool is specified with "--server-ipv6 $base/$bits", this is a non-issue, as the address for the pool start will be incremented anyway.
Quoted 7 lines
v2: make comment more explicit about "we're only talking about the
host part here" and "base sees only only 32 bit of the host part"Reported-by:
NicolaF_in Trac
Trac: #1282Signed-off-by Gert Doering <[email protected]...>
Signature · 1 line
Antonio Quartulli
Patch has been applied to the master and release/2.5 branch.
Release/2.4 has the same "unintended feature", but the pool code is sufficiently different that this patch will not work - I do not see this as significant problem ("a documented workaround exists"), so do not currently plan to backport it.
commit 4dff236811a1ec9c97a27ad93182ad4beb12377f (master) commit 611382c16cbac83195cc0fd4825553dad149ff9a (release/2.5)
Author: Gert Doering Date: Thu Sep 17 10:59:41 2020 +0200
If IPv6 pool specification sets pool start to ::0 address, increment.
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg21039.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering