diff mbox

[dpdk-dev,v2,4/6] testpmd: new commands for syn filter

Message ID 1423641110-658-5-git-send-email-jingjing.wu@intel.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Wu, Jingjing Feb. 11, 2015, 7:51 a.m. UTC
Following commands of syn filter are removed:
  - add_syn_filter (port_id) priority (high|low) queue (queue_id)
  - remove_syn_filter (port_id)
  - get_syn_filter (port_id)
New command is added for syn filter by using filter_ctrl API and new
syn filter structure:
  - syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
---
 app/test-pmd/cmdline.c | 143 ++++++++++++++++++++++---------------------------
 app/test-pmd/config.c  |  21 --------
 2 files changed, 65 insertions(+), 99 deletions(-)
diff mbox

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 590e427..f8d9f03 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -683,14 +683,8 @@  static void cmd_help_long_parsed(void *parsed_result,
 			"get_5tuple_filter (port_id) index (idx)\n"
 			"    get info of a 5tuple filter.\n\n"
 
-			"add_syn_filter (port_id) priority (high|low) queue (queue_id)"
-			"    add syn filter.\n\n"
-
-			"remove_syn_filter (port_id)"
-			"    remove syn filter.\n\n"
-
-			"get_syn_filter (port_id) "
-			"    get syn filter info.\n\n"
+			"syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)"
+			"    Add/Del syn filter.\n\n"
 
 			"add_flex_filter (port_id) len (len_value) bytes (bytes_string) mask (mask_value)"
 			" priority (prio_value) queue (queue_id) index (idx)\n"
@@ -7275,99 +7269,94 @@  cmdline_parse_inst_t cmd_dump_one = {
 	},
 };
 
-/* *** set SYN filter *** */
-struct cmd_set_syn_filter_result {
+/* *** Add/Del syn filter *** */
+struct cmd_syn_filter_result {
 	cmdline_fixed_string_t filter;
 	uint8_t port_id;
+	cmdline_fixed_string_t ops;
 	cmdline_fixed_string_t priority;
 	cmdline_fixed_string_t high;
 	cmdline_fixed_string_t queue;
-	uint16_t  queue_id;
+	uint16_t queue_id;
 };
 
 static void
-cmd_set_syn_filter_parsed(void *parsed_result,
+cmd_syn_filter_parsed(void *parsed_result,
 			__attribute__((unused)) struct cmdline *cl,
 			__attribute__((unused)) void *data)
 {
+	struct cmd_syn_filter_result *res = parsed_result;
+	struct rte_eth_syn_filter syn_filter;
 	int ret = 0;
-	struct cmd_set_syn_filter_result *res = parsed_result;
-	struct rte_syn_filter filter;
 
-	if (!strcmp(res->filter, "add_syn_filter")) {
+	ret = rte_eth_dev_filter_supported(res->port_id,
+					RTE_ETH_FILTER_SYN);
+	if (ret < 0) {
+		printf("syn filter is not supported on port %u.\n",
+				res->port_id);
+		return;
+	}
+
+	memset(&syn_filter, 0, sizeof(syn_filter));
+
+	if (!strcmp(res->ops, "add")) {
 		if (!strcmp(res->high, "high"))
-			filter.hig_pri = 1;
+			syn_filter.hig_pri = 1;
 		else
-			filter.hig_pri = 0;
-		ret = rte_eth_dev_add_syn_filter(res->port_id,
-				&filter, res->queue_id);
-	} else if (!strcmp(res->filter, "remove_syn_filter"))
-		ret = rte_eth_dev_remove_syn_filter(res->port_id);
-	else if (!strcmp(res->filter, "get_syn_filter"))
-		get_syn_filter(res->port_id);
-	if (ret < 0)
-		printf("syn filter setting error: (%s)\n", strerror(-ret));
+			syn_filter.hig_pri = 0;
+
+		syn_filter.queue = res->queue_id;
+		ret = rte_eth_dev_filter_ctrl(res->port_id,
+						RTE_ETH_FILTER_SYN,
+						RTE_ETH_FILTER_ADD,
+						&syn_filter);
+	} else
+		ret = rte_eth_dev_filter_ctrl(res->port_id,
+						RTE_ETH_FILTER_SYN,
+						RTE_ETH_FILTER_DELETE,
+						&syn_filter);
 
+	if (ret < 0)
+		printf("syn filter programming error: (%s)\n",
+				strerror(-ret));
 }
-cmdline_parse_token_num_t cmd_syn_filter_portid =
-	TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
-				port_id, UINT8);
+
+cmdline_parse_token_string_t cmd_syn_filter_filter =
+	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
+	filter, "syn_filter");
+cmdline_parse_token_num_t cmd_syn_filter_port_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
+	port_id, UINT8);
+cmdline_parse_token_string_t cmd_syn_filter_ops =
+	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
+	ops, "add#del");
 cmdline_parse_token_string_t cmd_syn_filter_priority =
