* Checks if a rule already exists in the rules table and updates * the nexthop if so. Otherwise it adds a new rule if enough space is available. * * Returns: * 0 - next hop of existed rule is updated * 1 - new rule successfully added * <0 - error */
| 479 | * <0 - error |
| 480 | */ |
| 481 | static inline int |
| 482 | rule_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint32_t next_hop) |
| 483 | { |
| 484 | int ret, rule_exist; |
| 485 | struct rte_lpm6_rule_key rule_key; |
| 486 | uint32_t unused; |
| 487 | |
| 488 | /* init a rule key */ |
| 489 | rule_key_init(&rule_key, ip, depth); |
| 490 | |
| 491 | /* Scan through rule list to see if rule already exists. */ |
| 492 | rule_exist = rule_find_with_key(lpm, &rule_key, &unused); |
| 493 | |
| 494 | /* |
| 495 | * If rule does not exist check if there is space to add a new rule to |
| 496 | * this rule group. If there is no space return error. |
| 497 | */ |
| 498 | if (!rule_exist && lpm->used_rules == lpm->max_rules) |
| 499 | return -ENOSPC; |
| 500 | |
| 501 | /* add the rule or update rules next hop */ |
| 502 | ret = rte_hash_add_key_data(lpm->rules_tbl, &rule_key, |
| 503 | (void *)(uintptr_t) next_hop); |
| 504 | if (ret < 0) |
| 505 | return ret; |
| 506 | |
| 507 | /* Increment the used rules counter for this rule group. */ |
| 508 | if (!rule_exist) { |
| 509 | lpm->used_rules++; |
| 510 | return 1; |
| 511 | } |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * Function that expands a rule across the data structure when a less-generic |
no test coverage detected