From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id 79A31FA68 for ; Mon, 19 Dec 2016 18:50:02 +0100 (CET) Received: by mail-wm0-f46.google.com with SMTP id a197so99886434wmd.0 for ; Mon, 19 Dec 2016 09:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=vE/CDT0MpLKnWDuy9H6c1CFJDdS4pfHKDS+qDDAPbxQ=; b=AGRtDqrKJM7OYrzkoLaDiRhQ4MdiC71HdqniCSVzIkZLGDe+ihzXgT9N5MyeaJp4In lNwEiz2wFwzvRi42poes6wY1Dcyr8BX9f0RZSGG4wWdRGVZeryJ89NASBWRJV+133nQv uC4GcCQFYiUSl1f14B7gmuKXCTHXJBvL74qCSALx2wA4kz7SCiYX5HkuScS2GGd1oW9b i5YRor0BUTvNxCls629Btonk1QH6DsJjn41NQbitos9pqc0WbRvBf9/wcIUyuXIPaXUV eAuGPU9XFLZu2k+vFjZgl3MvBPJVRMAc+sn7WXInwninIuNM/1VXbKcx5svrW++9vOQq ss8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=vE/CDT0MpLKnWDuy9H6c1CFJDdS4pfHKDS+qDDAPbxQ=; b=Vln8Rqb0s3FnNfz+d2AoEmN4MnCniPu9DRB+HlPxAj8kPMQUwGEU3mHlBCEgiKVrl0 whIh/ULw1TLg5MoXIWuNPs/2zvRlCdJri+l5KtJRebbctgQu7DhzT078Rq43H3qvQfDs KxxfmXHmLYpmf4qe555yu8B+rNgJxKc6VKSXxY64uelIO6ee8ASA+7vbm1cSqeI1f4/2 Fa++yXXP6mTn1I6hpBcK5x2o9E9QDkH2q+vd6lHyQGsPQhi8wTFxqCpnoaz3Vmt5osb6 c9ApSnc3qUrwJoYPduZ3yG9xWOUhCc12zZnnVg7ijCLSgCwwidfLioTA7zSMdwuGQ9Dr AAzw== X-Gm-Message-State: AIkVDXK8JZVSjxTPpi6PvcEryCugq7E51XkWbr1hSTFFZpxIPSKDyvPf8tfZV51Ln8FY9gQU X-Received: by 10.28.166.20 with SMTP id p20mr15420345wme.87.1482169801919; Mon, 19 Dec 2016 09:50:01 -0800 (PST) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id l67sm17829473wmf.0.2016.12.19.09.50.00 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 19 Dec 2016 09:50:01 -0800 (PST) From: Adrien Mazarguil To: dev@dpdk.org Date: Mon, 19 Dec 2016 18:49:05 +0100 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v3 15/25] app/testpmd: add rte_flow item spec prefix length X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Dec 2016 17:50:02 -0000 Generating bit-masks from prefix lengths is often more convenient than providing them entirely (e.g. to define IPv4 and IPv6 subnets). This commit adds the "prefix" operator that assigns generated bit-masks to any pattern item specification field. Signed-off-by: Adrien Mazarguil Acked-by: Olga Shern --- app/test-pmd/cmdline_flow.c | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index b66fecf..07f895e 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -56,6 +56,7 @@ enum index { /* Common tokens. */ INTEGER, UNSIGNED, + PREFIX, RULE_ID, PORT_ID, GROUP_ID, @@ -93,6 +94,7 @@ enum index { ITEM_PARAM_SPEC, ITEM_PARAM_LAST, ITEM_PARAM_MASK, + ITEM_PARAM_PREFIX, ITEM_NEXT, ITEM_END, ITEM_VOID, @@ -278,6 +280,7 @@ static const enum index item_param[] = { ITEM_PARAM_SPEC, ITEM_PARAM_LAST, ITEM_PARAM_MASK, + ITEM_PARAM_PREFIX, ZERO, }; @@ -321,6 +324,9 @@ static int parse_list(struct context *, const struct token *, static int parse_int(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_prefix(struct context *, const struct token *, + const char *, unsigned int, + void *, unsigned int); static int parse_port(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -361,6 +367,13 @@ static const struct token token_list[] = { .call = parse_int, .comp = comp_none, }, + [PREFIX] = { + .name = "{prefix}", + .type = "PREFIX", + .help = "prefix length for bit-mask", + .call = parse_prefix, + .comp = comp_none, + }, [RULE_ID] = { .name = "{rule id}", .type = "RULE ID", @@ -528,6 +541,11 @@ static const struct token token_list[] = { .help = "specify bit-mask with relevant bits set to one", .call = parse_vc_spec, }, + [ITEM_PARAM_PREFIX] = { + .name = "prefix", + .help = "generate bit-mask from a prefix length", + .call = parse_vc_spec, + }, [ITEM_NEXT] = { .name = "/", .help = "specify next pattern item", @@ -605,6 +623,62 @@ push_args(struct context *ctx, const struct arg *arg) return 0; } +/** + * Parse a prefix length and generate a bit-mask. + * + * Last argument (ctx->args) is retrieved to determine mask size, storage + * location and whether the result must use network byte ordering. + */ +static int +parse_prefix(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + const struct arg *arg = pop_args(ctx); + static const uint8_t conv[] = "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff"; + char *end; + uintmax_t u; + unsigned int bytes; + unsigned int extra; + + (void)token; + /* Argument is expected. */ + if (!arg) + return -1; + errno = 0; + u = strtoumax(str, &end, 0); + if (errno || (size_t)(end - str) != len) + goto error; + bytes = u / 8; + extra = u % 8; + size = arg->size; + if (bytes > size || bytes + !!extra > size) + goto error; + if (!ctx->object) + return len; + buf = (uint8_t *)ctx->object + arg->offset; +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN + if (!arg->hton) { + memset((uint8_t *)buf + size - bytes, 0xff, bytes); + memset(buf, 0x00, size - bytes); + if (extra) + ((uint8_t *)buf)[size - bytes - 1] = conv[extra]; + } else +#endif + { + memset(buf, 0xff, bytes); + memset((uint8_t *)buf + bytes, 0x00, size - bytes); + if (extra) + ((uint8_t *)buf)[bytes] = conv[extra]; + } + if (ctx->objmask) + memset((uint8_t *)ctx->objmask + arg->offset, 0xff, size); + return len; +error: + push_args(ctx, arg); + return -1; +} + /** Default parsing function for token name matching. */ static int parse_default(struct context *ctx, const struct token *token, @@ -776,6 +850,12 @@ parse_vc_spec(struct context *ctx, const struct token *token, case ITEM_PARAM_LAST: index = 1; break; + case ITEM_PARAM_PREFIX: + /* Modify next token to expect a prefix. */ + if (ctx->next_num < 2) + return -1; + ctx->next[ctx->next_num - 2] = NEXT_ENTRY(PREFIX); + /* Fall through. */ case ITEM_PARAM_MASK: index = 2; break; -- 2.1.4