From patchwork Sat Aug 13 22:51:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 2678 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director13.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id cMGnF7u3+GJcdgAAIUCqbw (envelope-from ) for ; Sun, 14 Aug 2022 04:52:11 -0400 Received: from proxy7.mail.ord1d.rsapps.net ([172.30.191.6]) by director13.mail.ord1d.rsapps.net with LMTP id 0DB+F7u3+GLDTQAA91zNiA (envelope-from ) for ; Sun, 14 Aug 2022 04:52:11 -0400 Received: from smtp37.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy7.mail.ord1d.rsapps.net with LMTPS id GApEF7u3+GLfegAAMe1Fpw (envelope-from ) for ; Sun, 14 Aug 2022 04:52:11 -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: smtp37.gate.ord1c.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=unstable.cc; dmarc=fail (p=none; dis=none) header.from=unstable.cc X-Suspicious-Flag: YES X-Classification-ID: 6227e212-1bae-11ed-9212-525400e8d833-1-1 Received: from [216.105.38.7] ([216.105.38.7:59116] helo=lists.sourceforge.net) by smtp37.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id B9/A1-11346-AB7B8F26; Sun, 14 Aug 2022 04:52:11 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1oN9Kn-0005Az-Mi; Sun, 14 Aug 2022 08:51:01 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1oN9Kh-0005Aq-Ib for openvpn-devel@lists.sourceforge.net; Sun, 14 Aug 2022 08:50:56 +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=txZxmsplz47h5Dre46NC2FPJZTyq7A5hnl9HfdaYtSk=; b=RuFSphpdR72vgdgb6661O2DMlJ UFe8Rw5c931BJRRPr8/A0qJxcBNS/KlYEvYQhzhgEpWqZ/H+fl0a1XRSB45rTQrUbjOJu8Rx8thLF LXsEtMXqIqZiIX5liZEbcf6WqDl6TyNZHTH6gAZkBxEZMZMhiSB65qhfRZQUWZYEs228=; 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=txZxmsplz47h5Dre46NC2FPJZTyq7A5hnl9HfdaYtSk=; b=HksqpEjap55PqzPRR+6OFbN6d3 D0IMN1GuZYe4DQwHQmY8B1j8qKNRA145eUSRz4xuESgvkBIkbqH428+X6L6b2eyYF14dgc05smoYp /xyjlFEXgPqxJuKIYgNpEh1NWcQ3hwfvt0IY9bfKn15FZQDtVjD36wCeX8eWpPiNS1fI=; Received: from mailout-l3b-97.contactoffice.com ([212.3.242.97]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1oN9Ke-001XWG-P5 for openvpn-devel@lists.sourceforge.net; Sun, 14 Aug 2022 08:50:53 +0000 Received: from smtpauth2.co-bxl (smtpauth2.co-bxl [10.2.0.24]) by mailout-l3b-97.contactoffice.com (Postfix) with ESMTP id 716135F1; Sun, 14 Aug 2022 10:50:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1660467046; s=20220809-q8oc; d=unstable.cc; i=a@unstable.cc; h=From:Cc:Date:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; l=1888; bh=txZxmsplz47h5Dre46NC2FPJZTyq7A5hnl9HfdaYtSk=; b=F3IcSPuaKedBssViA5gdVeno0UO0Mp4RrE9QsfmENFvSoWYMfx/L3Zloah/RQP9R rRhJl23GsvBB3P7J/Y1GAgoh9SJjw7R0lK4LUocK+kIQK/dOnJrawaJN49K6GtiRmi6 exC5RZxQfz1ImE1ATDVg6vpixy5yky1DWpzqVURFBUmnBGmxgcgHeq//xzTiXOYIm77 wRDsz+FpnHGck2EL5u9QVorQRWCC2IU8YoQtVbST7Jg3f0ag87kYV4vx7re+Glvw6um 5IdMpKNGP2WLHVdYPmfSYq44ACXSTagSFmSXjgjrpXzMWaZojj+N64TeWqDS/g7wAUP hxU/72Xlpw== Received: by smtp.mailfence.com with ESMTPSA ; Sun, 14 Aug 2022 10:50:44 +0200 (CEST) From: Antonio Quartulli To: openvpn-devel@lists.sourceforge.net Date: Sun, 14 Aug 2022 10:51:17 +0200 Message-Id: <20220814085117.7128-1-a@unstable.cc> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220813213920.18959-1-a@unstable.cc> References: MIME-Version: 1.0 X-Spam-Status: No, hits=-2.9 required=4.7 symbols=ALL_TRUSTED, BAYES_00, T_SCC_BODY_TEXT_LINE device=10.2.0.21 X-ContactOffice-Account: com:375058688 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: On Windows the high level API should still use the link_socket object to read and write packets. For this reason, even if dco_installed is true, we still need to rely on the classic link_socket object [...] Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [212.3.242.97 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches 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 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1oN9Ke-001XWG-P5 Subject: [Openvpn-devel] [PATCH v103 6/7] dco-win: ensure the DCO API is not used when running on Windows 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 On Windows the high level API should still use the link_socket object to read and write packets. For this reason, even if dco_installed is true, we still need to rely on the classic link_socket object. Signed-off-by: Antonio Quartulli --- Changes from v102: * mark helper as 'inline' * improve comment wording (by Lev) Changes from v101: * add defined(TARGET_FREEBSD) to the #if guard Changes from v100: * removed ASSERTs (moved to previous patch) * improve comment text in forward.c --- src/openvpn/forward.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index f6d416a3..e45aa0f9 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1601,6 +1601,26 @@ process_ip_header(struct context *c, unsigned int flags, struct buffer *buf) } } +/* Linux-like DCO implementations pass the socket to the kernel and + * disallow usage of it from userland, so (control) packets sent and + * received by OpenVPN need to go through the DCO interface. + * + * Windows DCO needs control packets to be sent via the normal + * standard Overlapped I/O. + * + * Hide that complexity (...especially if more platforms show up + * in future...) in a small inline function. + */ +static inline bool +should_use_dco_socket(struct link_socket *sock) +{ +#if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) + return sock->info.dco_installed; +#else + return false; +#endif +} + /* * Input: c->c2.to_link */ @@ -1674,7 +1694,7 @@ process_outgoing_link(struct context *c) socks_preprocess_outgoing_link(c, &to_addr, &size_delta); /* Send packet */ - if (c->c2.link_socket->info.dco_installed) + if (should_use_dco_socket(c->c2.link_socket)) { size = dco_do_write(&c->c1.tuntap->dco, c->c2.tls_multi->peer_id,