Use rtcache_validate() instead of rtcache_getrt(). Shorten staircase

in in6_losing().
This commit is contained in:
dyoung 2008-01-14 04:16:45 +00:00
parent 6a0b0c88d2
commit 19dd9ed4a7
4 changed files with 37 additions and 36 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: in6_pcb.c,v 1.93 2008/01/12 02:58:58 dyoung Exp $ */
/* $NetBSD: in6_pcb.c,v 1.94 2008/01/14 04:16:45 dyoung Exp $ */
/* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.93 2008/01/12 02:58:58 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.94 2008/01/14 04:16:45 dyoung Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@ -437,7 +437,7 @@ in6_pcbconnect(void *v, struct mbuf *nam, struct lwp *l)
return (error);
}
}
if (ifp == NULL && (rt = rtcache_getrt(&in6p->in6p_route)) != NULL)
if (ifp == NULL && (rt = rtcache_validate(&in6p->in6p_route)) != NULL)
ifp = rt->rt_ifp;
in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(in6p, ifp);
@ -648,7 +648,7 @@ in6_pcbnotify(struct inpcbtable *table, const struct sockaddr *dst,
*/
if ((PRC_IS_REDIRECT(cmd) || cmd == PRC_HOSTDEAD) &&
IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) &&
(rt = rtcache_getrt(&in6p->in6p_route)) != NULL &&
(rt = rtcache_validate(&in6p->in6p_route)) != NULL &&
!(rt->rt_flags & RTF_HOST)) {
const struct sockaddr_in6 *dst6;
@ -761,7 +761,7 @@ in6_pcbpurgeif(struct inpcbtable *table, struct ifnet *ifp)
nin6p = (struct in6pcb *)CIRCLEQ_NEXT(in6p, in6p_queue);
if (in6p->in6p_af != AF_INET6)
continue;
if ((rt = rtcache_getrt(&in6p->in6p_route)) != NULL &&
if ((rt = rtcache_validate(&in6p->in6p_route)) != NULL &&
rt->rt_ifp == ifp)
in6_rtchange(in6p, 0);
}
@ -782,22 +782,23 @@ in6_losing(struct in6pcb *in6p)
if (in6p->in6p_af != AF_INET6)
return;
if ((rt = rtcache_getrt(&in6p->in6p_route)) != NULL) {
memset(&info, 0, sizeof(info));
info.rti_info[RTAX_DST] = rtcache_getdst(&in6p->in6p_route);
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
rt_missmsg(RTM_LOSING, &info, rt->rt_flags, 0);
if (rt->rt_flags & RTF_DYNAMIC) {
(void)rtrequest(RTM_DELETE, rt_getkey(rt),
rt->rt_gateway, rt_mask(rt), rt->rt_flags, NULL);
}
rtcache_free(&in6p->in6p_route);
/*
* A new route can be allocated
* the next time output is attempted.
*/
if ((rt = rtcache_validate(&in6p->in6p_route)) == NULL)
return;
memset(&info, 0, sizeof(info));
info.rti_info[RTAX_DST] = rtcache_getdst(&in6p->in6p_route);
info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
info.rti_info[RTAX_NETMASK] = rt_mask(rt);
rt_missmsg(RTM_LOSING, &info, rt->rt_flags, 0);
if (rt->rt_flags & RTF_DYNAMIC) {
(void)rtrequest(RTM_DELETE, rt_getkey(rt),
rt->rt_gateway, rt_mask(rt), rt->rt_flags, NULL);
}
/*
* A new route can be allocated
* the next time output is attempted.
*/
rtcache_free(&in6p->in6p_route);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6_forward.c,v 1.61 2008/01/12 02:58:58 dyoung Exp $ */
/* $NetBSD: ip6_forward.c,v 1.62 2008/01/14 04:16:45 dyoung Exp $ */
/* $KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $ */
/*
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.61 2008/01/12 02:58:58 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.62 2008/01/14 04:16:45 dyoung Exp $");
#include "opt_ipsec.h"
#include "opt_pfil_hooks.h"
@ -334,7 +334,7 @@ ip6_forward(struct mbuf *m, int srcrt)
}
/* adjust pointer */
rt = state.ro ? rtcache_getrt(state.ro) : NULL;
rt = state.ro ? rtcache_validate(state.ro) : NULL;
dst = (const struct sockaddr_in6 *)state.dst;
if (dst != NULL && rt != NULL) {
ipsecrt = 1;
@ -367,7 +367,7 @@ ip6_forward(struct mbuf *m, int srcrt)
} u;
sockaddr_in6_init(&u.dst6, &ip6->ip6_dst, 0, 0, 0);
if (rtcache_lookup(&ip6_forward_rt, &u.dst) == NULL) {
if ((rt = rtcache_lookup(&ip6_forward_rt, &u.dst)) == NULL) {
ip6stat.ip6s_noroute++;
/* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */
if (mcopy) {
@ -377,8 +377,8 @@ ip6_forward(struct mbuf *m, int srcrt)
m_freem(m);
return;
}
} else if (rtcache_validate(&ip6_forward_rt) == NULL &&
rtcache_update(&ip6_forward_rt, 1) == NULL) {
} else if ((rt = rtcache_validate(&ip6_forward_rt)) == NULL &&
(rt = rtcache_update(&ip6_forward_rt, 1)) == NULL) {
/*
* rtcache_getdst(ip6_forward_rt)->sin6_addr was equal to
* ip6->ip6_dst
@ -393,7 +393,6 @@ ip6_forward(struct mbuf *m, int srcrt)
return;
}
dst = satocsin6(rtcache_getdst(&ip6_forward_rt));
rt = rtcache_getrt(&ip6_forward_rt);
#ifdef IPSEC
skip_routing:;
#endif /* IPSEC */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip6_output.c,v 1.125 2008/01/10 08:06:12 dyoung Exp $ */
/* $NetBSD: ip6_output.c,v 1.126 2008/01/14 04:16:45 dyoung Exp $ */
/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.125 2008/01/10 08:06:12 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.126 2008/01/14 04:16:45 dyoung Exp $");
#include "opt_inet.h"
#include "opt_inet6.h"
@ -731,7 +731,7 @@ skip_ipsec2:;
if (dst == NULL)
dst = satocsin6(rtcache_getdst(ro));
KASSERT(dst != NULL);
} else if (opt && rtcache_getrt(&opt->ip6po_nextroute) != NULL) {
} else if (opt && rtcache_validate(&opt->ip6po_nextroute) != NULL) {
/*
* The nexthop is explicitly specified by the
* application. We assume the next hop is an IPv6
@ -1412,9 +1412,10 @@ ip6_getpmtu(struct route *ro_pmtu, struct route *ro, struct ifnet *ifp,
/* The first hop and the final destination may differ. */
sockaddr_in6_init(&u.dst6, dst, 0, 0, 0);
rtcache_lookup(ro_pmtu, &u.dst);
}
if ((rt = rtcache_getrt(ro_pmtu)) != NULL) {
rt = rtcache_lookup(ro_pmtu, &u.dst);
} else
rt = rtcache_validate(ro_pmtu);
if (rt != NULL) {
u_int32_t ifmtu;
if (ifp == NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: udp6_output.c,v 1.31 2007/12/20 19:53:34 dyoung Exp $ */
/* $NetBSD: udp6_output.c,v 1.32 2008/01/14 04:16:46 dyoung Exp $ */
/* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
/*
@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.31 2007/12/20 19:53:34 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.32 2008/01/14 04:16:46 dyoung Exp $");
#include "opt_inet.h"
@ -350,7 +350,7 @@ udp6_output(struct in6pcb *in6p, struct mbuf *m, struct mbuf *addr6,
#endif
ip6->ip6_nxt = IPPROTO_UDP;
ip6->ip6_hlim = in6_selecthlim(in6p,
(rt = rtcache_getrt(&in6p->in6p_route)) != NULL
(rt = rtcache_validate(&in6p->in6p_route)) != NULL
? rt->rt_ifp : NULL);
ip6->ip6_src = *laddr;
ip6->ip6_dst = *faddr;