From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 2ED645A005E for ; Fri, 27 Jan 2023 06:11:17 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4P35Jd4l3Jz4xG5; Fri, 27 Jan 2023 16:11:13 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1674796273; bh=UpIb2dJBVv4d+gjyT0SmjIs6DDqGFuH4SPp2C91t3ks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NbTIZCeJ1DZDGUvpm68irinUnuYO+p5pjeWZk7vnMhGzd+Tpecfe7S9G4Cn0Krk7w IzJ4yaqk64cKUylxp9X72XPvk6q2wBrBTGE0qqs03mlOc+JVtjqBjQ93PnvrznLVVV J8skygfIs+aYnvtfj9iOcEluQ65C9dYE42V47d/c= From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 4/4] tcp: Remove 'zero_len' goto from tcp_data_from_sock Date: Fri, 27 Jan 2023 16:11:10 +1100 Message-Id: <20230127051110.2513363-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230127051110.2513363-1-david@gibson.dropbear.id.au> References: <20230127051110.2513363-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ZJ7PWTJ67XBJCAFD2C76QXDMCCYZNBJT X-Message-ID-Hash: ZJ7PWTJ67XBJCAFD2C76QXDMCCYZNBJT 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.3 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: This goto exists purely to move this exception case out of line. Although that does make the "normal" path a little clearer, it comes at the cost of not knowing how where control will flow after jumping to the zero_len label. The exceptional case isn't that long, so just put it inline. Signed-off-by: David Gibson --- tcp.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tcp.c b/tcp.c index f7228d1..4ae5ed5 100644 --- a/tcp.c +++ b/tcp.c @@ -2165,8 +2165,18 @@ static int tcp_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn) if (len < 0) goto err; - if (!len) - goto zero_len; + if (!len) { + if ((conn->events & (SOCK_FIN_RCVD | TAP_FIN_SENT)) == SOCK_FIN_RCVD) { + if ((ret = tcp_send_flag(c, conn, FIN | ACK))) { + tcp_rst(c, conn); + return ret; + } + + conn_event(c, conn, TAP_FIN_SENT); + } + + return 0; + } sendlen = len - already_sent; if (sendlen <= 0) { @@ -2205,18 +2215,6 @@ err: } return ret; - -zero_len: - if ((conn->events & (SOCK_FIN_RCVD | TAP_FIN_SENT)) == SOCK_FIN_RCVD) { - if ((ret = tcp_send_flag(c, conn, FIN | ACK))) { - tcp_rst(c, conn); - return ret; - } - - conn_event(c, conn, TAP_FIN_SENT); - } - - return 0; } /** -- 2.39.1