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=DuSQKiyA; 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 A49E35A0622 for ; Tue, 15 Apr 2025 11:43:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744710222; 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=9fXIU30j8OW91Ct3AWYPCMrvKH6+9CxN6EJJjqqghBw=; b=DuSQKiyA/E/JxpRBec5+azbqgVmPoZ/CSdIGGwrftkCcswviJRYyZClntLL7vII03XOZ+5 ZbY+hyXsz3RpyX5qR9kb2/10cnaW/Dce65dkrSYGqDcCG53U5jGqxPkePB5Gd+TZrrKlsy ixTeyfjIdUfN/8vr+15AqqBHFoTtCqw= Received: from mx-prod-mc-02.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-94-8wfTiBLTPHaYfGAcrIFEhg-1; Tue, 15 Apr 2025 05:43:41 -0400 X-MC-Unique: 8wfTiBLTPHaYfGAcrIFEhg-1 X-Mimecast-MFC-AGG-ID: 8wfTiBLTPHaYfGAcrIFEhg_1744710220 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3152E195609E for ; Tue, 15 Apr 2025 09:43:40 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.6]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1B8A8180B491; Tue, 15 Apr 2025 09:43:38 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v3 19/20] tap: Convert tap4_handler() to iov_tail Date: Tue, 15 Apr 2025 11:42:59 +0200 Message-ID: <20250415094300.65794-20-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.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ASu_oDBiqiFap9Mcxz4x6ZrwtPyOoBwXsHoy9Tgbpds_1744710220 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: R3RS647FBWGB2A7U2KKKGWXMDV7A53Z7 X-Message-ID-Hash: R3RS647FBWGB2A7U2KKKGWXMDV7A53Z7 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 --- tap.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tap.c b/tap.c index ca25ff9e90d9..aad6d4dc1f61 100644 --- a/tap.c +++ b/tap.c @@ -704,28 +704,34 @@ static int tap4_handler(struct ctx *c, const struct pool *in, i = 0; resume: for (seq_count = 0, seq = NULL; i < in->count; i++) { - size_t l2len, l3len, hlen, l4len; + size_t l3len, hlen, l4len; const struct ethhdr *eh; const struct udphdr *uh; struct iov_tail data; + struct ethhdr ehc; struct iphdr *iph; - const char *l4h; + struct iphdr iphc; + struct udphdr uhc; - packet_get(in, i, 0, 0, &l2len); + if (!packet_data(in, i, &data)) + continue; - eh = packet_get(in, i, 0, sizeof(*eh), &l3len); + eh = IOV_PEEK_HEADER(&data, ehc); if (!eh) continue; if (ntohs(eh->h_proto) == ETH_P_ARP) { PACKET_POOL_P(pkt, 1, in->buf, in->buf_size); - data = IOV_TAIL_FROM_BUF((void *)eh, l2len, 0); packet_add(pkt, &data); arp(c, pkt); continue; } - iph = packet_get(in, i, sizeof(*eh), sizeof(*iph), NULL); + if (!iov_tail_drop(&data, sizeof(*eh))) + continue; + l3len = iov_tail_size(&data); + + iph = IOV_PEEK_HEADER(&data, iphc); if (!iph) continue; @@ -753,8 +759,9 @@ resume: if (iph->saddr && c->ip4.addr_seen.s_addr != iph->saddr) c->ip4.addr_seen.s_addr = iph->saddr; - l4h = packet_get(in, i, sizeof(*eh) + hlen, l4len, NULL); - if (!l4h) + if (!iov_tail_drop(&data, hlen)) + continue; + if (iov_tail_size(&data) != l4len) continue; if (iph->protocol == IPPROTO_ICMP) { @@ -765,7 +772,6 @@ resume: tap_packet_debug(iph, NULL, NULL, 0, NULL, 1); - data = IOV_TAIL_FROM_BUF((void *)l4h, l4len, 0); packet_add(pkt, &data); icmp_tap_handler(c, PIF_TAP, AF_INET, &iph->saddr, &iph->daddr, @@ -773,15 +779,17 @@ resume: continue; } - uh = packet_get(in, i, sizeof(*eh) + hlen, sizeof(*uh), NULL); + uh = IOV_PEEK_HEADER(&data, uhc); if (!uh) continue; if (iph->protocol == IPPROTO_UDP) { + struct iov_tail eh_data; + PACKET_POOL_P(pkt, 1, in->buf, in->buf_size); - data = IOV_TAIL_FROM_BUF((void *)eh, l2len, 0); - packet_add(pkt, &data); + packet_data(in, i, &eh_data); + packet_add(pkt, &eh_data); if (dhcp(c, pkt)) continue; } @@ -832,7 +840,6 @@ resume: #undef L4_SET append: - data = IOV_TAIL_FROM_BUF((void *)l4h, l4len, 0); packet_add((struct pool *)&seq->p, &data); } -- 2.49.0