From d4849de4c687899911b44476b421653a24d3e542 Mon Sep 17 00:00:00 2001 From: Rajith Ramakrishna Date: Thu, 15 Dec 2022 07:09:36 +0000 Subject: [PATCH 01/23] Added the code structure and infra --- src/plugins/udps/CMakeLists.txt | 18 +++++++ src/plugins/udps/udps.h | 7 +++ src/plugins/udps/udps_includes.h | 22 ++++++++ src/plugins/udps/udps_node.c | 92 ++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/plugins/udps/CMakeLists.txt create mode 100644 src/plugins/udps/udps.h create mode 100644 src/plugins/udps/udps_includes.h create mode 100644 src/plugins/udps/udps_node.c diff --git a/src/plugins/udps/CMakeLists.txt b/src/plugins/udps/CMakeLists.txt new file mode 100644 index 000000000000..4cc84c3887c3 --- /dev/null +++ b/src/plugins/udps/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2018 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_vpp_plugin(udps + SOURCES + udps_node.c + +) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h new file mode 100644 index 000000000000..dae2a479667c --- /dev/null +++ b/src/plugins/udps/udps.h @@ -0,0 +1,7 @@ +#ifndef __UDPS_H__ +#define __UDPS_H__ + +void udps_node_policy_apply(uint32_t sw_if_index, uint8_t is_rx); +void udps_node_policy_remove(uint32_t sw_if_index, uint8_t is_rx); + +#endif /* __UDPS_H__ */ diff --git a/src/plugins/udps/udps_includes.h b/src/plugins/udps/udps_includes.h new file mode 100644 index 000000000000..525a1085fa35 --- /dev/null +++ b/src/plugins/udps/udps_includes.h @@ -0,0 +1,22 @@ +#ifndef __UDPS_INCLUDES_H__ +#define __UDPS_INCLUDES_H__ + +/** Core VPP includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* udps includes */ +#include "udps.h" + +#endif /* __UDPS_INCLUDES_H__ */ diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c new file mode 100644 index 000000000000..f1cdee140371 --- /dev/null +++ b/src/plugins/udps/udps_node.c @@ -0,0 +1,92 @@ +#include "udps_includes.h" + +void +udps_node_policy_apply(uint32_t sw_if_index, uint8_t is_rx) +{ + if (is_rx) { + vnet_feature_enable_disable("device-input", + "udps-rx-node", + sw_if_index, + 1, 0, 0); + } else { + vnet_feature_enable_disable("interface-output", + "udps-tx-node", + sw_if_index, + 1, 0, 0); + } +} + +void +udps_node_policy_remove(uint32_t sw_if_index, uint8_t is_rx) +{ + if (is_rx) { + vnet_feature_enable_disable("device-input", + "udps-rx-node", + sw_if_index, + 0, 0, 0); + } else { + vnet_feature_enable_disable("interface-output", + "udps-tx-node", + sw_if_index, + 0, 0, 0); + } +} + +VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, + vlib_node_runtime_t *node, + vlib_frame_t *frame) +{ + return 0; +} + +VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, + vlib_node_runtime_t *node, + vlib_frame_t *frame) +{ + return 0; +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (udps_rx_node) = +{ + .name = "udps-rx-node", + .vector_size = sizeof (u32), + .format_trace = NULL, + .type = VLIB_NODE_TYPE_INTERNAL, + .n_next_nodes = VNET_DEVICE_INPUT_N_NEXT_NODES, + .next_nodes = VNET_DEVICE_INPUT_NEXT_NODES, + .n_errors = 0, + .error_strings = NULL, +}; + +VNET_FEATURE_INIT (udps_rx_node, static) = +{ + .arc_name = "device-input", + .node_name = "udps-rx-node", + .runs_before = VNET_FEATURES ("ethernet-input"), +}; + +VLIB_REGISTER_NODE (udps_tx_node) = +{ + .name = "udps-tx-node", + .vector_size = sizeof (u32), + .format_trace = NULL, + .type = VLIB_NODE_TYPE_INTERNAL, + .n_next_nodes = 0, + .n_errors = 0, + .error_strings = NULL, +}; + +VNET_FEATURE_INIT (udps_tx_node, static) = +{ + .arc_name = "interface-output", + .node_name = "udps-tx-node", + .runs_before = VNET_FEATURES ("interface-tx"), +}; + +VLIB_PLUGIN_REGISTER () = +{ + .version = VPP_BUILD_VER, + .description = "user defined packet steer plugin registration", +}; +/* *INDENT-ON* */ From 76d3724e4addf5a464887dd74bda2cb62cb3f51c Mon Sep 17 00:00:00 2001 From: VM Date: Thu, 15 Dec 2022 08:27:23 +0000 Subject: [PATCH 02/23] cli_first_cut --- src/plugins/udps/CMakeLists.txt | 2 +- src/plugins/udps/udps_cli.c | 230 ++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 src/plugins/udps/udps_cli.c diff --git a/src/plugins/udps/CMakeLists.txt b/src/plugins/udps/CMakeLists.txt index 4cc84c3887c3..86582bca95eb 100644 --- a/src/plugins/udps/CMakeLists.txt +++ b/src/plugins/udps/CMakeLists.txt @@ -14,5 +14,5 @@ add_vpp_plugin(udps SOURCES udps_node.c - + udps_cli.c ) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c new file mode 100644 index 000000000000..a82d702ef1dc --- /dev/null +++ b/src/plugins/udps/udps_cli.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2020 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "udps_includes.h" + +static clib_error_t * +udps_policy_action_set (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_action_set, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands configure policy-action for UDPS feature + * set udps policy-action [offset [ [insert|replace] ] | remove ] [out-port ] + * Notes: above command can be usede to add multiple rewrites, single port redirect to same policy action (identified by action-name). +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (set_udps_policy_action_command, static) = { + .path = "set udps policy-action", + .function = udps_policy_action_set, + .short_help = "set udps policy-action " + "[offset [ [insert|replace] rewrite_string ] | remove ]" + " [out-port ]", +}; +/* *INDENT-ON* */ + + +static clib_error_t * +udps_policy_action_show (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_action_show, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands show policy-action for UDPS feature + * show udps policy-action +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_udps_policy_action_command, static) = { + .path = "show udps policy-action", + .function = udps_policy_action_show, + .short_help = "show udps policy-action ", + .is_mp_safe = 1, +}; +/* *INDENT-ON* */ + +static clib_error_t * +udps_policy_action_delete (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_action_delete, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands delete policy-action for UDPS feature + * delete udps policy-action +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (delete_udps_policy_action_command, static) = { + .path = "delete udps policy-action", + .function = udps_policy_action_delete, + .short_help = "delete udps policy-action ", + .is_mp_safe = 1, +}; +/* *INDENT-ON* */ + +static clib_error_t * +udps_policy_set (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_set, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands configure policy for UDPS feature + * set udps policy rule [ offset val ] [ action ] + * Notes: above command can be usede to add multiples rules to a policy. Mulitiple matches in each rule are allowed. For now, single action in a rule. +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (set_udps_policy_command, static) = { + .path = "set udps policy", + .function = udps_policy_set, + .short_help = "set udps policy rule " + " [ offset val ] [ action ]", +}; +/* *INDENT-ON* */ + + +static clib_error_t * +udps_policy_show (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_show, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands show policy for UDPS feature + * show udps policy +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_udps_policy_command, static) = { + .path = "show udps policy", + .function = udps_policy_show, + .short_help = "show udps policy ", + .is_mp_safe = 1, +}; +/* *INDENT-ON* */ + +static clib_error_t * +udps_policy_delete (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_delete, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands delete policy for UDPS feature + * delete udps policy +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (delete_udps_policy_command, static) = { + .path = "delete udps policy", + .function = udps_policy_delete, + .short_help = "delete udps policy ", + .is_mp_safe = 1, +}; +/* *INDENT-ON* */ + +static clib_error_t * +udps_policy_interface_set (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_interface_set, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands apply UDPS feature policy on interface + * set udps interface direction policy +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (set_udps_policy_interface_command, static) = { + .path = "set udps interface", + .function = udps_policy_interface_set, + .short_help = "set udps interface direction policy ", +}; +/* *INDENT-ON* */ + + +static clib_error_t * +udps_policy_interface_show (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_show, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands show policy for UDPS feature on interface + * show udps interface +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (show_udps_policy_interface_command, static) = { + .path = "show udps interface", + .function = udps_policy_interface_show, + .short_help = "show udps interface ", + .is_mp_safe = 1, +}; +/* *INDENT-ON* */ + +static clib_error_t * +udps_policy_interface_delete (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + clib_error_t *error = 0; + vlib_cli_output(vm, "udps_policy_interface_delete, WORK in PROGRESS, retry later\n"); + return error; +} + +/* + * This Commands delete policy for UDPS feature on an interface + * delete udps interface direction +*/ + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (delete_udps_policy_interface_command, static) = { + .path = "delete udps interface", + .function = udps_policy_interface_delete, + .short_help = "delete udps interface direction ", + .is_mp_safe = 1, +}; +/* *INDENT-ON* */ + + From 73624fff53feed93fb5bd4cda1cedffb4df3780f Mon Sep 17 00:00:00 2001 From: Rajith Ramakrishna Date: Thu, 15 Dec 2022 08:50:58 +0000 Subject: [PATCH 03/23] Added the API prototypes and structure definitions --- src/plugins/udps/CMakeLists.txt | 1 + src/plugins/udps/udps.h | 121 +++++++++++++++++++++++++++++++- src/plugins/udps/udps_node.c | 4 +- 3 files changed, 122 insertions(+), 4 deletions(-) diff --git a/src/plugins/udps/CMakeLists.txt b/src/plugins/udps/CMakeLists.txt index 86582bca95eb..a85d88eee618 100644 --- a/src/plugins/udps/CMakeLists.txt +++ b/src/plugins/udps/CMakeLists.txt @@ -15,4 +15,5 @@ add_vpp_plugin(udps SOURCES udps_node.c udps_cli.c + udps_db.c ) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h index dae2a479667c..3e5781234a46 100644 --- a/src/plugins/udps/udps.h +++ b/src/plugins/udps/udps.h @@ -1,7 +1,124 @@ #ifndef __UDPS_H__ #define __UDPS_H__ -void udps_node_policy_apply(uint32_t sw_if_index, uint8_t is_rx); -void udps_node_policy_remove(uint32_t sw_if_index, uint8_t is_rx); +#define UDPS_NO_PORT (~0) +#define UDPS_NO_ACTION (NULL) + +enum udps_rewrite_oper_e { + UDPS_REWRITE_UNUSED = 0, + UDPS_REWRITE_INSERT, + UDPS_REWRITE_REPLACE, + UDPS_REWRITE_REMOVE +}; + +enum udps_match_oper_e { + UDPS_MATCH_UNUSED = 0, + UDPS_MATCH_PKT, +}; + +typedef struct udps_rewrite_s { + u8 oper; + u16 offset; + u8 *value; + u8 len; +} udps_rewrite_t; + +typedef struct udps_rule_action_s { + u8 *name; + udps_rewrite_t *rewrite; + u32 out_port; +} udps_rule_action_t; + +typedef struct udps_match_pkt_s { + u16 offset; + u8 *value; +} udps_match_pkt_t; + +typedef struct udps_rule_entry_s { + u8 rule_id; + udps_match_pkt_t *match_pkt; + u32 act_id; +} udps_rule_entry_t; + +typedef struct udps_policy_entry_s { + u8 *name; + udps_rule_entry_t *rules; +} udps_policy_entry_t; + +typedef struct udps_main_s { + u32 *ing_policy_by_sw_if_index; + u32 *egr_policy_by_sw_if_index; + udps_policy_entry_t *policy_db; + udps_rule_action_t *action_db; + uword *action_by_name; + uword *policy_by_name; +} udps_main_t; + +/* Add a rule action. + Creates action if not present. + If already present updates the existing one. + name, oper are mandatory. + oper determines which of offset, value, len are set. +*/ +void udps_db_rule_action_add(u8 *name, u8 oper, u16 offset, u8 *value, u8 len, u32 out_port); + +/* Delete a rule action. + Deletes action if not used by a policy. + If used, returns false. +*/ +bool udps_db_rule_action_del(u8 *name); + +/* Get a rule action. + If present, rule action is returned in ra. + Otherwise, returns false. +*/ +bool udps_db_rule_action_get(u8 *name, udps_rule_action_t **ra); + +/* Get a matching rule action for the packet. + If present, rule action is returned in ra. + Otherwise, returns false. +*/ +bool udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, udps_rule_action_t **ra); + +/* Add a rule entry. + Creates rule entry if not present. + If already present updates the existing one. + name, id, oper are mandatory. + oper determines if offset, value is valid. + If aname is not created yet, returns false. +*/ +bool udps_db_rule_entry_add(u8 *name, u8 id, u8 oper, u16 offset, u8 *value, u8 *aname); + +/* Get the rule entry count. +*/ +u8 udps_db_rule_entry_cnt(u8 *name); + +/* Get a rule entry. + If present, rule entry is returned in re. + Otherwise, returns false. +*/ +bool udps_db_rule_entry_get(u8 *name, u8 id, udps_rule_entry_t **re); + +/* Delete a policy. + Deletes policy if not used by an interface. + If used, returns false. +*/ +bool udps_db_rule_policy_del(u8 *name); + +/* Applies policy on interface in the given direction. +*/ +void udps_db_policy_apply(u32 sw_if_index, u8 is_rx, u8 *name); + +/* Removes policy on interface in the given direction. +*/ +void udps_db_policy_remove(u32 sw_if_index, u8 is_rx, u8 *name); + +/* Applies policy on interface in the given direction. +*/ +void udps_node_policy_apply(u32 sw_if_index, u8 is_rx); + +/* Removes policy on interface in the given direction. +*/ +void udps_node_policy_remove(u32 sw_if_index, u8 is_rx); #endif /* __UDPS_H__ */ diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c index f1cdee140371..33a80ae93a96 100644 --- a/src/plugins/udps/udps_node.c +++ b/src/plugins/udps/udps_node.c @@ -1,7 +1,7 @@ #include "udps_includes.h" void -udps_node_policy_apply(uint32_t sw_if_index, uint8_t is_rx) +udps_node_policy_apply(u32 sw_if_index, u8 is_rx) { if (is_rx) { vnet_feature_enable_disable("device-input", @@ -17,7 +17,7 @@ udps_node_policy_apply(uint32_t sw_if_index, uint8_t is_rx) } void -udps_node_policy_remove(uint32_t sw_if_index, uint8_t is_rx) +udps_node_policy_remove(u32 sw_if_index, u8 is_rx) { if (is_rx) { vnet_feature_enable_disable("device-input", From 53de55a9203f0fa19a4e3369ed8b9f1329ae6622 Mon Sep 17 00:00:00 2001 From: Rajith Ramakrishna Date: Thu, 15 Dec 2022 08:52:40 +0000 Subject: [PATCH 04/23] Added skeleton functions --- src/plugins/udps/udps_db.c | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/plugins/udps/udps_db.c diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c new file mode 100644 index 000000000000..86710f7745fa --- /dev/null +++ b/src/plugins/udps/udps_db.c @@ -0,0 +1,59 @@ +#include "udps_includes.h" + +void +udps_db_rule_action_add(u8 *name, u8 oper, u16 offset, u8 *value, u8 len, u32 out_port) +{ +} + +bool +udps_db_rule_action_del(u8 *name) +{ + return true; +} + +bool +udps_db_rule_action_get(u8 *name, udps_rule_action_t **ra) +{ + return true; +} + +bool +udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, udps_rule_action_t **ra) +{ + return true; +} + +bool +udps_db_rule_entry_add(u8 *name, u8 id, u8 oper, u16 offset, u8 *value, u8 *aname) +{ + return true; +} + +u8 +udps_db_rule_entry_cnt(u8 *name) +{ + return 0; +} + +bool +udps_db_rule_entry_get(u8 *name, u8 id, udps_rule_entry_t **re) +{ + return true; +} + +bool +udps_db_rule_policy_del(u8 *name) +{ + return true; +} + +void +udps_db_policy_apply(u32 sw_if_index, u8 is_rx, u8 *name) +{ +} + +void +udps_db_policy_remove(u32 sw_if_index, u8 is_rx, u8 *name) +{ +} + From 6ac54f93b57b2a67124be0579e5e3ecd77367924 Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Wed, 14 Dec 2022 08:23:39 +0000 Subject: [PATCH 05/23] dummy commit for hackathon --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4cc283b5e530..3cf5b9cba861 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ Vector Packet Processing ======================== + ## Introduction The VPP platform is an extensible framework that provides out-of-the-box From ad26291d9f0dcb75699cf8fd11ebf5800973fee5 Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Wed, 14 Dec 2022 09:08:32 +0000 Subject: [PATCH 06/23] dummy commit 2 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3cf5b9cba861..e1c606a187c5 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Vector Packet Processing ======================== + ## Introduction The VPP platform is an extensible framework that provides out-of-the-box From 911bce17e2a0c170b23fa7cf67455a6418588850 Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Thu, 15 Dec 2022 07:37:36 +0000 Subject: [PATCH 07/23] cscope build file --- README.md | 2 -- src/bld_cscope.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 src/bld_cscope.sh diff --git a/README.md b/README.md index e1c606a187c5..4cc283b5e530 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ Vector Packet Processing ======================== - - ## Introduction The VPP platform is an extensible framework that provides out-of-the-box diff --git a/src/bld_cscope.sh b/src/bld_cscope.sh new file mode 100755 index 000000000000..39f03c3bb154 --- /dev/null +++ b/src/bld_cscope.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +echo -e "\033[36m Building Cscope ...\033[0m" +uname=`uname -s` +if [ x$uname == xLinux ] +then + find -type f -and -regex '.*/.*\.\(c\|cpp\|cc\|h\|hpp\|p4\|s\|asm\|py\|proto\|spec\|go\)$' > cscope.files + find ../platform/ -type f -and -regex '.*/.*\.\(c\|cpp\|cc\|h\|hpp\|p4\|s\|asm\|py\|proto\|spec\|go\)$' >> cscope.files +elif [ x$uname == xDarwin ] +then + find . -name '*.c' 2> /dev/null > cscope.files + find . -name '*.cpp' 2> /dev/null >> cscope.files + find . -name '*.cc' 2> /dev/null >> cscope.files + find . -name '*.hpp' 2> /dev/null >> cscope.files + find . -name '*.p4' 2> /dev/null >> cscope.files + find . -name '*.s' 2> /dev/null >> cscope.files + find . -name '*.asm' 2> /dev/null >> cscope.files + find . -name '*.py' 2> /dev/null >> cscope.files + find . -name '*.proto' 2> /dev/null >> cscope.files + find . -name '*.spec' 2> /dev/null >> cscope.files + find . -name '*.go' 2> /dev/null >> cscope.files +fi + +cscope -b -q + + +echo -e "\033[36m Done !! \033[0m" From 9d28d018dcceb3f9efeb9148457e27f6c6db9eae Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Thu, 15 Dec 2022 09:59:42 +0000 Subject: [PATCH 08/23] skeletal for nodes --- src/plugins/udps/udps_node.c | 96 +++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 6 deletions(-) diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c index 33a80ae93a96..606bb93d8828 100644 --- a/src/plugins/udps/udps_node.c +++ b/src/plugins/udps/udps_node.c @@ -1,5 +1,48 @@ #include "udps_includes.h" +#define foreach_udps_rx_error \ + _(UDPS_RX, "UDPS_RX outgoing packets") \ + _(DROP, "UDPS_RX drops") + +typedef enum +{ +#define _(sym,str) UDPS_RX_ERROR_##sym, + foreach_udps_rx_error +#undef _ + UDPS_RX_N_ERROR, +} udps_rx_error_t; + +static char *udps_rx_error_strings[] = { +#define _(sym,string) string, + foreach_udps_rx_error +#undef _ +}; + +#define foreach_udps_tx_error \ + _(UDPS_TX, "UDPS_TX outgoing packets") \ + _(DROP, "UDPS_TX drops") + +typedef enum +{ +#define _(sym,str) UDPS_TX_ERROR_##sym, + foreach_udps_tx_error +#undef _ + UDPS_TX_N_ERROR, +} udps_tx_error_t; + +static char *udps_tx_error_strings[] = { +#define _(sym,string) string, + foreach_udps_tx_error +#undef _ +}; + +typedef enum +{ + UDPS_TX_NEXT_DROP, + UDPS_TX_NEXT_INTERFACE_TX, + UDPS_TX_N_NEXT, +} udps_tx_next_t; + void udps_node_policy_apply(u32 sw_if_index, u8 is_rx) { @@ -32,17 +75,53 @@ udps_node_policy_remove(u32 sw_if_index, u8 is_rx) } } +static uword +udps_node_common_internal (vlib_main_t *vm, + vlib_node_runtime_t *node, + vlib_frame_t *frame, + bool is_rx) +{ + return 0; +} + VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) { - return 0; + u32 counter[UDPS_RX_N_ERROR] = {0}; + udps_node_common_internal(vm, node, frame, true); + counter[UDPS_RX_ERROR_UDPS_RX]++; +#define _(n, s) \ +{ \ + if (counter[UDPS_RX_ERROR_##n]) { \ + vlib_node_increment_counter(vm, node->node_index, \ + UDPS_RX_ERROR_##n, \ + counter[UDPS_RX_ERROR_##n]); \ + } \ +} + foreach_udps_rx_error +#undef _ + return 0; } VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) { + u32 counter[UDPS_TX_N_ERROR] = {0}; + udps_node_common_internal(vm, node, frame, false); + counter[UDPS_TX_ERROR_UDPS_TX]++; +#define _(n, s) \ +{ \ + if (counter[UDPS_TX_ERROR_##n]) { \ + vlib_node_increment_counter(vm, node->node_index, \ + UDPS_TX_ERROR_##n, \ + counter[UDPS_TX_ERROR_##n]); \ + } \ +} + foreach_udps_tx_error +#undef _ + return 0; } @@ -55,8 +134,8 @@ VLIB_REGISTER_NODE (udps_rx_node) = .type = VLIB_NODE_TYPE_INTERNAL, .n_next_nodes = VNET_DEVICE_INPUT_N_NEXT_NODES, .next_nodes = VNET_DEVICE_INPUT_NEXT_NODES, - .n_errors = 0, - .error_strings = NULL, + .n_errors = ARRAY_LEN(udps_rx_error_strings), + .error_strings = udps_rx_error_strings, }; VNET_FEATURE_INIT (udps_rx_node, static) = @@ -72,9 +151,14 @@ VLIB_REGISTER_NODE (udps_tx_node) = .vector_size = sizeof (u32), .format_trace = NULL, .type = VLIB_NODE_TYPE_INTERNAL, - .n_next_nodes = 0, - .n_errors = 0, - .error_strings = NULL, + .n_next_nodes = UDPS_TX_N_NEXT, + .n_errors = ARRAY_LEN(udps_tx_error_strings), + .error_strings = udps_tx_error_strings, + .next_nodes = { + [UDPS_TX_NEXT_DROP] = "error-drop", + [UDPS_TX_NEXT_INTERFACE_TX] = "interface-tx", + } + }; VNET_FEATURE_INIT (udps_tx_node, static) = From 1ff575676f814422645c7f335a082a823cc6bcc2 Mon Sep 17 00:00:00 2001 From: Rajith Ramakrishna Date: Thu, 15 Dec 2022 10:47:59 +0000 Subject: [PATCH 09/23] Added all set apis --- src/plugins/udps/udps.h | 4 +- src/plugins/udps/udps_db.c | 139 ++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 2 deletions(-) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h index 3e5781234a46..3c5f24037b20 100644 --- a/src/plugins/udps/udps.h +++ b/src/plugins/udps/udps.h @@ -3,6 +3,8 @@ #define UDPS_NO_PORT (~0) #define UDPS_NO_ACTION (NULL) +#define UDPS_INVALID_RULE (~0) +#define UDPS_INVALID_POLICY_ID (~0) enum udps_rewrite_oper_e { UDPS_REWRITE_UNUSED = 0, @@ -111,7 +113,7 @@ void udps_db_policy_apply(u32 sw_if_index, u8 is_rx, u8 *name); /* Removes policy on interface in the given direction. */ -void udps_db_policy_remove(u32 sw_if_index, u8 is_rx, u8 *name); +void udps_db_policy_remove(u32 sw_if_index, u8 is_rx); /* Applies policy on interface in the given direction. */ diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c index 86710f7745fa..201112d639a6 100644 --- a/src/plugins/udps/udps_db.c +++ b/src/plugins/udps/udps_db.c @@ -1,8 +1,46 @@ #include "udps_includes.h" +udps_main_t udps_main; + + +bool udps_db_rule_policy_get(u8 *name, udps_policy_entry_t **pe); + void udps_db_rule_action_add(u8 *name, u8 oper, u16 offset, u8 *value, u8 len, u32 out_port) { + udps_rewrite_t rw; + udps_rule_action_t *ra; + u32 act_id; + bool ret; + + ret = udps_db_rule_action_get(name, &ra); + if (false == ret) { + pool_get(udps_main.action_db, ra); + act_id = ra - udps_main.action_db; + ra->name = format(0, "%s%c", name, 0); + ra->rewrite = NULL; + ra->out_port = UDPS_NO_PORT; + } + rw.oper = oper; + switch(oper) { + case UDPS_REWRITE_INSERT: + case UDPS_REWRITE_REPLACE: + rw.offset = offset; + rw.value = vec_dup(value); + vec_add1(ra->rewrite, rw); + break; + case UDPS_REWRITE_REMOVE: + rw.offset = offset; + rw.len = len; + vec_add1(ra->rewrite, rw); + break; + } + if (UDPS_NO_PORT != out_port) { + ra->out_port = out_port; + } + if (false == ret){ + hash_set_mem(udps_main.action_by_name, name, act_id); + } } bool @@ -14,6 +52,15 @@ udps_db_rule_action_del(u8 *name) bool udps_db_rule_action_get(u8 *name, udps_rule_action_t **ra) { + uword *p; + u32 act_id; + + p = hash_get_mem(udps_main.action_by_name, name); + if (!p) { + return false; + } + act_id = p[0]; + *ra = pool_elt_at_index(udps_main.action_db, act_id); return true; } @@ -26,6 +73,44 @@ udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, udps_rule_action_t **ra bool udps_db_rule_entry_add(u8 *name, u8 id, u8 oper, u16 offset, u8 *value, u8 *aname) { + udps_rule_entry_t ir = {UDPS_INVALID_RULE}; + udps_match_pkt_t mp; + udps_rule_action_t *ra; + udps_policy_entry_t *pe; + u32 policy_id; + u32 act_id; + bool ret; + + if (aname) { + ret = udps_db_rule_action_get(aname, &ra); + if (false == ret) { + return false; + } + act_id = ra - udps_main.action_db; + } + + ret = udps_db_rule_policy_get(name, &pe); + if (false == ret) { + pool_get(udps_main.policy_db, pe); + policy_id = pe - udps_main.policy_db; + pe->name = format(0, "%s%c", name, 0); + pe->rules = NULL; + } + vec_validate_init_empty(pe->rules, id, ir); + pe->rules[id].rule_id = id; + switch(oper) { + case UDPS_MATCH_PKT: + mp.offset = offset; + mp.value = vec_dup(value); + vec_add1(pe->rules[id].match_pkt, mp); + break; + } + if (aname) { + pe->rules[id].act_id = act_id; + } + if (false == ret){ + hash_set_mem(udps_main.policy_by_name, name, policy_id); + } return true; } @@ -47,13 +132,65 @@ udps_db_rule_policy_del(u8 *name) return true; } +bool +udps_db_rule_policy_get(u8 *name, udps_policy_entry_t **pe) +{ + uword *p; + u32 policy_id; + + p = hash_get_mem(udps_main.policy_by_name, name); + if (!p) { + return false; + } + policy_id = p[0]; + *pe = pool_elt_at_index(udps_main.policy_db, policy_id); + return true; +} + + void udps_db_policy_apply(u32 sw_if_index, u8 is_rx, u8 *name) { + uword *p; + u32 policy_id; + + p = hash_get_mem(udps_main.policy_by_name, name); + if (!p) { + return; + } + policy_id = p[0]; + + if (is_rx) { + vec_validate_init_empty(udps_main.ing_policy_by_sw_if_index, + sw_if_index, UDPS_INVALID_POLICY_ID); + udps_main.ing_policy_by_sw_if_index[sw_if_index] = policy_id; + } else { + vec_validate_init_empty(udps_main.egr_policy_by_sw_if_index, + sw_if_index, UDPS_INVALID_POLICY_ID); + udps_main.egr_policy_by_sw_if_index[sw_if_index] = policy_id; + } } void -udps_db_policy_remove(u32 sw_if_index, u8 is_rx, u8 *name) +udps_db_policy_remove(u32 sw_if_index, u8 is_rx) { + if (is_rx) { + vec_validate_init_empty(udps_main.ing_policy_by_sw_if_index, + sw_if_index, UDPS_INVALID_POLICY_ID); + udps_main.ing_policy_by_sw_if_index[sw_if_index] = UDPS_INVALID_POLICY_ID; + } else { + vec_validate_init_empty(udps_main.egr_policy_by_sw_if_index, + sw_if_index, UDPS_INVALID_POLICY_ID); + udps_main.egr_policy_by_sw_if_index[sw_if_index] = UDPS_INVALID_POLICY_ID; + } +} + +static clib_error_t* +udps_db_init (vlib_main_t *vm) +{ + udps_main.action_by_name = hash_create_string(0, sizeof(uword)); + udps_main.policy_by_name = hash_create_string(0, sizeof(uword)); + return 0; } +VLIB_INIT_FUNCTION (udps_db_init); From 20f76e86b6b6b437804bc0afe0191d160b40a300 Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Thu, 15 Dec 2022 11:37:35 +0000 Subject: [PATCH 10/23] node loop for 1 pkt processing --- src/plugins/udps/udps_node.c | 114 ++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 15 deletions(-) diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c index 606bb93d8828..1ec565d72223 100644 --- a/src/plugins/udps/udps_node.c +++ b/src/plugins/udps/udps_node.c @@ -75,22 +75,59 @@ udps_node_policy_remove(u32 sw_if_index, u8 is_rx) } } -static uword -udps_node_common_internal (vlib_main_t *vm, - vlib_node_runtime_t *node, - vlib_frame_t *frame, - bool is_rx) -{ - return 0; -} - VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) { u32 counter[UDPS_RX_N_ERROR] = {0}; - udps_node_common_internal(vm, node, frame, true); - counter[UDPS_RX_ERROR_UDPS_RX]++; + u32 n_left_from, *from, *to_next; + vnet_device_input_next_t next_index; + + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; /* number of packets to process */ + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + /* get space to enqueue frame to graph node "next_index" */ + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0; + vlib_buffer_t *b0; + u32 next0; + u32 sw_if_index0; + + /* speculatively enqueue b0 to the current next frame */ + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; + + /* Determine the next node */ + next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? + + // Do the business logic + counter[UDPS_RX_ERROR_UDPS_RX]++; + + /* verify speculative enqueue, maybe switch current next frame */ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, + to_next, n_left_to_next, + bi0, next0); + } + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + #define _(n, s) \ { \ if (counter[UDPS_RX_ERROR_##n]) { \ @@ -101,7 +138,7 @@ VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, } foreach_udps_rx_error #undef _ - return 0; + return frame->n_vectors; } VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, @@ -109,8 +146,55 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, vlib_frame_t *frame) { u32 counter[UDPS_TX_N_ERROR] = {0}; - udps_node_common_internal(vm, node, frame, false); - counter[UDPS_TX_ERROR_UDPS_TX]++; + u32 n_left_from, *from, *to_next; + udps_tx_next_t next_index; + + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; /* number of packets to process */ + next_index = node->cached_next_index; + + while (n_left_from > 0) + { + u32 n_left_to_next; + + /* get space to enqueue frame to graph node "next_index" */ + vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + + while (n_left_from > 0 && n_left_to_next > 0) + { + u32 bi0; + vlib_buffer_t *b0; + u32 next0; + u32 sw_if_index0; + + /* speculatively enqueue b0 to the current next frame */ + bi0 = from[0]; + to_next[0] = bi0; + from += 1; + to_next += 1; + n_left_from -= 1; + n_left_to_next -= 1; + + b0 = vlib_get_buffer (vm, bi0); + + sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; + + /* Determine the next node */ + next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? + + // Do the business logic + counter[UDPS_TX_ERROR_UDPS_TX]++; + + /* verify speculative enqueue, maybe switch current next frame */ + vlib_validate_buffer_enqueue_x1 (vm, node, next_index, + to_next, n_left_to_next, + bi0, next0); + } + vlib_put_next_frame (vm, node, next_index, n_left_to_next); + } + + + #define _(n, s) \ { \ if (counter[UDPS_TX_ERROR_##n]) { \ @@ -122,7 +206,7 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, foreach_udps_tx_error #undef _ - return 0; + return frame->n_vectors; } /* *INDENT-OFF* */ From fd950a1b41656d9c707aa6f0acee51df709211eb Mon Sep 17 00:00:00 2001 From: Rajith Ramakrishna Date: Thu, 15 Dec 2022 12:27:54 +0000 Subject: [PATCH 11/23] Added match api for the lookup --- src/plugins/udps/udps.h | 2 +- src/plugins/udps/udps_db.c | 77 +++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h index 3c5f24037b20..15020e8acdcc 100644 --- a/src/plugins/udps/udps.h +++ b/src/plugins/udps/udps.h @@ -80,7 +80,7 @@ bool udps_db_rule_action_get(u8 *name, udps_rule_action_t **ra); If present, rule action is returned in ra. Otherwise, returns false. */ -bool udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, udps_rule_action_t **ra); +bool udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, u16 len, udps_rule_action_t **ra); /* Add a rule entry. Creates rule entry if not present. diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c index 201112d639a6..0a5260c5afd1 100644 --- a/src/plugins/udps/udps_db.c +++ b/src/plugins/udps/udps_db.c @@ -4,6 +4,7 @@ udps_main_t udps_main; bool udps_db_rule_policy_get(u8 *name, udps_policy_entry_t **pe); +bool udps_db_policy_get_by_sw_if_index(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe); void udps_db_rule_action_add(u8 *name, u8 oper, u16 offset, u8 *value, u8 len, u32 out_port) @@ -65,8 +66,61 @@ udps_db_rule_action_get(u8 *name, udps_rule_action_t **ra) } bool -udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, udps_rule_action_t **ra) +udps_db_rule_match_pkt(u8 *bytes, u16 len, udps_match_pkt_t *mp) { + u32 mpl = mp->offset + vec_len(mp->value); + bool ret = true; + + if (mpl > len) { + return false; + } + + for (int i = mp->offset; i < mpl; i++) { + if (bytes[i] != mp->value[i]) { + ret = false; + break; + } + } + return ret; +} + +bool +udps_db_rule_item_match(u8 *bytes, u16 len, udps_rule_entry_t *re) +{ + bool ret; + + for (int i = 0; i < vec_len(re->match_pkt); i++) { + ret = udps_db_rule_match_pkt(bytes, len, &re->match_pkt[i]); + if (false == ret) { + return false; + } + } + return true; +} + + +bool +udps_db_rule_match(u32 sw_if_index, u8 is_rx, u8 *bytes, u16 len, udps_rule_action_t **ra) +{ + udps_policy_entry_t *pe; + u32 i; + bool ret; + + ret = udps_db_policy_get_by_sw_if_index(sw_if_index, is_rx, &pe); + if (false == ret) { + return false; + } + ret = false; + for (i = 0; i < vec_len(pe->rules); i++) { + ret = udps_db_rule_item_match(bytes, len, &pe->rules[i]); + if (true == ret) { + break; + } + } + if (false == ret) { + return false; + } + *ra = pool_elt_at_index(udps_main.action_db, pe->rules[i].act_id); return true; } @@ -185,6 +239,27 @@ udps_db_policy_remove(u32 sw_if_index, u8 is_rx) } } +bool +udps_db_policy_get_by_sw_if_index(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe) +{ + u32 policy_id; + + if (is_rx) { + vec_validate_init_empty(udps_main.ing_policy_by_sw_if_index, + sw_if_index, UDPS_INVALID_POLICY_ID); + policy_id = udps_main.ing_policy_by_sw_if_index[sw_if_index]; + } else { + vec_validate_init_empty(udps_main.egr_policy_by_sw_if_index, + sw_if_index, UDPS_INVALID_POLICY_ID); + policy_id = udps_main.egr_policy_by_sw_if_index[sw_if_index]; + } + if (UDPS_INVALID_POLICY_ID == policy_id) { + return false; + } + *pe = pool_elt_at_index(udps_main.policy_db, policy_id); + return true; +} + static clib_error_t* udps_db_init (vlib_main_t *vm) { From a96feca70d937216e2d7f6dd0e5910229193ee38 Mon Sep 17 00:00:00 2001 From: Rajith Ramakrishna Date: Thu, 15 Dec 2022 14:43:47 +0000 Subject: [PATCH 12/23] Completed get apis --- src/plugins/udps/udps.h | 2 +- src/plugins/udps/udps_db.c | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h index 15020e8acdcc..8145857aae96 100644 --- a/src/plugins/udps/udps.h +++ b/src/plugins/udps/udps.h @@ -3,7 +3,7 @@ #define UDPS_NO_PORT (~0) #define UDPS_NO_ACTION (NULL) -#define UDPS_INVALID_RULE (~0) +#define UDPS_INVALID_RULE (255) #define UDPS_INVALID_POLICY_ID (~0) enum udps_rewrite_oper_e { diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c index 0a5260c5afd1..2ba2b76878bb 100644 --- a/src/plugins/udps/udps_db.c +++ b/src/plugins/udps/udps_db.c @@ -2,7 +2,7 @@ udps_main_t udps_main; - +/* Forward declaration of pvt functions */ bool udps_db_rule_policy_get(u8 *name, udps_policy_entry_t **pe); bool udps_db_policy_get_by_sw_if_index(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe); @@ -156,7 +156,7 @@ udps_db_rule_entry_add(u8 *name, u8 id, u8 oper, u16 offset, u8 *value, u8 *anam case UDPS_MATCH_PKT: mp.offset = offset; mp.value = vec_dup(value); - vec_add1(pe->rules[id].match_pkt, mp); + vec_add1(pe->rules[id].match_pkt, mp); break; } if (aname) { @@ -171,12 +171,33 @@ udps_db_rule_entry_add(u8 *name, u8 id, u8 oper, u16 offset, u8 *value, u8 *anam u8 udps_db_rule_entry_cnt(u8 *name) { - return 0; + udps_policy_entry_t *pe; + bool ret; + + ret = udps_db_rule_policy_get(name, &pe); + if (false == ret) { + return 0; + } + return vec_len(pe->rules); } bool udps_db_rule_entry_get(u8 *name, u8 id, udps_rule_entry_t **re) { + udps_policy_entry_t *pe; + bool ret; + + ret = udps_db_rule_policy_get(name, &pe); + if (false == ret) { + return false; + } + if (id >= vec_len(pe->rules)) { + return false; + } + if (pe->rules[id].rule_id == UDPS_INVALID_RULE) { + return false; + } + *re = &pe->rules[id]; return true; } From ae08e0ebf57711937284f8d18f3b4f25b8da7778 Mon Sep 17 00:00:00 2001 From: VM Date: Thu, 15 Dec 2022 15:07:28 +0000 Subject: [PATCH 13/23] set commands --- src/plugins/udps/udps_cli.c | 138 ++++++++++++++++++++++++++++++++++-- 1 file changed, 133 insertions(+), 5 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index a82d702ef1dc..66a1fadcf057 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -19,7 +19,59 @@ static clib_error_t * udps_policy_action_set (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { + vnet_main_t *vnm = vnet_get_main (); + u8* action_name = 0; + u8* rewrite_str = 0; + u32 out_port = UDPS_NO_PORT; clib_error_t *error = 0; + u32 offset_val = 0, len = 0; + enum udps_rewrite_oper_e oper = UDPS_REWRITE_UNUSED; + u8 offset_set = 0, name_set = 0, insert_set = 0, replace_set = 0, remove_set = 0, out_port_set = 0, rewrite_str_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %s", &action_name)) { + name_set = 1; + } else if (unformat(input, "offset %u", &offset_val)) { + offset_set = 1; + } else if (unformat(input, "insert")) { + insert_set = 1; + } else if (unformat(input, "replace")) { + replace_set = 1; + } else if (unformat(input, "rewrite_string %U", unformat_hex_string, &rewrite_str)) { + rewrite_str_set = 1; + } else if (unformat(input, "remove %u", &len)) { + remove_set = 1; + } else if (unformat(input, "out-port %U", unformat_vnet_sw_interface, vnm, &out_port)) { + out_port_set = 1; + } else { + vlib_cli_output(vm, "ERROR: Specify policy-action name " + " [offset [ [insert|replace] rewrite_string ]" + " | remove ] [out-port ]\n"); + return 0; + } + } + + if (!name_set || !offset_set) { + vlib_cli_output(vm, "ERROR: Invalid Command"); + return error; + } + + if (replace_set) { + oper = UDPS_REWRITE_REPLACE; + } else if (remove_set) { + oper = UDPS_REWRITE_REMOVE; + } else if (insert_set) { + oper = UDPS_REWRITE_INSERT; + } else { + oper = UDPS_REWRITE_UNUSED; + } + vlib_cli_output(vm, "Got below params: action name=%s, offset=%u, oper=%u, len=%d, out_port=%d", + action_name, offset_val, oper, len, out_port); + + vlib_cli_output(vm, "\n Hex rewrite_str :"); + for (int i =0; i [ [insert|replace] rewrite_string ] | remove ]" + .short_help = "set udps policy-action name " + "[offset [ [insert|replace] rewrite_string ] | [remove ]]" " [out-port ]", }; /* *INDENT-ON* */ @@ -92,6 +144,50 @@ udps_policy_set (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; + u8* policy_name = 0, *action_name = 0; + u8* val_str = 0; + u32 offset_val = 0, id = 0; + u8 offset_set = 0, name_set = 0, action_set = 0, rule_id_set = 0, val_str_set = 0; + + enum udps_match_oper_e oper; + + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %s", &policy_name)) { + name_set = 1; + } else if(unformat(input, "rule %u", &id)) { + rule_id_set = 1; + } else if (unformat(input, "offset %u", &offset_val)) { + offset_set = 1; + } else if (unformat(input, "val %U", unformat_hex_string, &val_str)) { + val_str_set = 1; + } else if (unformat(input, "action %s", &action_name)) { + action_set = 1; + } else { + vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); + return 0; + } + } + + if (!name_set || !rule_id_set) { + vlib_cli_output(vm, "ERROR: Invalid Command"); + return error; + } + + vlib_cli_output(vm, "Got below params: action name=%s, rule=%u, offset=%u, action=%s", + policy_name, id, offset_val, action_name); + + vlib_cli_output(vm, "\n Hex val_str :"); + for (int i =0; i val ] [ action ]", + .short_help = "set udps policy name rule [ offset val ] [ action ]", }; /* *INDENT-ON* */ @@ -163,6 +258,39 @@ udps_policy_interface_set (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; + u32 if_name; + vnet_main_t *vnm = vnet_get_main (); + u8* policy_name = 0; + u8 rx_set = 0, tx_set = 0, policy_set = 0, name_set = 0; + + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %U", unformat_vnet_sw_interface, vnm, &if_name)) { + name_set = 1; + } else if(unformat(input, "direction")) { + if (unformat(input, "rx")) { + rx_set = 1; + } else if (unformat(input, "tx")) { + tx_set = 1; + } else { + vlib_cli_output(vm, "ERROR: Invalid direction\n"); + return 0; + } + } else if (unformat(input, "policy %s", &policy_name)) { + policy_set = 1; + } else { + vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); + return 0; + } + } + + if (!name_set || !(rx_set || tx_set) || !policy_set ) { + vlib_cli_output(vm, "ERROR: Invalid Command"); + return error; + } + + vlib_cli_output(vm, "Got below params: if name=%d, rx_set=%d, tx_set=%d, policy=%s", + if_name, rx_set, tx_set, policy_name); + udps_db_policy_apply(if_name, rx_set, policy_name); vlib_cli_output(vm, "udps_policy_interface_set, WORK in PROGRESS, retry later\n"); return error; } @@ -176,7 +304,7 @@ udps_policy_interface_set (vlib_main_t * vm, VLIB_CLI_COMMAND (set_udps_policy_interface_command, static) = { .path = "set udps interface", .function = udps_policy_interface_set, - .short_help = "set udps interface direction policy ", + .short_help = "set udps interface name direction policy ", }; /* *INDENT-ON* */ From 860cef60fa5db837a14dc3bf675d1e2d58157eb8 Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Thu, 15 Dec 2022 16:46:14 +0000 Subject: [PATCH 14/23] rule action implemented in rx/tx nodes --- src/plugins/udps/udps_node.c | 107 +++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 6 deletions(-) diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c index 1ec565d72223..508061deb552 100644 --- a/src/plugins/udps/udps_node.c +++ b/src/plugins/udps/udps_node.c @@ -1,8 +1,11 @@ #include "udps_includes.h" #define foreach_udps_rx_error \ - _(UDPS_RX, "UDPS_RX outgoing packets") \ - _(DROP, "UDPS_RX drops") + _(UDPS_RX, "UDPS outgoing packets") \ + _(RULE_MATCHED, "Rule matched on intf") \ + _(RULE_ACTION_FOUND, "Rule action found") \ + _(VALID_OUT_PORT, "Out port rewritten") \ + _(DROP, "UDPS drop pkt") typedef enum { @@ -19,8 +22,11 @@ static char *udps_rx_error_strings[] = { }; #define foreach_udps_tx_error \ - _(UDPS_TX, "UDPS_TX outgoing packets") \ - _(DROP, "UDPS_TX drops") + _(UDPS_TX, "UDPS outgoing packets") \ + _(RULE_MATCHED, "Rule matched on intf") \ + _(RULE_ACTION_FOUND, "Rule action found") \ + _(VALID_OUT_PORT, "Out port rewritten") \ + _(DROP, "UDPS drop pkt") typedef enum { @@ -74,7 +80,59 @@ udps_node_policy_remove(u32 sw_if_index, u8 is_rx) 0, 0, 0); } } +void +udps_apply_rule_action (vlib_main_t *vm, + vlib_buffer_t * b, + udps_rule_action_t *ra, + bool is_rx) +{ + u32 offset, len; + u8 *write_ptr; + /* rewrite the out_port and be done with this */ + if (ra->out_port != UDPS_NO_PORT) { + vnet_buffer (b)->sw_if_index[VLIB_TX] = ra->out_port; + } + + /* loop through all the rewrite actions and apply them one by one */ + for (int i = 0; i < vec_len(ra->rewrite); i++) { + switch(ra->rewrite[i].oper) { + case UDPS_REWRITE_INSERT: + offset = ra->rewrite[i].offset; + len = ra->rewrite[i].len; + vlib_buffer_advance(b, offset); + vlib_buffer_move(vm, b, (len + offset)); + /* alter pkt len and rewind current_data*/ + b->current_length += len; + b->current_data -= len; + write_ptr = vlib_buffer_get_current (b); + clib_memcpy_fast (write_ptr, (u8 *)ra->rewrite[i].value, len); + /*rewind to start of l2 header again*/ + vlib_buffer_advance(b, -offset); + break; + case UDPS_REWRITE_REPLACE: + offset = ra->rewrite[i].offset; + len = ra->rewrite[i].len; + vlib_buffer_advance(b, offset); + write_ptr = vlib_buffer_get_current (b); + clib_memcpy_fast (write_ptr, (u8 *)ra->rewrite[i].value, len); + /*rewind to start of l2 header again*/ + vlib_buffer_advance(b, -offset); + break; + case UDPS_REWRITE_REMOVE: + offset = ra->rewrite[i].offset; + len = ra->rewrite[i].len; + vlib_buffer_advance(b, len+offset); + vlib_buffer_move(vm, b, offset); + /*rewind to start of l2 header again*/ + vlib_buffer_advance(b, -offset); + break; + default: + break; + } + } + return; +} VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) @@ -100,6 +158,8 @@ VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, vlib_buffer_t *b0; u32 next0; u32 sw_if_index0; + u8 *eth; + udps_rule_action_t *ra = NULL; /* speculatively enqueue b0 to the current next frame */ bi0 = from[0]; @@ -116,9 +176,23 @@ VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, /* Determine the next node */ next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? - // Do the business logic + /* Do the business logic */ counter[UDPS_RX_ERROR_UDPS_RX]++; - + + eth = (u8 *)vlib_buffer_get_current (b0); + if (udps_db_rule_match(sw_if_index0, true, eth, + vlib_buffer_length_in_chain(vm, b0),&ra)) { + counter[UDPS_RX_ERROR_RULE_MATCHED]++; + if (ra) { + counter[UDPS_RX_ERROR_RULE_ACTION_FOUND]++; + /* apply Rule action on b(0) */ + udps_apply_rule_action(vm, b0, ra, true); + if (ra->out_port != UDPS_NO_PORT) { + counter[UDPS_RX_ERROR_VALID_OUT_PORT]++; + } + } + } + /* verify speculative enqueue, maybe switch current next frame */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, @@ -166,6 +240,10 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, vlib_buffer_t *b0; u32 next0; u32 sw_if_index0; + vnet_sw_interface_t *tx_parent_intf; + vnet_main_t *vnm = vnet_get_main (); + u8 *eth; + udps_rule_action_t *ra = NULL; /* speculatively enqueue b0 to the current next frame */ bi0 = from[0]; @@ -178,10 +256,27 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, b0 = vlib_get_buffer (vm, bi0); sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; + tx_parent_intf = vnet_get_sup_sw_interface (vnm, sw_if_index0); + + sw_if_index0 = tx_parent_intf->sw_if_index; /* Determine the next node */ next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? + eth = (u8 *)vlib_buffer_get_current (b0); + if (udps_db_rule_match(sw_if_index0, false, eth, + vlib_buffer_length_in_chain(vm, b0),&ra)) { + counter[UDPS_TX_ERROR_RULE_MATCHED]++; + if (ra) { + counter[UDPS_TX_ERROR_RULE_ACTION_FOUND]++; + /* apply Rule action on b(0) */ + udps_apply_rule_action(vm, b0, ra, false); + if (ra->out_port != UDPS_NO_PORT) { + counter[UDPS_TX_ERROR_VALID_OUT_PORT]++; + } + } + } + // Do the business logic counter[UDPS_TX_ERROR_UDPS_TX]++; From b502589741caae8a64f1ed4169bb31bd05807a4d Mon Sep 17 00:00:00 2001 From: VM Date: Thu, 15 Dec 2022 17:06:32 +0000 Subject: [PATCH 15/23] show_cli_changes --- src/plugins/udps/udps_cli.c | 104 ++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 4 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index 66a1fadcf057..70fb1a43ce6c 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -92,13 +92,51 @@ VLIB_CLI_COMMAND (set_udps_policy_action_command, static) = { }; /* *INDENT-ON* */ +void +udps_dump_policy_action (vlib_main_t * vm, u8* action_name) +{ + udps_rule_action_t *ra; + bool ret = udps_db_rule_action_get(action_name, &ra); + if (!ret) { + vlib_cli_output(vm, "No policy action found for given name"); + return; + } + vlib_cli_output(vm, "Policy action_name=%s out_port=%d oper=%u offset=%d", + ra->name, ra->out_port, ra->rewrite->oper, ra->rewrite->offset); + if (ra->rewrite->oper == UDPS_REWRITE_REMOVE) { + vlib_cli_output(vm, "len=%d", ra->rewrite->len); + } + + vlib_cli_output(vm, "value: "); + for (int i =0; irewrite->value);i++) { + vlib_cli_output(vm, "%x",ra->rewrite->value[i]); + } +} static clib_error_t * udps_policy_action_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; - vlib_cli_output(vm, "udps_policy_action_show, WORK in PROGRESS, retry later\n"); + u8* action_name = 0; + u8 name_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %s", &action_name)) { + name_set = 1; + } else { + vlib_cli_output(vm, "ERROR: Cli not in correct form\n"); + return 0; + } + } + + if (!name_set) { + vlib_cli_output(vm, "ERROR: Invalid Command"); + return error; + } + + vlib_cli_output(vm, "got action name=%s", action_name); + udps_dump_policy_action(vm, action_name); + vlib_cli_output(vm, "udps_policy_action_show, WORK in PROGRESS, \n"); return error; } @@ -111,7 +149,7 @@ udps_policy_action_show (vlib_main_t * vm, VLIB_CLI_COMMAND (show_udps_policy_action_command, static) = { .path = "show udps policy-action", .function = udps_policy_action_show, - .short_help = "show udps policy-action ", + .short_help = "show udps policy-action name ", .is_mp_safe = 1, }; /* *INDENT-ON* */ @@ -207,11 +245,51 @@ VLIB_CLI_COMMAND (set_udps_policy_command, static) = { /* *INDENT-ON* */ +void +udps_dump_policy_rule_by_id (vlib_main_t * vm, u8* policy_name, u32 id) +{ + udps_rule_entry_t *re; + bool ret = udps_db_rule_entry_get(policy_name, id, &re); + if (!ret) { + vlib_cli_output(vm, "No policy rule found for given name and id"); + return; + } + vlib_cli_output(vm, "Policy name=%s rule id=%u action_id=%u offset=%d value= ", + policy_name, re->rule_id, re->act_id, re->match_pkt->offset); + + for (int i =0; imatch_pkt->value);i++) { + vlib_cli_output(vm, "%x",re->match_pkt->value[i]); + } +} + static clib_error_t * udps_policy_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; + u8* policy_name = 0; + u32 id = 0; + u8 name_set = 0, rule_id_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %s", &policy_name)) { + name_set = 1; + } else if(unformat(input, "rule %u", &id)) { + rule_id_set = 1; + } else { + vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); + return 0; + } + } + + if (!name_set || !rule_id_set) { + vlib_cli_output(vm, "ERROR: Invalid Command"); + return error; + } + + vlib_cli_output(vm, "Got below params: policy name=%s, rule=%u", + policy_name, id); + + udps_dump_policy_rule_by_id(vm, policy_name, id); vlib_cli_output(vm, "udps_policy_show, WORK in PROGRESS, retry later\n"); return error; } @@ -225,7 +303,7 @@ udps_policy_show (vlib_main_t * vm, VLIB_CLI_COMMAND (show_udps_policy_command, static) = { .path = "show udps policy", .function = udps_policy_show, - .short_help = "show udps policy ", + .short_help = "show udps policy name rule ", .is_mp_safe = 1, }; /* *INDENT-ON* */ @@ -314,6 +392,24 @@ udps_policy_interface_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; + vnet_main_t *vnm = vnet_get_main (); + u32 if_name; + u8 name_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %U", unformat_vnet_sw_interface, vnm, &if_name)) { + name_set = 1; + } else { + vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); + return 0; + } + } + + if (!name_set) { + vlib_cli_output(vm, "Error: Interface name required\n"); + return 0; + } + + vlib_cli_output(vm, "got if_sw_index = %d", if_name); vlib_cli_output(vm, "udps_policy_show, WORK in PROGRESS, retry later\n"); return error; } @@ -327,7 +423,7 @@ udps_policy_interface_show (vlib_main_t * vm, VLIB_CLI_COMMAND (show_udps_policy_interface_command, static) = { .path = "show udps interface", .function = udps_policy_interface_show, - .short_help = "show udps interface ", + .short_help = "show udps interface name ", .is_mp_safe = 1, }; /* *INDENT-ON* */ From 15f67f8b22781d3d6a4e27a5e10336ee07313e6b Mon Sep 17 00:00:00 2001 From: Bhuvan Mital Date: Thu, 15 Dec 2022 19:00:26 +0000 Subject: [PATCH 16/23] bug fix in interface-tx name --- src/plugins/udps/udps_node.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c index 508061deb552..9a43039f03fb 100644 --- a/src/plugins/udps/udps_node.c +++ b/src/plugins/udps/udps_node.c @@ -45,7 +45,6 @@ static char *udps_tx_error_strings[] = { typedef enum { UDPS_TX_NEXT_DROP, - UDPS_TX_NEXT_INTERFACE_TX, UDPS_TX_N_NEXT, } udps_tx_next_t; @@ -244,6 +243,7 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, vnet_main_t *vnm = vnet_get_main (); u8 *eth; udps_rule_action_t *ra = NULL; + vnet_hw_interface_t *hi0; /* speculatively enqueue b0 to the current next frame */ bi0 = from[0]; @@ -260,8 +260,8 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, sw_if_index0 = tx_parent_intf->sw_if_index; - /* Determine the next node */ - next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? + /* Do the business logic */ + counter[UDPS_TX_ERROR_UDPS_TX]++; eth = (u8 *)vlib_buffer_get_current (b0); if (udps_db_rule_match(sw_if_index0, false, eth, @@ -276,10 +276,8 @@ VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, } } } - - // Do the business logic - counter[UDPS_TX_ERROR_UDPS_TX]++; - + hi0 = vnet_get_sup_hw_interface (vnm,vnet_buffer (b0)->sw_if_index[VLIB_TX]); + next0 = hi0->output_node_next_index; /* verify speculative enqueue, maybe switch current next frame */ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, @@ -335,7 +333,6 @@ VLIB_REGISTER_NODE (udps_tx_node) = .error_strings = udps_tx_error_strings, .next_nodes = { [UDPS_TX_NEXT_DROP] = "error-drop", - [UDPS_TX_NEXT_INTERFACE_TX] = "interface-tx", } }; From 77d9561280f3d5e95747456e6c616b1985dfe465 Mon Sep 17 00:00:00 2001 From: Rajith Date: Fri, 16 Dec 2022 05:48:31 +0000 Subject: [PATCH 17/23] Fixes found during integration --- src/plugins/udps/udps_cli.c | 1 + src/plugins/udps/udps_db.c | 6 +- src/plugins/udps/udps_node.c | 153 +++-------------------------------- 3 files changed, 14 insertions(+), 146 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index 70fb1a43ce6c..c3f52c755be8 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -369,6 +369,7 @@ udps_policy_interface_set (vlib_main_t * vm, vlib_cli_output(vm, "Got below params: if name=%d, rx_set=%d, tx_set=%d, policy=%s", if_name, rx_set, tx_set, policy_name); udps_db_policy_apply(if_name, rx_set, policy_name); + udps_node_policy_apply(if_name, rx_set); vlib_cli_output(vm, "udps_policy_interface_set, WORK in PROGRESS, retry later\n"); return error; } diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c index 2ba2b76878bb..2e0279d46664 100644 --- a/src/plugins/udps/udps_db.c +++ b/src/plugins/udps/udps_db.c @@ -75,8 +75,8 @@ udps_db_rule_match_pkt(u8 *bytes, u16 len, udps_match_pkt_t *mp) return false; } - for (int i = mp->offset; i < mpl; i++) { - if (bytes[i] != mp->value[i]) { + for (int i = mp->offset, j = 0; i < mpl; i++) { + if (bytes[i] != mp->value[j++]) { ret = false; break; } @@ -263,7 +263,7 @@ udps_db_policy_remove(u32 sw_if_index, u8 is_rx) bool udps_db_policy_get_by_sw_if_index(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe) { - u32 policy_id; + int policy_id; if (is_rx) { vec_validate_init_empty(udps_main.ing_policy_by_sw_if_index, diff --git a/src/plugins/udps/udps_node.c b/src/plugins/udps/udps_node.c index 9a43039f03fb..9bb97445db2f 100644 --- a/src/plugins/udps/udps_node.c +++ b/src/plugins/udps/udps_node.c @@ -21,33 +21,6 @@ static char *udps_rx_error_strings[] = { #undef _ }; -#define foreach_udps_tx_error \ - _(UDPS_TX, "UDPS outgoing packets") \ - _(RULE_MATCHED, "Rule matched on intf") \ - _(RULE_ACTION_FOUND, "Rule action found") \ - _(VALID_OUT_PORT, "Out port rewritten") \ - _(DROP, "UDPS drop pkt") - -typedef enum -{ -#define _(sym,str) UDPS_TX_ERROR_##sym, - foreach_udps_tx_error -#undef _ - UDPS_TX_N_ERROR, -} udps_tx_error_t; - -static char *udps_tx_error_strings[] = { -#define _(sym,string) string, - foreach_udps_tx_error -#undef _ -}; - -typedef enum -{ - UDPS_TX_NEXT_DROP, - UDPS_TX_N_NEXT, -} udps_tx_next_t; - void udps_node_policy_apply(u32 sw_if_index, u8 is_rx) { @@ -85,7 +58,7 @@ udps_apply_rule_action (vlib_main_t *vm, udps_rule_action_t *ra, bool is_rx) { - u32 offset, len; + int offset, len; u8 *write_ptr; /* rewrite the out_port and be done with this */ if (ra->out_port != UDPS_NO_PORT) { @@ -97,7 +70,7 @@ udps_apply_rule_action (vlib_main_t *vm, switch(ra->rewrite[i].oper) { case UDPS_REWRITE_INSERT: offset = ra->rewrite[i].offset; - len = ra->rewrite[i].len; + len = vec_len(ra->rewrite[i].value); vlib_buffer_advance(b, offset); vlib_buffer_move(vm, b, (len + offset)); /* alter pkt len and rewind current_data*/ @@ -110,7 +83,7 @@ udps_apply_rule_action (vlib_main_t *vm, break; case UDPS_REWRITE_REPLACE: offset = ra->rewrite[i].offset; - len = ra->rewrite[i].len; + len = vec_len(ra->rewrite[i].value); vlib_buffer_advance(b, offset); write_ptr = vlib_buffer_get_current (b); clib_memcpy_fast (write_ptr, (u8 *)ra->rewrite[i].value, len); @@ -173,7 +146,8 @@ VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; /* Determine the next node */ - next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? + //next0 = VNET_DEVICE_INPUT_NEXT_ETHERNET_INPUT; // is this correct ?? + next0 = 0; /* Do the business logic */ counter[UDPS_RX_ERROR_UDPS_RX]++; @@ -188,6 +162,7 @@ VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, udps_apply_rule_action(vm, b0, ra, true); if (ra->out_port != UDPS_NO_PORT) { counter[UDPS_RX_ERROR_VALID_OUT_PORT]++; + next0 = 1; } } } @@ -214,94 +189,6 @@ VLIB_NODE_FN (udps_rx_node) (vlib_main_t *vm, return frame->n_vectors; } -VLIB_NODE_FN (udps_tx_node) (vlib_main_t *vm, - vlib_node_runtime_t *node, - vlib_frame_t *frame) -{ - u32 counter[UDPS_TX_N_ERROR] = {0}; - u32 n_left_from, *from, *to_next; - udps_tx_next_t next_index; - - from = vlib_frame_vector_args (frame); - n_left_from = frame->n_vectors; /* number of packets to process */ - next_index = node->cached_next_index; - - while (n_left_from > 0) - { - u32 n_left_to_next; - - /* get space to enqueue frame to graph node "next_index" */ - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); - - while (n_left_from > 0 && n_left_to_next > 0) - { - u32 bi0; - vlib_buffer_t *b0; - u32 next0; - u32 sw_if_index0; - vnet_sw_interface_t *tx_parent_intf; - vnet_main_t *vnm = vnet_get_main (); - u8 *eth; - udps_rule_action_t *ra = NULL; - vnet_hw_interface_t *hi0; - - /* speculatively enqueue b0 to the current next frame */ - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - - sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; - tx_parent_intf = vnet_get_sup_sw_interface (vnm, sw_if_index0); - - sw_if_index0 = tx_parent_intf->sw_if_index; - - /* Do the business logic */ - counter[UDPS_TX_ERROR_UDPS_TX]++; - - eth = (u8 *)vlib_buffer_get_current (b0); - if (udps_db_rule_match(sw_if_index0, false, eth, - vlib_buffer_length_in_chain(vm, b0),&ra)) { - counter[UDPS_TX_ERROR_RULE_MATCHED]++; - if (ra) { - counter[UDPS_TX_ERROR_RULE_ACTION_FOUND]++; - /* apply Rule action on b(0) */ - udps_apply_rule_action(vm, b0, ra, false); - if (ra->out_port != UDPS_NO_PORT) { - counter[UDPS_TX_ERROR_VALID_OUT_PORT]++; - } - } - } - hi0 = vnet_get_sup_hw_interface (vnm,vnet_buffer (b0)->sw_if_index[VLIB_TX]); - next0 = hi0->output_node_next_index; - /* verify speculative enqueue, maybe switch current next frame */ - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, - to_next, n_left_to_next, - bi0, next0); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); - } - - - -#define _(n, s) \ -{ \ - if (counter[UDPS_TX_ERROR_##n]) { \ - vlib_node_increment_counter(vm, node->node_index, \ - UDPS_TX_ERROR_##n, \ - counter[UDPS_TX_ERROR_##n]); \ - } \ -} - foreach_udps_tx_error -#undef _ - - return frame->n_vectors; -} - /* *INDENT-OFF* */ VLIB_REGISTER_NODE (udps_rx_node) = { @@ -309,8 +196,10 @@ VLIB_REGISTER_NODE (udps_rx_node) = .vector_size = sizeof (u32), .format_trace = NULL, .type = VLIB_NODE_TYPE_INTERNAL, - .n_next_nodes = VNET_DEVICE_INPUT_N_NEXT_NODES, - .next_nodes = VNET_DEVICE_INPUT_NEXT_NODES, + .n_next_nodes = 2, + .next_nodes = { [0] = "ethernet-input", + [1] = "interface-output" + }, .n_errors = ARRAY_LEN(udps_rx_error_strings), .error_strings = udps_rx_error_strings, }; @@ -322,28 +211,6 @@ VNET_FEATURE_INIT (udps_rx_node, static) = .runs_before = VNET_FEATURES ("ethernet-input"), }; -VLIB_REGISTER_NODE (udps_tx_node) = -{ - .name = "udps-tx-node", - .vector_size = sizeof (u32), - .format_trace = NULL, - .type = VLIB_NODE_TYPE_INTERNAL, - .n_next_nodes = UDPS_TX_N_NEXT, - .n_errors = ARRAY_LEN(udps_tx_error_strings), - .error_strings = udps_tx_error_strings, - .next_nodes = { - [UDPS_TX_NEXT_DROP] = "error-drop", - } - -}; - -VNET_FEATURE_INIT (udps_tx_node, static) = -{ - .arc_name = "interface-output", - .node_name = "udps-tx-node", - .runs_before = VNET_FEATURES ("interface-tx"), -}; - VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, From 0a00917fa7a025d1e6674475f057a1170de2f724 Mon Sep 17 00:00:00 2001 From: Rajith Date: Thu, 5 Jan 2023 05:35:54 +0000 Subject: [PATCH 18/23] Made get APIs for policy public --- src/plugins/udps/udps.h | 18 ++++++++++++++++++ src/plugins/udps/udps_db.c | 4 ---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h index 8145857aae96..6568ae6c9255 100644 --- a/src/plugins/udps/udps.h +++ b/src/plugins/udps/udps.h @@ -123,4 +123,22 @@ void udps_node_policy_apply(u32 sw_if_index, u8 is_rx); */ void udps_node_policy_remove(u32 sw_if_index, u8 is_rx); +/* Get policy on interface in the given direction. + If present, policy entry is returned in pe. + Otherwise, returns false. +*/ +bool udps_db_policy_get(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe); + +/* Get policy by name. + If present, policy entry is returned in pe. + Otherwise, returns false. +*/ +bool udps_db_rule_policy_get(u8 *name, udps_policy_entry_t **pe); + +/* Get policy on interface in the given direction. + If present, policy entry is returned in pe. + Otherwise, returns false. +*/ +bool udps_db_policy_get_by_sw_if_index(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe); + #endif /* __UDPS_H__ */ diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c index 2e0279d46664..a1fcb5004387 100644 --- a/src/plugins/udps/udps_db.c +++ b/src/plugins/udps/udps_db.c @@ -2,10 +2,6 @@ udps_main_t udps_main; -/* Forward declaration of pvt functions */ -bool udps_db_rule_policy_get(u8 *name, udps_policy_entry_t **pe); -bool udps_db_policy_get_by_sw_if_index(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe); - void udps_db_rule_action_add(u8 *name, u8 oper, u16 offset, u8 *value, u8 len, u32 out_port) { From 9c1e9ba95efb1aefaa265c88e49760694c7d5aae Mon Sep 17 00:00:00 2001 From: VM Date: Thu, 5 Jan 2023 07:19:36 +0000 Subject: [PATCH 19/23] imporve policy rule and policy action cli --- src/plugins/udps/udps_cli.c | 89 +++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index c3f52c755be8..9b04546ae198 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -64,15 +64,8 @@ udps_policy_action_set (vlib_main_t * vm, } else { oper = UDPS_REWRITE_UNUSED; } - vlib_cli_output(vm, "Got below params: action name=%s, offset=%u, oper=%u, len=%d, out_port=%d", - action_name, offset_val, oper, len, out_port); - - vlib_cli_output(vm, "\n Hex rewrite_str :"); - for (int i =0; iname, ra->out_port, ra->rewrite->oper, ra->rewrite->offset); + vlib_cli_output(vm, "Policy Action"); + for (int i = 0; i < 65; i++) { + strcat(delimiter, "-"); + } + vlib_cli_output(vm, "%s\n", delimiter); + vlib_cli_output(vm,"%-40s : %s", "Policy Action name", ra->name); + vlib_cli_output(vm,"%-40s : %d", "Out-port", ra->out_port); + vlib_cli_output(vm,"%-40s : %s", "Oper", udps_oper_id_to_name(ra->rewrite->oper)); + vlib_cli_output(vm,"%-40s : %d", "Packet Offset", ra->rewrite->offset); if (ra->rewrite->oper == UDPS_REWRITE_REMOVE) { - vlib_cli_output(vm, "len=%d", ra->rewrite->len); + vlib_cli_output(vm,"%-40s : %d", "Rewrite Length", ra->rewrite->len); } - - vlib_cli_output(vm, "value: "); - for (int i =0; irewrite->value);i++) { - vlib_cli_output(vm, "%x",ra->rewrite->value[i]); - } + vlib_cli_output(vm,"%-40s : %U", "Value", format_hex_bytes, ra->rewrite->value, vec_len(ra->rewrite->value)); } static clib_error_t * @@ -130,13 +144,10 @@ udps_policy_action_show (vlib_main_t * vm, } if (!name_set) { - vlib_cli_output(vm, "ERROR: Invalid Command"); + vlib_cli_output(vm, "ERROR: Policy action name needed!"); return error; } - - vlib_cli_output(vm, "got action name=%s", action_name); udps_dump_policy_action(vm, action_name); - vlib_cli_output(vm, "udps_policy_action_show, WORK in PROGRESS, \n"); return error; } @@ -211,14 +222,6 @@ udps_policy_set (vlib_main_t * vm, return error; } - vlib_cli_output(vm, "Got below params: action name=%s, rule=%u, offset=%u, action=%s", - policy_name, id, offset_val, action_name); - - vlib_cli_output(vm, "\n Hex val_str :"); - for (int i =0; imatch_pkt->value[i]); - } + vlib_cli_output(vm, "Policy Rule"); + for (int i = 0; i < 65; i++) { + strcat(delimiter, "-"); + } + vlib_cli_output(vm, "%s\n", delimiter); + vlib_cli_output(vm,"%-40s : %s", "Policy name", policy_name); + vlib_cli_output(vm,"%-40s : %u", "Rule Id", re->rule_id); + vlib_cli_output(vm,"%-40s : %u", "Action Id", re->act_id); + vlib_cli_output(vm,"%-40s : %d", "Packet Offset", re->match_pkt->offset); + vlib_cli_output(vm,"%-40s : %U", "Value", format_hex_bytes, re->match_pkt->value, vec_len(re->match_pkt->value)); } static clib_error_t * @@ -282,15 +290,10 @@ udps_policy_show (vlib_main_t * vm, } if (!name_set || !rule_id_set) { - vlib_cli_output(vm, "ERROR: Invalid Command"); + vlib_cli_output(vm, "ERROR: Policy name or rule id not set"); return error; } - - vlib_cli_output(vm, "Got below params: policy name=%s, rule=%u", - policy_name, id); - udps_dump_policy_rule_by_id(vm, policy_name, id); - vlib_cli_output(vm, "udps_policy_show, WORK in PROGRESS, retry later\n"); return error; } From 13ca1d2af6f85f058223c1babf7fb39a8ef8e10f Mon Sep 17 00:00:00 2001 From: Rajith Date: Thu, 5 Jan 2023 07:49:57 +0000 Subject: [PATCH 20/23] Added delete apis --- src/plugins/udps/udps.h | 6 ------ src/plugins/udps/udps_db.c | 44 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/plugins/udps/udps.h b/src/plugins/udps/udps.h index 6568ae6c9255..c0004dc723b5 100644 --- a/src/plugins/udps/udps.h +++ b/src/plugins/udps/udps.h @@ -123,12 +123,6 @@ void udps_node_policy_apply(u32 sw_if_index, u8 is_rx); */ void udps_node_policy_remove(u32 sw_if_index, u8 is_rx); -/* Get policy on interface in the given direction. - If present, policy entry is returned in pe. - Otherwise, returns false. -*/ -bool udps_db_policy_get(u32 sw_if_index, u8 is_rx, udps_policy_entry_t **pe); - /* Get policy by name. If present, policy entry is returned in pe. Otherwise, returns false. diff --git a/src/plugins/udps/udps_db.c b/src/plugins/udps/udps_db.c index a1fcb5004387..bb14a9be405f 100644 --- a/src/plugins/udps/udps_db.c +++ b/src/plugins/udps/udps_db.c @@ -36,13 +36,35 @@ udps_db_rule_action_add(u8 *name, u8 oper, u16 offset, u8 *value, u8 len, u32 ou ra->out_port = out_port; } if (false == ret){ - hash_set_mem(udps_main.action_by_name, name, act_id); + hash_set_mem(udps_main.action_by_name, ra->name, act_id); } } bool udps_db_rule_action_del(u8 *name) { + udps_rewrite_t rw; + udps_rule_action_t *ra; + bool ret; + + ret = udps_db_rule_action_get(name, &ra); + if (false == ret) { + return true; + } + hash_unset_mem(udps_main.action_by_name, ra->name); + for (int i = 0; i < vec_len(ra->rewrite); i++) { + rw = ra->rewrite[i]; + switch(rw.oper) { + case UDPS_REWRITE_INSERT: + case UDPS_REWRITE_REPLACE: + vec_free(rw.value); + break; + } + } + vec_free(ra->rewrite); + vec_free(ra->name); + pool_put(udps_main.action_db, ra); + return true; } @@ -159,7 +181,7 @@ udps_db_rule_entry_add(u8 *name, u8 id, u8 oper, u16 offset, u8 *value, u8 *anam pe->rules[id].act_id = act_id; } if (false == ret){ - hash_set_mem(udps_main.policy_by_name, name, policy_id); + hash_set_mem(udps_main.policy_by_name, pe->name, policy_id); } return true; } @@ -200,6 +222,24 @@ udps_db_rule_entry_get(u8 *name, u8 id, udps_rule_entry_t **re) bool udps_db_rule_policy_del(u8 *name) { + udps_policy_entry_t *pe; + bool ret; + + ret = udps_db_rule_policy_get(name, &pe); + if (false == ret) { + return false; + } + hash_unset_mem(udps_main.policy_by_name, pe->name); + for (int i = 0; i < vec_len(pe->rules); i++) { + for (int j = 0; j < vec_len(pe->rules[i].match_pkt); j++) { + vec_free(pe->rules[i].match_pkt[j].value); + } + vec_free(pe->rules[i].match_pkt); + } + vec_free(pe->rules); + vec_free(pe->name); + pool_put(udps_main.policy_db, pe); + return true; } From 37cc0786e52237a20d10218badd701e27fc0ad71 Mon Sep 17 00:00:00 2001 From: VM Date: Thu, 5 Jan 2023 08:58:42 +0000 Subject: [PATCH 21/23] show multiple rule per policy --- src/plugins/udps/udps_cli.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index 9b04546ae198..63357afeff10 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -266,8 +266,14 @@ udps_dump_policy_rule_by_id (vlib_main_t * vm, u8* policy_name, u32 id) vlib_cli_output(vm,"%-40s : %s", "Policy name", policy_name); vlib_cli_output(vm,"%-40s : %u", "Rule Id", re->rule_id); vlib_cli_output(vm,"%-40s : %u", "Action Id", re->act_id); - vlib_cli_output(vm,"%-40s : %d", "Packet Offset", re->match_pkt->offset); - vlib_cli_output(vm,"%-40s : %U", "Value", format_hex_bytes, re->match_pkt->value, vec_len(re->match_pkt->value)); + vlib_cli_output(vm, "%s\n", delimiter); + vlib_cli_output(vm, "Packet Matches"); + vlib_cli_output(vm, "%s\n", delimiter); + vlib_cli_output(vm, "%-40s | %s", "Packet Offset", "Value"); + for (int i = 0; imatch_pkt); i++) { + vlib_cli_output(vm,"%-40d | %U", re->match_pkt[i].offset, format_hex_bytes, re->match_pkt[i].value, vec_len(re->match_pkt[i].value)); + } + vlib_cli_output(vm, "%s\n", delimiter); } static clib_error_t * From ae85e5b476b5558deb2c71b0186aa614af729a52 Mon Sep 17 00:00:00 2001 From: VM Date: Thu, 5 Jan 2023 11:42:16 +0000 Subject: [PATCH 22/23] show policy on interface and show policy by given name --- src/plugins/udps/udps_cli.c | 114 ++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 25 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index 63357afeff10..879b1d045f2e 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -247,6 +247,49 @@ VLIB_CLI_COMMAND (set_udps_policy_command, static) = { }; /* *INDENT-ON* */ +void +udps_dump_policy_rule_by_rule_entry (vlib_main_t * vm, udps_rule_entry_t *re, char *delimiter) +{ + vlib_cli_output(vm,"%-40s : %u", "Rule Id", re->rule_id); + vlib_cli_output(vm,"%-40s : %u", "Action Id", re->act_id); + vlib_cli_output(vm, "%s\n", delimiter); + vlib_cli_output(vm, "%-40s | %s", "Packet Offset", "Value"); + for (int i = 0; imatch_pkt); i++) { + vlib_cli_output(vm,"%-40d | %U", re->match_pkt[i].offset, format_hex_bytes, re->match_pkt[i].value, vec_len(re->match_pkt[i].value)); + } + vlib_cli_output(vm, "%s\n", delimiter); +} + +void +udps_dump_policy_rule_by_policy_entry (vlib_main_t * vm, udps_policy_entry_t *pe, char *delimiter) +{ + vlib_cli_output(vm,"%-40s : %s", "Policy Name", pe->name); + vlib_cli_output(vm, "%s\n", delimiter); + + for (int i=0;i< vec_len(pe->rules); i++) { + if (pe->rules[i].rule_id == UDPS_INVALID_RULE){ + continue; + } + vlib_cli_output(vm, "\n"); + udps_dump_policy_rule_by_rule_entry(vm, &pe->rules[i], delimiter); + } +} + +void +udps_dump_policy_rule (vlib_main_t * vm, u8* policy_name) +{ + udps_policy_entry_t *pe; + char delimiter[65] = ""; + bool ret = udps_db_rule_policy_get(policy_name, &pe); + if (!ret) { + vlib_cli_output(vm, "No policy rule found for given name:%s", policy_name); + return; + } + for (int i = 0; i < 65; i++) { + strcat(delimiter, "-"); + } + udps_dump_policy_rule_by_policy_entry(vm, pe, delimiter); +} void udps_dump_policy_rule_by_id (vlib_main_t * vm, u8* policy_name, u32 id) @@ -258,22 +301,12 @@ udps_dump_policy_rule_by_id (vlib_main_t * vm, u8* policy_name, u32 id) vlib_cli_output(vm, "No policy rule found for given name:%s and id:%d", policy_name, id); return; } - vlib_cli_output(vm, "Policy Rule"); + vlib_cli_output(vm,"%-40s : %s", "Policy name", policy_name); for (int i = 0; i < 65; i++) { strcat(delimiter, "-"); } vlib_cli_output(vm, "%s\n", delimiter); - vlib_cli_output(vm,"%-40s : %s", "Policy name", policy_name); - vlib_cli_output(vm,"%-40s : %u", "Rule Id", re->rule_id); - vlib_cli_output(vm,"%-40s : %u", "Action Id", re->act_id); - vlib_cli_output(vm, "%s\n", delimiter); - vlib_cli_output(vm, "Packet Matches"); - vlib_cli_output(vm, "%s\n", delimiter); - vlib_cli_output(vm, "%-40s | %s", "Packet Offset", "Value"); - for (int i = 0; imatch_pkt); i++) { - vlib_cli_output(vm,"%-40d | %U", re->match_pkt[i].offset, format_hex_bytes, re->match_pkt[i].value, vec_len(re->match_pkt[i].value)); - } - vlib_cli_output(vm, "%s\n", delimiter); + udps_dump_policy_rule_by_rule_entry(vm, re, delimiter); } static clib_error_t * @@ -295,11 +328,17 @@ udps_policy_show (vlib_main_t * vm, } } - if (!name_set || !rule_id_set) { - vlib_cli_output(vm, "ERROR: Policy name or rule id not set"); + if (!name_set) { + vlib_cli_output(vm, "ERROR: Policy name"); return error; } - udps_dump_policy_rule_by_id(vm, policy_name, id); + + if (rule_id_set) { + udps_dump_policy_rule_by_id(vm, policy_name, id); + } else { + udps_dump_policy_rule(vm, policy_name); + } + return error; } @@ -312,7 +351,7 @@ udps_policy_show (vlib_main_t * vm, VLIB_CLI_COMMAND (show_udps_policy_command, static) = { .path = "show udps policy", .function = udps_policy_show, - .short_help = "show udps policy name rule ", + .short_help = "show udps policy name [rule ]", .is_mp_safe = 1, }; /* *INDENT-ON* */ @@ -375,11 +414,9 @@ udps_policy_interface_set (vlib_main_t * vm, return error; } - vlib_cli_output(vm, "Got below params: if name=%d, rx_set=%d, tx_set=%d, policy=%s", - if_name, rx_set, tx_set, policy_name); udps_db_policy_apply(if_name, rx_set, policy_name); udps_node_policy_apply(if_name, rx_set); - vlib_cli_output(vm, "udps_policy_interface_set, WORK in PROGRESS, retry later\n"); + vlib_cli_output(vm, "Policy applied on interface successfully\n"); return error; } @@ -396,6 +433,24 @@ VLIB_CLI_COMMAND (set_udps_policy_interface_command, static) = { }; /* *INDENT-ON* */ +void +udps_dump_interface_policy (vlib_main_t * vm, u32 if_index, u8 is_rx) +{ + udps_policy_entry_t *pe; + char delimiter[65] = ""; + bool ret = udps_db_policy_get_by_sw_if_index(if_index, is_rx, &pe); + if (!ret) { + vlib_cli_output(vm, "No policy entry found for given if_index:%d and direction :%s", + if_index, is_rx?"RX":"TX"); + return; + } + vlib_cli_output(vm, "Interface Policy sw_if_index=%d Direction=%s", if_index, is_rx?"RX":"TX"); + for (int i = 0; i < 65; i++) { + strcat(delimiter, "-"); + } + vlib_cli_output(vm, "%s\n\n", delimiter); + udps_dump_policy_rule_by_policy_entry(vm, pe, delimiter); +} static clib_error_t * udps_policy_interface_show (vlib_main_t * vm, @@ -405,22 +460,31 @@ udps_policy_interface_show (vlib_main_t * vm, vnet_main_t *vnm = vnet_get_main (); u32 if_name; u8 name_set = 0; + u8 rx_set = 0, tx_set = 0; while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { if (unformat(input, "name %U", unformat_vnet_sw_interface, vnm, &if_name)) { name_set = 1; + } else if(unformat(input, "direction")) { + if (unformat(input, "rx")) { + rx_set = 1; + } else if (unformat(input, "tx")) { + tx_set = 1; + } else { + vlib_cli_output(vm, "ERROR: Invalid direction\n"); + return 0; + } } else { vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); return 0; } } - if (!name_set) { - vlib_cli_output(vm, "Error: Interface name required\n"); + if (!name_set || (!rx_set && !tx_set)) { + vlib_cli_output(vm, "Error: Interface name and direction required\n"); return 0; } - - vlib_cli_output(vm, "got if_sw_index = %d", if_name); - vlib_cli_output(vm, "udps_policy_show, WORK in PROGRESS, retry later\n"); + + udps_dump_interface_policy (vm, if_name, rx_set); return error; } @@ -433,7 +497,7 @@ udps_policy_interface_show (vlib_main_t * vm, VLIB_CLI_COMMAND (show_udps_policy_interface_command, static) = { .path = "show udps interface", .function = udps_policy_interface_show, - .short_help = "show udps interface name ", + .short_help = "show udps interface name direction ", .is_mp_safe = 1, }; /* *INDENT-ON* */ From 229d9f0d468022a547a054de5df18f9ad20ea38e Mon Sep 17 00:00:00 2001 From: VM Date: Fri, 6 Jan 2023 06:36:17 +0000 Subject: [PATCH 23/23] delete cli --- src/plugins/udps/udps_cli.c | 65 +++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/plugins/udps/udps_cli.c b/src/plugins/udps/udps_cli.c index 879b1d045f2e..380332db5b3c 100644 --- a/src/plugins/udps/udps_cli.c +++ b/src/plugins/udps/udps_cli.c @@ -170,7 +170,23 @@ udps_policy_action_delete (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; - vlib_cli_output(vm, "udps_policy_action_delete, WORK in PROGRESS, retry later\n"); + u8* action_name = 0; + u8 name_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %s", &action_name)) { + name_set = 1; + } else { + vlib_cli_output(vm, "ERROR: Cli not in correct form\n"); + return 0; + } + } + + if (!name_set) { + vlib_cli_output(vm, "ERROR: Policy action name needed!"); + return error; + } + udps_db_rule_action_del(action_name); + vlib_cli_output(vm, "Policy action deleted successfully"); return error; } @@ -361,7 +377,23 @@ udps_policy_delete (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; - vlib_cli_output(vm, "udps_policy_delete, WORK in PROGRESS, retry later\n"); + u8* policy_name = 0; + u8 name_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %s", &policy_name)) { + name_set = 1; + } else { + vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); + return 0; + } + } + + if (!name_set) { + vlib_cli_output(vm, "ERROR: Policy rule name required."); + return error; + } + udps_db_rule_policy_del(policy_name); + vlib_cli_output(vm, "Policy rule deleted successfully \n"); return error; } @@ -507,7 +539,34 @@ udps_policy_interface_delete (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { clib_error_t *error = 0; - vlib_cli_output(vm, "udps_policy_interface_delete, WORK in PROGRESS, retry later\n"); + vnet_main_t *vnm = vnet_get_main (); + u32 if_name; + u8 name_set = 0; + u8 rx_set = 0, tx_set = 0; + while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { + if (unformat(input, "name %U", unformat_vnet_sw_interface, vnm, &if_name)) { + name_set = 1; + } else if(unformat(input, "direction")) { + if (unformat(input, "rx")) { + rx_set = 1; + } else if (unformat(input, "tx")) { + tx_set = 1; + } else { + vlib_cli_output(vm, "ERROR: Invalid direction\n"); + return 0; + } + } else { + vlib_cli_output(vm, "ERROR: CLI not in proper form\n"); + return 0; + } + } + + if (!name_set || (!rx_set && !tx_set)) { + vlib_cli_output(vm, "Error: Interface name and direction required\n"); + return 0; + } + udps_db_policy_remove(if_name, rx_set); + vlib_cli_output(vm, "Interface Policy Deleted Successfully\n"); return error; }