| 69 | /* Hash management functions */ |
| 70 | |
| 71 | int |
| 72 | nhops_init_rib(struct rib_head *rh) |
| 73 | { |
| 74 | struct nh_control *ctl; |
| 75 | size_t alloc_size; |
| 76 | uint32_t num_buckets, num_items; |
| 77 | void *ptr; |
| 78 | |
| 79 | ctl = malloc(sizeof(struct nh_control), M_NHOP, M_WAITOK | M_ZERO); |
| 80 | |
| 81 | /* |
| 82 | * Allocate nexthop hash. Start with 16 items by default (128 bytes). |
| 83 | * This will be enough for most of the cases. |
| 84 | */ |
| 85 | num_buckets = 16; |
| 86 | alloc_size = CHT_SLIST_GET_RESIZE_SIZE(num_buckets); |
| 87 | ptr = malloc(alloc_size, M_NHOP, M_WAITOK | M_ZERO); |
| 88 | CHT_SLIST_INIT(&ctl->nh_head, ptr, num_buckets); |
| 89 | |
| 90 | /* |
| 91 | * Allocate nexthop index bitmask. |
| 92 | */ |
| 93 | num_items = 128 * 8; /* 128 bytes */ |
| 94 | ptr = malloc(bitmask_get_size(num_items), M_NHOP, M_WAITOK | M_ZERO); |
| 95 | bitmask_init(&ctl->nh_idx_head, ptr, num_items); |
| 96 | |
| 97 | NHOPS_LOCK_INIT(ctl); |
| 98 | |
| 99 | rh->nh_control = ctl; |
| 100 | ctl->ctl_rh = rh; |
| 101 | |
| 102 | DPRINTF("NHOPS init for fib %u af %u: ctl %p rh %p", rh->rib_fibnum, |
| 103 | rh->rib_family, ctl, rh); |
| 104 | |
| 105 | return (0); |
| 106 | } |
| 107 | |
| 108 | static void |
| 109 | destroy_ctl(struct nh_control *ctl) |
no test coverage detected