From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 4D1A65A0271 for ; Fri, 2 Feb 2024 15:11:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706883114; 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=aQ7hujSgsbqOOX/I4oolVHtmuPe1G1QrCuvBXLPtDZs=; b=LBfjWvJmC6K44Oqer6bNMqGVIeNJ6xN8tXfnENaQSWTt/O5uzBr9iM+nfve2NschJnHuAi 1SZ9MaToIBwBxZHYoqjpOPIW5JwaOqOeRlhxE8wYGUCJ6cz9huBmkDs65eYezlOIEEiOm0 qWiBmmHaIVoC3s5GkiEAcztgmwcu9Wk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-MM45XvEbNrWCButkXrYvBA-1; Fri, 02 Feb 2024 09:11:53 -0500 X-MC-Unique: MM45XvEbNrWCButkXrYvBA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id CDC0238562D9 for ; Fri, 2 Feb 2024 14:11:52 +0000 (UTC) Received: from virtlab218.virt.lab.eng.bos.redhat.com (virtlab218.virt.lab.eng.bos.redhat.com [10.19.152.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id B648A40C95AD; Fri, 2 Feb 2024 14:11:52 +0000 (UTC) From: Laurent Vivier To: passt-dev@passt.top Subject: [PATCH 02/24] pcap: add pcap_iov() Date: Fri, 2 Feb 2024 15:11:29 +0100 Message-ID: <20240202141151.3762941-3-lvivier@redhat.com> In-Reply-To: <20240202141151.3762941-1-lvivier@redhat.com> References: <20240202141151.3762941-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: LFAVRJHOLKOXCFD3Q6Y3W2RV3D6IHLWO X-Message-ID-Hash: LFAVRJHOLKOXCFD3Q6Y3W2RV3D6IHLWO 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: Signed-off-by: Laurent Vivier --- pcap.c | 32 ++++++++++++++++++++++++++++++++ pcap.h | 1 + 2 files changed, 33 insertions(+) diff --git a/pcap.c b/pcap.c index 501d52d4992b..b002bb01314c 100644 --- a/pcap.c +++ b/pcap.c @@ -31,6 +31,7 @@ #include "util.h" #include "passt.h" #include "log.h" +#include "iov.h" #define PCAP_VERSION_MINOR 4 @@ -130,6 +131,37 @@ void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset) } } +void pcap_iov(const struct iovec *iov, unsigned int n) +{ + struct timeval tv; + struct pcap_pkthdr h; + size_t len; + unsigned int i; + + if (pcap_fd == -1) + return; + + gettimeofday(&tv, NULL); + + len = iov_size(iov, n); + + h.tv_sec = tv.tv_sec; + h.tv_usec = tv.tv_usec; + h.caplen = h.len = len; + + if (write(pcap_fd, &h, sizeof(h)) < 0) { + debug("Cannot write pcap header"); + return; + } + + for (i = 0; i < n; i++) { + if (write(pcap_fd, iov[i].iov_base, iov[i].iov_len) < 0) { + debug("Cannot log packet, iov %d length %lu\n", + i, iov[i].iov_len); + } + } +} + /** * pcap_init() - Initialise pcap file * @c: Execution context diff --git a/pcap.h b/pcap.h index da5a7e846b72..732a0ddf14cc 100644 --- a/pcap.h +++ b/pcap.h @@ -8,6 +8,7 @@ void pcap(const char *pkt, size_t len); void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset); +void pcap_iov(const struct iovec *iov, unsigned int n); void pcap_init(struct ctx *c); #endif /* PCAP_H */ -- 2.42.0