From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 858755A0278 for ; Thu, 16 Feb 2023 06:43:23 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PHP4L1J4Zz4x8P; Thu, 16 Feb 2023 16:43:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1676526194; bh=wULg8aHh9dX9Y7eMAcdTPuo0zgMoGDj7j94a3QAwqwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NMKdkQ5mrOV6Qrc30r+EIR9//EpoHcODTSuk1fL4rJUEQzouAx30MFeCRcVTzfLuu lma8+Sj7FUsDA8djXOsd4p2LxLjTGCM3GkvDXd+7J9rFJmBgyIQHNYgH37LogWDJFd +L2lCmfPv7UA+VfZXcLTUGwQoZo2WPCWAVJKkBNU= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 4/4] tcp: Remove 'zero_len' goto from tcp_data_from_sock Date: Thu, 16 Feb 2023 16:43:11 +1100 Message-Id: <20230216054311.2131853-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230216054311.2131853-1-david@gibson.dropbear.id.au> References: <20230216054311.2131853-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: U3JZM2WHKULORLNZMXJDFS5PFQJVLD54 X-Message-ID-Hash: U3JZM2WHKULORLNZMXJDFS5PFQJVLD54 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 b101441..10dbdb8 100644 --- a/tcp.c +++ b/tcp.c @@ -2193,8 +2193,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) { @@ -2233,18 +2243,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