Use GNU style like the rest of the file for my last commit.
[dragonfly/vkernel-mp.git] / usr.sbin / atm / atmarpd / atmarp_timer.c
blobcad3a456ea1f76f060e60ad90d2e4f3225212844
1 /*
3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
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.
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.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
26 * @(#) $FreeBSD: src/usr.sbin/atm/atmarpd/atmarp_timer.c,v 1.3 1999/08/28 01:15:30 peter Exp $
27 * @(#) $DragonFly: src/usr.sbin/atm/atmarpd/atmarp_timer.c,v 1.4 2004/12/18 23:48:02 swildner Exp $
31 * Server Cache Synchronization Protocol (SCSP) Support
32 * ----------------------------------------------------
34 * SCSP-ATMARP server interface: timer routines
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>
51 #include <errno.h>
52 #include <libatm.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include <syslog.h>
58 #include "../scspd/scsp_msg.h"
59 #include "../scspd/scsp_if.h"
60 #include "../scspd/scsp_var.h"
61 #include "atmarp_var.h"
64 * Cache update timeout processing
66 * When the cache update timer fires, we read the cache from the
67 * kernel, update the internal cache, and restart the timer.
69 * Arguments:
70 * tp pointer to a HARP timer block
72 * Returns:
73 * None
76 void
77 atmarp_cache_timeout(Harp_timer *tp)
79 Atmarp_intf *aip;
82 * Verify the status of all configured interfaces
84 for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
85 if (atmarp_if_ready(aip)) {
87 * The interface is up but we don't have
88 * a connection to SCSP--make a connection
90 if (aip->ai_state == AI_STATE_NULL)
91 atmarp_scsp_connect(aip);
92 } else {
94 * The interface is down--disconnect from SCSP
96 if (aip->ai_state != AI_STATE_NULL)
97 atmarp_scsp_disconnect(aip);
102 * Read the cache from the kernel
104 atmarp_get_updated_cache();
107 * Restart the cache update timer
109 HARP_TIMER(tp, ATMARP_CACHE_INTERVAL, atmarp_cache_timeout);
114 * Permanent cache entry timer processing
116 * Permanent cache entries (entries that are administratively added
117 * and the entry for the server itself) don't ever get refreshed, so
118 * we broadcast updates for them every 10 minutes so they won't get
119 * deleted from the remote servers' caches
121 * Arguments:
122 * tp pointer to a HARP timer block
124 * Returns:
125 * None
128 void
129 atmarp_perm_timeout(Harp_timer *tp)
131 int i, rc;
132 Atmarp_intf *aip;
133 Atmarp *aap;
136 * Loop through all interfaces
138 for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
140 * Loop through the interface's cache
142 for (i = 0; i < ATMARP_HASHSIZ; i++) {
143 for (aap = aip->ai_arptbl[i]; aap;
144 aap = aap->aa_next) {
146 * Find and update permanent entries
148 if ((aap->aa_flags & (AAF_PERM |
149 AAF_SERVER)) != 0) {
150 aap->aa_seq++;
151 rc = atmarp_scsp_update(aap,
152 SCSP_ASTATE_UPD);
159 * Restart the permanent cache entry timer
161 HARP_TIMER(tp, ATMARP_PERM_INTERVAL, atmarp_perm_timeout);
166 * Keepalive timeout processing
168 * When the keepalive timer fires, we send a NOP to SCSP. This
169 * will help us detect a broken connection.
171 * Arguments:
172 * tp pointer to a HARP timer block
174 * Returns:
175 * None
178 void
179 atmarp_keepalive_timeout(Harp_timer *tp)
181 Atmarp_intf *aip;
182 Scsp_if_msg *msg;
185 * Back off to start of DCS entry
187 aip = (Atmarp_intf *) ((caddr_t)tp -
188 (int)(&((Atmarp_intf *)0)->ai_keepalive_t));
191 * Get a message buffer
193 msg = (Scsp_if_msg *)UM_ALLOC(sizeof(Scsp_if_msg));
194 if (!msg) {
196 UM_ZERO(msg, sizeof(Scsp_if_msg));
199 * Build a NOP message
201 msg->si_type = SCSP_NOP_REQ;
202 msg->si_proto = SCSP_PROTO_ATMARP;
203 msg->si_len = sizeof(Scsp_if_msg_hdr);
206 * Send the message to SCSP
208 atmarp_scsp_out(aip, (char *)msg, msg->si_len);
209 UM_FREE(msg);
212 * Restart the keepalive timer
214 HARP_TIMER(&aip->ai_keepalive_t, ATMARP_KEEPALIVE_INTERVAL,
215 atmarp_keepalive_timeout);