projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
time now a structure
[unix-history]
/
usr
/
src
/
sys
/
net
/
route.c
diff --git
a/usr/src/sys/net/route.c
b/usr/src/sys/net/route.c
index
5d455b0
..
ea73e40
100644
(file)
--- a/
usr/src/sys/net/route.c
+++ b/
usr/src/sys/net/route.c
@@
-1,4
+1,4
@@
-/* route.c 4.
9 82/06/06
*/
+/* route.c 4.
11 82/06/20
*/
#include "../h/param.h"
#include "../h/systm.h"
#include "../h/param.h"
#include "../h/systm.h"
@@
-13,10
+13,10
@@
#include "../net/route.h"
#include <errno.h>
#include "../net/route.h"
#include <errno.h>
+int rttrash; /* routes not in table but not freed */
/*
* Packet routing routines.
*/
/*
* Packet routing routines.
*/
-
rtalloc(ro)
register struct route *ro;
{
rtalloc(ro)
register struct route *ro;
{
@@
-27,7
+27,6
@@
rtalloc(ro)
struct sockaddr *dst = &ro->ro_dst;
int af = dst->sa_family;
struct sockaddr *dst = &ro->ro_dst;
int af = dst->sa_family;
-COUNT(RTALLOC);
if (ro->ro_rt && ro->ro_rt->rt_ifp) /* XXX */
return;
if (af >= AF_MAX)
if (ro->ro_rt && ro->ro_rt->rt_ifp) /* XXX */
return;
if (af >= AF_MAX)
@@
-72,38
+71,37
@@
found:
rtfree(rt)
register struct rtentry *rt;
{
rtfree(rt)
register struct rtentry *rt;
{
+ register struct mbuf **mp;
if (rt == 0)
panic("freeroute");
rt->rt_refcnt--;
if (rt == 0)
panic("freeroute");
rt->rt_refcnt--;
- /* on refcnt == 0 reclaim? notify someone? */
+ if (rt->rt_refcnt == 0 && (rt->rt_flags&RTF_UP) == 0) {
+ rttrash--;
+ (void) m_free(dtom(rt));
+ }
}
}
-#define equal(a1, a2) \
- (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
/*
* Carry out a request to change the routing table. Called by
* interfaces at boot time to make their ``local routes'' known
* and for ioctl's.
*/
/*
* Carry out a request to change the routing table. Called by
* interfaces at boot time to make their ``local routes'' known
* and for ioctl's.
*/
-rtrequest(req,
new
)
+rtrequest(req,
entry
)
int req;
int req;
-
struct rtentry *new
;
+
register struct rtentry *entry
;
{
{
- register struct rtentry *rt;
register struct mbuf *m, **mprev;
register struct mbuf *m, **mprev;
- register struct sockaddr *sa = &new->rt_dst;
- register struct sockaddr *gate = &new->rt_gateway;
+ register struct rtentry *rt;
struct afhash h;
struct afhash h;
- int af
= sa->sa_family, doinghost, s, error = 0
;
-
int hash, (*match)()
;
+ int af
, s, error = 0, hash, (*match)()
;
+
struct ifnet *ifp
;
-
COUNT(RTREQUEST)
;
+
af = entry->rt_dst.sa_family
;
if (af >= AF_MAX)
return (EAFNOSUPPORT);
if (af >= AF_MAX)
return (EAFNOSUPPORT);
- (*afswitch[af].af_hash)(sa, &h);
- doinghost = new->rt_flags & RTF_HOST;
- if (doinghost) {
+ (*afswitch[af].af_hash)(&entry->rt_dst, &h);
+ if (entry->rt_flags & RTF_HOST) {
hash = h.afh_hosthash;
mprev = &rthost[hash % RTHASHSIZ];
} else {
hash = h.afh_hosthash;
mprev = &rthost[hash % RTHASHSIZ];
} else {
@@
-116,15
+114,17
@@
COUNT(RTREQUEST);
rt = mtod(m, struct rtentry *);
if (rt->rt_hash != hash)
continue;
rt = mtod(m, struct rtentry *);
if (rt->rt_hash != hash)
continue;
- if (doinghost) {
- if (!equal(&rt->rt_dst, sa))
+ if (entry->rt_flags & RTF_HOST) {
+#define equal(a1, a2) \
+ (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
+ if (!equal(&rt->rt_dst, &entry->rt_dst))
continue;
} else {
continue;
} else {
- if (rt->rt_dst.sa_family !=
sa->
sa_family ||
- (*match)(&rt->rt_dst,
sa
) == 0)
+ if (rt->rt_dst.sa_family !=
entry->rt_dst.
sa_family ||
+ (*match)(&rt->rt_dst,
&entry->rt_dst
) == 0)
continue;
}
continue;
}
- if (equal(&rt->rt_gateway,
gate
))
+ if (equal(&rt->rt_gateway,
&entry->rt_gateway
))
break;
}
switch (req) {
break;
}
switch (req) {
@@
-134,49
+134,45
@@
COUNT(RTREQUEST);
error = ESRCH;
goto bad;
}
error = ESRCH;
goto bad;
}
- rt->rt_flags &= ~RTF_UP;
- if (rt->rt_refcnt > 0) /* should we notify protocols? */
- error = EBUSY;
- else
- *mprev = m_free(m);
- break;
-
- case SIOCCHGRT:
- if (m == 0) {
- error = ESRCH;
- goto bad;
- }
- rt->rt_flags = new->rt_flags;
+ *mprev = m->m_next;
if (rt->rt_refcnt > 0) {
if (rt->rt_refcnt > 0) {
-
error = EBUSY
;
-
goto bad
;
- }
- if (!equal(&rt->rt_gateway, gate))
-
goto changerouter
;
+
rt->rt_flags &= ~RTF_UP
;
+
rttrash++
;
+ m->m_next = 0;
+ } else
+
(void) m_free(m)
;
break;
case SIOCADDRT:
break;
case SIOCADDRT:
- if (m
!= 0
) {
+ if (m) {
error = EEXIST;
goto bad;
}
error = EEXIST;
goto bad;
}
+ ifp = if_ifwithaddr(&entry->rt_gateway);
+ if (ifp == 0) {
+ ifp = if_ifwithnet(&entry->rt_gateway);
+ if (ifp == 0) {
+ error = ENETUNREACH;
+ goto bad;
+ }
+ }
m = m_get(M_DONTWAIT);
if (m == 0) {
error = ENOBUFS;
goto bad;
}
m = m_get(M_DONTWAIT);
if (m == 0) {
error = ENOBUFS;
goto bad;
}
+ *mprev = m;
m->m_off = MMINOFF;
m->m_len = sizeof (struct rtentry);
rt = mtod(m, struct rtentry *);
m->m_off = MMINOFF;
m->m_len = sizeof (struct rtentry);
rt = mtod(m, struct rtentry *);
- *rt = *new;
rt->rt_hash = hash;
rt->rt_hash = hash;
- *mprev = m;
- rt->rt_use = 0;
+ rt->rt_dst = entry->rt_dst;
+ rt->rt_gateway = entry->rt_gateway;
+ rt->rt_flags =
+ RTF_UP | (entry->rt_flags & (RTF_HOST|RTF_GATEWAY));
rt->rt_refcnt = 0;
rt->rt_refcnt = 0;
-changerouter:
- rt->rt_ifp = if_ifwithnet(gate);
- if (rt->rt_ifp == 0)
- rt->rt_flags &= ~RTF_UP;
+ rt->rt_use = 0;
+ rt->rt_ifp = ifp;
break;
}
bad:
break;
}
bad:
@@
-195,12
+191,9
@@
rtinit(dst, gateway, flags)
struct rtentry route;
struct route ro;
struct rtentry route;
struct route ro;
+ bzero((caddr_t)&route, sizeof (route));
route.rt_dst = *dst;
route.rt_gateway = *gateway;
route.rt_flags = flags;
route.rt_dst = *dst;
route.rt_gateway = *gateway;
route.rt_flags = flags;
- route.rt_use = 0;
(void) rtrequest(SIOCADDRT, &route);
(void) rtrequest(SIOCADDRT, &route);
- ro.ro_rt = 0;
- ro.ro_dst = *dst;
- rtalloc(&ro);
}
}