From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by dpdk.org (Postfix) with ESMTP id 83D5C1C38C for ; Wed, 27 Jun 2018 20:08:31 +0200 (CEST) Received: by mail-wr0-f195.google.com with SMTP id l2-v6so2358644wro.7 for ; Wed, 27 Jun 2018 11:08:31 -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=vowwvn2lJbLTtsrzkUyNNl062xLLE43DSfy0OjgKNpA=; b=RaJ8T779SqKbwI3G1rHbTFuRyScPRjCvjZA8eeH8EhOrG0xF/UBpopCw+K5JdA0aZz AaRWNLRPANAd9DP+q8SzPDfHlpckRi2y5pwC1w0T7si+QfMKSN69Sk19A5EjhJ3wXZag xdlFga2513JBAXLC8vnxNI/ZbOpYWf5lbxMqtuVvxSPcKXURx5X8+nlDL1ENQs5BQ07o WuJ7tkmrhJ+AsJZEfzhIiBBWBL4iXZsmp1GUOyFAdH6QKODtKmVTZWavr2zhinwXCmJw Up1zNTcc+FVc37rZ43nRAx7OY5F0Nfg78YBpl3lq7xI7ge1RuzbM5PvVnZ2szFu3qVE9 h9sA== 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=vowwvn2lJbLTtsrzkUyNNl062xLLE43DSfy0OjgKNpA=; b=OsM6/9EXzqY7hjDrOvoRXojwK/mLnE6apfgQ0EGNtaioKJjwL3wyRiklbM8I9Szdpp OA2RVnnAebtUS0qILLxuGhrOQEYgnCC36llPSVMggu05wovXOQTA9SGgbcreVZybCs1J bq//HILkyvpZS0P+oQ9k1D1Wkgh+QSMBTN4fZbJ0Ink4AEWSho+k7gEQYhR0AKw7Uocd JCRNS4+MITmLvyQfNwvnx5ICPkXK80TysnTg9OazlbXEbrUvZ1a6H9A55unF3T139pbS UwLZQXUgVyRHPcxXN/3GJslbqg1lybelwGDXDlYQ2tNwStsb19hqsZgUWs4ndoqirXAV jgWA== X-Gm-Message-State: APt69E3sWnZ09h8Wyy4PuEbwo1wf4d5RLrI9X6ScyYl3g7fYX4msBxPE KuFZU0uH2tsFvrFa7iGvSJknxA== X-Google-Smtp-Source: AAOMgpfSH7+bCq2Ce24lK/EHsdTcXJV/IPFne47ziSdusGcBhfAMG+SMhTntW1XNq3sKsjiyBeKGsQ== X-Received: by 2002:adf:f708:: with SMTP id r8-v6mr975072wrp.85.1530122911280; Wed, 27 Jun 2018 11:08:31 -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 i4-v6sm4189360wrq.28.2018.06.27.11.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 11:08:30 -0700 (PDT) Date: Wed, 27 Jun 2018 20:08:14 +0200 From: Adrien Mazarguil To: Shahaf Shuler Cc: Nelio Laranjeiro , Yongseok Koh , dev@dpdk.org Message-ID: <20180627173355.4718-4-adrien.mazarguil@6wind.com> References: <20180627173355.4718-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180627173355.4718-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH 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: , X-List-Received-Date: Wed, 27 Jun 2018 18:08:31 -0000 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 --- 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 1fc62fb0a..70da85fd5 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 @@ -31,6 +33,8 @@ enum mlx5_nl_flow_trans { ITEM_VOID, ACTIONS, ACTION_VOID, + ACTION_PORT_ID, + ACTION_DROP, END, }; @@ -39,7 +43,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[] = { @@ -48,8 +54,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, }; @@ -98,6 +106,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; @@ -109,14 +118,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) @@ -207,12 +223,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) -- 2.11.0