{"id":811053,"url":"http://patchwork.ozlabs.org/api/patches/811053/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1504794403-45690-2-git-send-email-arkadis@mellanox.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1504794403-45690-2-git-send-email-arkadis@mellanox.com>","list_archive_url":null,"date":"2017-09-07T14:26:40","name":"[iproute2,1/4] devlink: Make match/action parsing more flexible","commit_ref":null,"pull_url":null,"state":"accepted","archived":true,"hash":"4c30992b133e0722a2bc3abd3b32c52b34a0f5d1","submitter":{"id":71504,"url":"http://patchwork.ozlabs.org/api/people/71504/?format=json","name":"Arkadi Sharshevsky","email":"arkadis@mellanox.com"},"delegate":{"id":389,"url":"http://patchwork.ozlabs.org/api/users/389/?format=json","username":"shemminger","first_name":"stephen","last_name":"hemminger","email":"shemminger@vyatta.com"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1504794403-45690-2-git-send-email-arkadis@mellanox.com/mbox/","series":[{"id":2006,"url":"http://patchwork.ozlabs.org/api/series/2006/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=2006","date":"2017-09-07T14:26:41","name":"Add support for dpipe's global header formatting","version":1,"mbox":"http://patchwork.ozlabs.org/series/2006/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/811053/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/811053/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xp2lT1zWbz9sPm\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri,  8 Sep 2017 00:24:37 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S932113AbdIGOYe (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tThu, 7 Sep 2017 10:24:34 -0400","from mail-il-dmz.mellanox.com ([193.47.165.129]:40332 \"EHLO\n\tmellanox.co.il\" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org\n\twith ESMTP id S1755300AbdIGOYH (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Thu, 7 Sep 2017 10:24:07 -0400","from Internal Mail-Server by MTLPINE1 (envelope-from\n\tarkadis@mellanox.com)\n\twith ESMTPS (AES256-SHA encrypted); 7 Sep 2017 17:24:02 +0300","from dev-r-vrt-156.mtr.labs.mlnx (dev-r-vrt-156.mtr.labs.mlnx\n\t[10.212.156.1])\n\tby labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v87EO1oB010674;\n\tThu, 7 Sep 2017 17:24:01 +0300"],"From":"Arkadi Sharshevsky <arkadis@mellanox.com>","To":"netdev@vger.kernel.org","Cc":"davem@davemloft.net, stephen@networkplumber.org, jiri@resnulli.us,\n\tmlxsw@mellanox.com, andrew@lunn.ch,\n\tArkadi Sharshevsky <arkadis@mellanox.com>, Jiri Pirko <jiri@mellanox.com>","Subject":"[PATCH iproute2 1/4] devlink: Make match/action parsing more\n\tflexible","Date":"Thu,  7 Sep 2017 17:26:40 +0300","Message-Id":"<1504794403-45690-2-git-send-email-arkadis@mellanox.com>","X-Mailer":"git-send-email 2.4.11","In-Reply-To":"<1504794403-45690-1-git-send-email-arkadis@mellanox.com>","References":"<1504794403-45690-1-git-send-email-arkadis@mellanox.com>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"This patch decouples the match/action parsing from printing. This is\ndone as a preparation for adding the ability to print global header\nvalues, for example print IPv4 address, which require special formatting.\n\nSigned-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>\nSigned-off-by: Jiri Pirko <jiri@mellanox.com>\n---\n devlink/devlink.c | 127 ++++++++++++++++++++++++++++++++++--------------------\n 1 file changed, 80 insertions(+), 47 deletions(-)","diff":"diff --git a/devlink/devlink.c b/devlink/devlink.c\nindex 8f11f86..36a2b36 100644\n--- a/devlink/devlink.c\n+++ b/devlink/devlink.c\n@@ -3077,27 +3077,42 @@ static const char\n \t}\n }\n \n-static void pr_out_dpipe_action(struct dpipe_ctx *ctx,\n-\t\t\t\tuint32_t header_id, uint32_t field_id,\n-\t\t\t\tuint32_t action_type, bool global)\n+struct dpipe_op_info {\n+\tuint32_t header_id;\n+\tuint32_t field_id;\n+\tbool header_global;\n+};\n+\n+struct dpipe_action {\n+\tstruct dpipe_op_info info;\n+\tuint32_t type;\n+};\n+\n+static void pr_out_dpipe_action(struct dpipe_action *action,\n+\t\t\t\tstruct dpipe_ctx *ctx)\n {\n+\tstruct dpipe_op_info *op_info = &action->info;\n \tconst char *mapping;\n \n-\tpr_out_str(ctx->dl, \"type\", dpipe_action_type_e2s(action_type));\n-\tpr_out_str(ctx->dl, \"header\", dpipe_header_id2s(ctx, header_id,\n-\t\t\t\t\t\t\tglobal));\n-\tpr_out_str(ctx->dl, \"field\", dpipe_field_id2s(ctx, header_id, field_id,\n-\t\t\t\t\t\t      global));\n-\tmapping = dpipe_mapping_get(ctx, header_id, field_id, global);\n+\tpr_out_str(ctx->dl, \"type\",\n+\t\t   dpipe_action_type_e2s(action->type));\n+\tpr_out_str(ctx->dl, \"header\",\n+\t\t   dpipe_header_id2s(ctx, op_info->header_id,\n+\t\t\t\t     op_info->header_global));\n+\tpr_out_str(ctx->dl, \"field\",\n+\t\t   dpipe_field_id2s(ctx, op_info->header_id,\n+\t\t\t\t    op_info->field_id,\n+\t\t\t\t    op_info->header_global));\n+\tmapping = dpipe_mapping_get(ctx, op_info->header_id,\n+\t\t\t\t    op_info->field_id,\n+\t\t\t\t    op_info->header_global);\n \tif (mapping)\n \t\tpr_out_str(ctx->dl, \"mapping\", mapping);\n }\n \n-static int dpipe_action_show(struct dpipe_ctx *ctx, struct nlattr *nl)\n+static int dpipe_action_parse(struct dpipe_action *action, struct nlattr *nl)\n {\n \tstruct nlattr *nla_action[DEVLINK_ATTR_MAX + 1] = {};\n-\tuint32_t header_id, field_id, action_type;\n-\tbool global;\n \tint err;\n \n \terr = mnl_attr_parse_nested(nl, attr_cb, nla_action);\n@@ -3111,12 +3126,11 @@ static int dpipe_action_show(struct dpipe_ctx *ctx, struct nlattr *nl)\n \t\treturn -EINVAL;\n \t}\n \n-\theader_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_HEADER_ID]);\n-\tfield_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_FIELD_ID]);\n-\taction_type = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_ACTION_TYPE]);\n-\tglobal = !!mnl_attr_get_u8(nla_action[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);\n+\taction->type = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_ACTION_TYPE]);\n+\taction->info.header_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_HEADER_ID]);\n+\taction->info.field_id = mnl_attr_get_u32(nla_action[DEVLINK_ATTR_DPIPE_FIELD_ID]);\n+\taction->info.header_global = !!mnl_attr_get_u8(nla_action[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);\n \n-\tpr_out_dpipe_action(ctx, header_id, field_id, action_type, global);\n \treturn 0;\n }\n \n@@ -3124,16 +3138,18 @@ static int dpipe_table_actions_show(struct dpipe_ctx *ctx,\n \t\t\t\t    struct nlattr *nla_actions)\n {\n \tstruct nlattr *nla_action;\n+\tstruct dpipe_action action;\n \n \tmnl_attr_for_each_nested(nla_action, nla_actions) {\n \t\tpr_out_entry_start(ctx->dl);\n-\t\tif (dpipe_action_show(ctx, nla_action))\n-\t\t\tgoto err_action_show;\n+\t\tif (dpipe_action_parse(&action, nla_action))\n+\t\t\tgoto err_action_parse;\n+\t\tpr_out_dpipe_action(&action, ctx);\n \t\tpr_out_entry_end(ctx->dl);\n \t}\n \treturn 0;\n \n-err_action_show:\n+err_action_parse:\n \tpr_out_entry_end(ctx->dl);\n \treturn -EINVAL;\n }\n@@ -3149,28 +3165,38 @@ dpipe_match_type_e2s(enum devlink_dpipe_match_type match_type)\n \t}\n }\n \n-static void pr_out_dpipe_match(struct dpipe_ctx *ctx,\n-\t\t\t       uint32_t header_id, uint32_t field_id,\n-\t\t\t       uint32_t match_type, bool global)\n+struct dpipe_match {\n+\tstruct dpipe_op_info info;\n+\tuint32_t type;\n+};\n+\n+static void pr_out_dpipe_match(struct dpipe_match *match,\n+\t\t\t       struct dpipe_ctx *ctx)\n {\n+\tstruct dpipe_op_info *op_info = &match->info;\n \tconst char *mapping;\n \n-\tpr_out_str(ctx->dl, \"type\", dpipe_match_type_e2s(match_type));\n-\tpr_out_str(ctx->dl, \"header\", dpipe_header_id2s(ctx, header_id,\n-\t\t\t\t\t\t\tglobal));\n-\tpr_out_str(ctx->dl, \"field\", dpipe_field_id2s(ctx, header_id, field_id,\n-\t\t\t\t\t\t      global));\n-\tmapping = dpipe_mapping_get(ctx, header_id, field_id, global);\n+\tpr_out_str(ctx->dl, \"type\",\n+\t\t   dpipe_match_type_e2s(match->type));\n+\tpr_out_str(ctx->dl, \"header\",\n+\t\t   dpipe_header_id2s(ctx, op_info->header_id,\n+\t\t\t\t     op_info->header_global));\n+\tpr_out_str(ctx->dl, \"field\",\n+\t\t   dpipe_field_id2s(ctx, op_info->header_id,\n+\t\t\t\t    op_info->field_id,\n+\t\t\t\t    op_info->header_global));\n+\tmapping = dpipe_mapping_get(ctx, op_info->header_id,\n+\t\t\t\t    op_info->field_id,\n+\t\t\t\t    op_info->header_global);\n \tif (mapping)\n \t\tpr_out_str(ctx->dl, \"mapping\", mapping);\n-\n }\n \n-static int dpipe_match_show(struct dpipe_ctx *ctx, struct nlattr *nl)\n+static int dpipe_match_parse(struct dpipe_match *match,\n+\t\t\t     struct nlattr *nl)\n+\n {\n \tstruct nlattr *nla_match[DEVLINK_ATTR_MAX + 1] = {};\n-\tuint32_t header_id, field_id, match_type;\n-\tbool global;\n \tint err;\n \n \terr = mnl_attr_parse_nested(nl, attr_cb, nla_match);\n@@ -3184,12 +3210,11 @@ static int dpipe_match_show(struct dpipe_ctx *ctx, struct nlattr *nl)\n \t\treturn -EINVAL;\n \t}\n \n-\tmatch_type = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_MATCH_TYPE]);\n-\theader_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_HEADER_ID]);\n-\tfield_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_FIELD_ID]);\n-\tglobal = !!mnl_attr_get_u8(nla_match[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);\n+\tmatch->type = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_MATCH_TYPE]);\n+\tmatch->info.header_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_HEADER_ID]);\n+\tmatch->info.field_id = mnl_attr_get_u32(nla_match[DEVLINK_ATTR_DPIPE_FIELD_ID]);\n+\tmatch->info.header_global = !!mnl_attr_get_u8(nla_match[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL]);\n \n-\tpr_out_dpipe_match(ctx, header_id, field_id, match_type, global);\n \treturn 0;\n }\n \n@@ -3197,16 +3222,18 @@ static int dpipe_table_matches_show(struct dpipe_ctx *ctx,\n \t\t\t\t    struct nlattr *nla_matches)\n {\n \tstruct nlattr *nla_match;\n+\tstruct dpipe_match match;\n \n \tmnl_attr_for_each_nested(nla_match, nla_matches) {\n \t\tpr_out_entry_start(ctx->dl);\n-\t\tif (dpipe_match_show(ctx, nla_match))\n-\t\t\tgoto err_match_show;\n+\t\tif (dpipe_match_parse(&match, nla_match))\n+\t\t\tgoto err_match_parse;\n+\t\tpr_out_dpipe_match(&match, ctx);\n \t\tpr_out_entry_end(ctx->dl);\n \t}\n \treturn 0;\n \n-err_match_show:\n+err_match_parse:\n \tpr_out_entry_end(ctx->dl);\n \treturn -EINVAL;\n }\n@@ -3382,6 +3409,7 @@ static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,\n \t\t\t\t\tstruct nlattr *nl)\n {\n \tstruct nlattr *nla_match_value[DEVLINK_ATTR_MAX + 1] = {};\n+\tstruct dpipe_match match;\n \tint err;\n \n \terr = mnl_attr_parse_nested(nl, attr_cb, nla_match_value);\n@@ -3394,16 +3422,18 @@ static int dpipe_entry_match_value_show(struct dpipe_ctx *ctx,\n \t}\n \n \tpr_out_entry_start(ctx->dl);\n-\tif (dpipe_match_show(ctx, nla_match_value[DEVLINK_ATTR_DPIPE_MATCH]))\n-\t\tgoto err_match_show;\n+\tif (dpipe_match_parse(&match,\n+\t\t\t      nla_match_value[DEVLINK_ATTR_DPIPE_MATCH]))\n+\t\tgoto err_match_parse;\n+\tpr_out_dpipe_match(&match, ctx);\n \tif (dpipe_entry_value_show(ctx, nla_match_value))\n \t\tgoto err_value_show;\n \tpr_out_entry_end(ctx->dl);\n \n \treturn 0;\n \n-err_match_show:\n err_value_show:\n+err_match_parse:\n \tpr_out_entry_end(ctx->dl);\n \treturn -EINVAL;\n }\n@@ -3412,6 +3442,7 @@ static int dpipe_entry_action_value_show(struct dpipe_ctx *ctx,\n \t\t\t\t\t struct nlattr *nl)\n {\n \tstruct nlattr *nla_action_value[DEVLINK_ATTR_MAX + 1] = {};\n+\tstruct dpipe_action action;\n \tint err;\n \n \terr = mnl_attr_parse_nested(nl, attr_cb, nla_action_value);\n@@ -3424,16 +3455,18 @@ static int dpipe_entry_action_value_show(struct dpipe_ctx *ctx,\n \t}\n \n \tpr_out_entry_start(ctx->dl);\n-\tif (dpipe_action_show(ctx, nla_action_value[DEVLINK_ATTR_DPIPE_ACTION]))\n-\t\tgoto err_action_show;\n+\tif (dpipe_action_parse(&action,\n+\t\t\t       nla_action_value[DEVLINK_ATTR_DPIPE_ACTION]))\n+\t\tgoto err_action_parse;\n+\tpr_out_dpipe_action(&action, ctx);\n \tif (dpipe_entry_value_show(ctx, nla_action_value))\n \t\tgoto err_value_show;\n \tpr_out_entry_end(ctx->dl);\n \n \treturn 0;\n \n-err_action_show:\n err_value_show:\n+err_action_parse:\n \tpr_out_entry_end(ctx->dl);\n \treturn -EINVAL;\n }\n","prefixes":["iproute2","1/4"]}