if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
- if (te != NULL)
+ lpm = NULL;
+ if (te != NULL) {
+ rte_errno = EEXIST;
goto exit;
+ }
/* allocate tailq entry */
te = rte_zmalloc("LPM_TAILQ_ENTRY", sizeof(*te), 0);
if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0)
break;
}
- if (te != NULL)
+ lpm = NULL;
+ if (te != NULL) {
+ rte_errno = EEXIST;
goto exit;
+ }
/* allocate tailq entry */
te = rte_zmalloc("LPM_TAILQ_ENTRY", sizeof(*te), 0);
(size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id);
if (lpm->rules_tbl == NULL) {
- RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+ RTE_LOG(ERR, LPM, "LPM rules_tbl memory allocation failed\n");
rte_free(lpm);
+ lpm = NULL;
rte_free(te);
goto exit;
}
(size_t)tbl8s_size, RTE_CACHE_LINE_SIZE, socket_id);
if (lpm->tbl8 == NULL) {
- RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+ RTE_LOG(ERR, LPM, "LPM tbl8 memory allocation failed\n");
+ rte_free(lpm->rules_tbl);
rte_free(lpm);
+ lpm = NULL;
rte_free(te);
goto exit;
}
if (te->data == (void *) lpm)
break;
}
- if (te == NULL) {
- rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
- return;
- }
-
- TAILQ_REMOVE(lpm_list, te, next);
+ if (te != NULL)
+ TAILQ_REMOVE(lpm_list, te, next);
rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
if (te->data == (void *) lpm)
break;
}
- if (te == NULL) {
- rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
- return;
- }
-
- TAILQ_REMOVE(lpm_list, te, next);
+ if (te != NULL)
+ TAILQ_REMOVE(lpm_list, te, next);
rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
+ rte_free(lpm->tbl8);
+ rte_free(lpm->rules_tbl);
rte_free(lpm);
rte_free(te);
}
lpm->tbl24[i].depth <= depth)) {
struct rte_lpm_tbl_entry_v20 new_tbl24_entry = {
- { .next_hop = next_hop, },
.valid = VALID,
.valid_group = 0,
.depth = depth,
};
+ new_tbl24_entry.next_hop = next_hop;
/* Setting tbl24 entry in one go to avoid race
* conditions
.valid = VALID,
.valid_group = VALID,
.depth = depth,
- .next_hop = next_hop,
};
+ new_tbl8_entry.next_hop = next_hop;
/*
* Setting tbl8 entry in one go to avoid
/* Insert new rule into the tbl8 entry. */
for (i = tbl8_index; i < tbl8_index + tbl8_range; i++) {
- if (!lpm->tbl8[i].valid ||
- lpm->tbl8[i].depth <= depth) {
- lpm->tbl8[i].valid = VALID;
- lpm->tbl8[i].depth = depth;
- lpm->tbl8[i].next_hop = next_hop;
-
- continue;
- }
+ lpm->tbl8[i].valid = VALID;
+ lpm->tbl8[i].depth = depth;
+ lpm->tbl8[i].next_hop = next_hop;
}
/*
struct rte_lpm_tbl_entry_v20 new_tbl8_entry = {
.valid = VALID,
.depth = depth,
- .next_hop = next_hop,
.valid_group = lpm->tbl8[i].valid_group,
};
-
+ new_tbl8_entry.next_hop = next_hop;
/*
* Setting tbl8 entry in one go to avoid race
* condition
/* Insert new rule into the tbl8 entry. */
for (i = tbl8_index; i < tbl8_index + tbl8_range; i++) {
- if (!lpm->tbl8[i].valid ||
- lpm->tbl8[i].depth <= depth) {
- lpm->tbl8[i].valid = VALID;
- lpm->tbl8[i].depth = depth;
- lpm->tbl8[i].next_hop = next_hop;
-
- continue;
- }
+ lpm->tbl8[i].valid = VALID;
+ lpm->tbl8[i].depth = depth;
+ lpm->tbl8[i].next_hop = next_hop;
}
/*
.valid = VALID,
.valid_group = VALID,
.depth = sub_rule_depth,
- .next_hop = lpm->rules_tbl
- [sub_rule_index].next_hop,
};
+ new_tbl8_entry.next_hop =
+ lpm->rules_tbl[sub_rule_index].next_hop;
for (i = tbl24_index; i < (tbl24_index + tbl24_range); i++) {
* and if so check the rest of the entries to verify that they
* are all of this depth.
*/
- if (tbl8[tbl8_group_start].depth < MAX_DEPTH_TBL24) {
+ if (tbl8[tbl8_group_start].depth <= MAX_DEPTH_TBL24) {
for (i = (tbl8_group_start + 1); i < tbl8_group_end;
i++) {
* and if so check the rest of the entries to verify that they
* are all of this depth.
*/
- if (tbl8[tbl8_group_start].depth < MAX_DEPTH_TBL24) {
+ if (tbl8[tbl8_group_start].depth <= MAX_DEPTH_TBL24) {
for (i = (tbl8_group_start + 1); i < tbl8_group_end;
i++) {
.valid = VALID,
.depth = sub_rule_depth,
.valid_group = lpm->tbl8[tbl8_group_start].valid_group,
- .next_hop = lpm->rules_tbl[sub_rule_index].next_hop,
};
+ new_tbl8_entry.next_hop =
+ lpm->rules_tbl[sub_rule_index].next_hop;
/*
* Loop through the range of entries on tbl8 for which the
* rule_to_delete must be modified.