Author: melifaro
Date: Tue Apr 28 18:42:30 2020
New Revision: 360447
URL: https://svnweb.freebsd.org/changeset/base/360447

Log:
  Move struct rtentry definition to nhop_var.h.
  
  One of the goals of the new routing KPI defined in r359823
   is to entirely hide`struct rtentry` from the consumers.
  It will allow to improve routing subsystem internals and deliver
   features much faster.
  
  This is one of the last changes, effectively moving struct rtentry
   definition to a net/route_var.h header, internal to the routing subsystem.
  
  Differential Revision:        https://reviews.freebsd.org/D24580

Modified:
  head/sys/net/route.h
  head/sys/net/route_var.h
  head/sys/netinet6/nd6.c

Modified: head/sys/net/route.h
==============================================================================
--- head/sys/net/route.h        Tue Apr 28 17:59:37 2020        (r360446)
+++ head/sys/net/route.h        Tue Apr 28 18:42:30 2020        (r360447)
@@ -35,7 +35,6 @@
 #ifndef _NET_ROUTE_H_
 #define _NET_ROUTE_H_
 
-#include <sys/counter.h>
 #include <net/vnet.h>
 
 /*
@@ -129,42 +128,6 @@ VNET_DECLARE(u_int, rt_add_addr_allfibs); /* Announce 
  * gateways are marked so that the output routines know to address the
  * gateway rather than the ultimate destination.
  */
-#ifndef RNF_NORMAL
-#include <net/radix.h>
-#ifdef RADIX_MPATH
-#include <net/radix_mpath.h>
-#endif
-#endif
-
-#if defined(_KERNEL)
-struct rtentry {
-       struct  radix_node rt_nodes[2]; /* tree glue, and other values */
-       /*
-        * XXX struct rtentry must begin with a struct radix_node (or two!)
-        * because the code does some casts of a 'struct radix_node *'
-        * to a 'struct rtentry *'
-        */
-#define        rt_key(r)       (*((struct sockaddr 
**)(&(r)->rt_nodes->rn_key)))
-#define        rt_mask(r)      (*((struct sockaddr 
**)(&(r)->rt_nodes->rn_mask)))
-#define        rt_key_const(r)         (*((const struct sockaddr * const 
*)(&(r)->rt_nodes->rn_key)))
-#define        rt_mask_const(r)        (*((const struct sockaddr * const 
*)(&(r)->rt_nodes->rn_mask)))
-       struct  sockaddr *rt_gateway;   /* value */
-       struct  ifnet *rt_ifp;          /* the answer: interface to use */
-       struct  ifaddr *rt_ifa;         /* the answer: interface address to use 
*/
-       struct nhop_object      *rt_nhop;       /* nexthop data */
-       int             rt_flags;       /* up/down?, host/net */
-       int             rt_refcnt;      /* # held references */
-       u_int           rt_fibnum;      /* which FIB */
-       u_long          rt_mtu;         /* MTU for this path */
-       u_long          rt_weight;      /* absolute weight */ 
-       u_long          rt_expire;      /* lifetime for route, e.g. redirect */
-#define        rt_endzero      rt_pksent
-       counter_u64_t   rt_pksent;      /* packets sent using this route */
-       struct mtx      rt_mtx;         /* mutex for routing entry */
-       struct rtentry  *rt_chain;      /* pointer to next rtentry to delete */
-};
-#endif /* _KERNEL */
-
 #define        RTF_UP          0x1             /* route usable */
 #define        RTF_GATEWAY     0x2             /* destination is a gateway */
 #define        RTF_HOST        0x4             /* host entry (net otherwise) */
@@ -369,53 +332,7 @@ struct rt_addrinfo {
 #define RT_LINK_IS_UP(ifp)     (!((ifp)->if_capabilities & IFCAP_LINKSTATE) \
                                 || (ifp)->if_link_state == LINK_STATE_UP)
 
