install approved copyright notice
[unix-history] / usr / src / sys / deprecated / netimp / if_imphost.h
CommitLineData
8ae0e4b4 1/*
616d42db 2 * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
b0c21e3a 3 * All rights reserved.
8ae0e4b4 4 *
b0c21e3a 5 * Redistribution and use in source and binary forms are permitted
616d42db
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
b0c21e3a 16 *
616d42db 17 * @(#)if_imphost.h 7.6 (Berkeley) %G%
8ae0e4b4 18 */
81776a4f
SL
19
20/*
21 * Host structure used with IMP's.
22 * Used to hold outgoing packets which
23 * would exceed allowed RFNM count.
24 *
25 * These structures are packed into
26 * mbuf's and kept as small as possible.
27 */
28struct host {
29 struct mbuf *h_q; /* holding queue */
b0c21e3a 30 u_short h_timer; /* used to stay off deletion */
be7e9ce3
MK
31 u_short h_imp; /* host's imp number */
32 u_char h_host; /* host's number on imp */
ba45553a 33 u_char h_qcnt; /* size of holding q */
81776a4f 34 u_char h_rfnm; /* # outstanding rfnm's */
ba45553a 35 u_char h_flags; /* see below */
81776a4f
SL
36};
37
ba45553a
SL
38/*
39 * A host structure is kept around (even when there are no
40 * references to it) for a spell to avoid constant reallocation
41 * and also to reflect IMP status back to sites which aren't
42 * directly connected to the IMP. When structures are marked
2c63532d 43 * idle, a timer is started; when the timer expires the structure
b0c21e3a
MK
44 * is deallocated. A structure may be reused before the timer expires.
45 * A structure holds a reference on the containing mbuf when it is marked
2c63532d 46 * HF_INUSE.
ba45553a
SL
47 */
48#define HF_INUSE 0x1
49#define HF_DEAD (1<<IMPTYPE_HOSTDEAD)
50#define HF_UNREACH (1<<IMPTYPE_HOSTUNREACH)
51
b0c21e3a
MK
52#define HOSTTIMER 128 /* keep structure around awhile */
53
be7e9ce3 54/*
2c63532d
MK
55 * Mark a host structure free; used if host entry returned by hostlookup
56 * isn't needed. h_rfnm must be zero.
be7e9ce3
MK
57 */
58#define hostfree(hp) { \
2c63532d
MK
59 if ((hp)->h_timer == 0 && (hp)->h_qcnt == 0 && \
60 (hp)->h_flags & HF_INUSE) \
61 hostrelease(hp); \
be7e9ce3
MK
62}
63
2c63532d
MK
64/*
65 * Release a host entry when last rfnm is received.
66 */
67#define hostidle(hp) { (hp)->h_timer = HOSTTIMER; }
68
81776a4f
SL
69/*
70 * Host structures, as seen inside an mbuf.
be7e9ce3 71 * Hashing on the host and imp is used to
81776a4f
SL
72 * select an index into the first mbuf. Collisions
73 * are then resolved by searching successive
74 * mbuf's at the same index. Reclamation is done
b0c21e3a 75 * automatically at the time a structure is freed.
81776a4f
SL
76 */
77#define HPMBUF ((MLEN - sizeof(int)) / sizeof(struct host))
2c63532d 78/* don't need to swab as long as HPMBUF is odd */
be7e9ce3 79#if defined(notdef) && BYTE_ORDER == BIG_ENDIAN
2c63532d 80#define HOSTHASH(imp, host) ((unsigned)(ntohs(imp)+(host)) % HPMBUF)
be7e9ce3 81#else
2c63532d 82#define HOSTHASH(imp, host) ((unsigned)((imp)+(host)) % HPMBUF)
e33b5b1a
BJ
83#endif
84
85/*
86 * In-line expansions for queuing operations on
87 * host message holding queue. Queue is maintained
88 * as circular list with the head pointing to the
89 * last message in the queue.
90 */
91#define HOST_ENQUE(hp, m) { \
92 register struct mbuf *n; \
c19356d7
BJ
93 (hp)->h_qcnt++; \
94 if ((n = (hp)->h_q) == 0) \
95 (hp)->h_q = (m)->m_act = (m); \
e33b5b1a 96 else { \
c19356d7
BJ
97 (m)->m_act = n->m_act; \
98 (hp)->h_q = n->m_act = (m); \
e33b5b1a
BJ
99 } \
100}
101#define HOST_DEQUE(hp, m) { \
c19356d7
BJ
102 if ((m) = (hp)->h_q) { \
103 if ((m)->m_act == (m)) \
104 (hp)->h_q = 0; \
e33b5b1a 105 else { \
c19356d7
BJ
106 (m) = (m)->m_act; \
107 (hp)->h_q->m_act = (m)->m_act; \
e33b5b1a 108 } \
c19356d7
BJ
109 (hp)->h_qcnt--; \
110 (m)->m_act = 0; \
e33b5b1a
BJ
111 } \
112}
81776a4f
SL
113
114struct hmbuf {
115 int hm_count; /* # of struct's in use */
116 struct host hm_hosts[HPMBUF]; /* data structures proper */
117};
118
119#ifdef KERNEL
a2cd4df7
BJ
120struct host *hostlookup();
121struct host *hostenter();
81776a4f 122#endif