Skip to content

Commit

Permalink
Automatically enable ifconfig-exec/route-exec behaviour for afunix tu…
Browse files Browse the repository at this point in the history
…n/tap

Change-Id: I0a2957699757665d70514ba7cafe833443018ad6
Signed-off-by: Arne Schwabe <[email protected]>
  • Loading branch information
schwabe committed Sep 16, 2024
1 parent cb8178e commit 7b89c3f
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,17 @@ initialization_sequence_completed(struct context *c, const unsigned int flags)
#endif /* ifdef ENABLE_MANAGEMENT */
}

/**
* Determine if external route commands should be executed based on
* configured options and backend driver
*/
static bool
route_noexec_enabled(const struct options *o, const struct tuntap *tt)
{
return o->route_noexec
|| (tt && tt->backend_driver == DRIVER_AFUNIX);
}

/*
* Possibly add routes and/or call route-up script
* based on options.
Expand All @@ -1693,7 +1704,7 @@ do_route(const struct options *options,
openvpn_net_ctx_t *ctx)
{
bool ret = true;
if (!options->route_noexec && ( route_list || route_ipv6_list ) )
if (!route_noexec_enabled(options, tt) && ( route_list || route_ipv6_list ) )
{
ret = add_routes(route_list, route_ipv6_list, tt, ROUTE_OPTION_FLAGS(options),
es, ctx);
Expand Down Expand Up @@ -1858,6 +1869,18 @@ del_wfp_block(struct context *c, unsigned long adapter_index)
#endif
}

/**
* Determines if ifconfig execution should be disabled because of a
* @param c
* @return
*/
static bool
ifconfig_noexec_enabled(const struct context *c)
{
return c->options.ifconfig_noexec
|| (c->c1.tuntap && c->c1.tuntap->backend_driver == DRIVER_AFUNIX);
}

static void
open_tun_backend(struct context *c)
{
Expand Down Expand Up @@ -1937,7 +1960,7 @@ do_open_tun(struct context *c, int *error_flags)
}

/* do ifconfig */
if (!c->options.ifconfig_noexec
if (!ifconfig_noexec_enabled(c)
&& ifconfig_order(c->c1.tuntap) == IFCONFIG_BEFORE_TUN_OPEN)
{
/* guess actual tun/tap unit number that will be returned
Expand Down Expand Up @@ -1978,7 +2001,7 @@ do_open_tun(struct context *c, int *error_flags)
}

/* do ifconfig */
if (!c->options.ifconfig_noexec
if (!ifconfig_noexec_enabled(c)
&& ifconfig_order(c->c1.tuntap) == IFCONFIG_AFTER_TUN_OPEN)
{
do_ifconfig(c->c1.tuntap, c->c1.tuntap->actual_name,
Expand Down Expand Up @@ -2061,7 +2084,7 @@ do_close_tun_simple(struct context *c)

if (c->c1.tuntap)
{
if (!c->options.ifconfig_noexec)
if (!ifconfig_noexec_enabled(c))
{
undo_ifconfig(c->c1.tuntap, &c->net_ctx);
}
Expand Down

0 comments on commit 7b89c3f

Please sign in to comment.