hash: check flags on creation for future proofing
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 27 Apr 2020 23:16:23 +0000 (16:16 -0700)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 16 Jun 2020 15:46:39 +0000 (17:46 +0200)
All API's should check that they support the flag values
passed. If an application passes an invalid flag it could
cause problems in later ABI.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Yipeng Wang <yipeng1.wang@intel.com>
lib/librte_hash/rte_cuckoo_hash.c

index 90cb99b..5f701d5 100644 (file)
 #include "rte_hash.h"
 #include "rte_cuckoo_hash.h"
 
+/* Mask of all flags supported by this version */
+#define RTE_HASH_EXTRA_FLAGS_MASK (RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT | \
+                                  RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD | \
+                                  RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
+                                  RTE_HASH_EXTRA_FLAGS_EXT_TABLE |     \
+                                  RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
+                                  RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
        for (CURRENT_BKT = START_BUCKET;                                      \
                CURRENT_BKT != NULL;                                          \
@@ -164,6 +172,12 @@ rte_hash_create(const struct rte_hash_parameters *params)
                return NULL;
        }
 
+       if (params->extra_flag & ~RTE_HASH_EXTRA_FLAGS_MASK) {
+               rte_errno = EINVAL;
+               RTE_LOG(ERR, HASH, "rte_hash_create: unsupported extra flags\n");
+               return NULL;
+       }
+
        /* Validate correct usage of extra options */
        if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
            (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {