Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
616d42db | 2 | * Copyright (c) 1982, 1986, 1988 Regents of the University of California. |
b0c21e3a | 3 | * All rights reserved. |
8ae0e4b4 | 4 | * |
dbf0c423 | 5 | * %sccs.include.redist.c% |
b0c21e3a | 6 | * |
dbf0c423 | 7 | * @(#)if_imphost.h 7.7 (Berkeley) %G% |
8ae0e4b4 | 8 | */ |
81776a4f SL |
9 | |
10 | /* | |
11 | * Host structure used with IMP's. | |
12 | * Used to hold outgoing packets which | |
13 | * would exceed allowed RFNM count. | |
14 | * | |
15 | * These structures are packed into | |
16 | * mbuf's and kept as small as possible. | |
17 | */ | |
18 | struct host { | |
19 | struct mbuf *h_q; /* holding queue */ | |
b0c21e3a | 20 | u_short h_timer; /* used to stay off deletion */ |
be7e9ce3 MK |
21 | u_short h_imp; /* host's imp number */ |
22 | u_char h_host; /* host's number on imp */ | |
ba45553a | 23 | u_char h_qcnt; /* size of holding q */ |
81776a4f | 24 | u_char h_rfnm; /* # outstanding rfnm's */ |
ba45553a | 25 | u_char h_flags; /* see below */ |
81776a4f SL |
26 | }; |
27 | ||
ba45553a SL |
28 | /* |
29 | * A host structure is kept around (even when there are no | |
30 | * references to it) for a spell to avoid constant reallocation | |
31 | * and also to reflect IMP status back to sites which aren't | |
32 | * directly connected to the IMP. When structures are marked | |
2c63532d | 33 | * idle, a timer is started; when the timer expires the structure |
b0c21e3a MK |
34 | * is deallocated. A structure may be reused before the timer expires. |
35 | * A structure holds a reference on the containing mbuf when it is marked | |
2c63532d | 36 | * HF_INUSE. |
ba45553a SL |
37 | */ |
38 | #define HF_INUSE 0x1 | |
39 | #define HF_DEAD (1<<IMPTYPE_HOSTDEAD) | |
40 | #define HF_UNREACH (1<<IMPTYPE_HOSTUNREACH) | |
41 | ||
b0c21e3a MK |
42 | #define HOSTTIMER 128 /* keep structure around awhile */ |
43 | ||
be7e9ce3 | 44 | /* |
2c63532d MK |
45 | * Mark a host structure free; used if host entry returned by hostlookup |
46 | * isn't needed. h_rfnm must be zero. | |
be7e9ce3 MK |
47 | */ |
48 | #define hostfree(hp) { \ | |
2c63532d MK |
49 | if ((hp)->h_timer == 0 && (hp)->h_qcnt == 0 && \ |
50 | (hp)->h_flags & HF_INUSE) \ | |
51 | hostrelease(hp); \ | |
be7e9ce3 MK |
52 | } |
53 | ||
2c63532d MK |
54 | /* |
55 | * Release a host entry when last rfnm is received. | |
56 | */ | |
57 | #define hostidle(hp) { (hp)->h_timer = HOSTTIMER; } | |
58 | ||
81776a4f SL |
59 | /* |
60 | * Host structures, as seen inside an mbuf. | |
be7e9ce3 | 61 | * Hashing on the host and imp is used to |
81776a4f SL |
62 | * select an index into the first mbuf. Collisions |
63 | * are then resolved by searching successive | |
64 | * mbuf's at the same index. Reclamation is done | |
b0c21e3a | 65 | * automatically at the time a structure is freed. |
81776a4f SL |
66 | */ |
67 | #define HPMBUF ((MLEN - sizeof(int)) / sizeof(struct host)) | |
2c63532d | 68 | /* don't need to swab as long as HPMBUF is odd */ |
be7e9ce3 | 69 | #if defined(notdef) && BYTE_ORDER == BIG_ENDIAN |
2c63532d | 70 | #define HOSTHASH(imp, host) ((unsigned)(ntohs(imp)+(host)) % HPMBUF) |
be7e9ce3 | 71 | #else |
2c63532d | 72 | #define HOSTHASH(imp, host) ((unsigned)((imp)+(host)) % HPMBUF) |
e33b5b1a BJ |
73 | #endif |
74 | ||
75 | /* | |
76 | * In-line expansions for queuing operations on | |
77 | * host message holding queue. Queue is maintained | |
78 | * as circular list with the head pointing to the | |
79 | * last message in the queue. | |
80 | */ | |
81 | #define HOST_ENQUE(hp, m) { \ | |
82 | register struct mbuf *n; \ | |
c19356d7 BJ |
83 | (hp)->h_qcnt++; \ |
84 | if ((n = (hp)->h_q) == 0) \ | |
85 | (hp)->h_q = (m)->m_act = (m); \ | |
e33b5b1a | 86 | else { \ |
c19356d7 BJ |
87 | (m)->m_act = n->m_act; \ |
88 | (hp)->h_q = n->m_act = (m); \ | |
e33b5b1a BJ |
89 | } \ |
90 | } | |
91 | #define HOST_DEQUE(hp, m) { \ | |
c19356d7 BJ |
92 | if ((m) = (hp)->h_q) { \ |
93 | if ((m)->m_act == (m)) \ | |
94 | (hp)->h_q = 0; \ | |
e33b5b1a | 95 | else { \ |
c19356d7 BJ |
96 | (m) = (m)->m_act; \ |
97 | (hp)->h_q->m_act = (m)->m_act; \ | |
e33b5b1a | 98 | } \ |
c19356d7 BJ |
99 | (hp)->h_qcnt--; \ |
100 | (m)->m_act = 0; \ | |
e33b5b1a BJ |
101 | } \ |
102 | } | |
81776a4f SL |
103 | |
104 | struct hmbuf { | |
105 | int hm_count; /* # of struct's in use */ | |
106 | struct host hm_hosts[HPMBUF]; /* data structures proper */ | |
107 | }; | |
108 | ||
109 | #ifdef KERNEL | |
a2cd4df7 BJ |
110 | struct host *hostlookup(); |
111 | struct host *hostenter(); | |
81776a4f | 112 | #endif |