* Deletes a rule */
| 1286 | * Deletes a rule |
| 1287 | */ |
| 1288 | int |
| 1289 | rte_lpm6_delete(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth) |
| 1290 | { |
| 1291 | uint8_t masked_ip[RTE_LPM6_IPV6_ADDR_SIZE]; |
| 1292 | struct rte_lpm6_rule lsp_rule_obj; |
| 1293 | struct rte_lpm6_rule *lsp_rule; |
| 1294 | int ret; |
| 1295 | uint32_t tbl_ind; |
| 1296 | struct rte_lpm6_tbl_entry *from, *to; |
| 1297 | |
| 1298 | /* Check input arguments. */ |
| 1299 | if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH)) |
| 1300 | return -EINVAL; |
| 1301 | |
| 1302 | /* Copy the IP and mask it to avoid modifying user's input data. */ |
| 1303 | ip6_copy_addr(masked_ip, ip); |
| 1304 | ip6_mask_addr(masked_ip, depth); |
| 1305 | |
| 1306 | /* Delete the rule from the rule table. */ |
| 1307 | ret = rule_delete(lpm, masked_ip, depth); |
| 1308 | if (ret < 0) |
| 1309 | return -ENOENT; |
| 1310 | |
| 1311 | /* find rule cells */ |
| 1312 | rule_find_range(lpm, masked_ip, depth, &from, &to, &tbl_ind); |
| 1313 | |
| 1314 | /* find a less specific rule (a rule with smaller depth) |
| 1315 | * note: masked_ip will be modified, don't use it anymore |
| 1316 | */ |
| 1317 | ret = rule_find_less_specific(lpm, masked_ip, depth, |
| 1318 | &lsp_rule_obj); |
| 1319 | lsp_rule = ret ? &lsp_rule_obj : NULL; |
| 1320 | |
| 1321 | /* decrement the table rule counter, |
| 1322 | * note that tbl24 doesn't have a header |
| 1323 | */ |
| 1324 | if (tbl_ind != TBL24_IND) { |
| 1325 | struct rte_lpm_tbl8_hdr *tbl_hdr = &lpm->tbl8_hdrs[tbl_ind]; |
| 1326 | if (--tbl_hdr->ref_cnt == 0) { |
| 1327 | /* remove the table */ |
| 1328 | remove_tbl(lpm, tbl_hdr, tbl_ind, lsp_rule); |
| 1329 | return 0; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | /* iterate rule cells */ |
| 1334 | for (; from <= to; from++) |
| 1335 | if (from->ext_entry == 1) { |
| 1336 | /* reference to a more specific space |
| 1337 | * of the prefix/rule. Entries in a more |
| 1338 | * specific space that are not used by |
| 1339 | * a more specific prefix must be occupied |
| 1340 | * by the prefix |
| 1341 | */ |
| 1342 | if (lsp_rule != NULL) |
| 1343 | expand_rule(lpm, |
| 1344 | from->lpm6_tbl8_gindex * |
| 1345 | RTE_LPM6_TBL8_GROUP_NUM_ENTRIES, |