From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=jTPz6LUP; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 66F7D5A9C3A for ; Wed, 05 Mar 2025 07:20:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1741155605; bh=t3BisUu29Mf+FG/Q0LqcIOQS5y1iEvWgzPhSOan4DRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jTPz6LUPt3hp8+5oWlNNdK7jdeflKIcLIO5BAcFAqO5dhJahEt7wXj28TtI4njnjs URzHBHnvtOKDQAxsCbJFOtmt1uRq0E0vhrurtmIzTb6TX5qt3uSzxQojt9SmyWIqaz j3yQrZQgTp/8nPuxWI0MnWpRiHRY9kiowmiOtI0akj0P8jsChgNFGtgzrOgeMOPZwZ Frxwei7njCDM5eW/0CALUeuyrxiIiyIcpsQxTZX7mo+MFaUiijt2v+Mg8OxBDi/iY7 i8NqXPoXhg8X+XDRMUA/MP6yNCgy6cudCgQNAnUNcTaQAWr253FeV+jOmg1oCH2nQ8 /2RbuYbCvyXqg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Z72Td1WN0z4wcw; Wed, 5 Mar 2025 17:20:05 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v4 1/1] conf: Be more precise about minimum MTUs Date: Wed, 5 Mar 2025 17:20:03 +1100 Message-ID: <20250305062003.1700831-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305062003.1700831-1-david@gibson.dropbear.id.au> References: <20250305062003.1700831-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: OUCTCNXZPRQSEJW3L2DX4YG3JL2EMM2A X-Message-ID-Hash: OUCTCNXZPRQSEJW3L2DX4YG3JL2EMM2A X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Currently we reject the -m option if given a value less than ETH_MIN_MTU (68). That define is derived from the kernel, but its name is misleading: it doesn't really have anything to do with Ethernet per se, but is rather the minimum payload any L2 link must be able to handle in order to carry IPv4. For IPv6, it's not sufficient: that requires an MTU of at least 1280. Newer kernels have better named constants IPV4_MIN_MTU and IPv6_MIN_MTU. Copy and use those constants instead, along with some more specific error messages. Signed-off-by: David Gibson --- conf.c | 18 +++++++++++++++--- ip.h | 7 +++++++ util.h | 6 ------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/conf.c b/conf.c index c5ee07b0..065e7201 100644 --- a/conf.c +++ b/conf.c @@ -1663,9 +1663,9 @@ void conf(struct ctx *c, int argc, char **argv) if (errno || *e) die("Invalid MTU: %s", optarg); - if (mtu && (mtu < ETH_MIN_MTU || mtu > ETH_MAX_MTU)) { - die("MTU %lu out of range (%u..%u)", mtu, - ETH_MIN_MTU, ETH_MAX_MTU); + if (mtu > ETH_MAX_MTU) { + die("MTU %lu too large (max %u)", + mtu, ETH_MAX_MTU); } c->mtu = mtu; @@ -1842,9 +1842,21 @@ void conf(struct ctx *c, int argc, char **argv) c->ifi4 = conf_ip4(ifi4, &c->ip4); if (!v4_only) c->ifi6 = conf_ip6(ifi6, &c->ip6); + + if (c->ifi4 && c->mtu < IPV4_MIN_MTU) { + warn("MTU %"PRIu16" is too small for IPv4 (minimum %u)", + c->mtu, IPV4_MIN_MTU); + } + if (c->ifi6 && c->mtu < IPV6_MIN_MTU) { + warn("MTU %"PRIu16" is too small for IPv6 (minimum %u)", + c->mtu, IPV6_MIN_MTU); + } + if ((*c->ip4.ifname_out && !c->ifi4) || (*c->ip6.ifname_out && !c->ifi6)) die("External interface not usable"); + + if (!c->ifi4 && !c->ifi6) { info("No external interface as template, switch to local mode"); diff --git a/ip.h b/ip.h index 858cc899..d9099bda 100644 --- a/ip.h +++ b/ip.h @@ -105,4 +105,11 @@ static const struct in6_addr in6addr_ll_all_nodes = { /* IPv4 Limited Broadcast (RFC 919, Section 7), 255.255.255.255 */ static const struct in_addr in4addr_broadcast = { 0xffffffff }; +#ifndef IPV4_MIN_MTU +#define IPV4_MIN_MTU 68 +#endif +#ifndef IPV6_MIN_MTU +#define IPV6_MIN_MTU 1280 +#endif + #endif /* IP_H */ diff --git a/util.h b/util.h index 50e96d32..0f70f4d4 100644 --- a/util.h +++ b/util.h @@ -34,15 +34,9 @@ #ifndef ETH_MAX_MTU #define ETH_MAX_MTU USHRT_MAX #endif -#ifndef ETH_MIN_MTU -#define ETH_MIN_MTU 68 -#endif #ifndef IP_MAX_MTU #define IP_MAX_MTU USHRT_MAX #endif -#ifndef IPV6_MIN_MTU -#define IPV6_MIN_MTU 1280 -#endif #ifndef MIN #define MIN(x, y) (((x) < (y)) ? (x) : (y)) -- 2.48.1