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=WbYg7KY1; 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 9C50E5A061C for ; Fri, 11 Apr 2025 15:11:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744377071; 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=fOynT+f1RMiRZwB03hsqL93i0+OEuEj3JoJBpynrJBk=; b=WbYg7KY1NCSV8LuYTj/CdYBzXPcfAqCBaXqBiJZm+E3JlgJXxnmVWQlYBG6iVJ1wL4Z6vO zL6BDYeJ5AxJFIBiujlgDEk3bMSr4J4E04bn6KWPzfUR4JzpUxzgO+W3pHlMnEoKPktfAp pTzNMyw/m2gL4Gha8WGpn5kXexSaYTM= 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-108-uhv81BsVP8CScnB7M9S4cg-1; Fri, 11 Apr 2025 09:11:10 -0400 X-MC-Unique: uhv81BsVP8CScnB7M9S4cg-1 X-Mimecast-MFC-AGG-ID: uhv81BsVP8CScnB7M9S4cg_1744377069 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 79E2E19560AB for ; Fri, 11 Apr 2025 13:11:09 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.44.32.165]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6968B19560AD; Fri, 11 Apr 2025 13:11:08 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH v2 19/20] tap: Convert tap4_handler() to iov_tail Date: Fri, 11 Apr 2025 15:10:29 +0200 Message-ID: <20250411131031.1398006-20-lvivier@redhat.com> In-Reply-To: <20250411131031.1398006-1-lvivier@redhat.com> References: <20250411131031.1398006-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: bDyW7D08FvlUcVrx5XUD1wnVILjkV2TwMvjsbE1O8fk_1744377069 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: QUBQG2UUL77Q4FMKEOFHQNPSJHPWR62Q X-Message-ID-Hash: QUBQG2UUL77Q4FMKEOFHQNPSJHPWR62Q 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_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 e8726ae35cef..7899902e1042 100644 --- a/tap.c +++ b/tap.c @@ -699,28 +699,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_base(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; @@ -748,8 +754,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) { @@ -760,7 +767,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, @@ -768,15 +774,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_base(in, i, &eh_data); + packet_add(pkt, &eh_data); if (dhcp(c, pkt)) continue; } @@ -825,7 +833,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