/*-
* BSD LICENSE
*
- * Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
+ * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <rte_per_lcore.h>
#include <rte_string_fns.h>
#include <rte_errno.h>
+#include <rte_rwlock.h>
+#include <rte_spinlock.h>
#include "rte_lpm.h"
return NULL;
}
+ rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
TAILQ_FOREACH(l, lpm_list, next) {
if (strncmp(name, l->name, RTE_LPM_NAMESIZE) == 0)
break;
}
+ rte_rwlock_read_unlock(RTE_EAL_TAILQ_RWLOCK);
if (l == NULL)
rte_errno = ENOENT;
/* Determine the amount of memory to allocate. */
mem_size = sizeof(*lpm) + (sizeof(lpm->rules_tbl[0]) * max_rules);
+ rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
+
/* guarantee there's no existing */
TAILQ_FOREACH(lpm, lpm_list, next) {
if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
if (lpm != NULL)
- return NULL;
+ goto exit;
/* Allocate memory to store the LPM data structures. */
lpm = (struct rte_lpm *)rte_zmalloc_socket(mem_name, mem_size,
CACHE_LINE_SIZE, socket_id);
if (lpm == NULL) {
RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
- return NULL;
+ goto exit;
}
/* Save user arguments. */
TAILQ_INSERT_TAIL(lpm_list, lpm, next);
+exit:
+ rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+
return lpm;
}
last_rule = rule_gindex + lpm->used_rules_at_depth[depth - 1];
/* Scan through rule group to see if rule already exists. */
- for (rule_index = rule_gindex; rule_index < last_rule; rule_index++) {
+ for (; rule_index < last_rule; rule_index++) {
/* If rule already exists update its next_hop and return. */
if (lpm->rules_tbl[rule_index].ip == ip_masked) {
lpm->tbl24[i].depth <= depth)) {
struct rte_lpm_tbl24_entry new_tbl24_entry = {
+ { .next_hop = next_hop, },
.valid = VALID,
.ext_entry = 0,
.depth = depth,
- { .next_hop = next_hop, }
};
/* Setting tbl24 entry in one go to avoid race
*/
struct rte_lpm_tbl24_entry new_tbl24_entry = {
+ { .tbl8_gindex = (uint8_t)tbl8_group_index, },
.valid = VALID,
.ext_entry = 1,
.depth = 0,
- { .tbl8_gindex = (uint8_t)tbl8_group_index, }
};
lpm->tbl24[tbl24_index] = new_tbl24_entry;
*/
struct rte_lpm_tbl24_entry new_tbl24_entry = {
+ { .tbl8_gindex = (uint8_t)tbl8_group_index, },
.valid = VALID,
.ext_entry = 1,
.depth = 0,
- { .tbl8_gindex = (uint8_t)tbl8_group_index, }
};
lpm->tbl24[tbl24_index] = new_tbl24_entry;
lpm->max_rules_per_depth);
struct rte_lpm_tbl24_entry new_tbl24_entry = {
+ {.next_hop = lpm->rules_tbl[sub_rule_index].next_hop,},
.valid = VALID,
.ext_entry = 0,
.depth = new_depth,
- {.next_hop = lpm->rules_tbl[sub_rule_index].next_hop,}
};
struct rte_lpm_tbl8_entry new_tbl8_entry = {
else if (tbl8_recycle_index > -1) {
/* Update tbl24 entry. */
struct rte_lpm_tbl24_entry new_tbl24_entry = {
+ { .next_hop = lpm->tbl8[tbl8_recycle_index].next_hop, },
.valid = VALID,
.ext_entry = 0,
.depth = lpm->tbl8[tbl8_recycle_index].depth,
- { .next_hop = lpm->tbl8[tbl8_recycle_index].next_hop, }
};
/* Set tbl24 before freeing tbl8 to avoid race condition. */