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 1AD294253E; Fri, 8 Sep 2023 07:37:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E0777402D7; Fri, 8 Sep 2023 07:37:50 +0200 (CEST) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by mails.dpdk.org (Postfix) with ESMTP id 30BFE40285 for ; Fri, 8 Sep 2023 07:37:49 +0200 (CEST) Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4135f97435eso11356041cf.2 for ; Thu, 07 Sep 2023 22:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694151468; x=1694756268; 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=c3TufGLY6+P30SHkGYKBENlfbg9UihMnAsP016mrY6U=; b=Ai9WYl4NnLvc7PPvM1Cpvx8xdK+kJ670qz/7KuCWJynEZfql2BTg0h/sztbP5PUa1c 0CRiDGL+Xwn+iT1KmcBhw9njMN8OrfMJw9+8K9gj3QGJKWoCCUzgFiF9tT6srqVooXib T3sQkfYMo1oxW3F2ieDbHPf8AmcmbvM7gisbzA8WhG/t9pPI87RLoaW58UvpgXIRzrlO k6o8ElN/BufkFcNMC7zR5ByJOL0oCa8/2Nv6ImpUxrqrkUDXMFdyw/RJ24iNtLd2/qwk H4JxMvtsOqqUzLP0DN8H7cx4F6D211FfclxACeFJdAK+sRRbP+Qa+qxHI2QqvFoZ+0Sg dezg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694151468; x=1694756268; 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=c3TufGLY6+P30SHkGYKBENlfbg9UihMnAsP016mrY6U=; b=HtfjR2M3aWAC9+WNQTQ13R5CEFg4RnchAxaxJSXVPtVhGBccYrFGsfS6sB/z6shw+z hzqwHKQAbFm2m4TcgYF9pkH3C33Rw70hOz2zZ/z6dq2wU8Q9VaY0zPSToDY0eKWzOlRb IVbfTf9h6N75tCIvh1J6Y47hjkXVbAJ7ycaoRPhTN2DJPBCxG+JUnYATkwnzzLcS7N8u vWsl1MWYd8dHYTZum6LUSnmIesl/ufaLSmkxY6u0TIoypPlOOVu8FeeG9Vt0ZMx9qt1l bqElT2iLPY2Ntz8hGnH8z+pJ74wCuPsp1XuiF9Wfz0eL9Dlfp58L0BQFRO4XDefuv8ie foHA== X-Gm-Message-State: AOJu0Yzrmzi1ysRUdQqHiAWusefispm1dLLOoprGbn1kU4kf31lpKKck 4clMAo3hFXOlIPl/nZcQcv8yvdhDtTEn38unLSc= X-Google-Smtp-Source: AGHT+IEP2KTfEf+5TahrMWPZGUBajlSgmaaN1+fCQIzNH/vGka95ViawPHSm1CjNoK8pARnr3YzphYz93ic2rjfUXu4= X-Received: by 2002:a05:622a:1008:b0:410:8b52:a496 with SMTP id d8-20020a05622a100800b004108b52a496mr1915744qte.43.1694151468380; Thu, 07 Sep 2023 22:37:48 -0700 (PDT) MIME-Version: 1.0 References: <20230605112645.6204-1-pbhagavatula@marvell.com> <20230727143656.10260-1-pbhagavatula@marvell.com> In-Reply-To: <20230727143656.10260-1-pbhagavatula@marvell.com> From: Nithin Dabilpuram Date: Fri, 8 Sep 2023 11:07:36 +0530 Message-ID: Subject: Re: [PATCH v4] node: add IPv4 reassembly node To: pbhagavatula@marvell.com Cc: jerinj@marvell.com, ndabilpuram@marvell.com, Kiran Kumar K , Zhirun Yan , 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 Thu, Jul 27, 2023 at 8:07=E2=80=AFPM wrote: > > From: Pavan Nikhilesh > > Add IPv4 reassembly node. > > Signed-off-by: Pavan Nikhilesh > --- > v4 Changes: > - Add packet drop node as the 0th edge. > - Free deathrow packets to packet drop node. > 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 | 186 ++++++++++++++++++++++++++++ > 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, 264 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 e7b6e12004..10d146e2f6 100644 > --- a/doc/guides/prog_guide/graph_lib.rst > +++ b/doc/guides/prog_guide/graph_lib.rst > @@ -453,6 +453,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 d131034991..3e8fac1df4 100644 > --- a/lib/node/ethdev_rx.c > +++ b/lib/node/ethdev_rx.c > @@ -215,6 +215,7 @@ static struct rte_node_register ethdev_rx_node_base = =3D { > .next_nodes =3D { > [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..04823cc596 > --- /dev/null > +++ b/lib/node/ip4_reassembly.c > @@ -0,0 +1,186 @@ > +/* 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; > + void **to_next, **to_free; > + uint16_t idx =3D 0; > + 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, 1); > + if (dr->cnt) { > + to_free =3D rte_node_next_stream_get(graph, node, > + RTE_NODE_IP4_REASSEMBL= Y_NEXT_PKT_DROP, dr->cnt); > + rte_memcpy(to_free, dr->row, dr->cnt * sizeof(to_free[0])= ); > + rte_node_next_stream_put(graph, node, RTE_NODE_IP4_REASSE= MBLY_NEXT_PKT_DROP, > + dr->cnt); > + idx +=3D dr->cnt; > + dr->cnt =3D 0; > + } > + > + 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_PKT_DROP + 1, > + .next_nodes =3D { > + [RTE_NODE_IP4_REASSEMBLY_NEXT_PKT_DROP] =3D "pkt_drop", > + }, > +}; > + > +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 2fa7c1c8f3..72474c0856 100644 > --- a/lib/node/meson.build > +++ b/lib/node/meson.build > @@ -13,6 +13,7 @@ sources =3D files( > 'ethdev_tx.c', > 'ip4_lookup.c', > 'ip4_rewrite.c', > + 'ip4_reassembly.c', > 'ip6_lookup.c', > 'ip6_rewrite.c', > 'kernel_rx.c', > @@ -30,4 +31,4 @@ headers =3D files( > > # 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 3397da0ae8..8d8e4c41b2 100644 > --- a/lib/node/rte_node_ip4_api.h > +++ b/lib/node/rte_node_ip4_api.h > @@ -22,6 +22,8 @@ extern "C" { > #include > #include > > +#include > + > /** > * IP4 lookup next nodes. > */ > @@ -34,6 +36,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_PKT_DROP, > + /**< Packet drop 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. > * > @@ -72,6 +95,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.25.1 >