* [PATCH 0/2] pcpang changes
@ 2025-11-05 21:03 Stephen Hemminger
2025-11-05 21:03 ` [PATCH 1/2] pcapng: use alloca instead of fixed buffer Stephen Hemminger
2025-11-05 21:03 ` [PATCH 2/2] test: add more tests for comments Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Stephen Hemminger @ 2025-11-05 21:03 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
Fix compilation with Gcc 16 by using alloca, and add additional tests
Stephen Hemminger (2):
pcapng: use alloca instead of fixed buffer
test: add more tests for comments
app/test/test_pcapng.c | 18 ++++++++++++++++--
lib/pcapng/rte_pcapng.c | 19 ++++++++++---------
2 files changed, 26 insertions(+), 11 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] pcapng: use alloca instead of fixed buffer
2025-11-05 21:03 [PATCH 0/2] pcpang changes Stephen Hemminger
@ 2025-11-05 21:03 ` Stephen Hemminger
2025-11-05 21:03 ` [PATCH 2/2] test: add more tests for comments Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2025-11-05 21:03 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
This is an API that accepts strings as options, and user could
potentially ask for very large string as comment.
The dynamic way to fix is to use alloca() to allocate the buffer
used to hold options.
Bugzilla ID: 1820
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/pcapng/rte_pcapng.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 21bc94cea1..3067033e89 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -34,9 +34,6 @@
/* conversion from DPDK speed to PCAPNG */
#define PCAPNG_MBPS_SPEED 1000000ull
-/* upper bound for section, stats and interface blocks (in uint32_t) */
-#define PCAPNG_BLKSIZ (2048 / sizeof(uint32_t))
-
/* Format of the capture file handle */
struct rte_pcapng {
int outfd; /* output file */
@@ -145,7 +142,7 @@ pcapng_section_block(rte_pcapng_t *self,
{
struct pcapng_section_header *hdr;
struct pcapng_option *opt;
- uint32_t buf[PCAPNG_BLKSIZ];
+ uint32_t *buf;
uint32_t len;
len = sizeof(*hdr);
@@ -162,7 +159,8 @@ pcapng_section_block(rte_pcapng_t *self,
len += pcapng_optlen(0);
len += sizeof(uint32_t);
- if (len > sizeof(buf))
+ buf = alloca(len);
+ if (buf == NULL)
return -1;
hdr = (struct pcapng_section_header *)buf;
@@ -214,7 +212,7 @@ rte_pcapng_add_interface(rte_pcapng_t *self, uint16_t port, uint16_t link_type,
struct pcapng_option *opt;
const uint8_t tsresol = 9; /* nanosecond resolution */
uint32_t len;
- uint32_t buf[PCAPNG_BLKSIZ];
+ uint32_t *buf;
char ifname_buf[IF_NAMESIZE];
char ifhw[256];
uint64_t speed = 0;
@@ -268,7 +266,8 @@ rte_pcapng_add_interface(rte_pcapng_t *self, uint16_t port, uint16_t link_type,
len += pcapng_optlen(0);
len += sizeof(uint32_t);
- if (len > sizeof(buf))
+ buf = alloca(len);
+ if (buf == NULL)
return -1;
hdr = (struct pcapng_interface_block *)buf;
@@ -333,7 +332,7 @@ rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,
uint64_t start_time = self->offset_ns;
uint64_t sample_time;
uint32_t optlen, len;
- uint32_t buf[PCAPNG_BLKSIZ];
+ uint32_t *buf;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
@@ -353,7 +352,9 @@ rte_pcapng_write_stats(rte_pcapng_t *self, uint16_t port_id,
optlen += pcapng_optlen(0);
len = sizeof(*hdr) + optlen + sizeof(uint32_t);
- if (len > sizeof(buf))
+
+ buf = alloca(len);
+ if (buf == NULL)
return -1;
hdr = (struct pcapng_statistics *)buf;
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] test: add more tests for comments
2025-11-05 21:03 [PATCH 0/2] pcpang changes Stephen Hemminger
2025-11-05 21:03 ` [PATCH 1/2] pcapng: use alloca instead of fixed buffer Stephen Hemminger
@ 2025-11-05 21:03 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2025-11-05 21:03 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
Add some more cases where comment is set in pcapng file.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
app/test/test_pcapng.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c
index bcf99724fa..7e50457794 100644
--- a/app/test/test_pcapng.c
+++ b/app/test/test_pcapng.c
@@ -162,13 +162,20 @@ fill_pcapng_file(rte_pcapng_t *pcapng, unsigned int num_packets)
burst_size = rte_rand_max(MAX_BURST) + 1;
for (i = 0; i < burst_size; i++) {
struct rte_mbuf *mc;
+ char *comment = NULL;
+
+ /* Put comment on one out of hundred packets */
+ if ((count + i % 100) == 0)
+ asprintf(&comment, "Function: %s\nPacket %u\n",
+ __func__, count + i);
mc = rte_pcapng_copy(port_id, 0, orig, mp, rte_pktmbuf_pkt_len(orig),
- RTE_PCAPNG_DIRECTION_IN, NULL);
+ RTE_PCAPNG_DIRECTION_IN, comment);
if (mc == NULL) {
fprintf(stderr, "Cannot copy packet\n");
return -1;
}
+ free(comment);
clones[i] = mc;
}
@@ -386,7 +393,7 @@ static int
test_write_packets(void)
{
char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng";
- static rte_pcapng_t *pcapng;
+ rte_pcapng_t *pcapng = NULL;
int ret, tmp_fd, count;
uint64_t now = current_timestamp();
@@ -413,6 +420,13 @@ test_write_packets(void)
goto fail;
}
+ /* write a statistics block */
+ ret = rte_pcapng_write_stats(pcapng, port_id, 0, 0, NULL);
+ if (ret <= 0) {
+ fprintf(stderr, "Write of statistics failed\n");
+ goto fail;
+ }
+
count = fill_pcapng_file(pcapng, TOTAL_PACKETS);
if (count < 0)
goto fail;
--
2.51.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-05 21:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-05 21:03 [PATCH 0/2] pcpang changes Stephen Hemminger
2025-11-05 21:03 ` [PATCH 1/2] pcapng: use alloca instead of fixed buffer Stephen Hemminger
2025-11-05 21:03 ` [PATCH 2/2] test: add more tests for comments Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).