lpm: fix overflow issue
[dpdk.git] / lib / librte_lpm / rte_lpm.c
index 9e76988..cc51210 100644 (file)
@@ -42,7 +42,7 @@
 #include <rte_log.h>
 #include <rte_branch_prediction.h>
 #include <rte_common.h>
-#include <rte_memory.h>        /* for definition of CACHE_LINE_SIZE */
+#include <rte_memory.h>        /* for definition of RTE_CACHE_LINE_SIZE */
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_tailq.h>
@@ -199,7 +199,7 @@ rte_lpm_create(const char *name, int socket_id, int max_rules,
 
        /* Allocate memory to store the LPM data structures. */
        lpm = (struct rte_lpm *)rte_zmalloc_socket(mem_name, mem_size,
-                       CACHE_LINE_SIZE, socket_id);
+                       RTE_CACHE_LINE_SIZE, socket_id);
        if (lpm == NULL) {
                RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
                rte_free(te);
@@ -298,6 +298,9 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
                                return rule_index;
                        }
                }
+
+               if (rule_index == lpm->max_rules)
+                       return -ENOSPC;
        } else {
                /* Calculate the position in which the rule will be stored. */
                rule_index = 0;