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 9A758431DE; Mon, 23 Oct 2023 09:05:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8A34740A7F; Mon, 23 Oct 2023 09:05:12 +0200 (CEST) Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by mails.dpdk.org (Postfix) with ESMTP id 7311440647 for ; Mon, 23 Oct 2023 09:05:10 +0200 (CEST) Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-41cd6e1d4fbso16165941cf.1 for ; Mon, 23 Oct 2023 00:05:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698044710; x=1698649510; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=k95Rx+jDGiGSDR7QBLJ55NtxEf54Y9CxxlyJVAbGsp4=; b=GOZbKWdNbzyX4uNt6pGM76DhAz8IAEp91ZMNleSt43osQ6R8bF2VuqeM2fEnIB7QtL 2S2cqez8p3wF3NFyAbN/efwFqaPYZmVSdOjQz8lY+r2BlVepVLiVmw0xCjarW/f4U1U7 wbvEVHVUe9y1WezgX0CgZK2oqUfKneV0VRgeYXmBaSASDwSJYAzvckhxq2LjuRmkl+eB m2Yo+zb+rjtuPJXVU0JqxFwdRnbnj9RoBT07icQHCYWwBcajfYX3fV2c8RGZXCYvtQfO WZJDHXYrxaeAR31PYByPJwNPsFo+qZlv7eA92yuPhFk7KTiC/ayr+J8L4nqc6psvvGP3 i3cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698044710; x=1698649510; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k95Rx+jDGiGSDR7QBLJ55NtxEf54Y9CxxlyJVAbGsp4=; b=VtiTMeIfoJoBtEEsm3UsDmbbzOI9TA2AUceZWwMyyXEjHV2R5U+/PsJ4neC6QJ6fJr s7qzy9sMI8UeeYb3c+O5ZgAU1AA5EGdfRQK/UVc0Fc7wiUW6LdvPCcuYE60LAm4TO26b qU0Uk2vQCK0DqjwCf/8Uf4QqW8LBfSr+5nG82orBDPp6c82bdvPMDqP/uUdoFThuZ2/e OKJvb2BiQa9gqCkXRzy+nPrxu6KkpAhRy8dQFk6GqwI/dTaxmXKTal0a7jmcVjB0hKcp jvGaGLp2ywNt05BxuhHZJTnb6ePKhi7x0a5GZjfJulQmzXd9GCP7rAvBq65sTFDoPB95 sVTA== X-Gm-Message-State: AOJu0YwCZ6hNybpRP6e+wrz/ag64U43YSLS9iRHD7HftQuuHvYiROK/r 8ISR400UA7rCsokoRSqDfmtkTJ0MUnIGgULbnCXZov3RCaQ= X-Google-Smtp-Source: AGHT+IFT6VEa74eYG2PhlCmYmeLkFiF5bND2OJhi4D1s2dKXLYYzm+EllWuIzTB41OkNXBm+1Kq5OuLtMqpvbEajWmg= X-Received: by 2002:a05:622a:589:b0:41c:be07:c6c7 with SMTP id c9-20020a05622a058900b0041cbe07c6c7mr7423066qtb.24.1698044709764; Mon, 23 Oct 2023 00:05:09 -0700 (PDT) MIME-Version: 1.0 References: <20231019105000.520914-13-skori@marvell.com> <20231019173011.1186656-1-skori@marvell.com> <20231019173011.1186656-8-skori@marvell.com> In-Reply-To: <20231019173011.1186656-8-skori@marvell.com> From: Nithin Dabilpuram Date: Mon, 23 Oct 2023 12:34:57 +0530 Message-ID: Subject: Re: [PATCH v11 07/12] app/graph: support IPv6 lookup command line interfaces To: skori@marvell.com Cc: Rakesh Kudurumalla , dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Acked-By: Nithin Dabilpuram On Fri, Oct 20, 2023 at 2:37=E2=80=AFAM wrote: > > 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 > --- > 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[] =3D { > (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[] =3D "ipv6_lookup route add ipv6 netmask via "; > + > +struct ip6_route route6 =3D TAILQ_HEAD_INITIALIZER(route6); > + > +void > +route_ip6_list_clean(void) > +{ > + struct route_ipv6_config *route; > + > + while (!TAILQ_EMPTY(&route6)) { > + route =3D 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 =3D 0; > + uint8_t mask; > + int i; > + > + for (i =3D 0; i < ETHDEV_IPV6_ADDR_LEN; i++) { > + mask =3D netmask[i]; > + while (mask & 0x80) { > + mask =3D mask << 1; > + setbits++; > + } > + } > + > + return setbits; > +} > + > +static int > +route6_rewirte_table_update(struct route_ipv6_config *ipv6route) > +{ > + uint8_t depth; > + int portid; > + > + portid =3D ethdev_portid_by_ip6(ipv6route->gateway, ipv6route->ma= sk); > + if (portid < 0) { > + printf("Invalid portid found to install the route\n"); > + return portid; > + } > + depth =3D 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 =3D -EINVAL; > + int j; > + > + ipv6route =3D find_route6_entry(route); > + if (!ipv6route) { > + ipv6route =3D malloc(sizeof(struct route_ipv6_config)); > + if (!ipv6route) > + return -ENOMEM; > + } else { > + return 0; > + } > + > + for (j =3D 0; j < ETHDEV_IPV6_ADDR_LEN; j++) { > + ipv6route->ip[j] =3D route->ip[j]; > + ipv6route->mask[j] =3D route->mask[j]; > + ipv6route->gateway[j] =3D route->gateway[j]; > + } > + ipv6route->is_used =3D true; > + > + /* FIXME: Get graph status here and then update table */ > + rc =3D 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 =3D NULL; > + int rc =3D -EINVAL; > + > + TAILQ_FOREACH(route, &route6, next) { > + rc =3D 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 stru= ct cmdline *cl, > + __rte_unused void *data) > +{ > + size_t len; > + > + len =3D strlen(conn->msg_out); > + conn->msg_out +=3D len; > + snprintf(conn->msg_out, conn->msg_out_len_max, "\n%s\n%s\n", > + "--------------------------- ipv6_lookup command help --= -------------------------", > + cmd_ipv6_lookup_help); > + > + len =3D strlen(conn->msg_out); > + conn->msg_out_len_max -=3D len; > +} > + > +static void > +cli_ipv6_lookup(void *parsed_result, __rte_unused struct cmdline *cl, vo= id *data __rte_unused) > +{ > + struct ip6_lookup_cmd_tokens *res =3D parsed_result; > + struct route_ipv6_config config; > + int rc =3D -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 =3D route_ip6_add(&config); > + if (rc) > + printf(MSG_CMD_FAIL, res->cmd); > +} > + > +cmdline_parse_token_string_t ip6_lookup_cmd =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, cmd, "ipv6= _lookup"); > +cmdline_parse_token_string_t ip6_lookup_route =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, route, "ro= ute"); > +cmdline_parse_token_string_t ip6_lookup_add =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, add, "add"= ); > +cmdline_parse_token_string_t ip6_lookup_ip6 =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, ip6, "ipv6= "); > +cmdline_parse_token_string_t ip6_lookup_ip =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, ip, NULL); > +cmdline_parse_token_string_t ip6_lookup_netmask =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, netmask, "= netmask"); > +cmdline_parse_token_string_t ip6_lookup_mask =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, mask, NULL= ); > +cmdline_parse_token_string_t ip6_lookup_via =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, via, "via"= ); > +cmdline_parse_token_string_t ip6_lookup_via_ip =3D > + TOKEN_STRING_INITIALIZER(struct ip6_lookup_cmd_tokens, via_ip, NU= LL); > + > +cmdline_parse_inst_t ipv6_lookup_cmd_ctx =3D { > + .f =3D cli_ipv6_lookup, > + .data =3D NULL, > + .help_str =3D cmd_ipv6_lookup_help, > + .tokens =3D { > + (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 =3D > + TOKEN_STRING_INITIALIZER(struct ipv6_lookup_help_cmd_tokens, cmd,= "help"); > +cmdline_parse_token_string_t ipv6_lookup_help_module =3D > + TOKEN_STRING_INITIALIZER(struct ipv6_lookup_help_cmd_tokens, modu= le, "ipv6_lookup"); > + > +cmdline_parse_inst_t ipv6_lookup_help_cmd_ctx =3D { > + .f =3D cli_ipv6_lookup_help, > + .data =3D NULL, > + .help_str =3D "", > + .tokens =3D { > + (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 =3D 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_loo= kup`` | Yes | Yes | > | | | help message. = | | | > +--------------------------------------+-----------------------------= ------+---------+----------+ > + | | ipv6_lookup route add ipv6 | | Command to add a route int= o | Yes | Yes | > + | | netmask via | | ``ipv6_lookup`` LPM table.= It is| | | > + | | | needed if user wishes to r= oute | | | > + | | | the packets based on LPM6 = lookup| | | > + | | | table. = | | | > + +--------------------------------------+-----------------------------= ------+---------+----------+ > + | help ipv6_lookup | | Command to dump ``ipv6_loo= kup`` | Yes | Yes | > + | | | help message. = | | | > + +--------------------------------------+-----------------------------= ------+---------+----------+ > > Runtime configuration > --------------------- > -- > 2.25.1 >