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

Function rte_rib_create

dpdk/lib/rib/rte_rib.c:395–474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393}
394
395struct rte_rib *
396rte_rib_create(const char *name, int socket_id, const struct rte_rib_conf *conf)
397{
398 char mem_name[RTE_RIB_NAMESIZE];
399 struct rte_rib *rib = NULL;
400 struct rte_tailq_entry *te;
401 struct rte_rib_list *rib_list;
402 struct rte_mempool *node_pool;
403
404 /* Check user arguments. */
405 if (unlikely(name == NULL || conf == NULL || conf->max_nodes <= 0)) {
406 rte_errno = EINVAL;
407 return NULL;
408 }
409
410 snprintf(mem_name, sizeof(mem_name), "MP_%s", name);
411 node_pool = rte_mempool_create(mem_name, conf->max_nodes,
412 sizeof(struct rte_rib_node) + conf->ext_sz, 0, 0,
413 NULL, NULL, NULL, NULL, socket_id, 0);
414
415 if (node_pool == NULL) {
416 RTE_LOG(ERR, LPM,
417 "Can not allocate mempool for RIB %s\n", name);
418 return NULL;
419 }
420
421 snprintf(mem_name, sizeof(mem_name), "RIB_%s", name);
422 rib_list = RTE_TAILQ_CAST(rte_rib_tailq.head, rte_rib_list);
423
424 rte_mcfg_tailq_write_lock();
425
426 /* guarantee there's no existing */
427 TAILQ_FOREACH(te, rib_list, next) {
428 rib = (struct rte_rib *)te->data;
429 if (strncmp(name, rib->name, RTE_RIB_NAMESIZE) == 0)
430 break;
431 }
432 rib = NULL;
433 if (te != NULL) {
434 rte_errno = EEXIST;
435 goto exit;
436 }
437
438 /* allocate tailq entry */
439 te = rte_zmalloc("RIB_TAILQ_ENTRY", sizeof(*te), 0);
440 if (unlikely(te == NULL)) {
441 RTE_LOG(ERR, LPM,
442 "Can not allocate tailq entry for RIB %s\n", name);
443 rte_errno = ENOMEM;
444 goto exit;
445 }
446
447 /* Allocate memory to store the RIB data structures. */
448 rib = rte_zmalloc_socket(mem_name,
449 sizeof(struct rte_rib), RTE_CACHE_LINE_SIZE, socket_id);
450 if (unlikely(rib == NULL)) {
451 RTE_LOG(ERR, LPM, "RIB %s memory allocation failed\n", name);
452 rte_errno = ENOMEM;

Callers 8

rte_fib_createFunction · 0.85
test_create_invalidFunction · 0.85
test_multiple_createFunction · 0.85
test_free_nullFunction · 0.85
test_insert_invalidFunction · 0.85
test_get_fnFunction · 0.85
test_basicFunction · 0.85
test_tree_traversalFunction · 0.85

Calls 10

snprintfFunction · 0.85
rte_mempool_createFunction · 0.85
strncmpFunction · 0.85
rte_zmallocFunction · 0.85
rte_zmalloc_socketFunction · 0.85
rte_strlcpyFunction · 0.85
rte_freeFunction · 0.85
rte_mempool_freeFunction · 0.85

Tested by 7

test_create_invalidFunction · 0.68
test_multiple_createFunction · 0.68
test_free_nullFunction · 0.68
test_insert_invalidFunction · 0.68
test_get_fnFunction · 0.68
test_basicFunction · 0.68
test_tree_traversalFunction · 0.68