| 461 | } |
| 462 | |
| 463 | struct rte_rib6 * |
| 464 | rte_rib6_create(const char *name, int socket_id, |
| 465 | const struct rte_rib6_conf *conf) |
| 466 | { |
| 467 | char mem_name[RTE_RIB6_NAMESIZE]; |
| 468 | struct rte_rib6 *rib = NULL; |
| 469 | struct rte_tailq_entry *te; |
| 470 | struct rte_rib6_list *rib6_list; |
| 471 | struct rte_mempool *node_pool; |
| 472 | |
| 473 | /* Check user arguments. */ |
| 474 | if (unlikely(name == NULL || conf == NULL || conf->max_nodes <= 0)) { |
| 475 | rte_errno = EINVAL; |
| 476 | return NULL; |
| 477 | } |
| 478 | |
| 479 | snprintf(mem_name, sizeof(mem_name), "MP_%s", name); |
| 480 | node_pool = rte_mempool_create(mem_name, conf->max_nodes, |
| 481 | sizeof(struct rte_rib6_node) + conf->ext_sz, 0, 0, |
| 482 | NULL, NULL, NULL, NULL, socket_id, 0); |
| 483 | |
| 484 | if (node_pool == NULL) { |
| 485 | RTE_LOG(ERR, LPM, |
| 486 | "Can not allocate mempool for RIB6 %s\n", name); |
| 487 | return NULL; |
| 488 | } |
| 489 | |
| 490 | snprintf(mem_name, sizeof(mem_name), "RIB6_%s", name); |
| 491 | rib6_list = RTE_TAILQ_CAST(rte_rib6_tailq.head, rte_rib6_list); |
| 492 | |
| 493 | rte_mcfg_tailq_write_lock(); |
| 494 | |
| 495 | /* guarantee there's no existing */ |
| 496 | TAILQ_FOREACH(te, rib6_list, next) { |
| 497 | rib = (struct rte_rib6 *)te->data; |
| 498 | if (strncmp(name, rib->name, RTE_RIB6_NAMESIZE) == 0) |
| 499 | break; |
| 500 | } |
| 501 | rib = NULL; |
| 502 | if (te != NULL) { |
| 503 | rte_errno = EEXIST; |
| 504 | goto exit; |
| 505 | } |
| 506 | |
| 507 | /* allocate tailq entry */ |
| 508 | te = rte_zmalloc("RIB6_TAILQ_ENTRY", sizeof(*te), 0); |
| 509 | if (unlikely(te == NULL)) { |
| 510 | RTE_LOG(ERR, LPM, |
| 511 | "Can not allocate tailq entry for RIB6 %s\n", name); |
| 512 | rte_errno = ENOMEM; |
| 513 | goto exit; |
| 514 | } |
| 515 | |
| 516 | /* Allocate memory to store the RIB6 data structures. */ |
| 517 | rib = rte_zmalloc_socket(mem_name, |
| 518 | sizeof(struct rte_rib6), RTE_CACHE_LINE_SIZE, socket_id); |
| 519 | if (unlikely(rib == NULL)) { |
| 520 | RTE_LOG(ERR, LPM, "RIB6 %s memory allocation failed\n", name); |