From patchwork Tue Dec 7 01:11:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 2115 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director15.mail.ord1d.rsapps.net ([172.27.255.57]) by backend41.mail.ord1d.rsapps.net with LMTP id 6GIhJdtPr2EoLgAAqwncew (envelope-from ) for ; Tue, 07 Dec 2021 07:13:15 -0500 Received: from proxy2.mail.iad3a.rsapps.net ([172.27.255.57]) by director15.mail.ord1d.rsapps.net with LMTP id GDiyNNtPr2FzfgAAIcMcQg (envelope-from ) for ; Tue, 07 Dec 2021 07:13:15 -0500 Received: from smtp33.gate.iad3a ([172.27.255.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy2.mail.iad3a.rsapps.net with LMTPS id EH4WLttPr2GJBgAABcWvHw (envelope-from ) for ; Tue, 07 Dec 2021 07:13:15 -0500 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: smtp33.gate.iad3a.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: 0de1f6f0-5757-11ec-8e4c-525400201c3f-1-1 Received: from [216.105.38.7] ([216.105.38.7:52880] helo=lists.sourceforge.net) by smtp33.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id C9/DB-08843-BDF4FA16; Tue, 07 Dec 2021 07:13:15 -0500 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 1muZKU-0002wD-Rl; Tue, 07 Dec 2021 12:12:18 +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 1muZKN-0002vd-6r for openvpn-devel@lists.sourceforge.net; Tue, 07 Dec 2021 12:12: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=txIlf29MTlgqHwmqcyP9f35HujIfPMA7e7DR4Y+Sf84=; b=NyZhopQy1eUEKXUAmsqZme2UET xkidbk8ppPGfCY7X9QZw7J7lCO8rL/iPeiXBoaIpPGbbyiqjDPQyEKulWhFTSFZDhMt1lQw+ClRV4 J7mQMfbPhq3dufX5LktD9cYR3Gq5VQoG/z6vxObjLN0r0w8N7mqd+PnSB9BFp7t3mJvU=; 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=txIlf29MTlgqHwmqcyP9f35HujIfPMA7e7DR4Y+Sf84=; b=CmgnmTYKPdi7szlGKst3VonrwC GsnkHai8oAEFEnwjMDCP/o8b74ric6iJDVSNinN5PbVxSW8vsOKPOeFcpES3hyplH//NJC6H5dP73 J3xUcQBBNtwxd7EcGO6/lpmFNlNl0jjf2wrm7RkOs4Ohvs9TrGt9QsxG7kN8Q+xrKf08=; Received: from s2.neomailbox.net ([5.148.176.60]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) id 1muZKJ-0008P6-B6 for openvpn-devel@lists.sourceforge.net; Tue, 07 Dec 2021 12:12:10 +0000 From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Tue, 7 Dec 2021 13:11:34 +0100 Message-Id: <20211207121137.3221-6-a@unstable.cc> In-Reply-To: <20211207121137.3221-1-a@unstable.cc> References: <20211207121137.3221-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. Signed-off-by: Arne Schwabe Signed-off-by: Antonio Quartulli --- src/openvpn/tun.c | 75 ++++++++++++++++++++++++++ 1 file changed, 41 insertions [...] Content analysis details: (0.0 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 X-Headers-End: 1muZKJ-0008P6-B6 Subject: [Openvpn-devel] [RFC 5/8] 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. Signed-off-by: Arne Schwabe Signed-off-by: Antonio Quartulli --- src/openvpn/tun.c | 75 ++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index fb3c2e8b..d8634ebf 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -6780,6 +6780,46 @@ 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 != NULL) + { + 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 != NULL) + { + 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) { @@ -6849,43 +6889,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);