summaryrefslogtreecommitdiff
path: root/tools/tcpdump
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2023-03-24 08:44:32 +0000
committersongyanchao <[email protected]>2023-03-24 08:44:32 +0000
commit9cc7f2559cbdf988fca44b4262c458c8f3483c22 (patch)
tree9b6532fe98915b7eacb8e9bd25b10f021a1c629d /tools/tcpdump
parent041df0559e0cc2b89bc49590e37f6c25ca9e9c59 (diff)
🐞 fix: 修复mrpdum在使用I350网卡时产生段错误问题
修复mrpdum在使用I350网卡时产生段错误问题
Diffstat (limited to 'tools/tcpdump')
-rw-r--r--tools/tcpdump/pdump.c89
1 files changed, 63 insertions, 26 deletions
diff --git a/tools/tcpdump/pdump.c b/tools/tcpdump/pdump.c
index 09bd559..1c948c2 100644
--- a/tools/tcpdump/pdump.c
+++ b/tools/tcpdump/pdump.c
@@ -57,6 +57,7 @@
#include <rte_ethdev.h>
#include <rte_kvargs.h>
#include <rte_lcore.h>
+#include <rte_malloc.h>
#include <rte_memory.h>
#include <rte_mempool.h>
#include <rte_pcapng.h>
@@ -192,7 +193,6 @@ static uint16_t port_index[MR_DEVICE_MAX] = {};
/* Pcapng */
static int pcapng_fd = 0;
-static rte_pcapng_t * _pcapng_item = NULL;
/**< display usage */
static void pdump_usage(const char * prgname)
@@ -267,7 +267,7 @@ static int parse_uint_value(const char * key, const char * value, void * extra_a
static int parse_device_name(const char * key __rte_unused, const char * value, void * extra_args)
{
struct pdump_tuples * pt = &pdump_t[num_tuples];
- memcpy(pt->dev_symbol, strdup(value), sizeof(pt->dev_symbol));
+ strlcpy(pt->dev_symbol, value, sizeof(pt->dev_symbol));
return 0;
}
@@ -640,6 +640,10 @@ static inline void pdump_rxtx(uint16_t port_id, struct rte_ring * ring, struct p
/* First dequeue packets from ring of primary process */
struct rte_mbuf * rxtx_bufs[BURST_SIZE];
const uint16_t nb_in_deq = rte_ring_dequeue_burst(ring, (void *)rxtx_bufs, BURST_SIZE, NULL);
+ if (nb_in_deq == 0)
+ return;
+
+ /* Updage stats */
stats->dequeue_pkts += nb_in_deq;
int iovcnt = mbuf_burst_segs(rxtx_bufs, nb_in_deq);
struct iovec iov[iovcnt];
@@ -672,7 +676,8 @@ static inline void pdump_rxtx(uint16_t port_id, struct rte_ring * ring, struct p
}
/* Write pkt */
- writev(pcapng_fd, iov, iovcnt);
+ if (writev(pcapng_fd, iov, iovcnt) <= 0)
+ perror("pcapng write error");
/* Pkt free */
for (int i = 0; i < nb_in_deq; i++)
@@ -733,6 +738,9 @@ static void err_value_dump(int32_t err_value)
case MR_PDUMP_ERR_FOR_MEMPOOL_FREE:
fprintf(stderr, "Message err info : Mempool free err.\n");
break;
+ case MR_PDUMP_ERR_FOR_PCAPNG_CREATE:
+ fprintf(stderr, "Message err info : Pcapng file create err.\n");
+ break;
}
}
@@ -1010,36 +1018,50 @@ static inline void dump_packets(void)
}
}
-static char * get_os_info(void)
+static inline void create_pcap_dumper()
{
- struct utsname uts;
- char * osname = NULL;
-
- if (uname(&uts) < 0)
- return NULL;
+ struct rte_mp_msg mp_req = {};
+ struct mr_pdump_request * req = (struct mr_pdump_request *)mp_req.param;
- if (asprintf(&osname, "%s %s", uts.sysname, uts.release) == -1)
- return NULL;
+ /* malloc msg dumpfile path,mrzcpd free this memory */
+ char * msg_dumpfile_path = rte_zmalloc(NULL, PATH_MAX, 0);
+ if (msg_dumpfile_path == NULL)
+ {
+ rte_exit(EXIT_FAILURE, "dumpfile path zmalloc err.\n");
+ }
- return osname;
-}
+ /* Fill request struct */
+ memset(req, 0, sizeof(*req));
+ memcpy(msg_dumpfile_path, dumpfile_path, sizeof(dumpfile_path));
+ req->op = CREATE_PCAPNG;
+ req->dumpfile_path = msg_dumpfile_path;
+
+ /* Fill request name */
+ rte_strscpy(mp_req.name, MR_PDUMP_MP, RTE_MP_MAX_NAME_LEN);
+ mp_req.len_param = sizeof(*req);
+ mp_req.num_fds = 0;
+
+ /* Send request and wait reply */
+ struct rte_mp_reply mp_reply = {};
+ struct timespec ts = {.tv_sec = 20, .tv_nsec = 0};
+ if (rte_mp_request_sync(&mp_req, &mp_reply, &ts) != 0)
+ {
+ rte_exit(EXIT_FAILURE, "create:%s send request faill.\n", dumpfile_path);
+ }
-static inline void create_pcap_dumper()
-{
- /* Save PCI devices */
- uint16_t port_id = 0;
- RTE_ETH_FOREACH_DEV(port_id)
+ /* Deal reply */
+ struct rte_mp_msg * mp_rep = &mp_reply.msgs[0];
+ struct mr_pdump_response * resp = (struct mr_pdump_response *)mp_rep->param;
+ if (resp->err_value != MR_PDUMP_SUCESS)
{
- /* The list if ports in pcapng needs to be contiguous */
- port_index[port_id] = interface_index++;
+ /* Dump error info */
+ err_value_dump(resp->err_value);
+ free(mp_reply.msgs);
+ rte_exit(EXIT_FAILURE, "create:%s err.\n", dumpfile_path);
}
- /* Create pcapng file */
- pcapng_fd = open(dumpfile_path, O_WRONLY | O_CREAT, 0640);
- char * os = get_os_info();
- _pcapng_item = rte_pcapng_fdopen(pcapng_fd, os, NULL, "Mrpdump v1.0", NULL);
- if (_pcapng_item == NULL)
- rte_exit(EXIT_FAILURE, "Cannot open pcap dumper for %s\n", dumpfile_path);
+ /* Save fd */
+ pcapng_fd = mp_rep->fds[0];
/* Set bpf */
if (is_str_bpf_expr_set)
@@ -1051,6 +1073,14 @@ static inline void create_pcap_dumper()
}
}
+ /* Save PCI devices */
+ uint16_t port_id = 0;
+ RTE_ETH_FOREACH_DEV(port_id)
+ {
+ /* The list if ports in pcapng needs to be contiguous */
+ port_index[port_id] = interface_index++;
+ }
+
return;
}
@@ -1085,6 +1115,13 @@ int main(int argc, char ** argv)
argc -= diag;
argv += (diag - 3);
+ /* get default dumpfile path */
+ static char default_dir[PATH_MAX];
+ if (getcwd(default_dir, sizeof(default_dir)) == NULL)
+ rte_exit(EXIT_FAILURE, "Get dumpfile path faill\n");
+
+ snprintf(dumpfile_path, sizeof(dumpfile_path), "%s/dumpfile.pcapng", default_dir);
+
/* parse app arguments */
if (argc > 1)
{