DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ankur Dwivedi <adwivedi@marvell.com>
To: <dev@dpdk.org>
Cc: <jerinj@marvell.com>, <vladimir.medvedkin@intel.com>,
	<ndabilpuram@marvell.com>, <pbhagavatula@marvell.com>,
	<skori@marvell.com>, <rkudurumalla@marvell.com>,
	Ankur Dwivedi <adwivedi@marvell.com>
Subject: [PATCH v1 08/12] node: add IP6 lookup FIB node
Date: Tue, 15 Apr 2025 17:40:48 +0530	[thread overview]
Message-ID: <20250415121052.1497155-9-adwivedi@marvell.com> (raw)
In-Reply-To: <20250415121052.1497155-1-adwivedi@marvell.com>

Adds a lookup FIB node for IP6.

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
---
 lib/node/ip6_lookup_fib.c | 124 ++++++++++++++++++++++++++++++++++++++
 lib/node/meson.build      |   1 +
 2 files changed, 125 insertions(+)
 create mode 100644 lib/node/ip6_lookup_fib.c

diff --git a/lib/node/ip6_lookup_fib.c b/lib/node/ip6_lookup_fib.c
new file mode 100644
index 0000000000..317cb53d7b
--- /dev/null
+++ b/lib/node/ip6_lookup_fib.c
@@ -0,0 +1,124 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2025 Marvell.
+ */
+
+#include <rte_errno.h>
+#include <rte_ether.h>
+#include <rte_fib6.h>
+#include <rte_graph.h>
+#include <rte_graph_worker.h>
+#include <rte_ip.h>
+
+#include "rte_node_ip6_api.h"
+
+#include "node_private.h"
+
+/* IP6 Lookup FIB global data struct */
+struct ip6_lookup_fib_node_main {
+	struct rte_fib6 *fib6[RTE_MAX_NUMA_NODES];
+};
+
+struct ip6_lookup_fib_node_ctx {
+	/* Socket's FIB6 */
+	struct rte_fib6 *fib6;
+	/* Dynamic offset to mbuf priv1 */
+	int mbuf_priv1_off;
+};
+
+static struct ip6_lookup_fib_node_main ip6_lookup_fib_nm;
+
+#define FIB6_MAX_ROUTES (1 << 16)
+#define FIB6_NUM_TBL8   (1 << 15)
+#define FIB6_DEFAULT_NH 999
+
+#define IP6_LOOKUP_FIB_NODE(ctx) \
+	(((struct ip6_lookup_fib_node_ctx *)ctx)->fib6)
+
+#define IP6_LOOKUP_FIB_NODE_PRIV1_OFF(ctx) \
+	(((struct ip6_lookup_fib_node_ctx *)ctx)->mbuf_priv1_off)
+
+static int
+setup_fib6(unsigned int socket)
+{
+	struct ip6_lookup_fib_node_main *nm = &ip6_lookup_fib_nm;
+	struct rte_fib6_conf conf;
+	char s[RTE_FIB6_NAMESIZE];
+
+	/* One fib6 per socket */
+	if (nm->fib6[socket])
+		return 0;
+
+	conf.type = RTE_FIB6_TRIE;
+	conf.default_nh = FIB6_DEFAULT_NH;
+	conf.max_routes = FIB6_MAX_ROUTES;
+	conf.rib_ext_sz = 0;
+	conf.trie.nh_sz = RTE_FIB6_TRIE_4B;
+	conf.trie.num_tbl8 = FIB6_NUM_TBL8;
+	snprintf(s, sizeof(s), "IPV6_LOOKUP_FIB_%u", socket);
+	nm->fib6[socket] = rte_fib6_create(s, socket, &conf);
+	if (nm->fib6[socket] == NULL)
+		return -rte_errno;
+
+	return 0;
+}
+
+static int
+ip6_lookup_fib_node_init(const struct rte_graph *graph, struct rte_node *node)
+{
+	static uint8_t init_once;
+	unsigned int socket;
+	uint16_t lcore_id;
+	int rc;
+
+	RTE_BUILD_BUG_ON(sizeof(struct ip6_lookup_fib_node_ctx) > RTE_NODE_CTX_SZ);
+
+	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+
+		/* Setup FIB6 for all sockets */
+		RTE_LCORE_FOREACH(lcore_id)
+		{
+			socket = rte_lcore_to_socket_id(lcore_id);
+			rc = setup_fib6(socket);
+			if (rc) {
+				node_err("ip6_lookup_fib",
+					 "Failed to setup fib6 for sock %u, rc=%d", socket, rc);
+				return rc;
+			}
+		}
+		init_once = 1;
+	}
+
+	/* Update socket's FIB and mbuf dyn priv1 offset in node ctx */
+	IP6_LOOKUP_FIB_NODE(node->ctx) = ip6_lookup_fib_nm.fib6[graph->socket];
+	IP6_LOOKUP_FIB_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;
+
+	node_dbg("ip6_lookup_fib", "Initialized ip6_lookup_fib node");
+
+	return 0;
+}
+
+static struct rte_node_xstats ip6_lookup_fib_xstats = {
+	.nb_xstats = 1,
+	.xstat_desc = {
+		[0] = "ip6_lookup_fib_error",
+	},
+};
+
+static struct rte_node_register ip6_lookup_fib_node = {
+	.name = "ip6_lookup_fib",
+
+	.init = ip6_lookup_fib_node_init,
+	.xstats = &ip6_lookup_fib_xstats,
+
+	.nb_edges = RTE_NODE_IP6_LOOKUP_NEXT_PKT_DROP + 1,
+	.next_nodes = {
+		[RTE_NODE_IP6_LOOKUP_NEXT_REWRITE] = "ip6_rewrite",
+		[RTE_NODE_IP6_LOOKUP_NEXT_PKT_DROP] = "pkt_drop",
+	},
+};
+
+RTE_NODE_REGISTER(ip6_lookup_fib_node);
diff --git a/lib/node/meson.build b/lib/node/meson.build
index d2011c8f56..70216a1a69 100644
--- a/lib/node/meson.build
+++ b/lib/node/meson.build
@@ -17,6 +17,7 @@ sources = files(
         'ip4_reassembly.c',
         'ip4_rewrite.c',
         'ip6_lookup.c',
+        'ip6_lookup_fib.c',
         'ip6_rewrite.c',
         'kernel_rx.c',
         'kernel_tx.c',
-- 
2.25.1


  parent reply	other threads:[~2025-04-15 12:12 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 12:10 [PATCH v1 00/12] add lookup fib nodes in graph library Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 01/12] fib: move macro to header file Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 02/12] node: add IP4 lookup FIB node Ankur Dwivedi
