From owner-svn-src-user@FreeBSD.ORG Mon Dec 29 22:07:19 2008 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2DBA21065732; Mon, 29 Dec 2008 22:07:19 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 19ED48FC0C; Mon, 29 Dec 2008 22:07:19 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBTM7IGl068142; Mon, 29 Dec 2008 22:07:18 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBTM7INk068138; Mon, 29 Dec 2008 22:07:18 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200812292207.mBTM7INk068138@svn.freebsd.org> From: Kip Macy Date: Mon, 29 Dec 2008 22:07:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186573 - user/kmacy/HEAD_fast_net/sys/netinet X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Dec 2008 22:07:19 -0000 Author: kmacy Date: Mon Dec 29 22:07:18 2008 New Revision: 186573 URL: http://svn.freebsd.org/changeset/base/186573 Log: cache rtentry in inpcb for connected sockets Modified: user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.c user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.h user/kmacy/HEAD_fast_net/sys/netinet/ip_output.c user/kmacy/HEAD_fast_net/sys/netinet/tcp_usrreq.c Modified: user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.c ============================================================================== --- user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.c Mon Dec 29 21:50:50 2008 (r186572) +++ user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.c Mon Dec 29 22:07:18 2008 (r186573) @@ -490,6 +490,39 @@ in_pcbbind_setup(struct inpcb *inp, stru return (0); } +void +in_pcbrtalloc(struct inpcb *inp, in_addr_t faddr, struct route *sro) +{ + struct sockaddr_in *sin; + + INP_WLOCK_ASSERT(inp); + bzero(sro, sizeof(*sro)); + sin = (struct sockaddr_in *)&sro->ro_dst; + sin->sin_family = AF_INET; + sin->sin_len = sizeof(struct sockaddr_in); + sin->sin_addr.s_addr = faddr; + /* + * If route is known our src addr is taken from the i/f, + * else punt. + * + * Find out route to destination. + */ + if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0) { +#ifdef RADIX_MPATH + rtalloc_mpath_fib(sro, ntohl(faddr->s_addr), + inp->inp_inc.inc_fibnum); +#else + in_rtalloc_ign(sro, 0, inp->inp_inc.inc_fibnum); +#endif + } + + if (sro->ro_rt != NULL) { + inp->inp_rt = sro->ro_rt; + inp->inp_vflag |= INP_RT_VALID; + + } +} + /* * Connect from a socket to a specified address. * Both address and port must be specified in argument sin. @@ -502,6 +535,7 @@ in_pcbconnect(struct inpcb *inp, struct u_short lport, fport; in_addr_t laddr, faddr; int anonport, error; + struct route sro; INP_INFO_WLOCK_ASSERT(inp->inp_pcbinfo); INP_WLOCK_ASSERT(inp); @@ -525,6 +559,7 @@ in_pcbconnect(struct inpcb *inp, struct } } + in_pcbrtalloc(inp, faddr, &sro); /* Commit the remaining changes. */ inp->inp_lport = lport; inp->inp_laddr.s_addr = laddr; @@ -869,6 +904,12 @@ in_pcbdisconnect(struct inpcb *inp) INP_INFO_WLOCK_ASSERT(inp->inp_pcbinfo); INP_WLOCK_ASSERT(inp); + if (inp->inp_vflag & INP_RT_VALID) { + RTFREE(inp->inp_rt); + inp->inp_rt = NULL; + inp->inp_vflag &= ~INP_RT_VALID; + } + inp->inp_faddr.s_addr = INADDR_ANY; inp->inp_fport = 0; in_pcbrehash(inp); @@ -906,6 +947,12 @@ in_pcbfree_internal(struct inpcb *inp) INP_INFO_WLOCK_ASSERT(ipi); INP_WLOCK_ASSERT(inp); + if (inp->inp_vflag & INP_RT_VALID) { + RTFREE(inp->inp_rt); + inp->inp_rt = NULL; + inp->inp_vflag &= ~INP_RT_VALID; + } + #ifdef IPSEC if (inp->inp_sp != NULL) ipsec_delete_pcbpolicy(inp); Modified: user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.h ============================================================================== --- user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.h Mon Dec 29 21:50:50 2008 (r186572) +++ user/kmacy/HEAD_fast_net/sys/netinet/in_pcb.h Mon Dec 29 22:07:18 2008 (r186573) @@ -169,7 +169,8 @@ struct inpcb { u_char inp_ip_minttl; /* (i) minimum TTL or drop */ uint32_t inp_ispare1; /* (x) connection id / queue id */ u_int inp_refcount; /* (i) refcount */ - void *inp_pspare[2]; /* (x) rtentry / general use */ + void *inp_pspare[1]; /* L2 information */ + struct rtentry *inp_rt; /* L3 information */ /* Local and foreign ports, local and foreign addr. */ struct in_conninfo inp_inc; /* (i/p) list for PCB's local port */ @@ -324,6 +325,9 @@ struct inpcbinfo { #define INP_RLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_RLOCKED) #define INP_WLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_WLOCKED) #define INP_UNLOCK_ASSERT(inp) rw_assert(&(inp)->inp_lock, RA_UNLOCKED) +#define INP_TRY_UPGRADE(inp) rw_try_upgrade(&(inp)->inp_lock) +#define INP_DOWNGRADE(inp) rw_downgrade(&(inp)->inp_lock) +#define INP_WLOCKED(inp) rw_wowned(&(inp)->inp_lock) #ifdef _KERNEL /* @@ -395,6 +399,7 @@ void inp_4tuple_get(struct inpcb *inp, #define INP_ONESBCAST 0x10 /* send all-ones broadcast */ #define INP_DROPPED 0x20 /* protocol drop flag */ #define INP_SOCKREF 0x40 /* strong socket reference */ +#define INP_RT_VALID 0x80 /* rtentry is set */ /* * Flags for inp_flag. @@ -487,6 +492,7 @@ void in_pcbdisconnect(struct inpcb *); void in_pcbdrop(struct inpcb *); void in_pcbfree(struct inpcb *); int in_pcbinshash(struct inpcb *); +void in_pcbrtalloc(struct inpcb *inp, in_addr_t faddr, struct route *sro); struct inpcb * in_pcblookup_local(struct inpcbinfo *, struct in_addr, u_short, int, struct ucred *); Modified: user/kmacy/HEAD_fast_net/sys/netinet/ip_output.c ============================================================================== --- user/kmacy/HEAD_fast_net/sys/netinet/ip_output.c Mon Dec 29 21:50:50 2008 (r186572) +++ user/kmacy/HEAD_fast_net/sys/netinet/ip_output.c Mon Dec 29 22:07:18 2008 (r186573) @@ -121,11 +121,13 @@ ip_output(struct mbuf *m, struct mbuf *o int hlen = sizeof (struct ip); int mtu; int len, error = 0; + int neednewroute = 0; struct sockaddr_in *dst = NULL; /* keep compiler happy */ struct in_ifaddr *ia = NULL; int isbroadcast, sw_csum; struct route iproute; struct in_addr odst; + struct sockaddr_in *sin; #ifdef IPFIREWALL_FORWARD struct m_tag *fwd_tag = NULL; #endif @@ -139,6 +141,16 @@ ip_output(struct mbuf *m, struct mbuf *o if (inp != NULL) { M_SETFIB(m, inp->inp_inc.inc_fibnum); INP_LOCK_ASSERT(inp); + if ((ro == &iproute) && (inp->inp_vflag & INP_RT_VALID)) { + if (inp->inp_rt->rt_flags & RTF_UP) { + sin = (struct sockaddr_in *)&ro->ro_dst; + sin->sin_family = AF_INET; + sin->sin_len = sizeof(struct sockaddr_in); + sin->sin_addr.s_addr = inp->inp_faddr.s_addr; + ro->ro_rt = inp->inp_rt; + } else + neednewroute = 1; + } } if (opt) { @@ -181,7 +193,8 @@ again: if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 || dst->sin_family != AF_INET || dst->sin_addr.s_addr != ip->ip_dst.s_addr)) { - RTFREE(ro->ro_rt); + if (inp == NULL || (ro->ro_rt != inp->inp_rt)) + RTFREE(ro->ro_rt); ro->ro_rt = (struct rtentry *)NULL; } #ifdef IPFIREWALL_FORWARD @@ -611,8 +624,20 @@ passout: V_ipstat.ips_fragmented++; done: - if (ro == &iproute && ro->ro_rt) { - RTFREE(ro->ro_rt); + if (ro == &iproute && ro->ro_rt != NULL) { + int wlocked; + + if (inp == NULL || (inp->inp_vflag & INP_RT_VALID) == 0) + RTFREE(ro->ro_rt); + else if (neednewroute && ro->ro_rt != inp->inp_rt) { + wlocked = INP_WLOCKED(inp); + if (!wlocked && INP_TRY_UPGRADE(inp) == 0) + return (error); + RTFREE(inp->inp_rt); + inp->inp_rt = ro->ro_rt; + if (!wlocked) + INP_DOWNGRADE(inp); + } } return (error); bad: Modified: user/kmacy/HEAD_fast_net/sys/netinet/tcp_usrreq.c ============================================================================== --- user/kmacy/HEAD_fast_net/sys/netinet/tcp_usrreq.c Mon Dec 29 21:50:50 2008 (r186572) +++ user/kmacy/HEAD_fast_net/sys/netinet/tcp_usrreq.c Mon Dec 29 22:07:18 2008 (r186573) @@ -1077,6 +1077,7 @@ tcp_connect(struct tcpcb *tp, struct soc struct socket *so = inp->inp_socket; INIT_VNET_INET(so->so_vnet); struct in_addr laddr; + struct route sro; u_short lport; int error; @@ -1105,6 +1106,7 @@ tcp_connect(struct tcpcb *tp, struct soc inp->inp_laddr = laddr; in_pcbrehash(inp); + in_pcbrtalloc(inp, inp->inp_faddr.s_addr, &sro); /* * Compute window scaling to request: * Scale to fit into sweet spot. See tcp_syncache.c.