summaryrefslogtreecommitdiffstats
path: root/sys/net
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2003-03-02 21:34:37 +0000
committermdodd <mdodd@FreeBSD.org>2003-03-02 21:34:37 +0000
commitcd4fafb346eda353b75a3fb1f4ba5b08a8f0e688 (patch)
tree029d8e13f59ab838fe4627ca66354af3d3e0b962 /sys/net
parent0a50041362fa551b46336f0c3c6d0faf524bc2d7 (diff)
downloadFreeBSD-src-cd4fafb346eda353b75a3fb1f4ba5b08a8f0e688.zip
FreeBSD-src-cd4fafb346eda353b75a3fb1f4ba5b08a8f0e688.tar.gz
Reduce code duplication. This adds the function rt_check() to route.c.
Approved by: sam (in principle)
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if_arcsubr.c25
-rw-r--r--sys/net/if_atmsubr.c26
-rw-r--r--sys/net/if_ethersubr.c30
-rw-r--r--sys/net/if_fddisubr.c27
-rw-r--r--sys/net/if_iso88025subr.c27
-rw-r--r--sys/net/route.c51
-rw-r--r--sys/net/route.h1
7 files changed, 71 insertions, 116 deletions
diff --git a/sys/net/if_arcsubr.c b/sys/net/if_arcsubr.c
index 667291d..dda353a 100644
--- a/sys/net/if_arcsubr.c
+++ b/sys/net/if_arcsubr.c
@@ -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
diff --git a/sys/net/if_atmsubr.c b/sys/net/if_atmsubr.c
index 3ec3894..1661a88 100644
--- a/sys/net/if_atmsubr.c
+++ b/sys/net/if_atmsubr.c
@@ -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)
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 0af1114..36a614c 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -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
diff --git a/sys/net/if_fddisubr.c b/sys/net/if_fddisubr.c
index 49a5f21..4fb4bad 100644
--- a/sys/net/if_fddisubr.c
+++ b/sys/net/if_fddisubr.c
@@ -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
diff --git a/sys/net/if_iso88025subr.c b/sys/net/if_iso88025subr.c
index acb1147..cf4ceb75 100644
--- a/sys/net/if_iso88025subr.c
+++ b/sys/net/if_iso88025subr.c
@@ -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 */
diff --git a/sys/net/route.c b/sys/net/route.c
index 7847466..543151f 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1131,5 +1131,56 @@ bad:
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);
diff --git a/sys/net/route.h b/sys/net/route.h
index 8c42b9a..fd14a9c 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -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
OpenPOWER on IntegriCloud