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 are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 * 12 * @(#)if_imphost.h 7.3 (Berkeley) 02/08/88 13 */ 14 15 /* 16 * Host structure used with IMP's. 17 * Used to hold outgoing packets which 18 * would exceed allowed RFNM count. 19 * 20 * These structures are packed into 21 * mbuf's and kept as small as possible. 22 */ 23 struct host { 24 struct mbuf *h_q; /* holding queue */ 25 u_short h_timer; /* used to stay off deletion */ 26 u_short h_imp; /* host's imp number */ 27 u_char h_host; /* host's number on imp */ 28 u_char h_qcnt; /* size of holding q */ 29 u_char h_rfnm; /* # outstanding rfnm's */ 30 u_char h_flags; /* see below */ 31 }; 32 33 /* 34 * A host structure is kept around (even when there are no 35 * references to it) for a spell to avoid constant reallocation 36 * and also to reflect IMP status back to sites which aren't 37 * directly connected to the IMP. When structures are marked 38 * free, a timer is started; when the timer expires the structure 39 * is deallocated. A structure may be reused before the timer expires. 40 * A structure holds a reference on the containing mbuf when it is marked 41 * HF_INUSE or its timer is running. 42 */ 43 #define HF_INUSE 0x1 44 #define HF_DEAD (1<<IMPTYPE_HOSTDEAD) 45 #define HF_UNREACH (1<<IMPTYPE_HOSTUNREACH) 46 47 #define HOSTTIMER 128 /* keep structure around awhile */ 48 49 /* 50 * Mark a host structure free 51 */ 52 #define hostfree(hp) { \ 53 (hp)->h_flags &= ~HF_INUSE; \ 54 (hp)->h_timer = HOSTTIMER; \ 55 } 56 57 /* 58 * Host structures, as seen inside an mbuf. 59 * Hashing on the host and imp is used to 60 * select an index into the first mbuf. Collisions 61 * are then resolved by searching successive 62 * mbuf's at the same index. Reclamation is done 63 * automatically at the time a structure is freed. 64 */ 65 #define HPMBUF ((MLEN - sizeof(int)) / sizeof(struct host)) 66 #if defined(notdef) && BYTE_ORDER == BIG_ENDIAN 67 #define HOSTHASH(imp, host) (((imp)+(host)) % HPMBUF) 68 #else 69 #define HOSTHASH(imp, host) ((ntohs(imp)+(host)) % HPMBUF) 70 #endif 71 72 /* 73 * In-line expansions for queuing operations on 74 * host message holding queue. Queue is maintained 75 * as circular list with the head pointing to the 76 * last message in the queue. 77 */ 78 #define HOST_ENQUE(hp, m) { \ 79 register struct mbuf *n; \ 80 (hp)->h_qcnt++; \ 81 if ((n = (hp)->h_q) == 0) \ 82 (hp)->h_q = (m)->m_act = (m); \ 83 else { \ 84 (m)->m_act = n->m_act; \ 85 (hp)->h_q = n->m_act = (m); \ 86 } \ 87 } 88 #define HOST_DEQUE(hp, m) { \ 89 if ((m) = (hp)->h_q) { \ 90 if ((m)->m_act == (m)) \ 91 (hp)->h_q = 0; \ 92 else { \ 93 (m) = (m)->m_act; \ 94 (hp)->h_q->m_act = (m)->m_act; \ 95 } \ 96 (hp)->h_qcnt--; \ 97 (m)->m_act = 0; \ 98 } \ 99 } 100 101 struct hmbuf { 102 int hm_count; /* # of struct's in use */ 103 struct host hm_hosts[HPMBUF]; /* data structures proper */ 104 }; 105 106 #ifdef KERNEL 107 struct host *hostlookup(); 108 struct host *hostenter(); 109 struct mbuf *hostdeque(); 110 #endif 111