Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / atm / atmarpd / atmarp_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/usr.sbin/atm/atmarpd/atmarp_timer.c,v 1.3 1999/08/28 01:15:30 peter Exp $
27  *
28  */
29
30 /*
31  * Server Cache Synchronization Protocol (SCSP) Support
32  * ----------------------------------------------------
33  *
34  * SCSP-ATMARP server interface: timer routines
35  *
36  */
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/queue.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_if.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_ioctl.h>
50  
51 #include <errno.h>
52 #include <libatm.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include <syslog.h>
57
58 #include "../scspd/scsp_msg.h"
59 #include "../scspd/scsp_if.h"
60 #include "../scspd/scsp_var.h"
61 #include "atmarp_var.h"
62
63 #ifndef lint
64 __RCSID("@(#) $FreeBSD: src/usr.sbin/atm/atmarpd/atmarp_timer.c,v 1.3 1999/08/28 01:15:30 peter Exp $");
65 #endif
66
67
68 /*
69  * Cache update timeout processing
70  *
71  * When the cache update timer fires, we read the cache from the
72  * kernel, update the internal cache, and restart the timer.
73  *
74  * Arguments:
75  *      tp      pointer to a HARP timer block
76  *
77  * Returns:
78  *      None
79  *
80  */
81 void
82 atmarp_cache_timeout(tp)
83         Harp_timer      *tp;
84 {
85         Atmarp_intf     *aip;
86
87         /*
88          * Verify the status of all configured interfaces
89          */
90         for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
91                 if (atmarp_if_ready(aip)) {
92                         /*
93                          * The interface is up but we don't have
94                          * a connection to SCSP--make a connection
95                          */
96                         if (aip->ai_state == AI_STATE_NULL)
97                                 (void)atmarp_scsp_connect(aip);
98                 } else {
99                         /*
100                          * The interface is down--disconnect from SCSP
101                          */
102                         if (aip->ai_state != AI_STATE_NULL)
103                                 (void)atmarp_scsp_disconnect(aip);
104                 }
105         }
106
107         /*
108          * Read the cache from the kernel
109          */
110         atmarp_get_updated_cache();
111
112         /*
113          * Restart the cache update timer
114          */
115         HARP_TIMER(tp, ATMARP_CACHE_INTERVAL, atmarp_cache_timeout);
116 }
117
118
119 /*
120  * Permanent cache entry timer processing
121  *
122  * Permanent cache entries (entries that are administratively added
123  * and the entry for the server itself) don't ever get refreshed, so
124  * we broadcast updates for them every 10 minutes so they won't get
125  * deleted from the remote servers' caches
126  *
127  * Arguments:
128  *      tp      pointer to a HARP timer block
129  *
130  * Returns:
131  *      None
132  *
133  */
134 void
135 atmarp_perm_timeout(tp)
136         Harp_timer      *tp;
137 {
138         int             i, rc;
139         Atmarp_intf     *aip;
140         Atmarp          *aap;
141
142         /*
143          * Loop through all interfaces
144          */
145         for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
146                 /*
147                  * Loop through the interface's cache
148                  */
149                 for (i = 0; i < ATMARP_HASHSIZ; i++) {
150                         for (aap = aip->ai_arptbl[i]; aap;
151                                         aap = aap->aa_next) {
152                                 /*
153                                  * Find and update permanent entries
154                                  */
155                                 if ((aap->aa_flags & (AAF_PERM |
156                                                 AAF_SERVER)) != 0) {
157                                         aap->aa_seq++;
158                                         rc = atmarp_scsp_update(aap,
159                                                 SCSP_ASTATE_UPD);
160                                 }
161                         }
162                 }
163         }
164
165         /*
166          * Restart the permanent cache entry timer
167          */
168         HARP_TIMER(tp, ATMARP_PERM_INTERVAL, atmarp_perm_timeout);
169 }
170
171
172 /*
173  * Keepalive timeout processing
174  *
175  * When the keepalive timer fires, we send a NOP to SCSP.  This
176  * will help us detect a broken connection.
177  *
178  * Arguments:
179  *      tp      pointer to a HARP timer block
180  *
181  * Returns:
182  *      None
183  *
184  */
185 void
186 atmarp_keepalive_timeout(tp)
187         Harp_timer      *tp;
188 {
189         Atmarp_intf     *aip;
190         Scsp_if_msg     *msg;
191
192         /*
193          * Back off to start of DCS entry
194          */
195         aip = (Atmarp_intf *) ((caddr_t)tp -
196                         (int)(&((Atmarp_intf *)0)->ai_keepalive_t));
197
198         /*
199          * Get a message buffer
200          */
201         msg = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
202         if (!msg) {
203         }
204         UM_ZERO(msg, sizeof(Scsp_if_msg));
205
206         /*
207          * Build a NOP message
208          */
209         msg->si_type = SCSP_NOP_REQ;
210         msg->si_proto = SCSP_PROTO_ATMARP;
211         msg->si_len = sizeof(Scsp_if_msg_hdr);
212
213         /*
214          * Send the message to SCSP
215          */
216         (void)atmarp_scsp_out(aip, (char *)msg, msg->si_len);
217         UM_FREE(msg);
218
219         /*
220          * Restart the keepalive timer
221          */
222         HARP_TIMER(&aip->ai_keepalive_t, ATMARP_KEEPALIVE_INTERVAL,
223                         atmarp_keepalive_timeout);
224 }