Date: Wed, 16 Oct 2013 08:58:58 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r256599 - user/ae/inet6/sys/netinet6 Message-ID: <201310160858.r9G8wwCt088991@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310160858.r9G8wwCt088991>