/* if_imphost.c 4.18 83/02/23 */
* Host table manipulation routines.
* Only needed when shipping stuff through an IMP.
* Everything in here is called at splimp from
* from the IMP protocol code (if_imp.c), or
* interlocks with the code at splimp.
#include "../netinet/in.h"
#include "../netinet/in_systm.h"
#include "../netimp/if_imp.h"
#include "../netimp/if_imphost.h"
* Head of host table hash chains.
* Given an internet address
* return a host structure (if it exists).
register struct host
*hp
;
register int hash
= HOSTHASH(addr
);
for (m
= hosts
; m
; m
= m
->m_next
) {
hp
= &mtod(m
, struct hmbuf
*)->hm_hosts
[hash
];
if (hp
->h_addr
.s_addr
== addr
.s_addr
) {
return ((struct host
*)0);
* Enter a reference to this host's internet
* address. If no host structure exists, create
* one and hook it into the host database.
register struct mbuf
*m
, **mprev
;
register struct host
*hp
, *hp0
= 0;
register int hash
= HOSTHASH(addr
);
hp
= &mtod(m
, struct hmbuf
*)->hm_hosts
[hash
];
if ((hp
->h_flags
& HF_INUSE
) == 0) {
if (hp
->h_addr
.s_addr
== addr
.s_addr
)
if (hp
->h_addr
.s_addr
== addr
.s_addr
)
* No current host structure, make one.
* If our search ran off the end of the
* chain of mbuf's, allocate another.
m
= m_getclr(M_DONTWAIT
, MT_HTABLE
);
return ((struct host
*)0);
hp0
= &mtod(m
, struct hmbuf
*)->hm_hosts
[hash
];
mtod(dtom(hp0
), struct hmbuf
*)->hm_count
++;
* Mark a host structure free and set it's
register struct host
*hp
;
hp
->h_flags
&= ~HF_INUSE
;
* Reset a given network's host entries.
register struct host
*hp
, *lp
;
for (m
= hosts
; m
; m
= m
->m_next
) {
hm
= mtod(m
, struct hmbuf
*);
while (hm
->hm_count
> 0 && hp
< lp
) {
if (hp
->h_addr
.s_net
== net
) {
hp
->h_flags
&= ~HF_INUSE
;
* Remove a host structure and release
* any resources it's accumulated.
register struct host
*hp
;
register struct mbuf
*m
, **mprev
, *mh
= dtom(hp
);
* Discard any packets left on the waiting q
if (--mtod(mh
, struct hmbuf
*)->hm_count
)
while ((m
= *mprev
) != mh
)
* Remove a packet from the holding q.
* The RFNM counter is also bumped.
register struct host
*hp
;
* Host data base timer routine.
* Decrement timers on structures which are
* waiting to be deallocated. On expiration
* release resources, possibly deallocating
* mbuf associated with structure.
register struct host
*hp
, *lp
;
for (m
= hosts
; m
; m
= m
->m_next
) {
hm
= mtod(m
, struct hmbuf
*);
for (; hm
->hm_count
> 0 && hp
< lp
; hp
++) {
if (hp
->h_flags
& HF_INUSE
)
if (hp
->h_timer
&& --hp
->h_timer
== 0)