From patchwork Fri May 12 13:21:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3211 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:7b9a:b0:c3:1364:a2a2 with SMTP id j26csp5004205dyk; Fri, 12 May 2023 06:22:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cv7Gs+zYFBNAXPy8XfBYsQwBvFgw3ps2gtYuKkhNBRYNzpWfHorVLXu1BkMu4cSKqdXyr X-Received: by 2002:a6b:e606:0:b0:76c:8877:861d with SMTP id g6-20020a6be606000000b0076c8877861dmr2705506ioh.1.1683897776473; Fri, 12 May 2023 06:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683897776; cv=none; d=google.com; s=arc-20160816; b=C/grZUOsqe/7ONGSBCIR3TVquFBF6rzZWO4vAHK4a/ehhEh7ScMMMBzx9XKZsMojBj WlE2Y8OQa3mPK3shxIs5xLIis7r58pr8X1J23D2PK+ydlwAhlEpeau6mc47If/K4zhEQ +b6W5nkrM9pkhzlE7k8e7c82YXKyD8mAHuuUjcKjoBTvJvINB+SCE3BME/Z2286Ve6A+ shQ05oGfToHukET/SSZLo297ao6a3AKJB0QpgyxMEdXegd3nhHwCc2YBOnf3qA6ORotz M/w2trRnaNd3NIZufGEcbdIXgZCacnHDNQlDvq6/RRdhDXOftfzQeIPt7gJNQth2PS4C BRug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=TrAoHW1/qrqDwBdM0+Px38y+vXG1no8FJKIi/V4tnlU=; b=gru7la5pglmPBRDIv0ZO3T9C0fIN6Q1dw5v9MZQ7BEQFpJ7DwRLJcq/QFkB6qBGBAO lR88HZC7RiNceu9uL9n4vtKoGFf3dgdU7m4Y0vrxxbpWkaH/nxKmSnDdj2vrQ+PLmY8U J/FqUUtrPHAJRUONWol9OTQdL2KeUv5y1ethjtNHIML36C3dk/loVlve4f7kGzFDRRCp y+gaAy3wNctnUx2t4saHPrw/eINCygKFughUhbnh4aZvQ0WYPKrJUiJDTc4brZ8TtfxU W1sQ5h8ZN2PzpeAZ+IGtJjGyx8Ko1G85OG2REI5BIbuSmn+wr22sUsD4s9oL7u4tlMmK JV4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=YcQY+5Cs; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Q5s6TRu/"; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=rABlf9C3; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id v41-20020a05663835a900b004188c989102si22224jal.19.2023.05.12.06.22.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2023 06:22:56 -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=YcQY+5Cs; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Q5s6TRu/"; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=rABlf9C3; 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 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 1pxSiV-0002ih-IT; Fri, 12 May 2023 13:21:51 +0000 Received: from [172.30.20.202] (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 1pxSiU-0002ia-95 for openvpn-devel@lists.sourceforge.net; Fri, 12 May 2023 13:21: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-Subscribe:List-Post:List-Owner:List-Archive; bh=q+UawtwLgABdKxV/5kYvwoS2pF06V4RbgOfc2NmaqQg=; b=YcQY+5Cs5b1niYKVZbUarOamgk 6B8+0rPj0x/ncT3wFdnK4NstbxV981erhglbRaiU/TGpEF7zVoO5tRnzpjM6OsZBbBsXGqnnjgXCL tIhhjbPY7m9XbtSG2dquK3eFHDI4sHTytgjfTWyGCnJAftpFkHOmK5CfQ8pkGPGnFfE8=; 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=q+UawtwLgABdKxV/5kYvwoS2pF06V4RbgOfc2NmaqQg=; b=Q5s6TRu/FGaNBhKK9Gr4pnZW8P Yp/a2UuJili8t2J5BG9KWhQqO9/mqAoFegOTjiRfHMzV/8jB9Fu0RRmm4/lipnIGUESbu7MFA4vjS v002EkwZNUpDzEhY0uWPOWL/eG5+krGXUUuL9eTLSoKZK9tl/wk6el1onptoBTIjzWDg=; Received: from mout-p-201.mailbox.org ([80.241.56.171]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1pxSiP-0003kB-Ms for openvpn-devel@lists.sourceforge.net; Fri, 12 May 2023 13:21:50 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4QHqD14ZdXz9sT6 for ; Fri, 12 May 2023 15:21:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1683897697; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q+UawtwLgABdKxV/5kYvwoS2pF06V4RbgOfc2NmaqQg=; b=rABlf9C3cJBOXgmdzOc09B/TTBuaBNUzXfrCLYc1mQFFTrX51Z4WC1D7k/fT/X8oJR97Be OIe1U5uD3rAfxPLLqXAgXJbfDAREcRZLEFZDA0jONIU5AbCuby1toS7WMg3BNvZBK86aNE VvLe2lyhHcuTiXnCWCPuDDfKAJ20CXC503lqUJAXSoSpfWdsEo7MMLunJF+kdUvdLWLRhO p96gg6OU6iTjhTjhkg1S84MXSg2A6hDFR0Z+g0pbfFURXERzstb0rzlHovJDkoqwunGLFg gWlcH/0tb6bDCoVV0/YcIAbEfBnxMzZ6y7mjBj9FVuwI53XH2+hYbjI2k4Tywg== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Fri, 12 May 2023 15:21:36 +0200 Message-Id: <20230512132136.417404-1-frank@lichtenheld.com> In-Reply-To: <20230510112236.248026-3-frank@lichtenheld.com> References: <20230510112236.248026-3-frank@lichtenheld.com> MIME-Version: 1.0 X-Spam-Score: -0.9 (/) 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: Since in the end this always ends up as an uint16_t anyway, just make the conversion much earlier. Cleans up the code and removes some -Wconversion warnings. v2: - proper error handling in options.c Change-Id: Id8321dfbb8ad8d79f4bb2a9da61f8cd6b6c6ee26 Signed-off-by: Frank Lichtenheld --- src/openvpn/mss.c | 21 +++++++++++ src/openvpn/mss.h | 4 ++-- src/openvpn/mt [...] 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 [80.241.56.171 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_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.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Headers-End: 1pxSiP-0003kB-Ms Subject: [Openvpn-devel] [PATCH v2 2/3] Change type of frame.mss_fix to uint16_t 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?1765506082700618037?= X-GMAIL-MSGID: =?utf-8?q?1765694795020609034?= Since in the end this always ends up as an uint16_t anyway, just make the conversion much earlier. Cleans up the code and removes some -Wconversion warnings. v2: - proper error handling in options.c Change-Id: Id8321dfbb8ad8d79f4bb2a9da61f8cd6b6c6ee26 Signed-off-by: Frank Lichtenheld --- src/openvpn/mss.c | 21 +++++++++++---------- src/openvpn/mss.h | 4 ++-- src/openvpn/mtu.c | 2 +- src/openvpn/mtu.h | 2 +- src/openvpn/options.c | 9 ++++++++- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c index fd2d3c1d..44b316da 100644 --- a/src/openvpn/mss.c +++ b/src/openvpn/mss.c @@ -46,7 +46,7 @@ * if yes, hand to mss_fixup_dowork() */ void -mss_fixup_ipv4(struct buffer *buf, int maxmss) +mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss) { const struct openvpn_iphdr *pip; int hlen; @@ -74,7 +74,7 @@ mss_fixup_ipv4(struct buffer *buf, int maxmss) struct openvpn_tcphdr *tc = (struct openvpn_tcphdr *) BPTR(&newbuf); if (tc->flags & OPENVPN_TCPH_SYN_MASK) { - mss_fixup_dowork(&newbuf, (uint16_t) maxmss); + mss_fixup_dowork(&newbuf, maxmss); } } } @@ -86,7 +86,7 @@ mss_fixup_ipv4(struct buffer *buf, int maxmss) * (IPv6 header structure is sufficiently different from IPv4...) */ void -mss_fixup_ipv6(struct buffer *buf, int maxmss) +mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss) { const struct openvpn_ipv6hdr *pip6; struct buffer newbuf; @@ -132,7 +132,7 @@ mss_fixup_ipv6(struct buffer *buf, int maxmss) struct openvpn_tcphdr *tc = (struct openvpn_tcphdr *) BPTR(&newbuf); if (tc->flags & OPENVPN_TCPH_SYN_MASK) { - mss_fixup_dowork(&newbuf, (uint16_t) maxmss-20); + mss_fixup_dowork(&newbuf, maxmss-20); } } } @@ -193,13 +193,14 @@ mss_fixup_dowork(struct buffer *buf, uint16_t maxmss) { continue; } - mssval = (opt[2]<<8)+opt[3]; + mssval = opt[2] << 8; + mssval += opt[3]; if (mssval > maxmss) { - dmsg(D_MSS, "MSS: %d -> %d", (int) mssval, (int) maxmss); + dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, maxmss); accumulate = htons(mssval); - opt[2] = (maxmss>>8)&0xff; - opt[3] = maxmss&0xff; + opt[2] = (uint8_t)((maxmss>>8)&0xff); + opt[3] = (uint8_t)(maxmss&0xff); accumulate -= htons(maxmss); ADJUST_CHECKSUM(accumulate, tc->check); } @@ -293,7 +294,7 @@ frame_calculate_mssfix(struct frame *frame, struct key_type *kt, { /* we subtract IPv4 and TCP overhead here, mssfix method will add the * extra 20 for IPv6 */ - frame->mss_fix = options->ce.mssfix - (20 + 20); + frame->mss_fix = (uint16_t)(options->ce.mssfix - (20 + 20)); return; } @@ -327,7 +328,7 @@ frame_calculate_mssfix(struct frame *frame, struct key_type *kt, /* This is the target value our payload needs to be smaller */ unsigned int target = options->ce.mssfix - overhead; - frame->mss_fix = adjust_payload_max_cbc(kt, target) - payload_overhead; + frame->mss_fix = (uint16_t)(adjust_payload_max_cbc(kt, target) - payload_overhead); } diff --git a/src/openvpn/mss.h b/src/openvpn/mss.h index 1c4704bd..b2a68cf7 100644 --- a/src/openvpn/mss.h +++ b/src/openvpn/mss.h @@ -29,9 +29,9 @@ #include "mtu.h" #include "ssl_common.h" -void mss_fixup_ipv4(struct buffer *buf, int maxmss); +void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss); -void mss_fixup_ipv6(struct buffer *buf, int maxmss); +void mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss); void mss_fixup_dowork(struct buffer *buf, uint16_t maxmss); diff --git a/src/openvpn/mtu.c b/src/openvpn/mtu.c index 2925b7fe..3c8468a9 100644 --- a/src/openvpn/mtu.c +++ b/src/openvpn/mtu.c @@ -212,7 +212,7 @@ frame_print(const struct frame *frame, buf_printf(&out, "%s ", prefix); } buf_printf(&out, "["); - buf_printf(&out, " mss_fix:%d", frame->mss_fix); + buf_printf(&out, " mss_fix:%" PRIu16, frame->mss_fix); #ifdef ENABLE_FRAGMENT buf_printf(&out, " max_frag:%d", frame->max_fragment_size); #endif diff --git a/src/openvpn/mtu.h b/src/openvpn/mtu.h index b602b86b..c64398de 100644 --- a/src/openvpn/mtu.h +++ b/src/openvpn/mtu.h @@ -115,7 +115,7 @@ struct frame { * decryption/encryption or compression. */ } buf; - unsigned int mss_fix; /**< The actual MSS value that should be + uint16_t mss_fix; /**< The actual MSS value that should be * written to the payload packets. This * is the value for IPv4 TCP packets. For * IPv6 packets another 20 bytes must diff --git a/src/openvpn/options.c b/src/openvpn/options.c index fa435c1d..c26ee30d 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -7257,9 +7257,16 @@ add_option(struct options *options, VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); if (p[1]) { + int mssfix = positive_atoi(p[1]); + if (mssfix > UINT16_MAX) + { + msg(msglevel, "--mssfix value '%s' is invalid", p[1]); + goto err; + } + /* value specified, assume encapsulation is not * included unless "mtu" follows later */ - options->ce.mssfix = positive_atoi(p[1]); + options->ce.mssfix = mssfix; options->ce.mssfix_encap = false; options->ce.mssfix_default = false; }