/* route.c 4.1 82/03/27 */
#include "../h/protosw.h"
#include "../h/socketvar.h"
#include "../net/in_systm.h"
#include "../net/route.h"
* Packet routing routines.
* With much ado about nothing...
* route the cars that climb halfway to the stars...
register struct route
*ro
;
register struct rtentry
*rt
, *rtmin
;
struct sockaddr
*dst
= &ro
->ro_dst
;
if (ro
->ro_ifp
) /* ??? */
(*afswitch
[af
].af_hash
)(dst
, &h
);
m
= routehash
[h
.afh_hosthash
% RTHASHSIZ
];
rtmin
= 0, doinghost
= 1;
for (; m
; m
= m
->m_next
) {
rt
= mtod(m
, struct rtentry
*);
(bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof(struct sockaddr)) == 0)
if (!equal(&rt
->rt_dst
, dst
))
if (rt
->rt_dst
.sa_family
!= af
)
if ((*afswitch
[af
].af_netmatch
)(&rt
->rt_dst
, dst
) == 0)
if (rtmin
== 0 || rt
->rt_use
< rtmin
->rt_use
)
m
= routethash
[h
.afh_nethash
% RTHASHSIZ
];
register struct sockaddr
*sa
;
register struct rtentry
*rt
;
(*afswitch
[sa
->sa_family
].af_hash
)(sa
, &h
);
m
= routehash
[h
.afh_hosthash
];
for (; m
; m
= m
->m_next
) {
rt
= mtod(m
, struct rtentry
*);
if (equal(&rt
->rt_gateway
, sa
))
* Routing control calls allow a routing daemon
* to consistenly access the routing data base for updates.
register struct rtreq rq
;
int x
= splimp(), err
= 0;
if (copyin(addr
, (caddr_t
)&rq
, sizeof(struct rtreq
))) {
err
= rtrequest(req
, &rq
);
* Carry out a user request to modify the data base.
register struct rtentry
*new;
register struct rtentry
*rt
;
register struct mbuf
*m
, **mprev
;
struct sockaddr
*sa
= &new->rt_dst
;
(*afswitch
[af
].af_hash
)(sa
, &h
);
mprev
= &routehash
[h
.afh_hosthash
% RTHASHSIZ
];
for (; m
= *mprev
; mprev
= &m
->m_next
) {
rt
= mtod(m
, struct rtentry
*);
if (!equal(&rt
->rt_dst
, dst
))
if (rt
->rt_dst
.sa_family
!= af
)
if ((*afswitch
[af
].af_netmatch
)(&rt
->rt_dst
, sa
) == 0)
if (m
== 0 && doinghost
) {
mprev
= &routehash
[h
.afh_nethash
% RTHASHSIZ
];
if (m
== 0 && req
!= SIOCADDRT
)
if (rt
->rt_refcnt
> 0) /* should we notify protocols? */
rt
->rt_flags
= new->rt_flags
;
if (!equal(&rt
->rt_gateway
, &new->rt_gateway
))
m
= m_getclr(M_DONTWAIT
);
rt
= mtod(m
, struct rtentry
*);
rt
->rt_key
= h
.afh_nethash
| h
.afh_hosthash
;
rt
->rt_ifp
= if_ifonnetof(&new->rt_gateway
);