From owner-svn-src-user@FreeBSD.ORG Wed Oct 16 08:58:58 2013 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E4556224; Wed, 16 Oct 2013 08:58:58 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D26BE2C3B; Wed, 16 Oct 2013 08:58:58 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G8wwEG088992; Wed, 16 Oct 2013 08:58:58 GMT (envelope-from ae@svn.freebsd.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G8wwCt088991; Wed, 16 Oct 2013 08:58:58 GMT (envelope-from ae@svn.freebsd.org) Message-Id: <201310160858.r9G8wwCt088991@svn.freebsd.org> From: "Andrey V. Elsukov" Date: Wed, 16 Oct 2013 08:58:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256599 - user/ae/inet6/sys/netinet6 X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.14 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: Wed, 16 Oct 2013 08:58:59 -0000 Author: ae Date: Wed Oct 16 08:58:58 2013 New Revision: 256599 URL: http://svnweb.freebsd.org/changeset/base/256599 Log: Add cached_rtlookup() function. It validates route and if it is ok, returns it. Otherwise it does new route lookup. Modified: user/ae/inet6/sys/netinet6/in6_src.c Modified: user/ae/inet6/sys/netinet6/in6_src.c ============================================================================== --- user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:48:45 2013 (r256598) +++ user/ae/inet6/sys/netinet6/in6_src.c Wed Oct 16 08:58:58 2013 (r256599) @@ -127,6 +127,9 @@ static VNET_DEFINE(struct in6_addrpolicy VNET_DEFINE(int, ip6_prefer_tempaddr) = 0; +static int cached_rtlookup(const struct sockaddr_in6 *dst, + struct route_in6 *ro, u_int fibnum); + static int selectroute(struct sockaddr_in6 *, struct ip6_pktopts *, struct ip6_moptions *, struct route_in6 *, struct ifnet **, struct rtentry **, int, u_int); @@ -294,6 +297,33 @@ next: #undef REPLACE #undef NEXT +static int +cached_rtlookup(const struct sockaddr_in6 *dst, struct route_in6 *ro, + u_int fibnum) +{ + + /* + * Use a cached route if it exists and is valid, else try to allocate + * a new one. Note that we should check the address family of the + * cached destination, in case of sharing the cache with IPv4. + */ + KASSERT(ro != NULL, ("%s: ro is NULL", __func__)); + if (ro->ro_rt != NULL && ( + (ro->ro_rt->rt_flags & RTF_UP) == 0 || + ro->ro_dst.sin6_family != AF_INET6 || + !IN6_ARE_ADDR_EQUAL(&ro->ro_dst.sin6_addr, &dst->sin6_addr))) { + RO_RTFREE(ro); + } + if (ro->ro_rt == NULL) { + /* No route yet, so try to acquire one */ + memcpy(&ro->ro_dst, dst, sizeof(*dst)); + in6_rtalloc(ro, fibnum); + } + if (ro->ro_rt == NULL) + return (EHOSTUNREACH); + return (0); +} + int in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, struct inpcb *inp, struct route_in6 *ro, struct ucred *cred,