Author: melifaro
Date: Mon Jun 22 07:35:23 2020
New Revision: 362487
URL: https://svnweb.freebsd.org/changeset/base/362487

Log:
  Switch cxgbe interface lookup to use fibX_lookup() from older
   fibX_lookup_nh_ext().
  
  fibX_lookup_nh_ represents pre-epoch generation of fib kpi,
  providing less guarantees over pointer validness and requiring
  on-stack data copying.
  
  Reviewed by:  np
  Differential Revision:        https://reviews.freebsd.org/D24975

Modified:
  head/sys/dev/cxgbe/iw_cxgbe/cm.c
  head/sys/dev/cxgbe/tom/t4_listen.c

Modified: head/sys/dev/cxgbe/iw_cxgbe/cm.c
==============================================================================
--- head/sys/dev/cxgbe/iw_cxgbe/cm.c    Mon Jun 22 07:00:26 2020        
(r362486)
+++ head/sys/dev/cxgbe/iw_cxgbe/cm.c    Mon Jun 22 07:35:23 2020        
(r362487)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/taskqueue.h>
 #include <netinet/in.h>
 #include <net/route.h>
+#include <net/route/nhop.h>
 
 #include <netinet/in_systm.h>
 #include <netinet/in_pcb.h>
@@ -537,32 +538,29 @@ static int
 get_ifnet_from_raddr(struct sockaddr_storage *raddr, struct ifnet **ifp)
 {
        int err = 0;
+       struct nhop_object *nh;
 
        if (raddr->ss_family == AF_INET) {
                struct sockaddr_in *raddr4 = (struct sockaddr_in *)raddr;
-               struct nhop4_extended nh4 = {0};
 
-               err = fib4_lookup_nh_ext(RT_DEFAULT_FIB, raddr4->sin_addr,
-                               NHR_REF, 0, &nh4);
-               *ifp = nh4.nh_ifp;
-               if (err)
-                       fib4_free_nh_ext(RT_DEFAULT_FIB, &nh4);
+               nh = fib4_lookup(RT_DEFAULT_FIB, raddr4->sin_addr, 0,
+                               NHR_NONE, 0);
        } else {
                struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)raddr;
-               struct nhop6_extended nh6 = {0};
                struct in6_addr addr6;
                uint32_t scopeid;
 
                memset(&addr6, 0, sizeof(addr6));
                in6_splitscope((struct in6_addr *)&raddr6->sin6_addr,
                                        &addr6, &scopeid);
-               err = fib6_lookup_nh_ext(RT_DEFAULT_FIB, &addr6, scopeid,
-                               NHR_REF, 0, &nh6);
-               *ifp = nh6.nh_ifp;
-               if (err)
-                       fib6_free_nh_ext(RT_DEFAULT_FIB, &nh6);
+               nh = fib6_lookup(RT_DEFAULT_FIB, &addr6, scopeid,
+                               NHR_NONE, 0);
        }
 
+       if (nh == NULL)
+               err = EHOSTUNREACH;
+       else
+               *ifp = nh->nh_ifp;
        CTR2(KTR_IW_CXGBE, "%s: return: %d", __func__, err);
        return err;
 }
@@ -2589,6 +2587,7 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_
        struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
        struct c4iw_ep *ep = NULL;
        struct ifnet    *nh_ifp;        /* Logical egress interface */
+       struct epoch_tracker et;
 #ifdef VIMAGE
        struct rdma_cm_id *rdma_id = (struct rdma_cm_id*)cm_id->context;
        struct vnet *vnet = rdma_id->route.addr.dev_addr.net;
@@ -2639,9 +2638,11 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_
        ref_qp(ep);
        ep->com.thread = curthread;
 
+       NET_EPOCH_ENTER(et);
        CURVNET_SET(vnet);
        err = get_ifnet_from_raddr(&cm_id->remote_addr, &nh_ifp);
        CURVNET_RESTORE();
+       NET_EPOCH_EXIT(et);
 
        if (err) {
 

Modified: head/sys/dev/cxgbe/tom/t4_listen.c
==============================================================================
--- head/sys/dev/cxgbe/tom/t4_listen.c  Mon Jun 22 07:00:26 2020        
(r362486)
+++ head/sys/dev/cxgbe/tom/t4_listen.c  Mon Jun 22 07:35:23 2020        
(r362487)
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_types.h>
 #include <net/if_vlan_var.h>
 #include <net/route.h>
+#include <net/route/nhop.h>
 #include <netinet/in.h>
 #include <netinet/in_fib.h>
 #include <netinet/in_pcb.h>
@@ -1052,10 +1053,9 @@ get_l2te_for_nexthop(struct port_info *pi, struct ifne
        struct l2t_entry *e;
        struct sockaddr_in6 sin6;
        struct sockaddr *dst = (void *)&sin6;
+       struct nhop_object *nh;
 
        if (inc->inc_flags & INC_ISIPV6) {
-               struct nhop6_basic nh6;
-
                bzero(dst, sizeof(struct sockaddr_in6));
                dst->sa_len = sizeof(struct sockaddr_in6);
                dst->sa_family = AF_INET6;
@@ -1066,24 +1066,28 @@ get_l2te_for_nexthop(struct port_info *pi, struct ifne
                        return (e);
                }
 
-               if (fib6_lookup_nh_basic(RT_DEFAULT_FIB, &inc->inc6_faddr,
-                   0, 0, 0, &nh6) != 0)
+               nh = fib6_lookup(RT_DEFAULT_FIB, &inc->inc6_faddr, 0, NHR_NONE, 
0);
+               if (nh == NULL)
                        return (NULL);
-               if (nh6.nh_ifp != ifp)
+               if (nh->nh_ifp != ifp)
                        return (NULL);
-               ((struct sockaddr_in6 *)dst)->sin6_addr = nh6.nh_addr;
+               if (nh->nh_flags & NHF_GATEWAY)
+                       ((struct sockaddr_in6 *)dst)->sin6_addr = 
nh->gw6_sa.sin6_addr;
+               else
+                       ((struct sockaddr_in6 *)dst)->sin6_addr = 
inc->inc6_faddr;
        } else {
-               struct nhop4_basic nh4;
-
                dst->sa_len = sizeof(struct sockaddr_in);
                dst->sa_family = AF_INET;
 
-               if (fib4_lookup_nh_basic(RT_DEFAULT_FIB, inc->inc_faddr, 0, 0,
-                   &nh4) != 0)
+               nh = fib4_lookup(RT_DEFAULT_FIB, inc->inc_faddr, 0, NHR_NONE, 
0);
+               if (nh == NULL)
                        return (NULL);
-               if (nh4.nh_ifp != ifp)
+               if (nh->nh_ifp != ifp)
                        return (NULL);
-               ((struct sockaddr_in *)dst)->sin_addr = nh4.nh_addr;
+               if (nh->nh_flags & NHF_GATEWAY)
+                       ((struct sockaddr_in *)dst)->sin_addr = 
nh->gw4_sa.sin_addr;
+               else
+                       ((struct sockaddr_in *)dst)->sin_addr = inc->inc_faddr;
        }
 
        e = t4_l2t_get(pi, ifp, dst);
_______________________________________________
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