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 EB600429EB; Tue, 25 Apr 2023 15:15:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 80EEA42BD9; Tue, 25 Apr 2023 15:15:47 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 3A5EA40ED6 for ; Tue, 25 Apr 2023 15:15:45 +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 33P9EsIB013403; Tue, 25 Apr 2023 06:15:44 -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=kYaAUYukWWxpoCw8YaCNyyjV5/HmP1gHgvjR6Ww37UI=; b=QzcBrhkX/82xsWNLkyunAZ1TdntVxmgkiJevMLIFzxcBH8GiVcd9yCr8Rp2MTNxK6gBL N0f7rnZqHiZLKjr/HVWb24gkdjLOXtH4IRuN5ct8qF6x08CwFauc0y99/YgrQ8sjdR9p eCfH2AzZurQkrIJNqwF2Qeh6bSoPsWIeqPV2fJfDGZjT4ZB9MSrGl1L5DZdy9WedZk+r R03zS+ltdmGHYkPIyxjWCxTVPEDdAYvMP6ow/a9i244TvPjotzwua6DU1xg3NjYpMjKc eY1n4jcBwB0JsxauMHkFCw57i0ynA2hzEquW/Kh4fPBvld+IfTU7dQ/7Td5hP8GZLDRO ww== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3q6c2f8vq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 25 Apr 2023 06:15:43 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Tue, 25 Apr 2023 06:15:42 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Tue, 25 Apr 2023 06:15:42 -0700 Received: from localhost.localdomain (unknown [10.28.36.156]) by maili.marvell.com (Postfix) with ESMTP id ECDF53F7058; Tue, 25 Apr 2023 06:15:39 -0700 (PDT) From: Vamsi Attunuru To: , , CC: , Subject: [PATCH v2 1/4] node: add pkt punt to kernel node Date: Tue, 25 Apr 2023 06:15:13 -0700 Message-ID: <20230425131516.3308612-2-vattunuru@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230425131516.3308612-1-vattunuru@marvell.com> References: <20230421060245.3136217-1-vattunuru@marvell.com> <20230425131516.3308612-1-vattunuru@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-GUID: hg9jQCOw3HfF_CfqJKQDXZOk0HJoE2-5 X-Proofpoint-ORIG-GUID: hg9jQCOw3HfF_CfqJKQDXZOk0HJoE2-5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-25_05,2023-04-25_01,2023-02-09_01 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 punt the packets to kernel over a raw socket. Signed-off-by: Vamsi Attunuru --- doc/guides/prog_guide/graph_lib.rst | 10 +++ lib/node/meson.build | 1 + lib/node/punt_kernel.c | 125 ++++++++++++++++++++++++++++ lib/node/punt_kernel_priv.h | 36 ++++++++ 4 files changed, 172 insertions(+) diff --git a/doc/guides/prog_guide/graph_lib.rst b/doc/guides/prog_guide/graph_lib.rst index 1cfdc86433..b3b5b14827 100644 --- a/doc/guides/prog_guide/graph_lib.rst +++ b/doc/guides/prog_guide/graph_lib.rst @@ -392,3 +392,13 @@ null ~~~~ This node ignores the set of objects passed to it and reports that all are processed. + +punt_kernel +~~~~~~~~~~~ +This node punts the packets to kernel using a raw socket interface. For sending +the received packets, raw socket uses the packet's destination IP address in +sockaddr_in address structure and node uses ``sendto`` function to send data +on the raw socket. + +Aftering sending the burst of packets to kernel, this node redirects the same +objects to pkt_drop node to free up the packet buffers. diff --git a/lib/node/meson.build b/lib/node/meson.build index dbdf673c86..48c2da73f7 100644 --- a/lib/node/meson.build +++ b/lib/node/meson.build @@ -17,6 +17,7 @@ sources = files( 'null.c', 'pkt_cls.c', 'pkt_drop.c', + 'punt_kernel.c', ) headers = files('rte_node_ip4_api.h', 'rte_node_eth_api.h') # Strict-aliasing rules are violated by uint8_t[] to context size casts. diff --git a/lib/node/punt_kernel.c b/lib/node/punt_kernel.c new file mode 100644 index 0000000000..e5dd15b759 --- /dev/null +++ b/lib/node/punt_kernel.c @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell International Ltd. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "node_private.h" +#include "punt_kernel_priv.h" + +static __rte_always_inline void +punt_kernel_process_mbuf(struct rte_node *node, struct rte_mbuf **mbufs, uint16_t cnt) +{ + punt_kernel_node_ctx_t *ctx = (punt_kernel_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("punt_kernel", "Unable to send packets: %s\n", strerror(errno)); + } +} + +static uint16_t +punt_kernel_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)); + + punt_kernel_process_mbuf(node, pkts, PREFETCH_CNT); + + obj_left -= PREFETCH_CNT; + pkts += PREFETCH_CNT; + } + + while (obj_left > 0) { + punt_kernel_process_mbuf(node, pkts, 1); + + obj_left--; + pkts++; + } + + rte_node_next_stream_move(graph, node, PUNT_KERNEL_NEXT_PKT_DROP); + + return nb_objs; +} + +static int +punt_kernel_node_init(const struct rte_graph *graph __rte_unused, struct rte_node *node) +{ + punt_kernel_node_ctx_t *ctx = (punt_kernel_node_ctx_t *)node->ctx; + + ctx->sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + if (ctx->sock < 0) + node_err("punt_kernel", "Unable to open RAW socket\n"); + + return 0; +} + +static void +punt_kernel_node_fini(const struct rte_graph *graph __rte_unused, struct rte_node *node) +{ + punt_kernel_node_ctx_t *ctx = (punt_kernel_node_ctx_t *)node->ctx; + + if (ctx->sock >= 0) { + close(ctx->sock); + ctx->sock = -1; + } +} + +static struct rte_node_register punt_kernel_node_base = { + .process = punt_kernel_node_process, + .name = "punt_kernel", + + .init = punt_kernel_node_init, + .fini = punt_kernel_node_fini, + + .nb_edges = PUNT_KERNEL_NEXT_MAX, + .next_nodes = { + [PUNT_KERNEL_NEXT_PKT_DROP] = "pkt_drop", + }, +}; + +struct rte_node_register * +punt_kernel_node_get(void) +{ + return &punt_kernel_node_base; +} + +RTE_NODE_REGISTER(punt_kernel_node_base); diff --git a/lib/node/punt_kernel_priv.h b/lib/node/punt_kernel_priv.h new file mode 100644 index 0000000000..25ba2072e7 --- /dev/null +++ b/lib/node/punt_kernel_priv.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2023 Marvell International Ltd. + */ + +#ifndef __INCLUDE_PUNT_KERNEL_PRIV_H__ +#define __INCLUDE_PUNT_KERNEL_PRIV_H__ + +struct punt_kernel_node_elem; +struct punt_kernel_node_ctx; +typedef struct punt_kernel_node_elem punt_kernel_node_elem_t; + +/** + * @internal + * + * PUNT Kernel node context structure. + */ +typedef struct punt_kernel_node_ctx { + int sock; +} punt_kernel_node_ctx_t; + +enum punt_kernel_next_nodes { + PUNT_KERNEL_NEXT_PKT_DROP, + PUNT_KERNEL_NEXT_MAX, +}; + +/** + * @internal + * + * Get the PUNT Kernel node. + * + * @return + * Pointer to the PUNT Kernel node. + */ +struct rte_node_register *punt_kernel_node_get(void); + +#endif /* __INCLUDE_PUNT_KERNEL_PRIV_H__ */ -- 2.25.1