* Copyright (c) 1982, 1986, 1988 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)if_imphost.c 7.10 (Berkeley) 6/28/90
* 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"
extern struct imp_softc imp_softc
[];
* Given an internet address
* return a host structure (if it exists).
hostlookup(imp
, host
, unit
)
register struct host
*hp
;
register int hash
= HOSTHASH(imp
, host
);
for (m
= imp_softc
[unit
].imp_hosts
; m
; m
= m
->m_next
) {
hp
= &mtod(m
, struct hmbuf
*)->hm_hosts
[hash
];
if (hp
->h_imp
== imp
&& hp
->h_host
== host
) {
if ((hp
->h_flags
& HF_INUSE
) == 0)
mtod(dtom(hp
), struct hmbuf
*)->hm_count
++;
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.
hostenter(imp
, host
, unit
)
register struct mbuf
*m
, **mprev
;
register struct host
*hp
, *hp0
= 0;
register int hash
= HOSTHASH(imp
, host
);
mprev
= &imp_softc
[unit
].imp_hosts
;
hp
= &mtod(m
, struct hmbuf
*)->hm_hosts
[hash
];
if (hp
->h_imp
== imp
&& hp
->h_host
== host
) {
if ((hp
->h_flags
& HF_INUSE
) == 0)
mtod(dtom(hp
), struct hmbuf
*)->hm_count
++;
if ((hp
->h_flags
& HF_INUSE
) == 0) {
* 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(hp
), struct hmbuf
*)->hm_count
++;
* Reset a given imp unit's host entries.
* Must be called at splimp.
register struct host
*hp
, *lp
;
for (m
= imp_softc
[unit
].imp_hosts
; m
; m
= m
->m_next
) {
hm
= mtod(m
, struct hmbuf
*);
while (hm
->hm_count
> 0 && hp
< lp
) {
* Remove a host structure and release
* any resources it's accumulated.
register struct host
*hp
;
if (hp
->h_flags
& HF_INUSE
)
--mtod(dtom(hp
), struct hmbuf
*)->hm_count
;
* Flush the message queue for a host.
register struct host
*hp
;
* Discard any packets left on the waiting q
* Release mbufs in host table that contain no entries
* currently in use. Must be called at splimp.
register struct mbuf
*m
, **mprev
;
struct imp_softc
*sc
= &imp_softc
[unit
];
if (mtod(m
, struct hmbuf
*)->hm_count
== 0)
* 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
;
int s
= splimp(), unit
, any
;
for (unit
= 0; unit
< NIMP
; unit
++) {
for (m
= sc
->imp_hosts
; m
; m
= m
->m_next
) {
hm
= mtod(m
, struct hmbuf
*);
for (; hm
->hm_count
> 0 && hp
< lp
; hp
++) {
if (hp
->h_timer
&& --hp
->h_timer
== 0) {
"imp%d: host %d/imp %d, lost rfnm\n",
unit
, hp
->h_host
, ntohs(hp
->h_imp
));