1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)if_imphost.h	7.2 (Berkeley) 02/03/88
7  */
8 
9 /*
10  * Host structure used with IMP's.
11  * Used to hold outgoing packets which
12  * would exceed allowed RFNM count.
13  *
14  * These structures are packed into
15  * mbuf's and kept as small as possible.
16  */
17 struct host {
18 	struct	mbuf *h_q;		/* holding queue */
19 	u_short	h_imp;			/* host's imp number */
20 	u_char	h_host;			/* host's number on imp */
21 	u_char	h_unit;			/* imp unit number */
22 	u_char	h_qcnt;          	/* size of holding q */
23 	u_char	h_timer;		/* used to stay off deletion */
24 	u_char	h_rfnm;			/* # outstanding rfnm's */
25 	u_char	h_flags;		/* see below */
26 };
27 
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
33  * free, a timer is started; when the timer expires the structure
34  * is scavenged.
35  */
36 #define	HF_INUSE	0x1
37 #define	HF_DEAD		(1<<IMPTYPE_HOSTDEAD)
38 #define	HF_UNREACH	(1<<IMPTYPE_HOSTUNREACH)
39 
40 /*
41  * Mark a host structure free
42  */
43 #define	hostfree(hp) { \
44 	(hp)->h_flags &= ~HF_INUSE; \
45 }
46 
47 #define	HOSTTIMER	128		/* keep structure around awhile */
48 
49 /*
50  * Host structures, as seen inside an mbuf.
51  * Hashing on the host and imp is used to
52  * select an index into the first mbuf.  Collisions
53  * are then resolved by searching successive
54  * mbuf's at the same index.  Reclamation is done
55  * automatically at the time a structure is free'd.
56  */
57 #define	HPMBUF	((MLEN - sizeof(int)) / sizeof(struct host))
58 #if defined(notdef) && BYTE_ORDER == BIG_ENDIAN
59 #define	HOSTHASH(imp, host)	(((imp)+(host)) % HPMBUF)
60 #else
61 #define	HOSTHASH(imp, host)	((ntohs(imp)+(host)) % HPMBUF)
62 #endif
63 
64 /*
65  * In-line expansions for queuing operations on
66  * host message holding queue.  Queue is maintained
67  * as circular list with the head pointing to the
68  * last message in the queue.
69  */
70 #define	HOST_ENQUE(hp, m) { \
71 	register struct mbuf *n; \
72 	(hp)->h_qcnt++; \
73 	if ((n = (hp)->h_q) == 0) \
74 		(hp)->h_q = (m)->m_act = (m); \
75 	else { \
76 		(m)->m_act = n->m_act; \
77 		(hp)->h_q = n->m_act = (m); \
78 	} \
79 }
80 #define	HOST_DEQUE(hp, m) { \
81 	if ((m) = (hp)->h_q) { \
82 		if ((m)->m_act == (m)) \
83 			(hp)->h_q = 0; \
84 		else { \
85 			(m) = (m)->m_act; \
86 			(hp)->h_q->m_act = (m)->m_act; \
87 		} \
88 		(hp)->h_qcnt--; \
89 		(m)->m_act = 0; \
90 	} \
91 }
92 
93 struct hmbuf {
94 	int	hm_count;		/* # of struct's in use */
95 	struct	host hm_hosts[HPMBUF];	/* data structures proper */
96 };
97 
98 #ifdef KERNEL
99 struct host *hostlookup();
100 struct host *hostenter();
101 struct mbuf *hostdeque();
102 #endif
103