From patchwork Sun Dec 29 14:17:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4030 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:998b:b0:5e7:b9eb:58e8 with SMTP id d11csp7254560mav; Sun, 29 Dec 2024 06:18:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUSbB1iXUb6olCq8DQ7Xgf7L64llFRkHJ7FwOAtScTd276gcQTjGpygWLeHb0O3uATh6h18Gst6r9Q=@openvpn.net X-Google-Smtp-Source: AGHT+IEtgSVTTSCf4PSrdTD3E9YgN5tWDkDqGvDGa3mSY3Oy7Kz7ih67MckzNbPaHmUq4pyJxuMQ X-Received: by 2002:a05:6830:448b:b0:71d:3fe2:2051 with SMTP id 46e09a7af769-720ff8b03a0mr17256969a34.22.1735481899750; Sun, 29 Dec 2024 06:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735481899; cv=none; d=google.com; s=arc-20240605; b=hKQNkWyNIWjnIxhJaAoOaMUlcRz2rQt7YBf/5iDbXxdQMKEDRONo/q9cvzDM3KiCPc bbkIjHy3j3BGC8Rgqd2ibtnDzBl0rh/dKpcKxPE9Gfzx32QfAPN9PSz70xXasnheujdg GIGK2QgK2fjkvgYW6czF0tad0Nhiv4dXbipODg9R1V+7/4kNePFa13ujMN5vUyWw8lD+ VsEjXJ7BLScLCLgBM7/AY03bMENYWfbLaRjJMBjcPzDcKUL3hOpDbu2V8wopbvQdTMZZ wONTkSSdVLCndv300KClyJ1WuqcmrVwXD+90OSaa7Epqe2cyN1NF9ZRDxxB1o96YS7SV DDtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature; bh=VNQt+4IcO9SlDgd5dyJ48rjDguR65wr5o2CJrEFtd0s=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=i0fyc4wNaLpaTUdUqijpm6durzF6ZDIkuFXJuBN1CQKPUZOWRP/iVvtmKgi6HuE+FX IrYpjzUWPmQlAVclxBL6QWXTgKJU0OBVr4AQjxlwE1mNS9t7QUvZN60w1zvupg1TPhf/ 06EYpynXP+OPXuAYBqs3kHJGQxPoXzZ1sNFy09b2H4phifwQBK3zeqed0OouRbrAQpT9 aEXM9kWyaXIBzD72yTHwALaYUDG5pJwAth9MLYzb21FaTCvAasm52QldKv0drMLKEt4q V8tXE7JyCybHBP5DqtetDsbsGa/ZbrbhSHzoADm963F8TxpgBjE2yoNvdGJw5GIa5L3i C1dw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=a2CtHzAH; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=BboEs8Rs; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-71fc9a102b0si13272944a34.213.2024.12.29.06.18.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Dec 2024 06:18:19 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=a2CtHzAH; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=BboEs8Rs; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de 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.95) (envelope-from ) id 1tRu7T-0001MM-Rt; Sun, 29 Dec 2024 14:18:16 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tRu7R-0001ME-IQ for openvpn-devel@lists.sourceforge.net; Sun, 29 Dec 2024 14:18:14 +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:To:From:Sender:Reply-To:Cc: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=5IhnG11za0W3x6fh2naWuNSR689ba/YNw1yJbwXQoC4=; b=a2CtHzAH5O6kw/d3L7o3K/B7sG ygiZ5vE8rsxlduwhxNYdHChldto8Rv5E84+O1jrxXHHmXo1Y8bLdN1oUxgqG15JdFQS6X5xVbYJJ4 6isEvcWgz0V8zRqhtGgwoL+J9alzO654/SbFBuAi2zC/ofw55K3nO5la/I/pQk3PSJCI=; 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:To:From:Sender:Reply-To:Cc: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=5IhnG11za0W3x6fh2naWuNSR689ba/YNw1yJbwXQoC4=; b=BboEs8Rs9ELz3uAD76yhz//Bmh dh85chUc/xb1Yedzqd5c7115X99xruR0RwpdPjdGz9SYC8v94CmxfL54zbs+DpYQqguFPWnUqiOPv C2ptfJE11IYtkzTs3gLap9uv4GIkGSemEDVV0NSTERCo369dbtWXCFtC7P1ZVTvmvds4=; Received: from dhcp-174.greenie.muc.de ([193.149.48.174] helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tRu7Q-0001U8-Ez for openvpn-devel@lists.sourceforge.net; Sun, 29 Dec 2024 14:18:14 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.17.1.9/8.17.1.9) with ESMTP id 4BTEI0L6004744 for ; Sun, 29 Dec 2024 15:18:00 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.17.1.9/8.17.1.9/Submit) id 4BTEI07l004743 for openvpn-devel@lists.sourceforge.net; Sun, 29 Dec 2024 15:18:00 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 29 Dec 2024 15:17:59 +0100 Message-ID: <20241229141800.4734-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 0.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: Lev Stipakov As a preparation for multipeer and data_v3, add function which returns dco version in machine-readable format. Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 Signed-off-by: Lev Stipakov Acked-by: Gert Doering --- Content analysis details: (0.0 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in sa-accredit.habeas.com] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [193.149.48.174 listed in bl.score.senderscore.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-Headers-End: 1tRu7Q-0001U8-Ez Subject: [Openvpn-devel] [PATCH v5] dco-win: factor out getting dco version 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 X-GMAIL-THRID: =?utf-8?q?1819784668654781819?= X-GMAIL-MSGID: =?utf-8?q?1819784668654781819?= From: Lev Stipakov As a preparation for multipeer and data_v3, add function which returns dco version in machine-readable format. Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 Signed-off-by: Lev Stipakov Acked-by: Gert Doering --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/733 This mail reflects revision 5 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 9224bca..f59bf8c 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -52,6 +52,57 @@ return tt; } +/** + * Gets version of dco-win driver + * + * Fills Major/Minor/Patch fields in a passed OVPN_VERSION + * struct. If version cannot be obtained, fields are set to 0. + * + * @param version pointer to OVPN_VERSION struct + * @returns true if version has been obtained, false otherwise + */ +static bool +dco_get_version(OVPN_VERSION *version) +{ + CLEAR(*version); + + bool res = false; + + HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, + 0, NULL, OPEN_EXISTING, 0, NULL); + + if (h == INVALID_HANDLE_VALUE) + { + /* fallback to a "normal" device, this will fail if device is already in use */ + h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, + 0, NULL, OPEN_EXISTING, 0, NULL); + } + + if (h == INVALID_HANDLE_VALUE) + { + goto done; + } + + DWORD bytes_returned = 0; + if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, + version, sizeof(*version), &bytes_returned, NULL)) + { + goto done; + } + + res = true; + +done: + if (h != INVALID_HANDLE_VALUE) + { + CloseHandle(h); + } + + msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch); + + return res; +} + bool ovpn_dco_init(int mode, dco_context_t *dco) { @@ -386,39 +437,17 @@ const char * dco_version_string(struct gc_arena *gc) { - OVPN_VERSION version; - ZeroMemory(&version, sizeof(OVPN_VERSION)); - - /* first, try a non-exclusive control device, available from 1.3.0 */ - HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); - - if (h == INVALID_HANDLE_VALUE) + OVPN_VERSION version = {0}; + if (dco_get_version(&version)) { - /* fallback to a "normal" device, this will fail if device is already in use */ - h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); + struct buffer out = alloc_buf_gc(256, gc); + buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch); + return BSTR(&out); } - - if (h == INVALID_HANDLE_VALUE) + else { return "N/A"; } - - DWORD bytes_returned = 0; - if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, - &version, sizeof(version), &bytes_returned, NULL)) - { - CloseHandle(h); - return "N/A"; - } - - CloseHandle(h); - - struct buffer out = alloc_buf_gc(256, gc); - buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch); - - return BSTR(&out); } int