-	TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
+	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
 				priority, "priority");
 cmdline_parse_token_string_t cmd_syn_filter_high =
-	TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
+	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
 				high, "high#low");
 cmdline_parse_token_string_t cmd_syn_filter_queue =
-	TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
+	TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result,
 				queue, "queue");
 cmdline_parse_token_num_t cmd_syn_filter_queue_id =
-	TOKEN_NUM_INITIALIZER(struct cmd_set_syn_filter_result,
+	TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result,
 				queue_id, UINT16);
-cmdline_parse_token_string_t cmd_syn_filter_add_filter =
-	TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
-				filter, "add_syn_filter");
-cmdline_parse_token_string_t cmd_syn_filter_remove_filter =
-	TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
-				filter, "remove_syn_filter");
-cmdline_parse_inst_t cmd_add_syn_filter = {
-		.f = cmd_set_syn_filter_parsed,
-		.data = NULL,
-		.help_str = "add syn filter",
-		.tokens = {
-			(void *)&cmd_syn_filter_add_filter,
-			(void *)&cmd_syn_filter_portid,
-			(void *)&cmd_syn_filter_priority,
-			(void *)&cmd_syn_filter_high,
-			(void *)&cmd_syn_filter_queue,
-			(void *)&cmd_syn_filter_queue_id,
-			NULL,
-		},
-};
-cmdline_parse_inst_t cmd_remove_syn_filter = {
-		.f = cmd_set_syn_filter_parsed,
-		.data = NULL,
-		.help_str = "remove syn filter",
-		.tokens = {
-			(void *)&cmd_syn_filter_remove_filter,
-			(void *)&cmd_syn_filter_portid,
-			NULL,
-		},
-};
-
-cmdline_parse_token_string_t cmd_syn_filter_get_filter =
-	TOKEN_STRING_INITIALIZER(struct cmd_set_syn_filter_result,
-				filter, "get_syn_filter");
 
-cmdline_parse_inst_t cmd_get_syn_filter = {
-		.f = cmd_set_syn_filter_parsed,
-		.data = NULL,
-		.help_str = "get syn filter",
-		.tokens = {
-			(void *)&cmd_syn_filter_get_filter,
-			(void *)&cmd_syn_filter_portid,
-			NULL,
-		},
+cmdline_parse_inst_t cmd_syn_filter = {
+	.f = cmd_syn_filter_parsed,
+	.data = NULL,
+	.help_str = "add/delete syn filter",
+	.tokens = {
+		(void *)&cmd_syn_filter_filter,
+		(void *)&cmd_syn_filter_port_id,
+		(void *)&cmd_syn_filter_ops,
+		(void *)&cmd_syn_filter_priority,
+		(void *)&cmd_syn_filter_high,
+		(void *)&cmd_syn_filter_queue,
+		(void *)&cmd_syn_filter_queue_id,
+		NULL,
+	},
 };
 
 /* *** ADD/REMOVE A 2tuple FILTER *** */
@@ -9118,9 +9107,7 @@  cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_dump,
 	(cmdline_parse_inst_t *)&cmd_dump_one,
 	(cmdline_parse_inst_t *)&cmd_ethertype_filter,
-	(cmdline_parse_inst_t *)&cmd_add_syn_filter,
-	(cmdline_parse_inst_t *)&cmd_remove_syn_filter,
-	(cmdline_parse_inst_t *)&cmd_get_syn_filter,
+	(cmdline_parse_inst_t *)&cmd_syn_filter,
 	(cmdline_parse_inst_t *)&cmd_add_2tuple_filter,
 	(cmdline_parse_inst_t *)&cmd_remove_2tuple_filter,
 	(cmdline_parse_inst_t *)&cmd_get_2tuple_filter,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index c40f819..10454ab 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2166,27 +2166,6 @@  set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
 }
 
 void
-get_syn_filter(uint8_t port_id)
-{
-	struct rte_syn_filter filter;
-	int ret = 0;
-	uint16_t rx_queue;
-
-	memset(&filter, 0, sizeof(filter));
-	ret = rte_eth_dev_get_syn_filter(port_id, &filter, &rx_queue);
-
-	if (ret < 0) {
-		if (ret == (-ENOENT))
-			printf("syn filter is not enabled\n");
-		else
-			printf("get syn filter fails(%s)\n", strerror(-ret));
-		return;
-	}
-	printf("syn filter: priority: %s, queue: %d\n",
-		filter.hig_pri ? "high" : "low",
-		rx_queue);
-}
-void
 get_2tuple_filter(uint8_t port_id, uint16_t index)
 {
 	struct rte_2tuple_filter filter;