From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id BEEAFA2EEB for ; Mon, 7 Oct 2019 18:53:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6718B1D17B; Mon, 7 Oct 2019 18:52:54 +0200 (CEST) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by dpdk.org (Postfix) with ESMTP id 82FBD1D159 for ; Mon, 7 Oct 2019 18:52:48 +0200 (CEST) Received: by mail-pf1-f196.google.com with SMTP id q10so9061010pfl.0 for ; Mon, 07 Oct 2019 09:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D7Ut9NY4CduPcybFFv1BswwflFn1DEn/bwr+5SzR2iw=; b=WbMnGBi+Moyc4GoqJLd77ZTKlQ9b4qylua0AcKiCFFZXkleF6UcZyPjavC70u/yO9d AwA4/M+3p+IMDFPN7J3FE7uMFg2ufwlc+J67K2Cr8323YLhfWaSzUW12bEJILKZ/FPD2 as1qgadQw8+Fsa7l4v/hWIWfpxwDAUoaTwbvt84gLE0AsPoa4Hgh5OKAHEZbefGq7iYn NRYts+gWym0P8zhlDgprhJbro1SAifrxYL9PajvtgzW01jlhjoR6he4PBrx1Msz0m3Yb Q6nSGKHKWih0VKHSflZ8EDGVSDzyRIWJG3gM3Rl5DyVsPHoy9wlY4GN0Nx7HYULDW6Nk J+eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D7Ut9NY4CduPcybFFv1BswwflFn1DEn/bwr+5SzR2iw=; b=CZCKHWtvb7t7SnPLkR8itYp6MNbj+0UOF/hj3da2IQ0YcTcldkyiwX/EnScFGbeDES LhOVb1yKo6rfO9tw1wAHk7nd+a9naCqxWGr58bu+KlCJR1h+ft0BpElixXcdfh37BmIl 1b/TagglqlD5c+2E/z7aoO2+cW1rpYpMp2U+xCmYbupq+JV3KqzHWAVWUvF6G8ix3B/R Be44KZzLGLQ0FRCogCufSXccrApXhu2tczNskbvxJaJwVcmoCUrlNj265xIYoR8W73/i ER1LjyjDVWkFYt52EL01CRXyNyGdDzPFN2bWhGl+YxaLQJbl7obJ7OjeNWHbWuUI5E04 8r6g== X-Gm-Message-State: APjAAAWgZDmeDSU7ekWnjHW5dkQ20vvsA+OfrWcipLvArpl6zLyN6rVJ szYgK8qBCKKw4T/kWtBjBLy2oiiVJZKgBA== X-Google-Smtp-Source: APXvYqxoTaV24QkYoCX4v24/f0kk5iCnUxVFfKxborrstRvhH1bDobFTuB/aR4+y1vFK+YXI6C4U7A== X-Received: by 2002:aa7:8edd:: with SMTP id b29mr354205pfr.138.1570467167192; Mon, 07 Oct 2019 09:52:47 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id w5sm15920979pfn.96.2019.10.07.09.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 09:52:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 7 Oct 2019 09:52:30 -0700 Message-Id: <20191007165232.14535-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191007165232.14535-1-stephen@networkplumber.org> References: <20191007165232.14535-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [RFC 6/8] pdump: add packet header truncation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add support for pcap style header truncation (called snap length). This optimizes packet capture by not copying the whole packet. Since API is already versioned (in previous patch), it is ok to add one new argument for the length. Signed-off-by: Stephen Hemminger --- app/pdump/main.c | 16 ++++++------- app/test/test_pdump.c | 6 +++-- lib/librte_pdump/rte_pdump.c | 46 +++++++++++++++++++++++------------- lib/librte_pdump/rte_pdump.h | 29 ++++++++++++++--------- 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/app/pdump/main.c b/app/pdump/main.c index c3eb554ef28b..e55a94c0f10e 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -825,45 +825,45 @@ enable_pdump(void) if (pt->dump_by_type == DEVICE_ID) { ret = rte_pdump_enable_by_deviceid( pt->device_id, - pt->queue, + pt->queue, UINT16_MAX, RTE_PDUMP_FLAG_RX, pt->rx_ring, pt->mp, NULL, 0); ret1 = rte_pdump_enable_by_deviceid( pt->device_id, - pt->queue, + pt->queue, UINT16_MAX, RTE_PDUMP_FLAG_TX, pt->tx_ring, pt->mp, NULL, 0); } else if (pt->dump_by_type == PORT_ID) { ret = rte_pdump_enable(pt->port, pt->queue, - RTE_PDUMP_FLAG_RX, + UINT16_MAX, RTE_PDUMP_FLAG_RX, pt->rx_ring, pt->mp, NULL, 0); ret1 = rte_pdump_enable(pt->port, pt->queue, - RTE_PDUMP_FLAG_TX, + UINT16_MAX, RTE_PDUMP_FLAG_TX, pt->tx_ring, pt->mp, NULL, 0); } } else if (pt->dir == RTE_PDUMP_FLAG_RX) { if (pt->dump_by_type == DEVICE_ID) ret = rte_pdump_enable_by_deviceid( pt->device_id, - pt->queue, + pt->queue, UINT16_MAX, pt->dir, pt->rx_ring, pt->mp, NULL, 0); else if (pt->dump_by_type == PORT_ID) ret = rte_pdump_enable(pt->port, pt->queue, - pt->dir, + UINT16_MAX, pt->dir, pt->rx_ring, pt->mp, NULL, 0); } else if (pt->dir == RTE_PDUMP_FLAG_TX) { if (pt->dump_by_type == DEVICE_ID) ret = rte_pdump_enable_by_deviceid( pt->device_id, - pt->queue, + pt->queue, UINT16_MAX, pt->dir, pt->tx_ring, pt->mp, NULL, 0); else if (pt->dump_by_type == PORT_ID) ret = rte_pdump_enable(pt->port, pt->queue, - pt->dir, + UINT16_MAX, pt->dir, pt->tx_ring, pt->mp, NULL, 0); } if (ret < 0 || ret1 < 0) { diff --git a/app/test/test_pdump.c b/app/test/test_pdump.c index f0187a4cd279..c2468b968247 100644 --- a/app/test/test_pdump.c +++ b/app/test/test_pdump.c @@ -78,7 +78,8 @@ run_pdump_client_tests(void) printf("\n***** flags = RTE_PDUMP_FLAG_TX *****\n"); for (itr = 0; itr < NUM_ITR; itr++) { - ret = rte_pdump_enable(portid, QUEUE_ID, flags, ring_client, + ret = rte_pdump_enable(portid, QUEUE_ID, flags, + UINT16_MAX, ring_client, mp, NULL, 0); if (ret < 0) { printf("rte_pdump_enable failed\n"); @@ -93,7 +94,8 @@ run_pdump_client_tests(void) } printf("pdump_disable success\n"); - ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, flags, + ret = rte_pdump_enable_by_deviceid(deviceid, QUEUE_ID, + flags, UINT16_MAX, ring_client, mp, NULL, 0); if (ret < 0) { printf("rte_pdump_enable_by_deviceid failed\n"); diff --git a/lib/librte_pdump/rte_pdump.c b/lib/librte_pdump/rte_pdump.c index 1206671c6f60..c3636bcdd029 100644 --- a/lib/librte_pdump/rte_pdump.c +++ b/lib/librte_pdump/rte_pdump.c @@ -44,6 +44,7 @@ struct pdump_request { struct enable_v1 { char device[DEVICE_ID_SIZE]; uint16_t queue; + uint16_t snaplen; struct rte_ring *ring; struct rte_mempool *mp; const void *filter; @@ -51,6 +52,7 @@ struct pdump_request { struct disable_v1 { char device[DEVICE_ID_SIZE]; uint16_t queue; + uint16_t snaplen; struct rte_ring *ring; struct rte_mempool *mp; const void *filter; @@ -69,6 +71,7 @@ static struct pdump_rxtx_cbs { struct rte_mempool *mp; const struct rte_eth_rxtx_callback *cb; const void *filter; + uint16_t snaplen; } rx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT], tx_cbs[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT]; @@ -93,7 +96,7 @@ pdump_copy(uint16_t port, struct rte_mbuf **pkts, if (rte_pcap_filter(cbs->filter, pkts[i]) == 0) continue; - p = rte_pktmbuf_copy(pkts[i], mp, 0, UINT32_MAX); + p = rte_pktmbuf_copy(pkts[i], mp, 0, cbs->snaplen); if (p) { p->port = port; p->timestamp = now; @@ -132,7 +135,8 @@ pdump_tx(uint16_t port, uint16_t qidx __rte_unused, static int pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue, struct rte_ring *ring, struct rte_mempool *mp, - uint16_t operation, const void *filter) + uint16_t operation, uint16_t snaplen, + const void *filter) { uint16_t qid; struct pdump_rxtx_cbs *cbs = NULL; @@ -151,6 +155,7 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue, cbs->ring = ring; cbs->mp = mp; cbs->filter = filter; + cbs->snaplen = snaplen; cbs->cb = rte_eth_add_first_rx_callback(port, qid, pdump_rx, cbs); if (cbs->cb == NULL) { @@ -187,7 +192,8 @@ pdump_register_rx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue, static int pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue, struct rte_ring *ring, struct rte_mempool *mp, - uint16_t operation, const void *filter) + uint16_t operation, uint16_t snaplen, + const void *filter) { uint16_t qid; @@ -207,6 +213,7 @@ pdump_register_tx_callbacks(uint16_t end_q, uint16_t port, uint16_t queue, cbs->ring = ring; cbs->mp = mp; cbs->filter = filter; + cbs->snaplen = snaplen; cbs->cb = rte_eth_add_tx_callback(port, qid, pdump_tx, cbs); if (cbs->cb == NULL) { @@ -244,7 +251,7 @@ static int set_pdump_rxtx_cbs(const struct pdump_request *p) { uint16_t nb_rx_q = 0, nb_tx_q = 0, end_q, queue; - uint16_t port; + uint16_t port, snaplen = 0; int ret = 0; uint32_t flags; uint16_t operation; @@ -266,6 +273,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) queue = p->data.en_v1.queue; ring = p->data.en_v1.ring; mp = p->data.en_v1.mp; + snaplen = p->data.en_v1.snaplen; filter = p->data.en_v1.filter; } else { ret = rte_eth_dev_get_port_by_name(p->data.dis_v1.device, @@ -310,7 +318,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) if (flags & RTE_PDUMP_FLAG_RX) { end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_rx_q : queue + 1; ret = pdump_register_rx_callbacks(end_q, port, queue, ring, mp, - operation, filter); + operation, snaplen, filter); if (ret < 0) return ret; } @@ -319,7 +327,7 @@ set_pdump_rxtx_cbs(const struct pdump_request *p) if (flags & RTE_PDUMP_FLAG_TX) { end_q = (queue == RTE_PDUMP_ALL_QUEUES) ? nb_tx_q : queue + 1; ret = pdump_register_tx_callbacks(end_q, port, queue, ring, mp, - operation, filter); + operation, snaplen, filter); if (ret < 0) return ret; } @@ -465,7 +473,7 @@ pdump_validate_filter(const void *filter, unsigned int len) static int pdump_prepare_client_request(const char *device, uint16_t queue, - uint32_t flags, + uint32_t flags, uint16_t snaplen, uint16_t operation, struct rte_ring *ring, struct rte_mempool *mp, @@ -485,6 +493,7 @@ pdump_prepare_client_request(const char *device, uint16_t queue, strlcpy(req->data.en_v1.device, device, sizeof(req->data.en_v1.device)); req->data.en_v1.queue = queue; + req->data.en_v1.snaplen = snaplen; req->data.en_v1.ring = ring; req->data.en_v1.mp = mp; req->data.en_v1.filter = filter; @@ -492,6 +501,7 @@ pdump_prepare_client_request(const char *device, uint16_t queue, strlcpy(req->data.dis_v1.device, device, sizeof(req->data.dis_v1.device)); req->data.dis_v1.queue = queue; + req->data.en_v1.snaplen = snaplen; req->data.dis_v1.ring = NULL; req->data.dis_v1.mp = NULL; req->data.dis_v1.filter = NULL; @@ -517,6 +527,7 @@ pdump_prepare_client_request(const char *device, uint16_t queue, int rte_pdump_enable_v1911(uint16_t port, uint16_t queue, uint32_t flags, + uint16_t snap_len, struct rte_ring *ring, struct rte_mempool *mp, const void *filter, uint32_t filter_len) { @@ -537,14 +548,15 @@ rte_pdump_enable_v1911(uint16_t port, uint16_t queue, uint32_t flags, if (ret < 0) return ret; - ret = pdump_prepare_client_request(name, queue, flags, + ret = pdump_prepare_client_request(name, queue, flags, snap_len, ENABLE, ring, mp, filter); return ret; } BIND_DEFAULT_SYMBOL(rte_pdump_enable, _v1911, 19.11); MAP_STATIC_SYMBOL(int rte_pdump_enable(uint16_t port, uint16_t queue, - uint32_t flags, struct rte_ring *ring, + uint32_t flags, uint16_t snap_len, + struct rte_ring *ring, struct rte_mempool *mp, const void *filter, uint32_t len), rte_pdump_enable_v1911); @@ -558,14 +570,14 @@ rte_pdump_enable_v1607(uint16_t port, uint16_t queue, uint32_t flags, if (filter != NULL) PDUMP_LOG(WARNING, "filter not supported in this version\n"); - return rte_pdump_enable_v1911(port, queue, flags, ring, mp, - NULL, 0); + return rte_pdump_enable_v1911(port, queue, flags, UINT16_MAX, + ring, mp, NULL, 0); } VERSION_SYMBOL(rte_pdump_enable, _v1607, 16.07); int rte_pdump_enable_by_deviceid_v1911(const char *device_id, uint16_t queue, - uint32_t flags, + uint32_t flags, uint16_t snap_len, struct rte_ring *ring, struct rte_mempool *mp, const void *filter, uint32_t filter_len) @@ -582,7 +594,7 @@ rte_pdump_enable_by_deviceid_v1911(const char *device_id, uint16_t queue, if (ret < 0) return ret; - ret = pdump_prepare_client_request(device_id, queue, flags, + ret = pdump_prepare_client_request(device_id, queue, flags, snap_len, ENABLE, ring, mp, filter); return ret; @@ -591,6 +603,7 @@ BIND_DEFAULT_SYMBOL(rte_pdump_enable_by_deviceid, _v1911, 19.11); MAP_STATIC_SYMBOL(int rte_pdump_enable_by_deviceid(const char *device_id, uint16_t queue, uint32_t flags, + uint16_t snap_len, struct rte_ring *ring, struct rte_mempool *mp, const void *filter, @@ -607,7 +620,8 @@ rte_pdump_enable_by_deviceid_v1607(char *device_id, uint16_t queue, if (filter != NULL) PDUMP_LOG(WARNING, "filter not supported in this version\n"); - return rte_pdump_enable_by_deviceid_v1911(device_id, queue, flags, + return rte_pdump_enable_by_deviceid_v1911(device_id, queue, + flags, UINT16_MAX, ring, mp, NULL, 0); } VERSION_SYMBOL(rte_pdump_enable_by_deviceid, _v1607, 16.07); @@ -625,7 +639,7 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags) if (ret < 0) return ret; - ret = pdump_prepare_client_request(name, queue, flags, + ret = pdump_prepare_client_request(name, queue, flags, 0, DISABLE, NULL, NULL, NULL); return ret; @@ -641,7 +655,7 @@ rte_pdump_disable_by_deviceid(char *device_id, uint16_t queue, if (ret < 0) return ret; - ret = pdump_prepare_client_request(device_id, queue, flags, + ret = pdump_prepare_client_request(device_id, queue, flags, 0, DISABLE, NULL, NULL, NULL); return ret; diff --git a/lib/librte_pdump/rte_pdump.h b/lib/librte_pdump/rte_pdump.h index 12cb46f8b0e9..e04ef4c1933b 100644 --- a/lib/librte_pdump/rte_pdump.h +++ b/lib/librte_pdump/rte_pdump.h @@ -63,13 +63,15 @@ rte_pdump_uninit(void); * @param flags * flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX * on which packet capturing should be enabled for a given port and queue. + * @param snap_len + * only the first snap_len bytes of packet will be captured. * @param ring * ring on which captured packets will be enqueued for user. * @param mp - * mempool on to which original packets will be mirrored or duplicated. + * mempool on to which original packets will be duplicated. * @param filter * filter to apply to incoming packet (classic BPF) - * @param len + * @param filter_len * length of filter (in BPF instructions) * * @return @@ -77,15 +79,17 @@ rte_pdump_uninit(void); */ int rte_pdump_enable(uint16_t port, uint16_t queue, uint32_t flags, - struct rte_ring *ring, struct rte_mempool *mp, - const void *filter, uint32_t len); + uint16_t snap_len, struct rte_ring *ring, + struct rte_mempool *mp, + const void *filter, uint32_t filter_len); int rte_pdump_enable_v1607(uint16_t port, uint16_t queue, uint32_t flags, struct rte_ring *ring, struct rte_mempool *mp, void *filter); int rte_pdump_enable_v1911(uint16_t port, uint16_t queue, uint32_t flags, - struct rte_ring *ring, struct rte_mempool *mp, + uint16_t snap_len, struct rte_ring *ring, + struct rte_mempool *mp, const void *filter, uint32_t len); /** @@ -121,13 +125,15 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags); * @param flags * flags specifies RTE_PDUMP_FLAG_RX/RTE_PDUMP_FLAG_TX/RTE_PDUMP_FLAG_RXTX * on which packet capturing should be enabled for a given port and queue. + * @param snap_len + * only the first snap_len bytes of packet will be captured. * @param ring * ring on which captured packets will be enqueued for user. * @param mp - * mempool on to which original packets will be mirrored or duplicated. + * mempool on to which original packets will be duplicated. * @param filter * filter to apply to incoming packet (classic BPF) - * @param len + * @param filter_len * length of filter (in BPF instructions) * * @return @@ -135,10 +141,10 @@ rte_pdump_disable(uint16_t port, uint16_t queue, uint32_t flags); */ int rte_pdump_enable_by_deviceid(const char *device_id, uint16_t queue, - uint32_t flags, + uint32_t flags, uint16_t snap_len, struct rte_ring *ring, struct rte_mempool *mp, - const void *filter, uint32_t len); + const void *filter, uint32_t filter_len); int rte_pdump_enable_by_deviceid_v1607(char *device_id, uint16_t queue, uint32_t flags, struct rte_ring *ring, @@ -146,9 +152,10 @@ rte_pdump_enable_by_deviceid_v1607(char *device_id, uint16_t queue, void *filter); int rte_pdump_enable_by_deviceid_v1911(const char *device_id, uint16_t queue, - uint32_t flags, struct rte_ring *ring, + uint32_t flags, uint16_t snap_len, + struct rte_ring *ring, struct rte_mempool *mp, - const void *filter, uint32_t len); + const void *filter, uint32_t filter_len); /** * Disables packet capturing on given device_id and queue. -- 2.20.1