| 271 | } |
| 272 | |
| 273 | static uint16_t |
| 274 | eth_pcap_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) |
| 275 | { |
| 276 | unsigned int i; |
| 277 | struct pcap_pkthdr *header; |
| 278 | struct pmd_process_private *pp; |
| 279 | const u_char *packet; |
| 280 | struct rte_mbuf *mbuf; |
| 281 | struct pcap_rx_queue *pcap_q = queue; |
| 282 | uint16_t num_rx = 0; |
| 283 | uint32_t rx_bytes = 0; |
| 284 | pcap_t *pcap; |
| 285 | |
| 286 | pp = rte_eth_devices[pcap_q->port_id].process_private; |
| 287 | pcap = pp->rx_pcap[pcap_q->queue_id]; |
| 288 | |
| 289 | if (unlikely(pcap == NULL || nb_pkts == 0)) |
| 290 | return 0; |
| 291 | |
| 292 | /* Reads the given number of packets from the pcap file one by one |
| 293 | * and copies the packet data into a newly allocated mbuf to return. |
| 294 | */ |
| 295 | for (i = 0; i < nb_pkts; i++) { |
| 296 | /* Get the next PCAP packet */ |
| 297 | int ret = pcap_next_ex(pcap, &header, &packet); |
| 298 | if (ret != 1) { |
| 299 | if (ret == PCAP_ERROR) |
| 300 | pcap_q->rx_stat.err_pkts++; |
| 301 | |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | mbuf = rte_pktmbuf_alloc(pcap_q->mb_pool); |
| 306 | if (unlikely(mbuf == NULL)) { |
| 307 | pcap_q->rx_stat.rx_nombuf++; |
| 308 | break; |
| 309 | } |
| 310 | |
| 311 | uint32_t len = header->caplen; |
| 312 | if (len <= rte_pktmbuf_tailroom(mbuf)) { |
| 313 | /* pcap packet will fit in the mbuf, can copy it */ |
| 314 | rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, len); |
| 315 | mbuf->data_len = len; |
| 316 | } else { |
| 317 | /* Try read jumbo frame into multi mbufs. */ |
| 318 | if (unlikely(eth_pcap_rx_jumbo(pcap_q->mb_pool, |
| 319 | mbuf, packet, len) == -1)) { |
| 320 | pcap_q->rx_stat.err_pkts++; |
| 321 | rte_pktmbuf_free(mbuf); |
| 322 | break; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | mbuf->pkt_len = len; |
| 327 | uint64_t us = (uint64_t)header->ts.tv_sec * US_PER_S + header->ts.tv_usec; |
| 328 | |
| 329 | *RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, rte_mbuf_timestamp_t *) = us; |
| 330 | mbuf->ol_flags |= timestamp_rx_dynflag; |
no test coverage detected