From patchwork Thu Jan 26 14:12:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Dumitrescu X-Patchwork-Id: 122556 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 09ACB42492; Thu, 26 Jan 2023 15:35:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 046C842D66; Thu, 26 Jan 2023 15:34:53 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id ECEDC42D40 for ; Thu, 26 Jan 2023 15:34:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674743690; x=1706279690; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bPk5oISKpPN7WXq1cGnrCU7ssUe/laSkJTh/pIGt51Q=; b=nmQ2QZCwkZUBnvq4RST52//s3XC1efvSTBvj4fT0vAFVaTrjRQoUslPS +i9PZm/SKOg+C7yq9n8snU7CGyTetwVMTIarr6ykv0lBbydAACmeiYJ9A 2CL0d68GK40u9rg0MfRlZ2Dcm5YyfSaotA3jzqVAcNvNrcIAIXXWnisBJ t0QpqrP2Zvcrl+bdg/zm+tOd7PeTQBjQTEzG29AO/6t+Vtj/zbOAj0AQH UdygNcca/J63Dv8+6NbLqoNq0TR5Oai2ciynpwZY65maTCARpmKC09MDn eXZSreEazHdBGBOXLfEWDkbE/ujRN51yJDPu+1BbasXjRO/UZMuEvzHeZ w==; X-IronPort-AV: E=McAfee;i="6500,9779,10602"; a="328081197" X-IronPort-AV: E=Sophos;i="5.97,248,1669104000"; d="scan'208";a="328081197" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2023 06:13:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10602"; a="664856504" X-IronPort-AV: E=Sophos;i="5.97,248,1669104000"; d="scan'208";a="664856504" Received: from silpixa00400573.ir.intel.com (HELO silpixa00400573.ger.corp.intel.com) ([10.237.222.53]) by fmsmga007.fm.intel.com with ESMTP; 26 Jan 2023 06:13:05 -0800 From: Cristian Dumitrescu To: dev@dpdk.org Cc: Kamalakannan R Subject: [PATCH V6 07/11] examples/pipeline: add IPsec CLI commands Date: Thu, 26 Jan 2023 14:12:52 +0000 Message-Id: <20230126141256.380415-8-cristian.dumitrescu@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230126141256.380415-1-cristian.dumitrescu@intel.com> References: <20230111205608.87953-1-cristian.dumitrescu@intel.com> <20230126141256.380415-1-cristian.dumitrescu@intel.com> MIME-Version: 1.0 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 Add CLI commands for IPsec block configuration. Signed-off-by: Cristian Dumitrescu Signed-off-by: Kamalakannan R --- examples/pipeline/cli.c | 298 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 298 insertions(+) diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c index dbaf436620..bcb3e54fb0 100644 --- a/examples/pipeline/cli.c +++ b/examples/pipeline/cli.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "cli.h" @@ -2913,6 +2914,263 @@ cmd_pipeline_mirror_session(char **tokens, } } +static const char cmd_ipsec_create_help[] = +"ipsec create " +"in out " +"cryptodev cryptoq " +"bsz " +"samax " +"numa \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 sa add \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 sa delete \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 pipeline enable [ period ]\n"; @@ -3071,6 +3329,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; @@ -3295,6 +3556,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)) { @@ -3543,6 +3824,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)) {