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 75EBD42C3C; Tue, 6 Jun 2023 08:14:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 63ECB40A84; Tue, 6 Jun 2023 08:14:14 +0200 (CEST) Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by mails.dpdk.org (Postfix) with ESMTP id D5F7A406B7 for ; Tue, 6 Jun 2023 08:14:12 +0200 (CEST) Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-3f86a7f3a65so25177441cf.0 for ; Mon, 05 Jun 2023 23:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686032052; x=1688624052; 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=h/fECEJby3u/qhdsC1OKdiqRmVjVJkzlPdu/7ChekJ0=; b=GUpVuaznYmxEuZk6AqEmtB/l21/5mmvcd5QTHz/33iJEECHdhJ8zl/Afsg5/46N6Ik QP8X7M8kDkQn461CrjGRZBkdDsuTnD6gI/srQfE5oVxeew4Nn5WvPFpSdCK97/LbW40t S+RxW4jwomGd+mAV7MYbNPWlvtvfTFpvLlNJP8qd/+0BTeuAR/dMBsIYei7i1hdXEfvb +zzRVXKWnR4Sl1IgE9EoVHVC01eGuMRobgNw45wQBSUtrfUfGDCXjiYLJDat8sQc0BqD /NpTfQQuzSI2xThfcEzCGCnsknzrZyqzRgCdC9iDLxRVnA2mFrAv0yO12c9dm3n6uCL1 uuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686032052; x=1688624052; 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=h/fECEJby3u/qhdsC1OKdiqRmVjVJkzlPdu/7ChekJ0=; b=cSHA/NWRM87CkeLmnrk5bdZKs9/KqX4ZwRdE44kGlhHyMNyNKy4F8I+CVUGVqZHUqF PqXsP5RQ/Djebm+9aZWsgj215RLwExEbHvPlGKNMWp17844r8K6QcG/EYmeVnsaB/arD /79s7MvqfQ04TZG0qlpSLAJnt4VJYOSIlRTJFzXQsq8IJoXum8nz6KashmgJy7WIZnVy QMoFxTfkM2Lc8W0iBFtghdj/vQ2mr2y4J8YYjQ30QYNi4QUzuKXshQ22qRwJRuORaq1o 95BjcyEAf/SwmpIp8G4JIU3BLN0NClbecBQ68ZHLaRRCJGen5GkV7gXGLpMqBF+b0SN9 H73w== X-Gm-Message-State: AC+VfDwkkv07UDpwMd6jZqXIWy4LnjaS8SgKyDSvD0/0tNJtmc2BYOXD oN6OQP1SKwr+fz2dLV/R3ImxZ3wJlvBZgFe4O0MOXih1+90= X-Google-Smtp-Source: ACHHUZ6CYJbCSNOwS0TwL4BS8qqAcTO7CARS3Ifk85HDE8xUGnlisBu8btxsuLe296IYojSiByM9gSXjcv5KjidGAME= X-Received: by 2002:ac8:57cb:0:b0:3f8:719e:d9d1 with SMTP id w11-20020ac857cb000000b003f8719ed9d1mr1156671qta.41.1686032052008; Mon, 05 Jun 2023 23:14:12 -0700 (PDT) MIME-Version: 1.0 References: <20230602164840.2295-1-pbhagavatula@marvell.com> <20230605112645.6204-1-pbhagavatula@marvell.com> In-Reply-To: <20230605112645.6204-1-pbhagavatula@marvell.com> From: Nithin Dabilpuram Date: Tue, 6 Jun 2023 11:44:00 +0530 Message-ID: Subject: Re: [PATCH v3] node: add ipv4 reassembly node To: pbhagavatula@marvell.com Cc: jerinj@marvell.com, Kiran Kumar K , Nithin Dabilpuram , 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 On Mon, Jun 5, 2023 at 4:57=E2=80=AFPM wrote: > > From: Pavan Nikhilesh > > Add IPv4 reassembly node. > > Signed-off-by: Pavan Nikhilesh > --- > Depends-on: series-28278 > > v3 Changes: > - Actually include the changes that fix compilation. > v2 Changes: > - Fix compilation. > > doc/guides/prog_guide/graph_lib.rst | 8 ++ > lib/node/ethdev_rx.c | 1 + > lib/node/ethdev_rx_priv.h | 1 + > lib/node/ip4_reassembly.c | 175 ++++++++++++++++++++++++++++ > lib/node/ip4_reassembly_priv.h | 28 +++++ > lib/node/meson.build | 3 +- > lib/node/rte_node_ip4_api.h | 37 ++++++ > lib/node/version.map | 1 + > 8 files changed, 253 insertions(+), 1 deletion(-) > create mode 100644 lib/node/ip4_reassembly.c > create mode 100644 lib/node/ip4_reassembly_priv.h > > diff --git a/doc/guides/prog_guide/graph_lib.rst b/doc/guides/prog_guide/= graph_lib.rst > index 841cabe259..49c470e287 100644 > --- a/doc/guides/prog_guide/graph_lib.rst > +++ b/doc/guides/prog_guide/graph_lib.rst > @@ -388,6 +388,14 @@ to determine the L2 header to be written to the pack= et before sending > the packet out to a particular ethdev_tx node. > ``rte_node_ip4_rewrite_add()`` is control path API to add next-hop info. > > +ip4_reassembly > +~~~~~~~~~~~~~~ > +This node is an intermediate node that reassembles ipv4 fragmented packe= ts, > +non-fragmented packets pass through the node un-effected. The node rewri= tes > +it's stream and moves it to the next node. > +The fragment table and death row table should be setup via the > +``rte_node_ip4_reassembly_configure`` API. > + > ip6_lookup > ~~~~~~~~~~ > This node is an intermediate node that does LPM lookup for the received > diff --git a/lib/node/ethdev_rx.c b/lib/node/ethdev_rx.c > index a19237b42f..6ed2e1834f 100644 > --- a/lib/node/ethdev_rx.c > +++ b/lib/node/ethdev_rx.c > @@ -218,6 +218,7 @@ static struct rte_node_register ethdev_rx_node_base = =3D { > /* Default pkt classification node */ > [ETHDEV_RX_NEXT_PKT_CLS] =3D "pkt_cls", > [ETHDEV_RX_NEXT_IP4_LOOKUP] =3D "ip4_lookup", > + [ETHDEV_RX_NEXT_IP4_REASSEMBLY] =3D "ip4_reassembly", > }, > }; > > diff --git a/lib/node/ethdev_rx_priv.h b/lib/node/ethdev_rx_priv.h > index 7f24cf962e..574a76c2a6 100644 > --- a/lib/node/ethdev_rx_priv.h > +++ b/lib/node/ethdev_rx_priv.h > @@ -39,6 +39,7 @@ struct ethdev_rx_node_elem { > enum ethdev_rx_next_nodes { > ETHDEV_RX_NEXT_IP4_LOOKUP, > ETHDEV_RX_NEXT_PKT_CLS, > + ETHDEV_RX_NEXT_IP4_REASSEMBLY, > ETHDEV_RX_NEXT_MAX, > }; > > diff --git a/lib/node/ip4_reassembly.c b/lib/node/ip4_reassembly.c > new file mode 100644 > index 0000000000..907db111c2 > --- /dev/null > +++ b/lib/node/ip4_reassembly.c > @@ -0,0 +1,175 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell. > + */ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "rte_node_ip4_api.h" > + > +#include "ip4_reassembly_priv.h" > +#include "node_private.h" > + > +struct ip4_reassembly_elem { > + struct ip4_reassembly_elem *next; > + struct ip4_reassembly_ctx ctx; > + rte_node_t node_id; > +}; > + > +/* IP4 reassembly global data struct */ > +struct ip4_reassembly_node_main { > + struct ip4_reassembly_elem *head; > +}; > + > +typedef struct ip4_reassembly_ctx ip4_reassembly_ctx_t; > +typedef struct ip4_reassembly_elem ip4_reassembly_elem_t; > + > +static struct ip4_reassembly_node_main ip4_reassembly_main; > + > +static uint16_t > +ip4_reassembly_node_process(struct rte_graph *graph, struct rte_node *no= de, void **objs, > + uint16_t nb_objs) > +{ > +#define PREFETCH_OFFSET 4 > + struct rte_mbuf *mbuf, *mbuf_out; > + struct rte_ip_frag_death_row *dr; > + struct ip4_reassembly_ctx *ctx; > + struct rte_ipv4_hdr *ipv4_hdr; > + struct rte_ip_frag_tbl *tbl; > + uint16_t idx =3D 0; > + void **to_next; > + int i; > + > + ctx =3D (struct ip4_reassembly_ctx *)node->ctx; > + > + /* Get core specific reassembly tbl */ > + tbl =3D ctx->tbl; > + dr =3D ctx->dr; > + > + for (i =3D 0; i < PREFETCH_OFFSET && i < nb_objs; i++) { > + rte_prefetch0(rte_pktmbuf_mtod_offset((struct rte_mbuf *)= objs[i], void *, > + sizeof(struct rte_e= ther_hdr))); > + } > + > + to_next =3D node->objs; > + for (i =3D 0; i < nb_objs - PREFETCH_OFFSET; i++) { > +#if RTE_GRAPH_BURST_SIZE > 64 > + /* Prefetch next-next mbufs */ > + if (likely(i + 8 < nb_objs)) > + rte_prefetch0(objs[i + 8]); > +#endif > + rte_prefetch0(rte_pktmbuf_mtod_offset((struct rte_mbuf *)= objs[i + PREFETCH_OFFSET], > + void *, sizeof(stru= ct rte_ether_hdr))); > + mbuf =3D (struct rte_mbuf *)objs[i]; > + > + ipv4_hdr =3D rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv= 4_hdr *, > + sizeof(struct rte_ethe= r_hdr)); > + if (rte_ipv4_frag_pkt_is_fragmented(ipv4_hdr)) { > + /* prepare mbuf: setup l2_len/l3_len. */ > + mbuf->l2_len =3D sizeof(struct rte_ether_hdr); > + mbuf->l3_len =3D sizeof(struct rte_ipv4_hdr); > + > + mbuf_out =3D rte_ipv4_frag_reassemble_packet(tbl,= dr, mbuf, rte_rdtsc(), > + ipv4_h= dr); > + } else { > + mbuf_out =3D mbuf; > + } > + > + if (mbuf_out) > + to_next[idx++] =3D (void *)mbuf_out; > + } > + > + for (; i < nb_objs; i++) { > + mbuf =3D (struct rte_mbuf *)objs[i]; > + > + ipv4_hdr =3D rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv= 4_hdr *, > + sizeof(struct rte_ethe= r_hdr)); > + if (rte_ipv4_frag_pkt_is_fragmented(ipv4_hdr)) { > + /* prepare mbuf: setup l2_len/l3_len. */ > + mbuf->l2_len =3D sizeof(struct rte_ether_hdr); > + mbuf->l3_len =3D sizeof(struct rte_ipv4_hdr); > + > + mbuf_out =3D rte_ipv4_frag_reassemble_packet(tbl,= dr, mbuf, rte_rdtsc(), > + ipv4_h= dr); > + } else { > + mbuf_out =3D mbuf; > + } > + > + if (mbuf_out) > + to_next[idx++] =3D (void *)mbuf_out; > + } > + node->idx =3D idx; > + rte_node_next_stream_move(graph, node, 0); > + rte_ip_frag_free_death_row(dr, 4); Can these mbufs that are being freed sent to drop node so that it is tracked and accounted as dropped ? > + > + return idx; > +} > + > +int > +rte_node_ip4_reassembly_configure(struct rte_node_ip4_reassembly_cfg *cf= g, uint16_t cnt) > +{ > + ip4_reassembly_elem_t *elem; > + int i; > + > + for (i =3D 0; i < cnt; i++) { > + elem =3D malloc(sizeof(ip4_reassembly_elem_t)); > + if (elem =3D=3D NULL) > + return -ENOMEM; > + elem->ctx.dr =3D cfg[i].dr; > + elem->ctx.tbl =3D cfg[i].tbl; > + elem->node_id =3D cfg[i].node_id; > + elem->next =3D ip4_reassembly_main.head; > + ip4_reassembly_main.head =3D elem; > + } > + > + return 0; > +} > + > +static int > +ip4_reassembly_node_init(const struct rte_graph *graph, struct rte_node = *node) > +{ > + ip4_reassembly_ctx_t *ctx =3D (ip4_reassembly_ctx_t *)node->ctx; > + ip4_reassembly_elem_t *elem =3D ip4_reassembly_main.head; > + > + RTE_SET_USED(graph); > + while (elem) { > + if (elem->node_id =3D=3D node->id) { > + /* Update node specific context */ > + memcpy(ctx, &elem->ctx, sizeof(ip4_reassembly_ctx= _t)); > + break; > + } > + elem =3D elem->next; > + } > + > + return 0; > +} > + > +static struct rte_node_register ip4_reassembly_node =3D { > + .process =3D ip4_reassembly_node_process, > + .name =3D "ip4_reassembly", > + > + .init =3D ip4_reassembly_node_init, > + > + .nb_edges =3D RTE_NODE_IP4_REASSEMBLY_NEXT_MAX, > +}; > + > +struct rte_node_register * > +ip4_reassembly_node_get(void) > +{ > + return &ip4_reassembly_node; > +} > + > +RTE_NODE_REGISTER(ip4_reassembly_node); > diff --git a/lib/node/ip4_reassembly_priv.h b/lib/node/ip4_reassembly_pri= v.h > new file mode 100644 > index 0000000000..1fa70274ba > --- /dev/null > +++ b/lib/node/ip4_reassembly_priv.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#ifndef __INCLUDE_IP4_REASSEMBLY_PRIV_H__ > +#define __INCLUDE_IP4_REASSEMBLY_PRIV_H__ > + > +/** > + * @internal > + * > + * Ip4_reassembly context structure. > + */ > +struct ip4_reassembly_ctx { > + struct rte_ip_frag_tbl *tbl; > + struct rte_ip_frag_death_row *dr; > +}; > + > +/** > + * @internal > + * > + * Get the IP4 reassembly node > + * > + * @return > + * Pointer to the IP4 reassembly node. > + */ > +struct rte_node_register *ip4_reassembly_node_get(void); > + > +#endif /* __INCLUDE_IP4_REASSEMBLY_PRIV_H__ */ > diff --git a/lib/node/meson.build b/lib/node/meson.build > index b2f04269c5..94d3f36163 100644 > --- a/lib/node/meson.build > +++ b/lib/node/meson.build > @@ -19,8 +19,9 @@ sources =3D files( > 'null.c', > 'pkt_cls.c', > 'pkt_drop.c', > + 'ip4_reassembly.c' > ) > headers =3D files('rte_node_ip4_api.h', 'rte_node_ip6_api.h', 'rte_node_= eth_api.h') > # Strict-aliasing rules are violated by uint8_t[] to context size casts. > cflags +=3D '-fno-strict-aliasing' > -deps +=3D ['graph', 'mbuf', 'lpm', 'ethdev', 'mempool', 'cryptodev'] > +deps +=3D ['graph', 'mbuf', 'lpm', 'ethdev', 'mempool', 'cryptodev', 'ip= _frag'] > diff --git a/lib/node/rte_node_ip4_api.h b/lib/node/rte_node_ip4_api.h > index 46d0d8976b..cec5c4e309 100644 > --- a/lib/node/rte_node_ip4_api.h > +++ b/lib/node/rte_node_ip4_api.h > @@ -23,6 +23,8 @@ extern "C" { > #include > #include > > +#include > + > /** > * IP4 lookup next nodes. > */ > @@ -35,6 +37,27 @@ enum rte_node_ip4_lookup_next { > /**< Number of next nodes of lookup node. */ > }; > > +/** > + * IP4 reassembly next nodes. > + */ > +enum rte_node_ip4_reassembly_next { > + RTE_NODE_IP4_REASSEMBLY_NEXT_MAX, > + /**< Number of next nodes of reassembly node. */ > +}; > + > +/** > + * Reassembly configure structure. > + * @see rte_node_ip4_reassembly_configure > + */ > +struct rte_node_ip4_reassembly_cfg { > + struct rte_ip_frag_tbl *tbl; > + /**< Reassembly fragmentation table. */ > + struct rte_ip_frag_death_row *dr; > + /**< Reassembly deathrow table. */ > + rte_node_t node_id; > + /**< Node identifier to configure. */ > +}; > + > /** > * Add ipv4 route to lookup table. > * > @@ -73,6 +96,20 @@ __rte_experimental > int rte_node_ip4_rewrite_add(uint16_t next_hop, uint8_t *rewrite_data, > uint8_t rewrite_len, uint16_t dst_port); > > +/** > + * Add reassembly node configuration data. > + * > + * @param cfg > + * Pointer to the configuration structure. > + * @param cnt > + * Number of configuration structures passed. > + * > + * @return > + * 0 on success, negative otherwise. > + */ > +__rte_experimental > +int rte_node_ip4_reassembly_configure(struct rte_node_ip4_reassembly_cfg= *cfg, uint16_t cnt); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/node/version.map b/lib/node/version.map > index 40df308bfe..c10e2e78ea 100644 > --- a/lib/node/version.map > +++ b/lib/node/version.map > @@ -4,6 +4,7 @@ EXPERIMENTAL { > rte_node_eth_config; > rte_node_ip4_route_add; > rte_node_ip4_rewrite_add; > + rte_node_ip4_reassembly_configure; > rte_node_ip6_rewrite_add; > rte_node_ip6_route_add; > rte_node_logtype; > -- > 2.39.1 >