kernel tree reorganization stage 1: Major cvs repository work (not logged as
[dragonfly.git] / sys / netproto / atm / uni / uniarp_timer.c
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/uniarp_timer.c,v 1.4 2000/01/17 20:49:55 mks Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/uni/uniarp_timer.c,v 1.3 2003/08/07 21:17:35 dillon Exp $
28  */
29
30 /*
31  * ATM Forum UNI Support
32  * ---------------------
33  *
34  * UNI ATMARP support (RFC1577) - Timer processing
35  *
36  */
37
38 #include <netatm/kern_include.h>
39
40 #include <netatm/ipatm/ipatm_var.h>
41 #include <netatm/ipatm/ipatm_serv.h>
42 #include "uniip_var.h"
43
44 /*
45  * Local functions
46  */
47 static void     uniarp_svc_oldage __P((struct uniarp *));
48 static void     uniarp_pvc_oldage __P((struct uniarp *));
49
50
51 /*
52  * Process a UNI ATMARP entry timeout
53  * 
54  * Called when a previously scheduled uniarp control block timer expires.
55  *
56  * Called at splnet.
57  *
58  * Arguments:
59  *      tip     pointer to uniarp timer control block
60  *
61  * Returns:
62  *      none
63  *
64  */
65 void
66 uniarp_timeout(tip)
67         struct atm_time *tip;
68 {
69         struct uniip    *uip;
70         struct uniarp   *uap;
71         struct ipvcc    *ivp;
72
73
74         /*
75          * Back-off to uniarp control block
76          */
77         uap = (struct uniarp *)
78                         ((caddr_t)tip - (int)(&((struct uniarp *)0)->ua_time));
79         uip = uap->ua_intf;
80
81
82         /*
83          * Do we know the IP address for this entry yet??
84          */
85         if (uap->ua_dstip.s_addr == 0) {
86
87                 /*
88                  * No, then send another InATMARP_REQ on each active VCC
89                  * associated with this entry to solicit the peer's identity.
90                  */
91                 for (ivp = uap->ua_ivp; ivp; ivp = ivp->iv_arpnext) {
92                         if (ivp->iv_state != IPVCC_ACTIVE)
93                                 continue;
94                         (void) uniarp_inarp_req(uip, &uap->ua_dstatm, 
95                                 &uap->ua_dstatmsub, ivp);
96                 }
97
98                 /*
99                  * Restart retry timer
100                  */
101                 UNIARP_TIMER(uap, UNIARP_ARP_RETRY);
102         } else {
103                 /*
104                  * Yes, then we're trying to find the ATM address for this
105                  * IP address - so send another ATMARP_REQ to the arpserver
106                  * (if it's up at the moment)
107                  */
108                 if (uip->uip_arpstate == UIAS_CLIENT_ACTIVE)
109                         (void) uniarp_arp_req(uip, &uap->ua_dstip);
110
111                 /*
112                  * Restart retry timer
113                  */
114                 UNIARP_TIMER(uap, UNIARP_ARP_RETRY);
115         }
116
117         return;
118 }
119
120
121 /*
122  * Process an UNI ARP SVC entry aging timer expiration
123  * 
124  * This function is called when an SVC arp entry's aging timer has expired.
125  *
126  * Called at splnet().
127  *
128  * Arguments:
129  *      uap     pointer to atmarp table entry
130  *
131  * Returns:
132  *      none
133  *
134  */
135 static void
136 uniarp_svc_oldage(uap)
137         struct uniarp   *uap;
138 {
139         struct ipvcc    *ivp, *inext;
140         struct uniip    *uip = uap->ua_intf;
141
142
143         /*
144          * Permanent (manually installed) entries are never aged
145          */
146         if (uap->ua_origin >= UAO_PERM)
147                 return;
148
149         /*
150          * If entry is valid and we're out of retrys, tell
151          * IP/ATM that the SVCs can't be used
152          */
153         if ((uap->ua_flags & UAF_VALID) && (uap->ua_retry-- == 0)) {
154                 uap->ua_flags |= UAF_LOCKED;
155                 for (ivp = uap->ua_ivp; ivp; ivp = inext) {
156                         inext = ivp->iv_arpnext;
157                         (*ivp->iv_ipnif->inf_arpnotify)(ivp, MAP_INVALID);
158                 }
159                 uap->ua_flags &= ~(UAF_LOCKED | UAF_VALID);
160                 uap->ua_origin = 0;
161
162                 /*
163                  * Delete and free an unused entry
164                  */
165                 if (uap->ua_ivp == NULL) {
166                         UNIARP_CANCEL(uap);
167                         UNIARP_DELETE(uap);
168                         atm_free((caddr_t)uap);
169                         return;
170                 }
171         }
172
173         /*
174          * We want to try and refresh this entry but we don't want
175          * to keep unused entries laying around forever.
176          */
177         if (uap->ua_ivp || (uap->ua_flags & UAF_USED)) {
178                 if (uip->uip_arpstate == UIAS_CLIENT_ACTIVE) {
179                         /*
180                          * If we are a client (and the server VCC is active),
181                          * then we'll ask the server for a refresh
182                          */ 
183                         (void) uniarp_arp_req(uip, &uap->ua_dstip);
184                 } else {
185                         /*
186                          * Otherwise, solicit the each active VCC peer with 
187                          * an Inverse ATMARP
188                          */
189                         for (ivp = uap->ua_ivp; ivp; ivp = ivp->iv_arpnext) {
190                                 if (ivp->iv_state != IPVCC_ACTIVE)
191                                         continue;
192                                 (void) uniarp_inarp_req(uip, &uap->ua_dstatm,
193                                         &uap->ua_dstatmsub, ivp);
194                         }
195                 }
196         }
197
198         /*
199          * Reset timeout
200          */
201         if (uap->ua_flags & UAF_VALID)
202                 uap->ua_aging = UNIARP_RETRY_AGE;
203         else
204                 uap->ua_aging = UNIARP_REVALID_AGE;
205
206         return;
207 }
208
209
210 /*
211  * Process an UNI ARP PVC entry aging timer expiration
212  * 
213  * This function is called when a PVC arp entry's aging timer has expired.
214  *
215  * Called at splnet().
216  *
217  * Arguments:
218  *      uap     pointer to atmarp table entry
219  *
220  * Returns:
221  *      none
222  *
223  */
224 static void
225 uniarp_pvc_oldage(uap)
226         struct uniarp   *uap;
227 {
228         struct ipvcc    *ivp = uap->ua_ivp;
229
230         /*
231          * If entry is valid and we're out of retrys, tell
232          * IP/ATM that PVC can't be used
233          */
234         if ((uap->ua_flags & UAF_VALID) && (uap->ua_retry-- == 0)) {
235                 (*ivp->iv_ipnif->inf_arpnotify)(ivp, MAP_INVALID);
236                 uap->ua_flags &= ~UAF_VALID;
237         }
238
239         /*
240          * Solicit peer with Inverse ATMARP
241          */
242         (void) uniarp_inarp_req(uap->ua_intf, &uap->ua_dstatm,
243                         &uap->ua_dstatmsub, ivp);
244
245         /*
246          * Reset timeout
247          */
248         if (uap->ua_flags & UAF_VALID)
249                 uap->ua_aging = UNIARP_RETRY_AGE;
250         else
251                 uap->ua_aging = UNIARP_REVALID_AGE;
252
253         return;
254 }
255
256
257 /*
258  * Process a UNI ARP aging timer tick
259  * 
260  * This function is called every UNIARP_AGING seconds, in order to age
261  * all the arp table entries.  If an entry's timer is expired, then the
262  * uniarp old-age timeout function will be called for that entry.
263  *
264  * Called at splnet.
265  *
266  * Arguments:
267  *      tip     pointer to uniarp aging timer control block
268  *
269  * Returns:
270  *      none
271  *
272  */
273 void
274 uniarp_aging(tip)
275         struct atm_time *tip;
276 {
277         struct uniarp   *uap, *unext;
278         int             i;
279
280
281         /*
282          * Schedule next timeout
283          */
284         atm_timeout(&uniarp_timer, UNIARP_AGING, uniarp_aging);
285
286         /*
287          * Run through arp table bumping each entry's aging timer.
288          * If an expired timer is found, process that entry.
289          */
290         for (i = 0; i < UNIARP_HASHSIZ; i++) {
291                 for (uap = uniarp_arptab[i]; uap; uap = unext) {
292                         unext = uap->ua_next;
293
294                         if (uap->ua_aging && --uap->ua_aging == 0)
295                                 uniarp_svc_oldage(uap);
296                 }
297         }
298
299         /*
300          * Check out PVC aging timers too
301          */
302         for (uap = uniarp_pvctab; uap; uap = unext) {
303                 unext = uap->ua_next;
304
305                 if (uap->ua_aging && --uap->ua_aging == 0)
306                         uniarp_pvc_oldage(uap);
307         }
308
309         /*
310          * Only fully resolved SVC entries need aging, so there's no need
311          * to examine the 'no map' table
312          */
313 }
314