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

Function nhgrp_ctl_alloc_default

freebsd/net/route/nhgrp.c:260–307  ·  view source on GitHub ↗

* Function allocating the necessary group data structures. */

Source from the content-addressed store, hash-verified

258 * Function allocating the necessary group data structures.
259 */
260bool
261nhgrp_ctl_alloc_default(struct nh_control *ctl, int malloc_flags)
262{
263 size_t alloc_size;
264 uint32_t num_buckets, num_items;
265 void *cht_ptr, *mask_ptr;
266
267 malloc_flags = (malloc_flags & (M_NOWAIT | M_WAITOK)) | M_ZERO;
268
269 num_buckets = 8;
270 alloc_size = CHT_SLIST_GET_RESIZE_SIZE(num_buckets);
271 cht_ptr = malloc(alloc_size, M_NHOP, malloc_flags);
272
273 if (cht_ptr == NULL) {
274 DPRINTF("mpath init failed");
275 return (false);
276 }
277
278 /*
279 * Allocate nexthop index bitmask.
280 */
281 num_items = 128;
282 mask_ptr = malloc(bitmask_get_size(num_items), M_NHOP, malloc_flags);
283 if (mask_ptr == NULL) {
284 DPRINTF("mpath bitmask init failed");
285 free(cht_ptr, M_NHOP);
286 return (false);
287 }
288
289 NHOPS_WLOCK(ctl);
290
291 if (ctl->gr_head.hash_size == 0) {
292 /* Init hash and bitmask */
293 CHT_SLIST_INIT(&ctl->gr_head, cht_ptr, num_buckets);
294 bitmask_init(&ctl->gr_idx_head, mask_ptr, num_items);
295 NHOPS_WUNLOCK(ctl);
296 } else {
297 /* Other thread has already initiliazed hash/bitmask */
298 NHOPS_WUNLOCK(ctl);
299 free(cht_ptr, M_NHOP);
300 free(mask_ptr, M_NHOP);
301 }
302
303 DPRINTF("mpath init done for fib/af %d/%d", ctl->rh->rib_fibnum,
304 ctl->rh->rib_family);
305
306 return (true);
307}
308
309int
310nhgrp_ctl_init(struct nh_control *ctl)

Callers 1

get_nhgrpFunction · 0.85

Calls 4

mallocFunction · 0.85
bitmask_get_sizeFunction · 0.85
bitmask_initFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected