Create a clone of mbuf to be placed into ring. */
| 80 | |
| 81 | /* Create a clone of mbuf to be placed into ring. */ |
| 82 | static void |
| 83 | pdump_copy(uint16_t port_id, uint16_t queue, |
| 84 | enum rte_pcapng_direction direction, |
| 85 | struct rte_mbuf **pkts, uint16_t nb_pkts, |
| 86 | const struct pdump_rxtx_cbs *cbs, |
| 87 | struct rte_pdump_stats *stats) |
| 88 | { |
| 89 | unsigned int i; |
| 90 | int ring_enq; |
| 91 | uint16_t d_pkts = 0; |
| 92 | struct rte_mbuf *dup_bufs[nb_pkts]; |
| 93 | struct rte_ring *ring; |
| 94 | struct rte_mempool *mp; |
| 95 | struct rte_mbuf *p; |
| 96 | uint64_t rcs[nb_pkts]; |
| 97 | |
| 98 | if (cbs->filter) |
| 99 | rte_bpf_exec_burst(cbs->filter, (void **)pkts, rcs, nb_pkts); |
| 100 | |
| 101 | ring = cbs->ring; |
| 102 | mp = cbs->mp; |
| 103 | for (i = 0; i < nb_pkts; i++) { |
| 104 | /* |
| 105 | * This uses same BPF return value convention as socket filter |
| 106 | * and pcap_offline_filter. |
| 107 | * if program returns zero |
| 108 | * then packet doesn't match the filter (will be ignored). |
| 109 | */ |
| 110 | if (cbs->filter && rcs[i] == 0) { |
| 111 | rte_atomic_fetch_add_explicit(&stats->filtered, |
| 112 | 1, rte_memory_order_relaxed); |
| 113 | continue; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * If using pcapng then want to wrap packets |
| 118 | * otherwise a simple copy. |
| 119 | */ |
| 120 | if (cbs->ver == V2) |
| 121 | p = rte_pcapng_copy(port_id, queue, |
| 122 | pkts[i], mp, cbs->snaplen, |
| 123 | direction, NULL); |
| 124 | else |
| 125 | p = rte_pktmbuf_copy(pkts[i], mp, 0, cbs->snaplen); |
| 126 | |
| 127 | if (unlikely(p == NULL)) |
| 128 | rte_atomic_fetch_add_explicit(&stats->nombuf, 1, rte_memory_order_relaxed); |
| 129 | else |
| 130 | dup_bufs[d_pkts++] = p; |
| 131 | } |
| 132 | |
| 133 | rte_atomic_fetch_add_explicit(&stats->accepted, d_pkts, rte_memory_order_relaxed); |
| 134 | |
| 135 | ring_enq = rte_ring_enqueue_burst(ring, (void *)&dup_bufs[0], d_pkts, NULL); |
| 136 | if (unlikely(ring_enq < d_pkts)) { |
| 137 | unsigned int drops = d_pkts - ring_enq; |
| 138 | |
| 139 | rte_atomic_fetch_add_explicit(&stats->ringfull, drops, rte_memory_order_relaxed); |
no test coverage detected