From patchwork Thu Jun 23 22:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 2538 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend41.mail.ord1d.rsapps.net with LMTP id sAEKJm5/tWJBXgAAqwncew (envelope-from ) for ; Fri, 24 Jun 2022 05:10:06 -0400 Received: from proxy1.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net with LMTP id +Hn0JW5/tWIJLQAAovjBpQ (envelope-from ) for ; Fri, 24 Jun 2022 05:10:06 -0400 Received: from smtp8.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy1.mail.iad3b.rsapps.net with LMTPS id KEmHIG5/tWLvQAAALM5PBw (envelope-from ) for ; Fri, 24 Jun 2022 05:10:06 -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: smtp8.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; dmarc=none (p=nil; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: 6fcfd7c8-f39d-11ec-a865-5254005eee35-1-1 Received: from [216.105.38.7] ([216.105.38.7:32878] helo=lists.sourceforge.net) by smtp8.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 5D/7B-12116-D6F75B26; Fri, 24 Jun 2022 05:10:06 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1o4fJS-0001dh-Aj; Fri, 24 Jun 2022 09:09:13 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1o4fJR-0001db-1i for openvpn-devel@lists.sourceforge.net; Fri, 24 Jun 2022 09:09:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=V/4Ky9qFBtn7Md0W6Bb80xSzrClVjAVwQ9sB41QgzO0=; b=XnZ5DwDuRmlg40HVFyoKCZZe+d q/9KNcTPqoq36tNyaAbdtsIhZyklfdoBSuiRmarE/bTWFZFXGQNTuxwotLWsNt38U/8Rf+jtJBXwB fiqzTsShcJBrQIFts9CmIFLFXcyscXQ3ST6hXcEya/cnVcLxoFh16YNPG+VNlFWhIw08=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=V/4Ky9qFBtn7Md0W6Bb80xSzrClVjAVwQ9sB41QgzO0=; b=g8HhdZmBv99nD/d7nCdx5eE09x NcezIiEdkv4cxV7LqOcPQPyHdQ7yJvAMDOEl1FF4DENrKm22XBid2YzUUjdJblBYjGgVw7T3f0Rdy hkqHtSztbT+yyiA2vzGIX91u4I8Hxe/aLGAM7uDohFJ1U+/p1mvBrSScXrCRuX7JqkF4=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1o4fJO-0005zs-Kd for openvpn-devel@lists.sourceforge.net; Fri, 24 Jun 2022 09:09:11 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Fri, 24 Jun 2022 10:38:01 +0200 Message-Id: <20220624083809.23487-18-a@unstable.cc> In-Reply-To: <20220624083809.23487-1-a@unstable.cc> References: <20220624083809.23487-1-a@unstable.cc> MIME-Version: 1.0 X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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: From: Arne Schwabe This moves closing the tun handle into its own function and also prints the adapter type we are operating on, instead hardcoding it to tap-windows. While at it, set the handle to NULL after closing, to prevent a double close due to multiple invocations of this helper. Content analysis details: (-0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-Headers-End: 1o4fJO-0005zs-Kd Subject: [Openvpn-devel] [PATCH 17/25] tun: extract close_tun_handle into its own fucntion and print correct type 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: , Cc: Antonio Quartulli Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Arne Schwabe This moves closing the tun handle into its own function and also prints the adapter type we are operating on, instead hardcoding it to tap-windows. While at it, set the handle to NULL after closing, to prevent a double close due to multiple invocations of this helper. Signed-off-by: Arne Schwabe Signed-off-by: Antonio Quartulli Acked-By: Frank Lichtenheld --- src/openvpn/tun.c | 76 ++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 5eefb0c6..f324ac91 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -6767,6 +6767,47 @@ netsh_delete_address_dns(const struct tuntap *tt, bool ipv6, struct gc_arena *gc argv_free(&argv); } +static void +close_tun_handle(struct tuntap *tt) +{ + const char *adaptertype = print_windows_driver(tt->windows_driver); + + if (tt->hand) + { + dmsg(D_WIN32_IO_LOW, "Attempting CancelIO on %s adapter", adaptertype); + if (!CancelIo(tt->hand)) + { + msg(M_WARN | M_ERRNO, "Warning: CancelIO failed on %s adapter", adaptertype); + } + } + + dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped read event on %s adapter", adaptertype); + overlapped_io_close(&tt->reads); + + dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped write event on %s adapter", adaptertype); + overlapped_io_close(&tt->writes); + + if (tt->hand) + { + dmsg(D_WIN32_IO_LOW, "Attempting CloseHandle on %s adapter", adaptertype); + if (!CloseHandle(tt->hand)) + { + msg(M_WARN | M_ERRNO, "Warning: CloseHandle failed on %s adapter", adaptertype); + } + tt->hand = NULL; + } + + if (tt->windows_driver == WINDOWS_DRIVER_WINTUN) + { + CloseHandle(tt->rw_handle.read); + CloseHandle(tt->rw_handle.write); + UnmapViewOfFile(tt->wintun_send_ring); + UnmapViewOfFile(tt->wintun_receive_ring); + CloseHandle(tt->wintun_send_ring_handle); + CloseHandle(tt->wintun_receive_ring_handle); + } +} + void close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) { @@ -6836,43 +6877,10 @@ close_tun(struct tuntap *tt, openvpn_net_ctx_t *ctx) dhcp_release(tt); - if (tt->hand != NULL) - { - dmsg(D_WIN32_IO_LOW, "Attempting CancelIO on TAP-Windows adapter"); - if (!CancelIo(tt->hand)) - { - msg(M_WARN | M_ERRNO, "Warning: CancelIO failed on TAP-Windows adapter"); - } - } - - dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped read event on TAP-Windows adapter"); - overlapped_io_close(&tt->reads); - - dmsg(D_WIN32_IO_LOW, "Attempting close of overlapped write event on TAP-Windows adapter"); - overlapped_io_close(&tt->writes); - - if (tt->hand != NULL) - { - dmsg(D_WIN32_IO_LOW, "Attempting CloseHandle on TAP-Windows adapter"); - if (!CloseHandle(tt->hand)) - { - msg(M_WARN | M_ERRNO, "Warning: CloseHandle failed on TAP-Windows adapter"); - } - } + close_tun_handle(tt); free(tt->actual_name); - if (tt->windows_driver == WINDOWS_DRIVER_WINTUN) - { - CloseHandle(tt->rw_handle.read); - CloseHandle(tt->rw_handle.write); - UnmapViewOfFile(tt->wintun_send_ring); - UnmapViewOfFile(tt->wintun_receive_ring); - CloseHandle(tt->wintun_send_ring_handle); - CloseHandle(tt->wintun_receive_ring_handle); - } - - clear_tuntap(tt); free(tt); gc_free(&gc);