git: ae6bfd12c8c8 - main - routing: refactor private KPI * Make nhgrp_get_nhops() return const struct weightened_nhop to indicate that the list is immutable * Make nhgrp_get_group() return the actual group, instead of group+weight.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 01 Aug 2022 10:06:32 UTC
The branch main has been updated by melifaro:
URL: https://cgit.FreeBSD.org/src/commit/?id=ae6bfd12c8c887b323d623c6c21d29f25622d42d
commit ae6bfd12c8c887b323d623c6c21d29f25622d42d
Author: Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-08-01 10:02:12 +0000
Commit: Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2022-08-01 10:02:12 +0000
routing: refactor private KPI
* Make nhgrp_get_nhops() return const struct weightened_nhop to
indicate that the list is immutable
* Make nhgrp_get_group() return the actual group, instead of
group+weight.
MFC after: 2 weeks
---
sys/net/route/nhgrp_ctl.c | 13 ++++++-------
sys/net/route/route_ctl.c | 11 ++++++-----
sys/net/route/route_ctl.h | 2 +-
sys/net/route/route_helpers.c | 4 ++--
sys/net/route/route_var.h | 2 +-
sys/net/rtsock.c | 4 ++--
sys/netinet/in_fib.c | 2 +-
sys/netinet6/in6_fib.c | 2 +-
8 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c
index bad237a334ef..f0b26916136c 100644
--- a/sys/net/route/nhgrp_ctl.c
+++ b/sys/net/route/nhgrp_ctl.c
@@ -598,7 +598,7 @@ append_nhops(struct nh_control *ctl, const struct nhgrp_object *gr_orig,
*/
int
nhgrp_get_group(struct rib_head *rh, struct weightened_nhop *wn, int num_nhops,
- struct route_nhop_data *rnd)
+ struct nhgrp_object **pnhg)
{
struct nh_control *ctl = rh->nh_control;
struct nhgrp_priv *nhg_priv;
@@ -606,8 +606,7 @@ nhgrp_get_group(struct rib_head *rh, struct weightened_nhop *wn, int num_nhops,
nhg_priv = get_nhgrp(ctl, wn, num_nhops, &error);
if (nhg_priv != NULL)
- rnd->rnd_nhgrp = nhg_priv->nhg;
- rnd->rnd_weight = 0;
+ *pnhg = nhg_priv->nhg;
return (error);
}
@@ -718,14 +717,14 @@ nhgrp_get_addition_group(struct rib_head *rh, struct route_nhop_data *rnd_orig,
* Returns pointer to array of nexthops with weights for
* given @nhg. Stores number of items in the array into @pnum_nhops.
*/
-struct weightened_nhop *
-nhgrp_get_nhops(struct nhgrp_object *nhg, uint32_t *pnum_nhops)
+const struct weightened_nhop *
+nhgrp_get_nhops(const struct nhgrp_object *nhg, uint32_t *pnum_nhops)
{
- struct nhgrp_priv *nhg_priv;
+ const struct nhgrp_priv *nhg_priv;
KASSERT(((nhg->nhg_flags & MPF_MULTIPATH) != 0), ("nhop is not mpath"));
- nhg_priv = NHGRP_PRIV(nhg);
+ nhg_priv = NHGRP_PRIV_CONST(nhg);
*pnum_nhops = nhg_priv->nhg_nh_count;
return (nhg_priv->nhg_nh_weights);
diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c
index 80682b7f3b87..394260e1421c 100644
--- a/sys/net/route/route_ctl.c
+++ b/sys/net/route/route_ctl.c
@@ -155,7 +155,7 @@ destroy_rtentry(struct rtentry *rt)
*/
#ifdef ROUTE_MPATH
if (NH_IS_NHGRP(nh)) {
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops);
nh = wn[0].nh;
@@ -1010,8 +1010,9 @@ change_mpath_route(struct rib_head *rnh, struct rt_addrinfo *info,
{
int error = 0, found_idx = 0;
struct nhop_object *nh_orig = NULL, *nh_new;
- struct route_nhop_data rnd_new;
- struct weightened_nhop *wn = NULL, *wn_new;
+ struct route_nhop_data rnd_new = {};
+ const struct weightened_nhop *wn = NULL;
+ struct weightened_nhop *wn_new;
uint32_t num_nhops;
wn = nhgrp_get_nhops(rnd_orig->rnd_nhgrp, &num_nhops);
@@ -1041,7 +1042,7 @@ change_mpath_route(struct rib_head *rnh, struct rt_addrinfo *info,
wn_new[found_idx].nh = nh_new;
wn_new[found_idx].weight = get_info_weight(info, wn[found_idx].weight);
- error = nhgrp_get_group(rnh, wn_new, num_nhops, &rnd_new);
+ error = nhgrp_get_group(rnh, wn_new, num_nhops, &rnd_new.rnd_nhgrp);
nhop_free(nh_new);
free(wn_new, M_TEMP);
@@ -1375,7 +1376,7 @@ rib_walk_del(u_int fibnum, int family, rib_filter_f_t *filter_f, void *arg, bool
if (report) {
#ifdef ROUTE_MPATH
struct nhgrp_object *nhg;
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
if (NH_IS_NHGRP(nh)) {
nhg = (struct nhgrp_object *)nh;
diff --git a/sys/net/route/route_ctl.h b/sys/net/route/route_ctl.h
index a670979df8c9..7a1f7f04be9b 100644
--- a/sys/net/route/route_ctl.h
+++ b/sys/net/route/route_ctl.h
@@ -135,7 +135,7 @@ uint32_t nhops_get_count(struct rib_head *rh);
/* Multipath */
struct weightened_nhop;
-struct weightened_nhop *nhgrp_get_nhops(struct nhgrp_object *nhg,
+const struct weightened_nhop *nhgrp_get_nhops(const struct nhgrp_object *nhg,
uint32_t *pnum_nhops);
uint32_t nhgrp_get_count(struct rib_head *rh);
diff --git a/sys/net/route/route_helpers.c b/sys/net/route/route_helpers.c
index 6c7f16eb047e..5472465d4f5f 100644
--- a/sys/net/route/route_helpers.c
+++ b/sys/net/route/route_helpers.c
@@ -290,7 +290,7 @@ decompose_change_notification(struct rib_cmd_info *rc, route_notification_t *cb,
void *cbdata)
{
uint32_t num_old, num_new;
- struct weightened_nhop *wn_old, *wn_new;
+ const struct weightened_nhop *wn_old, *wn_new;
struct weightened_nhop tmp = { NULL, 0 };
uint32_t idx_old = 0, idx_new = 0;
@@ -378,7 +378,7 @@ void
rib_decompose_notification(struct rib_cmd_info *rc, route_notification_t *cb,
void *cbdata)
{
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
struct rib_cmd_info rc_new;
diff --git a/sys/net/route/route_var.h b/sys/net/route/route_var.h
index e54ea08f4e80..403e432ea836 100644
--- a/sys/net/route/route_var.h
+++ b/sys/net/route/route_var.h
@@ -295,7 +295,7 @@ void nhgrp_ctl_unlink_all(struct nh_control *ctl);
int nhgrp_dump_sysctl(struct rib_head *rh, struct sysctl_req *w);
int nhgrp_get_group(struct rib_head *rh, struct weightened_nhop *wn,
- int num_nhops, struct route_nhop_data *rnd);
+ int num_nhops, struct nhgrp_object **pnhg);
typedef bool nhgrp_filter_cb_t(const struct nhop_object *nh, void *data);
int nhgrp_get_filtered_group(struct rib_head *rh, const struct nhgrp_object *src,
nhgrp_filter_cb_t flt_func, void *flt_data, struct route_nhop_data *rnd);
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index d189af761206..cbec7d351bd5 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -718,7 +718,7 @@ select_nhop(struct nhop_object *nh, const struct sockaddr *gw)
if (!NH_IS_NHGRP(nh))
return (nh);
#ifdef ROUTE_MPATH
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops);
if (gw == NULL)
@@ -2243,7 +2243,7 @@ sysctl_dumpentry(struct rtentry *rt, void *vw)
nh = rt_get_raw_nhop(rt);
#ifdef ROUTE_MPATH
if (NH_IS_NHGRP(nh)) {
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
int error;
wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops);
diff --git a/sys/netinet/in_fib.c b/sys/netinet/in_fib.c
index 3e09be7dc6e2..6f0e95bcf117 100644
--- a/sys/netinet/in_fib.c
+++ b/sys/netinet/in_fib.c
@@ -196,7 +196,7 @@ check_urpf(struct nhop_object *nh, uint32_t flags,
{
#ifdef ROUTE_MPATH
if (NH_IS_NHGRP(nh)) {
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops);
for (int i = 0; i < num_nhops; i++) {
diff --git a/sys/netinet6/in6_fib.c b/sys/netinet6/in6_fib.c
index 614f8111409a..8a0760aff02a 100644
--- a/sys/netinet6/in6_fib.c
+++ b/sys/netinet6/in6_fib.c
@@ -205,7 +205,7 @@ check_urpf(struct nhop_object *nh, uint32_t flags,
{
#ifdef ROUTE_MPATH
if (NH_IS_NHGRP(nh)) {
- struct weightened_nhop *wn;
+ const struct weightened_nhop *wn;
uint32_t num_nhops;
wn = nhgrp_get_nhops((struct nhgrp_object *)nh, &num_nhops);
for (int i = 0; i < num_nhops; i++) {