Skip to content

Commit

Permalink
Use topology default of "subnet" only for server mode
Browse files Browse the repository at this point in the history
The setting of --topology changes the syntax of --ifconfig.
So changing the default of --topology breaks all existing
configs that use --ifconfig but not --topology.

For P2P setups that is probably a signification percentage.
For server setups the percentage is hopefully lower since
--ifconfig is implicitly set by --server. Also more people
might have set their topology explicitly since it makes a
much bigger difference. Clients will usually get the
topology and the IP config pushed by the server.

So we decided to not switch the default for everyone to
not affect P2P setups. What we care about is to change
the default for --mode server, so we only do that now. For
people using --server this should be transparent except
for a pool reset.

Github: #529
Change-Id: Iefd209c0856ef395ab74055496130de00b86ead0
Signed-off-by: Frank Lichtenheld <[email protected]>
Acked-by: Arne Schwabe <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg28592.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
flichtenheld authored and cron2 committed May 1, 2024
1 parent d4eb413 commit 066fcdb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
11 changes: 6 additions & 5 deletions Changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ NTLMv1 authentication support for HTTP proxies has been removed.
``persist-key`` option has been enabled by default.
All the keys will be kept in memory across restart.

Default for ``--topology`` changed to ``subnet``
Previous releases used ``net30`` as default. This only affects
configs with ``--dev tun`` and only IPv4. Note that this
changes the semantics of ``--ifconfig``, so if you have manual
settings for that in your config but not set ``--topology``
Default for ``--topology`` changed to ``subnet`` for ``--mode server``
Previous releases always used ``net30`` as default. This only affects
configs with ``--mode server`` or ``--server`` (the latter implies the
former), and ``--dev tun``, and only if IPv4 is enabled.
Note that this changes the semantics of ``--ifconfig``, so if you have
manual settings for that in your config but not set ``--topology``
your config might fail to parse with the new version. Just adding
``--topology net30`` to the config should fix the problem.
By default ``--topology`` is pushed from server to client.
Expand Down
47 changes: 37 additions & 10 deletions src/openvpn/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ verify_common_subnet(const char *opt, const in_addr_t a, const in_addr_t b, cons
}


/**
* Set --topology default depending on --mode
*/
void
helper_setdefault_topology(struct options *o)
{
if (o->topology != TOP_UNDEF)
{
return;
}
int dev = dev_type_enum(o->dev, o->dev_type);
if (dev != DEV_TYPE_TUN)
{
return;
}
if (o->mode == MODE_SERVER)
{
o->topology = TOP_SUBNET;
}
else
{
o->topology = TOP_NET30;
}
}


/*
* Process server, server-bridge, and client helper
* directives after the parameters themselves have been
Expand All @@ -151,7 +177,6 @@ helper_client_server(struct options *o)
* Get tun/tap/null device type
*/
const int dev = dev_type_enum(o->dev, o->dev_type);
const int topology = o->topology;

/*
*
Expand All @@ -177,11 +202,11 @@ helper_client_server(struct options *o)

if (o->server_flags & SF_NOPOOL)
{
msg( M_USAGE, "--server-ipv6 is incompatible with 'nopool' option" );
msg(M_USAGE, "--server-ipv6 is incompatible with 'nopool' option");
}
if (o->ifconfig_ipv6_pool_defined)
{
msg( M_USAGE, "--server-ipv6 already defines an ifconfig-ipv6-pool, so you can't also specify --ifconfig-pool explicitly");
msg(M_USAGE, "--server-ipv6 already defines an ifconfig-ipv6-pool, so you can't also specify --ifconfig-pool explicitly");
}

o->mode = MODE_SERVER;
Expand All @@ -207,7 +232,7 @@ helper_client_server(struct options *o)
o->server_netbits_ipv6 < 112 ? 0x1000 : 2);
o->ifconfig_ipv6_pool_netbits = o->server_netbits_ipv6;

push_option( o, "tun-ipv6", M_USAGE );
push_option(o, "tun-ipv6", M_USAGE);
}

/*
Expand Down Expand Up @@ -305,8 +330,10 @@ helper_client_server(struct options *o)

o->mode = MODE_SERVER;
o->tls_server = true;
/* Need to know topology now */
helper_setdefault_topology(o);

if (topology == TOP_NET30 || topology == TOP_P2P)
if (o->topology == TOP_NET30 || o->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);
Expand All @@ -324,12 +351,12 @@ helper_client_server(struct options *o)
{
push_option(o, print_opt_route(o->server_network, o->server_netmask, &o->gc), M_USAGE);
}
else if (topology == TOP_NET30)
else if (o->topology == TOP_NET30)
{
push_option(o, print_opt_route(o->server_network + 1, 0, &o->gc), M_USAGE);
}
}
else if (topology == TOP_SUBNET)
else if (o->topology == TOP_SUBNET)
{
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);
Expand All @@ -354,9 +381,9 @@ helper_client_server(struct options *o)
ASSERT(0);
}

push_option(o, print_opt_topology(topology, &o->gc), M_USAGE);
push_option(o, print_opt_topology(o->topology, &o->gc), M_USAGE);

if (topology == TOP_NET30 && !(o->server_flags & SF_NOPOOL))
if (o->topology == TOP_NET30 && !(o->server_flags & SF_NOPOOL))
{
msg(M_WARN, "WARNING: --topology net30 support for server "
"configs with IPv4 pools will be removed in a future "
Expand Down Expand Up @@ -394,7 +421,7 @@ helper_client_server(struct options *o)
}

/* set push-ifconfig-constraint directive */
if ((dev == DEV_TYPE_TAP || topology == TOP_SUBNET))
if ((dev == DEV_TYPE_TAP || o->topology == TOP_SUBNET))
{
o->push_ifconfig_constraint_defined = true;
o->push_ifconfig_constraint_network = o->server_network;
Expand Down
2 changes: 2 additions & 0 deletions src/openvpn/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "options.h"

void helper_setdefault_topology(struct options *o);

void helper_keepalive(struct options *o);

void helper_client_server(struct options *o);
Expand Down
5 changes: 4 additions & 1 deletion src/openvpn/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ init_options(struct options *o, const bool init_gc)
o->gc_owned = true;
}
o->mode = MODE_POINT_TO_POINT;
o->topology = TOP_SUBNET;
o->topology = TOP_UNDEF;
o->ce.proto = PROTO_UDP;
o->ce.af = AF_UNSPEC;
o->ce.bind_ipv6_only = false;
Expand Down Expand Up @@ -3478,6 +3478,7 @@ options_postprocess_verify(const struct options *o)
}
}


/**
* Checks for availibility of Chacha20-Poly1305 and sets
* the ncp_cipher to either AES-256-GCM:AES-128-GCM or
Expand Down Expand Up @@ -3680,6 +3681,8 @@ options_postprocess_mutate(struct options *o, struct env_set *es)
* sequences of options.
*/
helper_client_server(o);
/* must be called after helpers that might set --mode */
helper_setdefault_topology(o);
helper_keepalive(o);
helper_tcp_nodelay(o);

Expand Down

0 comments on commit 066fcdb

Please sign in to comment.