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=IPm+zsI2; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E7FCA5A0274 for ; Wed, 19 Mar 2025 06:14:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1742361265; bh=Vlj6c/l4sCQL1Jj5BT77CdyAVyALhPH+gFlR7EUY8Ng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IPm+zsI20BOKumtKswW0awZT6huVmn3F3akQzz//wc3A/W3SHTPyAwhExLoF09Bi9 rCnqwSDF+sezOladl6X1tseiIT0U14k3rArS/oa339uTZmXAT8wzqlDlvfrXUE3la+ ucydxP7d/OdjZI5S/2JLC24KBDBmhS7OB4XaNlMb0+9x0SFQG8h5IXuylP3qYgimdl RJ4x+k2eB68dDu+HPkmr4m4JV791juOKKryai5Jo/vj2nPqNWHsGqZnSectlQQdzP3 Qocyo1rEjPXT34tfxy7ujgpHbX3R57bMClwkFJYChRUwOVHO8vLYgEDuvnIckCiZoJ YPoiwVy5uWoCg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZHcMP12l3z4x2g; Wed, 19 Mar 2025 16:14:25 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 1/3] migrate, tcp: More careful marshalling of mss parameter during migration Date: Wed, 19 Mar 2025 16:14:21 +1100 Message-ID: <20250319051423.2378689-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250319051423.2378689-1-david@gibson.dropbear.id.au> References: <20250319051423.2378689-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: AAPCO7EBR2ADNSDTB4PSA4YJEKJXRLIZ X-Message-ID-Hash: AAPCO7EBR2ADNSDTB4PSA4YJEKJXRLIZ 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: During migration we extract the limit on segment size using TCP_MAXSEG, and set it on the other side with TCP_REPAIR_OPTIONS. However, unlike most 32-bit values we transfer we transfer it in native endian, not network endian. This is not correct; add it to the list of endian fixups we make. In addition, while MAXSEG will be 32-bits in practice, and is given as such to TCP_REPAIR_OPTIONS, the TCP_MAXSEG sockopt treats it as an 'int'. It's not strictly safe to pass a uint32_t to a getsockopt() expecting an int, although we'll get away with it on most (maybe all) platforms. Correct this as well. Signed-off-by: David Gibson --- tcp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tcp.c b/tcp.c index a4c840e6..163ddd60 100644 --- a/tcp.c +++ b/tcp.c @@ -2847,14 +2847,17 @@ static int tcp_flow_dump_tinfo(const struct tcp_tap_conn *conn, static int tcp_flow_dump_mss(const struct tcp_tap_conn *conn, struct tcp_tap_transfer_ext *t) { + int val; socklen_t sl = sizeof(t->mss); - if (getsockopt(conn->sock, SOL_TCP, TCP_MAXSEG, &t->mss, &sl)) { + if (getsockopt(conn->sock, SOL_TCP, TCP_MAXSEG, &val, &sl)) { int rc = -errno; flow_perror(conn, "Getting MSS"); return rc; } + t->mss = (uint32_t)val; + return 0; } @@ -3301,6 +3304,7 @@ int tcp_flow_migrate_source_ext(int fd, const struct tcp_tap_conn *conn) t->sndq = htonl(t->sndq); t->notsent = htonl(t->notsent); t->rcvq = htonl(t->rcvq); + t->mss = htonl(t->mss); t->snd_wl1 = htonl(t->snd_wl1); t->snd_wnd = htonl(t->snd_wnd); @@ -3514,6 +3518,7 @@ int tcp_flow_migrate_target_ext(struct ctx *c, struct tcp_tap_conn *conn, int fd t.sndq = ntohl(t.sndq); t.notsent = ntohl(t.notsent); t.rcvq = ntohl(t.rcvq); + t.mss = ntohl(t.mss); t.snd_wl1 = ntohl(t.snd_wl1); t.snd_wnd = ntohl(t.snd_wnd); -- 2.48.1