aboutsummaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2021-10-06 19:07:54 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2021-10-08 07:58:55 +0000
commit7e64580b5f477ba4523799f26d1178f611f5d6cb (patch)
tree0feac3f12032a3c148781d5d6ca6b6d319b03cac /sys/net
parentdfb7360222856e7e4f5e0e5564281a25af63319c (diff)
downloadsrc-7e64580b5f477ba4523799f26d1178f611f5d6cb.tar.gz
src-7e64580b5f477ba4523799f26d1178f611f5d6cb.zip
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
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/route/fib_algo.c6
-rw-r--r--sys/net/route/nhgrp.c31
-rw-r--r--sys/net/route/nhop_var.h1
3 files changed, 9 insertions, 29 deletions
diff --git a/sys/net/route/fib_algo.c b/sys/net/route/fib_algo.c
index 4bae9e5edd6c..54b0464711a5 100644
--- a/sys/net/route/fib_algo.c
+++ b/sys/net/route/fib_algo.c
@@ -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
diff --git a/sys/net/route/nhgrp.c b/sys/net/route/nhgrp.c
index 982ff2a72f15..07abdf480101 100644
--- a/sys/net/route/nhgrp.c
+++ b/sys/net/route/nhgrp.c
@@ -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
diff --git a/sys/net/route/nhop_var.h b/sys/net/route/nhop_var.h
index 4ce82dd4a968..76984df0497f 100644
--- a/sys/net/route/nhop_var.h
+++ b/sys/net/route/nhop_var.h
@@ -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 */