* Called when new route table is created. * Selects, allocates and attaches fib algo for the table. */
| 1583 | * Selects, allocates and attaches fib algo for the table. |
| 1584 | */ |
| 1585 | int |
| 1586 | fib_select_algo_initial(struct rib_head *rh) |
| 1587 | { |
| 1588 | struct fib_lookup_module *flm; |
| 1589 | struct fib_data *fd = NULL; |
| 1590 | enum flm_op_result result; |
| 1591 | struct epoch_tracker et; |
| 1592 | int error = 0; |
| 1593 | |
| 1594 | flm = fib_check_best_algo(rh, NULL); |
| 1595 | if (flm == NULL) { |
| 1596 | RH_PRINTF(LOG_CRIT, rh, "no algo selected"); |
| 1597 | return (ENOENT); |
| 1598 | } |
| 1599 | RH_PRINTF(LOG_INFO, rh, "selected algo %s", flm->flm_name); |
| 1600 | |
| 1601 | NET_EPOCH_ENTER(et); |
| 1602 | RIB_WLOCK(rh); |
| 1603 | result = setup_fd_instance(flm, rh, NULL, &fd, false); |
| 1604 | RIB_WUNLOCK(rh); |
| 1605 | NET_EPOCH_EXIT(et); |
| 1606 | |
| 1607 | RH_PRINTF(LOG_DEBUG, rh, "result=%d fd=%p", result, fd); |
| 1608 | if (result == FLM_SUCCESS) { |
| 1609 | |
| 1610 | /* |
| 1611 | * Attach datapath directly to avoid multiple reallocations |
| 1612 | * during fib growth |
| 1613 | */ |
| 1614 | struct fib_dp_header *fdp; |
| 1615 | struct fib_dp **pdp; |
| 1616 | |
| 1617 | pdp = get_family_dp_ptr(rh->rib_family); |
| 1618 | if (pdp != NULL) { |
| 1619 | fdp = get_fib_dp_header(*pdp); |
| 1620 | fdp->fdh_idx[fd->fd_fibnum] = fd->fd_dp; |
| 1621 | FD_PRINTF(LOG_INFO, fd, "datapath attached"); |
| 1622 | } |
| 1623 | } else { |
| 1624 | error = EINVAL; |
| 1625 | RH_PRINTF(LOG_CRIT, rh, "unable to setup algo %s", flm->flm_name); |
| 1626 | } |
| 1627 | |
| 1628 | fib_unref_algo(flm); |
| 1629 | |
| 1630 | return (error); |
| 1631 | } |
| 1632 | |
| 1633 | /* |
| 1634 | * Registers fib lookup module within the subsystem. |
no test coverage detected