-#define        RT_LOCK_INIT(_rt) \
-       mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK | MTX_NEW)
-#define        RT_LOCK(_rt)            mtx_lock(&(_rt)->rt_mtx)
-#define        RT_UNLOCK(_rt)          mtx_unlock(&(_rt)->rt_mtx)
-#define        RT_LOCK_DESTROY(_rt)    mtx_destroy(&(_rt)->rt_mtx)
-#define        RT_LOCK_ASSERT(_rt)     mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
-#define        RT_UNLOCK_COND(_rt)     do {                            \
-       if (mtx_owned(&(_rt)->rt_mtx))                          \
-               mtx_unlock(&(_rt)->rt_mtx);                     \
-} while (0)
-
-#define        RT_ADDREF(_rt)  do {                                    \
-       RT_LOCK_ASSERT(_rt);                                    \
-       KASSERT((_rt)->rt_refcnt >= 0,                          \
-               ("negative refcnt %d", (_rt)->rt_refcnt));      \
-       (_rt)->rt_refcnt++;                                     \
-} while (0)
-
-#define        RT_REMREF(_rt)  do {                                    \
-       RT_LOCK_ASSERT(_rt);                                    \
-       KASSERT((_rt)->rt_refcnt > 0,                           \
-               ("bogus refcnt %d", (_rt)->rt_refcnt)); \
-       (_rt)->rt_refcnt--;                                     \
-} while (0)
-
-#define        RTFREE_LOCKED(_rt) do {                                 \
-       if ((_rt)->rt_refcnt <= 1)                              \
-               rtfree(_rt);                                    \
-       else {                                                  \
-               RT_REMREF(_rt);                                 \
-               RT_UNLOCK(_rt);                                 \
-       }                                                       \
-       /* guard against invalid refs */                        \
-       _rt = 0;                                                \
-} while (0)
-
-#define        RTFREE(_rt) do {                                        \
-       RT_LOCK(_rt);                                           \
-       RTFREE_LOCKED(_rt);                                     \
-} while (0)
-
 #define        RTFREE_FUNC(_rt)        rtfree_func(_rt)
