From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JNFGwJRV; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 7A73A5A0279 for ; Thu, 11 Sep 2025 02:24:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757550261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WX8gOIolNZf/XfK3YWiZs9cBe0bOx5k2zkCeZE4wmko=; b=JNFGwJRVdS/ykfR+k8Ax4cFxf5selklEX4jYKx9kDycMKdBWITfSbBDdOuRmYPGGKxsghu CRKfOJU3QeIMcaXRkpgaeN7FDFufzZ2+TQtjMTsiFMtftDGbzHU8ZU5gxaFkDHndL2v/sC DL2doAqknzgeKm9btA8N43HKDJGH5Vg= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-Sr3N4oe9OgGdMYR1LlGKyg-1; Wed, 10 Sep 2025 20:24:19 -0400 X-MC-Unique: Sr3N4oe9OgGdMYR1LlGKyg-1 X-Mimecast-MFC-AGG-ID: Sr3N4oe9OgGdMYR1LlGKyg_1757550259 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4b5f4e4fe41so7490691cf.2 for ; Wed, 10 Sep 2025 17:24:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757550259; x=1758155059; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WX8gOIolNZf/XfK3YWiZs9cBe0bOx5k2zkCeZE4wmko=; b=JwzQPECinE1YoKtNU9ssE8m/XT/3SYzOJJGIH2TstS75ir+WrXOmi+peVmPVJfaycj hNLk3nRVw+H+dEwx6IWu+hMZZzxf+WAd72M0QAGAV45kbs2kEcwA0tuwOn1NNyyDB9/k iyhNLRLQBbaEOQFOPd7E0kgpg+B5C9zgc3+sogY7KJvfk5YJzoEqF8hjgChziFN1WZYu Tr5R0wQKYrgEuCN5PCwnprRjzgdOpL6h+fD84VRz24vp66tKu95wvRWKZ2kffyhGVLiq P6bdfXkOyo8C1Mu4j4SpAlo2MLJtbP0/oriJH4R0KohSwAMY8bu/U52QGhpS1q9MW5eE Rs3A== X-Forwarded-Encrypted: i=1; AJvYcCX0fx3uXqzz1sMt6qbcHfcs148Xm9dHPBGTuF2IOHRt8OCMFkUOq43epzlb20JdrREOOYZhT8GEIIY=@passt.top X-Gm-Message-State: AOJu0YzsvR9vIEU69naAm0hs2IvqcsD2pXogdc3oQOvfKchdN6hPnu0m wgaloysP/oC4x4N4EqX6R5i15zEuzCGpHESD4pvfIXwA2Q7+KjKzdK6M7RJ7w5JEHdfqMUskA1C 9aXJDNlADtRyjUCEea3ir2N4zr4PHpwe27YGxNubdBpjEqz+w4CegNQ== X-Gm-Gg: ASbGnctplvYxu60hmFWk+/4R2BblfPwlem6y7mEBlEVRIKf9yLwOnqecfukf83fCkSJ fDY+XCVfIHeEUAsrjvpXxxCYYARAymRol/tuy4/1wEYPUYHo6i9gq/RFoZfjNx5nD6b0HJK3Dgv shYjfB+jvQ7c0lOdKEZ9vyKphxUu8vOz95Em4tHjZAz9nLiJj1jLUsTYbaW7G2nhhLnJtkft82+ fEPm4Ge6CNuwN9T3saIiEbIlTh/Kj4i2GXwKn8xFLYLacgkdMK2OhNc/KlKBZMC+qiurCyCQ6MF ajPsOnAJm5psQzj1q7Cys3deWEO5c6VWG5HAut3AUc+iKfCzsV9iTg3jNyq09rHh3BDzurZ7wHK 5X0omUqBKHg== X-Received: by 2002:a05:622a:60a:b0:4b3:4d9d:940 with SMTP id d75a77b69052e-4b5f8445ca0mr173537231cf.54.1757550259195; Wed, 10 Sep 2025 17:24:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzm9B8HV2lQ9xbKB9ovpmPwIDx0TOtRRFqtpQKQ//hI/aHWWuEPaLg3O84zKjrcK/wzGG+UA== X-Received: by 2002:a05:622a:60a:b0:4b3:4d9d:940 with SMTP id d75a77b69052e-4b5f8445ca0mr173537071cf.54.1757550258830; Wed, 10 Sep 2025 17:24:18 -0700 (PDT) Received: from ?IPV6:2001:4958:2206:8901:6025:1483:4146:72dd? ([2001:4958:2206:8901:6025:1483:4146:72dd]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4b639dc918bsm1118491cf.36.2025.09.10.17.24.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Sep 2025 17:24:18 -0700 (PDT) Message-ID: <38c27afd-83ad-4232-ba59-2b3a17f01bff@redhat.com> Date: Wed, 10 Sep 2025 20:24:17 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 7/8] tcp: Fast re-transmit if half-closed, make TAP_FIN_RCVD path consistent To: Stefano Brivio , passt-dev@passt.top References: <20250909181655.2990223-1-sbrivio@redhat.com> <20250909181655.2990223-8-sbrivio@redhat.com> From: Jon Maloy In-Reply-To: <20250909181655.2990223-8-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zY5COZDX81r8n_9bvokuFgJlEDcVN6h78vOZkq-FDko_1757550259 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: 66SF4JQHNFBTPZFAKHP4NZ2W24GDMDLF X-Message-ID-Hash: 66SF4JQHNFBTPZFAKHP4NZ2W24GDMDLF X-MailFrom: jmaloy@redhat.com 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: Paul Holzinger , 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 2025-09-09 14:16, Stefano Brivio wrote: > We currently have a number of discrepancies in the tcp_tap_handler() > path between the half-closed connection path and the regular one, and > they are mostly a result of code duplication, which comes in turn from > the fact that tcp_data_from_tap() deals with data transfers as well as > general connection bookkeeping, so we can't use it for half-closed > connections. > > This suggests that we should probably rework it into two or more > functions, in the long term, Agreed. but for the moment being I'm just fixing > one obvious issue, which is the lack of fast retransmissions in the > TAP_FIN_RCVD path, and a potential one, which is the fact we don't > handle socket flush failures. > > Add fast re-transmit for half-closed connections, and handle the case > of socket flush (tcp_sock_consume()) flush failure in the same way as > tcp_data_from_tap() handles it. > > Signed-off-by: Stefano Brivio Reviewed-by: Jon Maloy > --- > tcp.c | 42 +++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 39 insertions(+), 3 deletions(-) > > diff --git a/tcp.c b/tcp.c > index 9c70a25..5163dbf 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1652,6 +1652,23 @@ static int tcp_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn) > return tcp_buf_data_from_sock(c, conn); > } > > +/** > + * tcp_packet_data_len() - Get data (TCP payload) length for a TCP packet > + * @th: Pointer to TCP header > + * @l4len: TCP packet length, including TCP header > + * > + * Return: data length of TCP packet, -1 on invalid value of Data Offset field > + */ > +static ssize_t tcp_packet_data_len(const struct tcphdr *th, size_t l4len) > +{ > + size_t off = th->doff * 4UL; > + > + if (off < sizeof(*th) || off > l4len) > + return -1; > + > + return l4len - off; > +} > + > /** > * tcp_data_from_tap() - tap/guest data for established connection > * @c: Execution context > @@ -2113,9 +2130,28 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, > > /* Established connections not accepting data from tap */ > if (conn->events & TAP_FIN_RCVD) { > - tcp_sock_consume(conn, ntohl(th->ack_seq)); > - tcp_update_seqack_from_tap(c, conn, ntohl(th->ack_seq)); > - if (tcp_tap_window_update(c, conn, ntohs(th->window))) > + bool retr; > + > + retr = th->ack && !tcp_packet_data_len(th, l4len) && !th->fin && > + ntohl(th->ack_seq) == conn->seq_ack_from_tap && > + ntohs(th->window) == conn->wnd_from_tap; > + > + /* On socket flush failure, pretend there was no ACK, try again > + * later > + */ > + if (th->ack && !tcp_sock_consume(conn, ntohl(th->ack_seq))) > + tcp_update_seqack_from_tap(c, conn, ntohl(th->ack_seq)); > + > + if (retr) { > + flow_trace(conn, > + "fast re-transmit, ACK: %u, previous sequence: %u", > + ntohl(th->ack_seq), conn->seq_to_tap); > + > + if (tcp_rewind_seq(c, conn)) > + return -1; > + } > + > + if (tcp_tap_window_update(c, conn, ntohs(th->window)) || retr) > tcp_data_from_sock(c, conn); > > if (conn->seq_ack_from_tap == conn->seq_to_tap) {