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 93FE95A026F for ; Tue, 27 Feb 2024 15:27:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709044024; 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=PwhgGpQ/dfGrDhX5rGpuuu3O6fdxB9mCoSmBh1i1YOE=; b=NMVGMtnz1F1wYNR7qaaFiyEi9btgikTexfMVLcRgwATFoXo91iNqvzUpKzMkn1/B5VH4gH u67Tv1/bVHX6iA1bwzW3lLV8B4I5zZHHI28SZ6UqzF13SyoRsCmVoTzHAF7tRlixgRzcjb jOkH5aMamYm8aiI+jOQ6K0qgAT1BzzQ= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-fIoij_AlOjyk-U_ZDLcNxw-1; Tue, 27 Feb 2024 09:27:03 -0500 X-MC-Unique: fIoij_AlOjyk-U_ZDLcNxw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a3fcf5b93faso225642366b.2 for ; Tue, 27 Feb 2024 06:27:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709044022; x=1709648822; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PwhgGpQ/dfGrDhX5rGpuuu3O6fdxB9mCoSmBh1i1YOE=; b=FC0umnkhuFrCFm5DudmrfnuNIje3x6QNbD1+kWXsMduvmgieatHdoxpPHaA0qX3DgX lVkYWtoRoZ91HCQLnDZPMzdETcArzDjv1b9iPIod2nYFbuQ99/W3RbHk6t40HbsaFo29 ecPDIjBlt85shH+n4/8vSK8aW3kCxxygwVLinH42Cu3XhkPNB5285tr8l2xItTlBQleZ 1x8KefWs/OrRHcbuDiv8zAF5fz9voJUv6SfeedHmBfo9ikHdvDY8hCA+EMxTlsQazK7J 38b1Kfx42IiymOcw/Rz7M2aIMnD+OqMx5tgX0kKxEYqm7Z0rujk2eT4MTZn6HdJddHP4 RsPg== X-Gm-Message-State: AOJu0Ywf83qzbo0aSfTU/KFH9J9iLxCsMfNrkpZJPKpho9m6xOpgPgkq az77m2sA902WpQmu6NuFQ/EBh5RwnAGoE9Kbdskdals3M4xO7y3evKKPRGnWTUYkhOUqD45FZCU k9lUMQZ2rQinTl7crGrDLl5nyTGDvYKZsy/yeF3GPnMWh2WxzfA== X-Received: by 2002:a17:906:355b:b0:a3f:ce89:f913 with SMTP id s27-20020a170906355b00b00a3fce89f913mr6074499eja.42.1709044022041; Tue, 27 Feb 2024 06:27:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8uweRvItKa/yg6TeGwnbbwXZGs+DOTFa1+5e/nQK1lMgq0jRs0PfDCJrER07Eal5Y32u4QQ== X-Received: by 2002:a17:906:355b:b0:a3f:ce89:f913 with SMTP id s27-20020a170906355b00b00a3fce89f913mr6074488eja.42.1709044021676; Tue, 27 Feb 2024 06:27:01 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id s24-20020a170906bc5800b00a3efa4e033asm811601ejv.151.2024.02.27.06.27.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2024 06:27:00 -0800 (PST) Date: Tue, 27 Feb 2024 15:26:26 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 5/6] pcap: Allow pcap_frame() and pcap_multiple() to take multi-buffer frames Message-ID: <20240227152626.3e1f560d@elisabeth> In-Reply-To: <20240222055602.1872516-6-david@gibson.dropbear.id.au> References: <20240222055602.1872516-1-david@gibson.dropbear.id.au> <20240222055602.1872516-6-david@gibson.dropbear.id.au> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: JNOVPPGE6VAKLPLCVMKKNXWJJMACP2GV X-Message-ID-Hash: JNOVPPGE6VAKLPLCVMKKNXWJJMACP2GV X-MailFrom: sbrivio@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: passt-dev@passt.top, 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: On Thu, 22 Feb 2024 16:56:01 +1100 David Gibson wrote: > pcap_frame() explicitly takes a single frame, and only allows a single > buffer (iovec) to be passed. pcap_multiple() takes multiple buffers, but > explicitly expects exactly one frame per buffer. > > Future changes are going to want to split single frames across multiple > buffers in some circumstances, so extend the pcap functions to allow for > that. > > Signed-off-by: David Gibson > --- > pcap.c | 24 ++++++++++++++---------- > pcap.h | 3 ++- > tap.c | 2 +- > 3 files changed, 17 insertions(+), 12 deletions(-) > > diff --git a/pcap.c b/pcap.c > index eeb71a3c..9eb4f3d2 100644 > --- a/pcap.c > +++ b/pcap.c > @@ -31,6 +31,7 @@ > #include "util.h" > #include "passt.h" > #include "log.h" > +#include "pcap.h" > > #define PCAP_VERSION_MINOR 4 > > @@ -67,14 +68,15 @@ struct pcap_pkthdr { > > /** > * pcap_frame() - Capture a single frame to pcap file with given timestamp > - * @iov: iovec referencing buffer containing frame (with L2 headers) > - * @offset: Offset of the frame from @iov->iov_base > + * @iov: IO vector containing frame (with L2 headers and tap headers) > + * @iovcnt: Number of buffers (@iov entries) in frame > + * @offset: Byte offset of the L2 headers within @iov I swear I didn't read "Byte offset" from here before commenting on 1/6, which is rather promising. > * @tv: Timestamp > * > * Returns: 0 on success, -errno on error writing to the file > */ > -static void pcap_frame(const struct iovec *iov, size_t offset, > - const struct timeval *tv) > +static void pcap_frame(const struct iovec *iov, size_t iovcnt, > + size_t offset, const struct timeval *tv) > { > size_t len = iov->iov_len - offset; > struct pcap_pkthdr h = { > @@ -86,7 +88,7 @@ static void pcap_frame(const struct iovec *iov, size_t offset, > struct iovec hiov = { &h, sizeof(h) }; > > if (write_remainder(pcap_fd, &hiov, 1, 0) < 0 || > - write_remainder(pcap_fd, iov, 1, offset) < 0) > + write_remainder(pcap_fd, iov, iovcnt, offset) < 0) > debug("Cannot log packet, length %zu: %s", > len, strerror(errno)); > } > @@ -105,16 +107,18 @@ void pcap(const char *pkt, size_t len) > return; > > gettimeofday(&tv, NULL); > - pcap_frame(&iov, 0, &tv); > + pcap_frame(&iov, 1, 0, &tv); > } > > /** > * pcap_multiple() - Capture multiple frames > - * @iov: Array of iovecs, one entry per frame > + * @iov: Array of iovecs, every @framebufs entries is one frame > + * @framebufs: Number of buffers per frame I found this a bit hard to understand. What about: * @iov: Array of IO vectors, with item count @frame_parts * @n * @frame_parts: Number of IO vector items for each frame ? The rest of the series looks good to me. -- Stefano