-
-#define        RO_RTFREE(_ro) do {                                     \
-       if ((_ro)->ro_rt)                                       \
-               RTFREE((_ro)->ro_rt);                           \
-} while (0)
 
 #define        RO_NHFREE(_ro) do {                                     \
        if ((_ro)->ro_nh) {                                     \

Modified: head/sys/net/route_var.h
==============================================================================
--- head/sys/net/route_var.h    Tue Apr 28 17:59:37 2020        (r360446)
+++ head/sys/net/route_var.h    Tue Apr 28 18:42:30 2020        (r360447)
@@ -32,6 +32,11 @@
 #ifndef _NET_ROUTE_VAR_H_
 #define _NET_ROUTE_VAR_H_
 
+#ifndef RNF_NORMAL
+#include <net/radix.h>
+#endif
+#include <sys/counter.h>
+
 struct nh_control;
 typedef int rnh_preadd_entry_f_t(u_int fibnum, const struct sockaddr *addr,
        const struct sockaddr *mask, struct nhop_object *nh);
@@ -100,6 +105,74 @@ VNET_PCPUSTAT_DECLARE(struct rtstat, rtstat);
 #define        RTSTAT_ADD(name, val)   \
        VNET_PCPUSTAT_ADD(struct rtstat, rtstat, name, (val))
 #define        RTSTAT_INC(name)        RTSTAT_ADD(name, 1)
+
+struct rtentry {
+       struct  radix_node rt_nodes[2]; /* tree glue, and other values */
+       /*
+        * XXX struct rtentry must begin with a struct radix_node (or two!)
+        * because the code does some casts of a 'struct radix_node *'
+        * to a 'struct rtentry *'
+        */
+#define        rt_key(r)       (*((struct sockaddr 
**)(&(r)->rt_nodes->rn_key)))
+#define        rt_mask(r)      (*((struct sockaddr 
**)(&(r)->rt_nodes->rn_mask)))
+#define        rt_key_const(r)         (*((const struct sockaddr * const 
*)(&(r)->rt_nodes->rn_key)))
+#define        rt_mask_const(r)        (*((const struct sockaddr * const 
*)(&(r)->rt_nodes->rn_mask)))
+       struct  sockaddr *rt_gateway;   /* value */
+       struct  ifnet *rt_ifp;          /* the answer: interface to use */
+       struct  ifaddr *rt_ifa;         /* the answer: interface address to use 
*/
+       struct nhop_object      *rt_nhop;       /* nexthop data */
+       int             rt_flags;       /* up/down?, host/net */
+       int             rt_refcnt;      /* # held references */
+       u_int           rt_fibnum;      /* which FIB */
+       u_long          rt_mtu;         /* MTU for this path */
+       u_long          rt_weight;      /* absolute weight */ 
+       u_long          rt_expire;      /* lifetime for route, e.g. redirect */
+#define        rt_endzero      rt_pksent
+       counter_u64_t   rt_pksent;      /* packets sent using this route */
+       struct mtx      rt_mtx;         /* mutex for routing entry */
+       struct rtentry  *rt_chain;      /* pointer to next rtentry to delete */
+};
+
+#define        RT_LOCK_INIT(_rt) \
+       mtx_init(&(_rt)->rt_mtx, "rtentry", NULL, MTX_DEF | MTX_DUPOK | MTX_NEW)
+#define        RT_LOCK(_rt)            mtx_lock(&(_rt)->rt_mtx)
+#define        RT_UNLOCK(_rt)          mtx_unlock(&(_rt)->rt_mtx)
+#define        RT_LOCK_DESTROY(_rt)    mtx_destroy(&(_rt)->rt_mtx)
+#define        RT_LOCK_ASSERT(_rt)     mtx_assert(&(_rt)->rt_mtx, MA_OWNED)
+#define        RT_UNLOCK_COND(_rt)     do {                            \
+       if (mtx_owned(&(_rt)->rt_mtx))                          \
+               mtx_unlock(&(_rt)->rt_mtx);                     \
+} while (0)
+
+#define        RT_ADDREF(_rt)  do {                                    \
+       RT_LOCK_ASSERT(_rt);                                    \
+       KASSERT((_rt)->rt_refcnt >= 0,                          \
+               ("negative refcnt %d", (_rt)->rt_refcnt));      \
+       (_rt)->rt_refcnt++;                                     \
+} while (0)
+
+#define        RT_REMREF(_rt)  do {                                    \
+       RT_LOCK_ASSERT(_rt);                                    \
+       KASSERT((_rt)->rt_refcnt > 0,                           \
+               ("bogus refcnt %d", (_rt)->rt_refcnt)); \
+       (_rt)->rt_refcnt--;                                     \
+} while (0)
+
+#define        RTFREE_LOCKED(_rt) do {                                 \
+       if ((_rt)->rt_refcnt <= 1)                              \
+               rtfree(_rt);                                    \
+       else {                                                  \
+               RT_REMREF(_rt);                                 \
+               RT_UNLOCK(_rt);                                 \
+       }                                                       \
+       /* guard against invalid refs */                        \
+       _rt = 0;                                                \
+} while (0)
+
+#define        RTFREE(_rt) do {                                        \
+       RT_LOCK(_rt);                                           \
+       RTFREE_LOCKED(_rt);                                     \
+} while (0)
 
 /*
  * With the split between the routing entry and the nexthop,

Modified: head/sys/netinet6/nd6.c
==============================================================================
--- head/sys/netinet6/nd6.c     Tue Apr 28 17:59:37 2020        (r360446)
+++ head/sys/netinet6/nd6.c     Tue Apr 28 18:42:30 2020        (r360447)
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_dl.h>
 #include <net/if_types.h>
 #include <net/route.h>
+#include <net/route_var.h>
 #include <net/route/nhop.h>
 #include <net/vnet.h>
 
_______________________________________________
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