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=RXuUe7ZV; 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 AF8F35A0620 for ; Tue, 15 Apr 2025 11:43:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744710208; 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=G2G8uSDqqI7pKslDf08fBwu2JWtTYCIIsb1bGzeWtOc=; b=RXuUe7ZVlw4621mYEQa/WD8CAKguISyXh8sQT7nJa8jFVUEQCQP9GFOuXhVC8AhbU+vz/Q 34YUj5Zbk8FwoV3kngRXD8j9eLGpqI0aeoH2wHdYgFZuc7OAjyc5zL7o2Sud6yLcshZwcE dUT0Y/e5DqOBL1Cnqa9K9EU7Q2pA3kQ= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-IljwSHWYMWKf57YVxrCY9g-1; Tue, 15 Apr 2025 05:43:26 -0400 X-MC-Unique: IljwSHWYMWKf57YVxrCY9g-1 X-Mimecast-MFC-AGG-ID: IljwSHWYMWKf57YVxrCY9g_1744710206 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2D0F51800EC5 for ; Tue, 15 Apr 2025 09:43:26 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1BCFE180175D; Tue, 15 Apr 2025 09:43:24 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v3 12/20] tcp: Convert tcp_data_from_tap() to use iov_tail Date: Tue, 15 Apr 2025 11:42:52 +0200 Message-ID: <20250415094300.65794-13-lvivier@redhat.com> In-Reply-To: <20250415094300.65794-1-lvivier@redhat.com> References: <20250415094300.65794-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JoIjPE65Mica3CqRViM8jNuIQwa4iomEUy-wfcVX33Q_1744710206 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: FHOS4ZJNBZPN4AW4GMRFMXF7SENMKNKH X-Message-ID-Hash: FHOS4ZJNBZPN4AW4GMRFMXF7SENMKNKH X-MailFrom: lvivier@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: Laurent Vivier 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: Use packet_data() and extract headers using IOV_PEEK_HEADER() rather than packet_get(). Signed-off-by: Laurent Vivier --- tcp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tcp.c b/tcp.c index 67d656a1cf97..a25fbc7ae182 100644 --- a/tcp.c +++ b/tcp.c @@ -1651,15 +1651,21 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, for (i = idx, iov_i = 0; i < (int)p->count; i++) { uint32_t seq, seq_offset, ack_seq; const struct tcphdr *th; - char *data; - size_t off; + struct iov_tail data; + struct tcphdr thc; + size_t off, size; + int count; - th = packet_get(p, i, 0, sizeof(*th), &len); + if (!packet_data(p, i, &data)) + return -1; + + th = IOV_PEEK_HEADER(&data, thc); if (!th) return -1; - len += sizeof(*th); + len = iov_tail_size(&data); off = th->doff * 4UL; + if (off < sizeof(*th) || off > len) return -1; @@ -1669,9 +1675,7 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, } len -= off; - data = packet_get(p, i, off, len, NULL); - if (!data) - continue; + iov_tail_drop(&data, off); seq = ntohl(th->seq); if (SEQ_LT(seq, conn->seq_from_tap) && len <= 1) { @@ -1745,10 +1749,14 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, continue; } - tcp_iov[iov_i].iov_base = data + seq_offset; - tcp_iov[iov_i].iov_len = len - seq_offset; - seq_from_tap += tcp_iov[iov_i].iov_len; - iov_i++; + iov_tail_drop(&data, seq_offset); + size = len - seq_offset; + count = iov_tail_slice(&tcp_iov[iov_i], UIO_MAXIOV - iov_i, + &data, &size); + if (count < 0) + break; + seq_from_tap += size; + iov_i += count; if (keep == i) keep = -1; -- 2.49.0