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.133.124]) by passt.top (Postfix) with ESMTP id 33EBE5A0271 for ; Tue, 6 Feb 2024 17:11:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707235891; 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=eHyUj5U9Fg3r6QLm62RnbO5jKYmwHduSEtFUsB+kSDc=; b=SuBj/I0OtcLJjDmOyW3FlMISZzcqGMXQGyyxsNnor2Ujirmw8PPhJrOZvBN4BQVMae2odS +iHbAyl/ypFadv965gINTkF6xsGd+accUY6/fPkwB1hLznsSTHnb4Zfq0V8Jf4yuqwsw4l JkSYKiYMcNAh2PkOpp5OLqtmWWxMB6I= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-422-QGlFSVMyMt2taPBzxm3roQ-1; Tue, 06 Feb 2024 11:11:29 -0500 X-MC-Unique: QGlFSVMyMt2taPBzxm3roQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2f1d0c3389so349263766b.0 for ; Tue, 06 Feb 2024 08:11:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707235888; x=1707840688; 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=GDobaZKdQFX6Xk+NM2CxecBrqVKXw/MaXFXLGTAG+b0=; b=XnxMH3ubUZVEBRVZtcgcxst3O+/4yQBOfRcuCVRC5yx8/OEQ3n/ldC4WyfxQ8/7ura MQX4dYlZqJLc0A/rsT2ThYvtKcqhYzcRcH/fpOdigd/psWli8QoucDYjFachAp2GIq3E ACE7U8Mibe5kl9j869otHPPADM30Wo6DoOGcx50vXOMpIzWEek8nw/hNNaGJtIKMwtYh RE2giFgatvNqhhPYruNnQ1yzt1I5i18xfPbTh9u9XQSQg785Ajl+bTON4prKhmiGmLJt IPEY6TSv0J2sQNNy4HiQWlEPt/XRUK3/IDnjjBlv3PSgVgs/kud/j3X1FYGCFsOcn8Gx Mn8A== X-Gm-Message-State: AOJu0Yz1es3wygG9N7lTBRVkqxziG/Yjd7YZQDflo28Z0MXsHsAxpUjB 1USch3qYyWty3hDdtCTZsGNA4wP2wSlrg1gwrID4kxZPKENkpfec0CyLBlZlNbYLfzCdBHBuwCP hdpMTSyv26Zxs74CZ+iSU4Iwh1X6+zQjt/h8NURJaCjlMlCm3vKlRuCDZyQDgT23K0449iKir19 uxfBMN+n3mI8wKduKCG7M3+BWZC4/lWUXocIE= X-Received: by 2002:a17:906:57c6:b0:a34:ba53:f582 with SMTP id u6-20020a17090657c600b00a34ba53f582mr2366634ejr.20.1707235887815; Tue, 06 Feb 2024 08:11:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGXW4d/4I+NYvKzJbRoWp0mlCWhAUQ9JVg5kCnFEVPrr2IsUH+w0jhC10Kqmg5UixEeKDXPA== X-Received: by 2002:a17:906:57c6:b0:a34:ba53:f582 with SMTP id u6-20020a17090657c600b00a34ba53f582mr2366601ejr.20.1707235887062; Tue, 06 Feb 2024 08:11:27 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id tj10-20020a170907c24a00b00a354a5d2c39sm1304492ejc.31.2024.02.06.08.11.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Feb 2024 08:11:26 -0800 (PST) Date: Tue, 6 Feb 2024 17:10:51 +0100 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH 02/24] pcap: add pcap_iov() Message-ID: <20240206171051.7493e450@elisabeth> In-Reply-To: <20240202141151.3762941-3-lvivier@redhat.com> References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-3-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.1.1 (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: quoted-printable Message-ID-Hash: ARJQ6TQU4GLLC5BHFC6WEDS7MLAF5JML X-Message-ID-Hash: ARJQ6TQU4GLLC5BHFC6WEDS7MLAF5JML 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 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 Fri, 2 Feb 2024 15:11:29 +0100 Laurent Vivier wrote: > Signed-off-by: Laurent Vivier > --- > pcap.c | 32 ++++++++++++++++++++++++++++++++ > pcap.h | 1 + > 2 files changed, 33 insertions(+) >=20 > 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" > =20 > #define PCAP_VERSION_MINOR 4 > =20 > @@ -130,6 +131,37 @@ void pcap_multiple(const struct iovec *iov, unsigned= int n, size_t offset) > =09} > } > =20 > +void pcap_iov(const struct iovec *iov, unsigned int n) > +{ > +=09struct timeval tv; > +=09struct pcap_pkthdr h; > +=09size_t len; > +=09unsigned int i; >From longest to shortest, rationale: https://hisham.hm/2018/06/16/when-listing-repeated-things-make-pyramids/ > + > +=09if (pcap_fd =3D=3D -1) > +=09=09return; > + > +=09gettimeofday(&tv, NULL); > + > +=09len =3D iov_size(iov, n); > + > +=09h.tv_sec =3D tv.tv_sec; > +=09h.tv_usec =3D tv.tv_usec; > +=09h.caplen =3D h.len =3D len; > + > +=09if (write(pcap_fd, &h, sizeof(h)) < 0) { > +=09=09debug("Cannot write pcap header"); > +=09=09return; > +=09} > + > +=09for (i =3D 0; i < n; i++) { > +=09=09if (write(pcap_fd, iov[i].iov_base, iov[i].iov_len) < 0) { > +=09=09=09debug("Cannot log packet, iov %d length %lu\n", %zu instead of %lu -- that guarantees the correct width for size_t on different architectures (it's not always 'long'). And "iov %d" followed by the length doesn't really tell that we're printing the index of the vector, maybe something on the lines of: =09=09=09debug("Cannot log packet, length %zu, iovec index %i\n", ? > +=09=09=09 i, iov[i].iov_len); > +=09=09} > +=09} > +} > + > /** > * pcap_init() - Initialise pcap file > * @c:=09=09Execution context > diff --git a/pcap.h b/pcap.h > index da5a7e846b72..732a0ddf14cc 100644 > --- a/pcap.h > +++ b/pcap.h > @@ -8,6 +8,7 @@ > =20 > void pcap(const char *pkt, size_t len); > void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offse= t); > +void pcap_iov(const struct iovec *iov, unsigned int n); > void pcap_init(struct ctx *c); > =20 > #endif /* PCAP_H */ --=20 Stefano