1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-15 15:06:42 +00:00

Reduce code duplication. This adds the function rt_check() to route.c.

Approved by:	 sam (in principle)
This commit is contained in:
Matthew N. Dodd 2003-03-02 21:34:37 +00:00
parent 04b603e5a2
commit 7f760c4890
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=111767
7 changed files with 71 additions and 116 deletions

View File

@ -121,28 +121,9 @@ arc_output(ifp, m, dst, rt0)
error = 0;
ac = (struct arccom *)ifp;
if ((rt = rt0)) {
if ((rt->rt_flags & RTF_UP) == 0) {
if ((rt0 = rt = rtalloc1(dst, 1, 0UL)))
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_check(&rt, &rt0, dst);
if (error)
goto bad;
switch (dst->sa_family) {
#ifdef INET

View File

@ -117,29 +117,9 @@ atm_output(ifp, m0, dst, rt0)
/*
* check route
*/
if ((rt = rt0) != NULL) {
if ((rt->rt_flags & RTF_UP) == 0) { /* route went down! */
if ((rt0 = rt = RTALLOC1(dst, 0)) != NULL)
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, 0);
if ((rt = rt->rt_gwroute) == 0)
senderr(EHOSTUNREACH);
}
}
/* XXX: put RTF_REJECT code here if doing ATMARP */
}
error = rt_check(&rt, &rt0, dst);
if (error)
goto bad;
/*
* check for non-native ATM traffic (dst != NULL)

View File

@ -163,31 +163,11 @@ ether_output(ifp, m, dst, rt0)
senderr(ENETDOWN);
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_check(&rt, &rt0, dst);
if (error)
goto bad;
hlen = ETHER_HDR_LEN;
switch (dst->sa_family) {
#ifdef INET

View File

@ -136,28 +136,11 @@ fddi_output(ifp, m, dst, rt0)
if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
senderr(ENETDOWN);
getmicrotime(&ifp->if_lastchange);
if ((rt = rt0) != NULL) {
if ((rt->rt_flags & RTF_UP) == 0) {
if ((rt0 = rt = rtalloc1(dst, 1, 0UL)) != NULL)
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_check(&rt, &rt0, dst);
if (error)
goto bad;
switch (dst->sa_family) {
#ifdef INET

View File

@ -225,30 +225,9 @@ iso88025_output(ifp, m, dst, rt0)
senderr(ENETDOWN);
getmicrotime(&ifp->if_lastchange);
rt = rt0;
if (rt != NULL) {
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_check(&rt, &rt0, dst);
if (error) {
goto bad;
}
/* Calculate routing info length based on arp table entry */

View File

@ -1131,5 +1131,56 @@ rtinit(ifa, cmd, flags)
return (error);
}
int
rt_check(lrt, lrt0, dst)
struct rtentry **lrt;
struct rtentry **lrt0;
struct sockaddr *dst;
{
struct rtentry *rt;
struct rtentry *rt0;
int error;
rt = *lrt;
rt0 = *lrt0;
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:
*lrt = rt;
*lrt0 = rt0;
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);

View File

@ -296,6 +296,7 @@ void rtredirect(struct sockaddr *, struct sockaddr *,
int rtrequest(int, struct sockaddr *,
struct sockaddr *, struct sockaddr *, int, struct rtentry **);
int rtrequest1(int, struct rt_addrinfo *, struct rtentry **);
int rt_check(struct rtentry **, struct rtentry **, struct sockaddr *);
#endif
#endif