pcapng: call writev as needed on highly segmented mbuf
PATCH 1/4 pcapng: call writev as needed on highly segmented mbuf
It is possible to have an mbuf with more segments than the max number of io vectors (1024 on Linux). This is an odd corner case but it is allowed by DPDK since maximum number of segments per mbuf is UINT16_MAX.
The old check assumed a single mbuf chain always fit in the io vector, so a chain longer than IOV_MAX overran the stack array. Consolidate the checks so now when io vector gets full it is written. A packet may now be split across writev calls; the previous flush at packet boundaries was incidental and not a documented guarantee.
Bugzilla ID: 2133
Fixes 0744f1c9f991 ("pcapng: fix write more packets than IOV_MAX limit")
Reported-by Anthropic OSS scanner (ANT-2026-DC6DT4HP)
Signed-off-by Stephen Hemminger <[email protected]>
--- lib/pcapng/rte_pcapng.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
lib/pcapng/rte_pcapng.c +19 -20
@@ -706,20 +706,6 @@ rte_pcapng_write_packets(rte_pcapng_t *self, epb->timestamp_hi = timestamp >>32 ; epb->timestamp_lo = (uint32_t )timestamp; -/* -* Handle case of highly fragmented and large burst size -* Note: this assumes that max segments per mbuf < IOV_MAX -*/ -if (unlikely (cnt + m->nb_segs >=IOV_MAX )) { - ret =writev (self->outfd, iov, cnt); -if (unlikely (ret <0 )) { - rte_errno = errno; -return -1 ; - } - total += ret; - cnt =0 ; - } -/* * The DPDK port is recorded during pcapng_copy. * Map that to PCAPNG interface in file.
@@ -727,16 +713,29 @@ rte_pcapng_write_packets(rte_pcapng_t *self,do { iov[cnt].iov_base = rte_pktmbuf_mtod(m, void *); iov[cnt].iov_len =rte_pktmbuf_data_len (m); - ++cnt; + +/* If current iov is maxed out then send it */ +if (++cnt ==IOV_MAX ) { + ret =writev (self->outfd, iov, cnt); +if (unlikely (ret <0 )) { + rte_errno = errno; +return -1 ; + } + cnt =0 ; + total += ret; + } }while ((m = m->next)); } - ret =writev (self->outfd, iov, cnt); -if (unlikely (ret <0 )) { - rte_errno = errno; -return -1 ; +if (likely (cnt >0 )) { + ret =writev (self->outfd, iov, cnt); +if (unlikely (ret <0 )) { + rte_errno = errno; +return -1 ; + } + total += ret; } -return total + ret; +return total; }/* Create new pcapng writer handle */
Signature · 1 line
2.53.0