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