kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / netproto / atm / uni / uniip_var.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/uni/uniip_var.h,v 1.2 1999/08/28 00:49:04 peter Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/uni/uniip_var.h,v 1.2 2003/06/17 04:28:49 dillon Exp $
28  *
29  */
30
31 /*
32  * ATM Forum UNI Support
33  * ---------------------
34  *
35  * IP interface control blocks
36  *
37  */
38
39 #ifndef _UNI_UNIIP_VAR_H
40 #define _UNI_UNIIP_VAR_H
41
42 #ifdef ATM_KERNEL
43 /*
44  * UNI IP network interface structure.  There will be one such structure for 
45  * each IP network interface attached via a UNI signalling instance.
46  */
47 struct uniip {
48         struct uniip    *uip_next;      /* Next attached IP interface */
49         struct ip_nif   *uip_ipnif;     /* IP network interface */
50         u_char          uip_flags;      /* Interface flags (see below) */
51
52         /* ATMARP (RFC1577) */
53         u_char          uip_arpstate;   /* ARP interface state (see below) */
54         struct arpmap   uip_arpsvrmap;  /* ATMARP server map info */
55         struct ipvcc    *uip_arpsvrvcc; /* ATMARP server's VCC */
56         int             uip_nprefix;    /* Count of IP prefixes (server only) */
57         struct uniarp_prf *uip_prefix;  /* Array of IP prefixes (server only) */
58         struct atm_time uip_arptime;    /* ARP timer controls */
59 };
60 #define uip_arpsvrip    uip_arpsvrmap.am_dstip
61 #define uip_arpsvratm   uip_arpsvrmap.am_dstatm
62 #define uip_arpsvrsub   uip_arpsvrmap.am_dstatmsub
63 #endif  /* ATM_KERNEL */
64
65 /*
66  * UNI Interface Flags
67  */
68 #define UIF_IFADDR      0x01            /* Interface address is set */
69
70 /*
71  * UNI ARP Interface States
72  */
73 #define UIAS_NOTCONF            1       /* Not configured */
74 #define UIAS_SERVER_ACTIVE      2       /* Server - active */
75 #define UIAS_CLIENT_PADDR       3       /* Client - pending ATM address */
76 #define UIAS_CLIENT_POPEN       4       /* Client - pending server vcc open */
77 #define UIAS_CLIENT_REGISTER    5       /* Client - registering with server */
78 #define UIAS_CLIENT_ACTIVE      6       /* Client - active */
79
80
81 #ifdef ATM_KERNEL
82 /*
83  * Structure for allowable IP prefixes for ATMARP server registration
84  */
85 struct uniarp_prf {
86         struct in_addr  upf_addr;       /* Prefix address */
87         struct in_addr  upf_mask;       /* Prefix mask */
88 };
89
90
91 /*
92  * UNI ARP protocol constants
93  */
94 #define UNIARP_AGING            (60 * ATM_HZ)   /* Aging timer tick */
95 #define UNIARP_HASHSIZ          19      /* Hash table size */
96 #define UNIARP_REGIS_REFRESH    (15 * 60 * ATM_HZ)
97                                         /* Client registration refresh timer */
98 #define UNIARP_REGIS_RETRY      (60 * ATM_HZ)
99                                         /* Client registration retry timer */
100 #define UNIARP_ARP_RETRY        (3 * ATM_HZ)    /* ARP command retry timer */
101 #define UNIARP_CLIENT_AGE       12      /* Client validation timeout */
102 #define UNIARP_CLIENT_RETRY     3       /* Client validation retrys */
103 #define UNIARP_SERVER_AGE       17      /* Server validation timeout */
104 #define UNIARP_SERVER_RETRY     3       /* Server validation retrys */
105 #define UNIARP_RETRY_AGE        1       /* Retry timeout */
106 #define UNIARP_REVALID_AGE      2       /* Revalidation timeout */
107 #define UNIARP_MIN_REFRESH      10      /* Minimum entry refresh time */
108
109
110 /*
111  * Structure for ATMARP mappings.  Each of these structures will contain
112  * IP address to ATM hardware address mappings.  There will be one such
113  * structure for each IP address and for each unresolved ATM address
114  * currently in use.
115  */
116 struct uniarp {
117         struct arpmap   ua_arpmap;      /* Common entry header */
118         struct uniip    *ua_intf;       /* Interface where we learned answer */
119         struct uniarp   *ua_next;       /* Hash chain link */
120         u_char          ua_flags;       /* Flags (see below) */
121         u_char          ua_origin;      /* Source of mapping (see below) */
122         u_char          ua_retry;       /* Retry counter */
123         u_char          ua_aging;       /* Aging timeout value (minutes) */
124         struct ipvcc    *ua_ivp;        /* Head of IP VCC chain */
125         struct atm_time ua_time;        /* Timer controls */
126 };
127 #define ua_dstip        ua_arpmap.am_dstip
128 #define ua_dstatm       ua_arpmap.am_dstatm
129 #define ua_dstatmsub    ua_arpmap.am_dstatmsub
130 #endif  /* ATM_KERNEL */
131
132 /*
133  * UNIARP Entry Flags
134  */
135 #define UAF_VALID       ARPF_VALID      /* Entry is valid */
136 #define UAF_REFRESH     ARPF_REFRESH    /* Entry has been refreshed */
137 #define UAF_LOCKED      0x04            /* Entry is locked */
138 #define UAF_USED        0x08            /* Entry has been used recently */
139
140 /*
141  * UNIARP Entry Origin
142  *
143  * The origin values are ranked according to the source precedence.  
144  * Larger values are more preferred.
145  */
146 #define UAO_LOCAL       100             /* Local address */
147 #define UAO_PERM        ARP_ORIG_PERM   /* Permanently installed */
148 #define UAO_REGISTER    40              /* Learned via client registration */
149 #define UAO_SCSP        30              /* Learned via SCSP */
150 #define UAO_LOOKUP      20              /* Learned via server lookup */
151 #define UAO_PEER_RSP    15              /* Learned from peer - inarp rsp */
152 #define UAO_PEER_REQ    10              /* Learned from peer - inarp req */
153
154 /*
155  * ATMARP/InATMARP Packet Format
156  */
157 struct atmarp_hdr {
158         u_short         ah_hrd;         /* Hardware type (see below) */
159         u_short         ah_pro;         /* Protocol type */
160         u_char          ah_shtl;        /* Type/len of source ATM address */
161         u_char          ah_sstl;        /* Type/len of source ATM subaddress */
162         u_short         ah_op;          /* Operation code (see below) */
163         u_char          ah_spln;        /* Length of source protocol address */
164         u_char          ah_thtl;        /* Type/len of target ATM address */
165         u_char          ah_tstl;        /* Type/len of target ATM subaddress */
166         u_char          ah_tpln;        /* Length of target protocol address */
167 #ifdef notdef
168         /* Variable size fields */
169         u_char          ah_sha[];       /* Source ATM address */
170         u_char          ah_ssa[];       /* Source ATM subaddress */
171         u_char          ah_spa[];       /* Source protocol address */
172         u_char          ah_tha[];       /* Target ATM subaddress */
173         u_char          ah_tsa[];       /* Target ATM address */
174         u_char          ah_tpa[];       /* Target protocol subaddress */
175 #endif
176 };
177
178 /*
179  * Hardware types
180  */
181 #define ARP_ATMFORUM    19
182
183 /*
184  * Operation types
185  */
186 #define ARP_REQUEST     1               /* ATMARP request */
187 #define ARP_REPLY       2               /* ATMARP response */
188 #define INARP_REQUEST   8               /* InATMARP request */
189 #define INARP_REPLY     9               /* InATMARP response */
190 #define ARP_NAK         10              /* ATMARP negative ack */
191
192 /*
193  * Type/length fields
194  */
195 #define ARP_TL_TMASK    0x40            /* Type mask */
196 #define ARP_TL_NSAPA    0x00            /* Type = ATM Forum NSAPA */
197 #define ARP_TL_E164     0x40            /* Type = E.164 */
198 #define ARP_TL_LMASK    0x3f            /* Length mask */
199
200
201 #ifdef ATM_KERNEL
202 /*
203  * Timer macros
204  */
205 #define UNIIP_ARP_TIMER(s, t)   atm_timeout(&(s)->uip_arptime, (t), uniarp_iftimeout)
206 #define UNIIP_ARP_CANCEL(s)     atm_untimeout(&(s)->uip_arptime)
207 #define UNIARP_TIMER(s, t)      atm_timeout(&(s)->ua_time, (t), uniarp_timeout)
208 #define UNIARP_CANCEL(s)        atm_untimeout(&(s)->ua_time)
209
210
211 /*
212  * Macros for manipulating UNIARP tables and entries
213  */
214 #define UNIARP_HASH(ip) ((u_long)(ip) % UNIARP_HASHSIZ)
215
216 #define UNIARP_ADD(ua)                                          \
217 {                                                               \
218         struct uniarp   **h;                                    \
219         h = &uniarp_arptab[UNIARP_HASH((ua)->ua_dstip.s_addr)]; \
220         LINK2TAIL((ua), struct uniarp, *h, ua_next);            \
221 }
222
223 #define UNIARP_DELETE(ua)                                       \
224 {                                                               \
225         struct uniarp   **h;                                    \
226         h = &uniarp_arptab[UNIARP_HASH((ua)->ua_dstip.s_addr)]; \
227         UNLINK((ua), struct uniarp, *h, ua_next);               \
228 }
229
230 #define UNIARP_LOOKUP(ip, ua)                                   \
231 {                                                               \
232         for ((ua) = uniarp_arptab[UNIARP_HASH(ip)];             \
233                                 (ua); (ua) = (ua)->ua_next) {   \
234                 if ((ua)->ua_dstip.s_addr == (ip))              \
235                         break;                                  \
236         }                                                       \
237 }
238
239
240 /*
241  * Global UNIARP Statistics
242  */
243 struct uniarp_stat {
244         u_long          uas_rcvdrop;    /* Input packets dropped */
245 };
246
247
248 /*
249  * External variables
250  */
251 extern struct uniip             *uniip_head;
252 extern struct ip_serv           uniip_ipserv;
253 extern struct uniarp            *uniarp_arptab[];
254 extern struct uniarp            *uniarp_nomaptab;
255 extern struct uniarp            *uniarp_pvctab;
256 extern struct sp_info           uniarp_pool;
257 extern struct atm_time          uniarp_timer;
258 extern int                      uniarp_print;
259 extern Atm_endpoint             uniarp_endpt;
260 extern struct uniarp_stat       uniarp_stat;
261
262
263 /*
264  * Global function declarations
265  */
266         /* uniarp.c */
267 int             uniarp_start __P((void));
268 void            uniarp_stop __P((void));
269 void            uniarp_ipact __P((struct uniip *));
270 void            uniarp_ipdact __P((struct uniip *));
271 void            uniarp_ifaddr __P((struct siginst *));
272 void            uniarp_iftimeout __P((struct atm_time *));
273 int             uniarp_ioctl __P((int, caddr_t, caddr_t));
274 caddr_t         uniarp_getname __P((void *));
275
276         /* uniarp_cache.c */
277 int             uniarp_cache_svc __P((struct uniip *, struct in_addr *,
278                         Atm_addr *, Atm_addr *, u_int));
279 void            uniarp_cache_pvc __P((struct ipvcc *, struct in_addr *,
280                         Atm_addr *, Atm_addr *));
281 int             uniarp_validate_ip __P((struct uniip *, struct in_addr *,
282                         u_int));
283
284         /* uniarp_input.c */
285 void            uniarp_cpcs_data __P((void *, KBuffer *));
286 void            uniarp_pdu_print __P((struct ipvcc *, KBuffer *, char *));
287
288         /* uniarp_output.c */
289 int             uniarp_arp_req __P((struct uniip *, struct in_addr *));
290 int             uniarp_arp_rsp __P((struct uniip *, struct arpmap *,
291                         struct in_addr *, Atm_addr *,
292                         Atm_addr *, struct ipvcc *));
293 int             uniarp_arp_nak __P((struct uniip *, KBuffer *, struct ipvcc *));
294 int             uniarp_inarp_req __P((struct uniip *, Atm_addr *,
295                         Atm_addr *, struct ipvcc *));
296 int             uniarp_inarp_rsp __P((struct uniip *, struct in_addr *,
297                         Atm_addr *, Atm_addr *, struct ipvcc *));
298
299         /* uniarp_timer.c */
300 void            uniarp_timeout __P((struct atm_time *));
301 void            uniarp_aging __P((struct atm_time *));
302
303         /* uniarp_vcm.c */
304 int             uniarp_pvcopen __P((struct ipvcc *));
305 int             uniarp_svcout __P((struct ipvcc *, struct in_addr *));
306 int             uniarp_svcin __P((struct ipvcc *, Atm_addr *, Atm_addr *));
307 int             uniarp_svcactive __P((struct ipvcc *));
308 void            uniarp_vcclose __P((struct ipvcc *));
309 void            uniarp_connected __P((void *));
310 void            uniarp_cleared __P((void *, struct t_atm_cause *));
311
312         /* uniip.c */
313 int             uniip_start __P((void));
314 int             uniip_stop __P((void));
315
316
317 #endif  /* ATM_KERNEL */
318
319 #endif  /* _UNI_UNIIP_VAR_H */