X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Flibrte_lpm%2Frte_lpm.c;h=8c15c4c9ffb204316c407bfc2c31d6f50739bd59;hb=c7e9d6a6ed90a022067f42727d5d1675a3f3df11;hp=3dee15c5e07a8a388efbcbee2e4a31161b406695;hpb=d4c18f0a1d5d03297a393b6bcda90e5acc27c710;p=dpdk.git diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index 3dee15c5e0..8c15c4c9ff 100644 --- a/lib/librte_lpm/rte_lpm.c +++ b/lib/librte_lpm/rte_lpm.c @@ -209,8 +209,11 @@ rte_lpm_create_v20(const char *name, int socket_id, int max_rules, 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); @@ -280,8 +283,11 @@ rte_lpm_create_v1604(const char *name, int socket_id, 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); @@ -303,8 +309,9 @@ rte_lpm_create_v1604(const char *name, int socket_id, (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; } @@ -313,8 +320,10 @@ rte_lpm_create_v1604(const char *name, int socket_id, (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; } @@ -365,7 +374,6 @@ rte_lpm_free_v20(struct rte_lpm_v20 *lpm) rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); - rte_free(lpm->rules_tbl); rte_free(lpm); rte_free(te); } @@ -395,6 +403,7 @@ rte_lpm_free_v1604(struct rte_lpm *lpm) rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK); + rte_free(lpm->tbl8); rte_free(lpm->rules_tbl); rte_free(lpm); rte_free(te); @@ -742,11 +751,11 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth, 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 @@ -773,8 +782,8 @@ add_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth, .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 @@ -933,14 +942,9 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth, /* 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; } /* @@ -973,10 +977,9 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth, 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 @@ -1065,14 +1068,9 @@ add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth, /* 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; } /* @@ -1373,9 +1371,9 @@ delete_depth_small_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, .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++) { @@ -1527,7 +1525,7 @@ tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8, * 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++) { @@ -1574,7 +1572,7 @@ tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8, * 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++) { @@ -1637,9 +1635,10 @@ delete_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, .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.