Date: Thu, 4 Oct 2001 06:57:12 -0400 (EDT) From: "Matthew N. Dodd" <winter@jurai.net> To: freebsd-net@freebsd.org Subject: review request: new function sys/net/route.c:rt_resolv() Message-ID: <Pine.BSF.4.21.0110040651200.38937-200000@sasami.jurai.net>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] Find attached for your review a patch implementing the rt_resolv() (better name requested if you can think of one.) function. This is intended to replace the ~25 lines of duplicated code currently in if_ethersubr.c, if_fddisubr.c, and if_iso88025subr.c in the respective output functions. Only the modification to if_ethersubr.c is included in this patch as I've got local changes to the other files that aren't relevant and most people aren't likely to have FDDI or Token Ring stuff they want to test this on anyway. It appears to work for me though I'm sure I've missed something obvious. Comments? -- | Matthew N. Dodd | '78 Datsun 280Z | '75 Volvo 164E | FreeBSD/NetBSD | | winter@jurai.net | 2 x '84 Volvo 245DL | ix86,sparc,pmax | | http://www.jurai.net/~winter | For Great Justice! | ISO8802.5 4ever | [-- Attachment #2 --] Index: route.c =================================================================== RCS file: /cvs/src/sys/net/route.c,v retrieving revision 1.64 diff -u -r1.64 route.c --- route.c 25 Jul 2001 20:15:28 -0000 1.64 +++ route.c 4 Oct 2001 10:49:14 -0000 @@ -1094,5 +1094,49 @@ return (error); } +int +rt_resolv(rt, rt0, dst) + struct rtentry **rt; + struct rtentry **rt0; + struct sockaddr *dst; +{ + int error; + + error = 0; + *rt = *rt0; + + if (*rt != NULL) { + if (((*rt)->rt_flags & RTF_UP) == 0) { + *rt0 = *rt = rtalloc1(dst, 1, 0UL); + if (*rt0 != NULL) + (*rt)->rt_refcnt--; + else + senderr(EHOSTUNREACH); + } + if ((*rt)->rt_flags & RTF_GATEWAY) { + if ((*rt)->rt_gwroute == NULL) + goto lookup; + + *rt = (*rt)->rt_gwroute; + if (((*rt)->rt_flags & RTF_UP) == 0) { + rtfree(*rt); + *rt = *rt0; + lookup: + (*rt)->rt_gwroute = rtalloc1((*rt)->rt_gateway, 1, 0UL); + *rt = (*rt)->rt_gwroute; + if (*rt == NULL) + senderr(EHOSTUNREACH); + } + } + if ((*rt)->rt_flags & RTF_REJECT) + if ((*rt)->rt_rmx.rmx_expire == 0 || + time_second < (*rt)->rt_rmx.rmx_expire) + senderr(*rt == *rt0 ? EHOSTDOWN : EHOSTUNREACH); + } + +bad: + return (error); +} + /* This must be before ip6_init2(), which is now SI_ORDER_MIDDLE */ SYSINIT(route, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, route_init, 0); Index: route.h =================================================================== RCS file: /cvs/src/sys/net/route.h,v retrieving revision 1.39 diff -u -r1.39 route.h --- route.h 12 Sep 2001 08:37:52 -0000 1.39 +++ route.h 4 Oct 2001 10:48:47 -0000 @@ -290,6 +290,8 @@ struct sockaddr *, int, struct sockaddr *, struct rtentry **)); int rtrequest __P((int, struct sockaddr *, struct sockaddr *, struct sockaddr *, int, struct rtentry **)); + +int rt_resolv __P((struct rtentry **, struct rtentry **, struct sockaddr *)); #endif #endif Index: if_ethersubr.c =================================================================== RCS file: /cvs/src/sys/net/if_ethersubr.c,v retrieving revision 1.97 diff -u -r1.97 if_ethersubr.c --- if_ethersubr.c 10 Sep 2001 01:33:03 -0000 1.97 +++ if_ethersubr.c 4 Oct 2001 10:37:20 -0000 @@ -137,39 +137,19 @@ short type; int error = 0, hdrcmplt = 0; u_char esrc[6], edst[6]; - register struct rtentry *rt; - register struct ether_header *eh; + struct rtentry *rt; + struct ether_header *eh; int off, loop_copy = 0; int hlen; /* link layer header lenght */ struct arpcom *ac = IFP2AC(ifp); if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) senderr(ENETDOWN); - rt = rt0; - if (rt) { - if ((rt->rt_flags & RTF_UP) == 0) { - rt0 = rt = rtalloc1(dst, 1, 0UL); - if (rt0) - rt->rt_refcnt--; - else - senderr(EHOSTUNREACH); - } - if (rt->rt_flags & RTF_GATEWAY) { - if (rt->rt_gwroute == 0) - goto lookup; - if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { - rtfree(rt); rt = rt0; - lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, - 0UL); - if ((rt = rt->rt_gwroute) == 0) - senderr(EHOSTUNREACH); - } - } - if (rt->rt_flags & RTF_REJECT) - if (rt->rt_rmx.rmx_expire == 0 || - time_second < rt->rt_rmx.rmx_expire) - senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); - } + + error = rt_resolv(&rt, &rt0, dst); + if (error) + goto bad; + hlen = ETHER_HDR_LEN; switch (dst->sa_family) { #ifdef INET
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0110040651200.38937-200000>
