get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 61429,
    "url": "http://patches.dpdk.org/api/patches/61429/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/bbcaa0afdec85b94be24dd5a38b9c890057d3498.1571322983.git.vladimir.medvedkin@intel.com/",
    "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": "<bbcaa0afdec85b94be24dd5a38b9c890057d3498.1571322983.git.vladimir.medvedkin@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/bbcaa0afdec85b94be24dd5a38b9c890057d3498.1571322983.git.vladimir.medvedkin@intel.com",
    "date": "2019-10-17T15:48:00",
    "name": "[v6,3/6] ipsec: add SAD add/delete/lookup implementation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "e47049b4f78bef1f17debe9b115adb914bc39142",
    "submitter": {
        "id": 1216,
        "url": "http://patches.dpdk.org/api/people/1216/?format=api",
        "name": "Vladimir Medvedkin",
        "email": "vladimir.medvedkin@intel.com"
    },
    "delegate": {
        "id": 6690,
        "url": "http://patches.dpdk.org/api/users/6690/?format=api",
        "username": "akhil",
        "first_name": "akhil",
        "last_name": "goyal",
        "email": "gakhil@marvell.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/bbcaa0afdec85b94be24dd5a38b9c890057d3498.1571322983.git.vladimir.medvedkin@intel.com/mbox/",
    "series": [
        {
            "id": 6917,
            "url": "http://patches.dpdk.org/api/series/6917/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=6917",
            "date": "2019-10-17T15:47:57",
            "name": "ipsec: add inbound SAD",
            "version": 6,
            "mbox": "http://patches.dpdk.org/series/6917/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/61429/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/61429/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 49F871EA0E;\n\tThu, 17 Oct 2019 17:48:24 +0200 (CEST)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby dpdk.org (Postfix) with ESMTP id 031C91E9CB\n\tfor <dev@dpdk.org>; Thu, 17 Oct 2019 17:48:12 +0200 (CEST)",
            "from orsmga005.jf.intel.com ([10.7.209.41])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t17 Oct 2019 08:48:12 -0700",
            "from silpixa00400072.ir.intel.com ([10.237.222.213])\n\tby orsmga005.jf.intel.com with ESMTP; 17 Oct 2019 08:48:11 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.67,308,1566889200\"; d=\"scan'208\";a=\"371174143\"",
        "From": "Vladimir Medvedkin <vladimir.medvedkin@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "konstantin.ananyev@intel.com, bernard.iremonger@intel.com,\n\takhil.goyal@nxp.com",
        "Date": "Thu, 17 Oct 2019 16:48:00 +0100",
        "Message-Id": "<bbcaa0afdec85b94be24dd5a38b9c890057d3498.1571322983.git.vladimir.medvedkin@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": [
            "<cover.1571322982.git.vladimir.medvedkin@intel.com>",
            "<cover.1571322982.git.vladimir.medvedkin@intel.com>"
        ],
        "References": [
            "<cover.1571322982.git.vladimir.medvedkin@intel.com>",
            "<cover.1570725871.git.vladimir.medvedkin@intel.com>\n\t<cover.1571322982.git.vladimir.medvedkin@intel.com>"
        ],
        "Subject": "[dpdk-dev] [PATCH v6 3/6] ipsec: add SAD add/delete/lookup\n\timplementation",
        "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": "Replace rte_ipsec_sad_add(), rte_ipsec_sad_del() and\nrte_ipsec_sad_lookup() stubs with actual implementation.\n\nIt uses three librte_hash tables each of which contains\nan entries for a specific SA type (either it is addressed by SPI only\nor SPI+DIP or SPI+DIP+SIP)\n\nSigned-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>\nAcked-by: Akhil Goyal <akhil.goyal@nxp.com>\nAcked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>\nTested-by: Konstantin Ananyev <konstantin.ananyev@intel.com>\n---\n lib/librte_ipsec/ipsec_sad.c | 278 +++++++++++++++++++++++++++++++++++++++++--\n 1 file changed, 266 insertions(+), 12 deletions(-)",
    "diff": "diff --git a/lib/librte_ipsec/ipsec_sad.c b/lib/librte_ipsec/ipsec_sad.c\nindex e16c7d9..db2c44c 100644\n--- a/lib/librte_ipsec/ipsec_sad.c\n+++ b/lib/librte_ipsec/ipsec_sad.c\n@@ -49,20 +49,182 @@ static struct rte_tailq_elem rte_ipsec_sad_tailq = {\n };\n EAL_REGISTER_TAILQ(rte_ipsec_sad_tailq)\n \n+#define SET_BIT(ptr, bit)\t(void *)((uintptr_t)(ptr) | (uintptr_t)(bit))\n+#define CLEAR_BIT(ptr, bit)\t(void *)((uintptr_t)(ptr) & ~(uintptr_t)(bit))\n+#define GET_BIT(ptr, bit)\t(void *)((uintptr_t)(ptr) & (uintptr_t)(bit))\n+\n+/*\n+ * @internal helper function\n+ * Add a rule of type SPI_DIP or SPI_DIP_SIP.\n+ * Inserts a rule into an appropriate hash table,\n+ * updates the value for a given SPI in SPI_ONLY hash table\n+ * reflecting presence of more specific rule type in two LSBs.\n+ * Updates a counter that reflects the number of rules whith the same SPI.\n+ */\n+static inline int\n+add_specific(struct rte_ipsec_sad *sad, const void *key,\n+\t\tint key_type, void *sa)\n+{\n+\tvoid *tmp_val;\n+\tint ret, notexist;\n+\n+\t/* Check if the key is present in the table.\n+\t * Need for further accaunting in cnt_arr\n+\t */\n+\tret = rte_hash_lookup(sad->hash[key_type], key);\n+\tnotexist = (ret == -ENOENT);\n+\n+\t/* Add an SA to the corresponding table.*/\n+\tret = rte_hash_add_key_data(sad->hash[key_type], key, sa);\n+\tif (ret != 0)\n+\t\treturn ret;\n+\n+\t/* Check if there is an entry in SPI only table with the same SPI */\n+\tret = rte_hash_lookup_data(sad->hash[RTE_IPSEC_SAD_SPI_ONLY],\n+\t\tkey, &tmp_val);\n+\tif (ret < 0)\n+\t\ttmp_val = NULL;\n+\ttmp_val = SET_BIT(tmp_val, key_type);\n+\n+\t/* Add an entry into SPI only table */\n+\tret = rte_hash_add_key_data(sad->hash[RTE_IPSEC_SAD_SPI_ONLY],\n+\t\tkey, tmp_val);\n+\tif (ret != 0)\n+\t\treturn ret;\n+\n+\t/* Update a counter for a given SPI */\n+\tret = rte_hash_lookup(sad->hash[RTE_IPSEC_SAD_SPI_ONLY], key);\n+\tif (key_type == RTE_IPSEC_SAD_SPI_DIP)\n+\t\tsad->cnt_arr[ret].cnt_dip += notexist;\n+\telse\n+\t\tsad->cnt_arr[ret].cnt_dip_sip += notexist;\n+\n+\treturn 0;\n+}\n+\n int\n-rte_ipsec_sad_add(__rte_unused struct rte_ipsec_sad *sad,\n-\t\t__rte_unused const union rte_ipsec_sad_key *key,\n-\t\t__rte_unused int key_type, __rte_unused void *sa)\n+rte_ipsec_sad_add(struct rte_ipsec_sad *sad,\n+\t\tconst union rte_ipsec_sad_key *key,\n+\t\tint key_type, void *sa)\n {\n-\treturn -ENOTSUP;\n+\tvoid *tmp_val;\n+\tint ret;\n+\n+\tif ((sad == NULL) || (key == NULL) || (sa == NULL) ||\n+\t\t\t/* sa must be 4 byte aligned */\n+\t\t\t(GET_BIT(sa, RTE_IPSEC_SAD_KEY_TYPE_MASK) != 0))\n+\t\treturn -EINVAL;\n+\n+\t/*\n+\t * Rules are stored in three hash tables depending on key_type.\n+\t * All rules will also have an entry in SPI_ONLY table, with entry\n+\t * value's two LSB's also indicating presence of rule with this SPI\n+\t * in other tables.\n+\t */\n+\tswitch (key_type) {\n+\tcase(RTE_IPSEC_SAD_SPI_ONLY):\n+\t\tret = rte_hash_lookup_data(sad->hash[key_type],\n+\t\t\tkey, &tmp_val);\n+\t\tif (ret >= 0)\n+\t\t\ttmp_val = SET_BIT(sa, GET_BIT(tmp_val,\n+\t\t\t\tRTE_IPSEC_SAD_KEY_TYPE_MASK));\n+\t\telse\n+\t\t\ttmp_val = sa;\n+\t\tret = rte_hash_add_key_data(sad->hash[key_type],\n+\t\t\tkey, tmp_val);\n+\t\treturn ret;\n+\tcase(RTE_IPSEC_SAD_SPI_DIP):\n+\tcase(RTE_IPSEC_SAD_SPI_DIP_SIP):\n+\t\treturn add_specific(sad, key, key_type, sa);\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+}\n+\n+/*\n+ * @internal helper function\n+ * Delete a rule of type SPI_DIP or SPI_DIP_SIP.\n+ * Deletes an entry from an appropriate hash table and decrements\n+ * an entry counter for given SPI.\n+ * If entry to remove is the last one with given SPI within the table,\n+ * then it will also update related entry in SPI_ONLY table.\n+ * Removes an entry from SPI_ONLY hash table if there no rule left\n+ * for this SPI in any table.\n+ */\n+static inline int\n+del_specific(struct rte_ipsec_sad *sad, const void *key, int key_type)\n+{\n+\tvoid *tmp_val;\n+\tint ret;\n+\tuint32_t *cnt;\n+\n+\t/* Remove an SA from the corresponding table.*/\n+\tret = rte_hash_del_key(sad->hash[key_type], key);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\t/* Get an index of cnt_arr entry for a given SPI */\n+\tret = rte_hash_lookup_data(sad->hash[RTE_IPSEC_SAD_SPI_ONLY],\n+\t\tkey, &tmp_val);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\tcnt = (key_type == RTE_IPSEC_SAD_SPI_DIP) ?\n+\t\t\t&sad->cnt_arr[ret].cnt_dip :\n+\t\t\t&sad->cnt_arr[ret].cnt_dip_sip;\n+\tif (--(*cnt) != 0)\n+\t\treturn 0;\n+\n+\t/* corresponding counter is 0, clear the bit indicating\n+\t * the presence of more specific rule for a given SPI.\n+\t */\n+\ttmp_val = CLEAR_BIT(tmp_val, key_type);\n+\n+\t/* if there are no rules left with same SPI,\n+\t * remove an entry from SPI_only table\n+\t */\n+\tif (tmp_val == NULL)\n+\t\tret = rte_hash_del_key(sad->hash[RTE_IPSEC_SAD_SPI_ONLY], key);\n+\telse\n+\t\tret = rte_hash_add_key_data(sad->hash[RTE_IPSEC_SAD_SPI_ONLY],\n+\t\t\tkey, tmp_val);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\treturn 0;\n }\n \n int\n-rte_ipsec_sad_del(__rte_unused struct rte_ipsec_sad *sad,\n-\t\t__rte_unused const union rte_ipsec_sad_key *key,\n-\t\t__rte_unused int key_type)\n+rte_ipsec_sad_del(struct rte_ipsec_sad *sad,\n+\t\tconst union rte_ipsec_sad_key *key,\n+\t\tint key_type)\n {\n-\treturn -ENOTSUP;\n+\tvoid *tmp_val;\n+\tint ret;\n+\n+\tif ((sad == NULL) || (key == NULL))\n+\t\treturn -EINVAL;\n+\tswitch (key_type) {\n+\tcase(RTE_IPSEC_SAD_SPI_ONLY):\n+\t\tret = rte_hash_lookup_data(sad->hash[key_type],\n+\t\t\tkey, &tmp_val);\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t\tif (GET_BIT(tmp_val, RTE_IPSEC_SAD_KEY_TYPE_MASK) == 0) {\n+\t\t\tret = rte_hash_del_key(sad->hash[key_type],\n+\t\t\t\tkey);\n+\t\t\tret = ret < 0 ? ret : 0;\n+\t\t} else {\n+\t\t\ttmp_val = GET_BIT(tmp_val,\n+\t\t\t\tRTE_IPSEC_SAD_KEY_TYPE_MASK);\n+\t\t\tret = rte_hash_add_key_data(sad->hash[key_type],\n+\t\t\t\tkey, tmp_val);\n+\t\t}\n+\t\treturn ret;\n+\tcase(RTE_IPSEC_SAD_SPI_DIP):\n+\tcase(RTE_IPSEC_SAD_SPI_DIP_SIP):\n+\t\treturn del_specific(sad, key, key_type);\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n }\n \n struct rte_ipsec_sad *\n@@ -252,10 +414,102 @@ rte_ipsec_sad_destroy(struct rte_ipsec_sad *sad)\n \t\trte_free(te);\n }\n \n+/*\n+ * @internal helper function\n+ * Lookup a batch of keys in three hash tables.\n+ * First lookup key in SPI_ONLY table.\n+ * If there is an entry for the corresponding SPI check its value.\n+ * Two least significant bits of the value indicate\n+ * the presence of more specific rule in other tables.\n+ * Perform additional lookup in corresponding hash tables\n+ * and update the value if lookup succeeded.\n+ */\n+static int\n+__ipsec_sad_lookup(const struct rte_ipsec_sad *sad,\n+\t\tconst union rte_ipsec_sad_key *keys[], void *sa[], uint32_t n)\n+{\n+\tconst void *keys_2[RTE_HASH_LOOKUP_BULK_MAX];\n+\tconst void *keys_3[RTE_HASH_LOOKUP_BULK_MAX];\n+\tvoid *vals_2[RTE_HASH_LOOKUP_BULK_MAX] = {NULL};\n+\tvoid *vals_3[RTE_HASH_LOOKUP_BULK_MAX] = {NULL};\n+\tuint32_t idx_2[RTE_HASH_LOOKUP_BULK_MAX];\n+\tuint32_t idx_3[RTE_HASH_LOOKUP_BULK_MAX];\n+\tuint64_t mask_1, mask_2, mask_3;\n+\tuint64_t map, map_spec;\n+\tuint32_t n_2 = 0;\n+\tuint32_t n_3 = 0;\n+\tuint32_t i;\n+\tint found = 0;\n+\n+\tfor (i = 0; i < n; i++)\n+\t\tsa[i] = NULL;\n+\n+\t/*\n+\t * Lookup keys in SPI only hash table first.\n+\t */\n+\trte_hash_lookup_bulk_data(sad->hash[RTE_IPSEC_SAD_SPI_ONLY],\n+\t\t(const void **)keys, n, &mask_1, sa);\n+\tfor (map = mask_1; map; map &= (map - 1)) {\n+\t\ti = rte_bsf64(map);\n+\t\t/*\n+\t\t * if returned value indicates presence of a rule in other\n+\t\t * tables save a key for further lookup.\n+\t\t */\n+\t\tif ((uintptr_t)sa[i] & RTE_IPSEC_SAD_SPI_DIP_SIP) {\n+\t\t\tidx_3[n_3] = i;\n+\t\t\tkeys_3[n_3++] = keys[i];\n+\t\t}\n+\t\tif ((uintptr_t)sa[i] & RTE_IPSEC_SAD_SPI_DIP) {\n+\t\t\tidx_2[n_2] = i;\n+\t\t\tkeys_2[n_2++] = keys[i];\n+\t\t}\n+\t\t/* clear 2 LSB's which indicate the presence\n+\t\t * of more specific rules\n+\t\t */\n+\t\tsa[i] = CLEAR_BIT(sa[i], RTE_IPSEC_SAD_KEY_TYPE_MASK);\n+\t}\n+\n+\t/* Lookup for more specific rules in SPI_DIP table */\n+\tif (n_2 != 0) {\n+\t\trte_hash_lookup_bulk_data(sad->hash[RTE_IPSEC_SAD_SPI_DIP],\n+\t\t\tkeys_2, n_2, &mask_2, vals_2);\n+\t\tfor (map_spec = mask_2; map_spec; map_spec &= (map_spec - 1)) {\n+\t\t\ti = rte_bsf64(map_spec);\n+\t\t\tsa[idx_2[i]] = vals_2[i];\n+\t\t}\n+\t}\n+\t/* Lookup for more specific rules in SPI_DIP_SIP table */\n+\tif (n_3 != 0) {\n+\t\trte_hash_lookup_bulk_data(sad->hash[RTE_IPSEC_SAD_SPI_DIP_SIP],\n+\t\t\tkeys_3, n_3, &mask_3, vals_3);\n+\t\tfor (map_spec = mask_3; map_spec; map_spec &= (map_spec - 1)) {\n+\t\t\ti = rte_bsf64(map_spec);\n+\t\t\tsa[idx_3[i]] = vals_3[i];\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < n; i++)\n+\t\tfound += (sa[i] != NULL);\n+\n+\treturn found;\n+}\n+\n int\n-rte_ipsec_sad_lookup(__rte_unused const struct rte_ipsec_sad *sad,\n-\t\t__rte_unused const union rte_ipsec_sad_key *keys[],\n-\t\t__rte_unused void *sa[], __rte_unused uint32_t n)\n+rte_ipsec_sad_lookup(const struct rte_ipsec_sad *sad,\n+\t\tconst union rte_ipsec_sad_key *keys[], void *sa[], uint32_t n)\n {\n-\treturn -ENOTSUP;\n+\tuint32_t num, i = 0;\n+\tint found = 0;\n+\n+\tif (unlikely((sad == NULL) || (keys == NULL) || (sa == NULL)))\n+\t\treturn -EINVAL;\n+\n+\tdo {\n+\t\tnum = RTE_MIN(n - i, (uint32_t)RTE_HASH_LOOKUP_BULK_MAX);\n+\t\tfound += __ipsec_sad_lookup(sad,\n+\t\t\t&keys[i], &sa[i], num);\n+\t\ti += num;\n+\t} while (i != n);\n+\n+\treturn found;\n }\n",
    "prefixes": [
        "v6",
        "3/6"
    ]
}