examples/rpcapd: demo version of packet capture daemon
PATCH 1/1 examples/rpcapd: demo version of packet capture daemon
This example adds RPCAP support over localhost TCP integrated with DPDK. It uses a secondary process that allows connections from using tcpdump defacto protocol rpcap.
See: doc/guides/sample_app_ug/rpcap.rst for more info. This does not preclude using pdump, dumpcap, or the wireshark extcap integration.
---
doc/guides/rel_notes/release_26_11.rst | 4 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/rpcapd.rst | 206 +++++ examples/meson.build | 1 + examples/rpcapd/main.c | 1014 ++++++++++++++++++++++++ examples/rpcapd/meson.build | 11 + examples/rpcapd/rpcap-protocol.h | 96 +++ 7 files changed, 1333 insertions(+) create mode 100644 doc/guides/sample_app_ug/rpcapd.rst create mode 100644 examples/rpcapd/main.c create mode 100644 examples/rpcapd/meson.build create mode 100644 examples/rpcapd/rpcap-protocol.h
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added an example of tcpdump remote pcap daemon.** + + Added an example that implements rpcap to allow live capture in tcpdump. + Removed Items -------------
doc/guides/sample_app_ug/index.rst +1 -0
@@ -31,6 +31,7 @@ Sample Applications User Guides l3_forward_graph l3_forward_power_man link_status_intr + rpcapd server_node_efd service_cores multi_process
doc/guides/sample_app_ug/rpcapd.rst new file +206 -0
206 lines not on this page · raw message
examples/meson.build +1 -0
@@ -45,6 +45,7 @@ all_examples = [ 'ptpclient', 'qos_meter', 'qos_sched', + 'rpcapd', 'rxtx_callbacks', 'server_node_efd/efd_node', 'server_node_efd/efd_server',
examples/rpcapd/main.c new file +1014 -0
1,014 lines not on this page · raw message
examples/rpcapd/meson.build new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 + +if is_windows + build = false + reason = 'not supported on Windows' + subdir_done() +endif + +sources = files('main.c') +deps += ['ethdev', 'pdump']
examples/rpcapd/rpcap-protocol.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v2 1/1 examples/rpcapd: demo version of packet capture daemon
This example adds RPCAP support over localhost TCP integrated with DPDK. It uses a secondary process that allows connections from using tcpdump defacto protocol rpcap.
See: doc/guides/sample_app_ug/rpcapd.rst for more info
---
v2 - Build on Linux only
- add filter support
- fix lots of AI review feedback
MAINTAINERS | 2 + doc/guides/rel_notes/release_26_11.rst | 4 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/rpcapd.rst | 216 ++++ examples/meson.build | 1 + examples/rpcapd/main.c | 1430 ++++++++++++++++++++++++ examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++ 8 files changed, 1800 insertions(+) create mode 100644 doc/guides/sample_app_ug/rpcapd.rst create mode 100644 examples/rpcapd/main.c create mode 100644 examples/rpcapd/meson.build create mode 100644 examples/rpcapd/rpcap-protocol.h
MAINTAINERS +2 -0
@@ -1724,6 +1724,8 @@ F: app/pdump/ F: doc/guides/tools/pdump.rst F: app/dumpcap/ F: doc/guides/tools/dumpcap.rst +F: examples/rpcapd/ +F: doc/guides/sample_app_ug/rpcapd.rst Packet Framework
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added an example of tcpdump remote pcap daemon.** + + Added an example that implements rpcap to allow live capture in tcpdump. + Removed Items -------------
doc/guides/sample_app_ug/index.rst +1 -0
@@ -31,6 +31,7 @@ Sample Applications User Guides l3_forward_graph l3_forward_power_man link_status_intr + rpcapd server_node_efd service_cores multi_process
doc/guides/sample_app_ug/rpcapd.rst new file +216 -0
216 lines not on this page · raw message
examples/meson.build +1 -0
@@ -45,6 +45,7 @@ all_examples = [ 'ptpclient', 'qos_meter', 'qos_sched', + 'rpcapd', 'rxtx_callbacks', 'server_node_efd/efd_node', 'server_node_efd/efd_server',
examples/rpcapd/main.c new file +1430 -0
1,430 lines not on this page · raw message
examples/rpcapd/meson.build new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Stephen Hemminger + +# since it relies on primary/secondary process +# this example is Linux only +if not is_linux + build = false + subdir_done() +endif + +if not dpdk_conf.has('RTE_HAS_LIBPCAP') + build = false + reason = 'missing dependency, "libpcap"' + subdir_done() +endif + +sources = files('main.c') +ext_deps += pcap_dep +deps += ['ethdev', 'pdump', 'bpf']
examples/rpcapd/rpcap-protocol.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.53.0
Very cool example, demonstrating many advanced DPDK features at once. In this regard, it really excels.
It could be however useful as a debug tool, and in this case having to deal with a secondary process is a hassle. Could we have this feature in dpdk-testpmd, instead or as well?
Otherwise, having seen the demonstration, I do not have many comments, except for a couple nits below.
Quoted 12 lines · Stephen Hemminger
This example adds RPCAP support over localhost TCP integrated with DPDK. It uses a secondary process that allows connections from using tcpdump defacto protocol rpcap.
See:
doc/guides/sample_app_ug/rpcapd.rstfor more infoSigned-off-by Stephen Hemminger <[email protected]>---
v2 - Build on Linux only
- add filter support
- fix lots of AI review feedback
Quoted 6 lines
MAINTAINERS | 2 + doc/guides/rel_notes/release_26_11.rst | 4 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/rpcapd.rst | 216 ++++ examples/meson.build | 1 + examples/rpcapd/main.c | 1430 ++++++++++++++++++++++++
main.c is a bit large and handles many different functions. It would be more readable if different aspects were handled by different files, or at least clearly marked sections of the file, with overall structure explained somewhere at the top.
Quoted 2 lines
examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++
Could we just use one from libpcap?
Quoted 6 lines · On Mon, 21 Sep 2026 10:51:39 +0100 Marat Khalili <[email protected]> wrote:
Very cool example, demonstrating many advanced DPDK features at once. In this regard, it really excels.
It could be however useful as a debug tool, and in this case having to deal with a secondary process is a hassle. Could we have this feature in dpdk-testpmd, instead or as well?
No. There is dpdk-extcap which is better tool.
Testpmd doesn't need more bloat and opening a socket in testpmd would also expose more attack surface
Quoted 3 lines
Otherwise, having seen the demonstration, I do not have many comments, except for a couple nits below.
Quoted 3 lines · On Mon, 21 Sep 2026 10:51:39 +0100 Marat Khalili <[email protected]> wrote:
Quoted 2 lines
examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++Could we just use one from libpcap?
Could but since most distro's don't enable rpcapd the header file is not exported. We could "vendor it".
Quoted 8 lines · Stephen Hemminger
Quoted 3 lines · On Mon, 21 Sep 2026 10:51:39 +0100 Marat Khalili <[email protected]> wrote:
Quoted 2 lines
examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++Could we just use one from libpcap?
Could but since most distro's don't enable rpcapd the header file is not exported. We could "vendor it".
Is it possible to use your new app without having a full version of libpcap in the system (that would have this rpcap-protocol.h anyway)? In "Client Setup" you mention that libpcap must be rebuilt with remote support enabled, and at this moment our own abridged copy of rpcap-protocol.h becomes redundant. Our copy allows building the application in systems where rpcapd is missing or built without the remote support, but then the build result cannot be used. Am I misunderstanding something?
Quoted 9 lines · On Mon, 21 Sep 2026 17:43:31 +0100 Marat Khalili <[email protected]> wrote:
Quoted 8 lines · Stephen Hemminger
Quoted 3 lines · On Mon, 21 Sep 2026 10:51:39 +0100 Marat Khalili <[email protected]> wrote:
Quoted 2 lines
examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++Could we just use one from libpcap?
Could but since most distro's don't enable rpcapd the header file is not exported. We could "vendor it".
Quoted 8 lines
Is it possible to use your new app without having a full version of libpcap in the system (that would have this
rpcap-protocol.hanyway)? In "Client Setup" you mention that libpcap must be rebuilt with remote support enabled, and at this moment our own abridged copy ofrpcap-protocol.hbecomes redundant. Our copy allows building the application in systems where rpcapd is missing or built without the remote support, but then the build result cannot be used. Am I misunderstanding something?
Read the docs, there are two issues:
1. You need to rebuild libpcap since rpcap is a security problem, it is not enabled by default. Tcpdump et al will not support rpcap without rebuild.
2. The rpcap-protocol.h file is not exported by libpcap and considered internal. The original is too damn messy to use in DPDK as a copy.
Quoted 3 lines
2. The
rpcap-protocol.hfile is not exported by libpcap and considered internal. The original is too damn messy to use in DPDK as a copy.
Ok, I missed that part, Strange that they don't have a public header with protocol constants, but I guess there is little we can do, we have to have our own version. Maybe worth explaining it in the file header.
Quoted 6 lines · On Mon, 21 Sep 2026 10:51:39 +0100 Marat Khalili <[email protected]> wrote:
Quoted 1 line
examples/rpcapd/main.c | 1430 ++++++++++++++++++++++++
main.cis a bit large and handles many different functions. It would be more readable if different aspects were handled by different files, or at least clearly marked sections of the file, with overall structure explained somewhere at the top.
It is mostly comments.
Fits within the general sizes of examples.
source blank comments comment-lines
2569 499 13 17 examples/fips_validation/main.c
2302 411 272 151 examples/l3fwd-power/main.c
2208 452 226 173 examples/l2fwd-crypto/main.c
1542 343 200 102 examples/vhost/main.c
1489 226 104 77 examples/l3fwd/main.c
1254 216 101 99 examples/l2fwd-macsec/main.c
1116 224 99 85 examples/l3fwd-graph/main.c
1045 190 195 72 examples/rpcapd/main.c
944 181 69 60 examples/bbdev_app/main.cQuoted 3 lines
Quoted 2 lines
examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++Could we just use one from libpcap?
The long answer:
- the file is internal to libpcap and not shipped.
- Would have to add SPDX
- It isn't just wire format but includes function prototypes for code in libpcap's implementation
- It is ugly style overall: lots of typedefs, windows-ism's, #pragma
What AI did was extract the parts that were used.
Quoted 8 lines · On Sun, 20 Sep 2026 11:59:09 -0700 Stephen Hemminger…
This example adds RPCAP support over localhost TCP integrated with DPDK. It uses a secondary process that allows connections from using tcpdump defacto protocol rpcap.
See:
doc/guides/sample_app_ug/rpcapd.rstfor more infoSigned-off-by Stephen Hemminger <[email protected]>---
Recheck-request: rebase=main, iol-unit-arm64-testing
PATCH v3 1/1 examples/rpcapd: demo version of packet capture daemon
In reply to Stephen HemmingerThis example adds RPCAP support over localhost TCP integrated with DPDK. It uses a secondary process that allows connections from using tcpdump defacto protocol rpcap.
See: doc/guides/sample_app_ug/rpcapd.rst for more info
---
v3 - rebase to force retest
MAINTAINERS | 2 + doc/guides/rel_notes/release_26_11.rst | 4 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/rpcapd.rst | 216 ++++ examples/meson.build | 1 + examples/rpcapd/main.c | 1430 ++++++++++++++++++++++++ examples/rpcapd/meson.build | 19 + examples/rpcapd/rpcap-protocol.h | 127 +++ 8 files changed, 1800 insertions(+) create mode 100644 doc/guides/sample_app_ug/rpcapd.rst create mode 100644 examples/rpcapd/main.c create mode 100644 examples/rpcapd/meson.build create mode 100644 examples/rpcapd/rpcap-protocol.h
MAINTAINERS +2 -0
@@ -1724,6 +1724,8 @@ F: app/pdump/ F: doc/guides/tools/pdump.rst F: app/dumpcap/ F: doc/guides/tools/dumpcap.rst +F: examples/rpcapd/ +F: doc/guides/sample_app_ug/rpcapd.rst Packet Framework
doc/guides/rel_notes/release_26_11.rst +4 -0
@@ -65,6 +65,10 @@ New Features * Added VF support on AMD Solarflare X45xx adapters. +* **Added an example of tcpdump remote pcap daemon.** + + Added an example that implements rpcap to allow live capture in tcpdump. + Removed Items -------------
doc/guides/sample_app_ug/index.rst +1 -0
@@ -31,6 +31,7 @@ Sample Applications User Guides l3_forward_graph l3_forward_power_man link_status_intr + rpcapd server_node_efd service_cores multi_process
doc/guides/sample_app_ug/rpcapd.rst new file +216 -0
216 lines not on this page · raw message
examples/meson.build +1 -0
@@ -45,6 +45,7 @@ all_examples = [ 'ptpclient', 'qos_meter', 'qos_sched', + 'rpcapd', 'rxtx_callbacks', 'server_node_efd/efd_node', 'server_node_efd/efd_server',
examples/rpcapd/main.c new file +1430 -0
1,430 lines not on this page · raw message
examples/rpcapd/meson.build new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Stephen Hemminger + +# since it relies on primary/secondary process +# this example is Linux only +if not is_linux + build = false + subdir_done() +endif + +if not dpdk_conf.has('RTE_HAS_LIBPCAP') + build = false + reason = 'missing dependency, "libpcap"' + subdir_done() +endif + +sources = files('main.c') +ext_deps += pcap_dep +deps += ['ethdev', 'pdump', 'bpf']
examples/rpcapd/rpcap-protocol.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.53.0
Summarizing the exchange to v2, our own copy of rpcap-protocol.h is unavoidable here since one included in libpcap is an internal header that is not installed by design (irrespective of package maintainers). I am ready to ack the patch after this is clarified in the code to prevent other people from being similarly confused since situation with the dependencies here is quite complex.
My request to better mark sections of main.c responsible for different concerns still stands, but is not a show stopper. Same for my request to make it a part of dpdk-testpmd instead of a secondary process. Anyone interested can probably do either or both locally in half an hour in a code agent anyway.
Quoted 7 lines · On Mon, 28 Sep 2026 17:18:40 +0100 Marat Khalili <[email protected]> wrote:
Summarizing the exchange to v2, our own copy of rpcap-protocol.h is unavoidable here since one included in libpcap is an internal header that is not installed by design (irrespective of package maintainers). I am ready to ack the patch after this is clarified in the code to prevent other people from being similarly confused since situation with the dependencies here is quite complex.
Quoted 6 lines
My request to better mark sections of
main.cresponsible for different concerns still stands, but is not a show stopper. Same for my request to make it a part of dpdk-testpmd instead of a secondary process. Anyone interested can probably do either or both locally in half an hour in a code agent anyway.
I have a new version which has more features and splits up the code.
v4 cover add rpcap remote capture daemon
In reply to Stephen HemmingerThis series adds support for live capture using tcpdump and related tools that use libpcap. See document doc/guides/tools/rpcapd.rst for the details.
The dpdkr rpcap daemon runs as a secondary process similar to dpdk-pdump and dpdk-dumpcap. The difference is instead of writing packets directly to a file, it provides a standard API for transferring packet capture over a socket. The command line arguments
are chosen to match the existing libpcap rpcapd, but not
all command flags are implemented.
The capture is only possible if the rpcap daemon is running. And since it is a secondary process, it needs to be started after the DPDK primary process. The daemon will also exit when the primary process exits.
Since it is intended for debugging (and due to limitations in the pdump API), only a single client can access rpcap at a time.
The dpdk-rpcapd uses existing pdump infrastructure to capture and filter packets. One small additional API was needed to extract the timestamp and original capture length from the mbuf that was processed with pcapng mode. Since rpcap protocol is limited to pcap legacy format, only microsecond timestamps (and no metadata info) are visible in the stream.
By default dpdk-rpcapd can only be used over local TCP sockets. This version also adds TLS and password authentication which could be useful if dpdk-rpcapd is setup to allow non-local access. An additional security feature was added based on what libpcap rpcapd has, with the -l flag a list of allowed hosts can be used.
Changes since previous version:
- Moved from examples/ to app/
- Added TLS and password authentication (patch 3).
- Added the -l host list option (patch 4).
Stephen Hemminger (4):
pcapng: add API to read back capture mbuf header app/rpcapd: remote pcap daemon app/rpcapd: add TLS support
app/rpcapd: add host list option
MAINTAINERS | 2 + app/meson.build | 1 + app/rpcapd/capture.c | 541 ++++++++++++++++ app/rpcapd/filter.c | 164 +++++ app/rpcapd/main.c | 840 +++++++++++++++++++++++++ app/rpcapd/meson.build | 40 ++ app/rpcapd/rpcap-protocol.h | 146 +++++ app/rpcapd/rpcapd.h | 122 ++++ app/rpcapd/session.c | 292 +++++++++ app/rpcapd/sock.c | 365 +++++++++++ app/rpcapd/tls.c | 273 ++++++++ app/test/test_pcapng.c | 133 ++++ doc/guides/rel_notes/release_26_11.rst | 13 + doc/guides/tools/index.rst | 1 + doc/guides/tools/rpcapd.rst | 288 +++++++++ lib/pcapng/rte_pcapng.c | 40 ++ lib/pcapng/rte_pcapng.h | 46 ++ 17 files changed, 3307 insertions(+) create mode 100644 app/rpcapd/capture.c create mode 100644 app/rpcapd/filter.c create mode 100644 app/rpcapd/main.c create mode 100644 app/rpcapd/meson.build create mode 100644 app/rpcapd/rpcap-protocol.h create mode 100644 app/rpcapd/rpcapd.h create mode 100644 app/rpcapd/session.c create mode 100644 app/rpcapd/sock.c create mode 100644 app/rpcapd/tls.c create mode 100644 doc/guides/tools/rpcapd.rst
Signature · 1 line
2.53.0
PATCH v4 1/4 pcapng: add API to read back capture mbuf header
An mbuf from rte_pcapng_copy() starts with an enhanced packet block holding the capture time, the length before truncation and the port. The only way to get at that was to write the mbuf to a file, which is no use to something forwarding captured packets elsewhere.
Add rte_pcapng_pkt_info() to decode that header in place, and check it is well formed before trusting the lengths in it.
The capture time is reported as the raw TSC value: there is no capture file here to take a reference point from, so converting it to a time of day is left to the caller.
--- app/test/test_pcapng.c | 133 +++++++++++++++++++++++++ doc/guides/rel_notes/release_26_11.rst | 5 + lib/pcapng/rte_pcapng.c | 40 ++++++++ lib/pcapng/rte_pcapng.h | 46 +++++++++ 4 files changed, 224 insertions(+)
app/test/test_pcapng.c +133 -0
@@ -672,6 +672,138 @@ test_write_before_open(void)return -1 ; } +/* +* Check that rte_pcapng_pkt_info() reads back what rte_pcapng_copy() +* recorded. The length before truncation and the capture time are +* only in the block header, so this is the only way a consumer that +* does not write a file can get at them. +*/ +static int +test_pkt_info (void ) +{ +struct dummy_mbuf mbfs; +struct rte_mbuf *mc; +struct rte_pcapng_pkt pkt; +uint32_t pkt_len, snaplen, saved; +uint64_t before, after; +const uint8_t *data; +int ret; + +mbuf1_prepare (&mbfs); +mbuf1_resize (&mbfs,512 ); + pkt_len =rte_pktmbuf_pkt_len (&mbfs.mb[0 ]); + +/* An untruncated copy reports the length it came in with. */ + before =rte_get_tsc_cycles (); + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, pkt_len, +RTE_PCAPNG_DIRECTION_IN ,NULL ); +TEST_ASSERT (mc !=NULL ,"rte_pcapng_copy failed" ); + after =rte_get_tsc_cycles (); + + ret =rte_pcapng_pkt_info (mc, &pkt); +TEST_ASSERT (ret ==0 ,"rte_pcapng_pkt_info failed: %d" , ret); + +TEST_ASSERT (pkt.original_len == pkt_len, +"original_len is %u, expected %u" , pkt.original_len, pkt_len); +TEST_ASSERT (pkt.captured_len == pkt_len, +"captured_len is %u, expected %u" , pkt.captured_len, pkt_len); +TEST_ASSERT (pkt.port == port_id, +"port is %u, expected %u" , pkt.port, port_id); + +/* The copy was made between the two readings, so the recorded +* cycle count has to fall between them. +*/ +TEST_ASSERT (pkt.cycles >= before && pkt.cycles <= after, +"cycles %" PRIu64" is outside [%" PRIu64", %" PRIu64"]" , + pkt.cycles, before, after); + +/* data_offset points at the packet itself, not the block header. */ + data = rte_pktmbuf_mtod_offset(mc, const uint8_t *, pkt.data_offset); + TEST_ASSERT(memcmp(data, rte_pktmbuf_mtod(&mbfs.mb[0], const void *), +rte_pktmbuf_data_len (&mbfs.mb[0 ])) ==0 , +"packet data is not at data_offset" ); + +/* A corrupt block is rejected rather than believed. */ + { +struct pcapng_test_epb { +uint32_t block_type; +uint32_t block_length; + } *epb = rte_pktmbuf_mtod(mc, struct pcapng_test_epb *); + + saved = epb->block_type; + epb->block_type = ~saved; +TEST_ASSERT (rte_pcapng_pkt_info (mc, &pkt) == -EINVAL , +"bad block_type was accepted" ); + epb->block_type = saved; + + saved = epb->block_length; + epb->block_length = saved +1 ; +TEST_ASSERT (rte_pcapng_pkt_info (mc, &pkt) == -EINVAL , +"bad block_length was accepted" ); + epb->block_length = saved; + +/* and is fine again once put back */ +TEST_ASSERT (rte_pcapng_pkt_info (mc, &pkt) ==0 , +"restored block was rejected" ); + } + +TEST_ASSERT (rte_pcapng_pkt_info (NULL , &pkt) == -EINVAL , +"NULL mbuf was accepted" ); +TEST_ASSERT (rte_pcapng_pkt_info (mc,NULL ) == -EINVAL , +"NULL result was accepted" ); + +rte_pktmbuf_free (mc); + +/* +* Truncated copy. This is the case that cannot be recovered +* from the mbuf alone: captured_len shrinks to the snaplen +* while original_len still describes the packet on the wire. +*/ + snaplen = pkt_len /2 ; + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, snaplen, +RTE_PCAPNG_DIRECTION_IN ,NULL ); +TEST_ASSERT (mc !=NULL ,"truncated rte_pcapng_copy failed" ); + + ret =rte_pcapng_pkt_info (mc, &pkt); +TEST_ASSERT (ret ==0 ,"rte_pcapng_pkt_info failed on truncated: %d" , ret); + +TEST_ASSERT (pkt.captured_len == snaplen, +"captured_len is %u, expected %u" , pkt.captured_len, snaplen); +TEST_ASSERT (pkt.original_len == pkt_len, +"original_len is %u, expected %u, truncation lost it" , + pkt.original_len, pkt_len); + +rte_pktmbuf_free (mc); + +/* +* A stripped VLAN tag is put back by the copy, but is not +* counted in the length reported by the hardware. So the +* captured packet is larger than the original, and a consumer +* has to cope with that rather than assume it cannot happen. +*/ + mbfs.mb[0 ].ol_flags |=RTE_MBUF_F_RX_VLAN_STRIPPED ; + mbfs.mb[0 ].vlan_tci =42 ; + + mc =rte_pcapng_copy (port_id,0 , &mbfs.mb[0 ], mp, pkt_len, +RTE_PCAPNG_DIRECTION_IN ,NULL ); +TEST_ASSERT (mc !=NULL ,"VLAN rte_pcapng_copy failed" ); + + ret =rte_pcapng_pkt_info (mc, &pkt); +TEST_ASSERT (ret ==0 ,"rte_pcapng_pkt_info failed on VLAN: %d" , ret); + +TEST_ASSERT (pkt.captured_len == pkt_len +sizeof (struct rte_vlan_hdr ), +"captured_len is %u, expected %zu with the tag restored" , + pkt.captured_len, pkt_len +sizeof (struct rte_vlan_hdr )); +TEST_ASSERT (pkt.original_len == pkt_len, +"original_len is %u, expected %u" , pkt.original_len, pkt_len); +TEST_ASSERT (pkt.captured_len > pkt.original_len, +"restored VLAN tag did not make the capture longer" ); + +rte_pktmbuf_free (mc); + +return 0 ; +} +static void test_cleanup (void ) {
@@ -688,6 +820,7 @@ unit_test_suite test_pcapng_suite = {TEST_CASE (test_add_interface),TEST_CASE (test_write_packets),TEST_CASE (test_write_before_open), +TEST_CASE (test_pkt_info), TEST_CASES_END() } };
doc/guides/rel_notes/release_26_11.rst +5 -0
@@ -55,6 +55,11 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added pcapng API to read back a captured packet header.** + + Added the experimental ``rte_pcapng_pkt_info()`` function to read back what + ``rte_pcapng_copy()`` records in a captured packet. + * **Added API to get CPU socket ID.** Added the experimental ``rte_cpu_socket_id()`` function
lib/pcapng/rte_pcapng.c +40 -0
@@ -707,6 +707,46 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,return NULL ; } +/* Read back the block header put there by rte_pcapng_copy() */ +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pcapng_pkt_info, 26.11) +int +rte_pcapng_pkt_info (const struct rte_mbuf *m,struct rte_pcapng_pkt *pkt) +{ +const struct pcapng_enhance_packet_block *epb; +struct pcapng_enhance_packet_block ebuf; + +if (unlikely (m ==NULL || pkt ==NULL )) +return -EINVAL ; + + epb =rte_pktmbuf_read (m,0 ,sizeof (*epb), &ebuf); +if (unlikely (epb ==NULL )) +return -EINVAL ; + +if (unlikely (epb->block_type !=PCAPNG_ENHANCED_PACKET_BLOCK )) +return -EINVAL ; + +/* +* rte_pcapng_copy() sets block_length to the whole mbuf length, and +* the packet data has to fit in what is left after the header. +*/ +if (unlikely (epb->block_length !=rte_pktmbuf_pkt_len (m))) +return -EINVAL ; + +if (unlikely (epb->capture_length > + epb->block_length -sizeof (*epb))) +return -EINVAL ; + + pkt->cycles = (uint64_t )epb->timestamp_hi <<32 ; + pkt->cycles += epb->timestamp_lo; + + pkt->captured_len = epb->capture_length; + pkt->original_len = epb->original_length; + pkt->data_offset =sizeof (*epb); + pkt->port = m->port; + +return 0 ; +} +/* Write pre-formatted packets to file. */ RTE_EXPORT_SYMBOL (rte_pcapng_write_packets) ssize_t
lib/pcapng/rte_pcapng.h +46 -0
58 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 2/4 app/rpcapd: remote pcap daemon
In reply to Stephen HemmingerAdd RPCAP support over localhost TCP integrated with DPDK. It runs as a secondary process that allows connections from tools using tcpdump's defacto protocol rpcap.
See: doc/guides/tools/rpcapd.rst for more info
--- MAINTAINERS | 2 + app/meson.build | 1 + app/rpcapd/capture.c | 526 ++++++++++++++++++++++ app/rpcapd/filter.c | 164 +++++++ app/rpcapd/main.c | 577 +++++++++++++++++++++++++ app/rpcapd/meson.build | 25 ++ app/rpcapd/rpcap-protocol.h | 142 ++++++ app/rpcapd/rpcapd.h | 105 +++++ app/rpcapd/session.c | 136 ++++++ app/rpcapd/sock.c | 315 ++++++++++++++ doc/guides/rel_notes/release_26_11.rst | 5 + doc/guides/tools/index.rst | 1 + doc/guides/tools/rpcapd.rst | 199 +++++++++ 13 files changed, 2198 insertions(+) create mode 100644 app/rpcapd/capture.c create mode 100644 app/rpcapd/filter.c create mode 100644 app/rpcapd/main.c create mode 100644 app/rpcapd/meson.build create mode 100644 app/rpcapd/rpcap-protocol.h create mode 100644 app/rpcapd/rpcapd.h create mode 100644 app/rpcapd/session.c create mode 100644 app/rpcapd/sock.c create mode 100644 doc/guides/tools/rpcapd.rst
MAINTAINERS +2 -0
@@ -1722,6 +1722,8 @@ F: app/pdump/ F: doc/guides/tools/pdump.rst F: app/dumpcap/ F: doc/guides/tools/dumpcap.rst +F: app/rpcapd/ +F: doc/guides/tools/rpcapd.rst Packet Framework
app/meson.build +1 -0
@@ -17,6 +17,7 @@ apps = [ 'graph', 'pdump', 'proc-info', + 'rpcapd', 'test-acl', 'test-bbdev', 'test-cmdline',
app/rpcapd/capture.c new file +526 -0
526 lines not on this page · raw message
app/rpcapd/filter.c new file +164 -0
164 lines not on this page · raw message
app/rpcapd/main.c new file +577 -0
577 lines not on this page · raw message
app/rpcapd/meson.build new file +25 -0
@@ -0,0 +1,25 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Stephen Hemminger + +# relies on primary/secondary process, so Linux only +if not is_linux + build = false + reason = 'only supported on Linux' + subdir_done() +endif + +if not dpdk_conf.has('RTE_HAS_LIBPCAP') + build = false + reason = 'missing dependency, "libpcap"' + subdir_done() +endif + +sources = files( + 'capture.c', + 'filter.c', + 'main.c', + 'session.c', + 'sock.c', +) +ext_deps += pcap_dep +deps += ['ethdev', 'pdump', 'bpf', 'pcapng']
app/rpcapd/rpcap-protocol.h new file +142 -0
142 lines not on this page · raw message
app/rpcapd/rpcapd.h new file +105 -0
105 lines not on this page · raw message
app/rpcapd/session.c new file +136 -0
136 lines not on this page · raw message
app/rpcapd/sock.c new file +315 -0
315 lines not on this page · raw message
doc/guides/rel_notes/release_26_11.rst +5 -0
@@ -143,6 +143,11 @@ New Features Added ``rte_bbdev_queue_stats_get()`` function to retrieve statistics for a specific queue, complementing the existing device-level statistics API. +* **Added libpcap remote capture daemon.** + + Added the ``dpdk-rpcapd`` application, which implements the rpcap + protocol to allow live capture in tcpdump and Wireshark. + Removed Items -------------
doc/guides/tools/index.rst +1 -0
@@ -13,6 +13,7 @@ DPDK Tools User Guides proc_info pmdinfo dumpcap + rpcapd pdump telemetrywatcher dmaperf
doc/guides/tools/rpcapd.rst new file +199 -0
199 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v4 2/4] app/rpcapd: remote pcap daemon
Two non-critical nits inline.
Quoted 4 lines · Stephen Hemminger
app/rpcapd/main.c new file +4
-0+static void +parse_bind_addr (void ) +{ +struct addrinfo hints = {
app/rpcapd/main.c line 106
Quoted 10 lines
app/rpcapd/main.c new file +10
-0+ .ai_family = bind_family, + .ai_socktype = SOCK_STREAM, + .ai_flags = AI_NUMERICHOST | AI_PASSIVE, + }; +struct addrinfo *res; +int rc; + +/* Loopback by default; the wildcard address is not a safe default. */ +if (bind_addr ==NULL ) + bind_addr = (bind_family ==AF_INET6 ) ?"::1" :"127.0.0.1" ;
When neither bind_addr nor bind_family are specified, can we bind to all local addresses (127.0.0.1, ::1) that exist in the system? Or at least to the first of them that exists, to improve the user experience on IPv6-only systems a little?
app/rpcapd/main.c line 115
Quoted 9 lines
app/rpcapd/main.c new file +9
-0+ + rc =getaddrinfo (bind_addr,NULL , &hints, &res); +if (rc !=0 ) +rte_exit (EXIT_FAILURE ,"Invalid bind address '%s': %s\n" , + bind_addr,gai_strerror (rc)); +memcpy (&listen_addr, res->ai_addr, res->ai_addrlen); + listen_addrlen = res->ai_addrlen; +freeaddrinfo (res); +}
// ...
app/rpcapd/rpcapd.h line 30
Quoted 2 lines
app/rpcapd/rpcapd.h new file +2
-0+/* Largest snaplen a client can be given. */ +#define DEFAULT_SNAPLEN RTE_MBUF_DEFAULT_DATAROOM
The naming is not optimal, it's upper limit not default.
PATCH v4 3/4 app/rpcapd: add TLS support
In reply to Stephen HemmingerSupport remote packet capture over TLS.
This requires OpenSSL to be available.
--- app/rpcapd/capture.c | 15 ++ app/rpcapd/main.c | 154 +++++++++++++- app/rpcapd/meson.build | 15 ++ app/rpcapd/rpcap-protocol.h | 3 + app/rpcapd/rpcapd.h | 20 +- app/rpcapd/session.c | 182 +++++++++++++++-- app/rpcapd/sock.c | 52 ++++- app/rpcapd/tls.c | 273 +++++++++++++++++++++++++ doc/guides/rel_notes/release_26_11.rst | 2 + doc/guides/tools/rpcapd.rst | 119 +++++++++-- 10 files changed, 789 insertions(+), 46 deletions(-) create mode 100644 app/rpcapd/tls.c
app/rpcapd/capture.c +15 -0
@@ -168,6 +168,7 @@ stop_capture(struct session *s)rte_free (s->prm); s->prm =NULL ;if (s->data.fd >=0 ) { +tls_close (&s->data);close (s->data.fd); s->data.fd =-1 ; }
@@ -312,6 +313,14 @@ handle_startcap(const struct conn *c, uint32_t plen, struct session *s) s->data.fd = data_fd; +/* The client starts its handshake as soon as it has connected, +* so promote before anything is sent. +*/ +if (use_tls &&tls_accept (&s->data) <0 ) { +stop_capture (s); +return -1 ; + } +RPCAPD_LOG (NOTICE ,"capture started on %s (snaplen %u, data port %u)" , s->name, s->snaplen, data_port);
@@ -427,6 +436,12 @@ check_socket_status(const struct conn *ctrl) {struct pollfd pfd = { .fd = ctrl->fd, .events =POLLIN }; +/* A request may already be decrypted and waiting out of sight +* of poll(), sharing a TLS record with an earlier one. +*/ +if (tls_pending (ctrl)) +return 1 ; +if (poll (&pfd,1 ,0 ) <0 ) {if (errno ==EINTR )return 0 ;
app/rpcapd/main.c +143 -11
249 lines not on this page · raw message
app/rpcapd/meson.build +15 -0
@@ -14,12 +14,27 @@ if not dpdk_conf.has('RTE_HAS_LIBPCAP') subdir_done() endif +# password authentication uses crypt(3) +libcrypt_dep = cc.find_library('crypt', required: false) +if not libcrypt_dep.found() + build = false + reason = 'missing dependency, "libcrypt"' + subdir_done() +endif + sources = files( 'capture.c', 'filter.c', 'main.c', 'session.c', 'sock.c', + 'tls.c', ) ext_deps += pcap_dep +ext_deps += libcrypt_dep deps += ['ethdev', 'pdump', 'bpf', 'pcapng'] + +# TLS support is optional; tls.c builds as stubs without it +if dpdk_conf.has('RTE_HAS_OPENSSL') + ext_deps += openssl_dep +endif
app/rpcapd/rpcap-protocol.h +3 -0
@@ -42,7 +42,10 @@#define RPCAP_MSG_STATS_REPLY (RPCAP_MSG_STATS_REQ | RPCAP_MSG_IS_REPLY)/* Error codes carried in the 'value' field of RPCAP_MSG_ERROR */ +#define PCAP_ERR_AUTH 3/* generic authentication error */ #define PCAP_ERR_WRONGVER 17 +#define PCAP_ERR_AUTH_FAILED 18/* credentials were not accepted */ +#define PCAP_ERR_TLS_REQUIRED 19/* server will only speak TLS */ #define PCAP_ERR_AUTH_TYPE_NOTSUP 20/* Authentication types in rpcap_auth.type */
app/rpcapd/rpcapd.h +18 -2
@@ -21,6 +21,7 @@struct rte_bpf_prm ;struct rte_mempool ;struct rte_ring ; +struct ssl_st ;#define RTE_LOGTYPE_RPCAPD RTE_LOGTYPE_USER1#define RPCAPD_LOG (level, ...) \
@@ -36,9 +37,10 @@ struct rte_ring;*/ #define MAX_CAPTURE_LEN (DEFAULT_SNAPLEN + 2 * sizeof(struct rte_vlan_hdr)) -/* A connection to the client. */ +/* A connection to the client; ssl is NULL when not encrypted. */ struct conn {int fd; +struct ssl_st *ssl; };/* Per-client capture session state. */
@@ -50,6 +52,7 @@ struct session {uint32_t snaplen;uint32_t npkt;/* packet sequence for rpcap_pkthdr */ uint32_t pdump_flags;/* direction bits handed to pdump */ +bool authenticated;/* AUTH_REQ has succeeded */ bool opened;/* OPEN_REQ has selected a port */ bool capture_on;bool promisc_set;/* we enabled promiscuous mode */
@@ -64,6 +67,8 @@ extern RTE_ATOMIC(bool) quit_signal;/* Command-line settings needed outside of main.c */ extern uint32_t ring_size;extern uint32_t send_timeout;/* seconds; 0 means no limit */ +extern bool use_tls;/* -S: encrypt both connections */ +extern bool null_auth_ok;/* -n: permit null auth off loopback */ /* Address the control socket is bound to; the data socket uses the same * address with an ephemeral port.
@@ -71,6 +76,8 @@ extern uint32_t send_timeout; /* seconds; 0 means no limit */extern struct sockaddr_storage listen_addr;extern socklen_t listen_addrlen; +bool is_loopback (const struct sockaddr_storage *ss); +/* sock.c: transport and message framing */ int wait_readable (const struct conn *c,int timeout_ms);int accept_timeout (int listen_fd,int timeout_ms);
@@ -85,8 +92,17 @@ int rpcap_discard(const struct conn *c, uint32_t plen);void set_sockaddr_port (struct sockaddr_storage *ss,uint16_t port);uint16_t get_sockaddr_port (const struct sockaddr_storage *ss); +/* tls.c: TLS transport, stubbed out when built without OpenSSL */ +int tls_init (const char *certfile,const char *keyfile); +int tls_accept (struct conn *c); +void tls_close (struct conn *c); +int tls_send (struct ssl_st *ssl,const void *buf,size_t len); +int tls_recv (struct ssl_st *ssl,void *buf,size_t len); +bool tls_pending (const struct conn *c); +void tls_reject_handshake (int fd); +/* session.c: control requests handled before a capture starts */ -int handle_auth (const struct conn *c,uint32_t plen); +int handle_auth (const struct conn *c,uint32_t plen,struct session *s);int handle_findallif (const struct conn *c);int handle_open (const struct conn *c,uint32_t plen,struct session *s);
app/rpcapd/session.c +169 -13
220 lines not on this page · raw message
app/rpcapd/sock.c +51 -1
82 lines not on this page · raw message
app/rpcapd/tls.c new file +273 -0
273 lines not on this page · raw message
doc/guides/rel_notes/release_26_11.rst +2 -0
@@ -147,6 +147,8 @@ New Features Added the ``dpdk-rpcapd`` application, which implements the rpcap protocol to allow live capture in tcpdump and Wireshark. + Remote clients can be authenticated with a system username and password, + and connections encrypted with TLS when built with OpenSSL. Removed Items
doc/guides/tools/rpcapd.rst +100 -19
148 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v4 4/4 app/rpcapd: add host list option
In reply to Stephen HemmingerAdd -l to restrict which clients may connect, as libpcap's rpcapd does. The argument is the list itself rather than a file naming one, with hosts separated by a comma, semicolon or space, so a list can be copied between the two daemons.
Names are resolved once at startup, so DNS stays out of the accept path and an unresolvable name fails at startup rather than when a client first arrives. Every address a name resolves to is accepted.
The list is checked after any TLS handshake, since a client using rpcaps:// can only read an error sent inside the session. Only the control connection is checked: the data connection is already restricted to the address the control connection came from.
This bounds which hosts may connect but does not identify them, so it complements the password authentication rather than replacing it.
--- app/rpcapd/main.c | 135 ++++++++++++++++++++++++- app/rpcapd/rpcap-protocol.h | 1 + app/rpcapd/rpcapd.h | 1 + app/rpcapd/sock.c | 2 +- doc/guides/rel_notes/release_26_11.rst | 1 + doc/guides/tools/rpcapd.rst | 8 ++ 6 files changed, 145 insertions(+), 3 deletions(-)
app/rpcapd/main.c +133 -2
@@ -66,6 +66,11 @@ bool use_tls; /* -S */bool null_auth_ok;/* -n */ static const char *tls_certfile;/* -X argument */ static const char *tls_keyfile;/* -K argument */ +static const char *host_list;/* -l argument; NULL means any host */ + +/* -l resolved at startup; empty means no restriction. */ +static struct sockaddr_storage *allowed_hosts; +static unsigned int num_allowed_hosts;struct sockaddr_storage listen_addr;socklen_t listen_addrlen;
@@ -94,6 +99,114 @@ is_loopback(const struct sockaddr_storage *ss)return false; } +/* Separators in the -l argument, same set as libpcap's rpcapd. */ +#define HOST_LIST_SEP " ,;" + +/* +* A dual-stack socket reports a v4 peer as ::ffff:a.b.c.d, which +* same_host() will not match against an AF_INET entry. Normalize both +* the peer and the list, since a resolver can also return a mapped +* address. +*/ +static void +unmap_v4 (struct sockaddr_storage *ss) +{ +const struct sockaddr_in6 *sin6 = (const void *)ss; +struct sockaddr_in sin = { + .sin_family =AF_INET , + .sin_port = sin6->sin6_port, + }; + +if (ss->ss_family !=AF_INET6 || !IN6_IS_ADDR_V4MAPPED (&sin6->sin6_addr)) +return ; + +memcpy (&sin.sin_addr, &sin6->sin6_addr.s6_addr[12 ],sizeof (sin.sin_addr)); +memset (ss,0 ,sizeof (*ss)); +memcpy (ss, &sin,sizeof (sin)); +} + +/* +* Resolve the -l list at startup, so an unresolvable name fails here +* rather than when a client connects. A name can have several +* addresses; all of them are accepted. +*/ +static void +parse_host_list (void ) +{ +static const struct addrinfo hints = { + .ai_family =AF_UNSPEC , + .ai_socktype =SOCK_STREAM , + }; +char *copy, *token, *saveptr; + +if (host_list ==NULL ) +return ; + + copy =strdup (host_list); +if (copy ==NULL ) +rte_exit (EXIT_FAILURE ,"Cannot copy host list: %s\n" ,strerror (errno)); + +for (token =strtok_r (copy,HOST_LIST_SEP , &saveptr); token !=NULL ; + token =strtok_r (NULL ,HOST_LIST_SEP , &saveptr)) { +struct addrinfo *res, *ai; +unsigned int n =0 ; +void *tmp; +int rc; + + rc =getaddrinfo (token,NULL , &hints, &res); +if (rc !=0 ) +rte_exit (EXIT_FAILURE ,"Invalid host '%s' in host list: %s\n" , + token,gai_strerror (rc)); + +for (ai = res; ai !=NULL ; ai = ai->ai_next) + n++; + + tmp =realloc (allowed_hosts, + (num_allowed_hosts + n) *sizeof (*allowed_hosts)); +if (tmp ==NULL ) +rte_exit (EXIT_FAILURE ,"Cannot grow host list: %s\n" , +strerror (errno)); + allowed_hosts = tmp; + +for (ai = res; ai !=NULL ; ai = ai->ai_next) { +struct sockaddr_storage *slot = + &allowed_hosts[num_allowed_hosts++]; + +memset (slot,0 ,sizeof (*slot)); +memcpy (slot, ai->ai_addr, ai->ai_addrlen); +unmap_v4 (slot); + } + +freeaddrinfo (res); + } +free (copy); + +/* An empty list is a typo, not a request to allow everyone. */ +if (num_allowed_hosts ==0 ) +rte_exit (EXIT_FAILURE ,"Host list '%s' contains no hosts\n" , host_list); +} + +/* Only the control connection is checked; accept_from() pins the data +* connection to the same peer. +*/ +static bool +host_allowed (const struct sockaddr_storage *ss) +{ +struct sockaddr_storage peer = *ss; +unsigned int i; + +if (num_allowed_hosts ==0 ) +return true; + +unmap_v4 (&peer); + +for (i =0 ; i < num_allowed_hosts; i++) +if (same_host (&peer, &allowed_hosts[i])) +return true; + +return false; +} +static void parse_bind_addr (void ) {
@@ -211,6 +324,17 @@ handle_client(int ctrl_fd)if (setup_tls (&ctrl) <0 ) goto done; +/* After the handshake: a TLS client can only read an error sent +* inside the session. +*/ +if (!host_allowed (&peer)) { +RPCAPD_LOG (WARNING ,"rejected client %s: not in the allowed host list" , + host); +rpcap_send_error (&ctrl,PCAP_ERR_HOSTNOAUTH , +"this host is not allowed to connect to this server" ); + goto done; + } +while (!rte_atomic_load_explicit (&quit_signal, rte_memory_order_relaxed)) {struct rpcap_header hdr;uint32_t plen;
@@ -343,6 +467,8 @@ usage(FILE *f, const char *progname)" -b, --bind <addr> bind address (default 127.0.0.1, ::1 with -6)\n" " -4 use only IPv4\n" " -6 use only IPv6\n" +" -l, --hosts <list> only accept clients from these hosts,\n" +" separated by ',' ';' or space\n" " -N <ring size> ring size in packets (default %u)\n" #ifdef RTE_HAS_OPENSSL" -S, --tls encrypt connections with TLS (rpcaps://)\n"
@@ -386,6 +512,7 @@ parse_opts(int argc, char **argv)static const struct option long_options[] = { {"port" , required_argument,NULL ,'p' }, {"bind" , required_argument,NULL ,'b' }, + {"hosts" , required_argument,NULL ,'l' }, {"null-auth" , no_argument,NULL ,'n' }, #ifdef RTE_HAS_OPENSSL { "tls", no_argument, NULL, 'S' },
@@ -403,7 +530,7 @@ parse_opts(int argc, char **argv) };int option_index, c; - while ((c = getopt_long(argc, argv, "hnD46p:b:N:" + while ((c = getopt_long(argc, argv, "hnD46p:b:l:N:" #ifdef RTE_HAS_OPENSSL "SX:K:" #endif
@@ -420,6 +547,9 @@ parse_opts(int argc, char **argv)case 'b' : bind_addr = optarg;break ; +case 'l' : + host_list = optarg; +break ;case '4' : bind_family =AF_INET ;break ;
@@ -506,6 +636,7 @@ parse_opts(int argc, char **argv)/* Resolve the bind address now that -4/-6/-b have been seen. */ parse_bind_addr (); +parse_host_list ();/* There is no sensible default for either: libpcap's rpcapd looks * for cert.pem and key.pem in the current directory, which is not
@@ -519,7 +650,7 @@ parse_opts(int argc, char **argv)rte_exit (EXIT_FAILURE ,"A certificate or key was given without -S\n" ); -if (null_auth_ok && !is_loopback (&listen_addr)) +if (null_auth_ok && !is_loopback (&listen_addr) && num_allowed_hosts ==0 )RPCAPD_LOG (ERR ,"-n allows any client that can reach this port to capture traffic" ); }
app/rpcapd/rpcap-protocol.h +1 -0
@@ -43,6 +43,7 @@/* Error codes carried in the 'value' field of RPCAP_MSG_ERROR */ #define PCAP_ERR_AUTH 3/* generic authentication error */ +#define PCAP_ERR_HOSTNOAUTH 10/* peer address is not in the allowed list */ #define PCAP_ERR_WRONGVER 17#define PCAP_ERR_AUTH_FAILED 18/* credentials were not accepted */ #define PCAP_ERR_TLS_REQUIRED 19/* server will only speak TLS */
app/rpcapd/rpcapd.h +1 -0
@@ -79,6 +79,7 @@ extern socklen_t listen_addrlen;bool is_loopback (const struct sockaddr_storage *ss);/* sock.c: transport and message framing */ +bool same_host (const struct sockaddr_storage *a,const struct sockaddr_storage *b);int wait_readable (const struct conn *c,int timeout_ms);int accept_timeout (int listen_fd,int timeout_ms); int accept_from(int listen_fd, const struct sockaddr_storage *want,
app/rpcapd/sock.c +1 -1
@@ -115,7 +115,7 @@ accept_timeout(int listen_fd, int timeout_ms)/* Compare the host part of two addresses, ignoring the port: the data * connection comes from an ephemeral port, not the control one. */ -static bool +bool same_host (const struct sockaddr_storage *a,const struct sockaddr_storage *b) {if (a->ss_family != b->ss_family)
doc/guides/rel_notes/release_26_11.rst +1 -0
@@ -149,6 +149,7 @@ New Features protocol to allow live capture in tcpdump and Wireshark. Remote clients can be authenticated with a system username and password, and connections encrypted with TLS when built with OpenSSL. + Access can also be restricted to a list of allowed client hosts. Removed Items
doc/guides/tools/rpcapd.rst +8 -0
@@ -60,6 +60,14 @@ The application has a small set of command-line options: Use only IPv6; an IPv4 argument to ``-b`` is rejected. The default bind address becomes ``::1``. +* ``-l <host_list>``, ``--hosts <host_list>`` + + Only allow the hosts in ``<host_list>`` to connect. The list is + host names or addresses separated by commas, semicolons or spaces, + and includes loopback, so ``127.0.0.1`` must be listed for a local + client. Names are resolved at startup. By default any host that + can reach the port may connect. + * ``-N <ring_size>`` Size of the per-session capture ring in packets. Default is 2048.
Signature · 1 line
2.53.0
Re: [PATCH v4 0/4] add rpcap remote capture daemon
In reply to Stephen HemmingerQuoted 1 line
pcapng: add API to read back capture mbuf header
Analysis with AI tells that there are some opportunities to make the fast path of lib/pcapng both lighter and less .pcapng-centric to make life of consumers that prefer other formats easier. It does not have to (probably even shouldn't) be a part of the current patchset though.
Quoted 1 line
app/rpcapd: remote pcap daemon
Ideally forwarding captured data could run in a separate thread with minimum unnecessary syscalls, although it's hard to tell without benchmarks how much current design is slowed down by them.
Quoted 1 line
app/rpcapd: add TLS support
This patch simultaneously adds authentication, but it's only required for non-loopback users. This is a common security vulnerability, not all loopback users can be trusted. So if we care about authentication at all, it should probably also be required for localhost users, at least by default.
Quoted 20 lines
app/rpcapd: add host list option
MAINTAINERS | 2 + app/meson.build | 1 + app/rpcapd/capture.c | 541 ++++++++++++++++ app/rpcapd/filter.c | 164 +++++ app/rpcapd/main.c | 840 +++++++++++++++++++++++++ app/rpcapd/meson.build | 40 ++ app/rpcapd/rpcap-protocol.h | 146 +++++ app/rpcapd/rpcapd.h | 122 ++++ app/rpcapd/session.c | 292 +++++++++ app/rpcapd/sock.c | 365 +++++++++++ app/rpcapd/tls.c | 273 ++++++++ app/test/test_pcapng.c | 133 ++++ doc/guides/rel_notes/release_26_11.rst | 13 + doc/guides/tools/index.rst | 1 + doc/guides/tools/rpcapd.rst | 288 +++++++++ lib/pcapng/rte_pcapng.c | 40 ++ lib/pcapng/rte_pcapng.h | 46 ++ 17 files changed, 3307 insertions(+)
Quoted 10 lines
create mode 100644
app/rpcapd/capture.c
create mode 100644app/rpcapd/filter.c
create mode 100644app/rpcapd/main.c
create mode 100644 app/rpcapd/meson.build
create mode 100644app/rpcapd/rpcap-protocol.h
create mode 100644app/rpcapd/rpcapd.h
create mode 100644app/rpcapd/session.c
create mode 100644app/rpcapd/sock.c
create mode 100644app/rpcapd/tls.c
create mode 100644doc/guides/tools/rpcapd.rst
With or without addressing any of the comments above,
Re: [PATCH v4 0/4] add rpcap remote capture daemon
Quoted 5 lines · On Thu, 1 Oct 2026 19:50:34 +0100 Marat Khalili <[email protected]> wrote:
Quoted 1 line
pcapng: add API to read back capture mbuf header
Analysis with AI tells that there are some opportunities to make the fast path of lib/pcapng both lighter and less .pcapng-centric to make life of consumers that prefer other formats easier. It does not have to (probably even shouldn't) be a part of the current patchset though.
Thought about that, and also looked at making rpcap another library but it ends up with DPDK reimplementing libpcap...
The other option would be using dynamic fields. There already is timestamp, but there is none for "original packet length".
Third option is not using pdump callbacks at all and just having rpcap specific callbacks. That is what the Wireshark extcap does. That is where I think this will end up. Would like to not use pdump since it has so many design problems baked in.
Quoted 4 lines
Quoted 1 line
app/rpcapd: remote pcap daemon
Ideally forwarding captured data could run in a separate thread with minimum unnecessary syscalls, although it's hard to tell without benchmarks how much current design is slowed down by them.
New version does use a data forwarding thread. It has to write to a socket, which it does with sendmsg. It could use liburing, to reduce syscalls further.
Quoted 6 lines
Quoted 1 line
app/rpcapd: add TLS support
This patch simultaneously adds authentication, but it's only required for non-loopback users. This is a common security vulnerability, not all loopback users can be trusted. So if we care about authentication at all, it should probably also be required for localhost users, at least by default.
Good point, but do not want to add DPDK specific user data base. The problem is that TCP loopback has no way to identify who is on the other end. Unix domain sockets do, but libpcap doesn't support that.
The real long term answer is having plugins in libpcap (Robin's proposal) and make this one of the plugins. But that will take longer to reach agreement on.
PATCH v5 1/1 examples/rpcapd: remote pcap daemon
In reply to Stephen HemmingerThis example provides a mechanism for doing live capture with tcpdump of a DPDK application. It uses libpcap tools (requires rebuild to enable rpcap). The example daemon uses the rpcap protocol that libpcap uses. It runs as a DPDK secondary process and takes packets from the existing pdump infrastructure.
There are security issues with opening up general rpcap access so the daemon is bound to loopback address only.
See doc/guides/sample_app_ug/rpcapd.rst for more info.
---
v5 - simplify only do what is needed for demo
- put in examples/
- only bind to loopback no option to allow remote
- document restrictions and security limitations
- don't bother with auth or TLS
- accept worse latency in timestamp instead of having to change pcapng
- repeated AI review scans
MAINTAINERS | 2 + doc/guides/rel_notes/release_26_11.rst | 6 + doc/guides/sample_app_ug/index.rst | 1 + doc/guides/sample_app_ug/rpcapd.rst | 199 ++++++++ examples/meson.build | 1 + examples/rpcapd/Makefile | 41 ++ examples/rpcapd/capture.c | 645 ++++++++++++++++++++++++ examples/rpcapd/filter.c | 163 ++++++ examples/rpcapd/main.c | 669 +++++++++++++++++++++++++ examples/rpcapd/meson.build | 28 ++ examples/rpcapd/rpcap-protocol.h | 143 ++++++ examples/rpcapd/rpcapd.h | 119 +++++ examples/rpcapd/session.c | 136 +++++ examples/rpcapd/sock.c | 292 +++++++++++ 14 files changed, 2445 insertions(+) create mode 100644 doc/guides/sample_app_ug/rpcapd.rst create mode 100644 examples/rpcapd/Makefile create mode 100644 examples/rpcapd/capture.c create mode 100644 examples/rpcapd/filter.c create mode 100644 examples/rpcapd/main.c create mode 100644 examples/rpcapd/meson.build create mode 100644 examples/rpcapd/rpcap-protocol.h create mode 100644 examples/rpcapd/rpcapd.h create mode 100644 examples/rpcapd/session.c create mode 100644 examples/rpcapd/sock.c
MAINTAINERS +2 -0
@@ -1727,6 +1727,8 @@ F: app/pdump/ F: doc/guides/tools/pdump.rst F: app/dumpcap/ F: doc/guides/tools/dumpcap.rst +F: examples/rpcapd/ +F: doc/guides/sample_app_ug/rpcapd.rst Packet Framework
doc/guides/rel_notes/release_26_11.rst +6 -0
@@ -158,6 +158,12 @@ New Features Added ``rte_bbdev_queue_stats_get()`` function to retrieve statistics for a specific queue, complementing the existing device-level statistics API. +* **Added libpcap remote capture daemon example.** + + Added the ``dpdk-rpcapd`` example application, which implements the + rpcap protocol over loopback to allow live capture in tcpdump and + Wireshark. + Removed Items -------------
doc/guides/sample_app_ug/index.rst +1 -0
@@ -50,6 +50,7 @@ Sample Applications User Guides vm_power_management ptpclient ptp_tap_relay_sw + rpcapd fips_validation ipsec_secgw bbdev_app
doc/guides/sample_app_ug/rpcapd.rst new file +199 -0
199 lines not on this page · raw message
examples/meson.build +1 -0
@@ -44,6 +44,7 @@ all_examples = [ 'ptpclient', 'qos_meter', 'qos_sched', + 'rpcapd', 'rxtx_callbacks', 'server_node_efd/efd_node', 'server_node_efd/efd_server',
examples/rpcapd/Makefile new file +41 -0
41 lines not on this page · raw message
examples/rpcapd/capture.c new file +645 -0
645 lines not on this page · raw message
examples/rpcapd/filter.c new file +163 -0
163 lines not on this page · raw message
examples/rpcapd/main.c new file +669 -0
669 lines not on this page · raw message
examples/rpcapd/meson.build new file +28 -0
@@ -0,0 +1,28 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2026 Stephen Hemminger + +# meson file, for building this example as part of a main DPDK build. +# +# To build this example as a standalone application with an already-installed +# DPDK instance, use 'make' + +# relies on primary/secondary process, so Linux only +if not is_linux + build = false + subdir_done() +endif + +if not dpdk_conf.has('RTE_HAS_LIBPCAP') + build = false + subdir_done() +endif + +ext_deps += pcap_dep +deps += ['pdump', 'bpf'] +sources = files( + 'capture.c', + 'filter.c', + 'main.c', + 'session.c', + 'sock.c', +)
examples/rpcapd/rpcap-protocol.h new file +143 -0
143 lines not on this page · raw message
examples/rpcapd/rpcapd.h new file +119 -0
119 lines not on this page · raw message
examples/rpcapd/session.c new file +136 -0
136 lines not on this page · raw message
examples/rpcapd/sock.c new file +292 -0
292 lines not on this page · raw message
Signature · 1 line
2.53.0