Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / netproto / atm / spans / spans_cls.h
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/sys/netatm/spans/spans_cls.h,v 1.2 1999/08/28 00:48:49 peter Exp $
27  *
28  */
29
30 /*
31  * SPANS Signalling Manager
32  * ---------------------------
33  *
34  * SPANS Connectionless Datagram Service (CLS) control blocks
35  *
36  */
37
38 #ifndef _SPANS_SPANSCLS_H
39 #define _SPANS_SPANSCLS_H
40
41 /*
42  * Protocol constants
43  */
44 #define SPANSARP_AGING          (60 * ATM_HZ)   /* ARP aging timer */
45 #define SPANSARP_RETRY          (3 * ATM_HZ)    /* ARP retry timer */
46 #define SPANSARP_MAXAGE         20              /* Max ARP entry age (minutes)*/
47 #define SPANSARP_HASHSIZ        19              /* Hash table size */
48
49
50 /*
51  * SPANS CLS protocol structure.  There will be one such structure for 
52  * each SPANS signalling instance.
53  */
54 struct spanscls {
55         struct spanscls *cls_next;      /* Next attached cls instance */
56         u_char          cls_state;      /* Protocol state (see below) */
57         struct spans    *cls_spans;     /* Spans signalling instance */
58         Atm_connection  *cls_conn;      /* Connection manager token */
59         struct ip_nif   *cls_ipnif;     /* IP network interface */
60 };
61
62 /*
63  * SPANS CLS Protocol States
64  */
65 #define CLS_CLOSED      1               /* CLS PVC is closed */
66 #define CLS_OPEN        2               /* CLS PVC is open */
67
68
69 /*
70  * Structure for SPANS ARP mappings.  Each of these structures will contain 
71  * IP address to SPANS hardware address mappings.  There will be one such
72  * structure for each IP address currently in use.
73  */
74 struct spansarp {
75         struct arpmap   sa_arpmap;      /* Common entry header */
76         struct spanscls *sa_cls;        /* Interface where we learned answer */
77         struct spansarp *sa_next;       /* Hash chain */
78         struct spansarp *sa_rnext;      /* Retry chain */
79         u_char          sa_flags;       /* Flags (see below) */
80         u_char          sa_origin;      /* Origin (see below) */
81         u_short         sa_reftime;     /* Entry reference time (minutes) */
82         struct ipvcc    *sa_ivp;        /* IP VCCs waiting for answer */
83 };
84 #define sa_dstip        sa_arpmap.am_dstip
85 #define sa_dstatm       sa_arpmap.am_dstatm
86 #define sa_dstatmsub    sa_arpmap.am_dstatmsub
87
88 /*
89  * Entry Flags
90  */
91 #define SAF_VALID       ARPF_VALID      /* Entry is valid */
92 #define SAF_REFRESH     ARPF_REFRESH    /* Entry has been refreshed */
93 #define SAF_LOCKED      0x04            /* Entry is locked */
94
95 /*
96  * Entry Origin
97  */
98 #define SAO_PERM        ARP_ORIG_PERM   /* Entry is permanently installed */
99 #define SAO_LOOKUP      20              /* Learned via lookup */
100
101
102 /*
103  * SPANS CLS Packet Header
104  */
105 struct spanscls_hdr {
106         /* IEEE 802.6 MAC header */
107         spans_addr      ch_dst;         /* Destination SPANS address */
108         spans_addr      ch_src;         /* Source SPANS address */
109         u_char          ch_proto;       /* */
110         u_char          ch_extlen;      /* */
111         u_short         ch_bridging;    /* */
112
113         /* LLC SNAP header */
114         u_char          ch_dsap;        /* Destination SAP */
115         u_char          ch_ssap;        /* Source SAP */
116         u_char          ch_ctl;         /* Control field */
117         u_char          ch_oui[3];      /* Organizationally Unique Identifier */
118         u_short         ch_pid;         /* Protocol Identifier */
119 };
120
121 /*
122  * SPANS ARP Packet Format
123  */
124 struct spansarp_hdr {
125         u_short         ah_hrd;         /* Hardware type (see below) */
126         u_short         ah_pro;         /* Protocol type */
127         u_char          ah_hln;         /* Length of hardware address */
128         u_char          ah_pln;         /* Length of protocol address */
129         u_short         ah_op;          /* Operation code (see below) */
130         spans_addr      ah_sha;         /* Source hardware address */
131         u_char          ah_spa[4];      /* Source protocol address */
132         spans_addr      ah_tha;         /* Target hardware address */
133         u_char          ah_tpa[4];      /* Target protocol address */
134 };
135
136 /*
137  * Hardware types
138  */
139 #define ARP_SPANS       0x4040
140
141 /*
142  * Operation types
143  */
144 #define ARP_REQUEST     1               /* SPANSARP request */
145 #define ARP_REPLY       2               /* SPANSARP response */
146
147 #define ARP_PACKET_LEN  \
148         (sizeof(struct spanscls_hdr) + sizeof(struct spansarp_hdr))
149
150 #ifdef ATM_KERNEL
151 /*
152  * Macros for manipulating SPANS ARP tables and entries
153  */
154 #define SPANSARP_HASH(ip)       ((u_long)(ip) % SPANSARP_HASHSIZ)
155
156 #define SPANSARP_ADD(sa)                                                \
157 {                                                               \
158         struct spansarp **h;                                    \
159         h = &spansarp_arptab[SPANSARP_HASH((sa)->sa_dstip.s_addr)];     \
160         LINK2TAIL((sa), struct spansarp, *h, sa_next);          \
161 }
162
163 #define SPANSARP_DELETE(sa)                                     \
164 {                                                               \
165         struct spansarp **h;                                    \
166         h = &spansarp_arptab[SPANSARP_HASH((sa)->sa_dstip.s_addr)];     \
167         UNLINK((sa), struct spansarp, *h, sa_next);             \
168 }
169
170 #define SPANSARP_LOOKUP(ip, sa)                                 \
171 {                                                               \
172         for ((sa) = spansarp_arptab[SPANSARP_HASH(ip)];         \
173                                 (sa); (sa) = (sa)->sa_next) {   \
174                 if ((sa)->sa_dstip.s_addr == (ip))              \
175                         break;                                  \
176         }                                                       \
177 }
178
179
180 /*
181  * External variables
182  */
183 extern struct spanscls          *spanscls_head;
184 extern struct spanscls_hdr      spanscls_hdr;
185
186 #endif  /* ATM_KERNEL */
187
188 #endif  /* _SPANS_SPANSCLS_H */