From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0E70742C11; Fri, 2 Jun 2023 18:22:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DBD0242D35; Fri, 2 Jun 2023 18:22:33 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 81B1B42D31 for ; Fri, 2 Jun 2023 18:22:32 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 352A1oka026966; Fri, 2 Jun 2023 09:22:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=JRW8tzjkBHECVW600jU0pTw+Sj6UocKuwurx/kJvo3k=; b=KqwozQG4wFMVdxOMEUGhaLPc9KWAgX+6NDBTcaZuiGZlXmF24Yswsd2iFRyF3+jGtflQ NdaV2drle+OYWsyn0UqJ2o0mgdP4LAB4XHegvtGFhzwWZFJIS7Z7nD2wwHt0jOPB+iMS 3bzKehvMuDL3zisIawjQr5jNRNrhD//pOoA7d0GmMCZR/LHgFr8eRKOenaJNycwd19B9 EuU9Ume/kc6MsCIWu8RQj9gVBh+0ult41861nCxCQDIIAnofGiBbTt+dvwoa1gE+lcwZ bCwx43l1xdaVV9gyTVonaMwndRfB/N+cYy9IhBvznHA17RQyiQ0CWXevPiXl9wLmIbzA uw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qy3uykfvu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 02 Jun 2023 09:22:31 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 2 Jun 2023 09:22:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 2 Jun 2023 09:22:29 -0700 Received: from localhost.localdomain (unknown [10.28.36.156]) by maili.marvell.com (Postfix) with ESMTP id CA0733F7061; Fri, 2 Jun 2023 09:22:27 -0700 (PDT) From: Vamsi Attunuru To: , , CC: , , Subject: [PATCH v3 1/3] node/kernel_tx: support packet transmit to kernel Date: Fri, 2 Jun 2023 09:22:14 -0700 Message-ID: <20230602162216.1868870-2-vattunuru@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230602162216.1868870-1-vattunuru@marvell.com> References: <20230425131516.3308612-1-vattunuru@marvell.com> <20230602162216.1868870-1-vattunuru@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: jWrL6i4EQ3hual9TkKekqVQjLk7TV2da X-Proofpoint-ORIG-GUID: jWrL6i4EQ3hual9TkKekqVQjLk7TV2da X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-02_12,2023-06-02_02,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Patch adds a node to transmit the packets to kernel over a raw socket. Signed-off-by: Vamsi Attunuru --- doc/guides/prog_guide/graph_lib.rst | 9 ++ lib/node/kernel_tx.c | 122 ++++++++++++++++++++++++++++ lib/node/kernel_tx_priv.h | 16 ++++ lib/node/meson.build | 1 + 4 files changed, 148 insertions(+) diff --git a/doc/guides/prog_guide/graph_lib.rst b/doc/guides/prog_guide/graph_lib.rst index 1cfdc86433..fa22b014f3 100644 --- a/doc/guides/prog_guide/graph_lib.rst +++ b/doc/guides/prog_guide/graph_lib.rst @@ -392,3 +392,12 @@ null ~~~~ This node ignores the set of objects passed to it and reports that all are processed. + +kernel_tx +~~~~~~~~~ +This node is an exit node that forwards the packets to kernel. It will be used +to forward any control plane traffic to kernel stack from DPDK. It uses a raw +socket interface to transmit the packets, it uses the packet's destination +IP address in sockaddr_in address structure and ``sendto`` function to send +data on the raw socket. Aftering sending the burst of packets to kernel, +this node free up the packet buffers. diff --git a/lib/node/kernel_tx.c b/lib/node/kernel_tx.c new file mode 100644 index 0000000000..27d1808c71 --- /dev/null +++ b/lib/node/kernel_tx.c @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell International Ltd. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kernel_tx_priv.h" +#include "node_private.h" + +static __rte_always_inline void +kernel_tx_process_mbuf(struct rte_node *node, struct rte_mbuf **mbufs, uint16_t cnt) +{ + kernel_tx_node_ctx_t *ctx = (kernel_tx_node_ctx_t *)node->ctx; + struct sockaddr_in sin = {0}; + struct rte_ipv4_hdr *ip4; + size_t len; + char *buf; + int i; + + for (i = 0; i < cnt; i++) { + ip4 = rte_pktmbuf_mtod(mbufs[i], struct rte_ipv4_hdr *); + len = rte_pktmbuf_data_len(mbufs[i]); + buf = (char *)ip4; + + sin.sin_family = AF_INET; + sin.sin_port = 0; + sin.sin_addr.s_addr = ip4->dst_addr; + + if (sendto(ctx->sock, buf, len, 0, (struct sockaddr *)&sin, sizeof(sin)) < 0) + node_err("kernel_tx", "Unable to send packets: %s\n", strerror(errno)); + } +} + +static uint16_t +kernel_tx_node_process(struct rte_graph *graph __rte_unused, struct rte_node *node, void **objs, + uint16_t nb_objs) +{ + struct rte_mbuf **pkts = (struct rte_mbuf **)objs; + uint16_t obj_left = nb_objs; + +#define PREFETCH_CNT 4 + + while (obj_left >= 12) { + /* Prefetch next-next mbufs */ + rte_prefetch0(pkts[8]); + rte_prefetch0(pkts[9]); + rte_prefetch0(pkts[10]); + rte_prefetch0(pkts[11]); + + /* Prefetch next mbuf data */ + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[4], void *, pkts[4]->l2_len)); + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[5], void *, pkts[5]->l2_len)); + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[6], void *, pkts[6]->l2_len)); + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[7], void *, pkts[7]->l2_len)); + + kernel_tx_process_mbuf(node, pkts, PREFETCH_CNT); + + obj_left -= PREFETCH_CNT; + pkts += PREFETCH_CNT; + } + + while (obj_left > 0) { + kernel_tx_process_mbuf(node, pkts, 1); + + obj_left--; + pkts++; + } + + rte_pktmbuf_free_bulk((struct rte_mbuf **)objs, nb_objs); + + return nb_objs; +} + +static int +kernel_tx_node_init(const struct rte_graph *graph __rte_unused, struct rte_node *node) +{ + kernel_tx_node_ctx_t *ctx = (kernel_tx_node_ctx_t *)node->ctx; + + ctx->sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + if (ctx->sock < 0) + node_err("kernel_tx", "Unable to open RAW socket\n"); + + return 0; +} + +static void +kernel_tx_node_fini(const struct rte_graph *graph __rte_unused, struct rte_node *node) +{ + kernel_tx_node_ctx_t *ctx = (kernel_tx_node_ctx_t *)node->ctx; + + if (ctx->sock >= 0) { + close(ctx->sock); + ctx->sock = -1; + } +} + +static struct rte_node_register kernel_tx_node_base = { + .process = kernel_tx_node_process, + .name = "kernel_tx", + + .init = kernel_tx_node_init, + .fini = kernel_tx_node_fini, + + .nb_edges = 0, +}; + +struct rte_node_register * +kernel_tx_node_get(void) +{ + return &kernel_tx_node_base; +} + +RTE_NODE_REGISTER(kernel_tx_node_base); diff --git a/lib/node/kernel_tx_priv.h b/lib/node/kernel_tx_priv.h new file mode 100644 index 0000000000..6fd8a4f2af --- /dev/null +++ b/lib/node/kernel_tx_priv.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell International Ltd. + */ + +#ifndef __KERNEL_TX_PRIV_H__ +#define __KERNEL_TX_PRIV_H__ + +/* kernel_tx node context structure. */ +typedef struct kernel_tx_node_ctx { + int sock; +} kernel_tx_node_ctx_t; + +/* Get the pointer to kernel_tx node register structure */ +struct rte_node_register *kernel_tx_node_get(void); + +#endif /* __KERNEL_TX_PRIV_H__ */ diff --git a/lib/node/meson.build b/lib/node/meson.build index dbdf673c86..0520be23ff 100644 --- a/lib/node/meson.build +++ b/lib/node/meson.build @@ -13,6 +13,7 @@ sources = files( 'ethdev_tx.c', 'ip4_lookup.c', 'ip4_rewrite.c', + 'kernel_tx.c', 'log.c', 'null.c', 'pkt_cls.c', -- 2.25.1