From patchwork Mon Nov 16 10:51:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5711 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:9292:b0:11a:f58a:e788 with SMTP id dc18csp1027702lab; Mon, 16 Nov 2026 02:51:53 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFEDNtIasNSEhaUgwA3GVt0W5XVeIlkb+ldeL0C2OnuZyFzNmmeulflbAEJxK0JTAD4jCnp/DvTlII=@openvpn.net X-Received: by 2002:a05:693c:4152:10b0:36a:4a68:84e5 with SMTP id 5a478bee46e88-379659c6839mr11147045eec.8.1794826313091; Mon, 16 Nov 2026 02:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794826313; cv=none; d=google.com; s=arc-20260327; b=AnSMiRD9A4LmESBImksADt59xBtRs7XAUUeV51jCuaaYG3W0jaRjHoFTrQ6QEEV1Ur RvOcHe5eewhUWEGTBFgti+gNEoX9iCR7RcP3hzpeRTd9HSeqFRGjhZdSrqFkWoCQnaC6 ScjdivpjPanuNLSwpmghLubqAQSBH/6zJqPdfSbjRA0+DdllICUOZU7D4GYMkHfuObuQ t1d1emi5z/A4GUvhMNiFza3WZXRLcaFmcjcrmn249SLkjWmf8pbdTk6k5CJBq3wI8xs9 Fz4UVysj3ASukU3oXXwZB7iX3NYsdNdbLaInVpB2PY8PuNVfd3ERTPM3AdO2T2CP/ejU op/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; 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:dkim-signature; bh=UI4pIxQTlcbEK8nkOlKppn0a/Yk2RW92tErd8InACEU=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=VwZ/c2YrUjXvZacICa/X7B3n/CbluJ6IvFtoYFCbQbaIV+PB+eynrUnlPCYZa2htC4 F5lsb3XwqBtL/jA5h6NYgkMuyl7h9BrKLYUC7GptACn9MVZn2si3/nFEOJkLcFwLp/LW h7guj7TSEwi7Zzvn17ZKNkAUVOQmm3agGvK6WcO3y5EEHyv0/nGChVXi7Yn/GjU3cn41 xrjB3SbYUWu5BtkSsYfoYSiO1o3xfQEBEDTVPj/KdupKoGkxDPnZDaWG6uoIoB4g0Y8a OOO91cpyT8txpeapLtor5q2y4cw34/zv+isoxRWj46s4T9jzK0GUyec0zdpmb2ANgD43 3oRg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=LzVXPwcB; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Y9sm97T3; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=gPLLZ7rn; 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 5a478bee46e88-379599be04esi31266047eec.27.2026.11.16.02.51.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Nov 2026 02:51:53 -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=pass header.i=@lists.sourceforge.net header.s=beta header.b=LzVXPwcB; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Y9sm97T3; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=gPLLZ7rn; 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 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=UI4pIxQTlcbEK8nkOlKppn0a/Yk2RW92tErd8InACEU=; b=LzVXPwcBP8xqey lC4hq6Cm8x9hXjSidIEfm6zeyVndHBWD3hO+DMUY2PwI+2zdpD+DNbwj4F12/XPagSo/q+VMFy+AP RmhovU6lTHPz/0QMSfYtsvNJuKIGUYU5ElXNs00ibcZ/lXNiiWnbshjSR+hppMXLdOUeX8HeEiEH6 6Ng=; 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.100.1) (envelope-from ) id 1xSuJU-000000005UM-0juP; Mon, 16 Nov 2026 10:51:52 +0000 Received: from [172.30.29.66] (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.100.1) (envelope-from ) id 1xSuJS-000000005UF-3MkA for openvpn-devel@lists.sourceforge.net; Mon, 16 Nov 2026 10:51:50 +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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8t5ePXCvQW9yqaEOclE4gYxN5XlBVlwRCHGWUkAy57Y=; b=Y9sm97T3Ci1SdP8jYB0g/XhWtc O3Ylh5wvJl1ags0uKGErEVrcDtcDIN+PvhK4norxqdAebaOq96Of8HhBtyMe4FeU7m8tPnV6DTFHu j5lgfk5CrdKQ4C9lmBZjujtW8PHcrglEomXrLpekuVWT4OyVr7wH3XixxumPMATtRZ7g=; 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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8t5ePXCvQW9yqaEOclE4gYxN5XlBVlwRCHGWUkAy57Y=; b=gPLLZ7rnniviaOv9WzJokxwIWW 9mi/FxrL/ORHOyfpbWNFsPkFFIjfdU+XVlzl1BG7bqaNphXS23UPJEZn7vfxBfjJ14cRyRPq0IXBm L/jzXTg2f7ld9IvZB6yp6dHyp+HObK8/vliQGLC7os4apsKW99UsMxnmPQVcFvROZwgI=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xSuJR-000000001P4-0Hk6 for openvpn-devel@lists.sourceforge.net; Mon, 16 Nov 2026 10:51:50 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6AGApgoJ017085 for ; Mon, 16 Nov 2026 11:51:42 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AGApfhc017084 for openvpn-devel@lists.sourceforge.net; Mon, 16 Nov 2026 11:51:41 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 16 Nov 2026 11:51:36 +0100 Message-ID: <20261116105141.17064-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", 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: Razvan Cojocaru Since 7f0214c9 ("Remove support for compression on send") the LZO and LZ4 compress methods only add the stub framing, duplicating stub_compress() and stubv2_compress(). Export those as comp_stub_compr [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xSuJR-000000001P4-0Hk6 Subject: [Openvpn-devel] [PATCH v2] comp: share the stub compress methods with LZO and LZ4 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: 1882005360379363132 X-GMAIL-MSGID: 1882011795947195484 From: Razvan Cojocaru Since 7f0214c9 ("Remove support for compression on send") the LZO and LZ4 compress methods only add the stub framing, duplicating stub_compress() and stubv2_compress(). Export those as comp_stub_compress() and compv2_stub_compress() and use them for all methods. Also allocate the context only once in comp_init(). This also fixes LZO sending dropped packets. encrypt_sign() drops packets by setting buf.len to 0 (e.g. before client-connect has completed) and still calls the compress method. lzo_compress() prepended NO_COMPRESS_BYTE regardless, turning the dropped packet into a one byte packet that was sent. The stub methods return early on empty buffers. Change-Id: I7c9e123a458b9d3757e9de93f401e4e421741675 Signed-off-by: Razvan Cojocaru Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2143 --- 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/+/2143 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/doc/doxygen/doc_compression.h b/doc/doxygen/doc_compression.h index 1f2e93bd1..efd18bf 100644 --- a/doc/doxygen/doc_compression.h +++ b/doc/doxygen/doc_compression.h @@ -60,10 +60,10 @@ * Data Channel Control module\endlink and processes them according to the * settings of the packet's VPN tunnel. The \link data_control Data * Channel Control module\endlink uses the following interface functions: - * - For packets which will be sent to a remote OpenVPN peer: \c - * lzo_compress() - * - For packets which have been received from a remote OpenVPN peer: \c - * lzo_decompress() + * - For packets which will be sent to a remote OpenVPN peer: the \c + * compress method of \c compress_alg + * - For packets which have been received from a remote OpenVPN peer: the + * \c decompress method of \c compress_alg * * @par Settings that control this module's activity * Whether or not the Data Channel Compression module is active depends on diff --git a/src/openvpn/comp-lz4.c b/src/openvpn/comp-lz4.c index 0c5f22f..736601a 100644 --- a/src/openvpn/comp-lz4.c +++ b/src/openvpn/comp-lz4.c @@ -55,40 +55,6 @@ { } -/* Doesn't do any actual compression anymore */ -static void -lz4_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, - const struct frame *frame) -{ - if (buf->len <= 0) - { - return; - } - - uint8_t comp_head_byte = NO_COMPRESS_BYTE_SWAP; - uint8_t *head = BPTR(buf); - uint8_t *tail = BEND(buf); - ASSERT(buf_safe(buf, 1)); - ++buf->len; - - /* move head byte of payload to tail */ - *tail = *head; - *head = comp_head_byte; -} - -/* Doesn't do any actual compression anymore */ -static void -lz4v2_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, - const struct frame *frame) -{ - if (buf->len <= 0) - { - return; - } - - compv2_escape_data_ifneeded(buf); -} - #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" @@ -207,9 +173,9 @@ #pragma GCC diagnostic pop #endif -const struct compress_alg lz4_alg = { "lz4", lz4_compress_init, lz4_compress_uninit, lz4_compress, - lz4_decompress }; +const struct compress_alg lz4_alg = { "lz4", lz4_compress_init, lz4_compress_uninit, + comp_stub_compress, lz4_decompress }; const struct compress_alg lz4v2_alg = { "lz4v2", lz4v2_compress_init, lz4_compress_uninit, - lz4v2_compress, lz4v2_decompress }; + compv2_stub_compress, lz4v2_decompress }; #endif /* ENABLE_LZ4 */ diff --git a/src/openvpn/comp.c b/src/openvpn/comp.c index 513a766..6ce9152 100644 --- a/src/openvpn/comp.c +++ b/src/openvpn/comp.c @@ -38,47 +38,41 @@ struct compress_context * comp_init(const struct compress_options *opt) { - struct compress_context *compctx = NULL; + const struct compress_alg *alg; switch (opt->alg) { case COMP_ALG_STUB: - ALLOC_OBJ_CLEAR(compctx, struct compress_context); - compctx->flags = opt->flags; - compctx->alg = comp_stub_alg; + alg = &comp_stub_alg; break; case COMP_ALGV2_UNCOMPRESSED: - ALLOC_OBJ_CLEAR(compctx, struct compress_context); - compctx->flags = opt->flags; - compctx->alg = compv2_stub_alg; + alg = &compv2_stub_alg; break; #ifdef ENABLE_LZO case COMP_ALG_LZO: - ALLOC_OBJ_CLEAR(compctx, struct compress_context); - compctx->flags = opt->flags; - compctx->alg = lzo_alg; + alg = &lzo_alg; break; #endif #ifdef ENABLE_LZ4 case COMP_ALG_LZ4: - ALLOC_OBJ_CLEAR(compctx, struct compress_context); - compctx->flags = opt->flags; - compctx->alg = lz4_alg; + alg = &lz4_alg; break; case COMP_ALGV2_LZ4: - ALLOC_OBJ_CLEAR(compctx, struct compress_context); - compctx->flags = opt->flags; - compctx->alg = lz4v2_alg; + alg = &lz4v2_alg; break; #endif + default: + return NULL; } - if (compctx) - { - (*compctx->alg.compress_init)(compctx); - } + + struct compress_context *compctx; + ALLOC_OBJ_CLEAR(compctx, struct compress_context); + compctx->flags = opt->flags; + compctx->alg = *alg; + (*compctx->alg.compress_init)(compctx); return compctx; } diff --git a/src/openvpn/comp.h b/src/openvpn/comp.h index ad80243..3f6411b 100644 --- a/src/openvpn/comp.h +++ b/src/openvpn/comp.h @@ -208,6 +208,14 @@ void compv2_escape_data_ifneeded(struct buffer *buf); +/* Compress methods of the stub algorithms, also used by LZO and LZ4, which + * no longer compress on send */ +void comp_stub_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, + const struct frame *frame); + +void compv2_stub_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, + const struct frame *frame); + static inline bool comp_enabled(const struct compress_options *info) { diff --git a/src/openvpn/compstub.c b/src/openvpn/compstub.c index 2eef587..b1115c9 100644 --- a/src/openvpn/compstub.c +++ b/src/openvpn/compstub.c @@ -44,9 +44,9 @@ { } -static void -stub_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, - const struct frame *frame) +void +comp_stub_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, + const struct frame *frame) { if (buf->len <= 0) { @@ -104,9 +104,9 @@ } -static void -stubv2_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, - const struct frame *frame) +void +compv2_stub_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, + const struct frame *frame) { if (buf->len <= 0) { @@ -154,8 +154,8 @@ } const struct compress_alg compv2_stub_alg = { "stubv2", stub_compress_init, stub_compress_uninit, - stubv2_compress, stubv2_decompress }; + compv2_stub_compress, stubv2_decompress }; const struct compress_alg comp_stub_alg = { "stub", stub_compress_init, stub_compress_uninit, - stub_compress, stub_decompress }; + comp_stub_compress, stub_decompress }; #endif /* USE_STUB */ diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 375635b..1a67319 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -102,7 +102,7 @@ * - Check that the client authentication has succeeded; if not, drop the * packet. * - If the \a comp_frag argument is true: - * - Call \c lzo_compress() of the \link compression Data Channel Compression + * - Call the \c compress method of the \link compression Data Channel Compression * module\endlink to (possibly) compress the packet. * - Call \c fragment_outgoing() of the \link fragmentation Data Channel Fragmentation * module\endlink to (possibly) fragment the packet. @@ -191,7 +191,7 @@ * - Call \c fragment_incoming() of the \link fragmentation Data Channel * Fragmentation module\endlink to reassemble the packet if it's * fragmented. - * - Call \c lzo_decompress() of the \link compression Data Channel + * - Call the \c decompress method of the \link compression Data Channel * Compression module\endlink to decompress the packet if it's * compressed. * - Place the resulting packet in \c c->c2.to_tun so that it can be sent diff --git a/src/openvpn/lzo.c b/src/openvpn/lzo.c index 2b0691b..207cea6 100644 --- a/src/openvpn/lzo.c +++ b/src/openvpn/lzo.c @@ -70,14 +70,6 @@ } static void -lzo_compress(struct buffer *buf, struct buffer work, struct compress_context *compctx, - const struct frame *frame) -{ - uint8_t *header = buf_prepend(buf, 1); - *header = NO_COMPRESS_BYTE; -} - -static void lzo_decompress(struct buffer *buf, struct buffer work, struct compress_context *compctx, const struct frame *frame) { @@ -129,6 +121,6 @@ #pragma GCC diagnostic pop #endif -const struct compress_alg lzo_alg = { "lzo", lzo_compress_init, lzo_compress_uninit, lzo_compress, - lzo_decompress }; +const struct compress_alg lzo_alg = { "lzo", lzo_compress_init, lzo_compress_uninit, + comp_stub_compress, lzo_decompress }; #endif /* ENABLE_LZO */