2025-04-16  7:32   ` Nitin Saxena
2025-04-16 10:26     ` [EXTERNAL] " Ankur Dwivedi
2025-04-16  9:34   ` Medvedkin, Vladimir
2025-04-16 10:07     ` [EXTERNAL] " Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 03/12] node: add IP4 FIB route add Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 04/12] node: add process callback for IP4 FIB Ankur Dwivedi
2025-04-16  7:54   ` Nitin Saxena
2025-04-16 12:54   ` Medvedkin, Vladimir
2025-04-18  7:38     ` [EXTERNAL] " Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 05/12] node: add next node in packet classification Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 06/12] app/graph: add IP4 lookup mode command Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 07/12] fib: move macro to header file Ankur Dwivedi
2025-04-15 12:10 ` Ankur Dwivedi [this message]
2025-04-15 12:10 ` [PATCH v1 09/12] node: add IP6 FIB route add Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 10/12] node: add process callback for IP6 FIB Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 11/12] node: add next node in packet classification Ankur Dwivedi
2025-04-15 12:10 ` [PATCH v1 12/12] app/graph: add IP6 lookup mode command Ankur Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250415121052.1497155-9-adwivedi@marvell.com \
    --to=adwivedi@marvell.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=ndabilpuram@marvell.com \
    --cc=pbhagavatula@marvell.com \
    --cc=rkudurumalla@marvell.com \
    --cc=skori@marvell.com \
    --cc=vladimir.medvedkin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).