From f3ed2586bd034c9a75914e4e28354af8bfe2aabc Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Thu, 6 Jan 2005 17:59:32 +0000 Subject: [PATCH] Now that I understand the poorly written BSD routing code and what it was trying to do, rewrite it in a clear and concise manner. The old rtalloc1() code written by CSRG had a number of problems: 1. it was not clear which route was being returned 2. it was not clear what was being reported 3. it hid the essential radix tree lookup operation inside a series of conditional tests and inline assignments 4. it had multiple gotos to the inside of if statements 5. it intermixed reporting code with the operational logic of lookup and cloning 6. it assigns multiple times to key variables 7. it has unnecessary assignments to key variables 8. it overloaded the "report" argument parameter, to have two different semantics 9. it misnamed the key route lookup function "rtalloc1", obscuring all uses of route lookup. In contrast to the rtalloc1 code in FreeBSD 4 or the even more convoluted rtalloc1 code in FreeBSD 5, the DragonFlyBSD version A. has a clear control flow that makes the common case obvious by highlighting the core call to the radix tree look up function, eliminating gotos into if statements, and completely separating out the special-case cloning logic B. makes it clear which route is being returned by only assigning once to the key "rt" variable and by expliciting returning "rt" or "clonedroute" C. abstracts out the reporting code into its own reporting API D. cleans up the semantics of the "report" argument parameter to only indicate whether to report a miss and not whether to clone E. introduces a simple single-argument API for caller that want to clone and those that do not. --- sys/net/faith/if_faith.c | 4 +- sys/net/hostcache.c | 4 +- sys/net/if_atm.h | 4 +- sys/net/if_fddisubr.c | 4 +- sys/net/route.c | 187 ++++++++++++++++++++++-------------- sys/net/route.h | 82 +++++++++++++++- sys/net/rtsock.c | 97 ++++++++++++++++--- sys/netinet/if_ether.c | 61 +++++++++++- sys/netinet/in_gif.c | 4 +- sys/netinet/in_hostcache.c | 4 +- sys/netinet/in_rmx.c | 5 +- sys/netinet/ip_icmp.c | 5 +- sys/netinet6/icmp6.c | 6 +- sys/netinet6/in6.c | 6 +- sys/netinet6/in6_gif.c | 4 +- sys/netinet6/in6_ifattach.c | 6 +- sys/netinet6/in6_pcb.c | 6 +- sys/netinet6/in6_rmx.c | 8 +- sys/netinet6/in6_src.c | 6 +- sys/netinet6/ip6_output.c | 6 +- sys/netinet6/nd6.c | 13 +-- sys/netinet6/nd6_nbr.c | 4 +- 22 files changed, 388 insertions(+), 138 deletions(-) diff --git a/sys/net/faith/if_faith.c b/sys/net/faith/if_faith.c index d723c2d494..778d785880 100644 --- a/sys/net/faith/if_faith.c +++ b/sys/net/faith/if_faith.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_faith.c,v 1.3.2.6 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/faith/if_faith.c,v 1.10 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/net/faith/if_faith.c,v 1.11 2005/01/06 17:59:32 hsu Exp $ */ /* * derived from @@ -368,7 +368,7 @@ faithprefix(in6) sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(struct sockaddr_in6); sin6.sin6_addr = *in6; - rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); + rt = rtpurelookup((struct sockaddr *)&sin6); if (rt != NULL && rt->rt_ifp && rt->rt_ifp->if_type == IFT_FAITH && (rt->rt_ifp->if_flags & IFF_UP)) ret = 1; diff --git a/sys/net/hostcache.c b/sys/net/hostcache.c index 9b11354117..8da69d8130 100644 --- a/sys/net/hostcache.c +++ b/sys/net/hostcache.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/hostcache.c,v 1.6.2.1 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/Attic/hostcache.c,v 1.4 2004/12/21 02:54:14 hsu Exp $ + * $DragonFly: src/sys/net/Attic/hostcache.c,v 1.5 2005/01/06 17:59:32 hsu Exp $ */ #include @@ -106,7 +106,7 @@ hc_get(struct sockaddr *sa) hc->hc_rt = NULL; } if (hc->hc_rt == NULL) { - hc->hc_rt = rtlookup(hc->hc_host, 1, 0); + hc->hc_rt = rtlookup(hc->hc_host); } hc_ref(hc); splx(s); diff --git a/sys/net/if_atm.h b/sys/net/if_atm.h index 255e8596a6..fb1a7f72e8 100644 --- a/sys/net/if_atm.h +++ b/sys/net/if_atm.h @@ -1,6 +1,6 @@ /* $NetBSD: if_atm.h,v 1.7 1996/11/09 23:02:27 chuck Exp $ */ /* $FreeBSD: src/sys/net/if_atm.h,v 1.4 1999/12/29 04:38:34 peter Exp $ */ -/* $DragonFly: src/sys/net/if_atm.h,v 1.5 2004/12/21 02:54:14 hsu Exp $ */ +/* $DragonFly: src/sys/net/if_atm.h,v 1.6 2005/01/06 17:59:32 hsu Exp $ */ /* * @@ -41,7 +41,7 @@ #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) #define RTALLOC1(A,B) rtalloc1((A), (B)) #elif defined(__DragonFly__) -#define RTALLOC1(A,B) rtlookup((A), (B), 0UL) +#define RTALLOC1(A,B) _rtlookup((A), (B), (B) ? RTL_DOCLONE : RTL_DONTCLONE) #elif defined(__FreeBSD__) #define RTALLOC1(A,B) rtalloc1((A), (B), 0UL) #endif diff --git a/sys/net/if_fddisubr.c b/sys/net/if_fddisubr.c index 3a6f2503a4..c16e702329 100644 --- a/sys/net/if_fddisubr.c +++ b/sys/net/if_fddisubr.c @@ -34,7 +34,7 @@ * * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp * $FreeBSD: src/sys/net/if_fddisubr.c,v 1.41.2.8 2002/02/20 23:34:09 fjoe Exp $ - * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.14 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.15 2005/01/06 17:59:32 hsu Exp $ */ #include "opt_atalk.h" @@ -113,7 +113,7 @@ static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *, #endif #if defined(__DragonFly__) -#define RTALLOC1(a, b) rtlookup(a, b, 0UL) +#define RTALLOC1(a, b) _rtlookup(a, b, b ? RTL_DOCLONE : RTL_DONTCLONE) #define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e) #elif defined(__FreeBSD__) #define RTALLOC1(a, b) rtalloc1(a, b, 0UL) diff --git a/sys/net/route.c b/sys/net/route.c index 1e76df9ea2..85ba6b4031 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,3 +1,53 @@ +/* + * Copyright (c) 2004, 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Jeffrey M. Hsu. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 2004, 2005 Jeffrey M. Hsu. All rights reserved. + * + * License terms: all terms for the DragonFly license above plus the following: + * + * 4. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Jeffrey M. Hsu + * for the DragonFly Project. + * + * This requirement may be waived with permission from Jeffrey Hsu. + * Permission will be granted to any DragonFly user for free. + * This requirement will sunset and may be removed on Jan 31, 2006, + * after which the standard DragonFly license (as shown above) will + * apply. + */ + /* * Copyright (c) 1980, 1986, 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +82,7 @@ * * @(#)route.c 8.3 (Berkeley) 1/9/95 * $FreeBSD: src/sys/net/route.c,v 1.59.2.10 2003/01/17 08:04:00 ru Exp $ - * $DragonFly: src/sys/net/route.c,v 1.12 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/net/route.c,v 1.13 2005/01/06 17:59:32 hsu Exp $ */ #include "opt_inet.h" @@ -81,9 +131,9 @@ route_init() */ /* - * Lookup and fill in the "ro_rt" rtentry field in a route structure given - * an address in the ro_dst field. Always send a report and always - * clone routes. + * Look up and fill in the "ro_rt" rtentry field in a route structure given + * an address in the "ro_dst" field. Always send a report on a miss and + * always clone routes. */ void rtalloc(struct route *ro) @@ -92,12 +142,13 @@ rtalloc(struct route *ro) } /* - * Lookup and fill in the "ro_rt" rtentry field in a route structure given - * an address in the ro_dst field. Always send a report and optionally - * clone routes when RTF_CLONING or RTF_PRCLONING are not being ignored. + * Look up and fill in the "ro_rt" rtentry field in a route structure given + * an address in the "ro_dst" field. Always send a report on a miss and + * optionally clone routes when RTF_CLONING or RTF_PRCLONING are not being + * ignored. */ void -rtalloc_ign(struct route *ro, u_long ignore) +rtalloc_ign(struct route *ro, u_long ignoreflags) { if (ro->ro_rt != NULL) { if (ro->ro_rt->rt_ifp != NULL && ro->ro_rt->rt_flags & RTF_UP) @@ -105,78 +156,74 @@ rtalloc_ign(struct route *ro, u_long ignore) rtfree(ro->ro_rt); ro->ro_rt = NULL; } - ro->ro_rt = rtlookup(&ro->ro_dst, 1, ignore); + ro->ro_rt = _rtlookup(&ro->ro_dst, RTL_REPORTMSG, ignoreflags); } /* * Look up the route that matches the given "dst" address. * - * Create and return a cloned route if "dst" matches a cloning route - * and the RTF_CLONING and RTF_PRCLONING flags are not being ignored. + * Route lookup can have the side-effect of creating and returning + * a cloned route instead if "dst" matches a cloning route and the + * RTF_CLONING and RTF_PRCLONING flags are not being ignored. * - * Any route returned has its refcnt incremented. + * Any route returned has its reference count incremented. */ struct rtentry * -rtlookup(struct sockaddr *dst, int report, u_long ignflags) +_rtlookup(struct sockaddr *dst, boolean_t report, u_long ignore) { struct radix_node_head *rnh = rt_tables[dst->sa_family]; - struct rtentry *rt; struct radix_node *rn; - struct rt_addrinfo info; - u_long nflags; - int s, err, msgtype; + struct rtentry *rt; - s = splnet(); - if (rnh != NULL && (rn = rnh->rnh_matchaddr((char *)dst, rnh))) { + if (rnh == NULL) + goto unreach; + + /* + * Look up route in the radix tree. + */ + rn = rnh->rnh_matchaddr((char *)dst, rnh); + if (rn == NULL) + goto unreach; + else rt = (struct rtentry *)rn; - nflags = rt->rt_flags & ~ignflags; - if (report && (nflags & (RTF_CLONING | RTF_PRCLONING))) { - struct rtentry *clonedroute; - - clonedroute = rt; /* value used in rtrequest()! */ - err = rtrequest(RTM_RESOLVE, dst, NULL, NULL, 0, - &clonedroute); - if (err != 0) { - /* use master cloning route on clone failure */ - rt->rt_refcnt++; - goto reportmiss; - } - rt = clonedroute; /* return cloned route to caller */ - if (clonedroute->rt_flags & RTF_XRESOLVE) { - /* Cloned route needs external resolution. */ - msgtype = RTM_RESOLVE; - goto reportmsg; - } - /* Inform listeners of the new route. */ - bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = rt_key(clonedroute); - info.rti_info[RTAX_NETMASK] = rt_mask(clonedroute); - info.rti_info[RTAX_GATEWAY] = clonedroute->rt_gateway; - if (clonedroute->rt_ifp != NULL) { - info.rti_info[RTAX_IFP] = - TAILQ_FIRST(&clonedroute->rt_ifp - ->if_addrhead)->ifa_addr; - info.rti_info[RTAX_IFA] = - clonedroute->rt_ifa->ifa_addr; - } - rt_missmsg(RTM_ADD, &info, clonedroute->rt_flags, 0); - } else - rt->rt_refcnt++; /* most common case */ - } else { - rt = NULL; - rtstat.rts_unreach++; + + /* + * Handle cloning routes. + */ + if ((rt->rt_flags & ~ignore & (RTF_CLONING | RTF_PRCLONING)) != 0) { + struct rtentry *clonedroute; + int error; + + clonedroute = rt; /* copy in/copy out parameter */ + error = rtrequest(RTM_RESOLVE, dst, NULL, NULL, 0, + &clonedroute); /* clone the route */ + if (error != 0) { /* cloning failed */ + if (report) + rt_dstmsg(RTM_MISS, dst, error); + rt->rt_refcnt++; + return (rt); /* return the uncloned route */ + } if (report) { - err = 0; -reportmiss: - msgtype = RTM_MISS; -reportmsg: - bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = dst; - rt_missmsg(msgtype, &info, 0, err); + if (clonedroute->rt_flags & RTF_XRESOLVE) + rt_dstmsg(RTM_RESOLVE, dst, 0); + else + rt_rtmsg(RTM_ADD, clonedroute, + clonedroute->rt_ifp, 0); } + return (clonedroute); /* return cloned route */ } - splx(s); + + /* + * Increment the reference count of the matched route and return. + */ + rt->rt_refcnt++; return (rt); + +unreach: + rtstat.rts_unreach++; + if (report) + rt_dstmsg(RTM_MISS, dst, 0); + return (NULL); } void @@ -237,7 +284,7 @@ rtredirect( * going down recently. */ if (!(flags & RTF_DONE) && - (rt = rtlookup(dst, 0, 0UL)) != NULL && + (rt = rtpurelookup(dst)) != NULL && (!sa_equal(src, rt->rt_gateway) || rt->rt_ifa != ifa)) { error = EINVAL; goto done; @@ -361,7 +408,7 @@ ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway) if (ifa == NULL) ifa = ifa_ifwithnet(gateway); if (ifa == NULL) { - struct rtentry *rt = rtlookup(gateway, 0, 0UL); + struct rtentry *rt = rtpurelookup(gateway); if (rt == NULL) return (NULL); @@ -590,7 +637,7 @@ makeroute: * cloned, then we blow it away and try * re-inserting the new one. */ - oldrt = rtlookup(ndst, 0, RTF_CLONING | RTF_PRCLONING); + oldrt = rtpurelookup(ndst); if (oldrt != NULL) { --oldrt->rt_refcnt; if (oldrt->rt_flags & RTF_WASCLONED) { @@ -876,7 +923,7 @@ rt_setgate(struct rtentry *rt0, struct sockaddr *dst, struct sockaddr *gate) * * This breaks TTCP for hosts outside the gateway! XXX JH */ - rt->rt_gwroute = rtlookup(gate, 1, RTF_PRCLONING); + rt->rt_gwroute = _rtlookup(gate, RTL_REPORTMSG, RTF_PRCLONING); if (rt->rt_gwroute == rt) { rt->rt_gwroute = NULL; --rt->rt_refcnt; @@ -928,7 +975,7 @@ rt_llroute(struct sockaddr *dst, struct rtentry *rt0, struct rtentry **drt) struct rtentry *up_rt, *rt; if (!(rt0->rt_flags & RTF_UP)) { - up_rt = rtlookup(dst, 1, 0UL); + up_rt = rtlookup(dst); if (up_rt == NULL) return (EHOSTUNREACH); up_rt->rt_refcnt--; @@ -936,12 +983,12 @@ rt_llroute(struct sockaddr *dst, struct rtentry *rt0, struct rtentry **drt) up_rt = rt0; if (up_rt->rt_flags & RTF_GATEWAY) { if (up_rt->rt_gwroute == NULL) { - up_rt->rt_gwroute = rtlookup(up_rt->rt_gateway, 1, 0UL); + up_rt->rt_gwroute = rtlookup(up_rt->rt_gateway); if (up_rt->rt_gwroute == NULL) return (EHOSTUNREACH); } else if (!(up_rt->rt_gwroute->rt_flags & RTF_UP)) { rtfree(up_rt->rt_gwroute); - up_rt->rt_gwroute = rtlookup(up_rt->rt_gateway, 1, 0UL); + up_rt->rt_gwroute = rtlookup(up_rt->rt_gateway); if (up_rt->rt_gwroute == NULL) return (EHOSTUNREACH); } diff --git a/sys/net/route.h b/sys/net/route.h index 8bb70b40c3..e6a84e3842 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -1,3 +1,53 @@ +/* + * Copyright (c) 2004, 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Jeffrey M. Hsu. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 2004, 2005 Jeffrey M. Hsu. All rights reserved. + * + * License terms: all terms for the DragonFly license above plus the following: + * + * 4. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Jeffrey M. Hsu + * for the DragonFly Project. + * + * This requirement may be waived with permission from Jeffrey Hsu. + * Permission will be granted to any DragonFly user for free. + * This requirement will sunset and may be removed on Jan 31, 2006, + * after which the standard DragonFly license (as shown above) will + * apply. + */ + /* * Copyright (c) 1980, 1986, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +82,7 @@ * * @(#)route.h 8.4 (Berkeley) 1/9/95 * $FreeBSD: src/sys/net/route.h,v 1.36.2.5 2002/02/01 11:48:01 ru Exp $ - * $DragonFly: src/sys/net/route.h,v 1.9 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/net/route.h,v 1.10 2005/01/06 17:59:32 hsu Exp $ */ #ifndef _NET_ROUTE_H_ @@ -275,6 +325,7 @@ struct ifmultiaddr; struct proc; void route_init (void); +void rt_dstmsg(int type, struct sockaddr *dst, int error); int rt_getifa (struct rt_addrinfo *); void rt_ifannouncemsg (struct ifnet *, int); void rt_ifmsg (struct ifnet *); @@ -283,12 +334,39 @@ int rt_llroute (struct sockaddr *dst, struct rtentry *rt0, void rt_missmsg (int, struct rt_addrinfo *, int, int); void rt_newaddrmsg (int, struct ifaddr *, int, struct rtentry *); void rt_newmaddrmsg (int, struct ifmultiaddr *); +void rt_rtmsg(int cmd, struct rtentry *rt, struct ifnet *ifp, int error); int rt_setgate (struct rtentry *, struct sockaddr *, struct sockaddr *); void rtalloc (struct route *); void rtalloc_ign (struct route *, u_long); + struct rtentry * - rtlookup (struct sockaddr *, int, u_long); + _rtlookup (struct sockaddr *, boolean_t, u_long); +#define RTL_REPORTMSG TRUE +#define RTL_DONTREPORT FALSE + +/* flags to ignore */ +#define RTL_DOCLONE 0UL +#define RTL_DONTCLONE (RTF_CLONING | RTF_PRCLONING) + +/* + * Look up a route with no cloning side-effects or miss reports generated. + */ +static __inline struct rtentry * +rtpurelookup(struct sockaddr *dst) +{ + return _rtlookup(dst, RTL_DONTREPORT, RTL_DONTCLONE); +} + +/* + * Do full route lookup with cloning and reporting on misses. + */ +static __inline struct rtentry * +rtlookup(struct sockaddr *dst) +{ + return _rtlookup(dst, RTL_REPORTMSG, RTL_DOCLONE); +} + void rtfree (struct rtentry *); int rtinit (struct ifaddr *, int, int); int rtioctl (u_long, caddr_t, struct thread *); diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 0afdc4ce03..dbba95b4eb 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,3 +1,53 @@ +/* + * Copyright (c) 2004, 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Jeffrey M. Hsu. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 2004, 2005 Jeffrey M. Hsu. All rights reserved. + * + * License terms: all terms for the DragonFly license above plus the following: + * + * 4. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Jeffrey M. Hsu + * for the DragonFly Project. + * + * This requirement may be waived with permission from Jeffrey Hsu. + * Permission will be granted to any DragonFly user for free. + * This requirement will sunset and may be removed on Jan 31, 2006, + * after which the standard DragonFly license (as shown above) will + * apply. + */ + /* * Copyright (c) 1988, 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +82,7 @@ * * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 * $FreeBSD: src/sys/net/rtsock.c,v 1.44.2.11 2002/12/04 14:05:41 ru Exp $ - * $DragonFly: src/sys/net/rtsock.c,v 1.19 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/net/rtsock.c,v 1.20 2005/01/06 17:59:32 hsu Exp $ */ #include @@ -745,6 +795,28 @@ rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error) raw_input(m, &route_proto, &route_src, &route_dst); } +void +rt_dstmsg(int type, struct sockaddr *dst, int error) +{ + struct rt_msghdr *rtm; + struct rt_addrinfo addrs; + struct mbuf *m; + + if (route_cb.any_count == 0) + return; + bzero(&addrs, sizeof(struct rt_addrinfo)); + addrs.rti_info[RTAX_DST] = dst; + m = rt_msg1(type, &addrs); + if (m == NULL) + return; + rtm = mtod(m, struct rt_msghdr *); + rtm->rtm_flags = RTF_DONE; + rtm->rtm_errno = error; + rtm->rtm_addrs = addrs.rti_addrs; + route_proto.sp_protocol = (dst != NULL) ? dst->sa_family : 0; + raw_input(m, &route_proto, &route_src, &route_dst); +} + /* * This routine is called to generate a message from the routing * socket indicating that the status of a network interface has changed. @@ -801,34 +873,37 @@ rt_ifamsg(int cmd, struct ifaddr *ifa) raw_input(m, &route_proto, &route_src, &route_dst); } -static void -rt_rtmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt) +void +rt_rtmsg(int cmd, struct rtentry *rt, struct ifnet *ifp, int error) { struct rt_msghdr *rtm; struct rt_addrinfo info; struct mbuf *m; - struct sockaddr *sa; - struct ifnet *ifp = ifa->ifa_ifp; + struct sockaddr *dst; if (rt == NULL) return; bzero(&info, sizeof info); - info.sa_netmask = rt_mask(rt); - info.sa_dst = sa = rt_key(rt); + info.sa_dst = dst = rt_key(rt); info.sa_gateway = rt->rt_gateway; + info.sa_netmask = rt_mask(rt); + if (ifp != NULL) + info.sa_ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr; + info.sa_ifaaddr = rt->rt_ifa->ifa_addr; m = rt_msg1(cmd, &info); if (m == NULL) return; rtm = mtod(m, struct rt_msghdr *); - rtm->rtm_index = ifp->if_index; + if (ifp != NULL) + rtm->rtm_index = ifp->if_index; rtm->rtm_flags |= rt->rt_flags; rtm->rtm_errno = error; rtm->rtm_addrs = info.rti_addrs; - route_proto.sp_protocol = sa ? sa->sa_family : 0; + route_proto.sp_protocol = (dst != NULL) ? dst->sa_family : 0; raw_input(m, &route_proto, &route_src, &route_dst); } @@ -849,10 +924,10 @@ rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt) if (cmd == RTM_ADD) { rt_ifamsg(RTM_NEWADDR, ifa); - rt_rtmsg(RTM_ADD, ifa, error, rt); + rt_rtmsg(RTM_ADD, rt, ifa->ifa_ifp, error); } else { KASSERT((cmd == RTM_DELETE), ("unknown cmd %d", cmd)); - rt_rtmsg(RTM_DELETE, ifa, error, rt); + rt_rtmsg(RTM_DELETE, rt, ifa->ifa_ifp, error); rt_ifamsg(RTM_DELADDR, ifa); } } diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index 5d15b7df55..c506f25dac 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -1,3 +1,53 @@ +/* + * Copyright (c) 2004, 2005 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Jeffrey M. Hsu. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 2004, 2005 Jeffrey M. Hsu. All rights reserved. + * + * License terms: all terms for the DragonFly license above plus the following: + * + * 4. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Jeffrey M. Hsu + * for the DragonFly Project. + * + * This requirement may be waived with permission from Jeffrey Hsu. + * Permission will be granted to any DragonFly user for free. + * This requirement will sunset and may be removed on Jan 31, 2006, + * after which the standard DragonFly license (as shown above) will + * apply. + */ + /* * Copyright (c) 1982, 1986, 1988, 1993 * The Regents of the University of California. All rights reserved. @@ -32,7 +82,7 @@ * * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/if_ether.c,v 1.64.2.23 2003/04/11 07:23:15 fjoe Exp $ - * $DragonFly: src/sys/netinet/if_ether.c,v 1.23 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/netinet/if_ether.c,v 1.24 2005/01/06 17:59:32 hsu Exp $ */ /* @@ -755,7 +805,7 @@ reply: sin.sin_len = sizeof sin; sin.sin_addr = itaddr; - rt = rtlookup((struct sockaddr *)&sin, 0, 0UL); + rt = rtpurelookup((struct sockaddr *)&sin); if (rt == NULL) { m_freem(m); return; @@ -867,12 +917,15 @@ static struct llinfo_arp * arplookup(in_addr_t addr, boolean_t create, boolean_t proxy) { struct rtentry *rt; - static struct sockaddr_inarp sin = { sizeof sin, AF_INET }; + struct sockaddr_inarp sin = { sizeof sin, AF_INET }; const char *why = NULL; sin.sin_addr.s_addr = addr; sin.sin_other = proxy ? SIN_PROXY : 0; - rt = rtlookup((struct sockaddr *)&sin, create, 0UL); + if (create) + rt = rtlookup((struct sockaddr *)&sin); + else + rt = rtpurelookup((struct sockaddr *)&sin); if (rt == NULL) return (NULL); rt->rt_refcnt--; diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index 8a6bd09e7f..64af73eaf5 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -1,6 +1,6 @@ /* * $FreeBSD: src/sys/netinet/in_gif.c,v 1.5.2.11 2003/01/23 21:06:45 sam Exp $ - * $DragonFly: src/sys/netinet/in_gif.c,v 1.12 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/netinet/in_gif.c,v 1.13 2005/01/06 17:59:32 hsu Exp $ * $KAME: in_gif.c,v 1.54 2001/05/14 14:02:16 itojun Exp $ */ /* @@ -331,7 +331,7 @@ gif_validate4(const struct ip *ip, struct gif_softc *sc, struct ifnet *ifp) sin.sin_family = AF_INET; sin.sin_len = sizeof(struct sockaddr_in); sin.sin_addr = ip->ip_src; - rt = rtlookup((struct sockaddr *)&sin, 0, 0UL); + rt = rtpurelookup((struct sockaddr *)&sin); if (!rt || rt->rt_ifp != ifp) { #if 0 log(LOG_WARNING, "%s: packet from 0x%x dropped " diff --git a/sys/netinet/in_hostcache.c b/sys/netinet/in_hostcache.c index 8fb7dbf87a..f4005ea220 100644 --- a/sys/netinet/in_hostcache.c +++ b/sys/netinet/in_hostcache.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/in_hostcache.c,v 1.3 1999/08/28 00:49:16 peter Exp $ - * $DragonFly: src/sys/netinet/Attic/in_hostcache.c,v 1.4 2004/12/21 02:54:15 hsu Exp $ + * $DragonFly: src/sys/netinet/Attic/in_hostcache.c,v 1.5 2005/01/06 17:59:32 hsu Exp $ */ #include @@ -75,7 +75,7 @@ inhc_alloc(struct sockaddr_in *sin) if (inhc != 0) return inhc; - rt = rtlookup(inhc->inhc_hc.hc_host, 1, 0); + rt = rtlookup(inhc->inhc_hc.hc_host); if (rt == 0) return 0; diff --git a/sys/netinet/in_rmx.c b/sys/netinet/in_rmx.c index 63594a96a9..685226cf39 100644 --- a/sys/netinet/in_rmx.c +++ b/sys/netinet/in_rmx.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/in_rmx.c,v 1.37.2.3 2002/08/09 14:49:23 ru Exp $ - * $DragonFly: src/sys/netinet/in_rmx.c,v 1.8 2005/01/01 09:20:05 hsu Exp $ + * $DragonFly: src/sys/netinet/in_rmx.c,v 1.9 2005/01/06 17:59:32 hsu Exp $ */ /* @@ -120,8 +120,7 @@ in_addroute(char *key, char *mask, struct radix_node_head *head, * Find out if it is because of an * ARP entry and delete it if so. */ - rt2 = rtlookup((struct sockaddr *)sin, 0, - RTF_CLONING | RTF_PRCLONING); + rt2 = rtpurelookup((struct sockaddr *)sin); if (rt2) { --rt->rt_refcnt; if (rt2->rt_flags & RTF_LLINFO && diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index eb1388841a..5883807d59 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -32,7 +32,7 @@ * * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94 * $FreeBSD: src/sys/netinet/ip_icmp.c,v 1.39.2.19 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/ip_icmp.c,v 1.18 2005/01/06 09:14:13 hsu Exp $ + * $DragonFly: src/sys/netinet/ip_icmp.c,v 1.19 2005/01/06 17:59:32 hsu Exp $ */ #include "opt_ipsec.h" @@ -422,8 +422,7 @@ icmp_input(struct mbuf *m, ...) struct rtentry *rt; int mtu; - rt = rtlookup((struct sockaddr *)&icmpsrc, 0, - RTF_CLONING | RTF_PRCLONING); + rt = rtpurelookup((struct sockaddr *)&icmpsrc); if (rt != NULL && (rt->rt_flags & RTF_HOST) && !(rt->rt_rmx.rmx_locks & RTV_MTU)) { mtu = ntohs(icp->icmp_nextmtu); diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 7ec4653577..dd7bc3e111 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/icmp6.c,v 1.6.2.13 2003/05/06 06:46:58 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/icmp6.c,v 1.15 2005/01/06 09:14:13 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/icmp6.c,v 1.16 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: icmp6.c,v 1.211 2001/04/04 05:56:20 itojun Exp $ */ /* @@ -1140,7 +1140,7 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated) htons(m->m_pkthdr.rcvif->if_index); } /* sin6.sin6_scope_id = XXX: should be set if DST is a scoped addr */ - rt = rtlookup((struct sockaddr *)&sin6, 0, RTF_CLONING | RTF_PRCLONING); + rt = rtpurelookup((struct sockaddr *)&sin6); if (rt != NULL && (rt->rt_flags & RTF_HOST) && !(rt->rt_rmx.rmx_locks & RTV_MTU)) { @@ -2254,7 +2254,7 @@ icmp6_redirect_input(struct mbuf *m, int off) sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(struct sockaddr_in6); bcopy(&reddst6, &sin6.sin6_addr, sizeof reddst6); - rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); + rt = rtpurelookup((struct sockaddr *)&sin6); if (rt != NULL) { if (rt->rt_gateway == NULL || rt->rt_gateway->sa_family != AF_INET6) { diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index a76654fd2c..7a8d505df4 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6.c,v 1.7.2.9 2002/04/28 05:40:26 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6.c,v 1.11 2005/01/06 09:14:13 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6.c,v 1.12 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: in6.c,v 1.259 2002/01/21 11:37:50 keiichi Exp $ */ /* @@ -223,7 +223,7 @@ in6_ifaddloop(struct ifaddr *ifa) struct rtentry *rt; /* If there is no loopback entry, allocate one. */ - rt = rtlookup(ifa->ifa_addr, 0, 0); + rt = rtpurelookup(ifa->ifa_addr); if (rt == NULL || !(rt->rt_flags & RTF_HOST) || !(rt->rt_ifp->if_flags & IFF_LOOPBACK)) in6_ifloop_request(RTM_ADD, ifa); @@ -275,7 +275,7 @@ in6_ifremloop(struct ifaddr *ifa) * a subnet-router anycast address on an interface attahced * to a shared medium. */ - rt = rtlookup(ifa->ifa_addr, 0, 0); + rt = rtpurelookup(ifa->ifa_addr); if (rt != NULL && (rt->rt_flags & RTF_HOST) && (rt->rt_ifp->if_flags & IFF_LOOPBACK)) { rt->rt_refcnt--; diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c index 69ccc16023..369d1e5d12 100644 --- a/sys/netinet6/in6_gif.c +++ b/sys/netinet6/in6_gif.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_gif.c,v 1.2.2.7 2003/01/23 21:06:47 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_gif.c,v 1.10 2005/01/06 09:14:13 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_gif.c,v 1.11 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: in6_gif.c,v 1.49 2001/05/14 14:02:17 itojun Exp $ */ /* @@ -327,7 +327,7 @@ gif_validate6(const struct ip6_hdr *ip6, struct gif_softc *sc, sin6.sin6_scope_id = 0; /* XXX */ #endif - rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); + rt = rtpurelookup((struct sockaddr *)&sin6); if (rt == NULL || rt->rt_ifp != ifp) { #if 0 log(LOG_WARNING, "%s: packet from %s dropped " diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index 4fe2900148..c05a59533a 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_ifattach.c,v 1.2.2.6 2002/04/28 05:40:26 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_ifattach.c,v 1.10 2005/01/06 09:14:13 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_ifattach.c,v 1.11 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: in6_ifattach.c,v 1.118 2001/05/24 07:44:00 itojun Exp $ */ /* @@ -894,7 +894,7 @@ in6_ifdetach(struct ifnet *ifp) /* remove from the routing table */ if ((ia->ia_flags & IFA_ROUTE) && - (rt = rtlookup((struct sockaddr *)&ia->ia_addr, 0, 0UL))) { + (rt = rtpurelookup((struct sockaddr *)&ia->ia_addr))) { rtflags = rt->rt_flags; --rt->rt_refcnt; rtrequest(RTM_DELETE, @@ -954,7 +954,7 @@ in6_ifdetach(struct ifnet *ifp) sin6.sin6_family = AF_INET6; sin6.sin6_addr = in6addr_linklocal_allnodes; sin6.sin6_addr.s6_addr16[1] = htons(ifp->if_index); - rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); + rt = rtpurelookup((struct sockaddr *)&sin6); if (rt != NULL && rt->rt_ifp == ifp) { --rt->rt_refcnt; rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt), diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index d0b4f06930..9cfe78c0e5 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_pcb.c,v 1.10.2.9 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_pcb.c,v 1.20 2004/12/28 19:55:16 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_pcb.c,v 1.21 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: in6_pcb.c,v 1.31 2001/05/21 05:45:10 jinmei Exp $ */ /* @@ -526,8 +526,8 @@ in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, dst6->sin6_len = sizeof(struct sockaddr_in6); dst6->sin6_addr = *dst; if (IN6_IS_ADDR_MULTICAST(dst)) { - ro->ro_rt = rtlookup( - (struct sockaddr *)&ro->ro_dst, 0, 0UL); + ro->ro_rt = + rtpurelookup((struct sockaddr *)&ro->ro_dst); } else { rtalloc((struct route *)ro); } diff --git a/sys/netinet6/in6_rmx.c b/sys/netinet6/in6_rmx.c index 04517bb15c..b0adf002e3 100644 --- a/sys/netinet6/in6_rmx.c +++ b/sys/netinet6/in6_rmx.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_rmx.c,v 1.1.2.4 2004/10/06 02:35:17 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_rmx.c,v 1.10 2005/01/06 09:14:13 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_rmx.c,v 1.11 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: in6_rmx.c,v 1.11 2001/07/26 06:53:16 jinmei Exp $ */ /* @@ -163,8 +163,7 @@ in6_addroute(char *key, char *mask, struct radix_node_head *head, * Find out if it is because of an * ARP entry and delete it if so. */ - rt2 = rtlookup((struct sockaddr *)sin6, 0, - RTF_CLONING | RTF_PRCLONING); + rt2 = rtpurelookup((struct sockaddr *)sin6); if (rt2 != NULL) { --rt2->rt_refcnt; if (rt2->rt_flags & RTF_LLINFO && @@ -192,8 +191,7 @@ in6_addroute(char *key, char *mask, struct radix_node_head *head, * net route entry, 3ffe:0501:: -> if0. * This case should not raise an error. */ - rt2 = rtlookup((struct sockaddr *)sin6, 0, - RTF_CLONING | RTF_PRCLONING); + rt2 = rtpurelookup((struct sockaddr *)sin6); if (rt2 != NULL) { if ((rt2->rt_flags & (RTF_CLONING|RTF_HOST|RTF_GATEWAY)) == RTF_CLONING && diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 32b02a7d1d..914a03364c 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_src.c,v 1.1.2.3 2002/02/26 18:02:06 ume Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_src.c,v 1.8 2004/12/21 02:54:47 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_src.c,v 1.9 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: in6_src.c,v 1.37 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -254,8 +254,8 @@ in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, sa6->sin6_addr = *dst; sa6->sin6_scope_id = dstsock->sin6_scope_id; if (IN6_IS_ADDR_MULTICAST(dst)) { - ro->ro_rt = rtlookup( - (struct sockaddr *)&ro->ro_dst, 0, 0UL); + ro->ro_rt = + rtpurelookup((struct sockaddr *)&ro->ro_dst); } else { rtalloc((struct route *)ro); } diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index fbf4d412ff..d1eb409052 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/ip6_output.c,v 1.13.2.18 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/ip6_output.c,v 1.15 2004/12/21 02:54:47 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/ip6_output.c,v 1.16 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: ip6_output.c,v 1.279 2002/01/26 06:12:30 jinmei Exp $ */ /* @@ -687,8 +687,8 @@ skip_ipsec2:; */ if (ifp == NULL) { if (ro->ro_rt == NULL) { - ro->ro_rt = rtlookup( - (struct sockaddr *)&ro->ro_dst, 0, 0UL); + ro->ro_rt = + rtpurelookup((struct sockaddr *)&ro->ro_dst); } if (ro->ro_rt == NULL) { ip6stat.ip6s_noroute++; diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 01db98bbd1..42aa8fa98e 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/nd6.c,v 1.2.2.15 2003/05/06 06:46:58 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/nd6.c,v 1.13 2004/12/30 02:26:12 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/nd6.c,v 1.14 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: nd6.c,v 1.144 2001/05/24 07:44:00 itojun Exp $ */ /* @@ -794,7 +794,10 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp) #ifdef SCOPEDROUTING sin6.sin6_scope_id = in6_addr2scopeid(ifp, addr6); #endif - rt = rtlookup((struct sockaddr *)&sin6, create, 0UL); + if (create) + rt = rtlookup((struct sockaddr *)&sin6); + else + rt = rtpurelookup((struct sockaddr *)&sin6); if (rt && !(rt->rt_flags & RTF_LLINFO)) { /* * This is the case for the default route. @@ -1851,8 +1854,7 @@ nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, */ if (rt) { if (!(rt->rt_flags & RTF_UP)) { - if ((rt0 = rt = - rtlookup((struct sockaddr *)dst, 1, 0UL))) { + if ((rt0 = rt = rtlookup((struct sockaddr *)dst))) { rt->rt_refcnt--; if (rt->rt_ifp != ifp) { /* XXX: loop care? */ @@ -1891,8 +1893,7 @@ nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, goto lookup; if (!(rt->rt_gwroute->rt_flags & RTF_UP)) { rtfree(rt->rt_gwroute); -lookup: rt->rt_gwroute = rtlookup(rt->rt_gateway, 1, - 0UL); +lookup: rt->rt_gwroute = rtlookup(rt->rt_gateway); if (rt->rt_gwroute == NULL) senderr(EHOSTUNREACH); } diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index 3fce1d2e6f..9c0f0bc92c 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/nd6_nbr.c,v 1.4.2.6 2003/01/23 21:06:47 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/nd6_nbr.c,v 1.8 2005/01/06 09:14:13 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/nd6_nbr.c,v 1.9 2005/01/06 17:59:32 hsu Exp $ */ /* $KAME: nd6_nbr.c,v 1.86 2002/01/21 02:33:04 jinmei Exp $ */ /* @@ -212,7 +212,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) tsin6.sin6_family = AF_INET6; tsin6.sin6_addr = taddr6; - rt = rtlookup((struct sockaddr *)&tsin6, 0, 0); + rt = rtpurelookup((struct sockaddr *)&tsin6); if (rt != NULL && (rt->rt_flags & RTF_ANNOUNCE) && rt->rt_gateway->sa_family == AF_LINK) { /* -- 2.41.0