routing: Use the same index space for both nexthop and nexthop groups.

This simplifies userland object handling along with kernel-level
 nexthop handling in fib algo framework.

MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D32342
This commit is contained in:
Alexander V. Chernikov 2021-10-06 19:07:54 +00:00
parent dfb7360222
commit 7e64580b5f
3 changed files with 9 additions and 29 deletions

View File

@ -1764,12 +1764,10 @@ get_nhop_idx(struct nhop_object *nh)
{
#ifdef ROUTE_MPATH
if (NH_IS_NHGRP(nh))
return (nhgrp_get_idx((struct nhgrp_object *)nh) * 2 - 1);
return (nhgrp_get_idx((struct nhgrp_object *)nh));
else
return (nhop_get_idx(nh) * 2);
#else
return (nhop_get_idx(nh));
#endif
return (nhop_get_idx(nh));
}
uint32_t

View File

@ -159,9 +159,9 @@ link_nhgrp(struct nh_control *ctl, struct nhgrp_priv *grp_priv)
NHOPS_WLOCK(ctl);
/* Check if we need to resize hash and index */
new_num_buckets = CHT_SLIST_GET_RESIZE_BUCKETS(&ctl->gr_head);
new_num_items = bitmask_get_resize_items(&ctl->gr_idx_head);
new_num_items = bitmask_get_resize_items(&ctl->nh_idx_head);
if (bitmask_alloc_idx(&ctl->gr_idx_head, &idx) != 0) {
if (bitmask_alloc_idx(&ctl->nh_idx_head, &idx) != 0) {
NHOPS_WUNLOCK(ctl);
DPRINTF("Unable to allocate mpath index");
consider_resize(ctl, new_num_buckets, new_num_items);
@ -196,7 +196,7 @@ unlink_nhgrp(struct nh_control *ctl, struct nhgrp_priv *key)
}
idx = nhg_priv_ret->nhg_idx;
ret = bitmask_free_idx(&ctl->gr_idx_head, idx);
ret = bitmask_free_idx(&ctl->nh_idx_head, idx);
nhg_priv_ret->nhg_idx = 0;
nhg_priv_ret->nh_control = NULL;
@ -243,8 +243,8 @@ consider_resize(struct nh_control *ctl, uint32_t new_gr_bucket, uint32_t new_idx
CHT_SLIST_RESIZE(&ctl->gr_head, mpath, gr_ptr, new_gr_bucket);
}
if (gr_idx_ptr != NULL) {
if (bitmask_copy(&ctl->gr_idx_head, gr_idx_ptr, new_idx_items) == 0)
bitmask_swap(&ctl->gr_idx_head, gr_idx_ptr, new_idx_items, &old_idx_ptr);
if (bitmask_copy(&ctl->nh_idx_head, gr_idx_ptr, new_idx_items) == 0)
bitmask_swap(&ctl->nh_idx_head, gr_idx_ptr, new_idx_items, &old_idx_ptr);
}
NHOPS_WUNLOCK(ctl);
@ -261,8 +261,8 @@ bool
nhgrp_ctl_alloc_default(struct nh_control *ctl, int malloc_flags)
{
size_t alloc_size;
uint32_t num_buckets, num_items;
void *cht_ptr, *mask_ptr;
uint32_t num_buckets;
void *cht_ptr;
malloc_flags = (malloc_flags & (M_NOWAIT | M_WAITOK)) | M_ZERO;
@ -275,29 +275,16 @@ nhgrp_ctl_alloc_default(struct nh_control *ctl, int malloc_flags)
return (false);
}
/*
* Allocate nexthop index bitmask.
*/
num_items = 128;
mask_ptr = malloc(bitmask_get_size(num_items), M_NHOP, malloc_flags);
if (mask_ptr == NULL) {
DPRINTF("mpath bitmask init failed");
free(cht_ptr, M_NHOP);
return (false);
}
NHOPS_WLOCK(ctl);
if (ctl->gr_head.hash_size == 0) {
/* Init hash and bitmask */
CHT_SLIST_INIT(&ctl->gr_head, cht_ptr, num_buckets);
bitmask_init(&ctl->gr_idx_head, mask_ptr, num_items);
NHOPS_WUNLOCK(ctl);
} else {
/* Other thread has already initiliazed hash/bitmask */
NHOPS_WUNLOCK(ctl);
free(cht_ptr, M_NHOP);
free(mask_ptr, M_NHOP);
}
DPRINTF("mpath init done for fib/af %d/%d", ctl->rh->rib_fibnum,
@ -315,18 +302,14 @@ nhgrp_ctl_init(struct nh_control *ctl)
* routes will not be necessarily used.
*/
CHT_SLIST_INIT(&ctl->gr_head, NULL, 0);
bitmask_init(&ctl->gr_idx_head, NULL, 0);
return (0);
}
void
nhgrp_ctl_free(struct nh_control *ctl)
{
if (ctl->gr_head.ptr != NULL)
free(ctl->gr_head.ptr, M_NHOP);
if (ctl->gr_idx_head.idx != NULL)
free(ctl->gr_idx_head.idx, M_NHOP);
}
void

View File

@ -57,7 +57,6 @@ struct nh_control {
struct nhops_head nh_head; /* hash table head */
struct bitmask_head nh_idx_head; /* nhop index head */
struct nhgroups_head gr_head; /* nhgrp hash table head */
struct bitmask_head gr_idx_head; /* nhgrp index head */
struct rwlock ctl_lock; /* overall ctl lock */
struct rib_head *ctl_rh; /* pointer back to rnh */
struct epoch_context ctl_epoch_ctx; /* epoch ctl helper */