From patchwork Thu Dec 19 11:39:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 948 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.31.255.6]) by backend30.mail.ord1d.rsapps.net with LMTP id 2Mj1HXL8+10jLgAAIUCqbw for ; Thu, 19 Dec 2019 17:40:50 -0500 Received: from proxy15.mail.iad3b.rsapps.net ([172.31.255.6]) by director7.mail.ord1d.rsapps.net with LMTP id GLckG3L8+124UAAAovjBpQ ; Thu, 19 Dec 2019 17:40:50 -0500 Received: from smtp40.gate.iad3b ([172.31.255.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy15.mail.iad3b.rsapps.net with LMTP id cOYbFXL8+12LLQAAhyf7VQ ; Thu, 19 Dec 2019 17:40:50 -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: smtp40.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 (signature verification failed) header.d=rozman.si; dmarc=fail (p=none; dis=none) header.from=rozman.si X-Suspicious-Flag: YES X-Classification-ID: 9ab1432a-22b0-11ea-b6bb-5254000cc6d4-1-1 Received: from [216.105.38.7] ([216.105.38.7:51984] helo=lists.sourceforge.net) by smtp40.gate.iad3b.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id C9/43-16219-17CFBFD5; Thu, 19 Dec 2019 17:40:50 -0500 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1ii4Sd-00042t-9K; Thu, 19 Dec 2019 22:39:59 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ii4SX-00041y-Si for openvpn-devel@lists.sourceforge.net; Thu, 19 Dec 2019 22:39:53 +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=9Mrkeh9kyJKVNK6suSHMZIzwMlPJAjNsNBoJRHv5Eu8=; b=l/GNxU7IBWOP82n/ooOOZCo+vk 44yE/PtvjgeC1zNXbUXX+zQRUIlKHWYWVVoReXqoEkVcJOiBjWYYFDyUX2CBcrAYAdrhMBWQYBi1w 8Nqm0kVMrD0M/++p41sHYyZBhucOQJK0um5/TtjIQV201JqJUslKWoJJcvHUNjffzDZc=; 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=9Mrkeh9kyJKVNK6suSHMZIzwMlPJAjNsNBoJRHv5Eu8=; b=i+YSZ9CVnO7OFReidgb+e1X3Kw XONp7IQGpL2Y4H05OvPVB1JIGUVwca+sNLc5VE2xOwGSUxQsLaDWTsDL7qnIAazoi1oWGeADaa7KU /pQ7fTjnLkz5mN4gr4nNNcguxuJatVTPyecTx/FH3C6bX2zp9fdTSSxWqwX4uXCweG+o=; Received: from pub5.amebis.si ([213.250.55.21]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1ii4SV-00AO0u-Hx for openvpn-devel@lists.sourceforge.net; Thu, 19 Dec 2019 22:39:53 +0000 Received: by pub5.amebis.si (Postfix, from userid 1000) id EDDCB1002FBA; Thu, 19 Dec 2019 23:39:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rozman.si; s=default; t=1576795177; bh=9Mrkeh9kyJKVNK6suSHMZIzwMlPJAjNsNBoJRHv5Eu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpYFE74iOgJHHfp15dS09sJFR9hM561+T1W9waPOs08Ndl4fvJy3c+SLb8KoKPzAj OAcgDmwIF/UmSnukQTUxOCvx2ombZ+AfWePtn2aGCujfAGVOIMGuNtNgO9e9zouPJ4 Y/2zIt3lSkCjVrGbVs7otx9JBUcd3WY9yA8GfLIg= X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on brana.amebis.doma X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.2 Received: from SR6.amebis.doma (unknown [IPv6:2a00:ee2:209:164:99ff:8a54:cadf:8a38]) by pub5.amebis.si (Postfix) with ESMTP id E3FE11002FBD; Thu, 19 Dec 2019 23:39:30 +0100 (CET) From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Thu, 19 Dec 2019 23:39:14 +0100 Message-Id: <20191219223917.1614-4-simon@rozman.si> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20191219223917.1614-1-simon@rozman.si> References: <20191219223917.1614-1-simon@rozman.si> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rozman.si] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.1 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1ii4SV-00AO0u-Hx Subject: [Openvpn-devel] [PATCH 4/7] wintun: register ring buffers when iterating adapters 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 Wintun adapters may be considered available if ring buffer registration succeeded. Therefore, we must attempt to register ring buffers when iterating adapters and continue on failure. Signed-off-by: Simon Rozman --- src/openvpn/tun.c | 110 +++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 46 deletions(-) diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 220dee87..9dc9b3a2 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -6129,11 +6129,71 @@ tuntap_dhcp_mask(const struct tuntap *tt, const char *device_guid) gc_free(&gc); } +static bool +tun_try_open_device(struct tuntap *tt, const char *device_guid, const struct device_instance_id_interface *device_instance_id_interface) +{ + const char *path = NULL; + char tuntap_device_path[256]; + + if (tt->wintun) + { + const struct device_instance_id_interface *dev_if; + + /* Open Wintun adapter */ + for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next) + { + if (strcmp(dev_if->net_cfg_instance_id, device_guid) == 0) + { + path = dev_if->device_interface_list; + break; + } + } + if (path == NULL) + { + return false; + } + } + else + { + /* Open TAP-Windows adapter */ + openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s", + USERMODEDEVICEDIR, + device_guid, + TAP_WIN_SUFFIX); + path = tuntap_device_path; + } + + tt->hand = CreateFile(path, + GENERIC_READ | GENERIC_WRITE, + 0, /* was: FILE_SHARE_READ */ + 0, + OPEN_EXISTING, + FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, + 0); + + if (tt->hand == INVALID_HANDLE_VALUE) + { + msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "Wintun" : "TAP-Windows", path); + return false; + } + + if (tt->wintun) + { + /* Wintun adapter may be considered "open" after ring buffers are successfuly registered. */ + if (!wintun_register_ring_buffer(tt)) + { + msg(D_TUNTAP_INFO, "Failed to register %s adapter ring buffers", device_guid); + return false; + } + } + + return true; +} + static void tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_guid) { struct gc_arena gc = gc_new(); - char *path = NULL; char tuntap_device_path[256]; const struct tap_reg* tap_reg = get_tap_reg(&gc); const struct panel_reg* panel_reg = get_panel_reg(&gc); @@ -6197,27 +6257,11 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui if (tt->wintun) { - const struct device_instance_id_interface* dev_if; - if (!is_picked_device_wintun) { /* wintun driver specified but picked adapter is not wintun, proceed to next one */ goto next; } - - path = NULL; - for (dev_if = device_instance_id_interface; dev_if != NULL; dev_if = dev_if->next) - { - if (strcmp(dev_if->net_cfg_instance_id, *device_guid) == 0) - { - path = (char*)dev_if->device_interface_list; - break; - } - } - if (path == NULL) - { - goto next; - } } else { @@ -6226,28 +6270,9 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui /* tap-windows6 driver specified but picked adapter is wintun, proceed to next one */ goto next; } - - /* Open Windows TAP-Windows adapter */ - openvpn_snprintf(tuntap_device_path, sizeof(tuntap_device_path), "%s%s%s", - USERMODEDEVICEDIR, - *device_guid, - TAP_WIN_SUFFIX); - path = tuntap_device_path; } - tt->hand = CreateFile(path, - GENERIC_READ | GENERIC_WRITE, - 0, /* was: FILE_SHARE_READ */ - 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, - 0); - - if (tt->hand == INVALID_HANDLE_VALUE) - { - msg(D_TUNTAP_INFO, "CreateFile failed on %s device: %s", tt->wintun ? "wintun" : "TAP", tuntap_device_path); - } - else + if (tun_try_open_device(tt, *device_guid, device_instance_id_interface)) { break; } @@ -6261,7 +6286,7 @@ tun_open_device(struct tuntap *tt, const char *dev_node, const char **device_gui * GUID using the registry */ tt->actual_name = string_alloc(actual_buffer, NULL); - msg(M_INFO, "%s device [%s] opened: %s", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name, path); + msg(M_INFO, "%s device [%s] opened", tt->wintun ? "Wintun" : "TAP-WIN32", tt->actual_name); tt->adapter_index = get_adapter_index(*device_guid); gc_free(&gc); @@ -6372,14 +6397,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun tun_open_device(tt, dev_node, &device_guid); - if (tt->wintun) - { - if (!wintun_register_ring_buffer(tt)) - { - msg(M_FATAL, "Failed to register ring buffers"); - } - } - else + if (!tt->wintun) { tuntap_post_open(tt, device_guid); }