From patchwork Mon May 30 05:13:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maximilian Fillinger X-Patchwork-Id: 2499 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director15.mail.ord1d.rsapps.net ([172.31.255.6]) by backend41.mail.ord1d.rsapps.net with LMTP id aHxbCyrjlGIGEAAAqwncew (envelope-from ) for ; Mon, 30 May 2022 11:30:50 -0400 Received: from proxy10.mail.iad3b.rsapps.net ([172.31.255.6]) by director15.mail.ord1d.rsapps.net with LMTP id AI6CFyrjlGJ/UwAAIcMcQg (envelope-from ) for ; Mon, 30 May 2022 11:30:50 -0400 Received: from smtp3.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy10.mail.iad3b.rsapps.net with LMTPS id MHQmEirjlGJ1EAAA/F5p9A (envelope-from ) for ; Mon, 30 May 2022 11:30:50 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp3.gate.iad3b.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (key not found in DNS) header.d=foxcrypto.com; dmarc=fail (p=none; dis=none) header.from=foxcrypto.com X-Suspicious-Flag: YES X-Classification-ID: 7b5af40c-e02d-11ec-b67c-525400bb3479-1-1 Received: from [216.105.38.7] ([216.105.38.7:58332] helo=lists.sourceforge.net) by smtp3.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id B3/FE-15544-923E4926; Mon, 30 May 2022 11:30:49 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nvhL0-0005ys-2N; Mon, 30 May 2022 15:29:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nvhKz-0005ym-5c for openvpn-devel@lists.sourceforge.net; Mon, 30 May 2022 15:29:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Date:Subject:CC:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LzItsxlcvHpU5cYY909gROJtxvn8E7aA0ooVUkaDJNM=; b=NHf3R+PRaqEpYckB2TqTFoxuYp 2v9Ot1LcdJ43/IX7PELKyqZyqYm4GVMV9GB2SzgQMW3kXQ4MZRNx9UfJdApX9aLqSm0S+YLfJyn54 Xtj148uAdmMBzzTgF9m4uK54Z/EgdZlp5JYxd+LBp/GK8m0cUzoPMkA5gTQh+S5h7sv8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:CC:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=LzItsxlcvHpU5cYY909gROJtxvn8E7aA0ooVUkaDJNM=; b=E sw4iSOTZ4jTh1mjxNlKEkMOAOSfEuip9Pd7OyfFFjuC+gzpyKXd/7aFBxQ8OxsZExA81lte48Ntcz nyN/L0SCl4SmTMMzwfmXQo/8O4UNEhLRam+bEClX+k6AJquL4NEjG5Iiqt25nq/5cunSpzHQbxPdv 84hYQcJRXsNUAHG4=; Received: from nl-dft-mx-01.fox-it.com ([178.250.144.135]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nvhKx-003QvU-Qf for openvpn-devel@lists.sourceforge.net; Mon, 30 May 2022 15:29:45 +0000 From: Max Fillinger To: Date: Mon, 30 May 2022 17:13:53 +0200 Message-ID: <20220530151353.46435-1-maximilian.fillinger@foxcrypto.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-ClientProxiedBy: FOXDFT1EX01.FOX.local (10.0.0.129) To FOXDFT1EX01.FOX.local (10.0.0.129) X-FE-Policy-ID: 13:3:2:SYSTEM DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; d=foxcrypto.com; s=NL-DFT-MX-01; c=relaxed/relaxed; h=from:to:cc:subject:date:message-id:mime-version:content-type; bh=LzItsxlcvHpU5cYY909gROJtxvn8E7aA0ooVUkaDJNM=; b=0I1GLTtrlv2jR8ajuboFa1ifSGKFCq8aeIXpuNAmvSzsQw7vi+mJw4P9E8TqrbWAGTSzJYOSA091 Jn5fRr6OxgGAn8BMxy7ICygY8Ef6dkOUvdCxxi50L3OCb9sMlO0AVgbSixW65+6HEoyD1v4eJwpQ orVJFe8Y1hiyGoQF2H+Swhc4+lS/2O4bHnfwewTYKHSG3asIdioDNx4dS84tSsXwi8R6+8twkRBS tbo8gGLS4hdA8CkT/NjcHQO3EYY3BUU2zmS3GiRVwvMIVfYMIbH448UXzsGIPDwHihGvwxNsiOQn gL2eHmwNo0ULa+0wjAIveTelI5gMMfzwHKMBDw== X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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() [...] Content analysis details: (0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 T_SCC_BODY_TEXT_LINE No description available. 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid X-Headers-End: 1nvhKx-003QvU-Qf Subject: [Openvpn-devel] [PATCH v2] Don't "undo" ifconfig on exit if it wasn't done X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox 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. Signed-off-by: Max Fillinger --- src/openvpn/init.c | 5 ++++- src/openvpn/tun.c | 37 +++++++++++++++++++++---------------- src/openvpn/tun.h | 10 +++++++++- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index b0c62a85..87f825c2 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1858,7 +1858,10 @@ 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; diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index e12f0369..015bf46d 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -1910,7 +1910,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun } void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -2073,7 +2073,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun 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 struct tuntap_options *options) { struct tuntap *tt; @@ -2112,7 +2112,7 @@ tuncfg(const char *dev, const char *dev_type, const char *dev_node, msg(M_ERR, "Cannot ioctl TUNSETGROUP(%s) %s", groupname, dev); } } - close_tun(tt, ctx); + close_tun(tt); msg(M_INFO, "Persist state set to: %s", (persist_mode ? "ON" : "OFF")); } @@ -2179,10 +2179,8 @@ undo_ifconfig_ipv6(struct tuntap *tt, openvpn_net_ctx_t *ctx) } void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +undo_ifconfig(struct tuntap *tt, openvpn_net_ctx_t *ctx) { - ASSERT(tt); - if (tt->type != DEV_TYPE_NULL) { if (tt->did_ifconfig_setup) @@ -2199,6 +2197,13 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) net_ctx_reset(ctx); } +} + +void +close_tun(struct tuntap *tt) +{ + ASSERT(tt); + close_tun_generic(tt); free(tt); } @@ -2513,7 +2518,7 @@ solaris_close_tun(struct tuntap *tt) * Close TUN device. */ void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -2546,7 +2551,7 @@ solaris_error_close(struct tuntap *tt, const struct env_set *es, argv_msg(M_INFO, &argv); openvpn_execve_check(&argv, es, 0, "Solaris ifconfig unplumb failed"); - close_tun(tt, NULL); + close_tun(tt); msg(M_FATAL, "Solaris ifconfig failed"); argv_free(&argv); } @@ -2609,7 +2614,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun */ void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -2695,7 +2700,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun * need to be explicitly destroyed */ void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -2836,7 +2841,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun * we need to call "ifconfig ... destroy" for cleanup */ void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -2952,7 +2957,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun } void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -3218,7 +3223,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun } void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -3366,7 +3371,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun /* tap devices need to be manually destroyed on AIX */ void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -6704,7 +6709,7 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc } void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); @@ -6887,7 +6892,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun } void -close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) +close_tun(struct tuntap *tt) { ASSERT(tt); diff --git a/src/openvpn/tun.h b/src/openvpn/tun.h index 4bc35916..71c31e8d 100644 --- a/src/openvpn/tun.h +++ b/src/openvpn/tun.h @@ -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); @@ -296,6 +296,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);