diff options
| author | songyanchao <[email protected]> | 2024-07-05 06:36:34 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2024-07-05 06:36:34 +0000 |
| commit | ddd463ce901fdda29c2aae8d5547cbb701b43f02 (patch) | |
| tree | 5c99cbebc0d152d17f268ff81f2abb42e89ca5a4 /service/src | |
| parent | 2c71bcd463ebb02e3f75fc9deb54a7cab784e6c9 (diff) | |
✨ feat(DPISDN-51): Add offset argument support to mrpdump for shmdev.
Add offset argument support to mrpdump for shmdev.
Diffstat (limited to 'service/src')
| -rw-r--r-- | service/src/pdump.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/service/src/pdump.c b/service/src/pdump.c index 392755c..b33b851 100644 --- a/service/src/pdump.c +++ b/service/src/pdump.c @@ -14,12 +14,14 @@ /* Mrpdump copy function */ typedef void (*shmdev_pdump_func)(uint16_t port_id, uint16_t queue, struct rte_mempool * mp, struct rte_ring * ring, struct rte_mbuf ** mbufs, unsigned int nr_pkts, struct rte_pdump_stats * stats, - struct rte_bpf * bpf, uint64_t snaplen, enum rte_pcapng_direction direction); + struct rte_bpf * bpf, uint32_t snaplen, uint32_t offset, + enum rte_pcapng_direction direction); struct port_resource { uint16_t queue; - uint64_t snaplen; + uint32_t snaplen; + uint32_t offset; struct rte_ring * rx_ring; struct rte_ring * tx_ring; shmdev_pdump_func rx_pdump_func; @@ -64,10 +66,11 @@ void mr_pdump_rx(port_id_t shmdev_port_id, queue_id_t qid, struct rte_mbuf ** mb struct rte_pdump_stats * stats = &_mr_pdump_main->ports[port_id]->rx_stats; shmdev_pdump_func pdump_func = _mr_pdump_main->ports[port_id]->rx_pdump_func; struct rte_bpf * bpf = _mr_pdump_main->ports[port_id]->rx_bpf; - uint64_t snaplen = _mr_pdump_main->ports[port_id]->snaplen; + uint32_t snaplen = _mr_pdump_main->ports[port_id]->snaplen; + uint32_t offset = _mr_pdump_main->ports[port_id]->offset; /* Dump the pkt */ - pdump_func(port_id, qid, mp, ring, mbufs, nr_pkts, stats, bpf, snaplen, RTE_PCAPNG_DIRECTION_IN); + pdump_func(port_id, qid, mp, ring, mbufs, nr_pkts, stats, bpf, snaplen, offset, RTE_PCAPNG_DIRECTION_IN); } /* Mrpdump for tx */ @@ -91,15 +94,16 @@ void mr_pdump_tx(port_id_t shmdev_port_id, queue_id_t qid, struct rte_mbuf ** mb struct rte_pdump_stats * stats = &_mr_pdump_main->ports[port_id]->tx_stats; shmdev_pdump_func pdump_func = _mr_pdump_main->ports[port_id]->tx_pdump_func; struct rte_bpf * bpf = _mr_pdump_main->ports[port_id]->tx_bpf; - uint64_t snaplen = _mr_pdump_main->ports[port_id]->snaplen; + uint32_t snaplen = _mr_pdump_main->ports[port_id]->snaplen; + uint32_t offset = _mr_pdump_main->ports[port_id]->offset; /* Dump the pkt */ - pdump_func(port_id, qid, mp, ring, mbufs, nr_pkts, stats, bpf, snaplen, RTE_PCAPNG_DIRECTION_OUT); + pdump_func(port_id, qid, mp, ring, mbufs, nr_pkts, stats, bpf, snaplen, offset, RTE_PCAPNG_DIRECTION_OUT); } void shmdev_pdump_copy(uint16_t port_id, uint16_t queue, struct rte_mempool * mp, struct rte_ring * ring, struct rte_mbuf ** mbufs, unsigned int nr_pkts, struct rte_pdump_stats * stats, - struct rte_bpf * bpf, uint64_t snaplen, enum rte_pcapng_direction direction) + struct rte_bpf * bpf, uint32_t snaplen, uint32_t offset, enum rte_pcapng_direction direction) { uint16_t d_pkts = 0; uint64_t rcs[nr_pkts]; @@ -107,7 +111,24 @@ void shmdev_pdump_copy(uint16_t port_id, uint16_t queue, struct rte_mempool * mp if (bpf != NULL) { - rte_bpf_exec_burst(bpf, (void **)mbufs, rcs, nr_pkts); + if (likely(offset == 0)) + { + rte_bpf_exec_burst(bpf, (void **)mbufs, rcs, nr_pkts); + } + else + { + for (int i = 0; i < nr_pkts; i++) + { + rte_pktmbuf_adj(mbufs[i], offset); + } + + rte_bpf_exec_burst(bpf, (void **)mbufs, rcs, nr_pkts); + + for (int i = 0; i < nr_pkts; i++) + { + rte_pktmbuf_prepend(mbufs[i], offset); + } + } } for (unsigned int i = 0; i < nr_pkts; i++) @@ -155,8 +176,8 @@ int mr_pdump_enable(const struct mr_pdump_request * _cli_req, struct mr_pdump_re struct rte_mempool * _mempool = NULL; /* Dump log */ - MR_INFO("Mrpdump enable device: %s, port: %u, queue: %u, rx/tx: %u.", dev_desc->symbol, port_id, _cli_req->queue, - _cli_req->flags); + MR_INFO("Mrpdump enable device: %s, port: %u, queue: %u, rx/tx: %u, offset: %u.", dev_desc->symbol, port_id, + _cli_req->queue, _cli_req->flags, _cli_req->offset); /* Deal rx */ if (_cli_req->flags & RTE_PDUMP_FLAG_RX) @@ -221,6 +242,7 @@ int mr_pdump_enable(const struct mr_pdump_request * _cli_req, struct mr_pdump_re /* Save the pdump info for public */ _mr_pdump_main->ports[port_id]->queue = _cli_req->queue; _mr_pdump_main->ports[port_id]->snaplen = _cli_req->snaplen; + _mr_pdump_main->ports[port_id]->offset = _cli_req->offset; return RT_SUCCESS; } @@ -382,7 +404,7 @@ int mr_pdump_init(struct sc_main * sc) MR_VERIFY_MALLOC(mr_pdump_main); g_mr_pdump_main = mr_pdump_main; - for (int index = 0; index < MR_DEVICE_MAX; index++) + for (int index = 0; index < MR_DEVICE_MAX; index++) { mr_pdump_main->ports[index] = ZMALLOC(sizeof(struct port_resource)); MR_VERIFY_MALLOC(mr_pdump_main->ports[index]); |
