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=PzGN2bgY; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 7E0185A0276 for ; Wed, 02 Apr 2025 19:24:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743614645; 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=LvmvVVbjdcSxQQ44NuXeRQOGKDxb6JFWfSC3CVdjTVA=; b=PzGN2bgYhuveGEZ9ufZCJqoVIXiBdrsCIn5vGnXZeLo4w+uvi9N75sU1YhjU5DBtqT/O9k TIa/CdcAqeJu1vQa9NEaWNyY02cvVGgf3lqCydgrS5gr+9doUVjoMHsVWhFsgLLgdregcw r5sdJZbVU7hqn4g3jG42d/e/8EtjGkQ= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-377-nl_l9wWrOCacE9AZomT-6g-1; Wed, 02 Apr 2025 13:24:02 -0400 X-MC-Unique: nl_l9wWrOCacE9AZomT-6g-1 X-Mimecast-MFC-AGG-ID: nl_l9wWrOCacE9AZomT-6g_1743614641 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 798ED19560B0 for ; Wed, 2 Apr 2025 17:24:01 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.33.101]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6A43A19560AD; Wed, 2 Apr 2025 17:24:00 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 10/18] tcp: Convert tcp_tap_handler() to use iov_tail Date: Wed, 2 Apr 2025 19:23:35 +0200 Message-ID: <20250402172343.858187-11-lvivier@redhat.com> In-Reply-To: <20250402172343.858187-1-lvivier@redhat.com> References: <20250402172343.858187-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: O27iEDEX9Ya5oVmE6wJ3rT46klv6RmxNobbSuoTc3vw_1743614641 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: QKHUGJZXCP54HX5JLCDGM6ODJP6QBNLW X-Message-ID-Hash: QKHUGJZXCP54HX5JLCDGM6ODJP6QBNLW 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_base() and extract headers using IOV_REMOVE_HEADER() and iov_peek_header_() rather than packet_get(). Signed-off-by: Laurent Vivier --- tcp.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tcp.c b/tcp.c index a4c840e6721c..790714a08793 100644 --- a/tcp.c +++ b/tcp.c @@ -310,6 +310,8 @@ #include "tcp_buf.h" #include "tcp_vu.h" +#define OPTLEN_MAX (((1UL << 4) - 6) * 4UL) + #ifndef __USE_MISC /* From Linux UAPI, missing in netinet/tcp.h provided by musl */ struct tcp_repair_opt { @@ -1957,7 +1959,10 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, { struct tcp_tap_conn *conn; const struct tcphdr *th; + char optsc[OPTLEN_MAX]; + struct iov_tail data; size_t optlen, len; + struct tcphdr thc; const char *opts; union flow *flow; flow_sidx_t sidx; @@ -1966,15 +1971,19 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, (void)pif; - th = packet_get(p, idx, 0, sizeof(*th), &len); + if (!packet_base(p, idx, &data)) + return 1; + + len = iov_tail_size(&data); + + th = IOV_REMOVE_HEADER(&data, thc); if (!th) return 1; - len += sizeof(*th); optlen = th->doff * 4UL - sizeof(*th); /* Static checkers might fail to see this: */ - optlen = MIN(optlen, ((1UL << 4) /* from doff width */ - 6) * 4UL); - opts = packet_get(p, idx, sizeof(*th), optlen, NULL); + optlen = MIN(optlen, OPTLEN_MAX); + opts = (char *)iov_peek_header_(&data, &optsc[0], optlen, 1); sidx = flow_lookup_af(c, IPPROTO_TCP, PIF_TAP, af, saddr, daddr, ntohs(th->source), ntohs(th->dest)); -- 2.49.0