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 4DE8942BF1; Mon, 5 Jun 2023 14:47:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E2FA94021F; Mon, 5 Jun 2023 14:47:14 +0200 (CEST) Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by mails.dpdk.org (Postfix) with ESMTP id 8B8944003C for ; Mon, 5 Jun 2023 14:47:13 +0200 (CEST) Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6261a61b38cso38906296d6.1 for ; Mon, 05 Jun 2023 05:47:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685969233; x=1688561233; 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=5ArUviOl15h0Vuwh3m7qQuXztJz0JO2ean/OG5arN+4=; b=biaOjCwCpnSDN/+VKe4anx1avor/XnosNT1Z4vZPgnBHhsmuo7nOYI6s9JKXRkeAdn AZVymPesxx7uHw3CA/gIfKHshB3klju2m7CXqcwodA/5gju3mAF6g09PYIzRYynWLVXm 9IWlDdw8QclsFfKFB1HFtZl/qZL6rqj5AFkthVJBOFiW4TLwOw47veitn5jlelK6cShu IC4bdUTuHYOI19RaZjHoHI1Q6OMwZfKA/PSVjm0o/ok+yGBmvVe5IP7ne4DD95iwaB+R br1V7vPJOg3XM0jhwxDrkw230606wolgWwQOM4l7Ljd5xtgoNPZ1GcK1rq7OkimCCI+q ZT/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685969233; x=1688561233; 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=5ArUviOl15h0Vuwh3m7qQuXztJz0JO2ean/OG5arN+4=; b=WS5sRCDSgogb5c8imVL03vR1YtI9Mf/RUpSVGYqDB0SAAlgFjngiqyerxX8UlvfZMy BE4kXbfbiT9EjD/zFiBqvQjZ6FIui5cNMbTt3RH8V2SdCI0B3mSi2snDszf+OJ2295Od 63dyTlo6z3uTURggTcy7BEkICYhBl2zHwHjj6UyeO6W7ylE/83DjHHvplLY4NKCw2UDb NML6AhS6AhsDkxv0t0lvW7MoOZlRhC8k8YBfiY42U3lHlcN9uMYoBBHaR3MJq1jqpVK0 vNhdI7uk50llfSl6vB1DpPzmJSTTDlsBCjDOn6z3nBoYyxs/OGuhJxgtBWeNLN0PfOpg W3Cw== X-Gm-Message-State: AC+VfDx3+hw7b+DMK3Lr5H8c1/RHG0xfTONhL2Ir+HHoZKDlI+ssu1n9 NLb0UmdNg3GBAUBSEMwc68ia7wM5fIpGV7YEC10= X-Google-Smtp-Source: ACHHUZ7Ff/1mzq+cP+HZ34IQ6t3KPzqyZbNT/tXLOQ4JHTeg+Td5NA5Vd2dAQ9q1QxMoz8g3jqPisxEuSreinsBik/M= X-Received: by 2002:a05:6214:d4e:b0:625:b962:30b6 with SMTP id 14-20020a0562140d4e00b00625b96230b6mr7723833qvr.22.1685969232740; Mon, 05 Jun 2023 05:47:12 -0700 (PDT) MIME-Version: 1.0 References: <20230425131516.3308612-1-vattunuru@marvell.com> <20230602162216.1868870-1-vattunuru@marvell.com> <20230602162216.1868870-2-vattunuru@marvell.com> In-Reply-To: <20230602162216.1868870-2-vattunuru@marvell.com> From: Nithin Dabilpuram Date: Mon, 5 Jun 2023 18:17:00 +0530 Message-ID: Subject: Re: [PATCH v3 1/3] node/kernel_tx: support packet transmit to kernel To: Vamsi Attunuru Cc: dev@dpdk.org, thomas@monjalon.net, jerinj@marvell.com, ndabilpuram@marvell.com, zhirun.yan@intel.com 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, Jun 2, 2023 at 9:52=E2=80=AFPM Vamsi Attunuru wrote: > > Patch adds a node to transmit the packets to kernel over > a raw socket. > > Signed-off-by: Vamsi Attunuru > --- > doc/guides/prog_guide/graph_lib.rst | 9 ++ > lib/node/kernel_tx.c | 122 ++++++++++++++++++++++++++++ > lib/node/kernel_tx_priv.h | 16 ++++ > lib/node/meson.build | 1 + > 4 files changed, 148 insertions(+) > > diff --git a/doc/guides/prog_guide/graph_lib.rst b/doc/guides/prog_guide/= graph_lib.rst > index 1cfdc86433..fa22b014f3 100644 > --- a/doc/guides/prog_guide/graph_lib.rst > +++ b/doc/guides/prog_guide/graph_lib.rst > @@ -392,3 +392,12 @@ null > ~~~~ > This node ignores the set of objects passed to it and reports that all a= re > processed. > + > +kernel_tx > +~~~~~~~~~ > +This node is an exit node that forwards the packets to kernel. It will b= e used > +to forward any control plane traffic to kernel stack from DPDK. It uses = a raw > +socket interface to transmit the packets, it uses the packet's destinati= on > +IP address in sockaddr_in address structure and ``sendto`` function to s= end > +data on the raw socket. Aftering sending the burst of packets to kernel, > +this node free up the packet buffers. > diff --git a/lib/node/kernel_tx.c b/lib/node/kernel_tx.c > new file mode 100644 > index 0000000000..27d1808c71 > --- /dev/null > +++ b/lib/node/kernel_tx.c > @@ -0,0 +1,122 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +#include "kernel_tx_priv.h" > +#include "node_private.h" > + > +static __rte_always_inline void > +kernel_tx_process_mbuf(struct rte_node *node, struct rte_mbuf **mbufs, u= int16_t cnt) > +{ > + kernel_tx_node_ctx_t *ctx =3D (kernel_tx_node_ctx_t *)node->ctx; > + struct sockaddr_in sin =3D {0}; > + struct rte_ipv4_hdr *ip4; > + size_t len; > + char *buf; > + int i; > + > + for (i =3D 0; i < cnt; i++) { > + ip4 =3D rte_pktmbuf_mtod(mbufs[i], struct rte_ipv4_hdr *)= ; > + len =3D rte_pktmbuf_data_len(mbufs[i]); > + buf =3D (char *)ip4; > + > + sin.sin_family =3D AF_INET; > + sin.sin_port =3D 0; > + sin.sin_addr.s_addr =3D ip4->dst_addr; > + > + if (sendto(ctx->sock, buf, len, 0, (struct sockaddr *)&si= n, sizeof(sin)) < 0) > + node_err("kernel_tx", "Unable to send packets: %s= \n", strerror(errno)); > + } > +} > + > +static uint16_t > +kernel_tx_node_process(struct rte_graph *graph __rte_unused, struct rte_= node *node, void **objs, > + uint16_t nb_objs) > +{ > + struct rte_mbuf **pkts =3D (struct rte_mbuf **)objs; > + uint16_t obj_left =3D nb_objs; > + > +#define PREFETCH_CNT 4 > + > + while (obj_left >=3D 12) { > + /* Prefetch next-next mbufs */ > + rte_prefetch0(pkts[8]); > + rte_prefetch0(pkts[9]); > + rte_prefetch0(pkts[10]); > + rte_prefetch0(pkts[11]); > + > + /* Prefetch next mbuf data */ > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[4], void *, pk= ts[4]->l2_len)); > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[5], void *, pk= ts[5]->l2_len)); > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[6], void *, pk= ts[6]->l2_len)); > + rte_prefetch0(rte_pktmbuf_mtod_offset(pkts[7], void *, pk= ts[7]->l2_len)); > + > + kernel_tx_process_mbuf(node, pkts, PREFETCH_CNT); > + > + obj_left -=3D PREFETCH_CNT; > + pkts +=3D PREFETCH_CNT; > + } > + > + while (obj_left > 0) { > + kernel_tx_process_mbuf(node, pkts, 1); > + > + obj_left--; > + pkts++; > + } > + > + rte_pktmbuf_free_bulk((struct rte_mbuf **)objs, nb_objs); > + > + return nb_objs; > +} > + > +static int > +kernel_tx_node_init(const struct rte_graph *graph __rte_unused, struct r= te_node *node) > +{ > + kernel_tx_node_ctx_t *ctx =3D (kernel_tx_node_ctx_t *)node->ctx; > + > + ctx->sock =3D socket(AF_INET, SOCK_RAW, IPPROTO_RAW); > + if (ctx->sock < 0) > + node_err("kernel_tx", "Unable to open RAW socket\n"); > + > + return 0; > +} > + > +static void > +kernel_tx_node_fini(const struct rte_graph *graph __rte_unused, struct r= te_node *node) > +{ > + kernel_tx_node_ctx_t *ctx =3D (kernel_tx_node_ctx_t *)node->ctx; > + > + if (ctx->sock >=3D 0) { > + close(ctx->sock); > + ctx->sock =3D -1; > + } > +} > + > +static struct rte_node_register kernel_tx_node_base =3D { > + .process =3D kernel_tx_node_process, > + .name =3D "kernel_tx", > + > + .init =3D kernel_tx_node_init, > + .fini =3D kernel_tx_node_fini, > + > + .nb_edges =3D 0, > +}; > + > +struct rte_node_register * > +kernel_tx_node_get(void) > +{ > + return &kernel_tx_node_base; > +} > + > +RTE_NODE_REGISTER(kernel_tx_node_base); > diff --git a/lib/node/kernel_tx_priv.h b/lib/node/kernel_tx_priv.h > new file mode 100644 > index 0000000000..6fd8a4f2af > --- /dev/null > +++ b/lib/node/kernel_tx_priv.h > @@ -0,0 +1,16 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(C) 2023 Marvell International Ltd. > + */ > + > +#ifndef __KERNEL_TX_PRIV_H__ > +#define __KERNEL_TX_PRIV_H__ > + > +/* kernel_tx node context structure. */ > +typedef struct kernel_tx_node_ctx { > + int sock; > +} kernel_tx_node_ctx_t; > + > +/* Get the pointer to kernel_tx node register structure */ > +struct rte_node_register *kernel_tx_node_get(void); > + > +#endif /* __KERNEL_TX_PRIV_H__ */ > diff --git a/lib/node/meson.build b/lib/node/meson.build > index dbdf673c86..0520be23ff 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', > + 'kernel_tx.c', > 'log.c', > 'null.c', > 'pkt_cls.c', > -- > 2.25.1 >