get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/47737/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 47737,
    "url": "http://patchwork.dpdk.org/api/patches/47737/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/1541158623-29742-3-git-send-email-cristian.dumitrescu@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1541158623-29742-3-git-send-email-cristian.dumitrescu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1541158623-29742-3-git-send-email-cristian.dumitrescu@intel.com",
    "date": "2018-11-02T11:36:54",
    "name": "[03/12] examples/ip_pipeline: track table rules on add bulk",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "04ff1a43ddc2d7e12a20d4e1e6b713bb9f483df8",
    "submitter": {
        "id": 19,
        "url": "http://patchwork.dpdk.org/api/people/19/?format=api",
        "name": "Cristian Dumitrescu",
        "email": "cristian.dumitrescu@intel.com"
    },
    "delegate": {
        "id": 10018,
        "url": "http://patchwork.dpdk.org/api/users/10018/?format=api",
        "username": "cristian_dumitrescu",
        "first_name": "Cristian",
        "last_name": "Dumitrescu",
        "email": "cristian.dumitrescu@intel.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/1541158623-29742-3-git-send-email-cristian.dumitrescu@intel.com/mbox/",
    "series": [
        {
            "id": 2226,
            "url": "http://patchwork.dpdk.org/api/series/2226/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=2226",
            "date": "2018-11-02T11:36:52",
            "name": "[01/12] examples/ip_pipeline: add rule list per table",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/2226/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/47737/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/47737/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id C061B1B445;\n\tFri,  2 Nov 2018 12:37:11 +0100 (CET)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id E93771B435\n\tfor <dev@dpdk.org>; Fri,  2 Nov 2018 12:37:08 +0100 (CET)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t02 Nov 2018 04:37:08 -0700",
            "from silpixa00382658.ir.intel.com ([10.237.223.29])\n\tby orsmga002.jf.intel.com with ESMTP; 02 Nov 2018 04:37:06 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.54,455,1534834800\"; d=\"scan'208\";a=\"105381772\"",
        "From": "Cristian Dumitrescu <cristian.dumitrescu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Jasvinder Singh <jasvinder.singh@intel.com>",
        "Date": "Fri,  2 Nov 2018 11:36:54 +0000",
        "Message-Id": "<1541158623-29742-3-git-send-email-cristian.dumitrescu@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1541158623-29742-1-git-send-email-cristian.dumitrescu@intel.com>",
        "References": "<1541158623-29742-1-git-send-email-cristian.dumitrescu@intel.com>",
        "Subject": "[dpdk-dev] [PATCH 03/12] examples/ip_pipeline: track table rules on\n\tadd bulk",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Support table rule tracking on table rule add bulk operation.\n\nSigned-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>\nSigned-off-by: Jasvinder Singh <jasvinder.singh@intel.com>\n---\n examples/ip_pipeline/cli.c      | 149 +++++++-------\n examples/ip_pipeline/pipeline.h |   7 +-\n examples/ip_pipeline/thread.c   | 429 ++++++++++++++++++++--------------------\n 3 files changed, 299 insertions(+), 286 deletions(-)",
    "diff": "diff --git a/examples/ip_pipeline/cli.c b/examples/ip_pipeline/cli.c\nindex 65600b7..5011cad 100644\n--- a/examples/ip_pipeline/cli.c\n+++ b/examples/ip_pipeline/cli.c\n@@ -4523,7 +4523,7 @@ cmd_pipeline_table_rule_add_default(char **tokens,\n \n \n static const char cmd_pipeline_table_rule_add_bulk_help[] =\n-\"pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>\\n\"\n+\"pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\\n\"\n \"\\n\"\n \"  File <file_name>:\\n\"\n \"  - line format: match <match> action <action>\\n\";\n@@ -4531,8 +4531,7 @@ static const char cmd_pipeline_table_rule_add_bulk_help[] =\n static int\n cli_rule_file_process(const char *file_name,\n \tsize_t line_len_max,\n-\tstruct table_rule_match *m,\n-\tstruct table_rule_action *a,\n+\tstruct table_rule_list **rule_list,\n \tuint32_t *n_rules,\n \tuint32_t *line_number,\n \tchar *out,\n@@ -4544,14 +4543,12 @@ cmd_pipeline_table_rule_add_bulk(char **tokens,\n \tchar *out,\n \tsize_t out_size)\n {\n-\tstruct table_rule_match *match;\n-\tstruct table_rule_action *action;\n-\tvoid **data;\n+\tstruct table_rule_list *list = NULL;\n \tchar *pipeline_name, *file_name;\n-\tuint32_t table_id, n_rules, n_rules_parsed, line_number;\n+\tuint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;\n \tint status;\n \n-\tif (n_tokens != 9) {\n+\tif (n_tokens != 8) {\n \t\tsnprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);\n \t\treturn;\n \t}\n@@ -4585,68 +4582,33 @@ cmd_pipeline_table_rule_add_bulk(char **tokens,\n \n \tfile_name = tokens[7];\n \n-\tif ((parser_read_uint32(&n_rules, tokens[8]) != 0) ||\n-\t\t(n_rules == 0)) {\n-\t\tsnprintf(out, out_size, MSG_ARG_INVALID, \"n_rules\");\n-\t\treturn;\n-\t}\n-\n-\t/* Memory allocation. */\n-\tmatch = calloc(n_rules, sizeof(struct table_rule_match));\n-\taction = calloc(n_rules, sizeof(struct table_rule_action));\n-\tdata = calloc(n_rules, sizeof(void *));\n-\tif ((match == NULL) || (action == NULL) || (data == NULL)) {\n-\t\tsnprintf(out, out_size, MSG_OUT_OF_MEMORY);\n-\t\tfree(data);\n-\t\tfree(action);\n-\t\tfree(match);\n-\t\treturn;\n-\t}\n-\n-\t/* Load rule file */\n-\tn_rules_parsed = n_rules;\n+\t/* Load rules from file. */\n \tstatus = cli_rule_file_process(file_name,\n \t\t1024,\n-\t\tmatch,\n-\t\taction,\n-\t\t&n_rules_parsed,\n+\t\t&list,\n+\t\t&n_rules,\n \t\t&line_number,\n \t\tout,\n \t\tout_size);\n \tif (status) {\n \t\tsnprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);\n-\t\tfree(data);\n-\t\tfree(action);\n-\t\tfree(match);\n-\t\treturn;\n-\t}\n-\tif (n_rules_parsed != n_rules) {\n-\t\tsnprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);\n-\t\tfree(data);\n-\t\tfree(action);\n-\t\tfree(match);\n \t\treturn;\n \t}\n \n \t/* Rule bulk add */\n \tstatus = pipeline_table_rule_add_bulk(pipeline_name,\n \t\ttable_id,\n-\t\tmatch,\n-\t\taction,\n-\t\tdata,\n-\t\t&n_rules);\n+\t\tlist,\n+\t\t&n_rules_added,\n+\t\t&n_rules_not_added);\n \tif (status) {\n \t\tsnprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);\n-\t\tfree(data);\n-\t\tfree(action);\n-\t\tfree(match);\n \t\treturn;\n \t}\n \n-\t/* Memory free */\n-\tfree(data);\n-\tfree(action);\n-\tfree(match);\n+\tsnprintf(out, out_size, \"Added %u rules out of %u.\\n\",\n+\t\tn_rules_added,\n+\t\tn_rules);\n }\n \n \n@@ -5950,44 +5912,56 @@ cli_script_process(const char *file_name,\n static int\n cli_rule_file_process(const char *file_name,\n \tsize_t line_len_max,\n-\tstruct table_rule_match *m,\n-\tstruct table_rule_action *a,\n+\tstruct table_rule_list **rule_list,\n \tuint32_t *n_rules,\n \tuint32_t *line_number,\n \tchar *out,\n \tsize_t out_size)\n {\n-\tFILE *f = NULL;\n+\tstruct table_rule_list *list = NULL;\n \tchar *line = NULL;\n-\tuint32_t rule_id, line_id;\n+\tFILE *f = NULL;\n+\tuint32_t rule_id = 0, line_id = 0;\n \tint status = 0;\n \n \t/* Check input arguments */\n \tif ((file_name == NULL) ||\n \t\t(strlen(file_name) == 0) ||\n-\t\t(line_len_max == 0)) {\n-\t\t*line_number = 0;\n-\t\treturn -EINVAL;\n+\t\t(line_len_max == 0) ||\n+\t\t(rule_list == NULL) ||\n+\t\t(n_rules == NULL) ||\n+\t\t(line_number == NULL) ||\n+\t\t(out == NULL)) {\n+\t\tstatus = -EINVAL;\n+\t\tgoto cli_rule_file_process_free;\n \t}\n \n \t/* Memory allocation */\n+\tlist = malloc(sizeof(struct table_rule_list));\n+\tif (list == NULL) {\n+\t\tstatus = -ENOMEM;\n+\t\tgoto cli_rule_file_process_free;\n+\t}\n+\n+\tTAILQ_INIT(list);\n+\n \tline = malloc(line_len_max + 1);\n \tif (line == NULL) {\n-\t\t*line_number = 0;\n-\t\treturn -ENOMEM;\n+\t\tstatus = -ENOMEM;\n+\t\tgoto cli_rule_file_process_free;\n \t}\n \n \t/* Open file */\n \tf = fopen(file_name, \"r\");\n \tif (f == NULL) {\n-\t\t*line_number = 0;\n-\t\tfree(line);\n-\t\treturn -EIO;\n+\t\tstatus = -EIO;\n+\t\tgoto cli_rule_file_process_free;\n \t}\n \n \t/* Read file */\n-\tfor (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {\n+\tfor (line_id = 1, rule_id = 0; ; line_id++) {\n \t\tchar *tokens[CMD_MAX_TOKENS];\n+\t\tstruct table_rule *rule = NULL;\n \t\tuint32_t n_tokens, n_tokens_parsed, t0;\n \n \t\t/* Read next line from file. */\n@@ -6003,7 +5977,7 @@ cli_rule_file_process(const char *file_name,\n \t\tstatus = parse_tokenize_string(line, tokens, &n_tokens);\n \t\tif (status) {\n \t\t\tstatus = -EINVAL;\n-\t\t\tbreak;\n+\t\t\tgoto cli_rule_file_process_free;\n \t\t}\n \n \t\t/* Empty line. */\n@@ -6011,15 +5985,24 @@ cli_rule_file_process(const char *file_name,\n \t\t\tcontinue;\n \t\tt0 = 0;\n \n+\t\t/* Rule alloc and insert. */\n+\t\trule = calloc(1, sizeof(struct table_rule));\n+\t\tif (rule == NULL) {\n+\t\t\tstatus = -ENOMEM;\n+\t\t\tgoto cli_rule_file_process_free;\n+\t\t}\n+\n+\t\tTAILQ_INSERT_TAIL(list, rule, node);\n+\n \t\t/* Rule match. */\n \t\tn_tokens_parsed = parse_match(tokens + t0,\n \t\t\tn_tokens - t0,\n \t\t\tout,\n \t\t\tout_size,\n-\t\t\t&m[rule_id]);\n+\t\t\t&rule->match);\n \t\tif (n_tokens_parsed == 0) {\n \t\t\tstatus = -EINVAL;\n-\t\t\tbreak;\n+\t\t\tgoto cli_rule_file_process_free;\n \t\t}\n \t\tt0 += n_tokens_parsed;\n \n@@ -6028,17 +6011,17 @@ cli_rule_file_process(const char *file_name,\n \t\t\tn_tokens - t0,\n \t\t\tout,\n \t\t\tout_size,\n-\t\t\t&a[rule_id]);\n+\t\t\t&rule->action);\n \t\tif (n_tokens_parsed == 0) {\n \t\t\tstatus = -EINVAL;\n-\t\t\tbreak;\n+\t\t\tgoto cli_rule_file_process_free;\n \t\t}\n \t\tt0 += n_tokens_parsed;\n \n \t\t/* Line completed. */\n \t\tif (t0 < n_tokens) {\n \t\t\tstatus = -EINVAL;\n-\t\t\tbreak;\n+\t\t\tgoto cli_rule_file_process_free;\n \t\t}\n \n \t\t/* Increment rule count */\n@@ -6051,7 +6034,31 @@ cli_rule_file_process(const char *file_name,\n \t/* Memory free */\n \tfree(line);\n \n+\t*rule_list = list;\n+\t*n_rules = rule_id;\n+\t*line_number = line_id;\n+\treturn 0;\n+\n+cli_rule_file_process_free:\n+\t*rule_list = NULL;\n \t*n_rules = rule_id;\n \t*line_number = line_id;\n+\n+\tfor ( ; ; ) {\n+\t\tstruct table_rule *rule;\n+\n+\t\trule = TAILQ_FIRST(list);\n+\t\tif (rule == NULL)\n+\t\t\tbreak;\n+\n+\t\tTAILQ_REMOVE(list, rule, node);\n+\t\tfree(rule);\n+\t}\n+\n+\tif (f)\n+\t\tfclose(f);\n+\tfree(line);\n+\tfree(list);\n+\n \treturn status;\n }\ndiff --git a/examples/ip_pipeline/pipeline.h b/examples/ip_pipeline/pipeline.h\nindex 58067ed..8a364a9 100644\n--- a/examples/ip_pipeline/pipeline.h\n+++ b/examples/ip_pipeline/pipeline.h\n@@ -334,10 +334,9 @@ pipeline_table_rule_add(const char *pipeline_name,\n int\n pipeline_table_rule_add_bulk(const char *pipeline_name,\n \tuint32_t table_id,\n-\tstruct table_rule_match *match,\n-\tstruct table_rule_action *action,\n-\tvoid **data,\n-\tuint32_t *n_rules);\n+\tstruct table_rule_list *list,\n+\tuint32_t *n_rules_added,\n+\tuint32_t *n_rules_not_added);\n \n int\n pipeline_table_rule_add_default(const char *pipeline_name,\ndiff --git a/examples/ip_pipeline/thread.c b/examples/ip_pipeline/thread.c\nindex 5019de9..2c0570f 100644\n--- a/examples/ip_pipeline/thread.c\n+++ b/examples/ip_pipeline/thread.c\n@@ -609,10 +609,7 @@ struct pipeline_msg_req_table_rule_add_default {\n };\n \n struct pipeline_msg_req_table_rule_add_bulk {\n-\tstruct table_rule_match *match;\n-\tstruct table_rule_action *action;\n-\tvoid **data;\n-\tuint32_t n_rules;\n+\tstruct table_rule_list *list;\n \tint bulk;\n };\n \n@@ -1206,6 +1203,128 @@ action_convert(struct rte_table_action *a,\n \tstruct table_rule_action *action,\n \tstruct rte_pipeline_table_entry *data);\n \n+struct table_ll {\n+\tstruct rte_pipeline *p;\n+\tint table_id;\n+\tstruct rte_table_action *a;\n+\tint bulk_supported;\n+};\n+\n+static int\n+table_rule_add_bulk_ll(struct table_ll *table,\n+\tstruct table_rule_list *list,\n+\tuint32_t *n_rules)\n+{\n+\tunion table_rule_match_low_level *match_ll = NULL;\n+\tuint8_t *action_ll = NULL;\n+\tvoid **match_ll_ptr = NULL;\n+\tstruct rte_pipeline_table_entry **action_ll_ptr = NULL;\n+\tstruct rte_pipeline_table_entry **entries_ptr = NULL;\n+\tint *found = NULL;\n+\tstruct table_rule *rule;\n+\tuint32_t n, i;\n+\tint status = 0;\n+\n+\tn = 0;\n+\tTAILQ_FOREACH(rule, list, node)\n+\t\tn++;\n+\n+\t/* Memory allocation */\n+\tmatch_ll = calloc(n, sizeof(union table_rule_match_low_level));\n+\taction_ll = calloc(n, TABLE_RULE_ACTION_SIZE_MAX);\n+\n+\tmatch_ll_ptr = calloc(n, sizeof(void *));\n+\taction_ll_ptr = calloc(n, sizeof(struct rte_pipeline_table_entry *));\n+\n+\tentries_ptr = calloc(n, sizeof(struct rte_pipeline_table_entry *));\n+\tfound = calloc(n, sizeof(int));\n+\n+\tif (match_ll == NULL ||\n+\t\taction_ll == NULL ||\n+\t\tmatch_ll_ptr == NULL ||\n+\t\taction_ll_ptr == NULL ||\n+\t\tentries_ptr == NULL ||\n+\t\tfound == NULL) {\n+\t\t\tstatus = -ENOMEM;\n+\t\t\tgoto table_rule_add_bulk_ll_free;\n+\t}\n+\n+\t/* Init */\n+\tfor (i = 0; i < n; i++) {\n+\t\tmatch_ll_ptr[i] = (void *)&match_ll[i];\n+\t\taction_ll_ptr[i] = (struct rte_pipeline_table_entry *)\n+\t\t\t&action_ll[i * TABLE_RULE_ACTION_SIZE_MAX];\n+\t}\n+\n+\t/* Rule (match, action) conversion */\n+\ti = 0;\n+\tTAILQ_FOREACH(rule, list, node) {\n+\t\tstatus = match_convert(&rule->match, match_ll_ptr[i], 1);\n+\t\tif (status)\n+\t\t\tgoto table_rule_add_bulk_ll_free;\n+\n+\t\tstatus = action_convert(table->a, &rule->action, action_ll_ptr[i]);\n+\t\tif (status)\n+\t\t\tgoto table_rule_add_bulk_ll_free;\n+\n+\t\ti++;\n+\t}\n+\n+\t/* Add rule (match, action) to table */\n+\tif (table->bulk_supported) {\n+\t\tstatus = rte_pipeline_table_entry_add_bulk(table->p,\n+\t\t\ttable->table_id,\n+\t\t\tmatch_ll_ptr,\n+\t\t\taction_ll_ptr,\n+\t\t\tn,\n+\t\t\tfound,\n+\t\t\tentries_ptr);\n+\t\tif (status)\n+\t\t\tgoto table_rule_add_bulk_ll_free;\n+\t} else\n+\t\tfor (i = 0; i < n; i++) {\n+\t\t\tstatus = rte_pipeline_table_entry_add(table->p,\n+\t\t\t\ttable->table_id,\n+\t\t\t\tmatch_ll_ptr[i],\n+\t\t\t\taction_ll_ptr[i],\n+\t\t\t\t&found[i],\n+\t\t\t\t&entries_ptr[i]);\n+\t\t\tif (status) {\n+\t\t\t\tif (i == 0)\n+\t\t\t\t\tgoto table_rule_add_bulk_ll_free;\n+\n+\t\t\t\t/* No roll-back. */\n+\t\t\t\tstatus = 0;\n+\t\t\t\tn = i;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\n+\t/* Write back to the rule list. */\n+\ti = 0;\n+\tTAILQ_FOREACH(rule, list, node) {\n+\t\tif (i >= n)\n+\t\t\tbreak;\n+\n+\t\trule->data = entries_ptr[i];\n+\n+\t\ti++;\n+\t}\n+\n+\t*n_rules = n;\n+\n+\t/* Free */\n+table_rule_add_bulk_ll_free:\n+\tfree(found);\n+\tfree(entries_ptr);\n+\tfree(action_ll_ptr);\n+\tfree(match_ll_ptr);\n+\tfree(action_ll);\n+\tfree(match_ll);\n+\n+\treturn status;\n+}\n+\n int\n pipeline_table_rule_add(const char *pipeline_name,\n \tuint32_t table_id,\n@@ -1408,156 +1527,119 @@ pipeline_table_rule_add_default(const char *pipeline_name,\n \treturn status;\n }\n \n+static uint32_t\n+table_rule_list_free(struct table_rule_list *list)\n+{\n+\tuint32_t n = 0;\n+\n+\tif (!list)\n+\t\treturn 0;\n+\n+\tfor ( ; ; ) {\n+\t\tstruct table_rule *rule;\n+\n+\t\trule = TAILQ_FIRST(list);\n+\t\tif (rule == NULL)\n+\t\t\tbreak;\n+\n+\t\tTAILQ_REMOVE(list, rule, node);\n+\t\tfree(rule);\n+\t\tn++;\n+\t}\n+\n+\tfree(list);\n+\treturn n;\n+}\n+\n int\n pipeline_table_rule_add_bulk(const char *pipeline_name,\n \tuint32_t table_id,\n-\tstruct table_rule_match *match,\n-\tstruct table_rule_action *action,\n-\tvoid **data,\n-\tuint32_t *n_rules)\n+\tstruct table_rule_list *list,\n+\tuint32_t *n_rules_added,\n+\tuint32_t *n_rules_not_added)\n {\n \tstruct pipeline *p;\n+\tstruct table *table;\n \tstruct pipeline_msg_req *req;\n \tstruct pipeline_msg_rsp *rsp;\n-\tuint32_t i;\n-\tint status;\n+\tstruct table_rule *rule;\n+\tint status = 0;\n \n \t/* Check input params */\n \tif ((pipeline_name == NULL) ||\n-\t\t(match == NULL) ||\n-\t\t(action == NULL) ||\n-\t\t(data == NULL) ||\n-\t\t(n_rules == NULL) ||\n-\t\t(*n_rules == 0))\n-\t\treturn -1;\n+\t\t(list == NULL) ||\n+\t\tTAILQ_EMPTY(list) ||\n+\t\t(n_rules_added == NULL) ||\n+\t\t(n_rules_not_added == NULL)) {\n+\t\ttable_rule_list_free(list);\n+\t\treturn -EINVAL;\n+\t}\n \n \tp = pipeline_find(pipeline_name);\n \tif ((p == NULL) ||\n-\t\t(table_id >= p->n_tables))\n-\t\treturn -1;\n-\n-\tfor (i = 0; i < *n_rules; i++)\n-\t\tif (match_check(match, p, table_id) ||\n-\t\t\taction_check(action, p, table_id))\n-\t\t\treturn -1;\n-\n-\tif (!pipeline_is_running(p)) {\n-\t\tstruct rte_table_action *a = p->table[table_id].a;\n-\t\tunion table_rule_match_low_level *match_ll;\n-\t\tuint8_t *action_ll;\n-\t\tvoid **match_ll_ptr;\n-\t\tstruct rte_pipeline_table_entry **action_ll_ptr;\n-\t\tstruct rte_pipeline_table_entry **entries_ptr =\n-\t\t\t(struct rte_pipeline_table_entry **)data;\n-\t\tuint32_t bulk =\n-\t\t\t(p->table[table_id].params.match_type == TABLE_ACL) ? 1 : 0;\n-\t\tint *found;\n-\n-\t\t/* Memory allocation */\n-\t\tmatch_ll = calloc(*n_rules, sizeof(union table_rule_match_low_level));\n-\t\taction_ll = calloc(*n_rules, TABLE_RULE_ACTION_SIZE_MAX);\n-\t\tmatch_ll_ptr = calloc(*n_rules, sizeof(void *));\n-\t\taction_ll_ptr =\n-\t\t\tcalloc(*n_rules, sizeof(struct rte_pipeline_table_entry *));\n-\t\tfound = calloc(*n_rules, sizeof(int));\n-\n-\t\tif (match_ll == NULL ||\n-\t\t\taction_ll == NULL ||\n-\t\t\tmatch_ll_ptr == NULL ||\n-\t\t\taction_ll_ptr == NULL ||\n-\t\t\tfound == NULL)\n-\t\t\tgoto fail;\n-\n-\t\tfor (i = 0; i < *n_rules; i++) {\n-\t\t\tmatch_ll_ptr[i] = (void *)&match_ll[i];\n-\t\t\taction_ll_ptr[i] =\n-\t\t\t\t(struct rte_pipeline_table_entry *)&action_ll[i * TABLE_RULE_ACTION_SIZE_MAX];\n-\t\t}\n+\t\t(table_id >= p->n_tables)) {\n+\t\ttable_rule_list_free(list);\n+\t\treturn -EINVAL;\n+\t}\n \n-\t\t/* Rule match conversion */\n-\t\tfor (i = 0; i < *n_rules; i++) {\n-\t\t\tstatus = match_convert(&match[i], match_ll_ptr[i], 1);\n-\t\t\tif (status)\n-\t\t\t\tgoto fail;\n-\t\t}\n+\ttable = &p->table[table_id];\n \n-\t\t/* Rule action conversion */\n-\t\tfor (i = 0; i < *n_rules; i++) {\n-\t\t\tstatus = action_convert(a, &action[i], action_ll_ptr[i]);\n-\t\t\tif (status)\n-\t\t\t\tgoto fail;\n+\tTAILQ_FOREACH(rule, list, node)\n+\t\tif (match_check(&rule->match, p, table_id) ||\n+\t\t\taction_check(&rule->action, p, table_id)) {\n+\t\t\ttable_rule_list_free(list);\n+\t\t\treturn -EINVAL;\n \t\t}\n \n-\t\t/* Add rule (match, action) to table */\n-\t\tif (bulk) {\n-\t\t\tstatus = rte_pipeline_table_entry_add_bulk(p->p,\n-\t\t\t\ttable_id,\n-\t\t\t\tmatch_ll_ptr,\n-\t\t\t\taction_ll_ptr,\n-\t\t\t\t*n_rules,\n-\t\t\t\tfound,\n-\t\t\t\tentries_ptr);\n-\t\t\tif (status)\n-\t\t\t\t*n_rules = 0;\n-\t\t} else {\n-\t\t\tfor (i = 0; i < *n_rules; i++) {\n-\t\t\t\tstatus = rte_pipeline_table_entry_add(p->p,\n-\t\t\t\t\ttable_id,\n-\t\t\t\t\tmatch_ll_ptr[i],\n-\t\t\t\t\taction_ll_ptr[i],\n-\t\t\t\t\t&found[i],\n-\t\t\t\t\t&entries_ptr[i]);\n-\t\t\t\tif (status) {\n-\t\t\t\t\t*n_rules = i;\n-\t\t\t\t\tbreak;\n-\t\t\t\t}\n-\t\t\t}\n+\tif (!pipeline_is_running(p)) {\n+\t\tstruct table_ll table_ll = {\n+\t\t\t.p = p->p,\n+\t\t\t.table_id = table_id,\n+\t\t\t.a = table->a,\n+\t\t\t.bulk_supported = table->params.match_type == TABLE_ACL,\n+\t\t};\n+\n+\t\tstatus = table_rule_add_bulk_ll(&table_ll, list, n_rules_added);\n+\t\tif (status) {\n+\t\t\ttable_rule_list_free(list);\n+\t\t\treturn status;\n \t\t}\n \n-\t\t/* Free */\n-\t\tfree(found);\n-\t\tfree(action_ll_ptr);\n-\t\tfree(match_ll_ptr);\n-\t\tfree(action_ll);\n-\t\tfree(match_ll);\n-\n-\t\treturn status;\n-\n-fail:\n-\t\tfree(found);\n-\t\tfree(action_ll_ptr);\n-\t\tfree(match_ll_ptr);\n-\t\tfree(action_ll);\n-\t\tfree(match_ll);\n-\n-\t\t*n_rules = 0;\n-\t\treturn -1;\n+\t\ttable_rule_add_bulk(table, list, *n_rules_added);\n+\t\t*n_rules_not_added = table_rule_list_free(list);\n+\t\treturn 0;\n \t}\n \n \t/* Allocate request */\n \treq = pipeline_msg_alloc();\n-\tif (req == NULL)\n-\t\treturn -1;\n+\tif (req == NULL) {\n+\t\ttable_rule_list_free(list);\n+\t\treturn -ENOMEM;\n+\t}\n \n \t/* Write request */\n \treq->type = PIPELINE_REQ_TABLE_RULE_ADD_BULK;\n \treq->id = table_id;\n-\treq->table_rule_add_bulk.match = match;\n-\treq->table_rule_add_bulk.action = action;\n-\treq->table_rule_add_bulk.data = data;\n-\treq->table_rule_add_bulk.n_rules = *n_rules;\n-\treq->table_rule_add_bulk.bulk =\n-\t\t(p->table[table_id].params.match_type == TABLE_ACL) ? 1 : 0;\n+\treq->table_rule_add_bulk.list = list;\n+\treq->table_rule_add_bulk.bulk = table->params.match_type == TABLE_ACL;\n \n \t/* Send request and wait for response */\n \trsp = pipeline_msg_send_recv(p, req);\n-\tif (rsp == NULL)\n-\t\treturn -1;\n+\tif (rsp == NULL) {\n+\t\ttable_rule_list_free(list);\n+\t\treturn -ENOMEM;\n+\t}\n \n \t/* Read response */\n \tstatus = rsp->status;\n-\tif (status == 0)\n-\t\t*n_rules = rsp->table_rule_add_bulk.n_rules;\n+\tif (status == 0) {\n+\t\t*n_rules_added = rsp->table_rule_add_bulk.n_rules;\n+\n+\t\ttable_rule_add_bulk(table, list, *n_rules_added);\n+\t\t*n_rules_not_added = table_rule_list_free(list);\n+\t} else\n+\t\ttable_rule_list_free(list);\n+\n \n \t/* Free response */\n \tpipeline_msg_free(rsp);\n@@ -2626,107 +2708,32 @@ static struct pipeline_msg_rsp *\n pipeline_msg_handle_table_rule_add_bulk(struct pipeline_data *p,\n \tstruct pipeline_msg_req *req)\n {\n-\n \tstruct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;\n \n \tuint32_t table_id = req->id;\n-\tstruct table_rule_match *match = req->table_rule_add_bulk.match;\n-\tstruct table_rule_action *action = req->table_rule_add_bulk.action;\n-\tstruct rte_pipeline_table_entry **data =\n-\t\t(struct rte_pipeline_table_entry **)req->table_rule_add_bulk.data;\n-\tuint32_t n_rules = req->table_rule_add_bulk.n_rules;\n+\tstruct table_rule_list *list = req->table_rule_add_bulk.list;\n \tuint32_t bulk = req->table_rule_add_bulk.bulk;\n \n-\tstruct rte_table_action *a = p->table_data[table_id].a;\n-\tunion table_rule_match_low_level *match_ll;\n-\tuint8_t *action_ll;\n-\tvoid **match_ll_ptr;\n-\tstruct rte_pipeline_table_entry **action_ll_ptr;\n-\tint *found, status;\n-\tuint32_t i;\n-\n-\t/* Memory allocation */\n-\tmatch_ll = calloc(n_rules, sizeof(union table_rule_match_low_level));\n-\taction_ll = calloc(n_rules, TABLE_RULE_ACTION_SIZE_MAX);\n-\tmatch_ll_ptr = calloc(n_rules, sizeof(void *));\n-\taction_ll_ptr =\n-\t\tcalloc(n_rules, sizeof(struct rte_pipeline_table_entry *));\n-\tfound = calloc(n_rules, sizeof(int));\n-\n-\tif ((match_ll == NULL) ||\n-\t\t(action_ll == NULL) ||\n-\t\t(match_ll_ptr == NULL) ||\n-\t\t(action_ll_ptr == NULL) ||\n-\t\t(found == NULL))\n-\t\tgoto fail;\n-\n-\tfor (i = 0; i < n_rules; i++) {\n-\t\tmatch_ll_ptr[i] = (void *)&match_ll[i];\n-\t\taction_ll_ptr[i] =\n-\t\t\t(struct rte_pipeline_table_entry *)&action_ll[i * TABLE_RULE_ACTION_SIZE_MAX];\n-\t}\n+\tuint32_t n_rules_added;\n+\tint status;\n \n-\t/* Rule match conversion */\n-\tfor (i = 0; i < n_rules; i++) {\n-\t\tstatus = match_convert(&match[i], match_ll_ptr[i], 1);\n-\t\tif (status)\n-\t\t\tgoto fail;\n-\t}\n+\tstruct table_ll table_ll = {\n+\t\t.p = p->p,\n+\t\t.table_id = table_id,\n+\t\t.a = p->table_data[table_id].a,\n+\t\t.bulk_supported = bulk,\n+\t};\n \n-\t/* Rule action conversion */\n-\tfor (i = 0; i < n_rules; i++) {\n-\t\tstatus = action_convert(a, &action[i], action_ll_ptr[i]);\n-\t\tif (status)\n-\t\t\tgoto fail;\n+\tstatus = table_rule_add_bulk_ll(&table_ll, list, &n_rules_added);\n+\tif (status) {\n+\t\trsp->status = -1;\n+\t\trsp->table_rule_add_bulk.n_rules = 0;\n+\t\treturn rsp;\n \t}\n \n-\t/* Add rule (match, action) to table */\n-\tif (bulk) {\n-\t\tstatus = rte_pipeline_table_entry_add_bulk(p->p,\n-\t\t\ttable_id,\n-\t\t\tmatch_ll_ptr,\n-\t\t\taction_ll_ptr,\n-\t\t\tn_rules,\n-\t\t\tfound,\n-\t\t\tdata);\n-\t\tif (status)\n-\t\t\tn_rules = 0;\n-\t} else\n-\t\tfor (i = 0; i < n_rules; i++) {\n-\t\t\tstatus = rte_pipeline_table_entry_add(p->p,\n-\t\t\t\ttable_id,\n-\t\t\t\tmatch_ll_ptr[i],\n-\t\t\t\taction_ll_ptr[i],\n-\t\t\t\t&found[i],\n-\t\t\t\t&data[i]);\n-\t\t\tif (status) {\n-\t\t\t\tn_rules = i;\n-\t\t\t\tbreak;\n-\t\t\t}\n-\t\t}\n-\n \t/* Write response */\n \trsp->status = 0;\n-\trsp->table_rule_add_bulk.n_rules = n_rules;\n-\n-\t/* Free */\n-\tfree(found);\n-\tfree(action_ll_ptr);\n-\tfree(match_ll_ptr);\n-\tfree(action_ll);\n-\tfree(match_ll);\n-\n-\treturn rsp;\n-\n-fail:\n-\tfree(found);\n-\tfree(action_ll_ptr);\n-\tfree(match_ll_ptr);\n-\tfree(action_ll);\n-\tfree(match_ll);\n-\n-\trsp->status = -1;\n-\trsp->table_rule_add_bulk.n_rules = 0;\n+\trsp->table_rule_add_bulk.n_rules = n_rules_added;\n \treturn rsp;\n }\n \n",
    "prefixes": [
        "03/12"
    ]
}