Don't "undo" ifconfig on exit if it wasn't done
PATCH v4 1/1 Don't "undo" ifconfig on exit if it wasn't done
When running with --ifconfig-noexec, OpenVPN does not execute ifconfig, but on exit, it still tries to "undo" the configuration it would have done. This patch fixes it by extracting an undo_ifconfig() function from close_tun(). The undo function is called before close_tun(), but only if --ifconfig-noexec isn't set. This is symmetric to how open_tun() and do_ifconfig() are used.
This change also allows us to drop the second argument from close_tun().
v2: Fix tabs-vs-spaces.
v3: Fix another style mistake.
v4: Move undo_ifconfig{4,6}() out of #ifdef TARGET_LINUX.
--- src/openvpn/init.c | 9 ++- src/openvpn/tun.c | 187 +++++++++++++++++++++++---------------------- src/openvpn/tun.h | 13 +++- 3 files changed, 113 insertions(+), 96 deletions(-)
src/openvpn/init.c +6 -3
@@ -1072,8 +1072,7 @@ do_persist_tuntap(const struct options *options, openvpn_net_ctx_t *ctx)#ifdef ENABLE_FEATURE_TUN_PERSIST tuncfg (options->dev, options->dev_type, options->dev_node, options->persist_mode, - options->username, options->groupname, &options->tuntap_options, - ctx); + options->username, options->groupname, &options->tuntap_options);if (options->persist_mode && options->lladdr) {set_lladdr (ctx, options->dev, options->lladdr,NULL );
@@ -1858,7 +1857,11 @@ do_close_tun_simple(struct context *c)msg (D_CLOSE ,"Closing TUN/TAP interface" );if (c->c1.tuntap) { -close_tun (c->c1.tuntap, &c->net_ctx); +if (!c->options.ifconfig_noexec) + { +undo_ifconfig (c->c1.tuntap, &c->net_ctx); + } +close_tun (c->c1.tuntap); c->c1.tuntap =NULL ; } c->c1.tuntap_owned = false;
src/openvpn/tun.c +97 -90
280 lines not on this page · raw message
src/openvpn/tun.h +10 -3
@@ -247,7 +247,7 @@ tuntap_ring_empty(struct tuntap *tt)void open_tun (const char *dev,const char *dev_type,const char *dev_node,struct tuntap *tt); -void close_tun (struct tuntap *tt,openvpn_net_ctx_t *ctx); +void close_tun (struct tuntap *tt);int write_tun (struct tuntap *tt,uint8_t *buf,int len);
@@ -255,8 +255,7 @@ int read_tun(struct tuntap *tt, uint8_t *buf, int len);void tuncfg (const char *dev,const char *dev_type,const char *dev_node,int persist_mode,const char *username, -const char *groupname,const struct tuntap_options *options, -openvpn_net_ctx_t *ctx); +const char *groupname,const struct tuntap_options *options); const char *guess_tuntap_dev(const char *dev, const char *dev_type,
@@ -296,6 +295,14 @@ void do_ifconfig_setenv(const struct tuntap *tt,void do_ifconfig (struct tuntap *tt,const char *ifname,int tun_mtu,const struct env_set *es,openvpn_net_ctx_t *ctx); +/** +* undo_ifconfig - undo configuration of the tunnel interface +* +* @param tt the tuntap interface context +* @param ctx the networking API opaque context +*/ +void undo_ifconfig (struct tuntap *tt,openvpn_net_ctx_t *ctx); +bool is_dev_type (const char *dev,const char *dev_type,const char *match_type);int dev_type_enum (const char *dev,const char *dev_type);
Signature · 1 line
2.30.2
Hi,
Quoted 7 lines · Max Fillinger
When running with --ifconfig-noexec, OpenVPN does not execute ifconfig, but on exit, it still tries to "undo" the configuration it would have done. This patch fixes it by extracting an
undo_ifconfig()function fromclose_tun(). The undo function is called beforeclose_tun(), but only if --ifconfig-noexec isn't set. This is symmetric to howopen_tun()anddo_ifconfig()are used.
Quoted 7 lines
This change also allows us to drop the second argument from
close_tun().v2: Fix tabs-vs-spaces.
v3: Fix another style mistake.
v4: Move undo_ifconfig{4,6}() out of #ifdefTARGET_LINUX.Signed-off-by Max Fillinger <[email protected]...>
Max, something that I feared (and that now became reality with DCO) is that we would still need the net-ctx object in open/close_tun().
The reason is that the DCO interface is created/destroyed by means of the networking APIs, therefore the net-ctx object is still required...
If you rebase this patch on top of latest master you will see what I mean.
Unfortunately this patch as is does not apply and does not compile easily anymore.
Max how do you feel about re-spinning this and see how to better handle this situation?
Thanks!
Signature · 1 line
Antonio Quartulli