MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rte_lpm6_add

Function rte_lpm6_add

dpdk/lib/lpm/rte_lpm6.c:851–902  ·  view source on GitHub ↗

* Add a route */

Source from the content-addressed store, hash-verified

849 * Add a route
850 */
851int
852rte_lpm6_add(struct rte_lpm6 *lpm, const uint8_t *ip, uint8_t depth,
853 uint32_t next_hop)
854{
855 struct rte_lpm6_tbl_entry *tbl;
856 struct rte_lpm6_tbl_entry *tbl_next = NULL;
857 /* init to avoid compiler warning */
858 uint32_t tbl_next_num = 123456;
859 int status;
860 uint8_t masked_ip[RTE_LPM6_IPV6_ADDR_SIZE];
861 int i;
862
863 /* Check user arguments. */
864 if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM6_MAX_DEPTH))
865 return -EINVAL;
866
867 /* Copy the IP and mask it to avoid modifying user's input data. */
868 ip6_copy_addr(masked_ip, ip);
869 ip6_mask_addr(masked_ip, depth);
870
871 /* Simulate adding a new route */
872 int ret = simulate_add(lpm, masked_ip, depth);
873 if (ret < 0)
874 return ret;
875
876 /* Add the rule to the rule table. */
877 int is_new_rule = rule_add(lpm, masked_ip, depth, next_hop);
878 /* If there is no space available for new rule return error. */
879 if (is_new_rule < 0)
880 return is_new_rule;
881
882 /* Inspect the first three bytes through tbl24 on the first step. */
883 tbl = lpm->tbl24;
884 status = add_step(lpm, tbl, TBL24_IND, &tbl_next, &tbl_next_num,
885 masked_ip, ADD_FIRST_BYTE, 1, depth, next_hop,
886 is_new_rule);
887 assert(status >= 0);
888
889 /*
890 * Inspect one by one the rest of the bytes until
891 * the process is completed.
892 */
893 for (i = ADD_FIRST_BYTE; i < RTE_LPM6_IPV6_ADDR_SIZE && status == 1; i++) {
894 tbl = tbl_next;
895 status = add_step(lpm, tbl, tbl_next_num, &tbl_next,
896 &tbl_next_num, masked_ip, 1, (uint8_t)(i + 1),
897 depth, next_hop, is_new_rule);
898 assert(status >= 0);
899 }
900
901 return status;
902}
903
904/*
905 * Takes a pointer to a table entry and inspect one level.

Callers 15

rebuild_lpmFunction · 0.70
rte_node_ip6_route_addFunction · 0.50
run_v6Function · 0.50
test_lpm6_perfFunction · 0.50
test4Function · 0.50
test9Function · 0.50
test10Function · 0.50
test11Function · 0.50
test12Function · 0.50
test13Function · 0.50
test14Function · 0.50

Calls 5

ip6_copy_addrFunction · 0.70
ip6_mask_addrFunction · 0.70
simulate_addFunction · 0.70
rule_addFunction · 0.70
add_stepFunction · 0.70

Tested by 15

test_lpm6_perfFunction · 0.40
test4Function · 0.40
test9Function · 0.40
test10Function · 0.40
test11Function · 0.40
test12Function · 0.40
test13Function · 0.40
test14Function · 0.40
test15Function · 0.40
test16Function · 0.40
test17Function · 0.40
test18Function · 0.40