Adds a public function to add IP6 route to FIB. The applications should
call this function to add IP6 routes to FIB.
Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
---
lib/node/ip6_lookup_fib.c | 34 ++++++++++++++++++++++++++++++++++
lib/node/rte_node_ip6_api.h | 19 +++++++++++++++++++
2 files changed, 53 insertions(+)
@@ -2,6 +2,9 @@
* Copyright(C) 2025 Marvell.
*/
+#include <arpa/inet.h>
+
+#include <eal_export.h>
#include <rte_errno.h>
#include <rte_ether.h>
#include <rte_fib6.h>
@@ -37,6 +40,37 @@ static struct ip6_lookup_fib_node_main ip6_lookup_fib_nm;
#define IP6_LOOKUP_FIB_NODE_PRIV1_OFF(ctx) \
(((struct ip6_lookup_fib_node_ctx *)ctx)->mbuf_priv1_off)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_node_ip6_fib_route_add, 25.07)
+int
+rte_node_ip6_fib_route_add(const struct rte_ipv6_addr *ip, uint8_t depth, uint16_t next_hop,
+ enum rte_node_ip6_lookup_next next_node)
+{
+ char abuf[INET6_ADDRSTRLEN];
+ uint8_t socket;
+ uint32_t val;
+ int ret;
+
+ inet_ntop(AF_INET6, ip, abuf, sizeof(abuf));
+ /* Embedded next node id into 24 bit next hop */
+ val = ((next_node << 16) | next_hop) & ((1ull << 24) - 1);
+ node_dbg("ip6_lookup_fib", "FIB6: Adding route %s / %d nh (0x%x)", abuf, depth, val);
+
+ for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) {
+ if (!ip6_lookup_fib_nm.fib6[socket])
+ continue;
+
+ ret = rte_fib6_add(ip6_lookup_fib_nm.fib6[socket], ip, depth, val);
+ if (ret < 0) {
+ node_err("ip6_lookup_fib",
+ "Unable to add entry %s / %d nh (%x) to FIB on sock %d, rc=%d",
+ abuf, depth, val, socket, ret);
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
static int
setup_fib6(unsigned int socket)
{
@@ -71,6 +71,25 @@ __rte_experimental
int rte_node_ip6_rewrite_add(uint16_t next_hop, uint8_t *rewrite_data,
uint8_t rewrite_len, uint16_t dst_port);
+/**
+ * Add IPv6 route to FIB.
+ *
+ * @param ip
+ * IPv6 address of route to be added.
+ * @param depth
+ * Depth of the rule to be added.
+ * @param next_hop
+ * Next hop id of the rule result to be added.
+ * @param next_node
+ * Next node to redirect traffic to.
+ *
+ * @return
+ * 0 on success, negative otherwise.
+ */
+__rte_experimental
+int rte_node_ip6_fib_route_add(const struct rte_ipv6_addr *ip, uint8_t depth, uint16_t next_hop,
+ enum rte_node_ip6_lookup_next next_node);
+
#ifdef __cplusplus
}
#endif