From patchwork Sun Feb 13 13:14:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 2280 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director15.mail.ord1d.rsapps.net ([172.30.191.6]) by backend41.mail.ord1d.rsapps.net with LMTP id yGz1GzufCWIcfQAAqwncew (envelope-from ) for ; Sun, 13 Feb 2022 19:15:55 -0500 Received: from proxy16.mail.ord1d.rsapps.net ([172.30.191.6]) by director15.mail.ord1d.rsapps.net with LMTP id wL0qIDufCWLvGAAAIcMcQg (envelope-from ) for ; Sun, 13 Feb 2022 19:15:55 -0500 Received: from smtp13.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.ord1d.rsapps.net with LMTPS id IBbwHzufCWJuCgAAetu3IA (envelope-from ) for ; Sun, 13 Feb 2022 19:15:55 -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: smtp13.gate.ord1d.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; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 46545640-8d2b-11ec-aa57-525400b197d9-1-1 Received: from [216.105.38.7] ([216.105.38.7:59162] helo=lists.sourceforge.net) by smtp13.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id FC/5B-20852-A3F99026; Sun, 13 Feb 2022 19:15:55 -0500 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.94.2) (envelope-from ) id 1nJP1C-000131-Gx; Mon, 14 Feb 2022 00:15:01 +0000 Received: from [172.30.20.202] (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.94.2) (envelope-from ) id 1nJP1A-00012h-JO for openvpn-devel@lists.sourceforge.net; Mon, 14 Feb 2022 00:14:59 +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: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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JtDTb29a8VQEi3SavnBUszHK66R2xG9PAP3TxJoE6E8=; b=YjcFS/mA61Yrx87LQXSx9TRJcF 5KaLFUKY9SCUzvUwnZ1IGmeA3YtqfgdizBD4WeNjvn2664AL6mKMieKAf5Ea4bCOi+4UM6avQmaZf VOfu4kR+FFvRagPGA/3LH9dKbYE9ON+aqnSQ+3R2MJIHBi4Y4q45Cmt8PibL4oyQrJDk=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version: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:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=JtDTb29a8VQEi3SavnBUszHK66R2xG9PAP3TxJoE6E8=; b=c xEjyGdrSI3aHtaPzF8nKPn6X5VesvJ7l3IpPK8QOcyBr1hE016GTDid+f2+nACgwjBhVcNQs9gD2I fEf3GkYzrFAb8H7ZL1N1h5o+qZKZG9qy6ZlhN3ZsP0TJ+tsNl++EX8CUuM9cM1Jb37XkBlbbak1Hs gY9uj5glCfuRCtTg=; Received: from mail.blinkt.de ([192.26.174.232]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nJP15-0005pX-9T for openvpn-devel@lists.sourceforge.net; Mon, 14 Feb 2022 00:14:59 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94.2 (FreeBSD)) (envelope-from ) id 1nJP0q-000LPx-4a for openvpn-devel@lists.sourceforge.net; Mon, 14 Feb 2022 01:14:40 +0100 Received: (nullmailer pid 3739884 invoked by uid 10006); Mon, 14 Feb 2022 00:14:40 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Mon, 14 Feb 2022 01:14:40 +0100 Message-Id: <20220214001440.3739838-1-arne@rfc2549.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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: The buffer overhaul simplified the frame struct to a point that these macros are either not used anymore or are not adding any benefit in understanding the code anymore. Replace the macros with direct [...] Content analysis details: (0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1nJP15-0005pX-9T Subject: [Openvpn-devel] [PATCH] Remove FRAME_HEADROOM, PAYLOAD_SIZE, EXTRA_FRAME and TUN_LINK_DELTA macros 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 The buffer overhaul simplified the frame struct to a point that these macros are either not used anymore or are not adding any benefit in understanding the code anymore. Replace the macros with direct member acessses. --- src/openvpn/comp-lz4.c | 8 ++++---- src/openvpn/crypto.c | 8 ++++---- src/openvpn/fragment.c | 6 +++--- src/openvpn/lzo.c | 6 +++--- src/openvpn/mtu.c | 2 +- src/openvpn/mtu.h | 21 --------------------- 6 files changed, 15 insertions(+), 36 deletions(-) diff --git a/src/openvpn/comp-lz4.c b/src/openvpn/comp-lz4.c index 0f2034f7..bf0c05b1 100644 --- a/src/openvpn/comp-lz4.c +++ b/src/openvpn/comp-lz4.c @@ -69,11 +69,11 @@ do_lz4_compress(struct buffer *buf, */ if (buf->len >= COMPRESS_THRESHOLD && (compctx->flags & COMP_F_ALLOW_COMPRESS)) { - const size_t ps = PAYLOAD_SIZE(frame); + const size_t ps = frame->buf.payload_size; int zlen_max = ps + COMP_EXTRA_BUFFER(ps); int zlen; - ASSERT(buf_init(work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(work, frame->buf.headroom)); ASSERT(buf_safe(work, zlen_max)); if (buf->len > ps) @@ -221,7 +221,7 @@ lz4_decompress(struct buffer *buf, struct buffer work, return; } - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&work, frame->buf.headroom)); /* do unframing/swap (assumes buf->len > 0) */ { @@ -258,7 +258,7 @@ lz4v2_decompress(struct buffer *buf, struct buffer work, return; } - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&work, frame->buf.headroom)); /* do unframing/swap (assumes buf->len > 0) */ uint8_t *head = BPTR(buf); diff --git a/src/openvpn/crypto.c b/src/openvpn/crypto.c index c8d2bcca..13ac1576 100644 --- a/src/openvpn/crypto.c +++ b/src/openvpn/crypto.c @@ -370,7 +370,7 @@ openvpn_decrypt_aead(struct buffer *buf, struct buffer work, ASSERT(ad_start >= buf->data && ad_start <= BPTR(buf)); - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&work, frame->buf.headroom)); /* IV and Packet ID required for this mode */ ASSERT(packet_id_initialized(&opt->packet_id)); @@ -533,7 +533,7 @@ openvpn_decrypt_v1(struct buffer *buf, struct buffer work, int outlen; /* initialize work buffer with FRAME_HEADROOM bytes of prepend capacity */ - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&work, frame->buf.headroom)); /* read the IV from the packet */ if (buf->len < iv_size) @@ -1035,7 +1035,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) void *buf_p; /* init work */ - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&work, frame->buf.headroom)); /* init implicit IV */ { @@ -1079,7 +1079,7 @@ test_crypto(struct crypto_options *co, struct frame *frame) memcpy(buf_p, BPTR(&src), BLEN(&src)); /* initialize work buffer with FRAME_HEADROOM bytes of prepend capacity */ - ASSERT(buf_init(&encrypt_workspace, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&encrypt_workspace, frame->buf.headroom)); /* encrypt */ openvpn_encrypt(&buf, encrypt_workspace, co); diff --git a/src/openvpn/fragment.c b/src/openvpn/fragment.c index 949db8f5..e7ca12f2 100644 --- a/src/openvpn/fragment.c +++ b/src/openvpn/fragment.c @@ -211,7 +211,7 @@ fragment_incoming(struct fragment_master *f, struct buffer *buf, frag->defined = true; frag->max_frag_size = size; frag->map = 0; - ASSERT(buf_init(&frag->buf, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&frag->buf, frame->buf.headroom)); } /* copy the data to fragment buffer */ @@ -342,7 +342,7 @@ fragment_outgoing(struct fragment_master *f, struct buffer *buf, { FRAG_ERR("too many fragments would be required to send datagram"); } - ASSERT(buf_init(&f->outgoing, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&f->outgoing, frame->buf.headroom)); ASSERT(buf_copy(&f->outgoing, buf)); f->outgoing_seq_id = modulo_add(f->outgoing_seq_id, 1, N_SEQ_ID); f->outgoing_frag_id = 0; @@ -391,7 +391,7 @@ fragment_ready_to_send(struct fragment_master *f, struct buffer *buf, /* initialize return buffer */ *buf = f->outgoing_return; - ASSERT(buf_init(buf, FRAME_HEADROOM(frame))); + ASSERT(buf_init(buf, frame->buf.headroom)); ASSERT(buf_copy_n(buf, &f->outgoing, size)); /* fragment flags differ based on whether or not we are sending the last fragment */ diff --git a/src/openvpn/lzo.c b/src/openvpn/lzo.c index a293ccad..39e833cb 100644 --- a/src/openvpn/lzo.c +++ b/src/openvpn/lzo.c @@ -160,8 +160,8 @@ lzo_compress(struct buffer *buf, struct buffer work, */ if (buf->len >= COMPRESS_THRESHOLD && lzo_compression_enabled(compctx)) { - const size_t ps = PAYLOAD_SIZE(frame); - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + const size_t ps = frame->buf.payload_size; + ASSERT(buf_init(&work, frame->buf.headroom)); ASSERT(buf_safe(&work, ps + COMP_EXTRA_BUFFER(ps))); if (buf->len > ps) @@ -222,7 +222,7 @@ lzo_decompress(struct buffer *buf, struct buffer work, return; } - ASSERT(buf_init(&work, FRAME_HEADROOM(frame))); + ASSERT(buf_init(&work, frame->buf.headroom)); c = *BPTR(buf); ASSERT(buf_advance(buf, 1)); diff --git a/src/openvpn/mtu.c b/src/openvpn/mtu.c index 3e48d275..aa810f1c 100644 --- a/src/openvpn/mtu.c +++ b/src/openvpn/mtu.c @@ -47,7 +47,7 @@ alloc_buf_sock_tun(struct buffer *buf, { /* allocate buffer for overlapped I/O */ *buf = alloc_buf(BUF_SIZE(frame)); - ASSERT(buf_init(buf, FRAME_HEADROOM(frame))); + ASSERT(buf_init(buf, frame->buf.headroom)); buf->len = frame->buf.payload_size; ASSERT(buf_safe(buf, 0)); } diff --git a/src/openvpn/mtu.h b/src/openvpn/mtu.h index dddbf4fc..08bd8dbc 100644 --- a/src/openvpn/mtu.h +++ b/src/openvpn/mtu.h @@ -148,27 +148,6 @@ struct frame { /* Forward declarations, to prevent includes */ struct options; -/* Routines which read struct frame should use the macros below */ - -/* - * Overhead added to packet payload due to encapsulation - */ -#define EXTRA_FRAME(f) ((f)->extra_frame) - -/* - * Delta between tun payload size and final TCP/UDP datagram size - * (not including extra_link additions) - */ -#define TUN_LINK_DELTA(f) ((f)->extra_frame + (f)->extra_tun) - -/* - * This is the maximum packet size that we need to be able to - * read from or write to a tun or tap device. For example, - * a tap device ifconfiged to an MTU of 1200 might actually want - * to return a packet size of 1214 on a read(). - */ -#define PAYLOAD_SIZE(f) ((f)->buf.payload_size) - /* * Control buffer headroom allocations to allow for efficient prepending. */