From: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
To: dev@dpdk.org
Cc: Kamalakannan R <kamalakannan.r@intel.com>
Subject: [PATCH V3 07/11] examples/pipeline: add IPsec CLI commands
Date: Thu, 12 Jan 2023 15:45:28 +0000 [thread overview]
Message-ID: <20230112154532.244235-8-cristian.dumitrescu@intel.com> (raw)
In-Reply-To: <20230112154532.244235-1-cristian.dumitrescu@intel.com>
Add CLI commands for IPsec block configuration.
Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Kamalakannan R <kamalakannan.r@intel.com>
---
examples/pipeline/cli.c | 298 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 298 insertions(+)
diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 6b5d5a3370..92ec0fd8e3 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -18,6 +18,7 @@
#include <rte_swx_port_fd.h>
#include <rte_swx_pipeline.h>
#include <rte_swx_ctl.h>
+#include <rte_swx_ipsec.h>
#include "cli.h"
@@ -2910,6 +2911,263 @@ cmd_pipeline_mirror_session(char **tokens,
}
}
+static const char cmd_ipsec_create_help[] =
+"ipsec <ipsec_instance_name> create "
+"in <ring_in_name> out <ring_out_name> "
+"cryptodev <crypto_dev_name> cryptoq <crypto_dev_queue_pair_id> "
+"bsz <ring_rd_bsz> <ring_wr_bsz> <crypto_wr_bsz> <crypto_rd_bsz> "
+"samax <n_sa_max> "
+"numa <numa_node>\n";
+
+static void
+cmd_ipsec_create(char **tokens,
+ uint32_t n_tokens,
+ char *out,
+ size_t out_size,
+ void *obj __rte_unused)
+{
+ struct rte_swx_ipsec_params p;
+ struct rte_swx_ipsec *ipsec;
+ char *ipsec_instance_name;
+ uint32_t numa_node;
+ int status;
+
+ if (n_tokens != 20) {
+ snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+ return;
+ }
+
+ ipsec_instance_name = tokens[1];
+
+ if (strcmp(tokens[2], "create")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "create");
+ return;
+ }
+
+ if (strcmp(tokens[3], "in")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
+ return;
+ }
+
+ p.ring_in_name = tokens[4];
+
+ if (strcmp(tokens[5], "out")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
+ return;
+ }
+
+ p.ring_out_name = tokens[6];
+
+ if (strcmp(tokens[7], "cryptodev")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cryptodev");
+ return;
+ }
+
+ p.crypto_dev_name = tokens[8];
+
+ if (strcmp(tokens[9], "cryptoq")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cryptoq");
+ return;
+ }
+
+ if (parser_read_uint32(&p.crypto_dev_queue_pair_id, tokens[10])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "crypto_dev_queue_pair_id");
+ return;
+ }
+
+ if (strcmp(tokens[11], "bsz")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
+ return;
+ }
+
+ if (parser_read_uint32(&p.bsz.ring_rd, tokens[12])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "ring_rd_bsz");
+ return;
+ }
+
+ if (parser_read_uint32(&p.bsz.ring_wr, tokens[13])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "ring_wr_bsz");
+ return;
+ }
+
+ if (parser_read_uint32(&p.bsz.crypto_wr, tokens[14])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "crypto_wr_bsz");
+ return;
+ }
+
+ if (parser_read_uint32(&p.bsz.crypto_rd, tokens[15])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "crypto_rd_bsz");
+ return;
+ }
+
+ if (strcmp(tokens[16], "samax")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "samax");
+ return;
+ }
+
+ if (parser_read_uint32(&p.n_sa_max, tokens[17])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "n_sa_max");
+ return;
+ }
+
+ if (strcmp(tokens[18], "numa")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa");
+ return;
+ }
+
+ if (parser_read_uint32(&numa_node, tokens[19])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
+ return;
+ }
+
+ status = rte_swx_ipsec_create(&ipsec,
+ ipsec_instance_name,
+ &p,
+ (int)numa_node);
+ if (status)
+ snprintf(out, out_size, "IPsec instance creation failed (%d).\n", status);
+}
+
+static const char cmd_ipsec_sa_add_help[] =
+"ipsec <ipsec_instance_name> sa add <file_name>\n";
+
+static void
+cmd_ipsec_sa_add(char **tokens,
+ uint32_t n_tokens,
+ char *out,
+ size_t out_size,
+ void *obj __rte_unused)
+{
+ struct rte_swx_ipsec *ipsec;
+ char *ipsec_instance_name, *file_name, *line = NULL;
+ FILE *file = NULL;
+ uint32_t line_id = 0;
+
+ if (n_tokens != 5) {
+ snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+ return;
+ }
+
+ ipsec_instance_name = tokens[1];
+ ipsec = rte_swx_ipsec_find(ipsec_instance_name);
+ if (!ipsec) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "ipsec_instance_name");
+ goto free;
+ }
+
+ if (strcmp(tokens[2], "sa")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "sa");
+ goto free;
+ }
+
+ if (strcmp(tokens[3], "add")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
+ goto free;
+ }
+
+ file_name = tokens[4];
+ file = fopen(file_name, "r");
+ if (!file) {
+ snprintf(out, out_size, "Cannot open file %s.\n", file_name);
+ goto free;
+ }
+
+ /* Buffer allocation. */
+ line = malloc(MAX_LINE_SIZE);
+ if (!line) {
+ snprintf(out, out_size, MSG_OUT_OF_MEMORY);
+ goto free;
+ }
+
+ /* File read. */
+ for (line_id = 1; ; line_id++) {
+ struct rte_swx_ipsec_sa_params *sa;
+ const char *err_msg;
+ uint32_t sa_id = 0;
+ int is_blank_or_comment, status = 0;
+
+ if (fgets(line, MAX_LINE_SIZE, file) == NULL)
+ break;
+
+ /* Read SA from file. */
+ sa = rte_swx_ipsec_sa_read(ipsec, line, &is_blank_or_comment, &err_msg);
+ if (!sa) {
+ if (is_blank_or_comment)
+ continue;
+
+ snprintf(out, out_size, "Invalid SA in file \"%s\" at line %u: \"%s\"\n",
+ file_name, line_id, err_msg);
+ goto free;
+ }
+
+ snprintf(out, out_size, "%s", line);
+ out_size -= strlen(out);
+ out += strlen(out);
+
+ /* Add the SA to the IPsec instance. Free the SA. */
+ status = rte_swx_ipsec_sa_add(ipsec, sa, &sa_id);
+ if (status)
+ snprintf(out, out_size, "\t: Error (%d)\n", status);
+ else
+ snprintf(out, out_size, "\t: OK (SA ID = %u)\n", sa_id);
+ out_size -= strlen(out);
+ out += strlen(out);
+
+ free(sa);
+ if (status)
+ goto free;
+ }
+
+free:
+ if (file)
+ fclose(file);
+ free(line);
+}
+
+static const char cmd_ipsec_sa_delete_help[] =
+"ipsec <ipsec_instance_name> sa delete <sa_id>\n";
+
+static void
+cmd_ipsec_sa_delete(char **tokens,
+ uint32_t n_tokens,
+ char *out,
+ size_t out_size,
+ void *obj __rte_unused)
+{
+ struct rte_swx_ipsec *ipsec;
+ char *ipsec_instance_name;
+ uint32_t sa_id;
+
+ if (n_tokens != 5) {
+ snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
+ return;
+ }
+
+ ipsec_instance_name = tokens[1];
+ ipsec = rte_swx_ipsec_find(ipsec_instance_name);
+ if (!ipsec) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "ipsec_instance_name");
+ return;
+ }
+
+ if (strcmp(tokens[2], "sa")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "sa");
+ return;
+ }
+
+ if (strcmp(tokens[3], "delete")) {
+ snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
+ return;
+ }
+
+ if (parser_read_uint32(&sa_id, tokens[4])) {
+ snprintf(out, out_size, MSG_ARG_INVALID, "sa_id");
+ return;
+ }
+
+ rte_swx_ipsec_sa_delete(ipsec, sa_id);
+}
+
static const char cmd_thread_pipeline_enable_help[] =
"thread <thread_id> pipeline <pipeline_name> enable [ period <timer_period_ms> ]\n";
@@ -3068,6 +3326,9 @@ cmd_help(char **tokens,
"\tpipeline meter stats\n"
"\tpipeline stats\n"
"\tpipeline mirror session\n"
+ "\tipsec create\n"
+ "\tipsec sa add\n"
+ "\tipsec sa delete\n"
"\tthread pipeline enable\n"
"\tthread pipeline disable\n\n");
return;
@@ -3292,6 +3553,26 @@ cmd_help(char **tokens,
return;
}
+ if (!strcmp(tokens[0], "ipsec") &&
+ (n_tokens == 2) && !strcmp(tokens[1], "create")) {
+ snprintf(out, out_size, "\n%s\n", cmd_ipsec_create_help);
+ return;
+ }
+
+ if (!strcmp(tokens[0], "ipsec") &&
+ (n_tokens == 3) && !strcmp(tokens[1], "sa")
+ && !strcmp(tokens[2], "add")) {
+ snprintf(out, out_size, "\n%s\n", cmd_ipsec_sa_add_help);
+ return;
+ }
+
+ if (!strcmp(tokens[0], "ipsec") &&
+ (n_tokens == 3) && !strcmp(tokens[1], "sa")
+ && !strcmp(tokens[2], "delete")) {
+ snprintf(out, out_size, "\n%s\n", cmd_ipsec_sa_delete_help);
+ return;
+ }
+
if ((n_tokens == 3) &&
(strcmp(tokens[0], "thread") == 0) &&
(strcmp(tokens[1], "pipeline") == 0)) {
@@ -3540,6 +3821,23 @@ cli_process(char *in, char *out, size_t out_size, void *obj)
}
}
+ if (!strcmp(tokens[0], "ipsec")) {
+ if (n_tokens >= 3 && !strcmp(tokens[2], "create")) {
+ cmd_ipsec_create(tokens, n_tokens, out, out_size, obj);
+ return;
+ }
+
+ if (n_tokens >= 4 && !strcmp(tokens[2], "sa") && !strcmp(tokens[3], "add")) {
+ cmd_ipsec_sa_add(tokens, n_tokens, out, out_size, obj);
+ return;
+ }
+
+ if (n_tokens >= 4 && !strcmp(tokens[2], "sa") && !strcmp(tokens[3], "delete")) {
+ cmd_ipsec_sa_delete(tokens, n_tokens, out, out_size, obj);
+ return;
+ }
+ }
+
if (strcmp(tokens[0], "thread") == 0) {
if ((n_tokens >= 5) &&
(strcmp(tokens[4], "enable") == 0)) {
--
2.34.1
next prev parent reply other threads:[~2023-01-12 15:53 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 20:55 [PATCH 00/11] pipeline: add IPsec support Cristian Dumitrescu
2023-01-11 20:55 ` [PATCH 01/11] " Cristian Dumitrescu
2023-01-11 20:55 ` [PATCH 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 07/11] examples/pipeline: add IPsec CLI commands Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-11 20:56 ` [PATCH 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 00/11] pipeline: add IPsec support Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 01/11] " Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 07/11] examples/pipeline: add IPsec CLI commands Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-11 23:43 ` [PATCH V2 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 00/11] pipeline: add IPsec support Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 01/11] " Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-12 15:45 ` Cristian Dumitrescu [this message]
2023-01-12 15:45 ` [PATCH V3 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-12 15:45 ` [PATCH V3 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 00/11] pipeline: add IPsec support Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 01/11] " Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 07/11] examples/pipeline: add IPsec CLI commands Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-12 15:49 ` [PATCH V3 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 00/11] pipeline: add IPsec support Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 01/11] " Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 07/11] examples/pipeline: add IPsec CLI commands Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-12 18:53 ` [PATCH V4 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-01-26 9:17 ` [PATCH V4 00/11] pipeline: add IPsec support Thomas Monjalon
2023-01-26 13:11 ` Dumitrescu, Cristian
2023-01-26 13:34 ` [PATCH V5 " Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 01/11] " Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 07/11] examples/pipeline: add IPsec CLI commands Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-26 13:34 ` [PATCH V5 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 00/11] pipeline: add IPsec support Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 01/11] " Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 02/11] examples/pipeline: rework memory pool support Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 03/11] examples/pipeline: streamline ring support Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 04/11] examples/pipeline: streamline the Ethernet device support Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 05/11] examples/pipeline: support crypto devices Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 06/11] examples/pipeline: add CLI command for crypto device Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 07/11] examples/pipeline: add IPsec CLI commands Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 08/11] examples/pipeline: rework the thread configuration updates Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 09/11] examples/pipeline: support blocks other than pipelines Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 10/11] examples/pipeline: add block enable/disable CLI commands Cristian Dumitrescu
2023-01-26 14:12 ` [PATCH V6 11/11] examples/pipeline: add IPsec example Cristian Dumitrescu
2023-02-05 16:13 ` [PATCH V6 00/11] pipeline: add IPsec support Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230112154532.244235-8-cristian.dumitrescu@intel.com \
--to=cristian.dumitrescu@intel.com \
--cc=dev@dpdk.org \
--cc=kamalakannan.r@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).