MCPcopy Create free account
hub / github.com/F-Stack/f-stack / pcap_source_load

Function pcap_source_load

dpdk/lib/port/rte_port_source_sink.c:50–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48#ifdef RTE_PORT_PCAP
49
50static int
51pcap_source_load(struct rte_port_source *port,
52 const char *file_name,
53 uint32_t n_bytes_per_pkt,
54 int socket_id)
55{
56 uint32_t n_pkts = 0;
57 uint32_t i;
58 uint32_t *pkt_len_aligns = NULL;
59 size_t total_buff_len = 0;
60 pcap_t *pcap_handle;
61 char pcap_errbuf[PCAP_ERRBUF_SIZE];
62 uint32_t max_len;
63 struct pcap_pkthdr pcap_hdr;
64 const uint8_t *pkt;
65 uint8_t *buff = NULL;
66 uint32_t pktmbuf_maxlen = (uint32_t)
67 (rte_pktmbuf_data_room_size(port->mempool) -
68 RTE_PKTMBUF_HEADROOM);
69
70 if (n_bytes_per_pkt == 0)
71 max_len = pktmbuf_maxlen;
72 else
73 max_len = RTE_MIN(n_bytes_per_pkt, pktmbuf_maxlen);
74
75 /* first time open, get packet number */
76 pcap_handle = pcap_open_offline(file_name, pcap_errbuf);
77 if (pcap_handle == NULL) {
78 RTE_LOG(ERR, PORT, "Failed to open pcap file "
79 "'%s' for reading\n", file_name);
80 goto error_exit;
81 }
82
83 while ((pkt = pcap_next(pcap_handle, &pcap_hdr)) != NULL)
84 n_pkts++;
85
86 pcap_close(pcap_handle);
87
88 port->pkt_len = rte_zmalloc_socket("PCAP",
89 (sizeof(*port->pkt_len) * n_pkts), 0, socket_id);
90 if (port->pkt_len == NULL) {
91 RTE_LOG(ERR, PORT, "No enough memory\n");
92 goto error_exit;
93 }
94
95 pkt_len_aligns = rte_malloc("PCAP",
96 (sizeof(*pkt_len_aligns) * n_pkts), 0);
97 if (pkt_len_aligns == NULL) {
98 RTE_LOG(ERR, PORT, "No enough memory\n");
99 goto error_exit;
100 }
101
102 port->pkts = rte_zmalloc_socket("PCAP",
103 (sizeof(*port->pkts) * n_pkts), 0, socket_id);
104 if (port->pkts == NULL) {
105 RTE_LOG(ERR, PORT, "No enough memory\n");
106 goto error_exit;
107 }

Callers

nothing calls this directly

Calls 5

rte_zmalloc_socketFunction · 0.85
rte_mallocFunction · 0.85
rte_freeFunction · 0.85
rte_memcpyFunction · 0.50

Tested by

no test coverage detected