diff options
| author | songyanchao <[email protected]> | 2022-04-11 02:30:50 -0400 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2022-04-20 04:18:50 -0400 |
| commit | 64956be1c26ed3b81c8c5b49ae3441e76d167c78 (patch) | |
| tree | ea037b642dace73ec8cecb6deaefc560c9a11abf /tools | |
| parent | 2b2d4e9ae4e47b5532e4de180f07fd5e840f8277 (diff) | |
✨ feat(TSG-10157): Cli 支持TCP Item
Offload Cli Tools 支持TCP类型的Item
https://jira.geedge.net/browse/TSG-10157?filter=-1
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mrctl/mrctl.c | 92 |
1 files changed, 91 insertions, 1 deletions
diff --git a/tools/mrctl/mrctl.c b/tools/mrctl/mrctl.c index ce99698..08a554c 100644 --- a/tools/mrctl/mrctl.c +++ b/tools/mrctl/mrctl.c @@ -45,6 +45,12 @@ enum mr_cli_arg MR_CLI_ITEM_UDP_SRC_PORT_MASK, MR_CLI_ITEM_UDP_DST_PORT, MR_CLI_ITEM_UDP_DST_PORT_MASK, + MR_CLI_ITEM_TCP, + MR_CLI_ITEM_TCP_SRC_PORT, + MR_CLI_ITEM_TCP_SRC_PORT_MASK, + MR_CLI_ITEM_TCP_DST_PORT, + MR_CLI_ITEM_TCP_DST_PORT_MASK, + MR_CLI_ITEM_TCP_FLAGS, MR_CLI_ACTION_COUNT, MR_CLI_ACTION_COUNT_SHARED, MR_CLI_ACTION_COUNT_ID, @@ -100,6 +106,12 @@ static struct option cli_options[] = {"udp_sport_mask", required_argument,NULL, MR_CLI_ITEM_UDP_SRC_PORT_MASK}, {"udp_dport", required_argument,NULL, MR_CLI_ITEM_UDP_DST_PORT}, {"udp_dport_mask", required_argument,NULL, MR_CLI_ITEM_UDP_DST_PORT_MASK}, + {"tcp", no_argument,NULL, MR_CLI_ITEM_TCP}, + {"tcp_sport", required_argument,NULL, MR_CLI_ITEM_TCP_SRC_PORT}, + {"tcp_sport_mask", required_argument,NULL, MR_CLI_ITEM_TCP_SRC_PORT_MASK}, + {"tcp_dport", required_argument,NULL, MR_CLI_ITEM_TCP_DST_PORT}, + {"tcp_dport_mask", required_argument,NULL, MR_CLI_ITEM_TCP_DST_PORT_MASK}, + {"tcp_flags", required_argument,NULL, MR_CLI_ITEM_TCP_FLAGS}, {"count", no_argument,NULL, MR_CLI_ACTION_COUNT}, {"shared", no_argument,NULL, MR_CLI_ACTION_COUNT_SHARED}, {"countid", required_argument,NULL, MR_CLI_ACTION_COUNT_ID}, @@ -247,7 +259,7 @@ void default_rule_create(struct mrctl_instance * instance) int send_request_msg(struct mrctl_instance * instance, struct mrctl_offload_rule * rule_item) { cJSON *cjson_rule = NULL,*cjson_attr = NULL,*cjson_action = NULL,*cjson_action_count = NULL,*cjson_action_drop = NULL; - cJSON *cjson_item = NULL,*cjson_ether_item = NULL,*cjson_ipv4_item = NULL,*cjson_udp_item = NULL; + cJSON *cjson_item = NULL,*cjson_ether_item = NULL,*cjson_ipv4_item = NULL,*cjson_udp_item = NULL,*cjson_tcp_item = NULL; struct ctrl_msg_offload_creat_request req_msg; ctrl_msg_header_construct(&req_msg.msg_header, sizeof(req_msg), CTRL_MSG_TYPE_REQUEST, CTRLMSG_TOPIC_OFFLOAD_CREATE); @@ -258,6 +270,7 @@ int send_request_msg(struct mrctl_instance * instance, struct mrctl_offload_rule cjson_ether_item = cJSON_CreateObject(); cjson_ipv4_item = cJSON_CreateObject(); cjson_udp_item = cJSON_CreateObject(); + cjson_tcp_item = cJSON_CreateObject(); cjson_action = cJSON_CreateObject(); cjson_action_count = cJSON_CreateObject(); cjson_action_drop = cJSON_CreateObject(); @@ -429,6 +442,41 @@ int send_request_msg(struct mrctl_instance * instance, struct mrctl_offload_rule cJSON_AddItemToObject(cjson_item,MR_CJSON_KEY_UDP,cjson_udp_item); } + + /* TCP Item */ + if (rule_item->item_list & MR_RULE_FLOW_ITEM_LIST_TCP) + { + struct mr_offload_item_tcp * tcp_item = &rule_item->items[MR_RULE_FLOW_ITEM_TCP].tcp_item; + cJSON_AddNumberToObject(cjson_tcp_item, MR_CJSON_KEY_ARG_FLG, tcp_item->arg_flg); + + if(tcp_item->arg_flg & MR_RULE_FLOW_TCP_ARG_SRC_PORT_ENABLE) + { + cJSON_AddNumberToObject(cjson_tcp_item, MR_CJSON_KEY_TCP_SRC_PORT, tcp_item->tcp_hdr.src_port); + } + + if(tcp_item->arg_flg & MR_RULE_FLOW_TCP_ARG_SRC_PORT_MASK_ENABLE) + { + cJSON_AddNumberToObject(cjson_tcp_item, MR_CJSON_KEY_TCP_SRC_PORT_MASK, tcp_item->tcp_mask.src_port); + } + + if(tcp_item->arg_flg & MR_RULE_FLOW_TCP_ARG_DST_PORT_ENABLE) + { + cJSON_AddNumberToObject(cjson_tcp_item, MR_CJSON_KEY_TCP_DST_PORT, tcp_item->tcp_hdr.dst_port); + } + + if(tcp_item->arg_flg & MR_RULE_FLOW_TCP_ARG_DST_PORT_MASK_ENABLE) + { + cJSON_AddNumberToObject(cjson_tcp_item, MR_CJSON_KEY_TCP_DST_PORT_MASK, tcp_item->tcp_mask.dst_port); + } + + if(tcp_item->arg_flg & MR_RULE_FLOW_TCP_ARG_FLAGS_ENABLE) + { + cJSON_AddNumberToObject(cjson_tcp_item, MR_CJSON_KEY_TCP_FLAGS, tcp_item->tcp_hdr.tcp_flags); + } + + cJSON_AddItemToObject(cjson_item,MR_CJSON_KEY_TCP,cjson_tcp_item); + } + cJSON_AddItemToObject(cjson_rule,MR_CJSON_KEY_ITEMS,cjson_item); /* Action */ @@ -490,6 +538,7 @@ int main(int argc, char * argv[]) struct mr_offload_item_ether * ether_item = NULL; struct mr_offload_item_ipv4 * ipv4_item = NULL; struct mr_offload_item_udp * udp_item = NULL; + struct mr_offload_item_tcp * tcp_item = NULL; struct mr_offload_action_count * count_action = NULL; memset(&rule_item, 0, sizeof(rule_item)); @@ -497,6 +546,7 @@ int main(int argc, char * argv[]) ether_item = &rule_item.items[MR_RULE_FLOW_ITEM_ETHER].ether_item; ipv4_item = &rule_item.items[MR_RULE_FLOW_ITEM_IPV4].ipv4_item; udp_item = &rule_item.items[MR_RULE_FLOW_ITEM_UDP].udp_item; + tcp_item = &rule_item.items[MR_RULE_FLOW_ITEM_TCP].tcp_item; count_action = &rule_item.actions[MR_RULE_FLOW_ACTION_COUNT].count; @@ -812,6 +862,46 @@ int main(int argc, char * argv[]) break; } + /* TCP Item */ + case MR_CLI_ITEM_TCP: + { + printf("TCP !!!\n"); + rule_item.rule_flg |= MR_RULE_ITEM_ENABLE; + rule_item.item_list |= MR_RULE_FLOW_ITEM_LIST_TCP; + rule_item.item_num ++; + break; + } + case MR_CLI_ITEM_TCP_SRC_PORT: + { + tcp_item->arg_flg |= MR_RULE_FLOW_TCP_ARG_SRC_PORT_ENABLE; + tcp_item->tcp_hdr.src_port = (uint16_t)strtoull(optarg, &endptr, 0); + break; + } + case MR_CLI_ITEM_TCP_SRC_PORT_MASK: + { + tcp_item->arg_flg |= MR_RULE_FLOW_TCP_ARG_SRC_PORT_MASK_ENABLE; + tcp_item->tcp_mask.src_port = (uint16_t)strtoull(optarg, &endptr, 0); + break; + } + case MR_CLI_ITEM_TCP_DST_PORT: + { + tcp_item->arg_flg |= MR_RULE_FLOW_TCP_ARG_DST_PORT_ENABLE; + tcp_item->tcp_hdr.dst_port = (uint16_t)strtoull(optarg, &endptr, 0); + break; + } + case MR_CLI_ITEM_TCP_DST_PORT_MASK: + { + tcp_item->arg_flg |= MR_RULE_FLOW_TCP_ARG_DST_PORT_MASK_ENABLE; + tcp_item->tcp_mask.dst_port = (uint16_t)strtoull(optarg, &endptr, 0); + break; + } + case MR_CLI_ITEM_TCP_FLAGS: + { + tcp_item->arg_flg |= MR_RULE_FLOW_TCP_ARG_FLAGS_ENABLE; + tcp_item->tcp_hdr.tcp_flags = (uint8_t)strtoull(optarg, &endptr, 0); + break; + } + /* Action */ /* Count */ case MR_CLI_ACTION_COUNT: |
