Author: melifaro
Date: Sun Jul 12 11:18:09 2020
New Revision: 363127
URL: https://svnweb.freebsd.org/changeset/base/363127

Log:
  Add destructor for the rib subscription system to simplify users code.
  
  Subscriptions are planned to be used by modules such as route lookup engines.
  In that case that's the module task to properly unsibscribe before detach.
  However, the in-kernel customer - inet6 wants to track default route changes.
  To avoid having inet6 store per-fib subscriptions, handle automatic
   destruction internally.
  
  Differential Revision:        https://reviews.freebsd.org/D25614

Modified:
  head/sys/net/route.c
  head/sys/net/route/route_ctl.c
  head/sys/net/route/shared.h

Modified: head/sys/net/route.c
==============================================================================
--- head/sys/net/route.c        Sun Jul 12 10:07:01 2020        (r363126)
+++ head/sys/net/route.c        Sun Jul 12 11:18:09 2020        (r363127)
@@ -348,7 +348,7 @@ rt_table_init(int offset, int family, u_int fibnum)
        nhops_init_rib(rh);
 
        /* Init subscription system */
-       CK_STAILQ_INIT(&rh->rnh_subscribers);
+       rib_init_subscriptions(rh);
 
        /* Finally, set base callbacks */
        rh->rnh_addaddr = rn_addroute;
@@ -382,6 +382,8 @@ rt_table_destroy(struct rib_head *rh)
        rn_walktree(&rh->rmhead.head, rt_freeentry, &rh->rmhead.head);
 
        nhops_destroy_rib(rh);
+
+       rib_destroy_subscriptions(rh);
 
        /* Assume table is already empty */
        RIB_LOCK_DESTROY(rh);

Modified: head/sys/net/route/route_ctl.c
==============================================================================
--- head/sys/net/route/route_ctl.c      Sun Jul 12 10:07:01 2020        
(r363126)
+++ head/sys/net/route/route_ctl.c      Sun Jul 12 11:18:09 2020        
(r363127)
@@ -847,3 +847,28 @@ destroy_subscription_epoch(epoch_context_t ctx)
 
        free(rs, M_RTABLE);
 }
+
+void
+rib_init_subscriptions(struct rib_head *rnh)
+{
+
+       CK_STAILQ_INIT(&rnh->rnh_subscribers);
+}
+
+void
+rib_destroy_subscriptions(struct rib_head *rnh)
+{
+       struct rib_subscription *rs;
+       struct epoch_tracker et;
+
+       NET_EPOCH_ENTER(et);
+       RIB_WLOCK(rnh);
+       while ((rs = CK_STAILQ_FIRST(&rnh->rnh_subscribers)) != NULL) {
+               CK_STAILQ_REMOVE_HEAD(&rnh->rnh_subscribers, next);
+               epoch_call(net_epoch_preempt, destroy_subscription_epoch,
+                   &rs->epoch_ctx);
+       }
+       RIB_WUNLOCK(rnh);
+       NET_EPOCH_EXIT(et);
+}
+

Modified: head/sys/net/route/shared.h
==============================================================================
--- head/sys/net/route/shared.h Sun Jul 12 10:07:01 2020        (r363126)
+++ head/sys/net/route/shared.h Sun Jul 12 11:18:09 2020        (r363127)
@@ -67,6 +67,10 @@ int nhop_create_from_nhop(struct rib_head *rnh, const 
 void nhops_update_ifmtu(struct rib_head *rh, struct ifnet *ifp, uint32_t mtu);
 int nhops_dump_sysctl(struct rib_head *rh, struct sysctl_req *w);
 
+/* subscriptions */
+void rib_init_subscriptions(struct rib_head *rnh);
+void rib_destroy_subscriptions(struct rib_head *rnh);
+
 /* route */
 VNET_DECLARE(uma_zone_t, rtzone);              /* Routing table UMA zone. */
 #define        V_rtzone        VNET(rtzone)
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to