|
|
1.1 root 1: /*
2: * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: *
33: * @(#)if_imphost.h 7.7 (Berkeley) 6/28/90
34: */
35:
36: /*
37: * Host structure used with IMP's.
38: * Used to hold outgoing packets which
39: * would exceed allowed RFNM count.
40: *
41: * These structures are packed into
42: * mbuf's and kept as small as possible.
43: */
44: struct host {
45: struct mbuf *h_q; /* holding queue */
46: u_short h_timer; /* used to stay off deletion */
47: u_short h_imp; /* host's imp number */
48: u_char h_host; /* host's number on imp */
49: u_char h_qcnt; /* size of holding q */
50: u_char h_rfnm; /* # outstanding rfnm's */
51: u_char h_flags; /* see below */
52: };
53:
54: /*
55: * A host structure is kept around (even when there are no
56: * references to it) for a spell to avoid constant reallocation
57: * and also to reflect IMP status back to sites which aren't
58: * directly connected to the IMP. When structures are marked
59: * idle, a timer is started; when the timer expires the structure
60: * is deallocated. A structure may be reused before the timer expires.
61: * A structure holds a reference on the containing mbuf when it is marked
62: * HF_INUSE.
63: */
64: #define HF_INUSE 0x1
65: #define HF_DEAD (1<<IMPTYPE_HOSTDEAD)
66: #define HF_UNREACH (1<<IMPTYPE_HOSTUNREACH)
67:
68: #define HOSTTIMER 128 /* keep structure around awhile */
69:
70: /*
71: * Mark a host structure free; used if host entry returned by hostlookup
72: * isn't needed. h_rfnm must be zero.
73: */
74: #define hostfree(hp) { \
75: if ((hp)->h_timer == 0 && (hp)->h_qcnt == 0 && \
76: (hp)->h_flags & HF_INUSE) \
77: hostrelease(hp); \
78: }
79:
80: /*
81: * Release a host entry when last rfnm is received.
82: */
83: #define hostidle(hp) { (hp)->h_timer = HOSTTIMER; }
84:
85: /*
86: * Host structures, as seen inside an mbuf.
87: * Hashing on the host and imp is used to
88: * select an index into the first mbuf. Collisions
89: * are then resolved by searching successive
90: * mbuf's at the same index. Reclamation is done
91: * automatically at the time a structure is freed.
92: */
93: #define HPMBUF ((MLEN - sizeof(int)) / sizeof(struct host))
94: /* don't need to swab as long as HPMBUF is odd */
95: #if defined(notdef) && BYTE_ORDER == BIG_ENDIAN
96: #define HOSTHASH(imp, host) ((unsigned)(ntohs(imp)+(host)) % HPMBUF)
97: #else
98: #define HOSTHASH(imp, host) ((unsigned)((imp)+(host)) % HPMBUF)
99: #endif
100:
101: /*
102: * In-line expansions for queuing operations on
103: * host message holding queue. Queue is maintained
104: * as circular list with the head pointing to the
105: * last message in the queue.
106: */
107: #define HOST_ENQUE(hp, m) { \
108: register struct mbuf *n; \
109: (hp)->h_qcnt++; \
110: if ((n = (hp)->h_q) == 0) \
111: (hp)->h_q = (m)->m_act = (m); \
112: else { \
113: (m)->m_act = n->m_act; \
114: (hp)->h_q = n->m_act = (m); \
115: } \
116: }
117: #define HOST_DEQUE(hp, m) { \
118: if ((m) = (hp)->h_q) { \
119: if ((m)->m_act == (m)) \
120: (hp)->h_q = 0; \
121: else { \
122: (m) = (m)->m_act; \
123: (hp)->h_q->m_act = (m)->m_act; \
124: } \
125: (hp)->h_qcnt--; \
126: (m)->m_act = 0; \
127: } \
128: }
129:
130: struct hmbuf {
131: int hm_count; /* # of struct's in use */
132: struct host hm_hosts[HPMBUF]; /* data structures proper */
133: };
134:
135: #ifdef KERNEL
136: struct host *hostlookup();
137: struct host *hostenter();
138: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.