get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 42575,
    "url": "http://patches.dpdk.org/api/patches/42575/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180708214606.124420-1-qiaobinf@bu.edu/",
    "project": {
        "id": 1,
        "url": "http://patches.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": "<20180708214606.124420-1-qiaobinf@bu.edu>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180708214606.124420-1-qiaobinf@bu.edu",
    "date": "2018-07-08T21:46:06",
    "name": "LPM: add iterator over LPM rules",
    "commit_ref": null,
    "pull_url": null,
    "state": "rejected",
    "archived": true,
    "hash": "0c89672df0974fd490fd7d2227a2ebabc7f58c56",
    "submitter": {
        "id": 1064,
        "url": "http://patches.dpdk.org/api/people/1064/?format=api",
        "name": "Fu, Qiaobin",
        "email": "qiaobinf@bu.edu"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180708214606.124420-1-qiaobinf@bu.edu/mbox/",
    "series": [
        {
            "id": 466,
            "url": "http://patches.dpdk.org/api/series/466/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=466",
            "date": "2018-07-08T21:46:06",
            "name": "LPM: add iterator over LPM rules",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/466/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/42575/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/42575/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 6A8D94C8B;\n\tSun,  8 Jul 2018 23:47:12 +0200 (CEST)",
            "from relay64.bu.edu (relay64.bu.edu [128.197.228.104])\n\tby dpdk.org (Postfix) with ESMTP id A5B664C74\n\tfor <dev@dpdk.org>; Sun,  8 Jul 2018 23:47:11 +0200 (CEST)",
            "from BU-AUTH (localhost.localdomain [127.0.0.1]) (authenticated\n\tbits=0)\n\tby relay64.bu.edu (8.14.3/8.14.3) with ESMTP id w68LkCJS007903\n\t(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);\n\tSun, 8 Jul 2018 17:46:19 -0400"
        ],
        "X-Envelope-From": "qiaobinf@bu.edu",
        "X-BU-AUTH": "xia1.bu.edu [128.197.41.97]",
        "From": "Qiaobin Fu <qiaobinf@bu.edu>",
        "To": "Bruce Richardson <bruce.richardson@intel.com>",
        "Cc": "dev@dpdk.org, michel@digirati.com.br, doucette@bu.edu, qiaobinf@bu.edu",
        "Date": "Sun,  8 Jul 2018 17:46:06 -0400",
        "Message-Id": "<20180708214606.124420-1-qiaobinf@bu.edu>",
        "X-Mailer": "git-send-email 2.17.1",
        "Subject": "[dpdk-dev] [PATCH] LPM: add iterator over LPM rules",
        "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": "Add an iterator over the LPM rules.\nThe iterator requires a prefix as a parameter and\nlists all entries as long as the given prefix (or longer).\n\nSigned-off-by: Qiaobin Fu <qiaobinf@bu.edu>\nReviewed-by: Cody Doucette <doucette@bu.edu>\nReviewed-by: Michel Machado <michel@digirati.com.br>\n---\n lib/librte_lpm/rte_lpm.c  | 99 +++++++++++++++++++++++++++++++++++++++\n lib/librte_lpm/rte_lpm.h  | 55 ++++++++++++++++++++++\n lib/librte_lpm/rte_lpm6.c | 82 +++++++++++++++++++++++++++++---\n lib/librte_lpm/rte_lpm6.h | 56 ++++++++++++++++++++++\n 4 files changed, 285 insertions(+), 7 deletions(-)",
    "diff": "diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c\nindex d00b13d93..17cc49a86 100644\n--- a/lib/librte_lpm/rte_lpm.c\n+++ b/lib/librte_lpm/rte_lpm.c\n@@ -85,6 +85,105 @@ depth_to_range(uint8_t depth)\n \treturn 1 << (RTE_LPM_MAX_DEPTH - depth);\n }\n \n+int\n+rte_lpm_iterator_state_init(const struct rte_lpm *lpm, uint32_t ip,\n+\tuint8_t depth, struct rte_lpm_iterator_state *state)\n+{\n+\tif (lpm == NULL || depth > RTE_LPM_MAX_DEPTH || state == NULL)\n+\t\treturn -EINVAL;\n+\n+\tstate->dmask = depth_to_mask(depth);\n+\tstate->ip_masked = ip & state->dmask;\n+\tstate->depth = depth == 0 ? 1 : depth;\n+\tstate->next = 0;\n+\tstate->lpm = lpm;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * An iterator over its rule entries.\n+ */\n+int\n+rte_lpm_rule_iterate_v20(struct rte_lpm_iterator_state *state,\n+\tconst struct rte_lpm_rule **rule)\n+{\n+\tif (state == NULL || rule == NULL) {\n+\t\tif (rule != NULL)\n+\t\t\t*rule = NULL;\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\twhile (state->depth <= RTE_LPM_MAX_DEPTH) {\n+\t\tuint32_t rule_gindex =\n+\t\t\tstate->lpm->rule_info[state->depth - 1].first_rule;\n+\t\tuint32_t last_rule = rule_gindex +\n+\t\t\tstate->lpm->rule_info[state->depth - 1].used_rules;\n+\t\tuint32_t rule_index = rule_gindex + state->next;\n+\n+\t\twhile (rule_index < last_rule) {\n+\t\t\tif ((state->lpm->rules_tbl[rule_index].ip &\n+\t\t\t\t\tstate->dmask) == state->ip_masked) {\n+\t\t\t\tstate->next = rule_index - rule_gindex + 1;\n+\t\t\t\t*rule = (const struct rte_lpm_rule *)\n+\t\t\t\t\t&state->lpm->rules_tbl[rule_index];\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\n+\t\t\trule_index++;\n+\t\t}\n+\n+\t\tstate->depth++;\n+\t\tstate->next = 0;\n+\t}\n+\n+\t*rule = NULL;\n+\treturn -ENOENT;\n+}\n+VERSION_SYMBOL(rte_lpm_rule_iterate, _v20, 2.0);\n+\n+int\n+rte_lpm_rule_iterate_v1604(struct rte_lpm_iterator_state *state,\n+\tconst struct rte_lpm_rule **rule)\n+{\n+\tif (state == NULL || rule == NULL) {\n+\t\tif (rule != NULL)\n+\t\t\t*rule = NULL;\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\twhile (state->depth <= RTE_LPM_MAX_DEPTH) {\n+\t\tuint32_t rule_gindex =\n+\t\t\tstate->lpm->rule_info[state->depth - 1].first_rule;\n+\t\tuint32_t last_rule = rule_gindex +\n+\t\t\tstate->lpm->rule_info[state->depth - 1].used_rules;\n+\t\tuint32_t rule_index = rule_gindex + state->next;\n+\n+\t\twhile (rule_index < last_rule) {\n+\t\t\tif ((state->lpm->rules_tbl[rule_index].ip &\n+\t\t\t\t\tstate->dmask) == state->ip_masked) {\n+\t\t\t\tstate->next = rule_index - rule_gindex + 1;\n+\t\t\t\t*rule = (const struct rte_lpm_rule *)\n+\t\t\t\t\t&state->lpm->rules_tbl[rule_index];\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\n+\t\t\trule_index++;\n+\t\t}\n+\n+\t\tstate->depth++;\n+\t\tstate->next = 0;\n+\t}\n+\n+\t*rule = NULL;\n+\treturn -ENOENT;\n+}\n+BIND_DEFAULT_SYMBOL(rte_lpm_rule_iterate, _v1604, 16.04);\n+MAP_STATIC_SYMBOL(int rte_lpm_rule_iterate(struct rte_lpm_iterator_state *state,\n+\tconst struct rte_lpm_rule **rule), rte_lpm_rule_iterate_v1604);\n+\n /*\n  * Find an existing lpm table and return a pointer to it.\n  */\ndiff --git a/lib/librte_lpm/rte_lpm.h b/lib/librte_lpm/rte_lpm.h\nindex 21550444d..c1311c67a 100644\n--- a/lib/librte_lpm/rte_lpm.h\n+++ b/lib/librte_lpm/rte_lpm.h\n@@ -188,6 +188,61 @@ struct rte_lpm {\n \tstruct rte_lpm_rule *rules_tbl; /**< LPM rules. */\n };\n \n+/** LPM iterator state structure. */\n+struct rte_lpm_iterator_state {\n+\tuint32_t dmask;\n+\tuint32_t ip_masked;\n+\tuint8_t  depth;\n+\tuint32_t next;\n+\tconst struct rte_lpm *lpm;\n+};\n+\n+/**\n+ * Initialize the lpm iterator state.\n+ *\n+ * @param lpm\n+ *   LPM object handle\n+ * @param ip\n+ *   IP of the rule to be searched\n+ * @param depth\n+ *   Initial depth of the rule to be searched.\n+ *   Pass zero to enumerate the whole LPM table.\n+ * @param state\n+ *   Pointer to the iterator state\n+ * @return\n+ *   0 on successfully initialize the state variable, negative otherwise.\n+ *   Possible error values include:\n+ *   - EINVAL - invalid parameter passed to function\n+ */\n+int\n+rte_lpm_iterator_state_init(const struct rte_lpm *lpm, uint32_t ip,\n+\tuint8_t depth, struct rte_lpm_iterator_state *state);\n+\n+/**\n+ * An iterator over its rule entries.\n+ * The iterator should require a prefix as a parameter\n+ * and should list all entries as long as the given prefix (or longer).\n+ *\n+ * @param state\n+ *   Pointer to the LPM rule iterator state\n+ * @param rule\n+ *   Pointer to the next rule entry\n+ * @return\n+ *   0 on successfully searching the next rule entry, negative otherwise.\n+ *   Possible error values include:\n+ *   - EINVAL - invalid parameter passed to function\n+ *   - ENOENT - no rule entries found\n+ */\n+int\n+rte_lpm_rule_iterate(struct rte_lpm_iterator_state *state,\n+\tconst struct rte_lpm_rule **rule);\n+int\n+rte_lpm_rule_iterate_v20(struct rte_lpm_iterator_state *state,\n+\tconst struct rte_lpm_rule **rule);\n+int\n+rte_lpm_rule_iterate_v1604(struct rte_lpm_iterator_state *state,\n+\tconst struct rte_lpm_rule **rule);\n+\n /**\n  * Create an LPM object.\n  *\ndiff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c\nindex 149677eb1..b2a9b0da7 100644\n--- a/lib/librte_lpm/rte_lpm6.c\n+++ b/lib/librte_lpm/rte_lpm6.c\n@@ -63,13 +63,6 @@ struct rte_lpm6_tbl_entry {\n \tuint32_t ext_entry :1;   /**< External entry. */\n };\n \n-/** Rules tbl entry structure. */\n-struct rte_lpm6_rule {\n-\tuint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */\n-\tuint32_t next_hop; /**< Rule next hop. */\n-\tuint8_t depth; /**< Rule depth. */\n-};\n-\n /** LPM6 structure. */\n struct rte_lpm6 {\n \t/* LPM metadata. */\n@@ -111,6 +104,81 @@ mask_ip(uint8_t *ip, uint8_t depth)\n \t\t}\n }\n \n+int\n+rte_lpm6_iterator_state_init(const struct rte_lpm6 *lpm, uint8_t *ip,\n+\tuint8_t depth, struct rte_lpm6_iterator_state *state)\n+{\n+\tif (lpm == NULL || depth > RTE_LPM6_MAX_DEPTH || state == NULL)\n+\t\treturn -EINVAL;\n+\n+\tif (ip == NULL)\n+\t\tmemset(state->ip_masked, 0, sizeof(state->ip_masked));\n+\telse {\n+\t\trte_memcpy(state->ip_masked, ip, sizeof(state->ip_masked));\n+\t\tmask_ip(state->ip_masked, depth);\n+\t}\n+\n+\tstate->depth = depth;\n+\tstate->next = 0;\n+\tstate->lpm = lpm;\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * An iterator over its rule entries.\n+ */\n+int\n+rte_lpm6_rule_iterate(struct rte_lpm6_iterator_state *state,\n+\tconst struct rte_lpm6_rule **rule)\n+{\n+\tuint32_t index;\n+\n+\t/* Check user arguments. */\n+\tif (state == NULL || rule == NULL) {\n+\t\tif (rule != NULL)\n+\t\t\t*rule = NULL;\n+\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (state->next >= state->lpm->used_rules) {\n+\t\t*rule = NULL;\n+\t\treturn -ENOENT;\n+\t}\n+\n+\tindex = state->next;\n+\n+\t/* Scan used rules to find rules. */\n+\twhile (index < state->lpm->used_rules) {\n+\t\tuint8_t rule_ip_masked[RTE_LPM6_IPV6_ADDR_SIZE];\n+\n+\t\tif (state->lpm->rules_tbl[index].depth < state->depth) {\n+\t\t\tindex++;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\trte_memcpy(rule_ip_masked, state->lpm->rules_tbl[index].ip,\n+\t\t\tRTE_LPM6_IPV6_ADDR_SIZE);\n+\t\tmask_ip(rule_ip_masked, state->depth);\n+\n+\t\t/* If rule is found return the rule index. */\n+\t\tif ((memcmp(state->ip_masked, rule_ip_masked,\n+\t\t\t\tRTE_LPM6_IPV6_ADDR_SIZE) == 0)) {\n+\t\t\tstate->next = index + 1;\n+\t\t\t*rule = (const struct rte_lpm6_rule *)\n+\t\t\t\t&state->lpm->rules_tbl[index];\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\tindex++;\n+\t}\n+\n+\tstate->next = index;\n+\t*rule = NULL;\n+\treturn -ENOENT;\n+}\n+\n /*\n  * Allocates memory for LPM object\n  */\ndiff --git a/lib/librte_lpm/rte_lpm6.h b/lib/librte_lpm/rte_lpm6.h\nindex 5d59ccb1f..b8a394f6d 100644\n--- a/lib/librte_lpm/rte_lpm6.h\n+++ b/lib/librte_lpm/rte_lpm6.h\n@@ -22,6 +22,13 @@ extern \"C\" {\n /** Max number of characters in LPM name. */\n #define RTE_LPM6_NAMESIZE                 32\n \n+/** Rules tbl entry structure. */\n+struct rte_lpm6_rule {\n+\tuint8_t ip[RTE_LPM6_IPV6_ADDR_SIZE]; /**< Rule IP address. */\n+\tuint8_t next_hop; /**< Rule next hop. */\n+\tuint8_t depth; /**< Rule depth. */\n+};\n+\n /** LPM structure. */\n struct rte_lpm6;\n \n@@ -32,6 +39,55 @@ struct rte_lpm6_config {\n \tint flags;               /**< This field is currently unused. */\n };\n \n+/** LPM6 iterator state structure. */\n+struct rte_lpm6_iterator_state {\n+\tuint8_t  ip_masked[RTE_LPM6_IPV6_ADDR_SIZE];\n+\tuint8_t  depth;\n+\tuint32_t next;\n+\tconst struct rte_lpm6 *lpm;\n+};\n+\n+/**\n+ * Initialize the lpm iterator state.\n+ *\n+ * @param lpm\n+ *   LPM object handle\n+ * @param ip\n+ *   IP of the rule to be searched\n+ *   ip == NULL behaves as having passed an all-zero IPv6 address\n+ * @param depth\n+ *   Initial depth of the rule to be searched.\n+ *   Pass zero to enumerate the whole LPM table.\n+ * @param state\n+ *   Pointer to the iterator state\n+ * @return\n+ *   0 on successfully initialize the state variable, negative otherwise.\n+ *   Possible error values include:\n+ *   - EINVAL - invalid parameter passed to function\n+ */\n+int\n+rte_lpm6_iterator_state_init(const struct rte_lpm6 *lpm, uint8_t *ip,\n+\tuint8_t depth, struct rte_lpm6_iterator_state *state);\n+\n+/**\n+ * An iterator over its rule entries.\n+ * The iterator should require a prefix as a parameter\n+ * and should list all entries as long as the given prefix (or longer).\n+ *\n+ * @param state\n+ *   Pointer to the LPM rule iterator state\n+ * @param rule\n+ *   Pointer to the next rule entry\n+ * @return\n+ *   0 on successfully searching the next rule entry, negative otherwise.\n+ *   Possible error values include:\n+ *   - EINVAL - invalid parameter passed to function\n+ *   - ENOENT - no rule entries found\n+ */\n+int\n+rte_lpm6_rule_iterate(struct rte_lpm6_iterator_state *state,\n+\tconst struct rte_lpm6_rule **rule);\n+\n /**\n  * Create an LPM object.\n  *\n",
    "prefixes": []
}