svn commit: r368149 - head/sys/net/route

Alexander V. Chernikov melifaro at FreeBSD.org
Sun Nov 29 13:52:07 UTC 2020


Author: melifaro
Date: Sun Nov 29 13:52:06 2020
New Revision: 368149
URL: https://svnweb.freebsd.org/changeset/base/368149

Log:
  Add nhop_ref_any() to unify referencing nhop or nexthop group.
  
  It allows code within routing subsystem to transparently reference nexthops
   and nexthop groups, similar to nhop_free_any(), abstracting ROUTE_MPATH
   details.
  
  Differential Revision:	https://reviews.freebsd.org/D27410

Modified:
  head/sys/net/route/nhgrp_ctl.c
  head/sys/net/route/nhop_ctl.c
  head/sys/net/route/route_var.h

Modified: head/sys/net/route/nhgrp_ctl.c
==============================================================================
--- head/sys/net/route/nhgrp_ctl.c	Sun Nov 29 13:45:53 2020	(r368148)
+++ head/sys/net/route/nhgrp_ctl.c	Sun Nov 29 13:52:06 2020	(r368149)
@@ -294,6 +294,17 @@ alloc_nhgrp(struct weightened_nhop *wn, int num_nhops)
 }
 
 void
+nhgrp_ref_object(struct nhgrp_object *nhg)
+{
+	struct nhgrp_priv *nhg_priv;
+	u_int old;
+
+	nhg_priv = NHGRP_PRIV(nhg);
+	old = refcount_acquire(&nhg_priv->nhg_refcount);
+	KASSERT(old > 0, ("%s: nhgrp object %p has 0 refs", __func__, nhg));
+}
+
+void
 nhgrp_free(struct nhgrp_object *nhg)
 {
 	struct nhgrp_priv *nhg_priv;

Modified: head/sys/net/route/nhop_ctl.c
==============================================================================
--- head/sys/net/route/nhop_ctl.c	Sun Nov 29 13:45:53 2020	(r368148)
+++ head/sys/net/route/nhop_ctl.c	Sun Nov 29 13:52:06 2020	(r368149)
@@ -691,6 +691,19 @@ nhop_free(struct nhop_object *nh)
 }
 
 void
+nhop_ref_any(struct nhop_object *nh)
+{
+#ifdef ROUTE_MPATH
+	if (!NH_IS_NHGRP(nh))
+		nhop_ref_object(nh);
+	else
+		nhgrp_ref_object((struct nhgrp_object *)nh);
+#else
+	nhop_ref_object(nh);
+#endif
+}
+
+void
 nhop_free_any(struct nhop_object *nh)
 {
 

Modified: head/sys/net/route/route_var.h
==============================================================================
--- head/sys/net/route/route_var.h	Sun Nov 29 13:45:53 2020	(r368148)
+++ head/sys/net/route/route_var.h	Sun Nov 29 13:52:06 2020	(r368149)
@@ -242,6 +242,7 @@ int nhops_init_rib(struct rib_head *rh);
 void nhops_destroy_rib(struct rib_head *rh);
 void nhop_ref_object(struct nhop_object *nh);
 int nhop_try_ref_object(struct nhop_object *nh);
+void nhop_ref_any(struct nhop_object *nh);
 void nhop_free_any(struct nhop_object *nh);
 
 void nhop_set_type(struct nhop_object *nh, enum nhop_type nh_type);
@@ -306,6 +307,7 @@ int nhgrp_get_addition_group(struct rib_head *rnh,
     struct route_nhop_data *rnd_orig, struct route_nhop_data *rnd_add,
     struct route_nhop_data *rnd_new);
 
+void nhgrp_ref_object(struct nhgrp_object *nhg);
 uint32_t nhgrp_get_idx(const struct nhgrp_object *nhg);
 void nhgrp_free(struct nhgrp_object *nhg);
 


More information about the svn-src-all mailing list