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