m_get inits m_off; remove TCPTRUEOOB
[unix-history] / usr / src / sys / deprecated / netimp / if_imphost.c
CommitLineData
77a4e3ca 1/* if_imphost.c 4.14 82/10/05 */
276c51cf
SL
2
3#include "imp.h"
4#if NIMP > 0
5/*
6 * Host table manipulation routines.
7 * Only needed when shipping stuff through an IMP.
8 */
9
10#include "../h/param.h"
11#include "../h/mbuf.h"
12#include "../net/in.h"
13#include "../net/in_systm.h"
276c51cf 14#include "../net/if_imp.h"
41e530c7 15#include "../net/if_imphost.h"
276c51cf
SL
16
17/*
18 * Head of host table hash chains.
19 */
41e530c7 20struct mbuf *hosts;
276c51cf
SL
21
22/*
23 * Given an internet address
24 * return a host structure (if it exists).
25 */
26struct host *
a2cd4df7 27hostlookup(addr)
276c51cf
SL
28 struct in_addr addr;
29{
30 register struct host *hp;
31 register struct mbuf *m;
32 register int hash = HOSTHASH(addr);
ba45553a 33 int s = splnet();
276c51cf 34
41e530c7 35 for (m = hosts; m; m = m->m_next) {
276c51cf 36 hp = &mtod(m, struct hmbuf *)->hm_hosts[hash];
ba45553a
SL
37 if (hp->h_addr.s_addr == addr.s_addr) {
38 hp->h_flags |= HF_INUSE;
39 goto found;
40 }
276c51cf 41 }
ba45553a
SL
42 hp = 0;
43found:
44 splx(s);
45 return (hp);
276c51cf
SL
46}
47
48/*
49 * Enter a reference to this host's internet
50 * address. If no host structure exists, create
51 * one and hook it into the host database.
52 */
53struct host *
a2cd4df7 54hostenter(addr)
276c51cf
SL
55 struct in_addr addr;
56{
41e530c7
BJ
57 register struct mbuf *m, **mprev;
58 register struct host *hp, *hp0 = 0;
276c51cf 59 register int hash = HOSTHASH(addr);
ba45553a 60 int s = splnet();
276c51cf 61
41e530c7
BJ
62 mprev = &hosts;
63 while (m = *mprev) {
1e977657 64 mprev = &m->m_next;
276c51cf 65 hp = &mtod(m, struct hmbuf *)->hm_hosts[hash];
ba45553a
SL
66 if ((hp->h_flags & HF_INUSE) == 0) {
67 if (hp->h_addr.s_addr == addr.s_addr)
68 goto foundhost;
41e530c7
BJ
69 if (hp0 == 0)
70 hp0 = hp;
71 continue;
72 }
276c51cf
SL
73 if (hp->h_addr.s_addr == addr.s_addr)
74 goto foundhost;
75 }
76
77 /*
78 * No current host structure, make one.
79 * If our search ran off the end of the
80 * chain of mbuf's, allocate another.
81 */
41e530c7 82 if (hp0 == 0) {
276c51cf 83 m = m_getclr(M_DONTWAIT);
ba45553a
SL
84 if (m == 0) {
85 splx(s);
276c51cf 86 return (0);
ba45553a 87 }
41e530c7 88 *mprev = m;
41e530c7 89 hp0 = &mtod(m, struct hmbuf *)->hm_hosts[hash];
276c51cf 90 }
41e530c7
BJ
91 mtod(dtom(hp0), struct hmbuf *)->hm_count++;
92 hp = hp0;
276c51cf 93 hp->h_addr = addr;
ba45553a 94 hp->h_timer = 0;
83969adf 95 hp->h_flags = 0;
276c51cf
SL
96
97foundhost:
ba45553a
SL
98 hp->h_flags |= HF_INUSE;
99 splx(s);
276c51cf
SL
100 return (hp);
101}
102
103/*
ba45553a
SL
104 * Mark a host structure free and set it's
105 * timer going.
276c51cf 106 */
41e530c7
BJ
107hostfree(hp)
108 register struct host *hp;
276c51cf 109{
ba45553a
SL
110 int s = splnet();
111
ba45553a
SL
112 hp->h_flags &= ~HF_INUSE;
113 hp->h_timer = HOSTTIMER;
114 hp->h_rfnm = 0;
115 splx(s);
276c51cf
SL
116}
117
118/*
119 * Reset a given network's host entries.
276c51cf 120 */
a2cd4df7 121hostreset(net)
276c51cf
SL
122 int net;
123{
124 register struct mbuf *m;
125 register struct host *hp, *lp;
41e530c7 126 struct hmbuf *hm;
ba45553a 127 int s = splnet();
276c51cf 128
41e530c7
BJ
129 for (m = hosts; m; m = m->m_next) {
130 hm = mtod(m, struct hmbuf *);
131 hp = hm->hm_hosts;
276c51cf 132 lp = hp + HPMBUF;
ba45553a 133 while (hm->hm_count > 0 && hp < lp) {
c19356d7 134 if (hp->h_addr.s_net == net) {
ba45553a 135 hp->h_flags &= ~HF_INUSE;
8239b605 136 hostrelease(hp);
c19356d7 137 }
276c51cf
SL
138 hp++;
139 }
140 }
ba45553a 141 splx(s);
276c51cf
SL
142}
143
144/*
145 * Remove a host structure and release
146 * any resources it's accumulated.
ba45553a 147 * This routine is always called at splnet.
276c51cf 148 */
41e530c7 149hostrelease(hp)
276c51cf
SL
150 register struct host *hp;
151{
41e530c7 152 register struct mbuf *m, **mprev, *mh = dtom(hp);
276c51cf 153
276c51cf
SL
154 /*
155 * Discard any packets left on the waiting q
156 */
a2cd4df7 157 if (m = hp->h_q) {
654fef96
BJ
158 register struct mbuf *n;
159
160 do {
161 n = m->m_act;
162 m_freem(m);
163 m = n;
164 } while (m != hp->h_q);
a2cd4df7 165 hp->h_q = 0;
276c51cf 166 }
83969adf 167 hp->h_flags = 0;
41e530c7 168 if (--mtod(mh, struct hmbuf *)->hm_count)
276c51cf 169 return;
41e530c7
BJ
170 mprev = &hosts;
171 while ((m = *mprev) != mh)
172 mprev = &m->m_next;
ba45553a 173 *mprev = m_free(mh);
276c51cf 174}
e33b5b1a
BJ
175
176/*
177 * Remove a packet from the holding q.
178 * The RFNM counter is also bumped.
179 */
180struct mbuf *
181hostdeque(hp)
182 register struct host *hp;
183{
184 register struct mbuf *m;
185
186 hp->h_rfnm--;
187 HOST_DEQUE(hp, m);
188 if (m)
189 return (m);
190 if (hp->h_rfnm == 0)
191 hostfree(hp);
192 return (0);
193}
ba45553a
SL
194
195/*
196 * Host data base timer routine.
197 * Decrement timers on structures which are
198 * waiting to be deallocated. On expiration
199 * release resources, possibly deallocating
200 * mbuf associated with structure.
201 */
202hostslowtimo()
203{
204 register struct mbuf *m;
205 register struct host *hp, *lp;
206 struct hmbuf *hm;
207 int s = splnet();
208
ba45553a
SL
209 for (m = hosts; m; m = m->m_next) {
210 hm = mtod(m, struct hmbuf *);
211 hp = hm->hm_hosts;
212 lp = hp + HPMBUF;
eef4963b 213 for (; hm->hm_count > 0 && hp < lp; hp++) {
ba45553a
SL
214 if (hp->h_flags & HF_INUSE)
215 continue;
216 if (hp->h_timer && --hp->h_timer == 0)
217 hostrelease(hp);
ba45553a
SL
218 }
219 }
220 splx(s);
221}