Author: melifaro
Date: Sun Jul 12 11:24:23 2020
New Revision: 363128
URL: https://svnweb.freebsd.org/changeset/base/363128

Log:
  Switch inet6 default route subscription to the new rib subscription api.
  
  Old subscription model allowed only single customer.
  
  Switch inet6 to the new subscription api and eliminate the old model.
  
  Differential Revision:        https://reviews.freebsd.org/D25615

Modified:
  head/sys/net/if_var.h
  head/sys/net/route/route_ctl.c
  head/sys/netinet6/in6_rmx.c
  head/sys/netinet6/nd6.c
  head/sys/netinet6/nd6.h
  head/sys/netinet6/nd6_rtr.c

Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h       Sun Jul 12 11:18:09 2020        (r363127)
+++ head/sys/net/if_var.h       Sun Jul 12 11:24:23 2020        (r363128)
@@ -61,8 +61,6 @@
  */
 
 struct rtentry;                /* ifa_rtrequest */
-struct nhop_object;            /* ifa_rtrequest */
-struct rt_addrinfo;            /* ifa_rtrequest */
 struct socket;
 struct carp_if;
 struct carp_softc;
@@ -551,9 +549,6 @@ struct ifaddr {
        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
        struct  carp_softc *ifa_carp;   /* pointer to CARP data */
        CK_STAILQ_ENTRY(ifaddr) ifa_link;       /* queue macro glue */
-       void    (*ifa_rtrequest)        /* check or clean routes (+ or -)'d */
-               (int, struct rtentry *, struct nhop_object *,
-                struct rt_addrinfo *);
        u_short ifa_flags;              /* mostly rt_flags for cloning */
 #define        IFA_ROUTE       RTF_UP          /* route installed */
 #define        IFA_RTSELF      RTF_HOST        /* loopback route to self 
installed */

Modified: head/sys/net/route/route_ctl.c
==============================================================================
--- head/sys/net/route/route_ctl.c      Sun Jul 12 11:18:09 2020        
(r363127)
+++ head/sys/net/route/route_ctl.c      Sun Jul 12 11:24:23 2020        
(r363128)
@@ -79,7 +79,6 @@ struct rib_subscription {
 static void rib_notify(struct rib_head *rnh, enum rib_subscription_type type,
     struct rib_cmd_info *rc);
 
-static void rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info);
 static void destroy_subscription_epoch(epoch_context_t ctx);
 
 static struct rib_head *
@@ -275,10 +274,8 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
        if ((rn != NULL) || (rt_old != NULL))
                rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
 
-       if (rt_old != NULL) {
-               rt_notifydelete(rt_old, info);
+       if (rt_old != NULL)
                rtfree(rt_old);
-       }
 
        /*
         * If it still failed to go into the tree,
@@ -290,13 +287,6 @@ add_route(struct rib_head *rnh, struct rt_addrinfo *in
                return (EEXIST);
        }
 
-       /*
-        * If this protocol has something to add to this then
-        * allow it to do that as well.
-        */
-       if (ifa->ifa_rtrequest)
-               ifa->ifa_rtrequest(RTM_ADD, rt, rt->rt_nhop, info);
-
        RT_UNLOCK(rt);
 
        return (0);
@@ -432,7 +422,6 @@ del_route(struct rib_head *rnh, struct rt_addrinfo *in
                return (error);
 
        rib_notify(rnh, RIB_NOTIFY_DELAYED, rc);
-       rt_notifydelete(rt, info);
 
        /*
         * If the caller wants it, then it can have it,
@@ -554,15 +543,9 @@ change_route_one(struct rib_head *rnh, struct rt_addri
        RT_LOCK(rt);
 
        /* Provide notification to the protocols.*/
-       if ((nh_orig->nh_ifa != nh->nh_ifa) && nh_orig->nh_ifa->ifa_rtrequest)
-               nh_orig->nh_ifa->ifa_rtrequest(RTM_DELETE, rt, nh_orig, info);
-
        rt->rt_nhop = nh;
        rt_setmetrics(info, rt);
 
-       if ((nh_orig->nh_ifa != nh->nh_ifa) && nh_orig->nh_ifa->ifa_rtrequest)
-               nh_orig->nh_ifa->ifa_rtrequest(RTM_DELETE, rt, nh_orig, info);
-
        /* Finalize notification */
        rc->rc_rt = rt;
        rc->rc_nh_old = nh_orig;
@@ -641,19 +624,6 @@ rib_action(uint32_t fibnum, int action, struct rt_addr
 }
 
 
-static void
-rt_notifydelete(struct rtentry *rt, struct rt_addrinfo *info)
-{
-       struct ifaddr *ifa;
-
-       /*
-        * give the protocol a chance to keep things in sync.
-        */
-       ifa = rt->rt_nhop->nh_ifa;
-       if (ifa != NULL && ifa->ifa_rtrequest != NULL)
-               ifa->ifa_rtrequest(RTM_DELETE, rt, rt->rt_nhop, info);
-}
-
 struct rt_delinfo
 {
        struct rt_addrinfo info;
@@ -748,8 +718,6 @@ rib_walk_del(u_int fibnum, int family, rt_filter_f_t *
                /* TODO std rt -> rt_addrinfo export */
                di.info.rti_info[RTAX_DST] = rt_key(rt);
                di.info.rti_info[RTAX_NETMASK] = rt_mask(rt);
-
-               rt_notifydelete(rt, &di.info);
 
                if (report)
                        rt_routemsg(RTM_DELETE, rt, rt->rt_nhop->nh_ifp, 0,

Modified: head/sys/netinet6/in6_rmx.c
==============================================================================
--- head/sys/netinet6/in6_rmx.c Sun Jul 12 11:18:09 2020        (r363127)
+++ head/sys/netinet6/in6_rmx.c Sun Jul 12 11:24:23 2020        (r363128)
@@ -150,6 +150,7 @@ rib6_preadd(u_int fibnum, const struct sockaddr *addr,
 int
 in6_inithead(void **head, int off, u_int fibnum)
 {
+       struct epoch_tracker et;
        struct rib_head *rh;
 
        rh = rt_table_init(offsetof(struct sockaddr_in6, sin6_addr) << 3,
@@ -162,6 +163,13 @@ in6_inithead(void **head, int off, u_int fibnum)
        rt_mpath_init_rnh(rh);
 #endif
        *head = (void *)rh;
+
+       NET_EPOCH_ENTER(et);
+       if (rib_subscribe(fibnum, AF_INET6, nd6_subscription_cb, NULL,
+           RIB_NOTIFY_IMMEDIATE, M_NOWAIT) == NULL)
+               log(LOG_ERR, "in6_inithead(): unable to subscribe to fib %u\n",
+                   fibnum);
+       NET_EPOCH_EXIT(et);
 
        return (1);
 }

Modified: head/sys/netinet6/nd6.c
==============================================================================
--- head/sys/netinet6/nd6.c     Sun Jul 12 11:18:09 2020        (r363127)
+++ head/sys/netinet6/nd6.c     Sun Jul 12 11:24:23 2020        (r363128)
@@ -62,7 +62,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_dl.h>
 #include <net/if_types.h>
 #include <net/route.h>
-#include <net/route/route_var.h>
+#include <net/route/route_ctl.h>
 #include <net/route/nhop.h>
 #include <net/vnet.h>
 
@@ -138,8 +138,6 @@ static void nd6_free_redirect(const struct llentry *);
 static void nd6_llinfo_timer(void *);
 static void nd6_llinfo_settimer_locked(struct llentry *, long);
 static void clear_llinfo_pqueue(struct llentry *);
-static void nd6_rtrequest(int, struct rtentry *, struct nhop_object *,
-    struct rt_addrinfo *);
 static int nd6_resolve_slow(struct ifnet *, int, struct mbuf *,
     const struct sockaddr_in6 *, u_char *, uint32_t *, struct llentry **);
 static int nd6_need_cache(struct ifnet *);
@@ -1580,39 +1578,24 @@ nd6_free_redirect(const struct llentry *ln)
 }
 
 /*
- * Rejuvenate this function for routing operations related
- * processing.
+ * Updates status of the default router route.
  */
 void
-nd6_rtrequest(int req, struct rtentry *rt, struct nhop_object *nh,
-    struct rt_addrinfo *info)
+nd6_subscription_cb(struct rib_head *rnh, struct rib_cmd_info *rc, void *arg)
 {
-       struct sockaddr_in6 *gateway;
        struct nd_defrouter *dr;
+       struct nhop_object *nh;
 
-       gateway = &nh->gw6_sa;
+       if (rc->rc_cmd == RTM_DELETE) {
+               nh = rc->rc_nh_old;
 
-       switch (req) {
-       case RTM_ADD:
-               break;
-
-       case RTM_DELETE:
-               /*
-                * Only indirect routes are interesting.
-                */
-               if ((nh->nh_flags & NHF_GATEWAY) == 0)
-                       return;
-               /*
-                * check for default route
-                */
                if (nh->nh_flags & NHF_DEFAULT) {
-                       dr = defrouter_lookup(&gateway->sin6_addr, nh->nh_ifp);
+                       dr = defrouter_lookup(&nh->gw6_sa.sin6_addr, 
nh->nh_ifp);
                        if (dr != NULL) {
                                dr->installed = 0;
                                defrouter_rele(dr);
                        }
                }
-               break;
        }
 }
 
@@ -2532,7 +2515,6 @@ nd6_add_ifa_lle(struct in6_ifaddr *ia)
        if (nd6_need_cache(ifp) == 0)
                return (0);
 
-       ia->ia_ifa.ifa_rtrequest = nd6_rtrequest;
        dst = (struct sockaddr *)&ia->ia_addr;
        ln = lltable_alloc_entry(LLTABLE6(ifp), LLE_IFADDR, dst);
        if (ln == NULL)

Modified: head/sys/netinet6/nd6.h
==============================================================================
--- head/sys/netinet6/nd6.h     Sun Jul 12 11:18:09 2020        (r363127)
+++ head/sys/netinet6/nd6.h     Sun Jul 12 11:24:23 2020        (r363128)
@@ -385,6 +385,11 @@ void nd6_rem_ifa_lle(struct in6_ifaddr *, int);
 int nd6_output_ifp(struct ifnet *, struct ifnet *, struct mbuf *,
     struct sockaddr_in6 *, struct route *);
 
+struct rib_head;
+struct rib_cmd_info;
+void nd6_subscription_cb(struct rib_head *rnh, struct rib_cmd_info *rc,
+    void *arg);
+
 /* nd6_nbr.c */
 void nd6_na_input(struct mbuf *, int, int);
 void nd6_na_output(struct ifnet *, const struct in6_addr *,

Modified: head/sys/netinet6/nd6_rtr.c
==============================================================================
--- head/sys/netinet6/nd6_rtr.c Sun Jul 12 11:18:09 2020        (r363127)
+++ head/sys/netinet6/nd6_rtr.c Sun Jul 12 11:24:23 2020        (r363128)
@@ -2014,10 +2014,6 @@ nd6_prefix_onlink_rtrequest(struct nd_prefix *pr, stru
        u_long rtflags;
        int error, a_failure, fibnum, maxfib;
 
-       /*
-        * in6_ifinit() sets nd6_rtrequest to ifa_rtrequest for all ifaddrs.
-        * ifa->ifa_rtrequest = nd6_rtrequest;
-        */
        bzero(&mask6, sizeof(mask6));
        mask6.sin6_len = sizeof(mask6);
        mask6.sin6_addr = pr->ndpr_mask;
_______________________________________________
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