From patchwork Thu Oct 19 17:30:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil Kumar Kori X-Patchwork-Id: 133024 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 24DCB431B0; Thu, 19 Oct 2023 19:31:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 48E0242DF2; Thu, 19 Oct 2023 19:30:37 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id F1FE242DE6 for ; Thu, 19 Oct 2023 19:30:33 +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 39JCXquM008133 for ; Thu, 19 Oct 2023 10:30:33 -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=4juaL9QmmG+C/Qz3+YSXNDs7m7OigePsjGqLH0a0skc=; b=UtrC84pt0dA2UTDBnExW4ad6rUr+lN4a7aXRRGPkyDIwypvLG0k1toeGBh8hcKcrjWa/ GJLQwPN8IAJVw7raNU+CaslNoOUrQg8UJb5S1OkSYaJSbNCoZgFEfn/oTGCkO1dguOmv Dy2We7Bx+Bji0RkV0QU44sx5YtAg0rGAU7MFj/KniWzp0nE4zjcw/nx51mX+Zp1ViROu tBGjEbpcy/19JFXW/z7xEni//gD136RgT8i8mCT6/4MBIkgjfecjjJJrCIs8RT/O5wng 8q2CWhjWksxlvZK7UcXNpGF2wqJIwYbBwwxxudH2QLQwynbDbWkAVKVmmzR1GaFMgohK cw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3ttshubs6m-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 19 Oct 2023 10:30:32 -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; Thu, 19 Oct 2023 10:30:30 -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; Thu, 19 Oct 2023 10:30:30 -0700 Received: from localhost.localdomain (unknown [10.28.34.25]) by maili.marvell.com (Postfix) with ESMTP id A2D703F703F; Thu, 19 Oct 2023 10:30:29 -0700 (PDT) From: To: Sunil Kumar Kori , Rakesh Kudurumalla CC: Subject: [PATCH v11 07/12] app/graph: support IPv6 lookup command line interfaces Date: Thu, 19 Oct 2023 23:00:06 +0530 Message-ID: <20231019173011.1186656-8-skori@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231019173011.1186656-1-skori@marvell.com> References: <20231019105000.520914-13-skori@marvell.com> <20231019173011.1186656-1-skori@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 3nhUxzGU-a7Bhm3Zq8p2UiGdxqgMJ4Ll X-Proofpoint-ORIG-GUID: 3nhUxzGU-a7Bhm3Zq8p2UiGdxqgMJ4Ll X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_16,2023-10-19_01,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 From: Rakesh Kudurumalla Adds ipv6_lookup module to configure LPM6 table. This LPM6 table will be used for IPv6 lookup and forwarding. Following commands are exposed: - ipv6_lookup route add ipv6 netmask via - help ipv6_lookup Signed-off-by: Sunil Kumar Kori Signed-off-by: Rakesh Kudurumalla Acked-By: Nithin Dabilpuram --- app/graph/cli.c | 2 + app/graph/ethdev.c | 1 + app/graph/ip6_route.c | 226 +++++++++++++++++++++++++++++++++++++ app/graph/meson.build | 1 + app/graph/route.h | 14 +++ doc/guides/tools/graph.rst | 9 ++ 6 files changed, 253 insertions(+) create mode 100644 app/graph/ip6_route.c diff --git a/app/graph/cli.c b/app/graph/cli.c index 25785ea4dc..1280422388 100644 --- a/app/graph/cli.c +++ b/app/graph/cli.c @@ -32,6 +32,8 @@ cmdline_parse_ctx_t modules_ctx[] = { (cmdline_parse_inst_t *)ðdev_help_cmd_ctx, (cmdline_parse_inst_t *)&ipv4_lookup_cmd_ctx, (cmdline_parse_inst_t *)&ipv4_lookup_help_cmd_ctx, + (cmdline_parse_inst_t *)&ipv6_lookup_cmd_ctx, + (cmdline_parse_inst_t *)&ipv6_lookup_help_cmd_ctx, NULL, }; diff --git a/app/graph/ethdev.c b/app/graph/ethdev.c index 4e4d23b692..e3f9ee3e0c 100644 --- a/app/graph/ethdev.c +++ b/app/graph/ethdev.c @@ -165,6 +165,7 @@ ethdev_stop(void) ethdev_list_clean(); route_ip4_list_clean(); + route_ip6_list_clean(); printf("Bye...\n"); } diff --git a/app/graph/ip6_route.c b/app/graph/ip6_route.c new file mode 100644 index 0000000000..e793cde830 --- /dev/null +++ b/app/graph/ip6_route.c @@ -0,0 +1,226 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 Marvell. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "module_api.h" +#include "route_priv.h" + +static const char +cmd_ipv6_lookup_help[] = "ipv6_lookup route add ipv6 netmask via "; + +struct ip6_route route6 = TAILQ_HEAD_INITIALIZER(route6); + +void +route_ip6_list_clean(void) +{ + struct route_ipv6_config *route; + + while (!TAILQ_EMPTY(&route6)) { + route = TAILQ_FIRST(&route6); + TAILQ_REMOVE(&route6, route, next); + } +} + +static struct route_ipv6_config * +find_route6_entry(struct route_ipv6_config *route) +{ + struct route_ipv6_config *ipv6route; + + TAILQ_FOREACH(ipv6route, &route6, next) { + if (!memcmp(ipv6route, route, sizeof(*route))) + return ipv6route; + } + return NULL; +} + +static uint8_t +convert_ip6_netmask_to_depth(uint8_t *netmask) +{ + uint8_t setbits = 0; + uint8_t mask; + int i; + + for (i = 0; i < ETHDEV_IPV6_ADDR_LEN; i++) { + mask = netmask[i]; + while (mask & 0x80) { + mask = mask << 1; + setbits++; + } + } + + return setbits; +} + +static int +route6_rewirte_table_update(struct route_ipv6_config *ipv6route) +{ + uint8_t depth; + int portid; + + portid = ethdev_portid_by_ip6(ipv6route->gateway, ipv6route->mask); + if (portid < 0) { + printf("Invalid portid found to install the route\n"); + return portid; + } + depth = convert_ip6_netmask_to_depth(ipv6route->mask); + + return rte_node_ip6_route_add(ipv6route->ip, depth, portid, + RTE_NODE_IP6_LOOKUP_NEXT_REWRITE); + +} + +static int +route_ip6_add(struct route_ipv6_config *route) +{ + struct route_ipv6_config *ipv6route; + int rc = -EINVAL; + int j; + + ipv6route = find_route6_entry(route); + if (!ipv6route) { + ipv6route = malloc(sizeof(struct route_ipv6_config)); + if (!ipv6route) + return -ENOMEM; + } else { + return 0; + } + + for (j = 0; j < ETHDEV_IPV6_ADDR_LEN; j++) { + ipv6route->ip[j] = route->ip[j]; + ipv6route->mask[j] = route->mask[j]; + ipv6route->gateway[j] = route->gateway[j]; + } + ipv6route->is_used = true; + + /* FIXME: Get graph status here and then update table */ + rc = route6_rewirte_table_update(ipv6route); + if (rc) + goto free; + + TAILQ_INSERT_TAIL(&route6, ipv6route, next); + return 0; +free: + free(ipv6route); + return rc; +} + +int +route_ip6_add_to_lookup(void) +{ + struct route_ipv6_config *route = NULL; + int rc = -EINVAL; + + TAILQ_FOREACH(route, &route6, next) { + rc = route6_rewirte_table_update(route); + if (rc < 0) + return rc; + } + + return 0; +} + +static void +cli_ipv6_lookup_help(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + size_t len; + + len = strlen(conn->msg_out); + conn->msg_out += len; + snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n", + "--------------------------- ipv6_lookup command help ---------------------------", + cmd_ipv6_lookup_help); + + len = strlen(conn->msg_out); + conn->msg_out_len_max -= len; +} + +static void +cli_ipv6_lookup(void *parsed_result, __rte_unused struct cmdline *cl, void *data __rte_unused) +{ + struct ip6_lookup_cmd_tokens *res = parsed_result; + struct route_ipv6_config config; + int rc = -EINVAL; + + if (parser_ip6_read(config.ip, res->ip)) { + printf(MSG_ARG_INVALID, "ipv6"); + return; + } + + if (parser_ip6_read(config.mask, res->mask)) { + printf(MSG_ARG_INVALID, "netmask"); + return; + } + + if (parser_ip6_read(config.gateway, res->via_ip)) { + printf(MSG_ARG_INVALID, "gateway ip"); + return; + } + + rc = route_ip6_add(&config); + if (rc) + printf(MSG_CMD_FAIL, res->cmd); +} + +cmdline_parse_token_string_t ip6_lookup_cmd = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, cmd, "ipv6_lookup"); +cmdline_parse_token_string_t ip6_lookup_route = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, route, "route"); +cmdline_parse_token_string_t ip6_lookup_add = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, add, "add"); +cmdline_parse_token_string_t ip6_lookup_ip6 = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, ip6, "ipv6"); +cmdline_parse_token_string_t ip6_lookup_ip = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, ip, NULL); +cmdline_parse_token_string_t ip6_lookup_netmask = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, netmask, "netmask"); +cmdline_parse_token_string_t ip6_lookup_mask = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, mask, NULL); +cmdline_parse_token_string_t ip6_lookup_via = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, via, "via"); +cmdline_parse_token_string_t ip6_lookup_via_ip = + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, via_ip, NULL); + +cmdline_parse_inst_t ipv6_lookup_cmd_ctx = { + .f = cli_ipv6_lookup, + .data = NULL, + .help_str = cmd_ipv6_lookup_help, + .tokens = { + (void *)&ip6_lookup_cmd, + (void *)&ip6_lookup_route, + (void *)&ip6_lookup_add, + (void *)&ip6_lookup_ip6, + (void *)&ip6_lookup_ip, + (void *)&ip6_lookup_netmask, + (void *)&ip6_lookup_mask, + (void *)&ip6_lookup_via, + (void *)&ip6_lookup_via_ip, + NULL, + }, +}; + +cmdline_parse_token_string_t ipv6_lookup_help_cmd = + TOKEN_STRING_INITIALIZER(struct ipv6_lookup_help_cmd_tokens, cmd, "help"); +cmdline_parse_token_string_t ipv6_lookup_help_module = + TOKEN_STRING_INITIALIZER(struct ipv6_lookup_help_cmd_tokens, module, "ipv6_lookup"); + +cmdline_parse_inst_t ipv6_lookup_help_cmd_ctx = { + .f = cli_ipv6_lookup_help, + .data = NULL, + .help_str = "", + .tokens = { + (void *)&ipv6_lookup_help_cmd, + (void *)&ipv6_lookup_help_module, + NULL, + }, +}; diff --git a/app/graph/meson.build b/app/graph/meson.build index 1f35f82583..413bbefc4e 100644 --- a/app/graph/meson.build +++ b/app/graph/meson.build @@ -14,6 +14,7 @@ sources = files( 'conn.c', 'ethdev.c', 'ip4_route.c', + 'ip6_route.c', 'main.c', 'mempool.c', 'utils.c', diff --git a/app/graph/route.h b/app/graph/route.h index a44d401d55..0d271d1350 100644 --- a/app/graph/route.h +++ b/app/graph/route.h @@ -8,7 +8,9 @@ #define MAX_ROUTE_ENTRIES 32 extern cmdline_parse_inst_t ipv4_lookup_cmd_ctx; +extern cmdline_parse_inst_t ipv6_lookup_cmd_ctx; extern cmdline_parse_inst_t ipv4_lookup_help_cmd_ctx; +extern cmdline_parse_inst_t ipv6_lookup_help_cmd_ctx; struct route_ipv4_config { TAILQ_ENTRY(route_ipv4_config) next; @@ -20,7 +22,19 @@ struct route_ipv4_config { TAILQ_HEAD(ip4_route, route_ipv4_config); +struct route_ipv6_config { + TAILQ_ENTRY(route_ipv6_config) next; + uint8_t ip[16]; + uint8_t mask[16]; + uint8_t gateway[16]; + bool is_used; +}; + +TAILQ_HEAD(ip6_route, route_ipv6_config); + int route_ip4_add_to_lookup(void); +int route_ip6_add_to_lookup(void); void route_ip4_list_clean(void); +void route_ip6_list_clean(void); #endif diff --git a/doc/guides/tools/graph.rst b/doc/guides/tools/graph.rst index 7530ef6f65..56c2eaad26 100644 --- a/doc/guides/tools/graph.rst +++ b/doc/guides/tools/graph.rst @@ -121,6 +121,15 @@ file to express the requested use case configuration. | help ipv4_lookup | | Command to dump ``ipv4_lookup`` | Yes | Yes | | | | help message. | | | +--------------------------------------+-----------------------------------+---------+----------+ + | | ipv6_lookup route add ipv6 | | Command to add a route into | Yes | Yes | + | | netmask via | | ``ipv6_lookup`` LPM table. It is| | | + | | | needed if user wishes to route | | | + | | | the packets based on LPM6 lookup| | | + | | | table. | | | + +--------------------------------------+-----------------------------------+---------+----------+ + | help ipv6_lookup | | Command to dump ``ipv6_lookup`` | Yes | Yes | + | | | help message. | | | + +--------------------------------------+-----------------------------------+---------+----------+ Runtime configuration ---------------------