From f4128ea4cd648d1a72d0f4b6a554e5712da4a3e9 Mon Sep 17 00:00:00 2001 From: Oussama Ghorbel <oussama.ghorbel@iopsys.eu> Date: Wed, 5 Feb 2020 11:29:10 +0100 Subject: [PATCH] update to ugw 8.4.1.30 --- cli.c | 8 +- cli_classcfg.c | 332 ++++++++++++++++++++++++++++++++++++++----------- cli_classcfg.h | 9 +- cli_ifcfg.c | 55 +++++--- cli_qcfg.c | 165 ++++++++++++++++++++---- cli_qoscfg.c | 20 +-- cli_qoscfg.h | 4 - 7 files changed, 458 insertions(+), 135 deletions(-) diff --git a/cli.c b/cli.c index a8b8ecf..74fe15f 100755 --- a/cli.c +++ b/cli.c @@ -60,6 +60,7 @@ main(int32_t argc, char** argv) { pfn_func_t pfnfunc=NULL; struct x_qoscfg_t xqoscfg; + int ret = LTQ_SUCCESS; memset_s(&xqoscfg, sizeof(xqoscfg), 0); log_type = QOS_LOG_FILE; @@ -83,6 +84,9 @@ main(int32_t argc, char** argv) LOGTYPE = xqoscfg.qoscfg.log_type; } - pfnfunc(argc,argv); - return LTQ_SUCCESS; + ret = pfnfunc(argc,argv); + if (ret != LTQ_SUCCESS) { + printf("QoS CLI Configuration Failed!\n"); + } + return ret; } diff --git a/cli_classcfg.c b/cli_classcfg.c index 073db9a..5103672 100755 --- a/cli_classcfg.c +++ b/cli_classcfg.c @@ -124,6 +124,7 @@ name_value_t axprototype[]={ {"icmp",CLI_PROTO_ICMP}, {"tcp",CLI_PROTO_TCP}, {"udp",CLI_PROTO_UDP}, + {"IGMP",CLI_PROTO_IGMP}, {"all",CLI_PROTO_ALL}, {"\0",0} }; @@ -145,6 +146,7 @@ name_value_t axfilteraction[]={ {"policer",CLI_ACTION_POLICER}, {"policyrt",CLI_ACTION_POLICYRT}, {"accl",CLI_ACTION_ACCL}, + {"meter",CLI_ACTION_METER}, {"\0",0} }; @@ -208,6 +210,7 @@ static struct option long_options[] = { {"actdscp", required_argument, 0, 0}, {"actethprio", required_argument, 0, 0}, {"mark", required_argument, 0, 0}, + {"mark_ing", required_argument, 0, 0}, {"priority", required_argument, 0, 0}, {"mark-loc", required_argument, 0, 0}, {"actaccl", required_argument, 0, 0}, @@ -228,10 +231,13 @@ static struct option long_options[] = { {"iphdr-len-min", required_argument, 0, 0}, {"iphdr-len-max", required_argument, 0, 0}, {"iphdr-dscp", required_argument, 0, 0}, + {"cl-eng", required_argument, 0, 0}, + {"id", required_argument, 0, 0}, /* Not sub commads */ {"dport", required_argument, 0, 'T'}, {"sport", required_argument, 0, 'S'}, {"tcp-flags", required_argument, 0, 'F'}, + {0,0,0,0} }; char actmp[QCLI_MAX_STR]; @@ -254,35 +260,35 @@ classcfg_show_classifiers(uint32_t order, char *sIface, int32_t num_entries, cl_ int32_t classcfg_invoke_fapi(qos_class_cfg_t *pxclscfg); static int32_t -classcfg_is_police_supported(qos_class_cfg_t xclscfg); +classcfg_is_police_supported(qos_class_cfg_t *pxclscfg); void classcfg_print_policer_usage(void); -static int32_t classcfg_is_police_supported(qos_class_cfg_t xclscfg) +static int32_t classcfg_is_police_supported(qos_class_cfg_t *pxclscfg) { -if (xclscfg.filter.param_in_ex.param_in & CLSCFG_PARAM_INNER_IP - || xclscfg.filter.param_in_ex.param_in & CLSCFG_PARAM_TX_IF - || xclscfg.filter.param_in_ex.param_in & CLSCFG_PARAM_TCP_HDR - || xclscfg.filter.param_in_ex.param_in & CLSCFG_PARAM_L7_PROTO - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_SSAP - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_DSAP - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_VLANID - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_INNER_VLANID - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_PRIO - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_INNER_PRIO - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_VLAN_DEI - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_INNER_VLAN_DEI - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_LLC_CONTROL - || xclscfg.filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_OUI - || xclscfg.filter.iphdr.param_in_ex.param_in & CLSCFG_PARAM_IP_HDR_LEN_MIN - || xclscfg.filter.iphdr.param_in_ex.param_in & CLSCFG_PARAM_IP_HDR_LEN_MAX - - || xclscfg.filter.param_in_ex.param_ex & CLSCFG_PARAM_SRC_MAC - || xclscfg.filter.param_in_ex.param_ex & CLSCFG_PARAM_DST_MAC - || xclscfg.filter.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP - || xclscfg.filter.outer_ip.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP_PROTO - || xclscfg.filter.outer_ip.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP_SRC_PORT - || xclscfg.filter.outer_ip.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP_DST_PORT - || xclscfg.filter.iphdr.param_in_ex.param_ex & CLSCFG_PARAM_IP_HDR_DSCP ) { +if (pxclscfg->filter.param_in_ex.param_in & CLSCFG_PARAM_INNER_IP + || pxclscfg->filter.param_in_ex.param_in & CLSCFG_PARAM_TX_IF + || pxclscfg->filter.param_in_ex.param_in & CLSCFG_PARAM_TCP_HDR + || pxclscfg->filter.param_in_ex.param_in & CLSCFG_PARAM_L7_PROTO + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_SSAP + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_DSAP + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_VLANID + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_INNER_VLANID + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_PRIO + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_INNER_PRIO + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_VLAN_DEI + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_INNER_VLAN_DEI + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_LLC_CONTROL + || pxclscfg->filter.ethhdr.param_in_ex.param_in & CLSCFG_PARAM_ETH_HDR_OUI + || pxclscfg->filter.iphdr.param_in_ex.param_in & CLSCFG_PARAM_IP_HDR_LEN_MIN + || pxclscfg->filter.iphdr.param_in_ex.param_in & CLSCFG_PARAM_IP_HDR_LEN_MAX + + || pxclscfg->filter.param_in_ex.param_ex & CLSCFG_PARAM_SRC_MAC + || pxclscfg->filter.param_in_ex.param_ex & CLSCFG_PARAM_DST_MAC + || pxclscfg->filter.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP + || pxclscfg->filter.outer_ip.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP_PROTO + || pxclscfg->filter.outer_ip.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP_SRC_PORT + || pxclscfg->filter.outer_ip.param_in_ex.param_ex & CLSCFG_PARAM_OUTER_IP_DST_PORT + || pxclscfg->filter.iphdr.param_in_ex.param_ex & CLSCFG_PARAM_IP_HDR_DSCP ) { printf("some/all of the configured filters are not supported with policer action\n\n"); return LTQ_FAIL; } @@ -615,7 +621,7 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud case CLI_CLSCFG_PARAM_ETH_TYPE: /*eth-type*/ pxclscfg->filter.ethhdr.eth_type = (int32_t)strtol(optarg, NULL, 0); - if ((pxclscfg->filter.ethhdr.eth_type > USHRT_MAX || pxclscfg->filter.ethhdr.eth_type == LONG_MIN) || (pxclscfg->filter.ethhdr.eth_type == 0)) { + if ((pxclscfg->filter.ethhdr.eth_type > USHRT_MAX || pxclscfg->filter.ethhdr.eth_type == INT_MIN) || (pxclscfg->filter.ethhdr.eth_type == 0)) { LOGF_LOG_ERROR("strtol failed please check the arguement\n"); exit(0); } @@ -654,12 +660,20 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud case CLI_CLSCFG_PARAM_VLAN_ID_INNER: /*vlan-id-inner*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, 4096)){ + printf("VLAN ID should be in range 0-4096"); + exit(0); + } pxclscfg->filter.ethhdr.inner_vlanid = atoi(optarg); classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ETH_HDR_INNER_VLANID, &pxclscfg->filter.ethhdr.param_in_ex); break; case CLI_CLSCFG_PARAM_VLAN_ID_OUTER: /*vlan-id-outer*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, 4096)){ + printf("VLAN ID should be in range 0-4096"); + exit(0); + } pxclscfg->filter.ethhdr.vlanid = atoi(optarg); classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ETH_HDR_VLANID, &pxclscfg->filter.param_in_ex); classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ETH_HDR_VLANID, &pxclscfg->filter.ethhdr.param_in_ex); @@ -727,30 +741,50 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud case CLI_CLSCFG_PARAM_CR: /*cr*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Validate Shaper value should be in Range of 0-%d\n", MAX_SHAPER_RANGE); + exit(0); + } pxclscfg->action.policer.cr = atoi(optarg); //classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ACT_POLICER_CR, &pxclscfg->action.policer.param_in_ex); break; case CLI_CLSCFG_PARAM_CBS: /*cbs*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Validate Shaper value should be in Range of 0-%d\n", MAX_SHAPER_RANGE); + exit(0); + } pxclscfg->action.policer.cbs = atoi(optarg); //classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ACT_POLICER_CBS, &pxclscfg->action.policer.param_in_ex); break; case CLI_CLSCFG_PARAM_PR: /*pr*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Validate Shaper value should be in Range of 0-%d\n", MAX_SHAPER_RANGE); + exit(0); + } pxclscfg->action.policer.pr = atoi(optarg); //classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ACT_POLICER_PR, &pxclscfg->action.policer.param_in_ex); break; case CLI_CLSCFG_PARAM_PBS: /*pbs*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Validate Shaper value should be in Range of 0-%d\n", MAX_SHAPER_RANGE); + exit(0); + } pxclscfg->action.policer.pbs = atoi(optarg); //classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ACT_POLICER_PBS, &pxclscfg->action.policer.param_in_ex); break; case CLI_CLSCFG_PARAM_EBS: /*ebs*/ + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Validate Shaper value should be in Range of 0-%d\n", MAX_SHAPER_RANGE); + exit(0); + } pxclscfg->action.policer.ebs = atoi(optarg); //classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ACT_POLICER_EBS, &pxclscfg->action.policer.param_in_ex); break; @@ -766,6 +800,10 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud case CLI_CLSCFG_PARAM_ACTDSCP: /*actdscp*/ + if(atoi(optarg) < 0){ + printf("ACT DSCP Value cannot be negative\n"); + exit(0); + } if(pxclscfg->action.flags & CL_ACTION_DSCP) { pxclscfg->action.dscp = atoi(optarg); } else { @@ -781,9 +819,26 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud case CLI_CLSCFG_PARAM_MARK: /*mark*/ pxclscfg->action.tc = atoi(optarg); + if((pxclscfg->action.tc <= 0) || (pxclscfg->action.tc > 16)) { + printf("Wrong TC Value, Egress TC should be b/w 1 to 16\n"); + exit(0); + } + pxclscfg->action.flags |= CL_ACTION_EGRESS_TC_SET; + break; + case CLI_CLSCFG_PARAM_MARK_ING: + /*mark_ing*/ + pxclscfg->action.tc_ing = atoi(optarg); + if((pxclscfg->action.tc_ing <= 0) || (pxclscfg->action.tc_ing > 16)) { + printf("Wrong TC Value, Ingress TC should be b/w 1 to 16\n"); + exit(0); + } + pxclscfg->action.flags |= CL_ACTION_INGRESS_TC_SET; break; - case CLI_CLSCFG_PARAM_MARK_PRIORITY: + if(!VALIDATE_RANGE(atoi(optarg), 1, MAX_PRIO)){ + printf("Wrong Priority Value Set\n"); + exit(0); + } pxclscfg->action.priority = atoi(optarg); break; @@ -791,8 +846,14 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud /*mark location*/ if(atoi(optarg) == 1) pxclscfg->action.flags &= ~CL_ACTION_TC_INGRESS; - else + else if(atoi(optarg) == 2) pxclscfg->action.flags |= CL_ACTION_TC_INGRESS; + else if(atoi(optarg) == 3) + pxclscfg->action.flags |= CL_ACTION_TC_INGRESS_EGRESS; + else { + printf("Given --mark-loc value is wrong\n"); + exit(0); + } break; case CLI_CLSCFG_PARAM_ACCL: @@ -911,7 +972,26 @@ int32_t classcfg_handle_subcmd(int32_t index, const char* optarg, int32_t exclud classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_IP_HDR, &pxclscfg->filter.param_in_ex); classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_IP_HDR_DSCP, &pxclscfg->filter.iphdr.param_in_ex); break; - + case CLI_CLSCFG_PARAM_ENGINE: + if(atoi(optarg) == 1) + pxclscfg->action.flags |= CL_ACTION_CL_SW_ENGINE; + else if(atoi(optarg) == 2) + pxclscfg->action.flags |= CL_ACTION_CL_HW_ENGINE; + else { + printf("Wrong cl-eng Value, it should be either 1 or 2\n"); + exit(0); + } + break; + case CLI_CLSCFG_PARAM_METER_ID: + if (atoi(optarg) > 1 && atoi(optarg) <= 64) { + pxclscfg->action.meter.id = atoi(optarg); + pxclscfg->action.meter.action = 2; + } + else { + printf("Invalid Meter ID\n"); + exit(0); + } + break; } return ret; } @@ -969,11 +1049,12 @@ void classcfg_print_usage(void) printf("--iphdr-len-min <length> => Minimum ip header length #\n"); printf("--iphdr-len-max <length> => Max ip header length #\n"); printf("--iphdr-dscp <dscp value> => DSCP value #\n"); + printf("--cl-eng <1/2> => Where 1 is for SW engine classification and 2 is for HW engine classification\n"); printf("-j <Action name> => Action name \n"); printf("\t [Action Values] %s\n",classcfg_getoptions(axfilteraction)); printf("\t When J is POLICER => --policer <name> --cr < commited rate> --cbs <commited burst size> --pr <peak rate> \n"); printf("\t --pbs <peak burst size> --ebr <excess burst rate> --actdscp <dscpval> --actdrop <dropval> --actethprio <ethprio>\n"); - printf("\t When J is MARK => --mark <tcval> --mark-loc <1/2> where 1 is for egress queue and 2 for ingress queue\n"); + printf("\t When J is MARK => --mark <tcval> --mark_ing <tcval> ingress tc value, --mark-loc <1/2/3> where 1 is for egress queue, 2 for ingress queue, 3 for egress queue and ingress queue\n"); printf("\t When J is DSCP => --actdscp <dscpval>\n"); printf("\t When J is DROP => --actdrop <dropval>\n"); printf("\t When J is VLAN => --vid-inner <VLANID> --vid-outer <VLANID> --pcp-inner <pcpval> --pcp-outer <pcpval> \n"); @@ -1031,6 +1112,51 @@ int32_t classcfg_invoke_fapi(qos_class_cfg_t *pxclscfg) } if(( pxclscfg->filter.flags & CL_FILTER_ADD ) || (pxclscfg->filter.flags & CL_FILTER_DELETE ) || pxclscfg->filter.flags & CL_FILTER_MODIFY) { + /*Validate --mark-loc and TC's*/ + if((pxclscfg->action.flags & CL_ACTION_TC_INGRESS_EGRESS)) { + if(!(pxclscfg->action.flags & CL_ACTION_EGRESS_TC_SET)) { + printf("--mark-loc is both ingress/egress but --mark <egress tc> is not set\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + if(!(pxclscfg->action.flags & CL_ACTION_INGRESS_TC_SET)) { + printf("--mark-loc is both ingress/egress but --mark_ing <ingress tc> is not set\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + if(pxclscfg->action.flags & CL_ACTION_CL_HW_ENGINE) { + printf("--mark-loc is both ingress/egress supportted only with SW Engine\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + } else { + if(!(pxclscfg->action.flags & CL_ACTION_TC_INGRESS)) { + if(!(pxclscfg->action.flags & CL_ACTION_EGRESS_TC_SET)) { + printf("--mark-loc is egress but --mark <egress TC> is not set\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + if(pxclscfg->action.flags & CL_ACTION_INGRESS_TC_SET) { + printf("--mark-loc is egress but --mark_ing <ingress tc> is set\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + } + } + + if(pxclscfg->action.flags & CL_ACTION_TC_INGRESS) { + if(pxclscfg->action.flags & CL_ACTION_EGRESS_TC_SET) { + printf("--mark-loc is ingress but --mark <egress tc> is set\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + if(!(pxclscfg->action.flags & CL_ACTION_INGRESS_TC_SET)) { + printf("--mark-loc is ingress but --mark_ing <ingress tc> is not set\n"); + iret = QOS_CL_INVALID_TC; + goto exit_lbl; + } + } + iret = fapi_qos_classifier_set(pxclscfg->filter.order, pxclscfg->filter, pxclscfg->action, pxclscfg->filter.flags); //fprintf(stderr, "l7proto:%s, flags:%s\n",pxclscfg->filter.l7_proto,(pxclscfg->filter.param_in_ex.param_in & CLSCFG_PARAM_L7_PROTO)?"yes":"No"); } else if( pxclscfg->filter.flags & CL_FILTER_GET ) { @@ -1040,6 +1166,7 @@ int32_t classcfg_invoke_fapi(qos_class_cfg_t *pxclscfg) os_free(filter); os_free(action); } +exit_lbl: if(iret<0){ nRet = find_error_message(iret, sErrMsg); printf("Classifier configuration failed.\n"); @@ -1056,7 +1183,7 @@ int32_t classcfg_main(int32_t argc, char**argv) { int32_t c, option_index = 0, exclude=0, proto_configured=0; qos_class_cfg_t xclscfg; - int32_t ret = -1; + int32_t ret = -1, i = 0; int32_t acclflag = 0; char subStr[3][64] = {0}; int32_t nSubCnt = 0; @@ -1090,31 +1217,61 @@ int32_t classcfg_main(int32_t argc, char**argv) case 'A': //action add xclscfg.filter.flags |= CL_FILTER_ADD; - if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) - { - printf("Error copying filter name!!\n"); - exit(0); - } + if (strnlen_s(optarg,QCLI_MAX_STR) > MAX_QUEUE_NAME_LEN) { + printf("Error Classifier Name len exceed Max Len\n"); + return LTQ_FAIL; + } + for (i = 0; i < MAX_QUEUE_NAME_LEN && optarg[i] != '\0'; i++) { + if (IS_SPECIAL_CHAR(optarg[i])) { + printf("Special Character is not allowed in Classifier Name\n"); + return LTQ_FAIL; + } + } + if (strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) + { + printf("Error copying filter name!!\n"); + return LTQ_FAIL; + } classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_FILTER_NAME, &xclscfg.filter.param_in_ex); break; case 'M': //action modify splitStr(optarg, ":", subStr, &nSubCnt); - if( nSubCnt == 2) { - xclscfg.filter.order = atoi(subStr[0]); - if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), subStr[1], strnlen_s(subStr[1], QCLI_MAX_STR)) != EOK) - { - printf("Error copying filter name!!\n"); - exit(0); + if( nSubCnt == 2) { + xclscfg.filter.order = atoi(subStr[0]); + if(strnlen_s(subStr[1],QCLI_MAX_STR) > MAX_QUEUE_NAME_LEN){ + printf("Error Classifier Name len exceed Max Len\n"); + return LTQ_FAIL; + } + for (i = 0; i < MAX_QUEUE_NAME_LEN && subStr[1][i] != '\0'; i++) { + if (IS_SPECIAL_CHAR(subStr[1][i])) { + printf("Special Character is not allowed in Classifier Name\n"); + return LTQ_FAIL; + } + } + if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), subStr[1], strnlen_s(subStr[1], QCLI_MAX_STR)) != EOK) + { + printf("Error copying filter name!!\n"); + return LTQ_FAIL; + } + } else { + if(strnlen_s(optarg,QCLI_MAX_STR) > MAX_QUEUE_NAME_LEN){ + printf("Error Classifier Name len exceed Max Len\n"); + return LTQ_FAIL; + } + for (i = 0; i < MAX_QUEUE_NAME_LEN && optarg[i] != '\0'; i++) { + if (IS_SPECIAL_CHAR(optarg[i])) { + printf("Special Character is not allowed in Classifier Name\n"); + return LTQ_FAIL; + } + } + if (strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) + { + printf("Error copying filter name!!\n"); + return LTQ_FAIL; + } } - }else { - if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) - { - printf("Error copying filter name!!\n"); - exit(0); - } - } xclscfg.filter.flags |= CL_FILTER_MODIFY; classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_FILTER_NAME, &xclscfg.filter.param_in_ex); //freeSubStr(subStr, nSubCnt); @@ -1130,24 +1287,47 @@ int32_t classcfg_main(int32_t argc, char**argv) return LTQ_FAIL; } xclscfg.filter.flags |= CL_FILTER_ADD; + if (!validate_range(atoi(subStr[0]), 1, MAX_RULES)) { + return QOS_INVALID_CL_ORDER_RANGE; + } xclscfg.filter.order = atoi(subStr[0]); classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_ORDER_NUM, &xclscfg.filter.param_in_ex); - if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), subStr[1], strnlen_s(subStr[1], QCLI_MAX_STR)) != EOK) - { - printf("Error copying filter name!!\n"); - exit(0); - } + if (strnlen_s(subStr[1], QCLI_MAX_STR) > MAX_QUEUE_NAME_LEN) { + printf("Error Classifier Name len exceed Max Len\n"); + return LTQ_FAIL; + } + for (i = 0; i < MAX_QUEUE_NAME_LEN && subStr[1][i] != '\0'; i++) { + if (IS_SPECIAL_CHAR(subStr[1][i])) { + printf("Special Character is not allowed in Classifier Name\n"); + return LTQ_FAIL; + } + } + if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), subStr[1], strnlen_s(subStr[1], QCLI_MAX_STR)) != EOK) + { + printf("Error copying filter name!!\n"); + return LTQ_FAIL; + } classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_FILTER_NAME, &xclscfg.filter.param_in_ex); //freeSubStr(subStr, nSubCnt); break; case 'D': xclscfg.filter.flags |= CL_FILTER_DELETE; - if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) + if (strnlen_s(optarg,QCLI_MAX_STR) > MAX_QUEUE_NAME_LEN) { + printf("Error Classifier Name len exceed Max Len\n"); + return LTQ_FAIL; + } + for (i = 0; i < MAX_QUEUE_NAME_LEN && optarg[i] != '\0'; i++) { + if (IS_SPECIAL_CHAR(optarg[i])) { + printf("Special Character is not allowed in Classifier Name\n"); + return LTQ_FAIL; + } + } + if(strncpy_s(xclscfg.filter.name, sizeof(xclscfg.filter.name), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) { - printf("Error copying filter name!!\n"); - exit(0); - } + printf("Error copying filter name!!\n"); + return LTQ_FAIL; + } classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_FILTER_NAME, &xclscfg.filter.param_in_ex); break; @@ -1235,6 +1415,10 @@ int32_t classcfg_main(int32_t argc, char**argv) xclscfg.filter.outer_ip.ip_p = CLI_PROTO_UDP; break; + case CLI_PROTO_IGMP: + xclscfg.filter.outer_ip.ip_p = CLI_PROTO_IGMP; + break; + case CLI_PROTO_ALL: xclscfg.filter.outer_ip.ip_p = CLI_PROTO_ALL; break; @@ -1250,20 +1434,20 @@ int32_t classcfg_main(int32_t argc, char**argv) break; case 'i': - if(strncpy_s(xclscfg.filter.rx_if, sizeof(xclscfg.filter.rx_if), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) - { - printf("Error copying filter Rx iface!!\n"); - exit(0); - } + if(strncpy_s(xclscfg.filter.rx_if, sizeof(xclscfg.filter.rx_if), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) + { + printf("Error copying filter Rx iface!!\n"); + return LTQ_FAIL; + } classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_RX_IF, &xclscfg.filter.param_in_ex); break; case 'o': - if(strncpy_s(xclscfg.filter.tx_if, sizeof(xclscfg.filter.tx_if), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) + if(strncpy_s(xclscfg.filter.tx_if, sizeof(xclscfg.filter.tx_if), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) { - printf("Error copying filter Tx iface!!\n"); - exit(0); - } + printf("Error copying filter Tx iface!!\n"); + return LTQ_FAIL; + } classcfg_set_param_in_ex(exclude, CLSCFG_PARAM_TX_IF, &xclscfg.filter.param_in_ex); break; @@ -1276,7 +1460,6 @@ int32_t classcfg_main(int32_t argc, char**argv) switch(classcfg_getval_fromname(optarg, axfilteraction)) { case CLI_ACTION_MARK: //mark xclscfg.action.flags |=CL_ACTION_TC; - xclscfg.action.tc = 1; //set capabality action tc selected //classcfg_set_param_in_ex(exclude, CL_ACTION_TC , &xclscfg.action.param_in_ex); break; @@ -1319,6 +1502,10 @@ int32_t classcfg_main(int32_t argc, char**argv) xclscfg.action.accl = acclflag; break; + case CLI_ACTION_METER: + xclscfg.action.flags |= CL_ACTION_METER; + break; + default: printf("****** Invalid filters values to -j %s\n", optarg); classcfg_print_usage(); @@ -1356,12 +1543,11 @@ int32_t classcfg_main(int32_t argc, char**argv) } if (xclscfg.action.flags & CL_ACTION_POLICER) { - if (classcfg_is_police_supported(xclscfg) == LTQ_FAIL) { + if (classcfg_is_police_supported(&xclscfg) == LTQ_FAIL) { classcfg_print_policer_usage(); - return LTQ_SUCCESS; + return LTQ_FAIL; } } - classcfg_invoke_fapi(&xclscfg); - return LTQ_SUCCESS; + return classcfg_invoke_fapi(&xclscfg); } diff --git a/cli_classcfg.h b/cli_classcfg.h index 320e972..108de63 100755 --- a/cli_classcfg.h +++ b/cli_classcfg.h @@ -16,7 +16,8 @@ typedef enum { CLI_ACTION_VLAN, CLI_ACTION_POLICER, CLI_ACTION_POLICYRT, - CLI_ACTION_ACCL + CLI_ACTION_ACCL, + CLI_ACTION_METER }classcfg_cli_actions; typedef enum { @@ -31,6 +32,7 @@ typedef enum { CLI_PROTO_ICMP = 1, CLI_PROTO_TCP, CLI_PROTO_UDP, + CLI_PROTO_IGMP, CLI_PROTO_ALL, }classcfg_cli_protocol; @@ -83,6 +85,7 @@ typedef enum { CLI_CLSCFG_PARAM_ACTDSCP, CLI_CLSCFG_PARAM_ACTETHPRIO, CLI_CLSCFG_PARAM_MARK, + CLI_CLSCFG_PARAM_MARK_ING, CLI_CLSCFG_PARAM_MARK_PRIORITY, CLI_CLSCFG_PARAM_MARK_LOC, CLI_CLSCFG_PARAM_ACCL, @@ -102,6 +105,8 @@ typedef enum { CLI_CLSCFG_PARAM_ETH_TYPE, CLI_CLSCFG_PARAM_IP_HDR_LEN_MIN, CLI_CLSCFG_PARAM_IP_HDR_LEN_MAX, - CLI_CLSCFG_PARAM_IP_HDR_DSCP + CLI_CLSCFG_PARAM_IP_HDR_DSCP, + CLI_CLSCFG_PARAM_ENGINE, + CLI_CLSCFG_PARAM_METER_ID }x_classcfg_param_list; diff --git a/cli_ifcfg.c b/cli_ifcfg.c index ec1a43e..3b3048e 100644 --- a/cli_ifcfg.c +++ b/cli_ifcfg.c @@ -99,6 +99,7 @@ ifcli_print_if_inggrp(ifinggrp_t ifgroup, int32_t inumifs, char ifnames[MAX_IF_P int32_t ifcli_invoke_fapi(struct x_ifcfg_t *pxifcfg) { + int32_t nRet = LTQ_SUCCESS; int i; if (!pxifcfg->uiFlags) { @@ -108,14 +109,34 @@ ifcli_invoke_fapi(struct x_ifcfg_t *pxifcfg) if ((pxifcfg->uiFlags & QOS_OP_F_ADD) || (pxifcfg->uiFlags & QOS_OP_F_DELETE)) { if (IFGROUP_VALID(pxifcfg->ifgroup)) { - fapi_qos_if_abs_set(pxifcfg->ifgroup, pxifcfg->ifnames[0], pxifcfg->uiFlags); - if (IFGROUP_IS_WAN(pxifcfg->ifgroup)) - fapi_qos_if_base_set(pxifcfg->ifnames[0], pxifcfg->base_ifnames[0], pxifcfg->logical_base[0], pxifcfg->uiFlags); + /* if Logical interface is not given, use base interface as logical*/ + if ((strnlen_s(pxifcfg->logical_base[0], MAX_IF_NAME_LEN)) == EOK) { + if(strncpy_s(pxifcfg->logical_base[0], MAX_IF_NAME_LEN, pxifcfg->base_ifnames[0], + strnlen_s(pxifcfg->base_ifnames[0], MAX_IF_NAME_LEN)) != EOK) { + printf("Copying Base interface to Logical interface Failed\n"); + return LTQ_FAIL; + } + } + nRet = fapi_qos_if_abs_set(pxifcfg->ifgroup, pxifcfg->ifnames[0], pxifcfg->uiFlags); + /*if (IFGROUP_IS_WAN(pxifcfg->ifgroup))*/ + nRet = fapi_qos_if_base_set(pxifcfg->ifnames[0], pxifcfg->base_ifnames[0], pxifcfg->logical_base[0], pxifcfg->uiFlags); + } + else { + printf("Invalid interface category!\n"); + ifcli_print_usage(); + return LTQ_FAIL; } if (IFINGGRP_VALID(pxifcfg->ifinggrp)) { - fapi_qos_if_inggrp_set(pxifcfg->ifinggrp, pxifcfg->ifnames[0], pxifcfg->uiFlags); + nRet = fapi_qos_if_inggrp_set(pxifcfg->ifinggrp, pxifcfg->ifnames[0], pxifcfg->uiFlags); if (IFGROUP_IS_WAN(pxifcfg->ifgroup)) - fapi_qos_if_inggrp_set(pxifcfg->ifinggrp, pxifcfg->base_ifnames[0], pxifcfg->uiFlags); + nRet = fapi_qos_if_inggrp_set(pxifcfg->ifinggrp, pxifcfg->base_ifnames[0], pxifcfg->uiFlags); + } + else { + if ((pxifcfg->uiFlags & QOS_OP_F_INGRESS) == QOS_OP_F_INGRESS) { + printf("Invalid interface group!\n"); + ifcli_print_usage(); + return LTQ_FAIL; + } } } else if (pxifcfg->uiFlags & QOS_PORT_F_RT_CHG) { fapi_qos_port_update(pxifcfg->ifnames[0], pxifcfg->uiFlags); @@ -144,7 +165,7 @@ ifcli_invoke_fapi(struct x_ifcfg_t *pxifcfg) } } - return LTQ_SUCCESS; + return nRet; } int32_t @@ -184,9 +205,11 @@ ifcfg_main(int32_t argc, char **argv) else xifcfg.uiFlags |= QOS_OP_F_ADD; #ifndef CONFIG_LANTIQ_OPENWRT - if (check_interface_exists(optarg) != LTQ_SUCCESS) { - printf("Interface %s does not exist.\n", optarg); - return LTQ_FAIL; + if (xifcfg.ifgroup != QOS_IF_CATEGORY_CPU) { + if (check_interface_exists(optarg) != LTQ_SUCCESS) { + printf("Interface %s does not exist.\n", optarg); + return LTQ_FAIL; + } } #endif if(strncpy_s(xifcfg.ifnames[0], MAX_IF_NAME_LEN, optarg, strnlen_s(optarg, MAX_IF_NAME_LEN)) != EOK) @@ -222,10 +245,13 @@ ifcfg_main(int32_t argc, char **argv) break; case 'b': /* applicable when ifmapop is set */ - if (check_interface_exists(optarg) != LTQ_SUCCESS) { - printf("Interface %s does not exist.\n", optarg); - return LTQ_FAIL; - } + LOGF_LOG_DEBUG("ifgroup:[%d]\n", xifcfg.ifgroup); + if (xifcfg.ifgroup != QOS_IF_CATEGORY_CPU) { + if (check_interface_exists(optarg) != LTQ_SUCCESS) { + printf("Interface %s does not exist.\n", optarg); + return LTQ_FAIL; + } + } if(strncpy_s(xifcfg.base_ifnames[0], MAX_IF_NAME_LEN, optarg, strnlen_s(optarg, MAX_IF_NAME_LEN)) != EOK) { printf("Error copying base interface name !!\n"); @@ -242,7 +268,8 @@ ifcfg_main(int32_t argc, char **argv) break; case 'L': if(ifmapop == 1) { - xifcfg.uiFlags |= CL_IF_ABS_GET | CL_IF_INGR_GET; + xifcfg.uiFlags |= CL_IF_ABS_GET; + xifcfg.uiFlags |= CL_IF_INGR_GET; } break; case 'R': diff --git a/cli_qcfg.c b/cli_qcfg.c index 80ac3cb..9629f1b 100755 --- a/cli_qcfg.c +++ b/cli_qcfg.c @@ -33,6 +33,10 @@ #define QCLI_MAX_STR 1024 +/* Max chars in queue name, we append interface + name before the queue name while creating iptable + chain for the queue, iptable max chain lenght is 30 chars*/ + extern uint16_t LOGLEVEL, LOGTYPE; char actmp[QCLI_MAX_STR]; @@ -80,6 +84,10 @@ static struct option long_options[] = { {"maxth1", required_argument, 0, 0 }, {"maxp1", required_argument, 0, 0 }, {"wredwt", required_argument, 0, 0 }, + {"gthx", required_argument, 0, 0 }, + {"ythx", required_argument, 0, 0 }, + {"rthx", required_argument, 0, 0 }, + {"ds-accel", required_argument, 0, 0 }, /*Not subcmds */ {"queue", no_argument, 0, 'q' }, {"port", no_argument, 0, 'P' }, @@ -126,7 +134,11 @@ qcli_print_usage(void) printf("Usage: qcfg --port/--queue \n"); printf("-A/-D/-M/ [qname] => Add/delete/modify specific queue name\n"); printf("-L/-S [all/qname] => Get all queues or a specific queue configuration/Statistics \n"); - printf("-l [qlen] => Length of the queue\n"); + printf("-l [qlen] => Length of the queue in bytes, applicable for Software TC Qdisc\n"); + printf("\tFor queue in hardware use along the below sub options\n"); + printf("\t--gthx [Green color Threshold value in 0-2304 packets (default value 288 packets)] => Applicable for queue in hardware \n"); + printf("\t--ythx [Yellow color Threshold value in 0-2304 packets (default value 288 packets)] => Applicable for queue in hardware \n"); + printf("\t--rthx [Red color Threshold value in 0-2304 packets (default value 288 packets)] => Applicable for queue in hardware \n"); printf("-i [interface name]\n"); printf("--map [comma seperated list of traffic class numbers between 1 and 16]\n"); printf("-m [%s] => Scheduler mode(sub options mentioned below)\n",qcli_getstring(axschednv)); @@ -146,6 +158,7 @@ qcli_print_usage(void) printf("\t--pbs [Peak burst size rate in kilo bits]\n"); printf("\t--cir [committed Info rate in kilo bits/sec]\n"); printf("\t--cbs [committed burst size rate in kilo bits]\n"); + printf("--ds-accel [value] => Downstream QoS acceleration Engine selection. Set to '1' to select MPE based QoS Acceleration in Downstream.\n"); } int32_t @@ -219,17 +232,17 @@ qcli_print_qstats(int32_t inumqs, qos_queue_stats_t *pxqstats) for(i=0;i<inumqs;i++){ printf("Queue Stats Name: %s\n",pxqstats->name); if (pxqstats->flags & QOS_Q_STAT_RX_PKT) - printf("\tReceived Packets: %llu\n",pxqstats->rx_pkt); + printf("\tReceived Packets: %llu\n", (long long unsigned int)pxqstats->rx_pkt); if (pxqstats->flags & QOS_Q_STAT_RX_BYTE) - printf("\tReceived Bytes: %llu\n",pxqstats->rx_bytes); + printf("\tReceived Bytes: %llu\n", (long long unsigned int)pxqstats->rx_bytes); if (pxqstats->flags & QOS_Q_STAT_TX_PKT) - printf("\tTransmitted Packets: %llu\n",pxqstats->tx_pkt); + printf("\tTransmitted Packets: %llu\n", (long long unsigned int)pxqstats->tx_pkt); if (pxqstats->flags & QOS_Q_STAT_TX_BYTE) - printf("\tTransmitted Bytes: %llu\n",pxqstats->tx_bytes); + printf("\tTransmitted Bytes: %llu\n", (long long unsigned int)pxqstats->tx_bytes); if (pxqstats->flags & QOS_Q_STAT_DROP_PKT) - printf("\tDropped Packets: %llu\n",pxqstats->drop_pkt); + printf("\tDropped Packets: %llu\n", (long long unsigned int)pxqstats->drop_pkt); if (pxqstats->flags & QOS_Q_STAT_DROP_BYTE) - printf("\tDropped Bytes: %llu\n",pxqstats->drop_bytes); + printf("\tDropped Bytes: %llu\n", (long long unsigned int)pxqstats->drop_bytes); pxqstats++; } return LTQ_SUCCESS; @@ -253,6 +266,7 @@ qcli_print_qcfg(int32_t inumqs, qos_queue_cfg_t *pxqcfg) } printf("\n"); printf("\tqlen: %d\n",pxqcfg->qlen); + printf("\t\tqlen thresholds: green :%d, yellow :%d, red:%d\n",pxqcfg->drop.wred.max_th0,pxqcfg->drop.wred.max_th1,pxqcfg->drop.wred.drop_th1); char *strVar =util_get_name_from_value(pxqcfg->sched,axschednv); printf("\tScheduler: %s\n",(strVar != NULL)?strVar:""); strVar = util_get_name_from_value(pxqcfg->flags&QOS_Q_F_INGRESS,axtypenv); @@ -286,7 +300,7 @@ qcli_invoke_fapi(struct x_qapi_t *pxqapi) int32_t inumqs; qos_queue_stats_t *pxqstats; iret=fapi_qos_queue_stats_get(pxqapi->acifname, pxqapi->xqcfg.name,&inumqs,&pxqstats,pxqapi->uiflags); - LOGF_LOG_DEBUG("\nQueue Stats for interface %s:\n", pxqapi->acifname); + LOGF_LOG_DEBUG("Queue Stats for interface %s:\n", pxqapi->acifname); qcli_print_qstats(inumqs, pxqstats); os_free(pxqstats); } @@ -294,7 +308,7 @@ qcli_invoke_fapi(struct x_qapi_t *pxqapi) int32_t inumqs; qos_queue_cfg_t *pxqcfg; iret=fapi_qos_queue_get(pxqapi->acifname, pxqapi->xqcfg.name,&inumqs,&pxqcfg,pxqapi->uiflags); - LOGF_LOG_DEBUG("\nQueue Configuration for interface %s:\n", pxqapi->acifname); + LOGF_LOG_DEBUG("Queue Configuration for interface %s:\n", pxqapi->acifname); qcli_print_qcfg(inumqs, pxqcfg); os_free(pxqcfg); } @@ -315,6 +329,11 @@ qcli_invoke_fapi(struct x_qapi_t *pxqapi) else{ if(pxqapi->uiflags&QOS_OP_F_MODIFY){ LOGF_LOG_DEBUG("Invoking port cfg update FAPI\n"); + if(pxqapi->xqcfg.shaper.pir !=0) { + iret=fapi_qos_port_config_set(pxqapi->acifname,&pxqapi->xqcfg.shaper, + pxqapi->xqcfg.weight,pxqapi->xqcfg.priority,pxqapi->uiflags); + } + else iret=fapi_qos_port_update(pxqapi->acifname,pxqapi->uiflags); } else{ @@ -355,14 +374,18 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p int32_t i=0; const char *pcptr=NULL; char *pctmp; - LOGF_LOG_DEBUG("Index [%d] option [%s]", index,long_options[index].name); + LOGF_LOG_DEBUG("Index [%d] option [%s]\n", index,long_options[index].name); switch(index) { case 0: /*Priority*/ if(((pxqapi->uiflags & QOS_OP_F_QUEUE_SCHED)!=QOS_OP_F_QUEUE_SCHED)&& (pxqapi->xqcfg.sched != 1)){ - printf("Appropriate Scheduler not set"); + printf("Appropriate Scheduler not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 1, MAX_PRIO)){ + printf("Appropriate Priority value is not set\n"); return LTQ_FAIL; } pxqapi->xqcfg.priority=atoi(optarg); @@ -371,7 +394,11 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p /*weight*/ if(((pxqapi->uiflags & QOS_OP_F_QUEUE_SCHED)!=QOS_OP_F_QUEUE_SCHED)&& (pxqapi->xqcfg.sched != 0)){ - printf("Appropriate Scheduler not set"); + printf("Appropriate Scheduler not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 1, 100)){ + printf("Appropriate Scheduler weight is not set\n"); return LTQ_FAIL; } pxqapi->xqcfg.weight=atoi(optarg); @@ -381,6 +408,10 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p i=0; pcptr=optarg; LOGF_LOG_DEBUG("map %s\n",optarg); + if(!VALIDATE_RANGE(atoi(optarg), 1, MAX_TC_NUM)){ + printf("Invalid TC Value set %d\n", atoi(optarg)); + return LTQ_FAIL; + } while((pctmp=strchr(pcptr,','))!=NULL){ LOGF_LOG_DEBUG("map %s\n",pcptr); pxqapi->xqcfg.tc_map[i]=atoi(pcptr); @@ -392,7 +423,11 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p case 3: /*cir*/ if((pxqapi->uiflags & QOS_OP_F_QUEUE_SHAPER)!=QOS_OP_F_QUEUE_SHAPER){ - printf("Appropriate Shaper not set"); + printf("Appropriate Shaper not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Shaper cir value not in range\n"); return LTQ_FAIL; } pxqapi->xqcfg.shaper.cir=atoi(optarg); @@ -400,7 +435,11 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p case 4: /*cbs*/ if((pxqapi->uiflags & QOS_OP_F_QUEUE_SHAPER)!=QOS_OP_F_QUEUE_SHAPER){ - printf("Appropriate Shaper not set"); + printf("Appropriate Shaper not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Shaper cbs value not in range\n"); return LTQ_FAIL; } pxqapi->xqcfg.shaper.cbs=atoi(optarg); @@ -408,7 +447,11 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p case 5: /*pir*/ if((pxqapi->uiflags & QOS_OP_F_QUEUE_SHAPER)!=QOS_OP_F_QUEUE_SHAPER){ - printf("Appropriate Shaper not set"); + printf("Appropriate Shaper not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Shaper pir value not in range\n"); return LTQ_FAIL; } pxqapi->xqcfg.shaper.pir=atoi(optarg); @@ -416,7 +459,11 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p case 6: /*pbs*/ if((pxqapi->uiflags & QOS_OP_F_QUEUE_SHAPER)!=QOS_OP_F_QUEUE_SHAPER){ - printf("Appropriate Shaper not set"); + printf("Appropriate Shaper not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 0, MAX_SHAPER_RANGE)){ + printf("Shaper pbs value not in range\n"); return LTQ_FAIL; } pxqapi->xqcfg.shaper.pbs=atoi(optarg); @@ -424,7 +471,11 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p case 7: /*minth0*/ if((pxqapi->uiflags & QOS_OP_F_QUEUE_DROP)!=QOS_OP_F_QUEUE_DROP){ - printf("Appropriate drop not set"); + printf("Appropriate drop not set\n"); + return LTQ_FAIL; + } + if(!VALIDATE_RANGE(atoi(optarg), 0, QOS_MAX_Q_LENGTH_THRESHOLD)){ + printf("Queue threshold value is not in range\n"); return LTQ_FAIL; } pxqapi->xqcfg.drop.wred.min_th0 =atoi(optarg); @@ -435,6 +486,10 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p printf("Appropriate drop not set"); return LTQ_FAIL; } + if(!VALIDATE_RANGE(atoi(optarg), 0, QOS_MAX_Q_LENGTH_THRESHOLD)){ + printf("Queue threshold value is not in range\n"); + return LTQ_FAIL; + } pxqapi->xqcfg.drop.wred.max_th0 =atoi(optarg); break; case 9: @@ -443,6 +498,10 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p printf("Appropriate drop not set"); return LTQ_FAIL; } + if(!VALIDATE_RANGE(atoi(optarg), 0, QOS_MAX_Q_LENGTH_THRESHOLD)){ + printf("Queue threshold value is not in range\n"); + return LTQ_FAIL; + } pxqapi->xqcfg.drop.wred.max_p0 =atoi(optarg); break; case 10: @@ -451,6 +510,10 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p printf("Appropriate drop not set"); return LTQ_FAIL; } + if(!VALIDATE_RANGE(atoi(optarg), 0, QOS_MAX_Q_LENGTH_THRESHOLD)){ + printf("Queue threshold value is not in range\n"); + return LTQ_FAIL; + } pxqapi->xqcfg.drop.wred.min_th1 =atoi(optarg); break; case 11: @@ -459,6 +522,10 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p printf("Appropriate drop not set"); return LTQ_FAIL; } + if(!VALIDATE_RANGE(atoi(optarg), 0, QOS_MAX_Q_LENGTH_THRESHOLD)){ + printf("Queue threshold value is not in range\n"); + return LTQ_FAIL; + } pxqapi->xqcfg.drop.wred.max_th1 =atoi(optarg); break; case 12: @@ -467,16 +534,56 @@ int32_t qcli_handle_subcmd(int32_t index, const char* optarg, struct x_qapi_t *p printf("Appropriate drop not set"); return LTQ_FAIL; } + if(!VALIDATE_RANGE(atoi(optarg), 0, QOS_MAX_Q_LENGTH_THRESHOLD)){ + printf("Queue threshold value is not in range\n"); + return LTQ_FAIL; + } pxqapi->xqcfg.drop.wred.max_p1 =atoi(optarg); break; case 13: /*wredwt*/ - if((pxqapi->uiflags & QOS_OP_F_QUEUE_DROP)!=QOS_OP_F_QUEUE_DROP){ + if(((pxqapi->uiflags & QOS_OP_F_QUEUE_DROP)!=QOS_OP_F_QUEUE_DROP) && (atoi(optarg) < 0)){ printf("Appropriate drop not set"); return LTQ_FAIL; } pxqapi->xqcfg.drop.wred.weight =atoi(optarg); break; + case 14: + /*qlen green threshold*/ + if((pxqapi->uiflags & QOS_OP_F_QUEUE_LENGTH)!=QOS_OP_F_QUEUE_LENGTH){ + printf("Appropriate QUEUE LENGTH threshold not set"); + return LTQ_FAIL; + } + pxqapi->xqcfg.drop.flags |= QOS_DT_F_GREEN_THRESHOLD; + pxqapi->xqcfg.drop.wred.max_th0 =atoi(optarg); + break; + case 15: + /*qlen yellow threshold*/ + if((pxqapi->uiflags & QOS_OP_F_QUEUE_LENGTH)!=QOS_OP_F_QUEUE_LENGTH){ + printf("Appropriate QUEUE LENGTH threshold not set"); + return LTQ_FAIL; + } + pxqapi->xqcfg.drop.flags |= QOS_DT_F_YELLOW_THRESHOLD; + pxqapi->xqcfg.drop.wred.max_th1 =atoi(optarg); + break; + case 16: + /*qlen red threshold*/ + if((pxqapi->uiflags & QOS_OP_F_QUEUE_LENGTH)!=QOS_OP_F_QUEUE_LENGTH){ + printf("Appropriate QUEUE LENGTH threshold not set"); + return LTQ_FAIL; + } + pxqapi->xqcfg.drop.flags |= QOS_DT_F_RED_THRESHOLD; + pxqapi->xqcfg.drop.wred.drop_th1 =atoi(optarg); + break; + case 17: + /*ds-accel*/ + if (atoi(optarg) == 1) { + pxqapi->xqcfg.flags |= QOS_Q_F_DS_QOS; + } else { + printf("Down stream QOS should be set with value 1\n"); + return LTQ_FAIL; + } + break; default: return LTQ_FAIL; } @@ -499,12 +606,19 @@ qcfg_main(int32_t argc, char**argv) switch(c){ case 0: if(optarg){ - LOGF_LOG_DEBUG("\n"); - qcli_handle_subcmd(option_index,optarg, &xqcfg); - } + LOGF_LOG_DEBUG("\n"); + nRet = qcli_handle_subcmd(option_index,optarg, &xqcfg); + if(nRet == LTQ_FAIL) { + return nRet; + } + } break; case 'A': CHECK_FOR_NULL_ARG(optarg, c) + if ((strnlen_s(optarg, QCLI_MAX_STR)) > MAX_QUEUE_NAME_LEN) { + printf("Error Queue Name is too Long, should be less than %d chars\n", MAX_QUEUE_NAME_LEN); + return LTQ_FAIL; + } if(strncpy_s(xqcfg.xqcfg.name, MAX_Q_NAME_LEN, optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) { printf("Error copying Queue name !!\n"); return LTQ_FAIL; @@ -514,6 +628,10 @@ qcfg_main(int32_t argc, char**argv) break; case 'D': CHECK_FOR_NULL_ARG(optarg, c) + if ((strnlen_s(optarg, QCLI_MAX_STR)) > MAX_QUEUE_NAME_LEN) { + printf("Error Queue Name is too Long, should be less than %d chars\n", MAX_QUEUE_NAME_LEN); + return LTQ_FAIL; + } if(strncpy_s(xqcfg.xqcfg.name, MAX_Q_NAME_LEN, optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) { printf("Error copying Queue name !!\n"); return LTQ_FAIL; @@ -523,6 +641,10 @@ qcfg_main(int32_t argc, char**argv) break; case 'M': CHECK_FOR_NULL_ARG(optarg, c) + if ((strnlen_s(optarg, QCLI_MAX_STR)) > MAX_QUEUE_NAME_LEN) { + printf("Error Queue Name is too Long, should be less than %d chars\n", MAX_QUEUE_NAME_LEN); + return LTQ_FAIL; + } if(strncpy_s(xqcfg.xqcfg.name, MAX_Q_NAME_LEN, optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) { printf("Error copying Queue name !!\n"); return LTQ_FAIL; @@ -617,6 +739,7 @@ qcfg_main(int32_t argc, char**argv) case 'l': /* Q len */ CHECK_FOR_NULL_ARG(optarg, c) + xqcfg.uiflags |= QOS_OP_F_QUEUE_LENGTH; xqcfg.xqcfg.qlen=atoi(optarg); break; case 'q': diff --git a/cli_qoscfg.c b/cli_qoscfg.c index 1be5af6..0a5f8e7 100644 --- a/cli_qoscfg.c +++ b/cli_qoscfg.c @@ -41,10 +41,8 @@ void qoscli_print_usage(void) { printf("Usage: qoscfg \n"); - printf("-I <1/0/2> [enable status ==> enable/disable/shut QoS]\n"); + printf("-I <1/0> [enable status ==> enable/disable]\n"); printf("-l <1/0> [log operation enable/disable]\n"); - printf("-t <1/2> [log to file/log to console]\n"); - printf("-f <file_name> [log file in case -t 1 is specified]\n"); printf("-w <1/0> [WMM QoS enable/disable]\n"); printf("-L [Get current enable status of QoS]\n"); printf("-v [Get current version of QoS FAPI]\n"); @@ -62,9 +60,6 @@ qoscli_invoke_fapi(struct x_qoscfg_t *pxcfg) if(pxcfg->uiflags&QOS_CFG_INIT){ iret = fapi_qos_init(&pxcfg->qoscfg, pxcfg->uiflags); } - else if(pxcfg->uiflags&QOS_CFG_SHUT){ - iret = fapi_qos_shut(pxcfg->uiflags); - } else if(pxcfg->uiflags&QOS_STATUS_SET){ iret = fapi_qos_cfg_set(&pxcfg->qoscfg, pxcfg->uiflags); } @@ -96,9 +91,6 @@ qoscfg_main(int32_t argc, char**argv) case 'I': xqoscfg.qoscfg.ena = atoi(optarg); xqoscfg.qoscfg.wmm_ena = atoi(optarg); - if (xqoscfg.qoscfg.ena == 2) - xqoscfg.uiflags |= QOS_CFG_SHUT; - else xqoscfg.uiflags |= QOS_CFG_INIT; bValidReq = false; break; @@ -117,16 +109,6 @@ qoscfg_main(int32_t argc, char**argv) LOGTYPE = xqoscfg.qoscfg.log_type; xqoscfg.uiflags |= QOS_STATUS_SET; break; - case 'f': - if(xqoscfg.qoscfg.log_level != 0 && xqoscfg.qoscfg.log_type == QOS_LOG_FILE) { - if(strncpy_s(xqoscfg.qoscfg.log_file, sizeof(xqoscfg.qoscfg.log_file), optarg, strnlen_s(optarg, QCLI_MAX_STR)) != EOK) - { - printf("Error copying Log file name !!\n"); - return LTQ_FAIL; - } - xqoscfg.uiflags |= QOS_STATUS_SET; - } - break; case 'e': xqoscfg.qoscfg.ena = atoi(optarg); xqoscfg.uiflags |= QOS_STATUS_SET; diff --git a/cli_qoscfg.h b/cli_qoscfg.h index 00c0507..6f3609e 100644 --- a/cli_qoscfg.h +++ b/cli_qoscfg.h @@ -20,8 +20,4 @@ \brief QOS configuration get operation flag */ #define QOS_STATUS_GET 0x40000000 -/*! - \brief QOS general configuration shut flag -*/ -#define QOS_CFG_SHUT 0x80000000 int32_t qoscfg_main(int32_t argc, char**argv); -- GitLab