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=a6V0Rlu6; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id A20B45A061A for ; Wed, 19 Feb 2025 04:14:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1739934871; bh=barheYSw88Sg3KOTFT0X+x5gUPvCmnvIA4dWAS3w18E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a6V0Rlu6gzMvGj++4JT7BlMU9adgMbmz41ffDzek7LKdOs8c9o9L4FdkUYMWYtqxm N4Et9Hv1FmWipC8mfYjlxBuY0QlZjmQ0Mw5m/Rb+kCxmENERtWK735rPVO6NKtN2e1 VQJZpflvFCK2GSowJqJiqvp/0eOpTk/rRhwhb87XxiC3boFBbCUjNjj/0k8+49mkHS 5UHZ35D/gKefqHKp8mY/O5nmhQPa5f84JPPLhmCwpoudeqoqss+/Zf6D3JHtdDLp/l nStMDWMEHBqqyjsSISb06uZcxxtCJ2PFyik3oRRRo/VApeE/fq2A8xgnlWD/LW+yJV stPmngVk3pCCA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4YyM1z2Gj0z4wyw; Wed, 19 Feb 2025 14:14:31 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/3] conf: Use 0 instead of -1 as "unassigned" mtu value Date: Wed, 19 Feb 2025 14:14:28 +1100 Message-ID: <20250219031429.3708026-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219031429.3708026-1-david@gibson.dropbear.id.au> References: <20250219031429.3708026-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: U4G6NJ5BPUTLIP55EGYTVWFX574UZ673 X-Message-ID-Hash: U4G6NJ5BPUTLIP55EGYTVWFX574UZ673 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: On the command line -m 0 means "don't assign an MTU" (letting the guest use its default. However, internally we use (c->mtu == -1) to represent that state. We use (c->mtu == 0) to represent "the user didn't specify on the command line, so use the default" - but this is only used during conf(), never afterwards. This is unnecessarily confusing. We can instead just initialise c->mtu to its default (65520) before parsing options and use 0 on both the command line and internally to represent the "don't assign" special case. This ensures that c->mtu is always 0..65535, so we can store it in a uint16_t which is more natural. Signed-off-by: David Gibson --- conf.c | 11 ++--------- dhcp.c | 2 +- ndp.c | 2 +- passt.h | 3 ++- pasta.c | 2 +- tcp.c | 2 +- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/conf.c b/conf.c index 335f37c9..c5ee07b0 100644 --- a/conf.c +++ b/conf.c @@ -1413,6 +1413,7 @@ void conf(struct ctx *c, int argc, char **argv) optstring = "+dqfel:hs:F:p:P:m:a:n:M:g:i:o:D:S:H:461t:u:"; } + c->mtu = ROUND_DOWN(ETH_MAX_MTU - ETH_HLEN, sizeof(uint32_t)); c->tcp.fwd_in.mode = c->tcp.fwd_out.mode = FWD_UNSET; c->udp.fwd_in.mode = c->udp.fwd_out.mode = FWD_UNSET; memcpy(c->our_tap_mac, MAC_OUR_LAA, ETH_ALEN); @@ -1662,12 +1663,7 @@ void conf(struct ctx *c, int argc, char **argv) if (errno || *e) die("Invalid MTU: %s", optarg); - if (!mtu) { - c->mtu = -1; - break; - } - - if (mtu < ETH_MIN_MTU || mtu > ETH_MAX_MTU) { + 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); } @@ -1980,9 +1976,6 @@ void conf(struct ctx *c, int argc, char **argv) c->no_dhcpv6 = 1; } - if (!c->mtu) - c->mtu = ROUND_DOWN(ETH_MAX_MTU - ETH_HLEN, sizeof(uint32_t)); - get_dns(c); if (!*c->pasta_ifn) { diff --git a/dhcp.c b/dhcp.c index 4a209f10..66a716e3 100644 --- a/dhcp.c +++ b/dhcp.c @@ -417,7 +417,7 @@ int dhcp(const struct ctx *c, const struct pool *p) &c->ip4.guest_gw, sizeof(c->ip4.guest_gw)); } - if (c->mtu != -1) { + if (c->mtu) { opts[26].slen = 2; opts[26].s[0] = c->mtu / 256; opts[26].s[1] = c->mtu % 256; diff --git a/ndp.c b/ndp.c index 37bf7a35..ded2081d 100644 --- a/ndp.c +++ b/ndp.c @@ -256,7 +256,7 @@ static void ndp_ra(const struct ctx *c, const struct in6_addr *dst) ptr = &ra.var[0]; - if (c->mtu != -1) { + if (c->mtu) { struct opt_mtu *mtu = (struct opt_mtu *)ptr; *mtu = (struct opt_mtu) { .header = { diff --git a/passt.h b/passt.h index 1f0dab54..28d13892 100644 --- a/passt.h +++ b/passt.h @@ -274,6 +274,8 @@ struct ctx { int fd_repair; unsigned char our_tap_mac[ETH_ALEN]; unsigned char guest_mac[ETH_ALEN]; + uint16_t mtu; + uint64_t hash_secret[2]; int ifi4; @@ -298,7 +300,6 @@ struct ctx { int no_icmp; struct icmp_ctx icmp; - int mtu; int no_dns; int no_dns_search; int no_dhcp_dns; diff --git a/pasta.c b/pasta.c index 585a51c6..fa3e7de5 100644 --- a/pasta.c +++ b/pasta.c @@ -319,7 +319,7 @@ void pasta_ns_conf(struct ctx *c) if (c->pasta_conf_ns) { unsigned int flags = IFF_UP; - if (c->mtu != -1) + if (c->mtu) nl_link_set_mtu(nl_sock_ns, c->pasta_ifi, c->mtu); if (c->ifi6) /* Avoid duplicate address detection on link up */ diff --git a/tcp.c b/tcp.c index f498f5bc..e3c0a53b 100644 --- a/tcp.c +++ b/tcp.c @@ -1139,7 +1139,7 @@ int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn, if (flags & SYN) { int mss; - if (c->mtu == -1) { + if (!c->mtu) { mss = tinfo.tcpi_snd_mss; } else { mss = c->mtu - sizeof(struct tcphdr); -- 2.48.1