From patchwork Fri Jul 13 09:40:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 43008 X-Patchwork-Delegate: shahafs@mellanox.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CAB461B061; Fri, 13 Jul 2018 11:41:01 +0200 (CEST) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 9D8F65323 for ; Fri, 13 Jul 2018 11:40:58 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id h10-v6so24452796wre.6 for ; Fri, 13 Jul 2018 02:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=fDcvwggnPvm8sYRmXaDdO7GhdeDWsmOgMKTOO0tNceI=; b=pNAyrIkwHxGlfUs2KbE1D2Zat+Xzdlh4UDsVdLDC1aa7NctJdGcgtpCIwcKZXeAg9e 6RU4zZtcQshpolTRtrdNe/s+02MLQeWce8R9BReqjo/3kXuwgqIj74FDw9xm6FnVYSaK RMuXdv/LFpDgnUjVbL6nT9m3CjUr6d27MhYJNF5d9ViWwPBJPq3hRKSsIP/rlYcxp0UP d9+rGFxMEnoUK0BZRoVZRfB9YC/atjJdMcYu/4UjJpYIHQCcAIZcgu61R8dNJH6s+a4W JHaeHeYrF1gP5lrLK/ACp2i9h7XGdFFxaprBqLwycpV23numbT3cbrbL2lFl35WgfDxB bl7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=fDcvwggnPvm8sYRmXaDdO7GhdeDWsmOgMKTOO0tNceI=; b=bhJpR4mR1L8ZxIRD3vRVJANHKaB+3ozAc9n9BvuR0GZGo4UqMZ2Gb+vfSkOmNkV34z p0uDa0xX2D3FeWUZMDcDh/LmV4CxCrinCWHjnZZi9sxQi8mqZ1B5y30i2Y1QlDlzy9Eq uM4zhzv0bBLt8UsOnBFlzXBrsOPumtkw4h51cgnTTemSHUc2qBNq8a3prN9jID372JlZ xfbd2diYtzCgW+RdSOzold5euc36bUzBTy0Y7ss76fQyPfvHu80V6Ag/JJ4x1y9Lt/Jn s/Asvak4GwYvYumi2EX7GCRUMBbJQXiwpuHWhgjZ8apHqjVu2QaExUHvi0PNEmI+csGN pZGA== X-Gm-Message-State: AOUpUlHCDrKgQ6HjKzXGuqFSvdT5HdPWomBFiSe1Dl3o1cIjtekAJbfJ M7gb5xIDjGcmCbV/co1o/D72RZIf X-Google-Smtp-Source: AAOMgpfG5zm8mzELmUVejIy9R/nLbvhMr6Qe7kPCi2DHGSehr1kB5c8duWOYe817gAmnyBXDaDNxWQ== X-Received: by 2002:adf:8162:: with SMTP id 89-v6mr4166423wrm.192.1531474858390; Fri, 13 Jul 2018 02:40:58 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id q140-v6sm9640757wmb.35.2018.07.13.02.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 02:40:57 -0700 (PDT) Date: Fri, 13 Jul 2018 11:40:41 +0200 From: Adrien Mazarguil To: Shahaf Shuler Cc: Nelio Laranjeiro , Yongseok Koh , dev@dpdk.org Message-ID: <20180713092910.26276-4-adrien.mazarguil@6wind.com> References: <20180627173355.4718-1-adrien.mazarguil@6wind.com> <20180713092910.26276-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180713092910.26276-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH v2 3/6] net/mlx5: add fate actions to switch flow rules 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch enables creation of rte_flow rules that direct matching traffic to a different port (e.g. another VF representor) or drop it directly at the switch level (PORT_ID and DROP actions). Testpmd examples: - Directing all traffic to port ID 0: flow create 1 ingress transfer pattern end actions port_id id 0 / end - Dropping all traffic normally received by port ID 1: flow create 1 ingress transfer pattern end actions drop / end Note the presence of the transfer attribute, which requests them to be applied at the switch level. All traffic is matched due to empty pattern. Signed-off-by: Adrien Mazarguil Acked-by: Nelio Laranjeiro Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_nl_flow.c | 77 +++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/drivers/net/mlx5/mlx5_nl_flow.c b/drivers/net/mlx5/mlx5_nl_flow.c index a9a5bac49..42b7c655e 100644 --- a/drivers/net/mlx5/mlx5_nl_flow.c +++ b/drivers/net/mlx5/mlx5_nl_flow.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include #include @@ -52,6 +54,8 @@ enum mlx5_nl_flow_trans { ITEM_VOID, ACTIONS, ACTION_VOID, + ACTION_PORT_ID, + ACTION_DROP, END, }; @@ -60,7 +64,9 @@ enum mlx5_nl_flow_trans { #define PATTERN_COMMON \ ITEM_VOID, ACTIONS #define ACTIONS_COMMON \ - ACTION_VOID, END + ACTION_VOID +#define ACTIONS_FATE \ + ACTION_PORT_ID, ACTION_DROP /** Parser state transitions used by mlx5_nl_flow_transpose(). */ static const enum mlx5_nl_flow_trans *const mlx5_nl_flow_trans[] = { @@ -69,8 +75,10 @@ static const enum mlx5_nl_flow_trans *const mlx5_nl_flow_trans[] = { [ATTR] = TRANS(PATTERN), [PATTERN] = TRANS(PATTERN_COMMON), [ITEM_VOID] = TRANS(BACK), - [ACTIONS] = TRANS(ACTIONS_COMMON), + [ACTIONS] = TRANS(ACTIONS_FATE, ACTIONS_COMMON), [ACTION_VOID] = TRANS(BACK), + [ACTION_PORT_ID] = TRANS(ACTION_VOID, END), + [ACTION_DROP] = TRANS(ACTION_VOID, END), [END] = NULL, }; @@ -119,6 +127,7 @@ mlx5_nl_flow_transpose(void *buf, const struct rte_flow_item *item; const struct rte_flow_action *action; unsigned int n; + uint32_t act_index_cur; struct nlattr *na_flower; struct nlattr *na_flower_act; const enum mlx5_nl_flow_trans *trans; @@ -130,14 +139,21 @@ mlx5_nl_flow_transpose(void *buf, item = pattern; action = actions; n = 0; + act_index_cur = 0; na_flower = NULL; na_flower_act = NULL; trans = TRANS(ATTR); back = trans; trans: switch (trans[n++]) { + union { + const struct rte_flow_action_port_id *port_id; + } conf; struct nlmsghdr *nlh; struct tcmsg *tcm; + struct nlattr *act_index; + struct nlattr *act; + unsigned int i; case INVALID: if (item->type) @@ -228,12 +244,69 @@ mlx5_nl_flow_transpose(void *buf, mnl_attr_nest_start_check(buf, size, TCA_FLOWER_ACT); if (!na_flower_act) goto error_nobufs; + act_index_cur = 1; break; case ACTION_VOID: if (action->type != RTE_FLOW_ACTION_TYPE_VOID) goto trans; ++action; break; + case ACTION_PORT_ID: + if (action->type != RTE_FLOW_ACTION_TYPE_PORT_ID) + goto trans; + conf.port_id = action->conf; + if (conf.port_id->original) + i = 0; + else + for (i = 0; ptoi[i].ifindex; ++i) + if (ptoi[i].port_id == conf.port_id->id) + break; + if (!ptoi[i].ifindex) + return rte_flow_error_set + (error, ENODEV, RTE_FLOW_ERROR_TYPE_ACTION_CONF, + conf.port_id, + "missing data to convert port ID to ifindex"); + act_index = + mnl_attr_nest_start_check(buf, size, act_index_cur++); + if (!act_index || + !mnl_attr_put_strz_check(buf, size, TCA_ACT_KIND, "mirred")) + goto error_nobufs; + act = mnl_attr_nest_start_check(buf, size, TCA_ACT_OPTIONS); + if (!act) + goto error_nobufs; + if (!mnl_attr_put_check(buf, size, TCA_MIRRED_PARMS, + sizeof(struct tc_mirred), + &(struct tc_mirred){ + .action = TC_ACT_STOLEN, + .eaction = TCA_EGRESS_REDIR, + .ifindex = ptoi[i].ifindex, + })) + goto error_nobufs; + mnl_attr_nest_end(buf, act); + mnl_attr_nest_end(buf, act_index); + ++action; + break; + case ACTION_DROP: + if (action->type != RTE_FLOW_ACTION_TYPE_DROP) + goto trans; + act_index = + mnl_attr_nest_start_check(buf, size, act_index_cur++); + if (!act_index || + !mnl_attr_put_strz_check(buf, size, TCA_ACT_KIND, "gact")) + goto error_nobufs; + act = mnl_attr_nest_start_check(buf, size, TCA_ACT_OPTIONS); + if (!act) + goto error_nobufs; + if (!mnl_attr_put_check(buf, size, TCA_GACT_PARMS, + sizeof(struct tc_gact), + &(struct tc_gact){ + .action = TC_ACT_SHOT, + })) + goto error_nobufs; + mnl_attr_nest_end(buf, act); + mnl_attr_nest_end(buf, act_index); + ++action; + break; case END: if (item->type != RTE_FLOW_ITEM_TYPE_END || action->type != RTE_FLOW_ACTION_TYPE_END)