src/dpdk/lib/librte_lpm/rte_lpm6.c
static inline int
rule_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint32_t next_hop)
{
	int ret, rule_exist;
	struct rte_lpm6_rule_key rule_key;
	uint32_t unused;

	/* init a rule key */
	rule_key_init(&rule_key, ip, depth);

	/* Scan through rule list to see if rule already exists. */
	rule_exist = rule_find_with_key(lpm, &rule_key, &unused);

	/*
	 * If rule does not exist check if there is space to add a new rule to
	 * this rule group. If there is no space return error.
	 */
	if (!rule_exist && lpm->used_rules == lpm->max_rules)
		return -ENOSPC;

	/* add the rule or update rules next hop */
	ret = rte_hash_add_key_data(lpm->rules_tbl, &rule_key,
		(void *)(uintptr_t) next_hop);
	if (ret < 0)
		return ret;

	/* Increment the used rules counter for this rule group. */
	if (!rule_exist) {
		lpm->used_rules++;
		return 1;
	}

	return 0;
}
/*
 * 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
 */
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.

next hop of existed rule is updated
1 - new rule successfully added
<0 - error
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 . next hop of existed rule is updated 1 - new rule successfully added <0 - error
static inline int
rule_add(struct rte_lpm6 *lpm, uint8_t *ip, uint8_t depth, uint32_t next_hop)
{
	int ret, rule_exist;
	struct rte_lpm6_rule_key rule_key;
	uint32_t unused;
	rule_key_init(&rule_key, ip, depth);
	rule_exist = rule_find_with_key(lpm, &rule_key, &unused);
	if (!rule_exist && lpm->used_rules == lpm->max_rules)
		return -ENOSPC;
	ret = rte_hash_add_key_data(lpm->rules_tbl, &rule_key,
		(void *)(uintptr_t) next_hop);
	if (ret < 0)
		return ret;
	if (!rule_exist) {
		lpm->used_rules++;
		return 1;
	}
	return 0;
}
static inline int rule_add ( struct rte_lpm6 * lpm , uint8_t * ip , uint8_t depth , uint32_t next_hop ) { int ret , rule_exist ; struct rte_lpm6_rule_key rule_key ; uint32_t unused ; rule_key_init ( & rule_key , ip , depth ) ; rule_exist = rule_find_with_key ( lpm , & rule_key , & unused ) ; if ( ! rule_exist && lpm -> used_rules == lpm -> max_rules ) return - ENOSPC ; ret = rte_hash_add_key_data ( lpm -> rules_tbl , & rule_key , ( void * ) ( uintptr_t ) next_hop ) ; if ( ret < 0 ) return ret ; if ( ! rule_exist ) { lpm -> used_rules ++ ; return 1 ; } return 0 ; }
Checks if a rule already exists in the rules table and updates
 the nexthop if so.
Checks if a rule already exists in the rules table and updates the nexthop if so .
/* init a rule key */ /* Scan through rule list to see if rule already exists. */ /*
	 * If rule does not exist check if there is space to add a new rule to
	 * this rule group. If there is no space return error.
	 */ /* add the rule or update rules next hop */ /* Increment the used rules counter for this rule group. */