123169Smckusick /* 234853Sbostic * Copyright (c) 1982, 1986, 1988 Regents of the University of California. 333453Skarels * All rights reserved. 423169Smckusick * 5*44469Sbostic * %sccs.include.redist.c% 633453Skarels * 7*44469Sbostic * @(#)if_imphost.h 7.7 (Berkeley) 06/28/90 823169Smckusick */ 95713Ssam 105713Ssam /* 115713Ssam * Host structure used with IMP's. 125713Ssam * Used to hold outgoing packets which 135713Ssam * would exceed allowed RFNM count. 145713Ssam * 155713Ssam * These structures are packed into 165713Ssam * mbuf's and kept as small as possible. 175713Ssam */ 185713Ssam struct host { 195713Ssam struct mbuf *h_q; /* holding queue */ 2033453Skarels u_short h_timer; /* used to stay off deletion */ 2133427Skarels u_short h_imp; /* host's imp number */ 2233427Skarels u_char h_host; /* host's number on imp */ 236589Ssam u_char h_qcnt; /* size of holding q */ 245713Ssam u_char h_rfnm; /* # outstanding rfnm's */ 256589Ssam u_char h_flags; /* see below */ 265713Ssam }; 275713Ssam 285713Ssam /* 296589Ssam * A host structure is kept around (even when there are no 306589Ssam * references to it) for a spell to avoid constant reallocation 316589Ssam * and also to reflect IMP status back to sites which aren't 326589Ssam * directly connected to the IMP. When structures are marked 3334209Skarels * idle, a timer is started; when the timer expires the structure 3433453Skarels * is deallocated. A structure may be reused before the timer expires. 3533453Skarels * A structure holds a reference on the containing mbuf when it is marked 3634209Skarels * HF_INUSE. 376589Ssam */ 386589Ssam #define HF_INUSE 0x1 396589Ssam #define HF_DEAD (1<<IMPTYPE_HOSTDEAD) 406589Ssam #define HF_UNREACH (1<<IMPTYPE_HOSTUNREACH) 416589Ssam 4233453Skarels #define HOSTTIMER 128 /* keep structure around awhile */ 4333453Skarels 4433427Skarels /* 4534209Skarels * Mark a host structure free; used if host entry returned by hostlookup 4634209Skarels * isn't needed. h_rfnm must be zero. 4733427Skarels */ 4833427Skarels #define hostfree(hp) { \ 4934209Skarels if ((hp)->h_timer == 0 && (hp)->h_qcnt == 0 && \ 5034209Skarels (hp)->h_flags & HF_INUSE) \ 5134209Skarels hostrelease(hp); \ 5233427Skarels } 5333427Skarels 546589Ssam /* 5534209Skarels * Release a host entry when last rfnm is received. 5634209Skarels */ 5734209Skarels #define hostidle(hp) { (hp)->h_timer = HOSTTIMER; } 5834209Skarels 5934209Skarels /* 605713Ssam * Host structures, as seen inside an mbuf. 6133427Skarels * Hashing on the host and imp is used to 625713Ssam * select an index into the first mbuf. Collisions 635713Ssam * are then resolved by searching successive 645713Ssam * mbuf's at the same index. Reclamation is done 6533453Skarels * automatically at the time a structure is freed. 665713Ssam */ 675713Ssam #define HPMBUF ((MLEN - sizeof(int)) / sizeof(struct host)) 6834209Skarels /* don't need to swab as long as HPMBUF is odd */ 6933427Skarels #if defined(notdef) && BYTE_ORDER == BIG_ENDIAN 7034209Skarels #define HOSTHASH(imp, host) ((unsigned)(ntohs(imp)+(host)) % HPMBUF) 7133427Skarels #else 7234209Skarels #define HOSTHASH(imp, host) ((unsigned)((imp)+(host)) % HPMBUF) 735924Sroot #endif 745713Ssam 755924Sroot /* 765924Sroot * In-line expansions for queuing operations on 775924Sroot * host message holding queue. Queue is maintained 785924Sroot * as circular list with the head pointing to the 795924Sroot * last message in the queue. 805924Sroot */ 815924Sroot #define HOST_ENQUE(hp, m) { \ 825924Sroot register struct mbuf *n; \ 836089Sroot (hp)->h_qcnt++; \ 846089Sroot if ((n = (hp)->h_q) == 0) \ 856089Sroot (hp)->h_q = (m)->m_act = (m); \ 865924Sroot else { \ 876089Sroot (m)->m_act = n->m_act; \ 886089Sroot (hp)->h_q = n->m_act = (m); \ 895924Sroot } \ 905924Sroot } 915924Sroot #define HOST_DEQUE(hp, m) { \ 926089Sroot if ((m) = (hp)->h_q) { \ 936089Sroot if ((m)->m_act == (m)) \ 946089Sroot (hp)->h_q = 0; \ 955924Sroot else { \ 966089Sroot (m) = (m)->m_act; \ 976089Sroot (hp)->h_q->m_act = (m)->m_act; \ 985924Sroot } \ 996089Sroot (hp)->h_qcnt--; \ 1006089Sroot (m)->m_act = 0; \ 1015924Sroot } \ 1025924Sroot } 1035924Sroot 1045713Ssam struct hmbuf { 1055713Ssam int hm_count; /* # of struct's in use */ 1065713Ssam struct host hm_hosts[HPMBUF]; /* data structures proper */ 1075713Ssam }; 1085713Ssam 1095713Ssam #ifdef KERNEL 1105771Swnj struct host *hostlookup(); 1115771Swnj struct host *hostenter(); 1125713Ssam #endif 113