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

Function try_setup_fd_instance

freebsd/net/route/fib_algo.c:877–965  ·  view source on GitHub ↗

* Tries to setup fd instance. * - Allocates fd/nhop table * - Runs algo:flm_init_cb algo init * - Subscribes fd to the rib * - Runs rtable dump * - Adds instance to the list of active instances. * * Returns: operation result. Fills in @pfd with resulting fd on success. * */

Source from the content-addressed store, hash-verified

875 *
876 */
877static enum flm_op_result
878try_setup_fd_instance(struct fib_lookup_module *flm, struct rib_head *rh,
879 struct fib_data *old_fd, struct fib_data **pfd)
880{
881 struct fib_data *fd;
882 size_t size;
883 enum flm_op_result result;
884
885 /* Allocate */
886 fd = malloc(sizeof(struct fib_data), M_RTABLE, M_NOWAIT | M_ZERO);
887 if (fd == NULL) {
888 *pfd = NULL;
889 RH_PRINTF(LOG_INFO, rh, "Unable to allocate fib_data structure");
890 return (FLM_REBUILD);
891 }
892 *pfd = fd;
893
894 estimate_nhop_scale(old_fd, fd);
895
896 fd->fd_rh = rh;
897 fd->fd_gen = ++fib_gen;
898 fd->fd_family = rh->rib_family;
899 fd->fd_fibnum = rh->rib_fibnum;
900 callout_init_rm(&fd->fd_callout, &rh->rib_lock, 0);
901 fd->fd_vnet = curvnet;
902 fd->fd_flm = flm;
903
904 FD_PRINTF(LOG_DEBUG, fd, "allocated fd %p", fd);
905
906 FIB_MOD_LOCK();
907 flm->flm_refcount++;
908 FIB_MOD_UNLOCK();
909
910 /* Allocate nhidx -> nhop_ptr table */
911 size = fd->number_nhops * sizeof(void *);
912 fd->nh_idx = malloc(size, M_RTABLE, M_NOWAIT | M_ZERO);
913 if (fd->nh_idx == NULL) {
914 FD_PRINTF(LOG_INFO, fd, "Unable to allocate nhop table idx (sz:%zu)", size);
915 return (FLM_REBUILD);
916 }
917
918 /* Allocate nhop index refcount table */
919 size = sizeof(struct nhop_ref_table);
920 size += fd->number_nhops * sizeof(uint32_t);
921 fd->nh_ref_table = malloc(size, M_RTABLE, M_NOWAIT | M_ZERO);
922 if (fd->nh_ref_table == NULL) {
923 FD_PRINTF(LOG_INFO, fd, "Unable to allocate nhop refcount table (sz:%zu)", size);
924 return (FLM_REBUILD);
925 }
926 FD_PRINTF(LOG_DEBUG, fd, "Allocated %u nhop indexes", fd->number_nhops);
927
928 /* Okay, we're ready for algo init */
929 void *old_algo_data = (old_fd != NULL) ? old_fd->fd_algo_data : NULL;
930 result = flm->flm_init_cb(fd->fd_fibnum, fd, old_algo_data, &fd->fd_algo_data);
931 if (result != FLM_SUCCESS) {
932 FD_PRINTF(LOG_INFO, fd, "%s algo init failed", flm->flm_name);
933 return (result);
934 }

Callers 1

setup_fd_instanceFunction · 0.85

Calls 4

mallocFunction · 0.85
estimate_nhop_scaleFunction · 0.85
rib_subscribe_lockedFunction · 0.85
sync_algoFunction · 0.85

Tested by

no test coverage detected