Allow IPv6-only tunnels
v4 cover Allow IPv6-only tunnels
This patchset allows servers to work with a tunnel configured with IPv6 only (client code has already been merged).
This new v4 is the result of some more reviews, including an hardcore reviewing session that me and Gert had yesterday afternoon.
We found some interesting bugs and agreed on some
previously-not-well-defined behaviours.
The patchset is now ready for broader testing and potential final vetting.
In a nutshell, after applying this patchset, it will be possible to configure a server with just --server-ipv6 and no IPv4 at all (in the tunnel).
Happy hacking!
(Note: this code is also available at [1] in the ipv6-only branch)
Cheers,
Trac: #208
[1] https://gitlab.com/ordex986/openvpn
Antonio Quartulli (7):
pool: prevent IPv6 pools to be larger than 2^16 addresses
pool: allow to configure an IPv6-only ifconfig-pool allow usage of --server-ipv6 even when no --server is specified
pool: add support for ifconfig-pool-persist with IPv6 only
route: warn on IPv4 routes installation when no IPv4 is configured
options: enable IPv4 redirection logic only if really required
ipv6-pool: get rid of size constraint
src/openvpn/helper.c | 15 +- src/openvpn/multi.c | 10 +- src/openvpn/options.c | 29 +++- src/openvpn/pool.c | 317 ++++++++++++++++++++++++++++++++---------- src/openvpn/pool.h | 8 +- src/openvpn/route.c | 16 ++- 6 files changed, 302 insertions(+), 93 deletions(-)
Signature · 1 line
2.26.2
PATCH v4 1/7 pool: prevent IPv6 pools to be larger than 2^16 addresses
--- src/openvpn/pool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/pool.c +1 -1
@@ -183,7 +183,7 @@ ifconfig_pool_init(enum pool_type type, in_addr_t start, in_addr_t end,if (pool->ipv6.enabled) { pool->ipv6.base = ipv6_base; - pool->ipv6.size = ipv6_netbits >96 ? (1 << (128 - ipv6_netbits)) + pool->ipv6.size = ipv6_netbits >112 ? (1 << (128 - ipv6_netbits)) :IFCONFIG_POOL_MAX ; msg( D_IFCONFIG_POOL, "IFCONFIG POOL IPv6: (IPv4) size=%d, size_ipv6=%d, netbits=%d, base_ipv6=%s",
Signature · 1 line
2.26.2
PATCH v4 2/7 pool: allow to configure an IPv6-only ifconfig-pool
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]...>
With this change a server is allowed to allocate an IPv6-only pool. This is required to make it capable of managing an IPv6-only tunnel.
Trac: #208
---
Changes from v3:
- properly compute pool size taking into account the actual base address
src/openvpn/multi.c | 10 ++- src/openvpn/pool.c | 181 ++++++++++++++++++++++++++++++++------------ src/openvpn/pool.h | 8 +- 3 files changed, 146 insertions(+), 53 deletions(-)
src/openvpn/multi.c +7 -3
@@ -388,7 +388,8 @@ multi_init(struct multi_context *m, struct context *t, bool tcp_mode, int thread* differently based on whether a tun or tap style * tunnel. */ -if (t->options.ifconfig_pool_defined) +if (t->options.ifconfig_pool_defined + || t->options.ifconfig_ipv6_pool_defined) {int pool_type =IFCONFIG_POOL_INDIV ;
@@ -397,7 +398,8 @@ multi_init(struct multi_context *m, struct context *t, bool tcp_mode, int thread pool_type =IFCONFIG_POOL_30NET ; } - m->ifconfig_pool = ifconfig_pool_init(pool_type, + m->ifconfig_pool = ifconfig_pool_init(t->options.ifconfig_pool_defined, + pool_type, t->options.ifconfig_pool_start, t->options.ifconfig_pool_end, t->options.duplicate_cn,
@@ -1495,7 +1497,9 @@ multi_select_virtual_addr(struct multi_context *m, struct multi_instance *mi)const int tunnel_topology =TUNNEL_TOPOLOGY (mi->context.c1.tuntap);msg (M_INFO ,"MULTI_sva: pool returned IPv4=%s, IPv6=%s" , -print_in_addr_t ( remote,0 , &gc ), + (mi->context.options.ifconfig_pool_defined + ?print_in_addr_t (remote,0 , &gc) + :"(Not enabled)" ), (mi->context.options.ifconfig_ipv6_pool_defined ?print_in6_addr ( remote_ipv6,0 , &gc ) :"(Not enabled)" ) );
src/openvpn/pool.c +132 -49
268 lines not on this page · raw message
src/openvpn/pool.h +7 -1
@@ -52,6 +52,7 @@ struct ifconfig_pool {bool duplicate_cn;struct { +bool enabled;enum pool_type type;in_addr_t base;int size;
@@ -72,7 +73,12 @@ struct ifconfig_pool_persisttypedef int ifconfig_pool_handle ; -struct ifconfig_pool *ifconfig_pool_init (enum pool_type type,in_addr_t start,in_addr_t end,const bool duplicate_cn,const bool ipv6_pool,const struct in6_addr ipv6_base,const int ipv6_netbits ); +struct ifconfig_pool *ifconfig_pool_init (const bool ipv4_pool, +enum pool_type type,in_addr_t start, +in_addr_t end,const bool duplicate_cn, +const bool ipv6_pool, +const struct in6_addr ipv6_base, +const int ipv6_netbits);void ifconfig_pool_free (struct ifconfig_pool *pool);
Signature · 1 line
2.26.2
PATCH v4 3/7 allow usage of --server-ipv6 even when no --server is specified
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]...>
Until now OpenVPN has not allowed to specify --server-ipv6 if no --server was also set. This constraint comes from the fact that most of the IPv6 logic (i.e. ifconfig-pool handling) relied on IPv4 components to be activated and configured as well.
Now that the IPv6 code path has been made independent from IPv4, it is finally possible to to relax the constraint mentioned above and make it possible for the user to have a configurations with --server-ipv6 only.
Trac: #208
---
Changes from v4:
- fix typ0 in message
Changes from v3:
- patchset rebased on top of pre-ipv6-only patchset
Changes from v4:
- change commit subject/message
- move ifconfig-ipv6-pool check change into 4/8
src/openvpn/helper.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
src/openvpn/helper.c +6 -2
@@ -174,10 +174,11 @@ helper_client_server(struct options *o)*/ if (o->server_ipv6_defined) { -if (!o->server_defined) +if (o->client) { -msg (M_USAGE ,"--server-ipv6 must be used together with --server" ); +msg (M_USAGE ,"--server-ipv6 and --client cannot be used together" ); } +if (o->server_flags &SF_NOPOOL ) {msg (M_USAGE ,"--server-ipv6 is incompatible with 'nopool' option" );
@@ -187,6 +188,9 @@ helper_client_server(struct options *o)msg (M_USAGE ,"--server-ipv6 already defines an ifconfig-ipv6-pool, so you can't also specify --ifconfig-pool explicitly" ); } + o->mode =MODE_SERVER ; + o->tls_server = true; +/* local ifconfig is "base address + 1" and "+2" */ o->ifconfig_ipv6_local =print_in6_addr (add_in6_addr ( o->server_network_ipv6,1 ),0 , &o->gc );
Signature · 1 line
2.26.2
PATCH v4 4/7 pool: add support for ifconfig-pool-persist with IPv6 only
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]...>
Without altering the pool logic, this patch enables using a persistent IP pool also when the server is configured with IPv6 only.
Trac: #208
---
Changes from v3:
- patchset rebased on top of pre-ipv6-only patchset
src/openvpn/options.c | 7 ++- src/openvpn/pool.c | 140 ++++++++++++++++++++++++++++++++---------- 2 files changed, 114 insertions(+), 33 deletions(-)
src/openvpn/options.c +5 -2
@@ -2346,9 +2346,12 @@ options_postprocess_verify_ce(const struct options *options, const struct connec {msg (M_USAGE ,"--up-delay cannot be used with --mode server" ); } -if (!options->ifconfig_pool_defined && options->ifconfig_pool_persist_filename) +if (!options->ifconfig_pool_defined + && !options->ifconfig_ipv6_pool_defined + && options->ifconfig_pool_persist_filename) { -msg (M_USAGE ,"--ifconfig-pool-persist must be used with --ifconfig-pool" ); +msg (M_USAGE , +"--ifconfig-pool-persist must be used with --ifconfig-pool or --ifconfig-ipv6-pool" ); }if (options->ifconfig_ipv6_pool_defined && !options->ifconfig_ipv6_local) {
src/openvpn/pool.c +109 -31
208 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v4 5/7 route: warn on IPv4 routes installation when no IPv4 is configured
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]...>
Same as already happens for IPv6, it is useful for the user to throw a warning when an IPv4 route is about to be installed and the tun interface has no IPv4 configured.
The twin message for IPv4 is adapted to have the same format.
The warning is not fatal, becuase the route might actually be external to the tun interface and therefore it may still work.
At the same time, modify the error message used for a route installation failure to explicitly mention "IPv4" since this it is used in the IPv4 code path only.
Trac: #208
---
Changes from v4:
- edit commit message
- modify IPv4 warning as well (moved from next patch)
Changes from v3:
- patchset rebased on top of pre-ipv6-only patchset
src/openvpn/route.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
src/openvpn/route.c +12 -4
@@ -987,7 +987,7 @@ redirect_default_route_to_vpn(struct route_list *rl, const struct tuntap *tt, unsigned int flags, const struct env_set *es, openvpn_net_ctx_t *ctx) { - const char err[] = "NOTE: unable to redirect default gateway --"; + const char err[] = "NOTE: unable to redirect IPv4 default gateway --";if (rl && rl->flags &RG_ENABLE ) {
@@ -1192,6 +1192,14 @@ add_routes(struct route_list *rl, struct route_ipv6_list *rl6, {struct route_ipv4 *r; +if (rl->routes && !tt->did_ifconfig_setup) + { +msg (M_INFO ,"WARNING: OpenVPN was configured to add an IPv4 " +"route. However, no IPv4 has been configured for %s, " +"therefore the route installation may fail or may not work " +"as expected." , tt->actual_name); + } +#ifdef ENABLE_MANAGEMENT if (management && rl->routes) {
@@ -1223,9 +1231,9 @@ add_routes(struct route_list *rl, struct route_ipv6_list *rl6,if (!tt->did_ifconfig_ipv6_setup) {msg (M_INFO ,"WARNING: OpenVPN was configured to add an IPv6 " -"route over %s. However, no IPv6 has been configured for " -"this interface, therefore the route installation may " -"fail or may not work as expected." , tt->actual_name); +"route. However, no IPv6 has been configured for %s, " +"therefore the route installation may fail or may not work " +"as expected." , tt->actual_name); }for (r = rl6->routes_ipv6; r; r = r->next)
Signature · 1 line
2.26.2
PATCH v4 6/7 options: enable IPv4 redirection logic only if really required
In reply to Antonio QuartulliFrom: Antonio Quartulli <[email protected]...>
If no IPv4 redirection flag is set, do not enable the IPv4 redirection logic at all so that it won't bother adding any useless IPv4 route.
Trac: #208
---
Changes from v4:
- move error message modification to previous patch
Changes from v3:
- patchset rebased on top of pre-ipv6-only patchset
src/openvpn/options.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
src/openvpn/options.c +8 -1
@@ -6591,7 +6591,14 @@ add_option(struct options *options,/* we need this here to handle pushed --redirect-gateway */ remap_redirect_gateway_flags (options);#endif - options->routes->flags |=RG_ENABLE ; +/* enable IPv4 redirection logic only if at least one IPv4 flag is set. +* For instance, when "redirect-gateway !ipv4 ipv6" is specified no +* IPv4 redirection should be activated. +*/ +if (options->routes->flags) + { + options->routes->flags |=RG_ENABLE ; + } }else if (streq (p[0 ],"block-ipv6" ) && !p[1 ]) {
Signature · 1 line
2.26.2
PATCH v4 7/7 ipv6-pool: get rid of size constraint
In reply to Antonio Quartulli--- src/openvpn/helper.c | 7 +++---- src/openvpn/options.c | 13 +++++++++---- src/openvpn/pool.c | 12 ++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-)
src/openvpn/helper.c +3 -4
@@ -198,12 +198,11 @@ helper_client_server(struct options *o)print_in6_addr (add_in6_addr ( o->server_network_ipv6,2 ),0 , &o->gc ); o->ifconfig_ipv6_netbits = o->server_netbits_ipv6; -/* pool starts at "base address + 0x1000" - leave enough room */ -ASSERT ( o->server_netbits_ipv6 <=112 );/* want 16 bits */ +/* basic sanity check */ +ASSERT (o->server_netbits_ipv6 >=64 && o->server_netbits_ipv6 <=124 ); o->ifconfig_ipv6_pool_defined = true; - o->ifconfig_ipv6_pool_base = -add_in6_addr ( o->server_network_ipv6,0x1000 ); + o->ifconfig_ipv6_pool_base =add_in6_addr (o->server_network_ipv6,2 ); o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;push_option ( o,"tun-ipv6" ,M_USAGE );
src/openvpn/options.c +9 -4
@@ -6714,9 +6714,12 @@ add_option(struct options *options,msg (msglevel,"error parsing --server-ipv6 parameter" ); goto err; } -if (netbits <64 || netbits >112 ) +if (netbits <64 || netbits >124 ) { -msg ( msglevel,"--server-ipv6 settings: only /64../112 supported right now (not /%d)" , netbits ); +msg (msglevel, +"--server-ipv6 settings: network must be between /64 and /124 (not /%d)" , + netbits); + goto err; } options->server_ipv6_defined = true;
@@ -6836,9 +6839,11 @@ add_option(struct options *options,msg (msglevel,"error parsing --ifconfig-ipv6-pool parameters" ); goto err; } -if (netbits <64 || netbits >112 ) +if (netbits <64 || netbits >124 ) { -msg ( msglevel,"--ifconfig-ipv6-pool settings: only /64../112 supported right now (not /%d)" , netbits ); +msg (msglevel, +"--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%d)" , + netbits); goto err; }
src/openvpn/pool.c +12 -0
@@ -207,6 +207,12 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start,ASSERT (0 ); } +if (pool->ipv4.size <2 ) + { +msg (M_FATAL ,"IPv4 pool size is too small (%d), must be at least 2" , + pool->ipv4.size); + } +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL: base=%s size=%d" ,print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size); }
@@ -245,6 +251,12 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ; +if (pool->ipv6.size <2 ) + { +msg (M_FATAL ,"IPv6 pool size is too small (%d), must be at least 2" , + pool->ipv6.size); + } +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: base=%s size=%d netbits=%d" ,print_in6_addr (pool->ipv6.base,0 , &gc), pool->ipv6.size, ipv6_netbits);
Signature · 1 line
2.26.2
[Openvpn-devel] [PATCH applied] Re: pool: prevent IPv6 pools to be larger than 2^16 addresses
In reply to Antonio QuartulliThis was an oversight by me, when initially implementing this - the intention was always "cap the IPv6 pool size at 2^16", not "let it grow until 2^31 and then cap to 2^16 thereafter". It did no harm, as the IPv6 pool was always limited by IPv4 pool size (which is capped to 2^16) - but with the "there can can be an IPv6-only pool now" work, this could lead to interesting malloc() explosions.
Your patch has been applied to the master and release/2.4 branch (bugfix).
commit 81d66a1f14d4be3282dd648ecc2049658e3a65ed (master) commit fc0297143494e0a0f08564d90dbb210669d0abf5 (release/2.4)
Author: Antonio Quartulli Date: Sat May 30 02:05:54 2020 +0200
pool: prevent IPv6 pools to be larger than 2^16 addresses
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg19945.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v4 2/7] pool: allow to configure an IPv6-only ifconfig-pool
In reply to Antonio QuartulliHi,
Quoted 6 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
With this change a server is allowed to allocate an IPv6-only pool. This is required to make it capable of managing an IPv6-only tunnel.
Quoted 6 lines
Trac: #208
Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v3:
- properly compute pool size taking into account the actual base address
Alas, we need a v5 of this patch.
One part is purely cosmetic...
src/openvpn/pool.c ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_a · line 210
Quoted 2 lines
src/openvpn/pool.c +2
-0+msg (D_IFCONFIG_POOL ,"IFCONFIG POOL: base=%s size=%d" , +print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size);
I think it should print "IFCONFIG POOL IPv4: ..." here, to make it symmetric with IPv6. Which is what we want, two equally-well supported protocols, not "the primary" and "IPv6" :-)
The other part is bigger, unfortunately...
Mon Jun 1 12:18:05 2020 us=584985 194.97.140.21:32015 [cron2-freebsd-tc-amd64] Peer Connection Initiated with [AF_INET6]::ffff:194.97.140.21:32015
Program received signal SIGSEGV, Segmentation fault. ifconfig_pool_release (pool=0x0, hand=-1, [email protected]...=false) at pool.c:361
361 int pool_size = ifconfig_pool_size(pool);
if you have a server that has *no* pools configured, no v4 and no v6 pool (because address management is done outside openvpn) it will crash the first time a given client reconnects.
GDB backtrace:
(gdb) where
#0 ifconfig_pool_release (pool=0x0, hand=-1, [email protected]...=false)
at pool.c:361
#1 0x000055555558cc20 in multi_close_instance (m=0x7fffffffc520,
mi=0x55555567d9a0, shutdown=<optimized out>) at multi.c:667
#2 0x000055555558e852 in multi_delete_dup (new_mi=0x5555556bf620,
m=0x7fffffffc520) at multi.c:1382
#3 multi_connection_established ([email protected]...=0x7fffffffc520,
[email protected]...=0x5555556bf620) at multi.c:1820
#4 0x000055555558fccd in multi_process_post ([email protected]...=0x7fffffffc520,
mi=0x5555556bf620, [email protected]...=5) at multi.c:2404
#5 0x00005555555901d2 in multi_process_incoming_link (
[email protected]...=0x7fffffffc520, [email protected]...=0x0,
[email protected]...=5) at multi.c:2768
#6 0x000055555558a3dc in multi_process_io_udp (m=0x7fffffffc520) at mudp.c:231
#7 tunnel_server_udp_single_threaded (top=0x7fffffffd580) at mudp.c:356
#8 0x0000555555594fc9 in openvpn_main (argc=2, argv=0x7fffffffe588)
at openvpn.c:309#9 0x00007ffff7a86deb in __libc_start_main () from /lib64/libc.so.6 #10 0x000055555555e86a in _start () at mudp.c:63
Not sure what is happening here - that part of the code hasn't been touched. Still, a "master" server with the same config (no pools, client ifconfig by means of ccd/ files) does not crash.
The ccd file looks like this:
--------------------------------------
vlan-pvid 200
# braucht explizites ifconfig*push wegen "kein pool" ifconfig-push 10.204.4.10 255.255.255.0 ifconfig-ipv6-push fd00:abcd:204:4::a:10/64 fd00:abcd:204:4::1
# for 2.3 push "tun-ipv6" --------------------------------------
Interesting enough, if I run "master" with the same config and do the same things, with a breakpoint set on ifconfig_pool_release(), I get a call that looks just the same:
Breakpoint 1, ifconfig_pool_release (pool=0x0, hand=-1, [email protected]...=false)
at pool.c:277
... but continue'ing will just do that, not crash.
Ah. So trivial...
ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, con
...
int pool_size = ifconfig_pool_size(pool);
if (pool && hand >= 0 && hand < pool_size)...ifconfig_pool_size(const struct ifconfig_pool *pool)
...
if (!pool->ipv4.enabled && !pool->ipv6.enabled)
{
return 0;
}... but if *neither* is enabled, "pool" actually is NULL... so this needs to become something like this
if (pool == NULL
|| (!pool->ipv4.enabled && !pool->ipv6.enabled) )
{
return 0;
}... which fixes the crash for good (all callers will verify that "hand < size" etc.).
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]...Re: [Openvpn-devel] [PATCH v4 2/7] pool: allow to configure an IPv6-only ifconfig-pool
Hi,
Quoted 18 lines · Gert Doering
Hi,
Quoted 6 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
With this change a server is allowed to allocate an IPv6-only pool. This is required to make it capable of managing an IPv6-only tunnel.
Quoted 6 lines
Trac: #208
Signed-off-by Antonio Quartulli <[email protected]...>---
Changes from v3:
- properly compute pool size taking into account the actual base addressAlas, we need a v5 of this patch.
Quoted 8 lines
One part is purely cosmetic...
src/openvpn/pool.c ifconfig_pool_verify_range(const int msglevel, const in_addr_t start, const in_a · line 210
Quoted 2 lines
src/openvpn/pool.c +2
-0+msg (D_IFCONFIG_POOL ,"IFCONFIG POOL: base=%s size=%d" , +print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size);I think it should print "IFCONFIG POOL IPv4: ..." here, to make it symmetric with IPv6. Which is what we want, two equally-well supported protocols, not "the primary" and "IPv6" :-)
Yeah, sounds good!
Quoted 98 lines
The other part is bigger, unfortunately...
Mon Jun 1 12:18:05 2020 us=584985 194.97.140.21:32015 [cron2-freebsd-tc-amd64] Peer Connection Initiated with [AF_INET6]::ffff:194.97.140.21:32015
Program received signal SIGSEGV, Segmentation fault.
ifconfig_pool_release(pool=0x0, hand=-1, [email protected]...=false) at pool.c:361
361 intpool_size=ifconfig_pool_size(pool);if you have a server that has *no* pools configured, no v4 and no v6 pool (because address management is done outside openvpn) it will crash the first time a given client reconnects.
GDB backtrace:
(gdb) where
#0ifconfig_pool_release(pool=0x0, hand=-1, [email protected]...=false)at pool.c:361 #1 0x000055555558cc20 in multi_close_instance (m=0x7fffffffc520, mi=0x55555567d9a0, shutdown=<optimized out>) at multi.c:667 #2 0x000055555558e852 in multi_delete_dup (new_mi=0x5555556bf620, m=0x7fffffffc520) at multi.c:1382 #3 multi_connection_established ([email protected]...=0x7fffffffc520, [email protected]...=0x5555556bf620) at multi.c:1820 #4 0x000055555558fccd in multi_process_post ([email protected]...=0x7fffffffc520, mi=0x5555556bf620, [email protected]...=5) at multi.c:2404 #5 0x00005555555901d2 in multi_process_incoming_link ( [email protected]...=0x7fffffffc520, [email protected]...=0x0, [email protected]...=5) at multi.c:2768 #6 0x000055555558a3dc in multi_process_io_udp (m=0x7fffffffc520) at mudp.c:231 #7 tunnel_server_udp_single_threaded (top=0x7fffffffd580) at mudp.c:356 #8 0x0000555555594fc9 in openvpn_main (argc=2, argv=0x7fffffffe588) at openvpn.c:309#9
0x00007ffff7a86debin__libc_start_main() from/lib64/libc.so.6#100x000055555555e86ain_start() at mudp.c:63Not sure what is happening here - that part of the code hasn't been touched. Still, a "master" server with the same config (no pools, client ifconfig by means of ccd/ files) does not crash.
The ccd file looks like this:
--------------------------------------
vlan-pvid 200# braucht explizites ifconfig*push wegen "kein pool" ifconfig-push 10.204.4.10 255.255.255.0 ifconfig-ipv6-push fd00:abcd:204:4::a:10/64 fd00:abcd:204:4::1# for 2.3 push "tun-ipv6" --------------------------------------Interesting enough, if I run "master" with the same config and do the same things, with a breakpoint set on
ifconfig_pool_release(), I get a call that looks just the same:Breakpoint 1,
ifconfig_pool_release(pool=0x0, hand=-1, [email protected]...=false)at pool.c:277... but continue'ing will just do that, not crash.
Ah. So trivial...
ifconfig_pool_release(struct
ifconfig_pool*pool,ifconfig_pool_handlehand, con
...int pool_size = ifconfig_pool_size(pool); if (pool && hand >= 0 && hand < pool_size)...
ifconfig_pool_size(const struct ifconfig_pool *pool)
...if (!pool->ipv4.enabled && !pool->ipv6.enabled) { return 0; }... but if *neither* is enabled, "pool" actually is NULL... so this needs to become something like this
if (pool == NULL || (!pool->ipv4.enabled && !pool->ipv6.enabled) ) { return 0; }
Quoted 2 lines
... which fixes the crash for good (all callers will verify that "hand < size" etc.).
Oh yeah - I missed this code path where pool_size() could be invoked with a null pool.
Will fix and send a v5.
Thanks a lot for digging into this!
Signature · 1 line
Antonio Quartulli
PATCH v5 1/1 pool: allow to configure an IPv6-only ifconfig-pool
From: Antonio Quartulli <[email protected]...>
With this change a server is allowed to allocate an IPv6-only pool. This is required to make it capable of managing an IPv6-only tunnel.
Trac: #208
---
Changes from v4:
- make 'IFCONFIG POOL' message symmetric across IPv4 and IPv6
- avoid crash when ifconfig_pool_size() is invoked with NULL poll (will create a trivial conflict with "ipv6-pool: get rid of size constraint")
Changes from v3:
- properly compute pool size taking into account the actual base address
--- src/openvpn/multi.c | 10 ++- src/openvpn/pool.c | 181 ++++++++++++++++++++++++++++++++------------ src/openvpn/pool.h | 8 +- 3 files changed, 146 insertions(+), 53 deletions(-)
src/openvpn/multi.c +7 -3
@@ -388,7 +388,8 @@ multi_init(struct multi_context *m, struct context *t, bool tcp_mode, int thread* differently based on whether a tun or tap style * tunnel. */ -if (t->options.ifconfig_pool_defined) +if (t->options.ifconfig_pool_defined + || t->options.ifconfig_ipv6_pool_defined) {int pool_type =IFCONFIG_POOL_INDIV ;
@@ -397,7 +398,8 @@ multi_init(struct multi_context *m, struct context *t, bool tcp_mode, int thread pool_type =IFCONFIG_POOL_30NET ; } - m->ifconfig_pool = ifconfig_pool_init(pool_type, + m->ifconfig_pool = ifconfig_pool_init(t->options.ifconfig_pool_defined, + pool_type, t->options.ifconfig_pool_start, t->options.ifconfig_pool_end, t->options.duplicate_cn,
@@ -1495,7 +1497,9 @@ multi_select_virtual_addr(struct multi_context *m, struct multi_instance *mi)const int tunnel_topology =TUNNEL_TOPOLOGY (mi->context.c1.tuntap);msg (M_INFO ,"MULTI_sva: pool returned IPv4=%s, IPv6=%s" , -print_in_addr_t ( remote,0 , &gc ), + (mi->context.options.ifconfig_pool_defined + ?print_in_addr_t (remote,0 , &gc) + :"(Not enabled)" ), (mi->context.options.ifconfig_ipv6_pool_defined ?print_in6_addr ( remote_ipv6,0 , &gc ) :"(Not enabled)" ) );
src/openvpn/pool.c +132 -49
268 lines not on this page · raw message
src/openvpn/pool.h +7 -1
@@ -52,6 +52,7 @@ struct ifconfig_pool {bool duplicate_cn;struct { +bool enabled;enum pool_type type;in_addr_t base;int size;
@@ -72,7 +73,12 @@ struct ifconfig_pool_persisttypedef int ifconfig_pool_handle ; -struct ifconfig_pool *ifconfig_pool_init (enum pool_type type,in_addr_t start,in_addr_t end,const bool duplicate_cn,const bool ipv6_pool,const struct in6_addr ipv6_base,const int ipv6_netbits ); +struct ifconfig_pool *ifconfig_pool_init (const bool ipv4_pool, +enum pool_type type,in_addr_t start, +in_addr_t end,const bool duplicate_cn, +const bool ipv6_pool, +const struct in6_addr ipv6_base, +const int ipv6_netbits);void ifconfig_pool_free (struct ifconfig_pool *pool);
Signature · 1 line
2.26.2
[Openvpn-devel] [PATCH applied] Re: pool: allow to configure an IPv6-only ifconfig-pool
Reviewed again ("stare at code"). Most of the changes are really
"straightforward", as soon as done :-) - make all the IPv4 stuff in the pool handling conditional, make IPv6 "stand on its own", plus fiddling with minimum sizes (if both protocols are "on", the more limited pool limits the size of the other protocol).
There still is *one* "pool" structure, but its IPv4 and IPv6 parts are now fully independent, except for the common size limitation - and that is fine, as there is currently no logic to tell openvpn "oh, this client only gets a v4 pool address", or "and v6 comes from that *other* pool". Maybe some day, but that's a different patchset.
One thing we actually might spend some more thought on is this one:
pool->ipv6.size = ipv6_netbits > 112
? (1 << (128 - ipv6_netbits)) - base
: IFCONFIG_POOL_MAX;which, I think, will not do the right thing for
ifconfig-ipv6-pool 2001:db8::f000/112
(it will come up with "65536", but the actual max size should be 4096, ::f000 to :ffff) - so it should be ">= 112" there.
But... even for a larger pool, if the base address is sufficiently silly, this will still not do what we intended to - 2001:db8::ffff:f000/96 will still overrun after 4096 clients, not having space for IFCONFIG_POOL_MAX.
Since this is no worse than today for silly configs, and better than today for /113.../128, it makes sense to merge as it is, but we need to revisit this.
(Note: when I say "overrun", it's not a "the pool structure will overrun and OpenVPN will segfault" overrun, it's just "we hand out pool addresses that are not part of the specified subnet" - which OpenVPN has always done, if the pool was specified in a silly-enough way, but Antonio and I decided to fix this now by reducing the pool size according to the base address, so the last address handed out is always "$net:ffff" - with the correct number of "f", of course)
Tested on the t_server setup with "no pools at all" (-> crash in v4) and "only v6 pool".
Passed t_client tests, of course, but since no client-related code paths are touched, this was just extra double-checking.
Your patch has been applied to the master branch.
commit 452113155e791fdf6091de0422391ff62bda2ac9
Author: Antonio Quartulli Date: Mon Jun 1 22:06:24 2020 +0200
pool: allow to configure an IPv6-only ifconfig-pool
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg19957.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: allow usage of --server-ipv6 even when no --server is specified
In reply to Antonio QuartulliStared-at-code and tested on the t_server setup. Sufficiently trivial change :-) - but also all the other code parts that assume "if you do --server-ipv6, you must have done --server as well!!" have been adjusted in previous patches (ipv6-only ifconfig, ipv6-only pools).
Your patch has been applied to the master branch.
commit 7d65aad8973fa85a007a3de8907b9cbced20b2b4
Author: Antonio Quartulli Date: Sat May 30 02:05:56 2020 +0200
allow usage of --server-ipv6 even when no --server is specified
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg19949.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Gert Doering
NAKRe: [Openvpn-devel] [PATCH v4 4/7] pool: add support for ifconfig-pool-persist with IPv6 only
In reply to Antonio QuartulliHI,
Quoted 8 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
Without altering the pool logic, this patch enables using a persistent IP pool also when the server is configured with IPv6 only.
Trac: #208
Signed-off-by Antonio Quartulli <[email protected]...>
NAK, as discussed on IRC, because this breaks (surprisingly) persistent pools for IPv4-only pools.
(An ipp.txt entry of just "CN,IPv4" will not pass the 3rd buf_parse() call, and thus be ignored as "malformed" - so pool assignments are lost at every server restart)
The rest of the code looks good, and it seems to work correctly on the t_server setup.
While at it, one cosmetic change:
src/openvpn/pool.c ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out) · line 529
Quoted 6 lines
src/openvpn/pool.c +2
-0@@ -459,23 +525,26 @@ ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)for (i =0 ; i < pool_size; ++i) {const struct ifconfig_pool_entry *e = &pool->list[i]; +struct in6_addr ip6; +in_addr_t ip;
I find these two declarations a bit awkward - they are "in a block", but it's not "the block where they are needed"... the old code had on-the-fly declarations
Quoted 1 line
src/openvpn/pool.c +0
-1-const in_addr_t ip =ifconfig_pool_handle_to_ip_base (pool, i);
...
Quoted 1 line
- struct
in6_addrip6 =ifconfig_pool_handle_to_ipv6_base(pool, i);
which, I assume, you removed due to line length considerations?
This is not a reason for NAKing, though. Just something I found surprising.
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]...PATCH v5 1/1 pool: add support for ifconfig-pool-persist with IPv6 only
From: Antonio Quartulli <[email protected]...>
Without altering the pool logic, this patch enables using a persistent IP pool also when the server is configured with IPv6 only.
Trac: #208
---
Changes from v4:
- prevent persist-pool parser from bailing out when only IPv4 addresses are used
- simplify ifconfig_pool_set() function
- re-arrange ifconfig_pool_read() function to better deal with all cases (i.e. only ipv6 or invalid ipv4 but not ipv6..etc..)
Changes from v3:
- patchset rebased on top of pre-ipv6-only patchset
--- src/openvpn/options.c | 7 +- src/openvpn/pool.c | 208 ++++++++++++++++++++++++++++++++---------- 2 files changed, 165 insertions(+), 50 deletions(-)
src/openvpn/options.c +5 -2
@@ -2346,9 +2346,12 @@ options_postprocess_verify_ce(const struct options *options, const struct connec {msg (M_USAGE ,"--up-delay cannot be used with --mode server" ); } -if (!options->ifconfig_pool_defined && options->ifconfig_pool_persist_filename) +if (!options->ifconfig_pool_defined + && !options->ifconfig_ipv6_pool_defined + && options->ifconfig_pool_persist_filename) { -msg (M_USAGE ,"--ifconfig-pool-persist must be used with --ifconfig-pool" ); +msg (M_USAGE , +"--ifconfig-pool-persist must be used with --ifconfig-pool or --ifconfig-ipv6-pool" ); }if (options->ifconfig_ipv6_pool_defined && !options->ifconfig_ipv6_local) {
src/openvpn/pool.c +160 -48
281 lines not on this page · raw message
Signature · 1 line
2.27.0
[Openvpn-devel] [PATCH applied] Re: pool: add support for ifconfig-pool-persist with IPv6 only
Much nicer code than in v4 :-)
Stared-at-code, and ran the t_client and t_server tests with ipv4-only, ipv4+ipv6 and ipv6-only pools (ipv4-only is something I never wanted to do again... :-) ).
Tested pool mishandling ("corrupt" and "out-of-bounds" v4+v6 addresses, mismatching pool indexes, etc.) - and that all behaves like planned. \o/
Something for the cleanup patch: pool.c seems to have grown an include for "options.h", but I can not see a reason why this is needed (it compiles fine without)...?
Your patch has been applied to the master branch.
commit 6a8cd033b1812a26b9b35c17eef33240d7ac2719
Author: Antonio Quartulli Date: Sat Jun 6 23:16:24 2020 +0200
pool: add support for ifconfig-pool-persist with IPv6 only
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg19990.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v4 7/7] ipv6-pool: get rid of size constraint
In reply to Antonio QuartulliHi,
src/openvpn/helper.c helper_client_server(struct options *o) · line 206
Quoted 5 lines · Antonio Quartulli
o->ifconfig_ipv6_pool_defined = true;src/openvpn/helper.c +1
-2- o->ifconfig_ipv6_pool_base = -add_in6_addr ( o->server_network_ipv6,0x1000 ); + o->ifconfig_ipv6_pool_base =add_in6_addr (o->server_network_ipv6,2 ); o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;
Thinking more about this, I'm not totally happy with this particular change.
Yes, it makes sense for smallish pools (/112 to /124) because there we do not have room for "wasting addresses".
OTOH, changing this for an existing /64 pool - or anything "large enough that 0x1000 addresses will not matter" - would change behaviour in existing setups - that's one of the feedbacks I already received via Twitter on the patchset
https://twitter.com/tschaeferm/status/1266822120497188876
One of the notable things that it would break is our buildbot t_client test environment - all clients would receive new v6 addresses, and since one of the tests is "have I received what I expect?" this would cause a buildbot explosion.
My idea would be to make this conditional on the pool size - if the size is /64.../111, make it +0x1000 ("keep existing behaviour for large-enough pools"), if it's /112.../124, make it +2
Thoughts?
gert
PS: the rest of the patch is fine
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]...[Openvpn-devel] [PATCH applied] Re: route: warn on IPv4 routes installation when no IPv4 is configured
In reply to Antonio Quartulli"because it makes sense" :-)
Tested on the client side (only) because this is really independent of client/server setup. Nicely warns if (and only if) a route for IPv4 or IPv6 is encountered without a previous ifconfig/ifconfig-ipv6.
Your patch has been applied to the master branch.
commit 826d8953a335fdbc8d20d800f800a44d0674f00a
Author: Antonio Quartulli Date: Sat May 30 02:05:58 2020 +0200
route: warn on IPv4 routes installation when no IPv4 is configured
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg19946.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Re: [Openvpn-devel] [PATCH v4 6/7] options: enable IPv4 redirection logic only if really required
In reply to Antonio QuartulliHi,
Quoted 8 lines · Antonio Quartulli
From: Antonio Quartulli <[email protected]...>
If no IPv4 redirection flag is set, do not enable the IPv4 redirection logic at all so that it won't bother adding any useless IPv4 route.
Trac: #208
Signed-off-by Antonio Quartulli <[email protected]...>
I can see why we want this - I tried to connect to a "v6-only-in-tunnel" server over v4, specifying "redirect-gateway !ipv4 ipv6", and it tried to install a v4 /32 redirect route...
Sun Jun 7 13:20:43 2020 net_route_v4_add: 199.102.77.82/32 via 193.149.48.190 dev [NULL] table 0 metric -1
... which is harmless, but "unnecesary fumbling" is not desirable.
The reason why I'm a bit unhappy about applying it is that it will change behaviour for the "redirect-private" case, and that might break people's setups. For "redirect-gateway" or "redirect-gateway def1" (etc), it will not change anything.
Can we make this conditional in a way that does not break "redirect-private"?
(I used to use "redirect-private" to handle overlapping IPv4 routes without actually redirecting the whole gateway - think "VPN server is on 192.0.2.1 and you want to push 'route 192.0.2.0/24'". IPv6 handles this automatically, but v4 needs "redirect-private" for that to work)
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]...Re: [Openvpn-devel] [PATCH v4 6/7] options: enable IPv4 redirection logic only if really required
Hi,
Quoted 1 line · Gert Doering
Can we make this conditional in a way that does not break "redirect-private"?
A very simple patch would be
if (streq(p[0], "redirect-gateway"))
{
options->routes->flags |= RG_REROUTE_GW;
}+ if (streq(p[0], "redirect-private"))
+ {
+ options->routes->flags |= RG_ENABLE;
+ }
and then take your patch as-is ("redirect-gateway with no options" would set RG_REROUTE_GW, which, if not cleared by !ipv4, would set RG_ENABLE later on, while "redirect-private" sets the RG_ENABLE itself).
Alternatively, set RG_ENABLE at the top (always), and clear it for "!ipv4"
else if (streq(p[j], "!ipv4"))
{
options->routes->flags &= ~(RG_REROUTE_GW|RG_ENABLE);
}... this should do the same thing, with less code convolutions.
Configs that have *both* "redirect-private" and "redirect-gateway !ipv4 ipv6" would still be broken. But I'm not sure such a config is well-defined in the first place.
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]...PATCH v5 1/1 options: enable IPv4 redirection logic only if really required
From: Antonio Quartulli <[email protected]...>
If no IPv4 redirection flag is set, do not enable the IPv4 redirection logic at all so that it won't bother adding any useless IPv4 route.
Trac: #208
---
Changes from v4:
- add warning about undefined behaviour when specifying redirect-gateway/private at the same time
- fix behaviour of redirect-private
Changes from v3:
- move error message modification to previous patch
Changes from v2:
- patchset rebased on top of pre-ipv6-only patchset
--- src/openvpn/options.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
src/openvpn/options.c +13 -2
@@ -6542,6 +6542,18 @@ add_option(struct options *options,int j;VERIFY_PERMISSION (OPT_P_ROUTE );rol_check_alloc (options); + +if (options->routes->flags &RG_ENABLE ) + { +msg (M_WARN , +"WARNING: You have specified redirect-gateway and " +"redirect-private at the same time (or the same option " +"multiple times). This is not well supported and may lead to " +"unexpected results" ); + } + + options->routes->flags |=RG_ENABLE ; +if (streq (p[0 ],"redirect-gateway" )) { options->routes->flags |=RG_REROUTE_GW ;
@@ -6579,7 +6591,7 @@ add_option(struct options *options, }else if (streq (p[j],"!ipv4" )) { - options->routes->flags &= ~RG_REROUTE_GW ; + options->routes->flags &= ~(RG_REROUTE_GW |RG_ENABLE ); }else {
@@ -6591,7 +6603,6 @@ add_option(struct options *options,/* we need this here to handle pushed --redirect-gateway */ remap_redirect_gateway_flags (options);#endif - options->routes->flags |=RG_ENABLE ; }else if (streq (p[0 ],"block-ipv6" ) && !p[1 ]) {
Signature · 1 line
2.27.0
Re: [Openvpn-devel] [PATCH v4 7/7] ipv6-pool: get rid of size constraint
In reply to Gert DoeringHi,
Quoted 5 lines · Gert Doering
My idea would be to make this conditional on the pool size - if the size is /64.../111, make it +0x1000 ("keep existing behaviour for large-enough pools"), if it's /112.../124, make it +2
Thoughts?
I think it makes sense, especially to preserve the current behaviour on already deployed setups.
New patch incoming!
Signature · 1 line
Antonio Quartulli
PATCH v5 1/1 ipv6-pool: get rid of size constraint
In reply to Gert Doering---
Changes from v4:
- make the base computation depending on the size of the pool:
- large pools will still start at +0x1000 (backward compatible)
- smaller pools will start at +2
src/openvpn/helper.c | 21 +++++++++++++++++---- src/openvpn/options.c | 13 +++++++++---- src/openvpn/pool.c | 12 ++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-)
src/openvpn/helper.c +17 -4
@@ -198,12 +198,25 @@ helper_client_server(struct options *o)print_in6_addr (add_in6_addr ( o->server_network_ipv6,2 ),0 , &o->gc ); o->ifconfig_ipv6_netbits = o->server_netbits_ipv6; -/* pool starts at "base address + 0x1000" - leave enough room */ -ASSERT ( o->server_netbits_ipv6 <=112 );/* want 16 bits */ +/* basic sanity check */ +ASSERT (o->server_netbits_ipv6 >=64 && o->server_netbits_ipv6 <=124 ); o->ifconfig_ipv6_pool_defined = true; - o->ifconfig_ipv6_pool_base = -add_in6_addr ( o->server_network_ipv6,0x1000 ); +/* For large enough pools we keep the original behaviour of adding +* 0x1000 when computing the base. +* +* Smaller pools can't get that far, therefore we just increase by 2 +*/ +if (o->server_netbits_ipv6 <112 ) + { + o->ifconfig_ipv6_pool_base =add_in6_addr (o->server_network_ipv6, +0x1000 ); + } +else + { + o->ifconfig_ipv6_pool_base =add_in6_addr (o->server_network_ipv6, +2 ); + } o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;push_option ( o,"tun-ipv6" ,M_USAGE );
src/openvpn/options.c +9 -4
@@ -6718,9 +6718,12 @@ add_option(struct options *options,msg (msglevel,"error parsing --server-ipv6 parameter" ); goto err; } -if (netbits <64 || netbits >112 ) +if (netbits <64 || netbits >124 ) { -msg ( msglevel,"--server-ipv6 settings: only /64../112 supported right now (not /%d)" , netbits ); +msg (msglevel, +"--server-ipv6 settings: network must be between /64 and /124 (not /%d)" , + netbits); + goto err; } options->server_ipv6_defined = true;
@@ -6840,9 +6843,11 @@ add_option(struct options *options,msg (msglevel,"error parsing --ifconfig-ipv6-pool parameters" ); goto err; } -if (netbits <64 || netbits >112 ) +if (netbits <64 || netbits >124 ) { -msg ( msglevel,"--ifconfig-ipv6-pool settings: only /64../112 supported right now (not /%d)" , netbits ); +msg (msglevel, +"--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%d)" , + netbits); goto err; }
src/openvpn/pool.c +12 -0
@@ -207,6 +207,12 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start,ASSERT (0 ); } +if (pool->ipv4.size <2 ) + { +msg (M_FATAL ,"IPv4 pool size is too small (%d), must be at least 2" , + pool->ipv4.size); + } +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv4: base=%s size=%d" ,print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size); }
@@ -245,6 +251,12 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ; +if (pool->ipv6.size <2 ) + { +msg (M_FATAL ,"IPv6 pool size is too small (%d), must be at least 2" , + pool->ipv6.size); + } +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: base=%s size=%d netbits=%d" ,print_in6_addr (pool->ipv6.base,0 , &gc), pool->ipv6.size, ipv6_netbits);
Signature · 1 line
2.27.0
[Openvpn-devel] [PATCH applied] Re: options: enable IPv4 redirection logic only if really required
In reply to Antonio QuartulliThanks :-)
Tested with "redirect-private", "redirect-gateway", "redirect-gateay !ipv4", and it seems to do what we want - not fumble any hostroutes if !ipv4 is set, but *do* fumble them if needed.
If you do "--redirect-private --redirect-gateway !ipv4 ipv6", it will unset the effect of "--redirect-private" (which is expected). If you do it the other way round, it will actually do what you told it to - redirect IPv6 default, and add a /32 host route for IPv4. So even in this somewhat very special case, we're not losing functionality, but if it might need reordering of config options.
There is changed behaviour for anything that has "!ipv4" in it - if you do "redirect-gateway !ipv4 block-local", before this patch, we'd "route the local lan into the tunnel, but not the default gateway" - now, we will just ignore the "block-local" bit. Anything with IPv4, actually, as RG_ENABLE gets dropped. This was not intentional, but it is actually making sense - you said "!ipv4", after all.
Your patch has been applied to the master branch.
commit 070319c13524125d8325a0df15fe795cc2a4bcf2
Author: Antonio Quartulli Date: Mon Jun 8 17:32:39 2020 +0200
options: enable IPv4 redirection logic only if really required
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/search?l=mid&[email protected]...
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
PATCH v6 1/1 ipv6-pool: get rid of size constraint
In reply to Antonio Quartulli---
Changes from v5:
- restyle base addr computation to avoid odd line wrapping
Changes from v4:
- make the base computation depending on the size of the pool:
- large pools will still start at +0x1000 (backward compatible)
- smaller pools will start at +2
src/openvpn/helper.c | 13 +++++++++---- src/openvpn/options.c | 13 +++++++++---- src/openvpn/pool.c | 12 ++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-)
src/openvpn/helper.c +9 -4
@@ -198,12 +198,17 @@ helper_client_server(struct options *o)print_in6_addr (add_in6_addr ( o->server_network_ipv6,2 ),0 , &o->gc ); o->ifconfig_ipv6_netbits = o->server_netbits_ipv6; -/* pool starts at "base address + 0x1000" - leave enough room */ -ASSERT ( o->server_netbits_ipv6 <=112 );/* want 16 bits */ +/* basic sanity check */ +ASSERT (o->server_netbits_ipv6 >=64 && o->server_netbits_ipv6 <=124 ); o->ifconfig_ipv6_pool_defined = true; - o->ifconfig_ipv6_pool_base = -add_in6_addr ( o->server_network_ipv6,0x1000 ); +/* For large enough pools we keep the original behaviour of adding +* 0x1000 when computing the base. +* +* Smaller pools can't get that far, therefore we just increase by 2 +*/ + o->ifconfig_ipv6_pool_base =add_in6_addr (o->server_network_ipv6, + o->server_netbits_ipv6 <112 ?0x1000 :2 ); o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;push_option ( o,"tun-ipv6" ,M_USAGE );
src/openvpn/options.c +9 -4
@@ -6718,9 +6718,12 @@ add_option(struct options *options,msg (msglevel,"error parsing --server-ipv6 parameter" ); goto err; } -if (netbits <64 || netbits >112 ) +if (netbits <64 || netbits >124 ) { -msg ( msglevel,"--server-ipv6 settings: only /64../112 supported right now (not /%d)" , netbits ); +msg (msglevel, +"--server-ipv6 settings: network must be between /64 and /124 (not /%d)" , + netbits); + goto err; } options->server_ipv6_defined = true;
@@ -6840,9 +6843,11 @@ add_option(struct options *options,msg (msglevel,"error parsing --ifconfig-ipv6-pool parameters" ); goto err; } -if (netbits <64 || netbits >112 ) +if (netbits <64 || netbits >124 ) { -msg ( msglevel,"--ifconfig-ipv6-pool settings: only /64../112 supported right now (not /%d)" , netbits ); +msg (msglevel, +"--ifconfig-ipv6-pool settings: network must be between /64 and /124 (not /%d)" , + netbits); goto err; }
src/openvpn/pool.c +12 -0
@@ -207,6 +207,12 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start,ASSERT (0 ); } +if (pool->ipv4.size <2 ) + { +msg (M_FATAL ,"IPv4 pool size is too small (%d), must be at least 2" , + pool->ipv4.size); + } +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv4: base=%s size=%d" ,print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size); }
@@ -245,6 +251,12 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ; +if (pool->ipv6.size <2 ) + { +msg (M_FATAL ,"IPv6 pool size is too small (%d), must be at least 2" , + pool->ipv6.size); + } +msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: base=%s size=%d netbits=%d" ,print_in6_addr (pool->ipv6.base,0 , &gc), pool->ipv6.size, ipv6_netbits);
Signature · 1 line
2.27.0
PATCH 1/1 Simplify pool size handling, fix possible array overrun on pool reading.
In reply to Antonio QuartulliRemove separate ipv4.size and ipv6.size in the pool structure, return to a single pool_size, which is also the allocated array size.
All calls to ifconfig_pool_size() change to "pool->size" now.
pool->size is set to the size of the active pool, or if both IPv4 and IPv6 are in use, to the smaller size (same underlying logic as in 452113155e7, but really put it into the size field).
This fixes a SIGSEGV crash if an ifconfig-pool-persist file is loaded that has IPv6 and no IPv4 (= ipv6 handle is used) and that has more entries than the IPv4 pool size (comparison was done with ipv6.size, not with actual pool size), introduced by commit 6a8cd033b18.
While at it, fix pool size calculation for IPv6 pools >= /112 (too many -1), introduced by commit 452113155e7.
--- src/openvpn/pool.c | 96 ++++++++++++++++++++-------------------------- src/openvpn/pool.h | 3 +- 2 files changed, 42 insertions(+), 57 deletions(-)
src/openvpn/pool.c +41 -55
@@ -59,29 +59,6 @@ ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard) } } -static const int -ifconfig_pool_size (const struct ifconfig_pool *pool) -{ -int min =INT_MAX ; - -if (!pool || (!pool->ipv4.enabled && !pool->ipv6.enabled)) - { -return 0 ; - } - -if (pool->ipv4.enabled) - { - min = pool->ipv4.size; - } - -if (pool->ipv6.enabled && pool->ipv6.size < min) - { - min = pool->ipv6.size; - } - -return min; -} -static int ifconfig_pool_find (struct ifconfig_pool *pool,const char *common_name) {
@@ -89,9 +66,8 @@ ifconfig_pool_find(struct ifconfig_pool *pool, const char *common_name)time_t earliest_release =0 ;int previous_usage =-1 ;int new_usage =-1 ; -int pool_size =ifconfig_pool_size (pool); -for (i =0 ; i < pool_size; ++i) +for (i =0 ; i < pool->size; ++i) {struct ifconfig_pool_entry *ipe = &pool->list[i];if (!ipe->in_use)
@@ -179,12 +155,13 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, {struct gc_arena gc =gc_new ();struct ifconfig_pool *pool =NULL ; -int pool_size =-1 ; +int pool_ipv4_size =-1 , pool_ipv6_size =-1 ;ASSERT (start <= end && end - start <IFCONFIG_POOL_MAX ); ALLOC_OBJ_CLEAR(pool, struct ifconfig_pool); pool->duplicate_cn = duplicate_cn; + pool->size =0 ; pool->ipv4.enabled = ipv4_pool;
@@ -195,26 +172,28 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, {case IFCONFIG_POOL_30NET : pool->ipv4.base = start & ~3 ; - pool->ipv4.size = (((end |3 ) +1 ) - pool->ipv4.base) >>2 ; + pool_ipv4_size = (((end |3 ) +1 ) - pool->ipv4.base) >>2 ;break ;case IFCONFIG_POOL_INDIV : pool->ipv4.base = start; - pool->ipv4.size = end - start +1 ; + pool_ipv4_size = end - start +1 ;break ;default :ASSERT (0 ); } -if (pool->ipv4.size <2 ) +if (pool_ipv4_size <2 ) {msg (M_FATAL ,"IPv4 pool size is too small (%d), must be at least 2" , - pool->ipv4.size); + pool_ipv4_size); }msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv4: base=%s size=%d" , -print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size); +print_in_addr_t (pool->ipv4.base,0 , &gc), pool_ipv4_size); + + pool->size = pool_ipv4_size; }/* IPv6 pools are always "INDIV" type */
@@ -239,49 +218,57 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start,* the address. * * Example: if we have netbits=31, the first bit has to be zero'd, -* the following operation first computes off=0x3fffff and then uses -* mask to extract the wanted bits from base +* the following operation first computes mask=0x3fffff and then +* uses mask to extract the wanted bits from base */ -uint32_t mask = (1 << (128 - ipv6_netbits -1 )) -1 ; +uint32_t mask = (1 << (128 - ipv6_netbits) ) -1 ; base &= mask; } pool->ipv6.base = ipv6_base; - pool->ipv6.size = ipv6_netbits >112 + pool_ipv6_size = ipv6_netbits >=112 ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ; -if (pool->ipv6.size <2 ) +if (pool_ipv6_size <2 ) {msg (M_FATAL ,"IPv6 pool size is too small (%d), must be at least 2" , - pool->ipv6.size); + pool_ipv6_size); }msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: base=%s size=%d netbits=%d" , -print_in6_addr (pool->ipv6.base,0 , &gc), pool->ipv6.size, +print_in6_addr (pool->ipv6.base,0 , &gc), pool_ipv6_size, ipv6_netbits); + +/* if there is no v4 pool, or the v6 pool is smaller, use +* v6 pool size as "unified pool size" +*/ +if ( pool->size <=0 || pool_ipv6_size < pool->size ) + { + pool->size = pool_ipv6_size; + } }if (pool->ipv4.enabled && pool->ipv6.enabled) { -if (pool->ipv4.size < pool->ipv6.size) +if (pool_ipv4_size < pool_ipv6_size) {msg (M_INFO ,"NOTE: IPv4 pool size is %d, IPv6 pool size is %d. " "IPv4 pool size limits the number of clients that can be " -"served from the pool" , pool->ipv4.size, pool->ipv6.size); +"served from the pool" , pool_ipv4_size, pool_ipv6_size); } -else if (pool->ipv4.size > pool->ipv6.size) +else if (pool_ipv4_size > pool_ipv6_size) {msg (M_WARN ,"WARNING: IPv4 pool size is %d, IPv6 pool size is %d. " "IPv6 pool size limits the number of clients that can be " "served from the pool. This is likely a MISTAKE - please check " -"your configuration" , pool->ipv4.size, pool->ipv6.size); +"your configuration" , pool_ipv4_size, pool_ipv6_size); } } - pool_size =ifconfig_pool_size (pool); +ASSERT (pool->size>0 ); - ALLOC_ARRAY_CLEAR(pool->list, struct ifconfig_pool_entry, pool_size); + ALLOC_ARRAY_CLEAR(pool->list, struct ifconfig_pool_entry, pool->size);gc_free (&gc);return pool;
@@ -292,9 +279,9 @@ ifconfig_pool_free(struct ifconfig_pool *pool) {if (pool) { -int i, pool_size =ifconfig_pool_size (pool); +int i; -for (i =0 ; i < pool_size; ++i) +for (i =0 ; i < pool->size; ++i) {ifconfig_pool_entry_free (&pool->list[i], true); }
@@ -358,9 +345,8 @@ bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard) { bool ret = false; -int pool_size =ifconfig_pool_size (pool); -if (pool && hand >=0 && hand < pool_size) +if (pool && hand >=0 && hand < pool->size) {ifconfig_pool_entry_free (&pool->list[hand], hard); ret = true;
@@ -396,7 +382,7 @@ ifconfig_pool_ip_base_to_handle(const struct ifconfig_pool *pool, const in_addr_ASSERT (0 ); } -if (ret <0 || ret >= pool->ipv4.size) +if (ret <0 || ret >= pool->size) { ret =-1 ; }
@@ -436,7 +422,7 @@ ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, | in_addr->s6_addr[15]; ret = addr - base; -if (ret <0 || ret >= pool->ipv6.size) +if (ret <0 || ret >= pool->size) { ret =-1 ; }
@@ -449,7 +435,7 @@ ifconfig_pool_handle_to_ip_base(const struct ifconfig_pool *pool, ifconfig_pool_ {in_addr_t ret =0 ; -if (pool->ipv4.enabled && hand >=0 && hand < pool->ipv4.size) +if (pool->ipv4.enabled && hand >=0 && hand < pool->size) {switch (pool->ipv4.type) {
@@ -479,7 +465,7 @@ ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool, ifconfig_poostruct in6_addr ret =IN6ADDR_ANY_INIT ;/* IPv6 pools are always INDIV (--linear) */ -if (pool->ipv6.enabled && hand >=0 && hand < pool->ipv6.size) +if (pool->ipv6.enabled && hand >=0 && hand < pool->size) { ret =add_in6_addr ( pool->ipv6.base, hand ); }
@@ -504,9 +490,9 @@ ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)if (pool && out) {struct gc_arena gc =gc_new (); -int i, pool_size =ifconfig_pool_size (pool); +int i; -for (i =0 ; i < pool_size; ++i) +for (i =0 ; i < pool->size; ++i) {const struct ifconfig_pool_entry *e = &pool->list[i];struct in6_addr ip6;
@@ -720,7 +706,7 @@ ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool **/ if (h >=0 ) { -msg (M_INFO ,"succeeded -> ifconfig_pool_set()" ); +msg (M_INFO ,"succeeded -> ifconfig_pool_set(hand=%d)" ,h);ifconfig_pool_set (pool, cn_buf, h, persist->fixed); } }
src/openvpn/pool.h +1 -2
@@ -55,13 +55,12 @@ struct ifconfig_poolbool enabled;enum pool_type type;in_addr_t base; -int size; } ipv4;struct {bool enabled;struct in6_addr base; -unsigned int size; } ipv6; +int size;struct ifconfig_pool_entry *list; };
Signature · 1 line
2.26.2
Re: [Openvpn-devel] [PATCH] Simplify pool size handling, fix possible array overrun on pool reading.
Hi,
Quoted 9 lines · Gert Doering
Remove separate ipv4.size and ipv6.size in the pool structure, return to a single
pool_size, which is also the allocated array size.All calls to
ifconfig_pool_size()change to "pool->size" now.
pool->sizeis set to the size of the active pool, or if both IPv4 and IPv6 are in use, to the smaller size (same underlying logic as in452113155e7, but really put it into the size field).
Quoted 7 lines
This fixes a SIGSEGV crash if an ifconfig-pool-persist file is loaded that has IPv6 and no IPv4 (= ipv6 handle is used) and that has more entries than the IPv4 pool size (comparison was done with ipv6.size, not with actual pool size), introduced by commit
6a8cd033b18.While at it, fix pool size calculation for IPv6 pools >= /112 (too many -1), introduced by commit
452113155e7.
Thanks for taking care of these issues :-)
Quoted 54 lines
Signed-off-by Gert Doering <[email protected]...>--- src/openvpn/pool.c | 96 ++++++++++++++++++++-------------------------- src/openvpn/pool.h | 3 +- 2 files changed, 42 insertions(+), 57 deletions(-)src/openvpn/pool.c +1
-25@@ -59,29 +59,6 @@ ifconfig_pool_entry_free(struct ifconfig_pool_entry *ipe, bool hard) } } -static const int -ifconfig_pool_size (const struct ifconfig_pool *pool) -{ -int min =INT_MAX ; - -if (!pool || (!pool->ipv4.enabled && !pool->ipv6.enabled)) - { -return 0 ; - } - -if (pool->ipv4.enabled) - { - min = pool->ipv4.size; - } - -if (pool->ipv6.enabled && pool->ipv6.size < min) - { - min = pool->ipv6.size; - } - -return min; -} -static int ifconfig_pool_find (struct ifconfig_pool *pool,const char *common_name) {@@ -89,9 +66,8 @@ ifconfig_pool_find(struct ifconfig_pool *pool, const char *common_name)time_t earliest_release =0 ;int previous_usage =-1 ;int new_usage =-1 ; -int pool_size =ifconfig_pool_size (pool); -for (i =0 ; i < pool_size; ++i) +for (i =0 ; i < pool->size; ++i) {struct ifconfig_pool_entry *ipe = &pool->list[i];if (!ipe->in_use)@@ -179,12 +155,13 @@ 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 164
Quoted 10 lines
src/openvpn/pool.c +2
-1struct gc_arena gc =gc_new ();struct ifconfig_pool *pool =NULL ; -int pool_size =-1 ; +int pool_ipv4_size =-1 , pool_ipv6_size =-1 ;ASSERT (start <= end && end - start <IFCONFIG_POOL_MAX ); ALLOC_OBJ_CLEAR(pool, struct ifconfig_pool); pool->duplicate_cn = duplicate_cn; + pool->size =0 ;
This is not needed. The object is already cleared out after allocation by the ALLOC_OBJ_CLEAR() macro.
Quoted 38 lines
src/openvpn/pool.c +7
-5pool->ipv4.enabled = ipv4_pool;@@ -195,26 +172,28 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, {case IFCONFIG_POOL_30NET : pool->ipv4.base = start & ~3 ; - pool->ipv4.size = (((end |3 ) +1 ) - pool->ipv4.base) >>2 ; + pool_ipv4_size = (((end |3 ) +1 ) - pool->ipv4.base) >>2 ;break ;case IFCONFIG_POOL_INDIV : pool->ipv4.base = start; - pool->ipv4.size = end - start +1 ; + pool_ipv4_size = end - start +1 ;break ;default :ASSERT (0 ); } -if (pool->ipv4.size <2 ) +if (pool_ipv4_size <2 ) {msg (M_FATAL ,"IPv4 pool size is too small (%d), must be at least 2" , - pool->ipv4.size); + pool_ipv4_size); }msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv4: base=%s size=%d" , -print_in_addr_t (pool->ipv4.base,0 , &gc), pool->ipv4.size); +print_in_addr_t (pool->ipv4.base,0 , &gc), pool_ipv4_size); + + pool->size = pool_ipv4_size; }/* IPv6 pools are always "INDIV" type */
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 224
Quoted 10 lines
src/openvpn/pool.c +3
-3@@ -239,49 +218,57 @@ ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start,* the address. * * Example: if we have netbits=31, the first bit has to be zero'd, -* the following operation first computes off=0x3fffff and then uses -* mask to extract the wanted bits from base +* the following operation first computes mask=0x3fffff and then +* uses mask to extract the wanted bits from base */ -uint32_t mask = (1 << (128 - ipv6_netbits -1 )) -1 ; +uint32_t mask = (1 << (128 - ipv6_netbits) ) -1 ;
please remove the space between the 2 parenthesis.
The computation now looks correct :-)
Quoted 16 lines
src/openvpn/pool.c +3
-3base &= mask; } pool->ipv6.base = ipv6_base; - pool->ipv6.size = ipv6_netbits >112 + pool_ipv6_size = ipv6_netbits >=112 ? (1 << (128 - ipv6_netbits)) - base :IFCONFIG_POOL_MAX ; -if (pool->ipv6.size <2 ) +if (pool_ipv6_size <2 ) {msg (M_FATAL ,"IPv6 pool size is too small (%d), must be at least 2" , - pool->ipv6.size); + pool_ipv6_size); }
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 246
Quoted 10 lines
src/openvpn/pool.c +6
-1msg (D_IFCONFIG_POOL ,"IFCONFIG POOL IPv6: base=%s size=%d netbits=%d" , -print_in6_addr (pool->ipv6.base,0 , &gc), pool->ipv6.size, +print_in6_addr (pool->ipv6.base,0 , &gc), pool_ipv6_size, ipv6_netbits); + +/* if there is no v4 pool, or the v6 pool is smaller, use +* v6 pool size as "unified pool size" +*/ +if ( pool->size <=0 || pool_ipv6_size < pool->size )
please remove the spaces after the opening and before the closing parenthesis.
Quoted 18 lines
src/openvpn/pool.c +6
-3+ { + pool->size = pool_ipv6_size; + } }if (pool->ipv4.enabled && pool->ipv6.enabled) { -if (pool->ipv4.size < pool->ipv6.size) +if (pool_ipv4_size < pool_ipv6_size) {msg (M_INFO ,"NOTE: IPv4 pool size is %d, IPv6 pool size is %d. " "IPv4 pool size limits the number of clients that can be " -"served from the pool" , pool->ipv4.size, pool->ipv6.size); +"served from the pool" , pool_ipv4_size, pool_ipv6_size); } -else if (pool->ipv4.size > pool->ipv6.size) +else if (pool_ipv4_size > pool_ipv6_size) {
src/openvpn/pool.c ifconfig_pool_init(const bool ipv4_pool, enum pool_type type, in_addr_t start, · line 269
Quoted 10 lines
src/openvpn/pool.c +2
-2msg (M_WARN ,"WARNING: IPv4 pool size is %d, IPv6 pool size is %d. " "IPv6 pool size limits the number of clients that can be " "served from the pool. This is likely a MISTAKE - please check " -"your configuration" , pool->ipv4.size, pool->ipv6.size); +"your configuration" , pool_ipv4_size, pool_ipv6_size); } } - pool_size =ifconfig_pool_size (pool); +ASSERT (pool->size>0 );
please add spaces around the '>' operator.
Asserting it sounds good - this happens during initialization and it's ok to abort in that case. However, we don't expect this to happen unless this function is misused by new code.
Quoted 96 lines
src/openvpn/pool.c +11
-12- ALLOC_ARRAY_CLEAR(pool->list, struct ifconfig_pool_entry, pool_size); + ALLOC_ARRAY_CLEAR(pool->list, struct ifconfig_pool_entry, pool->size);gc_free (&gc);return pool;@@ -292,9 +279,9 @@ ifconfig_pool_free(struct ifconfig_pool *pool) {if (pool) { -int i, pool_size =ifconfig_pool_size (pool); +int i; -for (i =0 ; i < pool_size; ++i) +for (i =0 ; i < pool->size; ++i) {ifconfig_pool_entry_free (&pool->list[i], true); }@@ -358,9 +345,8 @@ bool ifconfig_pool_release(struct ifconfig_pool *pool, ifconfig_pool_handle hand, const bool hard) { bool ret = false; -int pool_size =ifconfig_pool_size (pool); -if (pool && hand >=0 && hand < pool_size) +if (pool && hand >=0 && hand < pool->size) {ifconfig_pool_entry_free (&pool->list[hand], hard); ret = true;@@ -396,7 +382,7 @@ ifconfig_pool_ip_base_to_handle(const struct ifconfig_pool *pool, const in_addr_ASSERT (0 ); } -if (ret <0 || ret >= pool->ipv4.size) +if (ret <0 || ret >= pool->size) { ret =-1 ; }@@ -436,7 +422,7 @@ ifconfig_pool_ipv6_base_to_handle(const struct ifconfig_pool *pool, | in_addr->s6_addr[15]; ret = addr - base; -if (ret <0 || ret >= pool->ipv6.size) +if (ret <0 || ret >= pool->size) { ret =-1 ; }@@ -449,7 +435,7 @@ ifconfig_pool_handle_to_ip_base(const struct ifconfig_pool *pool, ifconfig_pool_ {in_addr_t ret =0 ; -if (pool->ipv4.enabled && hand >=0 && hand < pool->ipv4.size) +if (pool->ipv4.enabled && hand >=0 && hand < pool->size) {switch (pool->ipv4.type) {@@ -479,7 +465,7 @@ ifconfig_pool_handle_to_ipv6_base(const struct ifconfig_pool *pool, ifconfig_poostruct in6_addr ret =IN6ADDR_ANY_INIT ;/* IPv6 pools are always INDIV (--linear) */ -if (pool->ipv6.enabled && hand >=0 && hand < pool->ipv6.size) +if (pool->ipv6.enabled && hand >=0 && hand < pool->size) { ret =add_in6_addr ( pool->ipv6.base, hand ); }@@ -504,9 +490,9 @@ ifconfig_pool_list(const struct ifconfig_pool *pool, struct status_output *out)if (pool && out) {struct gc_arena gc =gc_new (); -int i, pool_size =ifconfig_pool_size (pool); +int i; -for (i =0 ; i < pool_size; ++i) +for (i =0 ; i < pool->size; ++i) {const struct ifconfig_pool_entry *e = &pool->list[i];struct in6_addr ip6;@@ -720,7 +706,7 @@ ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool **/ if (h >=0 ) { -msg (M_INFO ,"succeeded -> ifconfig_pool_set()" ); +msg (M_INFO ,"succeeded -> ifconfig_pool_set(hand=%d)" ,h);ifconfig_pool_set (pool, cn_buf, h, persist->fixed); } }src/openvpn/pool.h +0
-1@@ -55,13 +55,12 @@ struct ifconfig_poolbool enabled;enum pool_type type;in_addr_t base; -int size;
src/openvpn/pool.h struct ifconfig_pool · line 66
Quoted 10 lines
src/openvpn/pool.h +1
-1} ipv4;struct {bool enabled;struct in6_addr base; -unsigned int size; } ipv6; +int size;struct ifconfig_pool_entry *list; };
The rest looks good, thanks!
I am ACKing this patch under the assumption that those little changes are applied before merging:
Signature · 1 line
Antonio Quartulli
[Openvpn-devel] [PATCH applied] Re: ipv6-pool: get rid of size constraint
In reply to Antonio QuartulliStared-at-code and tested on the t_server machine. And crashed. But that was not actually *this* patch's fault, but 6a8cd033b18's (fixed).
This code does what it says on the lid - loosen up the "/112 is the minimum size" restriction on IPv6 pools, up to a /124 (which we can *now* handle correctly, as we do actual size calculations and checks).
At the same time it introduces a minimum size sanity check - a pool that has less than 2 free addresses left (::ffff/124) will error out.
(Which is not working right now, because the IPv6 pool size calculation is not correct yet for small pools - but that will be fixed with the next commit)
Your patch has been applied to the master branch.
commit 1379e5271d0057fcaed82d6985e614ca2ed8c265
Author: Antonio Quartulli Date: Mon Jun 8 22:16:13 2020 +0200
ipv6-pool: get rid of size constraint
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg20005.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [PATCH applied] Re: Simplify pool size handling, fix possible array overrun on pool reading.
In reply to Gert DoeringPatch has been applied to the master branch.
I have amended most whitespace as requested, and removed the "pool-> size = 0" initialization (not needed, indeed).
I have left the brackets on the pool size calculation as they were - uncrustify says "that is also ok", and I find visibly grouping the different parts of the formula helps understanding what it does.
commit e7c0cd996f35965172c5def9531b6ab9ca10c389
Author: Gert Doering Date: Tue Jun 9 10:02:29 2020 +0200
Simplify pool size handling, fix possible array overrun on pool reading.
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]/msg20006.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering