From patchwork Fri Sep 6 07:43:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "plaisthos (Code Review)" X-Patchwork-Id: 3796 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:3a64:b0:5b9:581e:f939 with SMTP id p4csp1243425mao; Fri, 6 Sep 2024 00:44:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXBMJKvB29/Wr3JJgkX7iXzhUXmTEoSdDewjl7U0FD0GRXn6RYvTqlbeIdHd6AYlA9K5TegTaR+IFY=@openvpn.net X-Google-Smtp-Source: AGHT+IFc+gaqANcVOQxQi75JpPSiLQXelWT/8uAoGriU4+HNe7h1jRwJ/bD77hJOvzDD3y7SH0Vr X-Received: by 2002:a05:6808:1285:b0:3da:e246:36f9 with SMTP id 5614622812f47-3df05e5e7b9mr29558306b6e.31.1725608683672; Fri, 06 Sep 2024 00:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1725608683; cv=none; d=google.com; s=arc-20240605; b=d5ZaLrh6xTFMq6Y/lF2UEleRbGXvSZn7zoc1B2dfMHM79l0KzLk9/GUkxDANl2+E/y QLgF5jDLrpdoBXfuhayqNiXtnrLGPzeLisIYOI+uuhew9Lv+tS1Z+I5yEHJFgSS5/o9b 85MuoifR8jPYPesncfd2ycgPmcYTAZd1TVkGCkq8bZixSUTFkif9qjoH8c/awbQW4wZ+ jMjGhOPYJVJ2GA+Au/NDtmUqPsySXDptBUe/JsbrwthSgDACKSPYCv1szWSVbylwJ3dT vNQsFzKmhhvU1L5U7dYBFskLGo1Xa0mjOEm4AktOTVfnuA/BpDF0PijKXYMU6DJnhUtH VYKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=p0uxtiUnhMiW0EMr2SmAxfJwGxK+bdhBLLSmMxL4rNI=; fh=U7wEyxtwz2o5+UdevFSA47vNeG9knhWH0KV//QhD5a0=; b=DDupD+DiQWzdw/af6zENguXxDfv2ffiqygX3NRL4fOwVWDfoReQE1Pntuz8VZgdOCs w2S3Sk2lyxNL+HcrOTvp8nwDIUfdz7x05ufGxlxGVsuIgfJzdTLgP30eE4tpCH+hE3G2 91f+PWpir7ZRDN2D+qo2NmPR6liWzu3UxnRDgfXFER9THGM68+Q99O+w/RXuhka4/CbD m9Cr+b6fzB93USgTm5mD16eNH0QAQXb34K+LIyM4pQeanoJYJ5a6j/8IjQop+J9pNEiW BlFv/xrojMIfQWxPVQ/jrrG0/2H+1aCIZF17U6EcrO54KAit0ZC0y2PYyvXMZePyedRm lrxQ==; 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=iF9c6p8F; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dy3qGAQV; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=d8sgVC0H; 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=openvpn.net; dara=fail header.i=@openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 41be03b00d2f7-7d50b852a4csi3468965a12.510.2024.09.06.00.44.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Sep 2024 00:44:43 -0700 (PDT) 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=iF9c6p8F; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dy3qGAQV; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=d8sgVC0H; 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=openvpn.net; dara=fail header.i=@openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1smTdb-0000nU-CT; Fri, 06 Sep 2024 07:44:10 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1smTda-0000nO-5P for openvpn-devel@lists.sourceforge.net; Fri, 06 Sep 2024 07:44:09 +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:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5U7TxhGQNG33WUifZX5HmDg7yDm4qtCeTRERvrT95uw=; b=iF9c6p8Fcnztt43c9GX29EQtwB n0fKH3d2lEcEwUcRKvCCxxKAaJaUJV5kF2s4rupIkO2LwCYvmJDpJUcKRhEYSdjskiZSy20xxD/bK O/3j5u9L3EDfPPAixge6W4KtW8TNNdpJ6g/X65oVYB3+n9mS9Z058sc7j1mamWF8O9fc=; 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:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=5U7TxhGQNG33WUifZX5HmDg7yDm4qtCeTRERvrT95uw=; b=d y3qGAQVq79CIZ0auR9yL+vRYadlNReKRNEpQ5/rklW0C8OcKWEkMi/ShZ5ObNYEYkUlhrrE2QAtD5 nMTw2MEAPH8n5XERcO2ykDBgXfEpzU9vYBPcRCG8sW88xNnpWU7pwvI4b+IgpJDdFsYl5tCwSTu/I 9VK3MukVf1yn9vdI=; Received: from mail-wm1-f52.google.com ([209.85.128.52]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1smTdY-0005p4-39 for openvpn-devel@lists.sourceforge.net; Fri, 06 Sep 2024 07:44:09 +0000 Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42bb8cf8a5bso12846205e9.2 for ; Fri, 06 Sep 2024 00:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1725608636; x=1726213436; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=5U7TxhGQNG33WUifZX5HmDg7yDm4qtCeTRERvrT95uw=; b=d8sgVC0H01V45vjRClAfwqoNtIHG5nbHUscNX7itvypn0hnmd7c0aFxEAFZh3OzjTQ l5Uj+Oix4NPCI2PdHT/qo6sO1XHXBZB0EnqEzxC1Ic3s1MOL7/8B958EwMlWsu7usrZl aQ+PipL44UJpPf/yzURoeCgSFnwrEqaXCfaDj9nDvy+LynOBFvtkOuG5jSoW1nYsRKpE X6pw3hX5PtbGRn5k9x2nLSDEFuq18dsUmLVdMhzftf6R5B91d6mgpk+s9anufepnpEBp s6FQalUUF5LRmBGUs+0iiCulSL2H/hH0+hRCBMXhez6ZJtnRDXYT9I3qZzhEOUVE9C6h roXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725608636; x=1726213436; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5U7TxhGQNG33WUifZX5HmDg7yDm4qtCeTRERvrT95uw=; b=BR3pGIJYRUEvR581uumL3N8MeuI4sR22XsShMExOuRlcgbaRzWB22DBRLWevYrdRD2 4VRszh5DF2PxlXAukCO9TylBDPyWrjqvVMAIaKOw/O0tm49VVyuW+QBISNihC+pvG6jW FudOgB1Z9RYB44wf8LU2/XWPKrVwTJAORqMYn7k/lbSXFs/hUaiZBGtLABVBSauixDR7 5Mb5tMxQLrgnCatfNRPMYndgSF5Wc8LozssMbtbGRFzJ0NQZRDcWEtK1lpZejcuErdu0 M+ViKcuu4qSUPYsOvlobUOCkieBQknri6LGoagxaA1VdeSXfJ+IxlHAym2O/g6N//PPG 08Ow== X-Gm-Message-State: AOJu0YzmPejJpSJH10OK7fT6nsF18dTay1MDS+pgy9uPhBDrgsi5aVfp 9/dE8CzROYs/6yv35ujODI9sgVSwexYpinowXXAhHZ8QgZidhrUhCpe0mm+8Yh4= X-Received: by 2002:a05:600c:4e8c:b0:427:b995:5bd0 with SMTP id 5b1f17b1804b1-42c9f9d6637mr10457895e9.23.1725608635760; Fri, 06 Sep 2024 00:43:55 -0700 (PDT) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42ca05ca4f6sm11379065e9.17.2024.09.06.00.43.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 00:43:55 -0700 (PDT) From: "stipa (Code Review)" X-Google-Original-From: "stipa (Code Review)" X-Gerrit-PatchSet: 1 Date: Fri, 6 Sep 2024 07:43:54 +0000 To: plaisthos , flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 X-Gerrit-Change-Number: 733 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: ac7740abe2d7f320f8bb93fe386a0e7040bf34a6 References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) 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: Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.128.52 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.128.52 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1smTdY-0005p4-39 Subject: [Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version info own function 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: , Reply-To: lstipakov@gmail.com, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1809431850959771540?= X-GMAIL-MSGID: =?utf-8?q?1809431850959771540?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email to review the following change. Change subject: dco-win: factor out getting dco version info own function ...................................................................... dco-win: factor out getting dco version info own function Instead of having duplicated code to get dco version for data_v3 checks and for version info, have it in one place and store the version in dco context - the latter is a preparation for dco v2 support (multi-peer). Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7 Signed-off-by: Lev Stipakov --- M src/openvpn/dco_win.c M src/openvpn/dco_win.h 2 files changed, 51 insertions(+), 56 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/1 diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 189864b..cf825b3 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -52,11 +52,54 @@ return tt; } +static void +dco_get_version(OVPN_VERSION *version) +{ + 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; + } + +done: + if (h != INVALID_HANDLE_VALUE) + { + CloseHandle(h); + } + + msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch); +} + +static inline +bool +dco_version_supports_data_v3(OVPN_VERSION *version) +{ + return (version->Major > 1) || (version->Minor >= 4); +} + bool ovpn_dco_init(int mode, dco_context_t *dco) { - dco->supports_data_v3 = dco_supports_data_v3(NULL); - msg(D_DCO_DEBUG, "dco supports data_v3: %d", dco->supports_data_v3); + dco_get_version(&dco->version); + dco->supports_data_v3 = dco_version_supports_data_v3(&dco->version); + + msg(D_DCO_DEBUG, "dco data_v3: %d", dco->supports_data_v3); return true; } @@ -428,33 +471,9 @@ dco_version_string(struct gc_arena *gc) { OVPN_VERSION version; - ZeroMemory(&version, sizeof(OVPN_VERSION)); + ZeroMemory(&version, sizeof(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) - { - /* 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) - { - 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); + dco_get_version(&version); struct buffer out = alloc_buf_gc(256, gc); buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch); @@ -538,36 +557,11 @@ bool dco_supports_data_v3(struct context *c) { - bool res = false; - - HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, - 0, NULL, OPEN_EXISTING, 0, NULL); - - if (h == INVALID_HANDLE_VALUE) - { - goto done; - } - OVPN_VERSION version; - ZeroMemory(&version, sizeof(OVPN_VERSION)); + ZeroMemory(&version, sizeof(version)); + dco_get_version(&version); - DWORD bytes_returned = 0; - if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0, - &version, sizeof(version), &bytes_returned, NULL)) - { - goto done; - } - - /* data_v3 is supported starting from 1.4 */ - res = (version.Major > 1) || (version.Minor >= 4); - -done: - if (h != INVALID_HANDLE_VALUE) - { - CloseHandle(h); - } - - return res; + return dco_version_supports_data_v3(&version); } #endif /* defined(_WIN32) */ diff --git a/src/openvpn/dco_win.h b/src/openvpn/dco_win.h index f58488f..ce57817 100644 --- a/src/openvpn/dco_win.h +++ b/src/openvpn/dco_win.h @@ -34,6 +34,7 @@ struct dco_context { struct tuntap *tt; bool supports_data_v3; + OVPN_VERSION version; }; typedef struct dco_context dco_context_t;