Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Aug 2015 18:16:42 +0000 (UTC)
From:      "Alexander V. Chernikov" <melifaro@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r287049 - in projects/routing/sys: net netinet
Message-ID:  <201508231816.t7NIGgCQ042378@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: melifaro
Date: Sun Aug 23 18:16:41 2015
New Revision: 287049
URL: https://svnweb.freebsd.org/changeset/base/287049

Log:
  Add new fib4_lookup_nh_extended() which fills in
   nhop4_extended  structure without doinf L2 resolve. It also requires freeing
    references by calling fib4_free_nh_ext().

Modified:
  projects/routing/sys/net/rt_nhops.c
  projects/routing/sys/net/rt_nhops.h
  projects/routing/sys/netinet/in_pcb.c
  projects/routing/sys/netinet/tcp_subr.c

Modified: projects/routing/sys/net/rt_nhops.c
==============================================================================
--- projects/routing/sys/net/rt_nhops.c	Sun Aug 23 18:15:58 2015	(r287048)
+++ projects/routing/sys/net/rt_nhops.c	Sun Aug 23 18:16:41 2015	(r287049)
@@ -380,7 +380,7 @@ fib4_rte_to_nh_extended(struct rtentry *
 	struct sockaddr_in *gw;
 	struct in_ifaddr *ia;
 
-	pnh4->nh_ifp = rte->rt_ifa->ifa_ifp;
+	pnh4->nh_ifp = rte->rt_ifp;
 	pnh4->nh_mtu = min(rte->rt_mtu, rte->rt_ifp->if_mtu);
 	if (rte->rt_flags & RTF_GATEWAY) {
 		gw = (struct sockaddr_in *)rte->rt_gateway;
@@ -435,6 +435,7 @@ fib4_lookup_nh_basic(uint32_t fibnum, st
 
 	/* Prepare lookup key */
 	memset(&sin, 0, sizeof(sin));
+	sin.sin_len = sizeof(struct sockaddr_in);
 	sin.sin_addr = dst;
 
 	RADIX_NODE_HEAD_RLOCK(rnh);
@@ -453,6 +454,49 @@ fib4_lookup_nh_basic(uint32_t fibnum, st
 
 	return (ENOENT);
 }
+
+int
+fib4_lookup_nh_extended(uint32_t fibnum, struct in_addr dst, uint32_t flowid,
+    struct nhop4_extended *pnh4)
+{
+	struct radix_node_head *rnh;
+	struct radix_node *rn;
+	struct sockaddr_in sin;
+	struct rtentry *rte;
+
+	KASSERT((fibnum < rt_numfibs), ("fib4_lookup_nh_basic: bad fibnum"));
+	rnh = rt_tables_get_rnh(fibnum, AF_INET);
+	if (rnh == NULL)
+		return (ENOENT);
+
+	/* Prepare lookup key */
+	memset(&sin, 0, sizeof(sin));
+	sin.sin_len = sizeof(struct sockaddr_in);
+	sin.sin_addr = dst;
+
+	RADIX_NODE_HEAD_RLOCK(rnh);
+	rn = rnh->rnh_matchaddr((void *)&sin, rnh);
+	if (rn != NULL && ((rn->rn_flags & RNF_ROOT) == 0)) {
+		rte = RNTORT(rn);
+		/* Ensure route & ifp is UP */
+		if (RT_LINK_IS_UP(rte->rt_ifp)) {
+			fib4_rte_to_nh_extended(rte, dst, pnh4);
+			RADIX_NODE_HEAD_RUNLOCK(rnh);
+
+			return (0);
+		}
+	}
+	RADIX_NODE_HEAD_RUNLOCK(rnh);
+
+	return (ENOENT);
+}
+
+void
+fib4_free_nh_ext(uint32_t fibnum, struct nhop4_extended *pnh4)
+{
+
+}
+
 #endif
 
 #ifdef INET6

Modified: projects/routing/sys/net/rt_nhops.h
==============================================================================
--- projects/routing/sys/net/rt_nhops.h	Sun Aug 23 18:15:58 2015	(r287048)
+++ projects/routing/sys/net/rt_nhops.h	Sun Aug 23 18:16:41 2015	(r287049)
@@ -192,6 +192,10 @@ int fib4_lookup_nh_basic(uint32_t fibnum
 int fib6_lookup_nh_basic(uint32_t fibnum, struct in6_addr dst, uint32_t flowid,
     struct nhop6_basic *pnh6);
 
+int fib4_lookup_nh_extended(uint32_t fibnum, struct in_addr dst,
+    uint32_t flowid, struct nhop4_extended *pnh4);
+void fib4_free_nh_ext(uint32_t fibnum, struct nhop4_extended *pnh4);
+
 void fib4_free_nh(uint32_t fibnum, struct nhop_data *nh);
 void fib4_choose_prepend(uint32_t fibnum, struct nhop_data *nh_src,
     uint32_t flowid, struct nhop_data *nh, struct nhop4_extended *nh_ext);

Modified: projects/routing/sys/netinet/in_pcb.c
==============================================================================
--- projects/routing/sys/netinet/in_pcb.c	Sun Aug 23 18:15:58 2015	(r287048)
+++ projects/routing/sys/netinet/in_pcb.c	Sun Aug 23 18:16:41 2015	(r287049)
@@ -758,8 +758,7 @@ in_pcbladdr(struct inpcb *inp, struct in
 	struct ifaddr *ifa;
 	struct sockaddr *sa;
 	struct sockaddr_in *sin, sin_storage;
-	struct nhop_data nhd, *pnhd;
-	struct nhop4_extended nh_ext;
+	struct nhop4_extended nh_ext, *pnh4;
 	u_int fibnum;
 	int error;
 
@@ -786,14 +785,12 @@ in_pcbladdr(struct inpcb *inp, struct in
 	 * Find out route to destination.
 	 */
 	fibnum = inp->inp_inc.inc_fibnum;
-	pnhd = &nhd;
-	memset(&nhd, 0, sizeof(nhd));
+	pnh4 = &nh_ext;
 	memset(&nh_ext, 0, sizeof(nh_ext));
 	if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0)
-		error = fib4_lookup_prepend(fibnum, *faddr,
-		    NULL, &nhd, &nh_ext);
+		error = fib4_lookup_nh_extended(fibnum, *faddr, 0, &nh_ext);
 	if (error != 0) {
-		pnhd = NULL;
+		pnh4 = NULL;
 		error = 0;
 	}
 
@@ -805,7 +802,7 @@ in_pcbladdr(struct inpcb *inp, struct in
 	 * network and try to find a corresponding interface to take
 	 * the source address from.
 	 */
-	if (pnhd == NULL) {
+	if (pnh4 == NULL) {
 		struct in_ifaddr *ia;
 		struct ifnet *ifp;
 
@@ -979,8 +976,8 @@ in_pcbladdr(struct inpcb *inp, struct in
 	}
 
 done:
-	if (pnhd != NULL)
-		fib4_free_nh(fibnum, pnhd);
+	if (pnh4 != NULL)
+		fib4_free_nh_ext(fibnum, pnh4);
 	return (error);
 }
 

Modified: projects/routing/sys/netinet/tcp_subr.c
==============================================================================
--- projects/routing/sys/netinet/tcp_subr.c	Sun Aug 23 18:15:58 2015	(r287048)
+++ projects/routing/sys/netinet/tcp_subr.c	Sun Aug 23 18:16:41 2015	(r287049)
@@ -83,6 +83,8 @@ __FBSDID("$FreeBSD$");
 #include <netinet6/nd6.h>
 #endif
 
+#include <net/rt_nhops.h>
+
 #include <netinet/tcp_fsm.h>
 #include <netinet/tcp_seq.h>
 #include <netinet/tcp_timer.h>
@@ -1858,30 +1860,25 @@ tcp_mtudisc(struct inpcb *inp, int mtuof
 u_long
 tcp_maxmtu(struct in_conninfo *inc, struct tcp_ifcap *cap)
 {
-	struct route sro;
-	struct sockaddr_in *dst;
+	struct nhop4_extended nh_ext;
 	struct ifnet *ifp;
+	int error;
 	u_long maxmtu = 0;
 
 	KASSERT(inc != NULL, ("tcp_maxmtu with NULL in_conninfo pointer"));
 
-	bzero(&sro, sizeof(sro));
-	if (inc->inc_faddr.s_addr != INADDR_ANY) {
-	        dst = (struct sockaddr_in *)&sro.ro_dst;
-		dst->sin_family = AF_INET;
-		dst->sin_len = sizeof(*dst);
-		dst->sin_addr = inc->inc_faddr;
-		in_rtalloc_ign(&sro, 0, inc->inc_fibnum);
-	}
-	if (sro.ro_rt != NULL) {
-		ifp = sro.ro_rt->rt_ifp;
-		if (sro.ro_rt->rt_mtu == 0)
-			maxmtu = ifp->if_mtu;
-		else
-			maxmtu = min(sro.ro_rt->rt_mtu, ifp->if_mtu);
+	if (inc->inc_faddr.s_addr == INADDR_ANY)
+		return (0);
+
+	memset(&nh_ext, 0, sizeof(nh_ext));
+	error = fib4_lookup_nh_extended(inc->inc_fibnum, inc->inc_faddr, 0,
+	    &nh_ext);
+	if (error == 0) {
+		maxmtu = nh_ext.nh_mtu;
 
 		/* Report additional interface capabilities. */
 		if (cap != NULL) {
+			ifp = nh_ext.nh_ifp;
 			if (ifp->if_capenable & IFCAP_TSO4 &&
 			    ifp->if_hwassist & CSUM_TSO) {
 				cap->ifcap |= CSUM_TSO;
@@ -1890,7 +1887,6 @@ tcp_maxmtu(struct in_conninfo *inc, stru
 				cap->tsomaxsegsize = ifp->if_hw_tsomaxsegsize;
 			}
 		}
-		RTFREE(sro.ro_rt);
 	}
 	return (maxmtu);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508231816.t7NIGgCQ042378>